function showForm($ID, $options = array())
{
global $CFG_GLPI;
// show kb item form
if (!Session::haveRightsOr(self::$rightname, array(UPDATE, self::PUBLISHFAQ, self::KNOWBASEADMIN))) {
return false;
}
$this->initForm($ID, $options);
$canedit = $this->can($ID, UPDATE);
// Load ticket solution
if (empty($ID) && isset($options['item_itemtype']) && !empty($options['item_itemtype']) && isset($options['item_items_id']) && !empty($options['item_items_id'])) {
if ($item = getItemForItemtype($options['item_itemtype'])) {
if ($item->getFromDB($options['item_items_id'])) {
$this->fields['name'] = $item->getField('name');
$this->fields['answer'] = $item->getField('solution');
if ($item->isField('itilcategories_id')) {
$ic = new ItilCategory();
if ($ic->getFromDB($item->getField('itilcategories_id'))) {
$this->fields['knowbaseitemcategories_id'] = $ic->getField('knowbaseitemcategories_id');
}
}
}
}
}
$rand = mt_rand();
Html::initEditorSystem('answer');
$this->initForm($ID, $options);
$this->showFormHeader($options);
echo "<tr class='tab_bg_1'>";
echo "<td>" . __('Category name') . "</td>";
echo "<td>";
echo "<input type='hidden' name='users_id' value=\"" . Session::getLoginUserID() . "\">";
KnowbaseItemCategory::dropdown(array('value' => $this->fields["knowbaseitemcategories_id"]));
echo "</td>";
echo "<td>";
if ($this->fields["date"]) {
//TRANS: %s is the datetime of insertion
printf(__('Created on %s'), Html::convDateTime($this->fields["date"]));
}
echo "</td><td>";
if ($this->fields["date_mod"]) {
//TRANS: %s is the datetime of update
printf(__('Last update on %s'), Html::convDateTime($this->fields["date_mod"]));
}
echo "</td>";
echo "</tr>\n";
echo "<tr class='tab_bg_1'>";
if (Session::haveRight(self::$rightname, self::PUBLISHFAQ)) {
echo "<td>" . __('Put this item in the FAQ') . "</td>";
echo "<td>";
Dropdown::showYesNo('is_faq', $this->fields["is_faq"]);
echo "</td>";
} else {
echo "<td colspan='2'>";
if ($this->fields["is_faq"]) {
_e('This item is part of the FAQ');
} else {
_e('This item is not part of the FAQ');
}
echo "</td>";
}
echo "<td>";
$showuserlink = 0;
if (Session::haveRight('user', READ)) {
$showuserlink = 1;
}
if ($this->fields["users_id"]) {
//TRANS: %s is the writer name
printf(__('%1$s: %2$s'), __('Writer'), getUserName($this->fields["users_id"], $showuserlink));
}
echo "</td><td>";
//TRANS: %d is the number of view
if ($ID) {
printf(_n('%d view', '%d views', $this->fields["view"]), $this->fields["view"]);
}
echo "</td>";
echo "</tr>\n";
echo "<tr class='tab_bg_1'>";
echo "<td>" . __('Visible since') . "</td><td>";
Html::showDateTimeField("begin_date", array('value' => $this->fields["begin_date"], 'timestep' => 1, 'maybeempty' => true, 'canedit' => $canedit));
echo "</td>";
echo "<td>" . __('Visible until') . "</td><td>";
Html::showDateTimeField("end_date", array('value' => $this->fields["end_date"], 'timestep' => 1, 'maybeempty' => true, 'canedit' => $canedit));
echo "</td></tr>";
echo "<tr class='tab_bg_1'>";
echo "<td>" . __('Subject') . "</td>";
echo "<td colspan='3'>";
echo "<textarea cols='100' rows='1' name='name'>" . $this->fields["name"] . "</textarea>";
echo "</td>";
echo "</tr>\n";
echo "<tr class='tab_bg_1'>";
echo "<td>" . __('Content') . "</td>";
echo "<td colspan='3'>";
$cols = 100;
$rows = 30;
if (isset($options['_in_modal']) && $options['_in_modal']) {
$rows = 15;
echo Html::hidden('_in_modal', array('value' => 1));
}
echo "<textarea cols='{$cols}' rows='{$rows}' id='answer' name='answer'>" . $this->fields["answer"];
echo "</textarea>";
echo "</td>";
echo "</tr>\n";
if ($this->isNewID($ID)) {
echo "<tr class='tab_bg_1'>";
echo "<td>" . _n('Target', 'Targets', 1) . "</td>";
echo "<td>";
$types = array('Entity', 'Group', 'Profile', 'User');
$addrand = Dropdown::showItemTypes('_visibility[_type]', $types);
echo "</td><td colspan='2'>";
$params = array('type' => '__VALUE__', 'right' => 'knowbase', 'prefix' => '_visibility', 'nobutton' => 1);
Ajax::updateItemOnSelectEvent("dropdown__visibility__type_" . $addrand, "visibility{$rand}", $CFG_GLPI["root_doc"] . "/ajax/visibility.php", $params);
echo "<span id='visibility{$rand}'></span>";
echo "</td></tr>\n";
}
$this->showFormButtons($options);
return true;
}