Skip to content
Snippets Groups Projects
categories.php 5.69 KiB
Newer Older
  • Learn to ignore specific revisions
  • Jared Hancock's avatar
    Jared Hancock committed
    <?php
    /*********************************************************************
        categories.php
    
        FAQ categories
    
        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('staff.inc.php');
    include_once(INCLUDE_DIR.'class.category.php');
    
    /* check permission */
    
    if(!$thisstaff ||
    
    Peter Rotich's avatar
    Peter Rotich committed
            !$thisstaff->getRole()->hasPerm(FAQ::PERM_MANAGE)) {
    
    Jared Hancock's avatar
    Jared Hancock committed
        header('Location: kb.php');
        exit;
    }
    
    
    $category=null;
    if($_REQUEST['id'] && !($category=Category::lookup($_REQUEST['id'])))
    
        $errors['err']=sprintf(__('%s: Unknown or invalid ID.'), __('category'));
    
    Jared Hancock's avatar
    Jared Hancock committed
    
    if($_POST){
        switch(strtolower($_POST['do'])) {
            case 'update':
                if(!$category) {
    
                    $errors['err']=sprintf(__('%s: Unknown or invalid'), __('category'));
    
    Jared Hancock's avatar
    Jared Hancock committed
                } elseif($category->update($_POST,$errors)) {
    
                    $msg=sprintf(__('Successfully updated %s'),
                        __('this category'));
    
    Jared Hancock's avatar
    Jared Hancock committed
                } elseif(!$errors['err']) {
    
                    $errors['err']=sprintf(__('Error updating %s. Correct error(s) below and try again.'), __('this category'));
    
    Jared Hancock's avatar
    Jared Hancock committed
                }
                break;
            case 'create':
    
                $category = Category::create();
                if ($category->update($_POST, $errors)) {
    
                    $msg=sprintf(__('Successfull added %s'), Format::htmlchars($_POST['name']));
    
    Jared Hancock's avatar
    Jared Hancock committed
                    $_REQUEST['a']=null;
                } elseif(!$errors['err']) {
    
                    $errors['err']=sprintf(__('Unable to add %s. Correct error(s) below and try again.'),
                        __('this category'));
    
    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 category'));
    
    Jared Hancock's avatar
    Jared Hancock committed
                } else {
                    $count=count($_POST['ids']);
    
                    switch(strtolower($_POST['a'])) {
                        case 'make_public':
    
                            $num = Category::objects()->filter(array(
                                'category_id__in'=>$_POST['ids']
                            ))->update(array(
                                'ispublic'=>true
                            ));
                            if ($num > 0) {
                                if ($num==$count)
    
                                    $msg = sprintf(__('Successfully made %s PUBLIC'),
                                        _N('selected category', 'selected categories', $count));
    
                                    $warn = sprintf(__('%1$d of %2$d %3$s made PUBLIC'), $num, $count,
                                        _N('selected category', 'selected categories', $count));
    
                                $errors['err'] = sprintf(__('Unable to make %s PUBLIC.'),
                                    _N('selected category', 'selected categories', $count));
    
                            }
                            break;
                        case 'make_private':
    
                            $num = Category::objects()->filter(array(
                                'category_id__in'=>$_POST['ids']
                            ))->update(array(
                                'ispublic'=>false
                            ));
                            if ($num > 0) {
    
                                    $msg = sprintf(__('Successfully made %s PRIVATE'),
                                        _N('selected category', 'selected categories', $count));
    
                                    $warn = sprintf(__('%1$d of %2$d %3$s made PRIVATE'), $num, $count,
                                        _N('selected category', 'selected categories', $count));
    
                                $errors['err'] = sprintf(__('Unable to make %s PRIVATE'),
                                    _N('selected category', 'selected categories', $count));
    
                            $i = Category::objects()->filter(array(
                                'category_id__in'=>$_POST['ids']
                            ))->delete();
    
                                $msg = sprintf(__('Successfully deleted %s'),
                                    _N('selected category', 'selected categories', $count));
    
                                $warn = sprintf(__('%1$d of %2$d %3$s deleted'), $i, $count,
                                    _N('selected category', 'selected categories', $count));
    
                            elseif (!$errors['err'])
    
                                $errors['err'] = sprintf(__('Unable to delete %s'),
                                    _N('selected category', 'selected categories', $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='categories.inc.php';
    
    Peter Rotich's avatar
    Peter Rotich committed
    $tip_namespace = 'knowledgebase.category';
    
    if($category || ($_REQUEST['a'] && !strcasecmp($_REQUEST['a'],'add'))) {
    
    Jared Hancock's avatar
    Jared Hancock committed
        $page='category.inc.php';
    
    Jared Hancock's avatar
    Jared Hancock committed
    
    $nav->setTabActive('kbase');
    
    $ost->addExtraHeader('<meta name="tip-namespace" content="' . $tip_namespace . '" />',
        "$('#content').data('tipNamespace', '".$tip_namespace."');");
    
    Jared Hancock's avatar
    Jared Hancock committed
    require(STAFFINC_DIR.'header.inc.php');
    require(STAFFINC_DIR.$page);
    include(STAFFINC_DIR.'footer.inc.php');
    ?>