function save($id, $vars, &$errors, $validation = false) { //Cleanup. $vars['question'] = Format::striptags(trim($vars['question'])); //validate if ($id && $id != $vars['id']) { $errors['err'] = __('Internal error. Try again'); } if (!$vars['question']) { $errors['question'] = __('Question required'); } elseif (($qid = self::findIdByQuestion($vars['question'])) && $qid != $id) { $errors['question'] = __('Question already exists'); } if (!$vars['category_id'] || !($category = Category::lookup($vars['category_id']))) { $errors['category_id'] = __('Category is required'); } if (!$vars['answer']) { $errors['answer'] = __('FAQ answer is required'); } if ($errors || $validation) { return !$errors; } //save $sql = ' updated=NOW() ' . ', question=' . db_input($vars['question']) . ', answer=' . db_input(Format::sanitize($vars['answer'], false)) . ', category_id=' . db_input($vars['category_id']) . ', ispublished=' . db_input(isset($vars['ispublished']) ? $vars['ispublished'] : 0) . ', notes=' . db_input(Format::sanitize($vars['notes'])); if ($id) { $sql = 'UPDATE ' . FAQ_TABLE . ' SET ' . $sql . ' WHERE faq_id=' . db_input($id); if (db_query($sql)) { return true; } $errors['err'] = sprintf(__('Unable to update %s.'), __('this FAQ article')); } else { $sql = 'INSERT INTO ' . FAQ_TABLE . ' SET ' . $sql . ',created=NOW()'; if (db_query($sql) && ($id = db_insert_id())) { Signal::send('model.created', FAQ::lookup($id)); return $id; } $errors['err'] = sprintf(__('Unable to create %s.'), __('this FAQ article')) . ' ' . __('Internal error occurred'); } return false; }
FAQs Clients' interface.. Peter Rotich <*****@*****.**> Copyright (c) 2006-2013 osTicket 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 'kb.inc.php'; require_once INCLUDE_DIR . 'class.faq.php'; $faq = $category = null; if ($_REQUEST['id'] && !($faq = FAQ::lookup($_REQUEST['id']))) { $errors['err'] = sprintf(__('%s: Unknown or invalid'), __('FAQ article')); } if (!$faq && $_REQUEST['cid'] && !($category = Category::lookup($_REQUEST['cid']))) { $errors['err'] = sprintf(__('%s: Unknown or invalid'), __('FAQ category')); } $inc = 'knowledgebase.inc.php'; //FAQs landing page. if ($faq && $faq->isPublished()) { $inc = 'faq.inc.php'; } elseif ($category && $category->isPublic() && $_REQUEST['a'] != 'search') { $inc = 'faq-category.inc.php'; } require_once CLIENTINC_DIR . 'header.inc.php'; require_once CLIENTINC_DIR . $inc; require_once CLIENTINC_DIR . 'footer.inc.php';
} } elseif ($_POST['private']) { $sql = 'UPDATE ' . FAQ_CATEGORY_TABLE . ' SET ispublic=0 WHERE category_id IN (' . implode(',', $_POST['ids']) . ')'; if (db_query($sql) && ($num = db_affected_rows())) { if ($num == $count) { $msg = 'Selected categories made PRIVATE'; } else { $warn = "{$num} of {$count} selected categories made PRIVATE"; } } else { $errors['err'] = 'Unable to disable selected categories PRIVATE'; } } elseif ($_POST['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'; } elseif ($i > 0) { $warn = "{$i} of {$count} selected categories deleted"; } elseif (!$errors['err']) { $errors['err'] = 'Unable to delete selected categories'; } } else { $errors['err'] = 'Unknown command'; } } break;
function save($id, $vars, &$errors, $validation = false) { //Cleanup. $vars['question'] = Format::striptags(trim($vars['question'])); //validate if ($id && $id != $vars['id']) { $errors['err'] = 'Internal error. Try again'; } if (!$vars['question']) { $errors['question'] = 'Question required'; } elseif (($qid = self::findIdByQuestion($vars['question'])) && $qid != $id) { $errors['question'] = 'Question already exists'; } if (!$vars['category_id'] || !($category = Category::lookup($vars['category_id']))) { $errors['category_id'] = 'Category is required'; } if (!$vars['answer']) { $errors['answer'] = 'FAQ answer is required'; } if ($errors || $validation) { return !$errors; } //save $sql = ' updated=NOW() ' . ', question=' . db_input($vars['question']) . ', answer=' . db_input(Format::safe_html($vars['answer'])) . ', category_id=' . db_input($vars['category_id']) . ', ispublished=' . db_input(isset($vars['ispublished']) ? $vars['ispublished'] : 0) . ', notes=' . db_input($vars['notes']); if ($id) { $sql = 'UPDATE ' . FAQ_TABLE . ' SET ' . $sql . ' WHERE faq_id=' . db_input($id); if (db_query($sql)) { return true; } $errors['err'] = 'Unable to update FAQ.'; } else { $sql = 'INSERT INTO ' . FAQ_TABLE . ' SET ' . $sql . ',created=NOW()'; if (db_query($sql) && ($id = db_insert_id())) { return $id; } $errors['err'] = 'Unable to create FAQ. Internal error'; } return false; }