Exemplo n.º 1
0
 /**
  * Print out an HTML "<form>" for knowbase item
  *
  * @param $ID
  * @param $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;
 }
Exemplo n.º 2
0
    Html::header_nocache();
} else {
    if (!defined('GLPI_ROOT')) {
        die("Sorry. You can't access this file directly");
    }
}
$opt = array('entity' => $_POST["entity_restrict"]);
if ($_SESSION["glpiactiveprofile"]["interface"] == "helpdesk") {
    $opt['condition'] = "`is_helpdeskvisible`='1' AND ";
} else {
    $opt['condition'] = '';
}
$currentcateg = new ItilCategory();
$currentcateg->getFromDB($_POST['value']);
if ($_POST["type"]) {
    switch ($_POST['type']) {
        case Ticket::INCIDENT_TYPE:
            $opt['condition'] .= " `is_incident`='1'";
            if ($currentcateg->getField('is_incident') == 1) {
                $opt['value'] = $_POST['value'];
            }
            break;
        case Ticket::DEMAND_TYPE:
            $opt['condition'] .= " `is_request`='1'";
            if ($currentcateg->getField('is_request') == 1) {
                $opt['value'] = $_POST['value'];
            }
            break;
    }
}
ItilCategory::dropdown($opt);
Exemplo n.º 3
0
 /**
  * Print out an HTML "<form>" for knowbase item
  *
  * @param $ID
  * @param $options array
  *     - target for the Form
  *
  * @return nothing (display the form)
  **/
 function showForm($ID, $options = array())
 {
     // show kb item form
     if (!Session::haveRight("knowbase", "w") && !Session::haveRight("faq", "w")) {
         return false;
     }
     $this->initForm($ID, $options);
     $canedit = $this->can($ID, 'w');
     $canrecu = $this->can($ID, 'recursive');
     if ($canedit) {
         // 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');
                         }
                     }
                 }
             }
         }
         echo "<div id='contenukb'>";
         Html::initEditorSystem('answer');
         echo "<form method='post' id='form_kb' name='form_kb' action=\"" . $this->getFormUrl() . "\">";
         if (!empty($ID)) {
             echo "<input type='hidden' name='id' value='{$ID}'>\n";
         }
         echo "<fieldset>";
         echo "<legend>" . __('Category name') . "</legend>";
         echo "<div class='center'>" . __('Select a category for this item') . "&nbsp;";
         KnowbaseItemCategory::dropdown(array('value' => $this->fields["knowbaseitemcategories_id"]));
         echo "</div></fieldset>";
         echo "<fieldset>";
         echo "<legend>" . __('Subject') . "</legend>";
         echo "<div class='center'>";
         echo "<textarea cols='80' rows='2' name='name'>" . $this->fields["name"] . "</textarea>";
         echo "</div></fieldset>";
         echo "<fieldset>";
         echo "<legend>" . __('Content') . "</legend>";
         echo "<div class='center spaced'>";
         echo "<textarea cols='80' rows='30' id='answer' name='answer'>" . $this->fields["answer"];
         echo "</textarea></div></fieldset>";
         if (!empty($ID)) {
             echo "<fieldset>";
             echo "<legend></legend>";
             echo "<div class='baskb'>";
             if ($this->fields["users_id"]) {
                 //TRANS: %s is the writer name
                 printf(__('%1$s: %2$s'), __('Writer'), getUserName($this->fields["users_id"], "1"));
             }
             echo "<span class='baskb_right'>";
             if ($this->fields["date_mod"]) {
                 //TRANS: %s is the datetime of update
                 printf(__('Last update on %s'), Html::convDateTime($this->fields["date_mod"]));
             }
             echo "</span><br>";
             if ($this->fields["date"]) {
                 //TRANS: %s is the datetime of insertion
                 printf(__('Created on %s'), Html::convDateTime($this->fields["date"]));
             }
             echo "<span class='baskb_right'>";
             //TRANS: %d is the number of view
             printf(_n('%d view', '%d views', $this->fields["view"]), $this->fields["view"]);
             echo "</span></div>";
             echo "</fieldset>";
         }
         echo "<p class='center'>";
         //          if (Session::isMultiEntitiesMode()) {
         //             _e('Entity');
         //             Entity::dropdown(array('value'    => $this->fields["entities_id"],
         //                                    'comments' => 0 ));
         //             _e('Child entities: ');
         //             if ($canrecu) {
         //                Dropdown::showYesNo("is_recursive", $this->fields["is_recursive"]);
         //             } else {
         //                echo Dropdown::getYesNo($this->fields["is_recursive"]);
         //             }
         //          }
         //          echo "<br><br>" .
         echo __('Put this item in the FAQ') . "&nbsp;";
         if (Session::haveRight("faq", "w") && Session::haveRight("knowbase", "w")) {
             Dropdown::showYesNo('is_faq', $this->fields["is_faq"]);
         } else {
             echo Dropdown::getYesNo($this->fields["is_faq"]);
         }
         echo "<br><br>";
         if ($ID > 0) {
             echo "<input type='submit' class='submit' name='update' value=\"" . _sx('button', 'Save') . "\">";
         } else {
             echo "<input type='hidden' name='users_id' value=\"" . Session::getLoginUserID() . "\">";
             echo "<input type='submit' class='submit' name='add' value=\"" . _sx('button', 'Add') . "\">";
         }
         echo "<span class='big_space'>";
         echo "<input type='reset' class='submit' value=\"" . _sx('button', 'Blank') . "\"></span>";
         echo "</p>";
         Html::closeForm();
         echo "</div>";
         return true;
     }
     //  ELSE Cannot edit
     return false;
 }