/**
  * Display all translated field for an KnowbaseItem
  *
  * @param $item a KnowbaseItem item
  *
  * @return true;
  **/
 static function showTranslations(KnowbaseItem $item)
 {
     global $DB, $CFG_GLPI;
     $canedit = $item->can($item->getID(), UPDATE);
     $rand = mt_rand();
     if ($canedit) {
         echo "<div id='viewtranslation" . $item->getID() . "{$rand}'></div>\n";
         echo "<script type='text/javascript' >\n";
         echo "function addTranslation" . $item->getID() . "{$rand}() {\n";
         $params = array('type' => __CLASS__, 'parenttype' => get_class($item), 'knowbaseitems_id' => $item->fields['id'], 'id' => -1);
         Ajax::updateItemJsCode("viewtranslation" . $item->getID() . "{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params);
         echo "};";
         echo "</script>\n";
         echo "<div class='center'>" . "<a class='vsubmit' href='javascript:addTranslation" . $item->getID() . "{$rand}();'>" . __('Add a new translation') . "</a></div><br>";
     }
     $obj = new self();
     $found = $obj->find("`knowbaseitems_id`='" . $item->getID() . "'", "`language` ASC");
     if (count($found) > 0) {
         if ($canedit) {
             Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
             $massiveactionparams = array('container' => 'mass' . __CLASS__ . $rand);
             Html::showMassiveActions($massiveactionparams);
         }
         echo "<div class='center'>";
         echo "<table class='tab_cadre_fixehov'><tr class='tab_bg_2'>";
         echo "<th colspan='4'>" . __("List of translations") . "</th></tr>";
         if ($canedit) {
             echo "<th width='10'>";
             Html::checkAllAsCheckbox('mass' . __CLASS__ . $rand);
             echo "</th>";
         }
         echo "<th>" . __("Language") . "</th>";
         echo "<th>" . __("Subject") . "</th>";
         foreach ($found as $data) {
             echo "<tr class='tab_bg_1' " . ($canedit ? "style='cursor:pointer'\n                     onClick=\"viewEditTranslation" . $data['id'] . "{$rand}();\"" : '') . ">";
             if ($canedit) {
                 echo "<td class='center'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["id"]);
                 echo "</td>";
             }
             echo "<td>";
             if ($canedit) {
                 echo "\n<script type='text/javascript' >\n";
                 echo "function viewEditTranslation" . $data["id"] . "{$rand}() {\n";
                 $params = array('type' => __CLASS__, 'parenttype' => get_class($item), 'knowbaseitems_id' => $item->getID(), 'id' => $data["id"]);
                 Ajax::updateItemJsCode("viewtranslation" . $item->getID() . "{$rand}", $CFG_GLPI["root_doc"] . "/ajax/viewsubitem.php", $params);
                 echo "};";
                 echo "</script>\n";
             }
             echo Dropdown::getLanguageName($data['language']);
             echo "</td><td>";
             echo $data["name"];
             if (isset($data['answer']) && !empty($data['answer'])) {
                 echo "&nbsp;";
                 Html::showToolTip(Toolbox::unclean_html_cross_side_scripting_deep($data['answer']));
             }
             echo "</td></tr>";
         }
         echo "</table>";
         if ($canedit) {
             $massiveactionparams['ontop'] = false;
             Html::showMassiveActions($massiveactionparams);
             Html::closeForm();
         }
     } else {
         echo "<table class='tab_cadre_fixe'><tr class='tab_bg_2'>";
         echo "<th class='b'>" . __("No translation found") . "</th></tr></table>";
     }
     return true;
 }
Esempio n. 2
0
 /**
  * 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;
 }
// Purpose of file:
// ----------------------------------------------------------------------
define('GLPI_ROOT', '..');
include GLPI_ROOT . "/inc/includes.php";
header("Content-Type: text/html; charset=UTF-8");
header_nocache();
if (!isset($_POST["id"])) {
    exit;
}
if (!isset($_REQUEST['glpi_tab'])) {
    exit;
}
if (empty($_POST["id"])) {
    $_POST["id"] = -1;
}
$kb = new KnowbaseItem();
if ($_POST['id'] > 0 && $kb->can($_POST['id'], 'r')) {
    switch ($_REQUEST['glpi_tab']) {
        case -1:
            $kb->showMenu();
            Document::showAssociated($kb);
            Plugin::displayAction($kb, $_REQUEST['glpi_tab']);
            break;
        default:
            if (!Plugin::displayAction($kb, $_REQUEST['glpi_tab'])) {
                $kb->showMenu();
                Document::showAssociated($kb);
            }
    }
}
ajaxFooter();