Skip to content
Snippets Groups Projects
categories.php 4.66 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 || !$thisstaff->canManageFAQ()) {
        header('Location: kb.php');
        exit;
    }
    
    
    $category=null;
    if($_REQUEST['id'] && !($category=Category::lookup($_REQUEST['id'])))
    
        $errors['err']=__('Unknown or invalid category ID.');
    
    Jared Hancock's avatar
    Jared Hancock committed
    
    if($_POST){
        switch(strtolower($_POST['do'])) {
            case 'update':
                if(!$category) {
    
                    $errors['err']=__('Unknown or invalid category.');
    
    Jared Hancock's avatar
    Jared Hancock committed
                } elseif($category->update($_POST,$errors)) {
    
                    $msg=__('Category updated successfully');
    
    Jared Hancock's avatar
    Jared Hancock committed
                } elseif(!$errors['err']) {
    
                    $errors['err']=__('Error updating category. Try again!');
    
    Jared Hancock's avatar
    Jared Hancock committed
                }
                break;
            case 'create':
                if(($id=Category::create($_POST,$errors))) {
    
                    $msg=__('Category added successfully');
    
    Jared Hancock's avatar
    Jared Hancock committed
                    $_REQUEST['a']=null;
                } elseif(!$errors['err']) {
    
                    $errors['err']=__('Unable to add category. Correct error(s) below and try again.');
    
    Jared Hancock's avatar
    Jared Hancock committed
                }
                break;
            case 'mass_process':
                if(!$_POST['ids'] || !is_array($_POST['ids']) || !count($_POST['ids'])) {
    
                    $errors['err']=__('You must select at least one category');
    
    Jared Hancock's avatar
    Jared Hancock committed
                } else {
                    $count=count($_POST['ids']);
    
                    switch(strtolower($_POST['a'])) {
                        case 'make_public':
                            $sql='UPDATE '.FAQ_CATEGORY_TABLE.' SET ispublic=1 '
                                .' WHERE category_id IN ('.implode(',', db_input($_POST['ids'])).')';
    
                            if(db_query($sql) && ($num=db_affected_rows())) {
                                if($num==$count)
    
                                    $msg = __('Selected categories made PUBLIC');
    
                                    $warn = sprintf(__('%1$d of %2$d selected categories made PUBLIC'), $num, $count);
    
                                $errors['err'] = __('Unable to enable selected categories public.');
    
                            }
                            break;
                        case 'make_private':
                            $sql='UPDATE '.FAQ_CATEGORY_TABLE.' SET ispublic=0 '
                                .' WHERE category_id IN ('.implode(',', db_input($_POST['ids'])).')';
    
                            if(db_query($sql) && ($num=db_affected_rows())) {
                                if($num==$count)
    
                                    $msg = __('Selected categories made PRIVATE');
    
                                    $warn = sprintf(__('%1$d of %2$d selected categories made PRIVATE'), $num, $count);
    
                                $errors['err'] = __('Unable to disable selected categories PRIVATE');
    
                            }
                            break;
                        case 'delete':
                            $i=0;
                            foreach($_POST['ids'] as $k=>$v) {
                                if(($c=Category::lookup($v)) && $c->delete())
                                    $i++;
                            }
    
                            if($i==$count)
    
                                $msg = __('Selected categories deleted successfully');
    
                                $warn = sprintf(__('%1$d of %2$d selected categories deleted'), $i, $count);
    
                            elseif(!$errors['err'])
    
                                $errors['err'] = __('Unable to delete selected categories');
    
                            $errors['err']=__('Unknown action/command');
    
    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');
    ?>