Newer
Older
<?php
/*********************************************************************
helptopics.php
Help Topics.
Peter Rotich <peter@osticket.com>
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.topic.php');
include_once(INCLUDE_DIR.'class.faq.php');
require_once(INCLUDE_DIR.'class.dynamic_forms.php');
$topic=null;
if($_REQUEST['id'] && !($topic=Topic::lookup($_REQUEST['id'])))
$errors['err']=sprintf(__('%s: Unknown or invalid ID.'), __('help topic'));
if($_POST){
switch(strtolower($_POST['do'])){
case 'update':
if(!$topic){
$errors['err']=sprintf(__('%s: Unknown or invalid'), __('help topic'));
$msg=sprintf(__('Successfully updated %s'),
__('this help topic'));
$errors['err']=sprintf(__('Error updating %s. Try again!'),
__('this help topic'));
$_topic = Topic::create();
if ($_topic->update($_POST, $errors)) {
$topic = $_topic;
$msg=sprintf(__('Successfully added %s'), Format::htmlchars($_POST['topic']));
$_REQUEST['a']=null;
}elseif(!$errors['err']){
$errors['err']=sprintf(__('Unable to add %s. Correct error(s) below and try again.'),
__('this help topic'));
switch(strtolower($_POST['a'])) {
case 'sort':
// Pass
break;
default:
if(!$_POST['ids'] || !is_array($_POST['ids']) || !count($_POST['ids']))
$errors['err'] = sprintf(__('You must select at least %s'),
__('one help topic'));
switch(strtolower($_POST['a'])) {
case 'enable':
$num = Topic::objects()->filter(array(
'topic_id__in' => $_POST['ids'],
))->update(array(
'isactive' => true,
));
$msg = sprintf(__('Successfully enabled %s'),
_N('selected help topic', 'selected help topics', $count));
$warn = sprintf(__('%1$d of %2$d %3$s enabled'), $num, $count,
_N('selected help topic', 'selected help topics', $count));
$errors['err'] = sprintf(__('Unable to enable %s.'),
_N('selected help topic', 'selected help topics', $count));
}
break;
case 'disable':
$num = Topic::objects()->filter(array(
'topic_id__in'=>$_POST['ids'],
))->exclude(array(
'topic_id'=>$cfg->getDefaultTopicId(),
))->update(array(
'isactive' => false,
));
if ($num > 0) {
$msg = sprintf(__('Successfully diabled %s'),
_N('selected help topic', 'selected help topics', $count));
$warn = sprintf(__('%1$d of %2$d %3$s disabled'), $num, $count,
_N('selected help topic', 'selected help topics', $count));
$errors['err'] = sprintf(__('Unable to disable %s'),
_N('selected help topic', 'selected help topics', $count));
}
break;
case 'delete':
$i = Topic::objects()->filter(array(
'topic_id__in'=>$_POST['ids']
))->delete();
if($i && $i==$count)
$msg = sprintf(__('Successfully deleted %s'),
_N('selected help topic', 'selected elp topics', $count));
$warn = sprintf(__('%1$d of %2$d %3$s deleted'), $i, $count,
_N('selected help topic', 'selected help topics', $count));
$errors['err'] = sprintf(__('Unable to delete %s'),
_N('selected help topic', 'selected help topics', $count));
break;
case 'sort':
try {
$cfg->setTopicSortMode($_POST['help_topic_sort_mode']);
if ($cfg->getTopicSortMode() == 'm') {
foreach ($_POST as $k=>$v) {
if (strpos($k, 'sort-') === 0
&& is_numeric($v)
&& ($t = Topic::lookup(substr($k, 5))))
$t->setSortOrder($v);
}
}
$msg = __('Successfully set sorting configuration');
}
catch (Exception $ex) {
$errors['err'] = __('Unable to set sorting mode');
$errors['err']=__('Unknown action - get technical help.');
$errors['err']=__('Unknown action');
if ($id or $topic) {
if (!$id) $id=$topic->getId();
}
if($topic || ($_REQUEST['a'] && !strcasecmp($_REQUEST['a'],'add'))) {
$ost->addExtraHeader('<meta name="tip-namespace" content="' . $tip_namespace . '" />',
"$('#content').data('tipNamespace', '".$tip_namespace."');");
require(STAFFINC_DIR.'header.inc.php');
require(STAFFINC_DIR.$page);
include(STAFFINC_DIR.'footer.inc.php');
?>