コード例 #1
0
ファイル: ajax.kbase.php プロジェクト: pkdevboxy/osTicket-1.7
 function faq($id, $format = 'html')
 {
     //XXX: user ajax->getThisStaff() (nolint)
     global $thisstaff;
     include_once INCLUDE_DIR . 'class.faq.php';
     if (!($faq = FAQ::lookup($id))) {
         return null;
     }
     //TODO: $f*g->getJSON() for json format. (nolint)
     $resp = sprintf('<div style="width:650px;">
              <strong>%s</strong><p>%s</p>
              <div class="faded">Last updated %s</div>
              <hr>
              <a href="faq.php?id=%d">View</a> | <a href="faq.php?id=%d">Attachments (%s)</a>', $faq->getQuestion(), Format::safe_html($faq->getAnswer()), Format::db_daydatetime($faq->getUpdateDate()), $faq->getId(), $faq->getId(), $faq->getNumAttachments());
     if ($thisstaff && $thisstaff->canManageFAQ()) {
         $resp .= sprintf(' | <a href="faq.php?id=%d&a=edit">Edit</a>', $faq->getId());
     }
     $resp .= '</div>';
     return $resp;
 }
コード例 #2
0
 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;
 }
コード例 #3
0
ファイル: class.search.php プロジェクト: KM-MFG/osTicket-1.8
 /**
  * Cooperates with the cron system to automatically find content that is
  * not index in the _search table and add it to the index.
  */
 function IndexOldStuff()
 {
     $class = get_class();
     $auto_create = function ($db_error) use($class) {
         if ($db_error != 1146) {
             // Perform the standard error handling
             return true;
         }
         // Create the search table automatically
         $class::__init();
     };
     // THREADS ----------------------------------
     $sql = "SELECT A1.`id`, A1.`title`, A1.`body`, A1.`format` FROM `" . TICKET_THREAD_TABLE . "` A1\n            LEFT JOIN `" . TABLE_PREFIX . "_search` A2 ON (A1.`id` = A2.`object_id` AND A2.`object_type`='H')\n            WHERE A2.`object_id` IS NULL AND (A1.poster <> 'SYSTEM')\n            AND (LENGTH(A1.`title`) + LENGTH(A1.`body`) > 0)\n            ORDER BY A1.`id` DESC";
     if (!($res = db_query_unbuffered($sql, $auto_create))) {
         return false;
     }
     while ($row = db_fetch_row($res)) {
         $body = ThreadBody::fromFormattedText($row[2], $row[3]);
         $body = $body->getSearchable();
         $title = Format::searchable($row[1]);
         if (!$body && !$title) {
             continue;
         }
         $record = array('H', $row[0], $title, $body);
         if (!$this->__index($record)) {
             return;
         }
     }
     // TICKETS ----------------------------------
     $sql = "SELECT A1.`ticket_id` FROM `" . TICKET_TABLE . "` A1\n            LEFT JOIN `" . TABLE_PREFIX . "_search` A2 ON (A1.`ticket_id` = A2.`object_id` AND A2.`object_type`='T')\n            WHERE A2.`object_id` IS NULL\n            ORDER BY A1.`ticket_id` DESC";
     if (!($res = db_query_unbuffered($sql, $auto_create))) {
         return false;
     }
     while ($row = db_fetch_row($res)) {
         $ticket = Ticket::lookup($row[0]);
         $cdata = $ticket->loadDynamicData();
         $content = array();
         foreach ($cdata as $k => $a) {
             if ($k != 'subject' && ($v = $a->getSearchable())) {
                 $content[] = $v;
             }
         }
         $record = array('T', $ticket->getId(), Format::searchable($ticket->getNumber() . ' ' . $ticket->getSubject()), implode("\n", $content));
         if (!$this->__index($record)) {
             return;
         }
     }
     // USERS ------------------------------------
     $sql = "SELECT A1.`id` FROM `" . USER_TABLE . "` A1\n            LEFT JOIN `" . TABLE_PREFIX . "_search` A2 ON (A1.`id` = A2.`object_id` AND A2.`object_type`='U')\n            WHERE A2.`object_id` IS NULL\n            ORDER BY A1.`id` DESC";
     if (!($res = db_query_unbuffered($sql, $auto_create))) {
         return false;
     }
     while ($row = db_fetch_row($res)) {
         $user = User::lookup($row[0]);
         $cdata = $user->getDynamicData();
         $content = array();
         foreach ($user->emails as $e) {
             $content[] = $e->address;
         }
         foreach ($cdata as $e) {
             foreach ($e->getAnswers() as $a) {
                 if ($c = $a->getSearchable()) {
                     $content[] = $c;
                 }
             }
         }
         $record = array('U', $user->getId(), Format::searchable($user->getFullName()), trim(implode("\n", $content)));
         if (!$this->__index($record)) {
             return;
         }
     }
     // ORGANIZATIONS ----------------------------
     $sql = "SELECT A1.`id` FROM `" . ORGANIZATION_TABLE . "` A1\n            LEFT JOIN `" . TABLE_PREFIX . "_search` A2 ON (A1.`id` = A2.`object_id` AND A2.`object_type`='O')\n            WHERE A2.`object_id` IS NULL\n            ORDER BY A1.`id` DESC";
     if (!($res = db_query_unbuffered($sql, $auto_create))) {
         return false;
     }
     while ($row = db_fetch_row($res)) {
         $org = Organization::lookup($row[0]);
         $cdata = $org->getDynamicData();
         $content = array();
         foreach ($cdata as $e) {
             foreach ($e->getAnswers() as $a) {
                 if ($c = $a->getSearchable()) {
                     $content[] = $c;
                 }
             }
         }
         $record = array('O', $org->getId(), Format::searchable($org->getName()), trim(implode("\n", $content)));
         if (!$this->__index($record)) {
             return null;
         }
     }
     // KNOWLEDGEBASE ----------------------------
     require_once INCLUDE_DIR . 'class.faq.php';
     $sql = "SELECT A1.`faq_id` FROM `" . FAQ_TABLE . "` A1\n            LEFT JOIN `" . TABLE_PREFIX . "_search` A2 ON (A1.`faq_id` = A2.`object_id` AND A2.`object_type`='K')\n            WHERE A2.`object_id` IS NULL\n            ORDER BY A1.`faq_id` DESC";
     if (!($res = db_query_unbuffered($sql, $auto_create))) {
         return false;
     }
     while ($row = db_fetch_row($res)) {
         $faq = FAQ::lookup($row[0]);
         $q = $faq->getQuestion();
         if ($k = $faq->getKeywords()) {
             $q = $k . ' ' . $q;
         }
         $record = array('K', $faq->getId(), Format::searchable($q), $faq->getSearchableAnswer());
         if (!$this->__index($record)) {
             return;
         }
     }
     // FILES ------------------------------------
     // Flush non-full batch of records
     $this->__index(null, true);
     if (!$this->_reindexed) {
         // Stop rebuilding the index
         $this->getConfig()->set('reindex', 0);
     }
 }
コード例 #4
0
ファイル: faq.php プロジェクト: dmiguel92/osTicket-1.8
    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';