static function pdfMain(PluginPdfSimplePDF $pdf, KnowbaseItem $item)
 {
     global $DB;
     $ID = $item->getField('id');
     if (!Session::haveRight('knowbase', 'r') || !Session::haveRight('faq', 'r')) {
         return false;
     }
     $knowbaseitemcategories_id = $item->getField('knowbaseitemcategories_id');
     $fullcategoryname = Html::clean(getTreeValueCompleteName("glpi_knowbaseitemcategories", $knowbaseitemcategories_id));
     $question = Html::clean(Toolbox::unclean_cross_side_scripting_deep(html_entity_decode($item->getField('name'), ENT_QUOTES, "UTF-8")));
     $answer = Html::clean(Toolbox::unclean_cross_side_scripting_deep(html_entity_decode($item->getField('answer'), ENT_QUOTES, "UTF-8")));
     $pdf->setColumnsSize(100);
     if (Toolbox::strlen($fullcategoryname) > 0) {
         $pdf->displayTitle('<b>' . __('Category name') . '</b>');
         $pdf->displayLine($fullcategoryname);
     }
     if (Toolbox::strlen($question) > 0) {
         $pdf->displayTitle('<b>' . __('Subject') . '</b>');
         $pdf->displayText('', $question, 5);
     } else {
         $pdf->displayTitle('<b>' . __('No question found', 'pdf') . '</b>');
     }
     if (Toolbox::strlen($answer) > 0) {
         $pdf->displayTitle('<b>' . __('Content') . '</b>');
         $pdf->displayText('', $answer, 5);
     } else {
         $pdf->displayTitle('<b>' . __('No answer found') . '</b>');
     }
     $pdf->setColumnsSize(50, 15, 15, 10, 10);
     $pdf->displayTitle(__('Writer'), __('Creation date'), __('Last update'), __('FAQ'), _n('View', 'Views', 2));
     $pdf->displayLine(getUserName($item->fields["users_id"]), Html::convDateTime($item->fields["date"]), Html::convDateTime($item->fields["date_mod"]), Dropdown::getYesNo($item->fields["is_faq"]), $item->fields["view"]);
     $pdf->displaySpace();
 }
 /**
  * Form to add a solution to an ITIL object
  *
  * @param $knowbase_id_toload integer  load a kb article as solution (0 = no load by default)
  *                                     (default 0)
  **/
 function showSolutionForm($knowbase_id_toload = 0)
 {
     global $CFG_GLPI;
     $this->check($this->getField('id'), READ);
     $canedit = $this->canSolve();
     $options = array();
     if ($knowbase_id_toload > 0) {
         $kb = new KnowbaseItem();
         if ($kb->getFromDB($knowbase_id_toload)) {
             $this->fields['solution'] = $kb->getField('answer');
         }
     }
     // Alert if validation waiting
     $validationtype = $this->getType() . 'Validation';
     if (method_exists($validationtype, 'alertValidation')) {
         $validationtype::alertValidation($this, 'solution');
     }
     $this->showFormHeader($options);
     $show_template = $canedit;
     //                        && $this->getField('solutiontypes_id') == 0
     //                        && empty($this->fields['solution']);
     $rand_template = mt_rand();
     $rand_text = $rand_type = 0;
     if ($canedit) {
         $rand_text = mt_rand();
         $rand_type = mt_rand();
     }
     if ($show_template) {
         echo "<tr class='tab_bg_2'>";
         echo "<td>" . _n('Solution template', 'Solution templates', 1) . "</td><td>";
         SolutionTemplate::dropdown(array('value' => 0, 'entity' => $this->getEntityID(), 'rand' => $rand_template, 'toupdate' => array('value_fieldname' => 'value', 'to_update' => 'solution' . $rand_text, 'url' => $CFG_GLPI["root_doc"] . "/ajax/solution.php", 'moreparams' => array('type_id' => 'dropdown_solutiontypes_id' . $rand_type))));
         echo "</td><td colspan='2'>";
         if (Session::haveRightsOr('knowbase', array(READ, KnowbaseItem::READFAQ))) {
             echo "<a class='vsubmit' title=\"" . __s('Search a solution') . "\"\n                   href='" . $CFG_GLPI['root_doc'] . "/front/knowbaseitem.php?item_itemtype=" . $this->getType() . "&amp;item_items_id=" . $this->getField('id') . "&amp;forcetab=Knowbase\$1'>" . __('Search a solution') . "</a>";
         }
         echo "</td></tr>";
     }
     echo "<tr class='tab_bg_2'>";
     echo "<td>" . __('Solution type') . "</td><td>";
     $current = $this->fields['status'];
     // Settings a solution will set status to solved
     if ($canedit) {
         SolutionType::dropdown(array('value' => $this->getField('solutiontypes_id'), 'rand' => $rand_type, 'entity' => $this->getEntityID()));
     } else {
         echo Dropdown::getDropdownName('glpi_solutiontypes', $this->getField('solutiontypes_id'));
     }
     echo "</td><td colspan='2'>&nbsp;</td></tr>";
     if ($canedit && Session::haveRight('knowbase', UPDATE)) {
         echo "<tr class='tab_bg_2'><td>" . __('Save and add to the knowledge base') . "</td><td>";
         Dropdown::showYesNo('_sol_to_kb', false);
         echo "</td><td colspan='2'>&nbsp;</td></tr>";
     }
     echo "<tr class='tab_bg_2'>";
     echo "<td>" . __('Description') . "</td><td colspan='3'>";
     if ($canedit) {
         $rand = mt_rand();
         Html::initEditorSystem("solution{$rand}");
         echo "<div id='solution{$rand_text}'>";
         echo "<textarea id='solution{$rand}' name='solution' rows='12' cols='80' class='form-control'>" . $this->getField('solution') . "</textarea></div>";
     } else {
         echo Toolbox::unclean_cross_side_scripting_deep($this->getField('solution'));
     }
     echo "</td></tr>";
     $options['candel'] = false;
     $options['canedit'] = $canedit;
     $this->showFormButtons($options);
 }
 /**
  * Form to add a solution to a ticket
  *
  * @param $knowbase_id_toload integer load a kb article as solution (0 = no load)
  **/
 function showSolutionForm($knowbase_id_toload = 0)
 {
     global $LANG, $CFG_GLPI;
     $this->check($this->getField('id'), 'r');
     $canedit = $this->canSolve();
     $options = array();
     if ($knowbase_id_toload > 0) {
         $kb = new KnowbaseItem();
         if ($kb->getFromDB($knowbase_id_toload)) {
             $this->fields['solution'] = $kb->getField('answer');
         }
     }
     $this->showFormHeader($options);
     $show_template = $canedit;
     //                        && $this->getField('ticketsolutiontypes_id') == 0
     //                        && empty($this->fields['solution']);
     $rand_template = mt_rand();
     $rand_text = $rand_type = 0;
     if ($canedit) {
         $rand_text = mt_rand();
         $rand_type = mt_rand();
     }
     if ($show_template) {
         echo "<tr class='tab_bg_2'>";
         echo "<td>" . $LANG['jobresolution'][6] . "&nbsp;:&nbsp;</td><td>";
         Dropdown::show('TicketSolutionTemplate', array('value' => 0, 'entity' => $this->getEntityID(), 'rand' => $rand_template, 'toupdate' => array('value_fieldname' => 'value', 'to_update' => 'solution' . $rand_text, 'url' => $CFG_GLPI["root_doc"] . "/ajax/solution.php", 'moreparams' => array('type_id' => 'dropdown_ticketsolutiontypes_id' . $rand_type))));
         echo "</td><td colspan='2'>";
         echo "<a title\"" . $LANG['job'][23] . "\"\n                  href='" . $CFG_GLPI['root_doc'] . "/front/knowbaseitem.php?tickets_id=" . $this->getField('id') . "'>" . $LANG['job'][23] . "</a>";
         echo "</td></tr>";
     }
     echo "<tr class='tab_bg_2'>";
     echo "<td>" . $LANG['job'][48] . "&nbsp;:&nbsp;</td><td>";
     $current = $this->fields['status'];
     // Settings a solution will set status to solved
     if ($canedit) {
         Dropdown::show('TicketSolutionType', array('value' => $this->getField('ticketsolutiontypes_id'), 'rand' => $rand_type));
     } else {
         echo Dropdown::getDropdownName('glpi_ticketsolutiontypes', $this->getField('ticketsolutiontypes_id'));
     }
     echo "</td><td>" . $LANG['job'][25] . "</td><td>";
     Dropdown::showYesNo('_sol_to_kb', false);
     echo "</td></tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td>" . $LANG['joblist'][6] . "&nbsp;: </td><td colspan='3'>";
     if ($canedit) {
         initEditorSystem("solution");
         echo "<div id='solution{$rand_text}'>";
         echo "<textarea id='solution' name='solution' rows='12' cols='80'>";
         echo $this->getField('solution');
         echo "</textarea></div>";
     } else {
         echo unclean_cross_side_scripting_deep($this->getField('solution'));
     }
     echo "</td></tr>";
     $options['candel'] = false;
     $options['canedit'] = $canedit;
     $this->showFormButtons($options);
 }
 /**
  * Get a KB/FAQ article
  * for an authenticated user (or anonymous if allowed from config)
  *
  * @param $params array of options
  * @param $protocol the commonication protocol used
  **/
 static function methodGetKnowBaseItem($params, $protocol)
 {
     global $DB, $CFG_GLPI;
     if (isset($params['help'])) {
         return array('id' => 'integer,mandatory', 'help' => 'bool,optional');
     }
     $kb = new KnowbaseItem();
     if (!isset($params['id'])) {
         return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'id');
     }
     if (!is_numeric($params['id'])) {
         return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'id');
     }
     if (!$kb->can($params['id'], 'r')) {
         return self::Error($protocol, WEBSERVICES_ERROR_NOTFOUND);
     }
     $answer = Toolbox::unclean_cross_side_scripting_deep($kb->getField('answer'));
     $resp = $kb->fields;
     $resp['answer'] = $answer;
     $resp['answer_text'] = html_entity_decode(Html::clean($answer), 0, 'UTF-8');
     $resp['documents'] = self::getDocForItem($kb);
     $kb->updateCounter();
     return $resp;
 }