Skip to content
Snippets Groups Projects
slas.php 5.77 KiB
Newer Older
Jared Hancock's avatar
Jared Hancock committed
<?php
/*********************************************************************
    slas.php

    SLA - Service Level Agreements

    Peter Rotich <peter@osticket.com>
    Copyright (c)  2006-2013 osTicket
Jared Hancock's avatar
Jared Hancock committed
    http://www.osticket.com

    Released under the GNU General Public License WITHOUT ANY WARRANTY.
    See LICENSE.TXT for details.

    vim: expandtab sw=4 ts=4 sts=4:
**********************************************************************/
require('admin.inc.php');
include_once(INCLUDE_DIR.'class.sla.php');

$sla=null;
if($_REQUEST['id'] && !($sla=SLA::lookup($_REQUEST['id'])))
    $errors['err']=sprintf(__('%s: Unknown or invalid ID.'),
        __('SLA plan'));
Jared Hancock's avatar
Jared Hancock committed

if($_POST){
    switch(strtolower($_POST['do'])){
        case 'update':
            if(!$sla){
                $errors['err']=sprintf(__('%s: Unknown or invalid'),
                    __('SLA plan'));
Jared Hancock's avatar
Jared Hancock committed
            }elseif($sla->update($_POST,$errors)){
                $msg=sprintf(__('Successfully updated %s'),
                    __('this SLA plan'));
Jared Hancock's avatar
Jared Hancock committed
            }elseif(!$errors['err']){
                $errors['err']=sprintf(__('Error updating %s. Try again!'),
                    __('this SLA plan'));
Jared Hancock's avatar
Jared Hancock committed
            }
            break;
        case 'add':
Peter Rotich's avatar
Peter Rotich committed
            $_sla = SLA::create();
            if (($_sla->update($_POST, $errors))) {
                $msg=sprintf(__('Successfully added %s'),
                    __('a SLA plan'));
Jared Hancock's avatar
Jared Hancock committed
                $_REQUEST['a']=null;
Peter Rotich's avatar
Peter Rotich committed
            } elseif (!$errors['err']) {
                $errors['err']=sprintf(__('Unable to add %s. Correct error(s) below and try again.'),
                    __('this SLA plan'));
Jared Hancock's avatar
Jared Hancock committed
            }
            break;
        case 'mass_process':
            if(!$_POST['ids'] || !is_array($_POST['ids']) || !count($_POST['ids'])) {
                $errors['err'] = sprintf(__('You must select at least %s.'),
                    __('one SLA plan'));
Jared Hancock's avatar
Jared Hancock committed
                $count=count($_POST['ids']);
                switch(strtolower($_POST['a'])) {
                    case 'enable':
Peter Rotich's avatar
Peter Rotich committed
                        $num = SLA::objects()->filter(array(
                            'id__in' => $_POST['ids']
                        ))->update(array(
                            'flags' => SqlExpression::bitor(
                                new SqlField('flags'), SLA::FLAG_ACTIVE)
Peter Rotich's avatar
Peter Rotich committed
                        ));
                        if ($num) {
                                $msg = sprintf(__('Successfully enabled %s'),
                                    _N('selected SLA plan', 'selected SLA plans', $count));
                                $warn = sprintf(__('%1$d of %2$d %3$s enabled'), $num, $count,
                                    _N('selected SLA plan', 'selected SLA plans', $count));
                            $errors['err'] = sprintf(__('Unable to enable %s'),
                                _N('selected SLA plan', 'selected SLA plans', $count));
Peter Rotich's avatar
Peter Rotich committed
                        $num = SLA::objects()->filter(array(
                            'id__in' => $_POST['ids']
                        ))->update(array(
                            'flags' => SqlExpression::bitand(
                                new SqlField('flags'), ~SLA::FLAG_ACTIVE)
Peter Rotich's avatar
Peter Rotich committed
                        ));

                        if ($num) {
                                $msg = sprintf(__('Successfully disabled %s'),
                                    _N('selected SLA plan', 'selected SLA plans', $count));
                                $warn = sprintf(__('%1$d of %2$d %3$s disabled'), $num, $count,
                                    _N('selected SLA plan', 'selected SLA plans', $count));
                            $errors['err'] = sprintf(__('Unable to disable %s'),
                                _N('selected SLA plan', 'selected SLA plans', $count));
                        }
                        break;
                    case 'delete':
                        $i=0;
Peter Rotich's avatar
Peter Rotich committed
                        foreach ($_POST['ids'] as $k => $v) {
Peter Rotich's avatar
Peter Rotich committed
                            if (($p=SLA::lookup($v))
                                && $p->getId() != $cfg->getDefaultSLAId()
                                && $p->delete())
                            $msg = sprintf(__('Successfully deleted %s'),
                                _N('selected SLA plan', 'selected SLA plans', $count));
                            $warn = sprintf(__('%1$d of %2$d %3$s deleted'), $i, $count,
                                _N('selected SLA plan', 'selected SLA plans', $count));
                        elseif(!$errors['err'])
                            $errors['err'] = sprintf(__('Unable to delete %s'),
                                _N('selected SLA plan', 'selected SLA plans', $count));
                        $errors['err']=__('Unknown action - get technical help.');
Jared Hancock's avatar
Jared Hancock committed
                }
            }
            break;
        default:
            $errors['err']=__('Unknown action');
Jared Hancock's avatar
Jared Hancock committed
            break;
    }
}

$page='slaplans.inc.php';
if($sla || ($_REQUEST['a'] && !strcasecmp($_REQUEST['a'],'add'))) {
Jared Hancock's avatar
Jared Hancock committed
    $page='slaplan.inc.php';
Peter Rotich's avatar
Peter Rotich committed
    $ost->addExtraHeader('<meta name="tip-namespace" content="manage.sla" />',
            "$('#content').data('tipNamespace', 'manage.sla');");
$nav->setTabActive('manage');
Jared Hancock's avatar
Jared Hancock committed
require(STAFFINC_DIR.'header.inc.php');
require(STAFFINC_DIR.$page);
include(STAFFINC_DIR.'footer.inc.php');
?>