KnowbaseItem::showForm PHP Method

showForm() public method

Print out an HTML "
" for knowbase item
public showForm ( $ID, $options = [] ) : nothing
$ID
$options array - target for the Form
return nothing (display the form)
    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;
    }

Usage Example

Ejemplo n.º 1
0
             $item->add($_POST);
             Event::log($_POST["knowbaseitems_id"], "knowbaseitem", 4, "tools", sprintf(__('%s adds a target'), $_SESSION["glpiname"]));
         }
     }
     Html::back();
 } else {
     if (isset($_GET["id"])) {
         if (isset($_GET["_in_modal"])) {
             Html::popHeader(__('Knowledge base'), $_SERVER['PHP_SELF']);
             $kb = new KnowbaseItem();
             if ($_GET['id']) {
                 $kb->check($_GET["id"], READ);
                 $kb->showFull();
             } else {
                 // New item
                 $kb->showForm($_GET["id"], $_GET);
             }
             Html::popFooter();
         } else {
             // modifier un item dans la base de connaissance
             $kb->check($_GET["id"], READ);
             if (Session::getLoginUserID()) {
                 if ($_SESSION["glpiactiveprofile"]["interface"] == "central") {
                     Html::header(KnowbaseItem::getTypeName(1), $_SERVER['PHP_SELF'], "tools", "knowbaseitem");
                 } else {
                     Html::helpHeader(__('FAQ'), $_SERVER['PHP_SELF']);
                 }
                 Html::helpHeader(__('FAQ'), $_SERVER['PHP_SELF'], $_SESSION["glpiname"]);
             } else {
                 $_SESSION["glpilanguage"] = $CFG_GLPI['language'];
                 // Anonymous FAQ
All Usage Examples Of KnowbaseItem::showForm