/**
  * Print the HTML array of suppliers for this contract
  *
  * @since version 0.84
  *
  * @param $contract Contract object
  *
  * @return Nothing (HTML display)
  **/
 static function showForContract(Contract $contract)
 {
     global $DB, $CFG_GLPI;
     $instID = $contract->fields['id'];
     if (!$contract->can($instID, 'r') || !Session::haveRight("contact_enterprise", "r")) {
         return false;
     }
     $canedit = $contract->can($instID, 'w');
     $rand = mt_rand();
     $query = "SELECT `glpi_contracts_suppliers`.`id`,\n                       `glpi_suppliers`.`id` AS entID,\n                       `glpi_suppliers`.`name` AS name,\n                       `glpi_suppliers`.`website` AS website,\n                       `glpi_suppliers`.`phonenumber` AS phone,\n                       `glpi_suppliers`.`suppliertypes_id` AS type,\n                       `glpi_entities`.`id` AS entity\n                FROM `glpi_contracts_suppliers`,\n                     `glpi_suppliers`\n                LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id`=`glpi_suppliers`.`entities_id`)\n                WHERE `glpi_contracts_suppliers`.`contracts_id` = '{$instID}'\n                      AND `glpi_contracts_suppliers`.`suppliers_id`=`glpi_suppliers`.`id`" . getEntitiesRestrictRequest(" AND", "glpi_suppliers", '', '', true) . "\n                ORDER BY `glpi_entities`.`completename`, `name`";
     $result = $DB->query($query);
     $suppliers = array();
     $used = array();
     if ($number = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $suppliers[$data['id']] = $data;
             $used[$data['entID']] = $data['entID'];
         }
     }
     if ($canedit) {
         echo "<div class='firstbloc'>";
         echo "<form name='contractsupplier_form{$rand}' id='contractsupplier_form{$rand}' method='post'\n                action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
         echo "<input type='hidden' name='contracts_id' value='{$instID}'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2'><th colspan='2'>" . __('Add a supplier') . "</th></tr>";
         echo "<tr class='tab_bg_1'><td class='right'>";
         Supplier::dropdown(array('used' => $used, 'entity' => $contract->fields["entities_id"], 'entity_sons' => $contract->fields["is_recursive"]));
         echo "</td><td class='center'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $number) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('num_displayed' => $number);
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
     }
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr>";
     if ($canedit && $number) {
         echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     }
     echo "<th>" . __('Supplier') . "</th>";
     echo "<th>" . __('Entity') . "</th>";
     echo "<th>" . __('Third party type') . "</th>";
     echo "<th>" . __('Phone') . "</th>";
     echo "<th>" . __('Website') . "</th>";
     echo "</tr>";
     $used = array();
     foreach ($suppliers as $data) {
         $ID = $data['id'];
         $website = $data['website'];
         if (!empty($website)) {
             if (!preg_match("?https*://?", $website)) {
                 $website = "http://" . $website;
             }
             $website = "<a target=_blank href='{$website}'>" . $data['website'] . "</a>";
         }
         $entID = $data['entID'];
         $entity = $data['entity'];
         $used[$entID] = $entID;
         $entname = Dropdown::getDropdownName("glpi_suppliers", $entID);
         echo "<tr class='tab_bg_1'>";
         if ($canedit) {
             echo "<td>";
             Html::showMassiveActionCheckBox(__CLASS__, $data["id"]);
             echo "</td>";
         }
         echo "<td class='center'>";
         if ($_SESSION["glpiis_ids_visible"] || empty($entname)) {
             $entname = sprintf(__('%1$s (%2$s)'), $entname, $entID);
         }
         echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/supplier.form.php?id={$entID}'>" . $entname;
         echo "</a></td>";
         echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $entity) . "</td>";
         echo "<td class='center'>";
         echo Dropdown::getDropdownName("glpi_suppliertypes", $data['type']) . "</td>";
         echo "<td class='center'>" . $data['phone'] . "</td>";
         echo "<td class='center'>" . $website . "</td>";
         echo "</tr>";
     }
     echo "</table>";
     if ($canedit && $number) {
         $paramsma['ontop'] = false;
         Html::showMassiveActions(__CLASS__, $paramsma);
         Html::closeForm();
     }
     echo "</div>";
 }
Beispiel #2
0
 /**
  * Show Infocom form for an item (not a standard showForm)
  *
  * @param $item                  CommonDBTM object
  * @param $withtemplate integer  template or basic item (default '')
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $CFG_GLPI;
     // Show Infocom or blank form
     if (!Session::haveRight("infocom", "r")) {
         return false;
     }
     if (!$item) {
         echo "<div class='spaced'>" . __('Requested item not found') . "</div>";
     } else {
         $date_tax = $CFG_GLPI["date_tax"];
         $dev_ID = $item->getField('id');
         $ic = new self();
         $option = "";
         if ($withtemplate == 2) {
             $option = " readonly ";
         }
         if (!strpos($_SERVER['PHP_SELF'], "infocoms-show") && in_array($item->getType(), array('CartridgeItem', 'ConsumableItem', 'Software'))) {
             echo "<div class='firstbloc center'>" . __('For this type of item, the financial and administrative information are only a model for the items which you should add.') . "</div>";
         }
         if (!$ic->getFromDBforDevice($item->getType(), $dev_ID)) {
             $input = array('itemtype' => $item->getType(), 'items_id' => $dev_ID, 'entities_id' => $item->getEntityID());
             if ($ic->can(-1, "w", $input) && $withtemplate != 2) {
                 echo "<div class='spaced b'>";
                 echo "<table class='tab_cadre_fixe'><tr class='tab_bg_1'><th>";
                 echo sprintf(__('%1$s - %2$s'), $item->getTypeName(1), $item->getName()) . "</th></tr>";
                 echo "<tr class='tab_bg_1'><td class='center'>";
                 Html::showSimpleForm($CFG_GLPI["root_doc"] . "/front/infocom.form.php", 'add', __('Enable the financial and administrative information'), array('itemtype' => $item->getType(), 'items_id' => $dev_ID));
                 echo "</td></tr></table></div>";
             }
         } else {
             // getFromDBforDevice
             $canedit = $ic->can($ic->fields['id'], "w") && $withtemplate != 2;
             if ($canedit) {
                 echo "<form name='form_ic' method='post' action='" . $CFG_GLPI["root_doc"] . "/front/infocom.form.php'>";
             }
             echo "<div class='spaced'>";
             echo "<table class='tab_cadre" . (!strpos($_SERVER['PHP_SELF'], "infocoms-show") ? "_fixe" : "") . "'>";
             echo "<tr><th colspan='4'>" . __('Financial and administrative information') . "</th></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Supplier') . "</td>";
             echo "<td>";
             if ($withtemplate == 2) {
                 echo Dropdown::getDropdownName("glpi_suppliers", $ic->fields["suppliers_id"]);
             } else {
                 Supplier::dropdown(array('value' => $ic->fields["suppliers_id"], 'entity' => $item->getEntityID()));
             }
             echo "</td>";
             if (Session::haveRight("budget", "r")) {
                 echo "<td>" . __('Budget') . "</td><td >";
                 Budget::dropdown(array('value' => $ic->fields["budgets_id"], 'entity' => $item->getEntityID(), 'comments' => 1));
             } else {
                 echo "<td colspan='2'>";
             }
             echo "</td></tr>";
             // Can edit calendar ?
             $editcalendar = $withtemplate != 2;
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Order number') . "</td>";
             echo "<td >";
             Html::autocompletionTextField($ic, "order_number", array('option' => $option));
             echo "</td>";
             echo "<td>" . __('Order date') . "</td><td>";
             Html::showDateFormItem("order_date", $ic->fields["order_date"], true, $editcalendar);
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             $istemplate = '';
             if ($item->isTemplate() || in_array($item->getType(), array('CartridgeItem', 'ConsumableItem', 'Software'))) {
                 $istemplate = '*';
             }
             echo "<td>" . sprintf(__('%1$s%2$s'), __('Immobilization number'), $istemplate) . "</td>";
             echo "<td>";
             $objectName = autoName($ic->fields["immo_number"], "immo_number", $withtemplate == 2, 'Infocom', $item->getEntityID());
             Html::autocompletionTextField($ic, "immo_number", array('value' => $objectName, 'option' => $option));
             echo "</td>";
             echo "<td>" . __('Date of purchase') . "</td><td>";
             Html::showDateFormItem("buy_date", $ic->fields["buy_date"], true, $editcalendar);
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Invoice number') . "</td>";
             echo "<td>";
             Html::autocompletionTextField($ic, "bill", array('option' => $option));
             echo "</td>";
             echo "<td>" . __('Delivery date') . "</td><td>";
             Html::showDateFormItem("delivery_date", $ic->fields["delivery_date"], true, $editcalendar);
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Delivery form') . "</td><td>";
             Html::autocompletionTextField($ic, "delivery_number", array('option' => $option));
             echo "</td>";
             echo "<td>" . __('Startup date') . "</td><td>";
             Html::showDateFormItem("use_date", $ic->fields["use_date"], true, $editcalendar);
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Value') . "</td>";
             echo "<td><input type='text' name='value' {$option} value='" . Html::formatNumber($ic->fields["value"], true) . "' size='14'></td>";
             echo "</td>";
             echo "<td>" . __('Date of last physical inventory') . "</td><td>";
             Html::showDateFormItem("inventory_date", $ic->fields["inventory_date"], true, $editcalendar);
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Warranty extension value') . "</td>";
             echo "<td><input type='text' {$option} name='warranty_value' value='" . Html::formatNumber($ic->fields["warranty_value"], true) . "' size='14'></td>";
             echo "<td rowspan='5'>" . __('Comments') . "</td>";
             echo "<td rowspan='5' class='middle'>";
             echo "<textarea cols='45' rows='9' name='comment' >" . $ic->fields["comment"];
             echo "</textarea></td></tr>\n";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Account net value') . "</td><td>";
             echo Html::formatNumber(self::Amort($ic->fields["sink_type"], $ic->fields["value"], $ic->fields["sink_time"], $ic->fields["sink_coeff"], $ic->fields["warranty_date"], $ic->fields["use_date"], $date_tax, "n"));
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Amortization type') . "</td><td >";
             if ($withtemplate == 2) {
                 echo self::getAmortTypeName($ic->fields["sink_type"]);
             } else {
                 self::dropdownAmortType("sink_type", $ic->fields["sink_type"]);
             }
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Amortization duration') . "</td><td>";
             if ($withtemplate == 2) {
                 printf(_n('%d year', '%d years', $ic->fields["sink_time"]), $ic->fields["sink_time"]);
             } else {
                 Dropdown::showNumber("sink_time", array('value' => $ic->fields["sink_time"], 'max' => 15, 'unit' => 'year'));
             }
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Amortization coefficient') . "</td>";
             echo "<td>";
             Html::autocompletionTextField($ic, "sink_coeff", array('size' => 14, 'option' => $option));
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             if (!in_array($item->getType(), array('Cartridge', 'CartridgeItem', 'Consumable', 'ConsumableItem', 'Software', 'SoftwareLicense'))) {
                 echo "<td>" . __('TCO (value + tracking cost)') . "</td><td>";
                 echo self::showTco($item->getField('ticket_tco'), $ic->fields["value"]);
             } else {
                 echo "<td colspan='2'>";
             }
             echo "</td>";
             if (!in_array($item->getType(), array('Cartridge', 'CartridgeItem', 'Consumable', 'ConsumableItem', 'Software', 'SoftwareLicense'))) {
                 echo "<td>" . __('Monthly TCO') . "</td><td>";
                 echo self::showTco($item->getField('ticket_tco'), $ic->fields["value"], $ic->fields["warranty_date"]);
             } else {
                 echo "<td colspan='2'>";
             }
             echo "</td></tr>";
             echo "<tr><th colspan='4'>" . __('Warranty information') . "</th></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Start date of warranty') . "</td><td>";
             Html::showDateFormItem("warranty_date", $ic->fields["warranty_date"], true, $editcalendar);
             echo "</td>";
             echo "<td>" . __('Warranty duration') . "</td><td>";
             if ($withtemplate == 2) {
                 // -1 = life
                 if ($ic->fields["warranty_duration"] == -1) {
                     _e('Lifelong');
                 } else {
                     printf(_n('%d month', '%d months', $ic->fields["warranty_duration"]), $ic->fields["warranty_duration"]);
                 }
             } else {
                 Dropdown::showInteger("warranty_duration", $ic->fields["warranty_duration"], 0, 120, 1, array(-1 => __('Lifelong')), array('unit' => 'month'));
             }
             $tmpdat = self::getWarrantyExpir($ic->fields["warranty_date"], $ic->fields["warranty_duration"], 0, true);
             if ($tmpdat) {
                 echo "<span class='small_space'>" . sprintf(__('Valid to %s'), $tmpdat) . "</span>";
             }
             echo "</td></tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Warranty information') . "</td>";
             echo "<td >";
             Html::autocompletionTextField($ic, "warranty_info", array('option' => $option));
             echo "</td>";
             if ($CFG_GLPI['use_mailing']) {
                 echo "<td>" . __('Alarms on financial and administrative information') . "</td>";
                 echo "<td>";
                 self::dropdownAlert(array('name' => "alert", 'value' => $ic->fields["alert"]));
                 Alert::displayLastAlert('Infocom', $ic->fields['id']);
                 echo "</td>";
             } else {
                 echo "</td><td colspan='2'>";
             }
             echo "</td></tr>";
             if ($canedit) {
                 echo "<tr>";
                 echo "<td class='tab_bg_2 center' colspan='2'>";
                 echo "<input type='hidden' name='id' value='" . $ic->fields['id'] . "'>";
                 echo "<input type='submit' name='update' value=\"" . _sx('button', 'Save') . "\"\n                      class='submit'>";
                 echo "</td>";
                 echo "<td class='tab_bg_2 center' colspan='2'>";
                 echo "<input type='submit' name='delete' value=\"" . _sx('button', 'Delete permanently') . "\"\n                      class='submit'>";
                 echo "</td></tr>";
                 echo "</table></div>";
                 Html::closeForm();
             } else {
                 echo "</table></div>";
             }
         }
     }
 }
 /**
  * show supplier add div on creation
  *
  * @param $options   array    options for default values ($options of showForm)
  *
  * @return nothing display
  **/
 function showSupplierAddFormOnCreate(array $options)
 {
     global $CFG_GLPI;
     $itemtype = $this->getType();
     echo self::getActorIcon('supplier', 'assign');
     // For ticket templates : mandatories
     if ($itemtype == 'Ticket' && isset($options['_tickettemplate'])) {
         echo $options['_tickettemplate']->getMandatoryMark("_suppliers_id_assign");
     }
     echo "&nbsp;";
     $rand = mt_rand();
     $params = array('name' => '_suppliers_id_assign', 'value' => $options["_suppliers_id_assign"], 'rand' => $rand);
     if ($CFG_GLPI['use_mailing']) {
         $paramscomment = array('value' => '__VALUE__', 'field' => "_suppliers_id_assign_notif", 'allow_email' => true, 'typefield' => 'supplier', 'use_notification' => $options["_suppliers_id_assign_notif"]['use_notification']);
         if (isset($options["_suppliers_id_assign_notif"]['alternative_email'])) {
             $paramscomment['alternative_email'] = $options["_suppliers_id_assign_notif"]['alternative_email'];
         }
         $params['toupdate'] = array('value_fieldname' => 'value', 'to_update' => "notif_assign_{$rand}", 'url' => $CFG_GLPI["root_doc"] . "/ajax/uemailUpdate.php", 'moreparams' => $paramscomment);
     }
     if ($itemtype == 'Ticket') {
         $toupdate = array();
         if (isset($params['toupdate']) && is_array($params['toupdate'])) {
             $toupdate[] = $params['toupdate'];
         }
         $toupdate[] = array('value_fieldname' => 'value', 'to_update' => "countassign_{$rand}", 'url' => $CFG_GLPI["root_doc"] . "/ajax/ticketassigninformation.php", 'moreparams' => array('suppliers_id_assign' => '__VALUE__'));
         $params['toupdate'] = $toupdate;
     }
     Supplier::dropdown($params);
     if ($itemtype == 'Ticket') {
         // Display active tickets for a tech
         // Need to update information on dropdown changes
         echo "<span id='countassign_{$rand}'>";
         echo "</span>";
         echo "<script type='text/javascript'>";
         Ajax::updateItemJsCode("countassign_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/ticketassigninformation.php", array('suppliers_id_assign' => '__VALUE__'), "dropdown__suppliers_id_assign" . $rand);
         echo "</script>";
     }
     if ($CFG_GLPI['use_mailing']) {
         echo "<div id='notif_assign_{$rand}'>";
         echo "</div>";
         echo "<script type='text/javascript'>";
         Ajax::updateItemJsCode("notif_assign_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/uemailUpdate.php", $paramscomment, "dropdown__suppliers_id_assign" . $rand);
         echo "</script>";
     }
 }
 if ($CFG_GLPI["use_mailing"]) {
     $withemail = isset($_POST["allow_email"]) ? $_POST["allow_email"] : false;
     $paramscomment = array('value' => '__VALUE__', 'allow_email' => $withemail, 'field' => '_itil_' . $_POST["actortype"], 'typefield' => "supplier", 'use_notification' => $_POST["use_notif"]);
     // Fix rand value
     $options['rand'] = $rand;
     $options['toupdate'] = array('value_fieldname' => 'value', 'to_update' => "notif_supplier_{$rand}", 'url' => $CFG_GLPI["root_doc"] . "/ajax/uemailUpdate.php", 'moreparams' => $paramscomment);
 }
 if ($_POST["itemtype"] == 'Ticket') {
     $toupdate = array();
     if (isset($options['toupdate']) && is_array($options['toupdate'])) {
         $toupdate[] = $options['toupdate'];
     }
     $toupdate[] = array('value_fieldname' => 'value', 'to_update' => "countassign_{$rand}", 'url' => $CFG_GLPI["root_doc"] . "/ajax/ticketassigninformation.php", 'moreparams' => array('suppliers_id_assign' => '__VALUE__'));
     $options['toupdate'] = $toupdate;
 }
 $rand = Supplier::dropdown($options);
 // Display active tickets for a supplier
 // Need to update information on dropdown changes
 if ($_POST["itemtype"] == 'Ticket') {
     echo "<span id='countassign_{$rand}'>";
     echo "</span>";
 }
 if ($CFG_GLPI["use_mailing"]) {
     echo "<br><span id='notif_supplier_{$rand}'>";
     if ($withemail) {
         echo __('Email followup') . '&nbsp;';
         $rand = Dropdown::showYesNo('_itil_' . $_POST["actortype"] . '[use_notification]', $_POST['use_notif']);
         echo '<br>';
         printf(__('%1$s: %2$s'), __('Email'), "<input type='text' size='25' name='_itil_" . $_POST["actortype"] . "[alternative_email]'>");
     }
     echo "</span>";
Beispiel #5
0
 public function showForm($ID, $options = array())
 {
     global $CFG_GLPI, $DB;
     $this->initForm($ID, $options);
     $this->showFormHeader($options);
     $rand = mt_rand();
     $config = PluginOrderConfig::getConfig();
     $user = new User();
     if (isset($options['withtemplate']) && $options['withtemplate'] == 2) {
         $template = "newcomp";
         $datestring = sprintf(__('Created on %s'), Html::convDateTime($_SESSION["glpi_currenttime"]));
     } elseif (isset($options['withtemplate']) && $options['withtemplate'] == 1) {
         $template = "newtemplate";
         $datestring = sprintf(__('Created on %s'), Html::convDateTime($_SESSION["glpi_currenttime"]));
     } else {
         $template = false;
         $datestring = sprintf(__('Last update on %s'), Html::convDateTime($this->fields["date_mod"]));
     }
     $canedit = $this->canUpdateOrder() && $this->canUpdate() && !$this->isCanceled();
     $cancancel = self::canCancel() && $this->can($ID, UPDATE) && $this->isCanceled();
     $options['canedit'] = $canedit;
     $options['candel'] = $cancancel;
     if ($template) {
         $this->fields['order_date'] = NULL;
     }
     // Displaying OVER BUDGET ALERT
     if ($this->fields['budgets_id'] > 0) {
         self::displayAlertOverBudget(self::isOverBudget($ID));
     }
     //Display without inside table
     /* title */
     echo "<tr class='tab_bg_1'><td>" . __("Order name", "order") . "*: </td>";
     echo "<td>";
     if ($canedit) {
         $objectName = autoName($this->fields["name"], "name", $template === "newcomp", $this->getType(), $this->fields["entities_id"]);
         Html::autocompletionTextField($this, "name", array('value' => $objectName));
     } else {
         echo $this->fields["name"];
     }
     echo "</td>";
     /* date of order */
     echo "<td>" . __("Date of order", "order") . ":</td><td>";
     if ($canedit) {
         if ($this->fields["order_date"] == NULL) {
             Html::showDateFormItem("order_date", date("Y-m-d"), true, true);
         } else {
             Html::showDateFormItem("order_date", $this->fields["order_date"], true, true);
         }
     } else {
         echo Html::convDate($this->fields["order_date"]);
     }
     echo "</td></tr>";
     /* num order */
     echo "<tr class='tab_bg_1'><td>" . __("Order number", "order");
     if ($ID > 0) {
         echo "*";
     } else {
         echo " <span class='red'>*</span>";
     }
     echo ": </td>";
     echo "<td>";
     if ($canedit) {
         $objectOrder = autoName($this->fields["num_order"], "num_order", $template === "newcomp", $this->getType(), $this->fields["entities_id"]);
         Html::autocompletionTextField($this, "num_order", array('value' => $objectOrder));
     } else {
         echo $this->fields["num_order"];
     }
     echo "</td>";
     /* type order */
     echo "<td>" . __("Type") . ": </td><td>";
     if ($canedit) {
         PluginOrderOrderType::Dropdown(array('name' => "plugin_order_ordertypes_id", 'value' => $this->fields["plugin_order_ordertypes_id"]));
     } else {
         echo Dropdown::getDropdownName("glpi_plugin_order_ordertypes", $this->fields["plugin_order_ordertypes_id"]);
     }
     echo "</td></tr>";
     /* state */
     echo "<tr class='tab_bg_1'><td>" . __("Order status", "order") . ": </td>";
     echo "<td>";
     if (!$this->getID()) {
         $state = $config->getDraftState();
     } else {
         $state = $this->fields["plugin_order_orderstates_id"];
     }
     if ($canedit) {
         PluginOrderOrderState::Dropdown(array('name' => "plugin_order_orderstates_id", 'value' => $state));
     } else {
         echo Dropdown::getDropdownName("glpi_plugin_order_orderstates", $this->getState());
     }
     echo "</td>";
     /* budget */
     echo "<td>" . __("Budget") . ": </td>";
     echo "<td>";
     if ($canedit) {
         if ($config->canHideInactiveBudgets()) {
             $restrict = " (`end_date` IS NULL) OR (`end_date`> '" . date("Y-m-d") . "')";
         } else {
             $restrict = "";
         }
         Budget::Dropdown(array('name' => "budgets_id", 'value' => $this->fields["budgets_id"], 'entity' => $this->fields["entities_id"], 'comments' => true, 'condition' => $restrict, 'width' => '150px'));
     } else {
         $budget = new Budget();
         if ($this->fields["budgets_id"] > 0 && $budget->can($this->fields["budgets_id"], READ)) {
             echo $budget->getLink();
         } else {
             echo Dropdown::getDropdownName("glpi_budgets", $this->fields["budgets_id"]);
         }
     }
     echo "</td></tr>";
     /* location */
     echo "<tr class='tab_bg_1'><td>" . __("Delivery location", "order") . ": </td>";
     echo "<td>";
     if ($canedit) {
         Location::Dropdown(array('name' => "locations_id", 'value' => $this->fields["locations_id"], 'entity' => $this->fields["entities_id"]));
     } else {
         echo Dropdown::getDropdownName("glpi_locations", $this->fields["locations_id"]);
     }
     echo "</td>";
     /* payment */
     echo "<td>" . __("Payment conditions", "order") . ": </td><td>";
     if ($canedit) {
         PluginOrderOrderPayment::Dropdown(array('name' => "plugin_order_orderpayments_id", 'value' => $this->fields["plugin_order_orderpayments_id"]));
     } else {
         echo Dropdown::getDropdownName("glpi_plugin_order_orderpayments", $this->fields["plugin_order_orderpayments_id"]);
     }
     echo "</td>";
     echo "</tr>";
     /* supplier of order */
     echo "<tr class='tab_bg_1'><td>" . __("Supplier") . ": </td>";
     echo "<td>";
     if ($canedit && !$this->checkIfDetailExists($ID)) {
         $rand = mt_rand();
         Supplier::dropdown(array('name' => "suppliers_id", 'rand' => $rand, 'value' => $this->fields["suppliers_id"], 'entity' => $this->fields["entities_id"]));
         $params = array('suppliers_id' => '__VALUE__', 'fieldname' => 'contacts_id');
         Ajax::updateItemOnSelectEvent("dropdown_suppliers_id{$rand}", "show_contacts_id{$rand}", "../ajax/dropdownSupplier.php", $params);
     } else {
         $supplier = new Supplier();
         if ($supplier->can($this->fields['suppliers_id'], READ)) {
             echo $supplier->getLink();
         } else {
             echo Dropdown::getDropdownName("glpi_suppliers", $this->fields["suppliers_id"]);
         }
     }
     echo "</td>";
     /* port price */
     echo "<td>" . __("Postage", "order") . ": </td>";
     echo "<td>";
     if ($canedit) {
         echo "<input type='number' step='" . PLUGIN_ORDER_NUMBER_STEP . "' name='port_price' size='5'" . " value=\"" . Html::formatNumber($this->fields["port_price"], true) . "\">";
     } else {
         echo Html::formatNumber($this->fields["port_price"]);
     }
     echo "</td>";
     echo "</tr>";
     /* linked contact of the supplier of order */
     echo "<tr class='tab_bg_1'><td>" . __("Contact") . ": </td>";
     echo "<td><span id='show_contacts_id'>";
     if ($canedit) {
         echo "<span id='show_contacts_id{$rand}'>";
         // Make a select box
         $query = "SELECT c.`id`, c.`name`, c.`firstname`\n                   FROM `glpi_contacts` c\n                   LEFT JOIN `glpi_contacts_suppliers` s ON (s.`contacts_id` = c.`id`)\n                   WHERE s.`suppliers_id` = '{$this->fields['suppliers_id']}'\n                   ORDER BY c.`name`";
         $result = $DB->query($query);
         $number = $DB->numrows($result);
         $values = array(0 => Dropdown::EMPTY_VALUE);
         if ($number) {
             while ($data = $DB->fetch_assoc($result)) {
                 $values[$data['id']] = formatUserName('', '', $data['name'], $data['firstname']);
             }
         }
         Dropdown::showFromArray("contacts_id", $values, array('value' => $this->fields['contacts_id'], 'rand' => $rand));
         echo "</span>\n";
     } else {
         echo Dropdown::getDropdownName("glpi_contacts", $this->fields["contacts_id"]);
     }
     echo "</span></td>";
     /* tva port price */
     echo "<td>" . __("VAT", "order") . " " . __("Postage", "order") . ": </td><td>";
     $PluginOrderConfig = new PluginOrderConfig();
     $default_taxes = $PluginOrderConfig->getDefaultTaxes();
     $taxes = empty($ID) || $ID < 0 ? $default_taxes : $this->fields["plugin_order_ordertaxes_id"];
     if ($canedit) {
         PluginOrderOrderTax::Dropdown(array('name' => "plugin_order_ordertaxes_id", 'value' => $taxes, 'display_emptychoice' => true, 'emptylabel' => __("No VAT", "order")));
     } else {
         echo Dropdown::getDropdownName("glpi_plugin_order_ordertaxes", $taxes);
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __("Associable to a ticket") . "&nbsp;:</td><td>";
     if ($canedit) {
         Dropdown::showYesNo('is_helpdesk_visible', $this->fields['is_helpdesk_visible']);
     } else {
         echo Dropdown::getYesNo($this->fields['is_helpdesk_visible']);
     }
     echo "</td>";
     echo "<td>";
     echo __("Estimated due date", "order") . ":";
     if ($this->isDelivered() && $this->fields['deliverydate']) {
         echo "<br/>" . __("Delivery date") . ":";
     }
     echo " </td><td>";
     if ($canedit) {
         if ($this->fields["duedate"] == NULL) {
             Html::showDateFormItem("duedate", '', true, true);
         } else {
             Html::showDateFormItem("duedate", $this->fields["duedate"], true, true);
         }
     } else {
         echo Html::convDate($this->fields["duedate"]);
     }
     if ($this->shouldBeAlreadyDelivered()) {
         echo "<br/><span class='red'>" . __("Due date overtaken", "order") . "</span>";
     }
     if ($this->isDelivered() && $this->fields['deliverydate']) {
         echo "<br/>" . Html::convDate($this->fields['deliverydate']);
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td colspan='2' class='center'>" . $datestring;
     if (!$template && !empty($this->fields['template_name'])) {
         echo "<span class='small_space'>(" . __("Template name") . "&nbsp;: " . $this->fields['template_name'] . ")</span>";
     }
     echo "</td><td colspan='2'></td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     //comments of order
     echo "<td>" . __("Comments") . ":  </td>";
     echo "<td colspan='3' align='center'>";
     if ($canedit) {
         echo "<textarea cols='40' rows='3' name='comment'>" . $this->fields["comment"] . "</textarea>";
     } else {
         echo $this->fields["comment"];
     }
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th colspan='2'>" . __("Actor") . "</th>";
     if ($ID > 0 && !$template) {
         echo "<th colspan='2'>" . __("Cost") . "</th></tr>";
     } else {
         echo "<th colspan='2'></th>";
     }
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td colspan='2'>";
     echo "<table class='format'>";
     echo "<tr class='tab_bg_1'><td>" . __("Author") . ":</td><td style='width: 170px;'>";
     if ($canedit) {
         if ($template == 'newcomp') {
             $value = Session::getLoginUserID();
         } else {
             $value = $this->fields['users_id'];
         }
         User::Dropdown(array('name' => 'users_id', 'value' => $value, 'right' => 'interface', 'entity' => $this->fields["entities_id"], 'width' => '150px'));
     } else {
         if ($this->fields['users_id']) {
             $output = "";
             if ($user->getFromDB($this->fields['users_id'])) {
                 $output = formatUserName($this->fields['users_id'], $user->fields['name'], $user->fields['realname'], $user->fields['firstname']);
             }
             echo $output;
         }
     }
     echo "</td>";
     echo "<td>" . __("Author group", "order") . ":</td>";
     echo "<td style='width: 180px;'>";
     if ($canedit) {
         if (empty($ID) || $ID < 0) {
             if (!empty($this->fields['groups_id'])) {
                 $groups_id = $this->fields['groups_id'];
             } else {
                 $groups_id = $config->getDefaultAuthorGroup();
             }
         } else {
             $groups_id = $this->fields['groups_id'];
         }
         Group::Dropdown(array('value' => $groups_id, 'width' => '150px'));
     } else {
         echo Dropdown::getDropdownName('glpi_groups', $this->fields['groups_id']);
     }
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __("Recipient") . ":</td>";
     echo "<td style='width: 170px;'>";
     if ($canedit) {
         if (empty($ID) || $ID < 0) {
             if (!empty($this->fields['users_id_delivery'])) {
                 $users_id = $this->fields['users_id_delivery'];
             } else {
                 $users_id = $config->getDefaultRecipient();
             }
         } else {
             $users_id = $this->fields['users_id_delivery'];
         }
         User::Dropdown(array('name' => 'users_id_delivery', 'value' => $users_id, 'right' => 'all', 'entity' => $this->fields["entities_id"], 'width' => '150px'));
     } else {
         if ($this->fields['users_id_delivery']) {
             $user->getFromDB($this->fields['users_id_delivery']);
             $output = formatUserName($this->fields['users_id'], $user->fields['name'], $user->fields['realname'], $user->fields['firstname']);
             echo $output;
         }
     }
     echo "</td>";
     echo "<td>" . __("Recipient group", "order") . ":</td>";
     echo "<td style='width: 180px;'>";
     if ($canedit) {
         if (empty($ID) || $ID < 0) {
             if (!empty($this->fields['groups_id_delivery'])) {
                 $groups_id = $this->fields['groups_id_delivery'];
             } else {
                 $groups_id = $config->getDefaultRecipientGroup();
             }
         } else {
             $groups_id = $this->fields['groups_id_delivery'];
         }
         Group::Dropdown(array('name' => 'groups_id_delivery', 'value' => $groups_id, 'width' => '150px'));
     } else {
         echo Dropdown::getDropdownName('glpi_groups', $this->fields['groups_id_delivery']);
     }
     echo "</td>";
     echo "</tr></table></td>";
     echo "<td colspan='2'>";
     if ($ID > 0 && !$template) {
         $PluginOrderOrder_Item = new PluginOrderOrder_Item();
         $prices = $PluginOrderOrder_Item->getAllPrices($ID);
         echo "<table class='format'>";
         echo "<tr>";
         echo "<td>" . __("Price tax free", "order") . "</td>";
         echo "<td>" . Html::formatNumber($prices["priceHT"]) . "</td>";
         echo "</tr>";
         // total price (with postage)
         $postagewithTVA = $PluginOrderOrder_Item->getPricesATI($this->fields["port_price"], Dropdown::getDropdownName("glpi_plugin_order_ordertaxes", $this->fields["plugin_order_ordertaxes_id"]));
         $priceHTwithpostage = $prices["priceHT"] + $this->fields["port_price"];
         echo "<tr>";
         echo "<td>" . __("Price tax free with postage", "order") . "</td>";
         echo "<td>" . Html::formatNumber($priceHTwithpostage) . "</td>";
         echo "</tr>";
         // total price (with taxes)
         $total = $prices["priceTTC"] + $postagewithTVA;
         echo "<tr>";
         echo "<td>" . __("Price ATI", "order") . "</td>";
         echo "<td>" . Html::formatNumber($total) . "</td>";
         echo "</tr>";
         // total TVA
         $total_tva = $prices["priceTVA"] + ($postagewithTVA - $this->fields["port_price"]);
         echo "<tr>";
         echo "<td>" . __("VAT", "order") . "</td>";
         echo "<td>" . Html::formatNumber($total_tva) . "</td>";
         echo "</tr>";
         echo "</table>";
     }
     echo "</td>";
     echo "</tr>";
     if ($canedit || $cancancel) {
         $this->showFormButtons($options);
     } else {
         echo "</table></div>";
         Html::closeForm();
     }
     return true;
 }
Beispiel #6
0
                }
                if ($CFG_GLPI["use_mailing"] == 1) {
                    echo "<br><span id='notif_user_{$rand}'>";
                    if ($withemail) {
                        echo __('Email followup') . '&nbsp;';
                        $rand = Dropdown::showYesNo('_itil_' . $_POST["actortype"] . '[use_notification]', 1);
                        echo '<br>';
                        printf(__('%1$s: %2$s'), __('Email'), "<input type='text' size='25' name='_itil_" . $_POST["actortype"] . "[alternative_email]'>");
                    }
                    echo "</span>";
                }
                break;
            case "group":
                $cond = $_POST["actortype"] == 'assign' ? $cond = '`is_assign`' : ($cond = '`is_requester`');
                $param = array('name' => '_itil_' . $_POST["actortype"] . '[groups_id]', 'entity' => $_POST['entity_restrict'], 'condition' => $cond, 'rand' => $rand);
                if ($_POST["itemtype"] == 'Ticket' && $_POST["actortype"] == 'assign') {
                    $param['toupdate'] = array('value_fieldname' => 'value', 'to_update' => "countgroupassign_{$rand}", 'url' => $CFG_GLPI["root_doc"] . "/ajax/ticketassigninformation.php", 'moreparams' => array('groups_id_assign' => '__VALUE__'));
                }
                $rand = Group::dropdown($param);
                if ($_POST["itemtype"] == 'Ticket' && $_POST["actortype"] == 'assign') {
                    echo "<br><span id='countgroupassign_{$rand}'>";
                    echo "</span>";
                }
                break;
            case "supplier":
                $param = array('name' => '_itil_' . $_POST["actortype"] . '[suppliers_id]', 'entity' => $_POST['entity_restrict'], 'rand' => $rand);
                $rand = Supplier::dropdown($param);
                break;
        }
    }
}
 /**
  * show actor part in ITIL object form
  *
  * @param $ID        integer  ITIL object ID
  * @param $options   array    options for default values ($options of showForm)
  *
  * @return nothing display
  **/
 function showActorsPartForm($ID, array $options)
 {
     global $CFG_GLPI;
     $showuserlink = 0;
     if (Session::haveRight('user', 'r')) {
         $showuserlink = 1;
     }
     // check is_hidden fields
     foreach (array('_users_id_requester', '_groups_id_requester', '_users_id_observer', '_groups_id_observer', '_users_id_assign', '_groups_id_assign', '_suppliers_id_assign') as $f) {
         $is_hidden[$f] = false;
         if (isset($options['_tickettemplate']) && $options['_tickettemplate']->isHiddenField($f)) {
             $is_hidden[$f] = true;
         }
     }
     $can_admin = $this->canAdminActors();
     $can_assign = $this->canAssign();
     $can_assigntome = $this->canAssignToMe();
     if (isset($options['_noupdate']) && $options['_noupdate']) {
         $can_admin = false;
         $can_assign = false;
         $can_assigntome = false;
     }
     // Manage actors : requester and assign
     echo "<table class='tab_cadre_fixe' id='mainformtable5'>";
     echo "<tr class='tab_bg_1'>";
     echo "<th rowspan='2' width='13%'>" . __('Actor') . "</th>";
     echo "<th width='29%'>";
     if (!$is_hidden['_users_id_requester'] || !$is_hidden['_groups_id_requester']) {
         _e('Requester');
     }
     $rand_requester = -1;
     $candeleterequester = false;
     if ($ID && $can_admin && (!$is_hidden['_users_id_requester'] || !$is_hidden['_groups_id_requester'])) {
         $rand_requester = mt_rand();
         echo "&nbsp;&nbsp;";
         echo "<img title=\"" . __s('Add') . "\" alt=\"" . __s('Add') . "\"\n                onClick=\"Ext.get('itilactor{$rand_requester}').setDisplayed('block')\"\n                class='pointer' src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png'>";
         $candeleterequester = true;
     }
     echo "</th>";
     echo "<th width='29%'>";
     if (!$is_hidden['_users_id_observer'] || !$is_hidden['_groups_id_observer']) {
         _e('Watcher');
     }
     $rand_observer = -1;
     $candeleteobserver = false;
     if ($ID && $can_admin && (!$is_hidden['_users_id_observer'] || !$is_hidden['_groups_id_observer'])) {
         $rand_observer = mt_rand();
         echo "&nbsp;&nbsp;";
         echo "<img title=\"" . __s('Add') . "\" alt=\"" . __s('Add') . "\"\n                onClick=\"Ext.get('itilactor{$rand_observer}').setDisplayed('block')\"\n                class='pointer' src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png'>";
         $candeleteobserver = true;
     } else {
         if ($ID > 0 && !in_array($this->fields['status'], $this->getClosedStatusArray()) && !$is_hidden['_users_id_observer'] && !$this->isUser(CommonITILActor::OBSERVER, Session::getLoginUserID()) && !$this->isUser(CommonITILActor::REQUESTER, Session::getLoginUserID())) {
             echo "&nbsp;&nbsp;&nbsp;&nbsp;";
             Html::showSimpleForm($this->getFormURL(), 'addme_observer', __('Associate myself with this ticket'), array('tickets_id' => $this->fields['id']));
         }
     }
     echo "</th>";
     echo "<th width='29%'>";
     if (!$is_hidden['_users_id_assign'] || !$is_hidden['_groups_id_assign'] || !$is_hidden['_suppliers_id_assign']) {
         _e('Assigned to');
     }
     $rand_assign = -1;
     $candeleteassign = false;
     if ($ID && ($can_assign || $can_assigntome) && (!$is_hidden['_users_id_assign'] || !$is_hidden['_groups_id_assign'] || !$is_hidden['_suppliers_id_assign'])) {
         $rand_assign = mt_rand();
         echo "&nbsp;&nbsp;";
         echo "<img title=\"" . __s('Add') . "\" alt=\"" . __s('Add') . "\"\n                onClick=\"Ext.get('itilactor{$rand_assign}').setDisplayed('block')\"\n                class='pointer' src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png'>";
     }
     if ($ID && $can_assign) {
         $candeleteassign = true;
     }
     echo "</th></tr>";
     echo "<tr class='tab_bg_1 top'>";
     echo "<td>";
     if ($rand_requester >= 0) {
         $this->showActorAddForm(CommonITILActor::REQUESTER, $rand_requester, $this->fields['entities_id'], $is_hidden);
     }
     // Requester
     if (!$ID) {
         $reqdisplay = false;
         if ($can_admin && !$is_hidden['_users_id_requester']) {
             $this->showActorAddFormOnCreate(CommonITILActor::REQUESTER, $options);
             $reqdisplay = true;
         } else {
             $delegating = User::getDelegateGroupsForUser($options['entities_id']);
             if (count($delegating) && !$is_hidden['_users_id_requester']) {
                 //$this->getDefaultActor(CommonITILActor::REQUESTER);
                 $options['_right'] = "delegate";
                 $this->showActorAddFormOnCreate(CommonITILActor::REQUESTER, $options);
                 $reqdisplay = true;
             } else {
                 // predefined value
                 if (isset($options["_users_id_requester"]) && $options["_users_id_requester"]) {
                     echo self::getActorIcon('user', CommonITILActor::REQUESTER) . "&nbsp;";
                     echo Dropdown::getDropdownName("glpi_users", $options["_users_id_requester"]);
                     echo "<input type='hidden' name='_users_id_requester' value=\"" . $options["_users_id_requester"] . "\">";
                     echo '<br>';
                     $reqdisplay = true;
                 }
             }
         }
         //If user have access to more than one entity, then display a combobox : Ticket case
         if ($this->userentity_oncreate && isset($this->countentitiesforuser) && $this->countentitiesforuser > 1) {
             echo "<br>";
             $rand = Entity::dropdown(array('value' => $this->fields["entities_id"], 'entity' => $this->userentities, 'on_change' => 'submit()'));
         } else {
             echo "<input type='hidden' name='entities_id' value='" . $this->fields["entities_id"] . "'>";
         }
         if ($reqdisplay) {
             echo '<hr>';
         }
     } else {
         if (!$is_hidden['_users_id_requester']) {
             $this->showUsersAssociated(CommonITILActor::REQUESTER, $candeleterequester, $options);
         }
     }
     // Requester Group
     if (!$ID) {
         if ($can_admin && !$is_hidden['_groups_id_requester']) {
             echo self::getActorIcon('group', CommonITILActor::REQUESTER);
             /// For ticket templates : mandatories
             if (isset($options['_tickettemplate'])) {
                 echo $options['_tickettemplate']->getMandatoryMark('_groups_id_requester');
             }
             echo "&nbsp;";
             Group::dropdown(array('name' => '_groups_id_requester', 'value' => $options["_groups_id_requester"], 'entity' => $this->fields["entities_id"], 'condition' => '`is_requester`'));
         } else {
             // predefined value
             if (isset($options["_groups_id_requester"]) && $options["_groups_id_requester"]) {
                 echo self::getActorIcon('group', CommonITILActor::REQUESTER) . "&nbsp;";
                 echo Dropdown::getDropdownName("glpi_groups", $options["_groups_id_requester"]);
                 echo "<input type='hidden' name='_groups_id_requester' value=\"" . $options["_groups_id_requester"] . "\">";
                 echo '<br>';
             }
         }
     } else {
         if (!$is_hidden['_groups_id_requester']) {
             $this->showGroupsAssociated(CommonITILActor::REQUESTER, $candeleterequester, $options);
         }
     }
     echo "</td>";
     echo "<td>";
     if ($rand_observer >= 0) {
         $this->showActorAddForm(CommonITILActor::OBSERVER, $rand_observer, $this->fields['entities_id'], $is_hidden);
     }
     // Observer
     if (!$ID) {
         if ($can_admin && !$is_hidden['_users_id_observer']) {
             $this->showActorAddFormOnCreate(CommonITILActor::OBSERVER, $options);
             echo '<hr>';
         } else {
             // predefined value
             if (isset($options["_users_id_observer"]) && $options["_users_id_observer"]) {
                 echo self::getActorIcon('user', CommonITILActor::OBSERVER) . "&nbsp;";
                 echo Dropdown::getDropdownName("glpi_users", $options["_users_id_observer"]);
                 echo "<input type='hidden' name='_users_id_observer' value=\"" . $options["_users_id_observer"] . "\">";
                 echo '<hr>';
             }
         }
     } else {
         if (!$is_hidden['_users_id_observer']) {
             $this->showUsersAssociated(CommonITILActor::OBSERVER, $candeleteobserver, $options);
         }
     }
     // Observer Group
     if (!$ID) {
         if ($can_admin && !$is_hidden['_groups_id_observer']) {
             echo self::getActorIcon('group', CommonITILActor::OBSERVER);
             /// For ticket templates : mandatories
             if (isset($options['_tickettemplate'])) {
                 echo $options['_tickettemplate']->getMandatoryMark('_groups_id_observer');
             }
             echo "&nbsp;";
             Group::dropdown(array('name' => '_groups_id_observer', 'value' => $options["_groups_id_observer"], 'entity' => $this->fields["entities_id"], 'condition' => '`is_requester`'));
         } else {
             // predefined value
             if (isset($options["_groups_id_observer"]) && $options["_groups_id_observer"]) {
                 echo self::getActorIcon('group', CommonITILActor::OBSERVER) . "&nbsp;";
                 echo Dropdown::getDropdownName("glpi_groups", $options["_groups_id_observer"]);
                 echo "<input type='hidden' name='_groups_id_observer' value=\"" . $options["_groups_id_observer"] . "\">";
                 echo '<br>';
             }
         }
     } else {
         if (!$is_hidden['_groups_id_observer']) {
             $this->showGroupsAssociated(CommonITILActor::OBSERVER, $candeleteobserver, $options);
         }
     }
     echo "</td>";
     echo "<td>";
     if ($rand_assign >= 0) {
         $this->showActorAddForm(CommonITILActor::ASSIGN, $rand_assign, $this->fields['entities_id'], $is_hidden, $can_assign, $can_assign);
     }
     // Assign User
     if (!$ID) {
         if ($can_assign && !$is_hidden['_users_id_assign']) {
             $this->showActorAddFormOnCreate(CommonITILActor::ASSIGN, $options);
             echo '<hr>';
         } else {
             if ($can_assigntome && !$is_hidden['_users_id_assign']) {
                 echo self::getActorIcon('user', CommonITILActor::ASSIGN) . "&nbsp;";
                 User::dropdown(array('name' => '_users_id_assign', 'value' => $options["_users_id_assign"], 'entity' => $this->fields["entities_id"], 'ldap_import' => true));
                 echo '<hr>';
             } else {
                 // predefined value
                 if (isset($options["_users_id_assign"]) && $options["_users_id_assign"]) {
                     echo self::getActorIcon('user', CommonITILActor::ASSIGN) . "&nbsp;";
                     echo Dropdown::getDropdownName("glpi_users", $options["_users_id_assign"]);
                     echo "<input type='hidden' name='_users_id_assign' value=\"" . $options["_users_id_assign"] . "\">";
                     echo '<hr>';
                 }
             }
         }
     } else {
         if (!$is_hidden['_users_id_assign']) {
             $this->showUsersAssociated(CommonITILActor::ASSIGN, $candeleteassign, $options);
         }
     }
     // Assign Groups
     if (!$ID) {
         if ($can_assign && !$is_hidden['_groups_id_assign']) {
             echo self::getActorIcon('group', CommonITILActor::ASSIGN);
             /// For ticket templates : mandatories
             if (isset($options['_tickettemplate'])) {
                 echo $options['_tickettemplate']->getMandatoryMark('_groups_id_assign');
             }
             echo "&nbsp;";
             $rand = mt_rand();
             $params = array('name' => '_groups_id_assign', 'value' => $options["_groups_id_assign"], 'entity' => $this->fields["entities_id"], 'condition' => '`is_assign`', 'rand' => $rand);
             if ($this->getType() == 'Ticket') {
                 $params['toupdate'] = array('value_fieldname' => 'value', 'to_update' => "countgroupassign_{$rand}", 'url' => $CFG_GLPI["root_doc"] . "/ajax/ticketassigninformation.php", 'moreparams' => array('groups_id_assign' => '__VALUE__'));
             }
             Group::dropdown($params);
             echo "<span id='countgroupassign_{$rand}'>";
             echo "</span>";
             echo "<script type='text/javascript'>";
             Ajax::updateItemJsCode("countgroupassign_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/ticketassigninformation.php", array('groups_id_assign' => '__VALUE__'), "dropdown__groups_id_assign{$rand}");
             echo "</script>";
             echo '<hr>';
         } else {
             // predefined value
             if (isset($options["_groups_id_assign"]) && $options["_groups_id_assign"]) {
                 echo self::getActorIcon('group', CommonITILActor::ASSIGN) . "&nbsp;";
                 echo Dropdown::getDropdownName("glpi_groups", $options["_groups_id_assign"]);
                 echo "<input type='hidden' name='_groups_id_assign' value=\"" . $options["_groups_id_assign"] . "\">";
                 echo '<hr>';
             }
         }
     } else {
         if (!$is_hidden['_groups_id_assign']) {
             $this->showGroupsAssociated(CommonITILActor::ASSIGN, $candeleteassign, $options);
         }
     }
     // Assign Suppliers
     if (!$ID) {
         if ($can_assign && !$is_hidden['_suppliers_id_assign']) {
             echo self::getActorIcon('supplier', CommonITILActor::ASSIGN);
             /// For ticket templates : mandatories
             if (isset($options['_tickettemplate'])) {
                 echo $options['_tickettemplate']->getMandatoryMark('_suppliers_id_assign');
             }
             echo "&nbsp;";
             $rand = mt_rand();
             $params = array('name' => '_suppliers_id_assign', 'value' => $options["_suppliers_id_assign"], 'entity' => $this->fields["entities_id"], 'rand' => $rand);
             Supplier::dropdown($params);
         } else {
             // predefined value
             if (isset($options["_suppliers_id_assign"]) && $options["_suppliers_id_assign"]) {
                 echo self::getActorIcon('supplier', CommonITILActor::ASSIGN) . "&nbsp;";
                 echo Dropdown::getDropdownName("glpi_suppliers", $options["_suppliers_id_assign"]);
                 echo "<input type='hidden' name='_suppliers_id_assign' value=\"" . $options["_suppliers_id_assign"] . "\">";
                 echo '<hr>';
             }
         }
     } else {
         if (!$is_hidden['_suppliers_id_assign']) {
             $this->showSuppliersAssociated(CommonITILActor::ASSIGN, $candeleteassign, $options);
         }
     }
     echo "</td>";
     echo "</tr>";
     echo "</table>";
 }
 /**
  * Show the Form edit form the the adminsitrator in the config page
  *
  * @param  Array  $options Optional options
  *
  * @return NULL         Nothing, just display the form
  */
 public function showForm($options = array())
 {
     $rand = mt_rand();
     $obj = new PluginFormcreatorTarget();
     $found = $obj->find("itemtype = '" . __CLASS__ . "' AND items_id = " . (int) $this->getID());
     $target = array_shift($found);
     $form = new PluginFormcreatorForm();
     $form->getFromDB($target['plugin_formcreator_forms_id']);
     echo '<div class="center" style="width: 950px; margin: 0 auto;">';
     echo '<form name="form_target" method="post" action="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/front/targetticket.form.php">';
     // General information : name
     echo '<table class="tab_cadre_fixe">';
     echo '<tr><th colspan="2">' . __('Edit a destination', 'formcreator') . '</th></tr>';
     echo '<tr class="line1">';
     echo '<td width="15%"><strong>' . __('Name') . ' <span style="color:red;">*</span></strong></td>';
     echo '<td width="85%"><input type="text" name="name" style="width:704px;" value="' . $target['name'] . '"></textarea</td>';
     echo '</tr>';
     echo '</table>';
     // Ticket information : title, template...
     echo '<table class="tab_cadre_fixe">';
     echo '<tr><th colspan="4">' . _n('Target ticket', 'Target tickets', 1, 'formcreator') . '</th></tr>';
     echo '<tr class="line1">';
     echo '<td><strong>' . __('Ticket title', 'formcreator') . ' <span style="color:red;">*</span></strong></td>';
     echo '<td colspan="3"><input type="text" name="title" style="width:704px;" value="' . $this->fields['name'] . '"></textarea</td>';
     echo '</tr>';
     echo '<tr class="line0">';
     echo '<td><strong>' . __('Description') . ' <span style="color:red;">*</span></strong></td>';
     echo '<td colspan="3">';
     echo '<textarea name="comment" style="width:700px;" rows="15">' . $this->fields['comment'] . '</textarea>';
     if ($GLOBALS['CFG_GLPI']["use_rich_text"]) {
         Html::initEditorSystem('comment');
     }
     echo '</td>';
     echo '</tr>';
     // Ticket Template
     echo '<tr class="line1">';
     echo '<td width="15%">' . _n('Ticket template', 'Ticket templates', 1) . '</td>';
     echo '<td width="25%">';
     Dropdown::show('TicketTemplate', array('name' => 'tickettemplates_id', 'value' => $this->fields['tickettemplates_id']));
     echo '</td>';
     echo '<td width="15%">' . __('Due date') . '</td>';
     echo '<td width="45%">';
     // -------------------------------------------------------------------------------------------
     // Due date type selection
     // -------------------------------------------------------------------------------------------
     Dropdown::showFromArray('due_date_rule', array('' => Dropdown::EMPTY_VALUE, 'answer' => __('equals to the answer to the question', 'formcreator'), 'ticket' => __('calculated from the ticket creation date', 'formcreator'), 'calcul' => __('calculated from the answer to the question', 'formcreator')), array('value' => $this->fields['due_date_rule'], 'on_change' => 'formcreatorChangeDueDate(this.value)'));
     // for each section ...
     $questions_list = array(Dropdown::EMPTY_VALUE);
     $query = "SELECT s.id, s.name\n                FROM glpi_plugin_formcreator_targets t\n                INNER JOIN glpi_plugin_formcreator_sections s ON s.plugin_formcreator_forms_id = t.plugin_formcreator_forms_id\n                WHERE t.items_id = " . (int) $this->getID() . "\n                ORDER BY s.order";
     $result = $GLOBALS['DB']->query($query);
     while ($section = $GLOBALS['DB']->fetch_array($result)) {
         // select all date and datetime questions
         $query2 = "SELECT q.id, q.name\n                   FROM glpi_plugin_formcreator_questions q\n                   INNER JOIN glpi_plugin_formcreator_sections s ON s.id = q.plugin_formcreator_sections_id\n                   WHERE s.id = {$section['id']}\n                   AND q.fieldtype IN ('date', 'datetime')";
         $result2 = $GLOBALS['DB']->query($query2);
         $section_questions = array();
         while ($question = $GLOBALS['DB']->fetch_array($result2)) {
             $section_questions[$question['id']] = $question['name'];
         }
         if (count($section_questions) > 0) {
             $questions_list[$section['name']] = $section_questions;
         }
     }
     // List questions
     if ($this->fields['due_date_rule'] != 'answer' && $this->fields['due_date_rule'] != 'calcul') {
         echo '<div id="due_date_questions" style="display:none">';
     } else {
         echo '<div id="due_date_questions">';
     }
     Dropdown::showFromArray('due_date_question', $questions_list, array('value' => $this->fields['due_date_question']));
     echo '</div>';
     if ($this->fields['due_date_rule'] != 'ticket' && $this->fields['due_date_rule'] != 'calcul') {
         echo '<div id="due_date_time" style="display:none">';
     } else {
         echo '<div id="due_date_time">';
     }
     Dropdown::showNumber("due_date_value", array('value' => $this->fields['due_date_value'], 'min' => -30, 'max' => 30));
     Dropdown::showFromArray('due_date_period', array('minute' => _n('Minute', 'Minutes', 2), 'hour' => _n('Hour', 'Hours', 2), 'day' => _n('Day', 'Days', 2), 'month' => __('Month')), array('value' => $this->fields['due_date_period']));
     echo '</div>';
     echo '</td>';
     echo '</tr>';
     // -------------------------------------------------------------------------------------------
     // Due date type selection end
     // -------------------------------------------------------------------------------------------
     if ($form->fields['validation_required']) {
         echo '<tr class="line0">';
         echo '<td colspan="4">';
         echo '<input type="hidden" name="validation_followup" value="0" />';
         echo '<input type="checkbox" name="validation_followup" id="validation_followup" value="1" ';
         if (!isset($this->fields['validation_followup']) || $this->fields['validation_followup'] == 1) {
             echo ' checked="checked"';
         }
         echo '/>';
         echo ' <label for="validation_followup">';
         echo __('Add validation message as first ticket followup', 'formcreator');
         echo '</label>';
         echo '</td>';
         echo '</tr>';
     }
     echo '</table>';
     // Buttons
     echo '<table class="tab_cadre_fixe">';
     echo '<tr class="line1">';
     echo '<td colspan="5" class="center">';
     echo '<input type="reset" name="reset" class="submit_button" value="' . __('Cancel', 'formcreator') . '"
            onclick="document.location = \'form.form.php?id=' . $target['plugin_formcreator_forms_id'] . '\'" /> &nbsp; ';
     echo '<input type="hidden" name="id" value="' . $this->getID() . '" />';
     echo '<input type="submit" name="update" class="submit_button" value="' . __('Save') . '" />';
     echo '</td>';
     echo '</tr>';
     echo '</table>';
     Html::closeForm();
     // Get available questions for actors lists
     $questions_user_list = array(Dropdown::EMPTY_VALUE);
     $questions_group_list = array(Dropdown::EMPTY_VALUE);
     $questions_supplier_list = array(Dropdown::EMPTY_VALUE);
     $query = "SELECT s.id, s.name\n                FROM glpi_plugin_formcreator_targets t\n                INNER JOIN glpi_plugin_formcreator_sections s ON s.plugin_formcreator_forms_id = t.plugin_formcreator_forms_id\n                WHERE t.items_id = " . (int) $this->getID() . "\n                ORDER BY s.order";
     $result = $GLOBALS['DB']->query($query);
     while ($section = $GLOBALS['DB']->fetch_array($result)) {
         // select all user, group or supplier questions (GLPI Object)
         $query2 = "SELECT q.id, q.name, q.values\n                   FROM glpi_plugin_formcreator_questions q\n                   INNER JOIN glpi_plugin_formcreator_sections s ON s.id = q.plugin_formcreator_sections_id\n                   WHERE s.id = {$section['id']}\n                   AND q.fieldtype = 'glpiselect'\n                   AND q.values IN ('User', 'Group', 'Supplier')";
         $result2 = $GLOBALS['DB']->query($query2);
         $section_questions_user = array();
         $section_questions_group = array();
         $section_questions_supplier = array();
         while ($question = $GLOBALS['DB']->fetch_array($result2)) {
             switch ($question['values']) {
                 case 'User':
                     $section_questions_user[$question['id']] = $question['name'];
                     break;
                 case 'Group':
                     $section_questions_group[$question['id']] = $question['name'];
                     break;
                 case 'Supplier':
                     $section_questions_supplier[$question['id']] = $question['name'];
                     break;
             }
         }
         $questions_user_list[$section['name']] = $section_questions_user;
         $questions_group_list[$section['name']] = $section_questions_group;
         $questions_supplier_list[$section['name']] = $section_questions_supplier;
     }
     // Get available questions for actors lists
     $actors = array('requester' => array(), 'observer' => array(), 'assigned' => array());
     $query = "SELECT id, actor_role, actor_type, actor_value, use_notification\n                FROM glpi_plugin_formcreator_targettickets_actors\n                WHERE plugin_formcreator_targettickets_id = " . $this->getID();
     $result = $GLOBALS['DB']->query($query);
     while ($actor = $GLOBALS['DB']->fetch_array($result)) {
         $actors[$actor['actor_role']][$actor['id']] = array('actor_type' => $actor['actor_type'], 'actor_value' => $actor['actor_value'], 'use_notification' => $actor['use_notification']);
     }
     $img_user = '******' . __('User') . '" title="' . __('User') . '" width="20" />';
     $img_group = '<img src="../../../pics/groupes.png" alt="' . __('Group') . '" title="' . __('Group') . '" width="20" />';
     $img_supplier = '<img src="../../../pics/supplier.png" alt="' . __('Supplier') . '" title="' . __('Supplier') . '" width="20" />';
     $img_mail = '<img src="../pics/email.png" alt="' . __('Yes') . '" title="' . __('Email followup') . ' ' . __('Yes') . '" />';
     $img_nomail = '<img src="../pics/email-no.png" alt="' . __('No') . '" title="' . __('Email followup') . ' ' . __('No') . '" />';
     echo '<table class="tab_cadre_fixe">';
     echo '<tr><th colspan="3">' . __('Ticket actors', 'formcreator') . '</th></tr>';
     echo '<tr>';
     echo '<th width="33%">';
     echo _n('Requester', 'Requesters', 1) . ' &nbsp;';
     echo '<img title="Ajouter" alt="Ajouter" onclick="displayRequesterForm()" class="pointer"
            id="btn_add_requester" src="../../../pics/add_dropdown.png">';
     echo '<img title="Annuler" alt="Annuler" onclick="hideRequesterForm()" class="pointer"
            id="btn_cancel_requester" src="../../../pics/delete.png" style="display:none">';
     echo '</th>';
     echo '<th width="34%">';
     echo _n('Watcher', 'Watchers', 1) . ' &nbsp;';
     echo '<img title="Ajouter" alt="Ajouter" onclick="displayWatcherForm()" class="pointer"
            id="btn_add_watcher" src="../../../pics/add_dropdown.png">';
     echo '<img title="Annuler" alt="Annuler" onclick="hideWatcherForm()" class="pointer"
            id="btn_cancel_watcher" src="../../../pics/delete.png" style="display:none">';
     echo '</th>';
     echo '<th width="33%">';
     echo __('Assigned to') . ' &nbsp;';
     echo '<img title="Ajouter" alt="Ajouter" onclick="displayAssignedForm()" class="pointer"
            id="btn_add_assigned" src="../../../pics/add_dropdown.png">';
     echo '<img title="Annuler" alt="Annuler" onclick="hideAssignedForm()" class="pointer"
            id="btn_cancel_assigned" src="../../../pics/delete.png" style="display:none">';
     echo '</th>';
     echo '</tr>';
     echo '<tr>';
     // Requester
     echo '<td valign="top">';
     // => Add requester form
     echo '<form name="form_target" id="form_add_requester" method="post" style="display:none" action="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/front/targetticket.form.php">';
     Dropdown::showFromArray('actor_type', array('' => Dropdown::EMPTY_VALUE, 'creator' => __('Form requester', 'formcreator'), 'validator' => __('Form validator', 'formcreator'), 'person' => __('Specific person', 'formcreator'), 'question_person' => __('Person from the question', 'formcreator'), 'group' => __('Specific group', 'formcreator'), 'question_group' => __('Group from the question', 'formcreator')), array('on_change' => 'formcreatorChangeActorRequester(this.value)'));
     echo '<div id="block_requester_user" style="display:none">';
     User::dropdown(array('name' => 'actor_value_person', 'right' => 'all', 'all' => 0));
     echo '</div>';
     echo '<div id="block_requester_group" style="display:none">';
     Group::dropdown(array('name' => 'actor_value_group'));
     echo '</div>';
     echo '<div id="block_requester_question_user" style="display:none">';
     Dropdown::showFromArray('actor_value_question_person', $questions_user_list, array('value' => $this->fields['due_date_question']));
     echo '</div>';
     echo '<div id="block_requester_question_group" style="display:none">';
     Dropdown::showFromArray('actor_value_question_group', $questions_group_list, array('value' => $this->fields['due_date_question']));
     echo '</div>';
     echo '<div>';
     echo __('Email followup');
     Dropdown::showYesNo('use_notification', 1);
     echo '</div>';
     echo '<p align="center">';
     echo '<input type="hidden" name="id" value="' . $this->getID() . '" />';
     echo '<input type="hidden" name="actor_role" value="requester" />';
     echo '<input type="submit" value="' . __('Add') . '" class="submit_button" />';
     echo '</p>';
     echo "<hr>";
     Html::closeForm();
     // => List of saved requesters
     foreach ($actors['requester'] as $id => $values) {
         echo '<div>';
         switch ($values['actor_type']) {
             case 'creator':
                 echo $img_user . ' <b>' . __('Form requester', 'formcreator') . '</b>';
                 break;
             case 'validator':
                 echo $img_user . ' <b>' . __('Form validator', 'formcreator') . '</b>';
                 break;
             case 'person':
                 $user = new User();
                 $user->getFromDB($values['actor_value']);
                 echo $img_user . ' <b>' . __('User') . ' </b> "' . $user->getName() . '"';
                 break;
             case 'question_person':
                 $question = new PluginFormcreatorQuestion();
                 $question->getFromDB($values['actor_value']);
                 echo $img_user . ' <b>' . __('Person from the question', 'formcreator') . '</b> "' . $question->getName() . '"';
                 break;
             case 'group':
                 $group = new Group();
                 $group->getFromDB($values['actor_value']);
                 echo $img_user . ' <b>' . __('Group') . ' </b> "' . $group->getName() . '"';
                 break;
             case 'question_group':
                 $question = new PluginFormcreatorQuestion();
                 $question->getFromDB($values['actor_value']);
                 echo $img_group . ' <b>' . __('Group from the question', 'formcreator') . '</b> "' . $question->getName() . '"';
                 break;
         }
         echo $values['use_notification'] ? ' ' . $img_mail . ' ' : ' ' . $img_nomail . ' ';
         echo self::getDeleteImage($id);
         echo '</div>';
     }
     echo '</td>';
     // Observer
     echo '<td valign="top">';
     // => Add observer form
     echo '<form name="form_target" id="form_add_watcher" method="post" style="display:none" action="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/front/targetticket.form.php">';
     Dropdown::showFromArray('actor_type', array('' => Dropdown::EMPTY_VALUE, 'creator' => __('Form requester', 'formcreator'), 'validator' => __('Form validator', 'formcreator'), 'person' => __('Specific person', 'formcreator'), 'question_person' => __('Person from the question', 'formcreator'), 'group' => __('Specific group', 'formcreator'), 'question_group' => __('Group from the question', 'formcreator')), array('on_change' => 'formcreatorChangeActorWatcher(this.value)'));
     echo '<div id="block_watcher_user" style="display:none">';
     User::dropdown(array('name' => 'actor_value_person', 'right' => 'all', 'all' => 0));
     echo '</div>';
     echo '<div id="block_watcher_group" style="display:none">';
     Group::dropdown(array('name' => 'actor_value_group'));
     echo '</div>';
     echo '<div id="block_watcher_question_user" style="display:none">';
     Dropdown::showFromArray('actor_value_question_person', $questions_user_list, array('value' => $this->fields['due_date_question']));
     echo '</div>';
     echo '<div id="block_watcher_question_group" style="display:none">';
     Dropdown::showFromArray('actor_value_question_group', $questions_group_list, array('value' => $this->fields['due_date_question']));
     echo '</div>';
     echo '<div>';
     echo __('Email followup');
     Dropdown::showYesNo('use_notification', 1);
     echo '</div>';
     echo '<p align="center">';
     echo '<input type="hidden" name="id" value="' . $this->getID() . '" />';
     echo '<input type="hidden" name="actor_role" value="observer" />';
     echo '<input type="submit" value="' . __('Add') . '" class="submit_button" />';
     echo '</p>';
     echo "<hr>";
     Html::closeForm();
     // => List of saved observers
     foreach ($actors['observer'] as $id => $values) {
         echo '<div>';
         switch ($values['actor_type']) {
             case 'creator':
                 echo $img_user . ' <b>' . __('Form requester', 'formcreator') . '</b>';
                 break;
             case 'validator':
                 echo $img_user . ' <b>' . __('Form validator', 'formcreator') . '</b>';
                 break;
             case 'person':
                 $user = new User();
                 $user->getFromDB($values['actor_value']);
                 echo $img_user . ' <b>' . __('User') . ' </b> "' . $user->getName() . '"';
                 break;
             case 'question_person':
                 $question = new PluginFormcreatorQuestion();
                 $question->getFromDB($values['actor_value']);
                 echo $img_user . ' <b>' . __('Person from the question', 'formcreator') . '</b> "' . $question->getName() . '"';
                 break;
             case 'group':
                 $group = new Group();
                 $group->getFromDB($values['actor_value']);
                 echo $img_user . ' <b>' . __('Group') . ' </b> "' . $group->getName() . '"';
                 break;
             case 'question_group':
                 $question = new PluginFormcreatorQuestion();
                 $question->getFromDB($values['actor_value']);
                 echo $img_group . ' <b>' . __('Group from the question', 'formcreator') . '</b> "' . $question->getName() . '"';
                 break;
         }
         echo $values['use_notification'] ? ' ' . $img_mail . ' ' : ' ' . $img_nomail . ' ';
         echo self::getDeleteImage($id);
         echo '</div>';
     }
     echo '</td>';
     // Assigned to
     echo '<td valign="top">';
     // => Add assigned to form
     echo '<form name="form_target" id="form_add_assigned" method="post" style="display:none" action="' . $GLOBALS['CFG_GLPI']['root_doc'] . '/plugins/formcreator/front/targetticket.form.php">';
     Dropdown::showFromArray('actor_type', array('' => Dropdown::EMPTY_VALUE, 'creator' => __('Form requester', 'formcreator'), 'validator' => __('Form validator', 'formcreator'), 'person' => __('Specific person', 'formcreator'), 'question_person' => __('Person from the question', 'formcreator'), 'group' => __('Specific group', 'formcreator'), 'question_group' => __('Group from the question', 'formcreator'), 'supplier' => __('Specific supplier', 'formcreator'), 'question_supplier' => __('Supplier from the question', 'formcreator')), array('on_change' => 'formcreatorChangeActorAssigned(this.value)'));
     echo '<div id="block_assigned_user" style="display:none">';
     User::dropdown(array('name' => 'actor_value_person', 'right' => 'all', 'all' => 0));
     echo '</div>';
     echo '<div id="block_assigned_group" style="display:none">';
     Group::dropdown(array('name' => 'actor_value_group'));
     echo '</div>';
     echo '<div id="block_assigned_supplier" style="display:none">';
     Supplier::dropdown(array('name' => 'actor_value_supplier'));
     echo '</div>';
     echo '<div id="block_assigned_question_user" style="display:none">';
     Dropdown::showFromArray('actor_value_question_person', $questions_user_list, array('value' => $this->fields['due_date_question']));
     echo '</div>';
     echo '<div id="block_assigned_question_group" style="display:none">';
     Dropdown::showFromArray('actor_value_question_group', $questions_group_list, array('value' => $this->fields['due_date_question']));
     echo '</div>';
     echo '<div id="block_assigned_question_supplier" style="display:none">';
     Dropdown::showFromArray('actor_value_question_supplier', $questions_supplier_list, array('value' => $this->fields['due_date_question']));
     echo '</div>';
     echo '<div>';
     echo __('Email followup');
     Dropdown::showYesNo('use_notification', 1);
     echo '</div>';
     echo '<p align="center">';
     echo '<input type="hidden" name="id" value="' . $this->getID() . '" />';
     echo '<input type="hidden" name="actor_role" value="assigned" />';
     echo '<input type="submit" value="' . __('Add') . '" class="submit_button" />';
     echo '</p>';
     echo "<hr>";
     Html::closeForm();
     // => List of saved assigned to
     foreach ($actors['assigned'] as $id => $values) {
         echo '<div>';
         switch ($values['actor_type']) {
             case 'creator':
                 echo $img_user . ' <b>' . __('Form requester', 'formcreator') . '</b>';
                 break;
             case 'validator':
                 echo $img_user . ' <b>' . __('Form validator', 'formcreator') . '</b>';
                 break;
             case 'person':
                 $user = new User();
                 $user->getFromDB($values['actor_value']);
                 echo $img_user . ' <b>' . __('User') . ' </b> "' . $user->getName() . '"';
                 break;
             case 'question_person':
                 $question = new PluginFormcreatorQuestion();
                 $question->getFromDB($values['actor_value']);
                 echo $img_user . ' <b>' . __('Person from the question', 'formcreator') . '</b> "' . $question->getName() . '"';
                 break;
             case 'group':
                 $group = new Group();
                 $group->getFromDB($values['actor_value']);
                 echo $img_user . ' <b>' . __('Group') . ' </b> "' . $group->getName() . '"';
                 break;
             case 'question_group':
                 $question = new PluginFormcreatorQuestion();
                 $question->getFromDB($values['actor_value']);
                 echo $img_group . ' <b>' . __('Group from the question', 'formcreator') . '</b> "' . $question->getName() . '"';
                 break;
             case 'supplier':
                 $group = new Group();
                 $group->getFromDB($values['actor_value']);
                 echo $img_supplier . ' <b>' . __('Supplier') . ' </b> "' . $group->getName() . '"';
                 break;
             case 'question_supplier':
                 $question = new PluginFormcreatorQuestion();
                 $question->getFromDB($values['actor_value']);
                 echo $img_supplier . ' <b>' . __('Supplier from the question', 'formcreator') . '</b> "' . $question->getName() . '"';
                 break;
         }
         echo $values['use_notification'] ? ' ' . $img_mail . ' ' : ' ' . $img_nomail . ' ';
         echo self::getDeleteImage($id);
         echo '</div>';
     }
     echo '</td>';
     echo '</tr>';
     echo '</table>';
     // List of available tags
     echo '<table class="tab_cadre_fixe">';
     echo '<tr><th colspan="5">' . __('List of available tags') . '</th></tr>';
     echo '<tr>';
     echo '<th width="40%" colspan="2">' . _n('Question', 'Questions', 1, 'formcreator') . '</th>';
     echo '<th width="20%">' . __('Title') . '</th>';
     echo '<th width="20%">' . _n('Answer', 'Answers', 1, 'formcreator') . '</th>';
     echo '<th width="20%">' . _n('Section', 'Sections', 1, 'formcreator') . '</th>';
     echo '</tr>';
     echo '<tr class="line0">';
     echo '<td colspan="2"><strong>' . __('Full form', 'formcreator') . '</strong></td>';
     echo '<td align="center"><code>-</code></td>';
     echo '<td align="center"><code><strong>##FULLFORM##</strong></code></td>';
     echo '<td align="center">-</td>';
     echo '</tr>';
     $table_questions = getTableForItemType('PluginFormcreatorQuestion');
     $table_sections = getTableForItemType('PluginFormcreatorSection');
     $query = "SELECT q.`id`, q.`name` AS question, s.`name` AS section\n                FROM {$table_questions} q\n                LEFT JOIN {$table_sections} s ON q.`plugin_formcreator_sections_id` = s.`id`\n                WHERE s.`plugin_formcreator_forms_id` = " . $target['plugin_formcreator_forms_id'] . "\n                ORDER BY s.`order`, q.`order`";
     $result = $GLOBALS['DB']->query($query);
     $i = 0;
     while ($question = $GLOBALS['DB']->fetch_array($result)) {
         $i++;
         echo '<tr class="line' . $i % 2 . '">';
         echo '<td colspan="2">' . $question['question'] . '</td>';
         echo '<td align="center"><code>##question_' . $question['id'] . '##</code></td>';
         echo '<td align="center"><code>##answer_' . $question['id'] . '##</code></td>';
         echo '<td align="center">' . $question['section'] . '</td>';
         echo '</tr>';
     }
     echo '</table>';
     echo '</div>';
 }
 /**
  * Print the HTML array for entreprises on the current contact
  *
  *@return Nothing (display)
  **/
 static function showForContact(Contact $contact)
 {
     global $DB, $CFG_GLPI;
     $instID = $contact->fields['id'];
     if (!$contact->can($instID, READ)) {
         return false;
     }
     $canedit = $contact->can($instID, UPDATE);
     $rand = mt_rand();
     $query = "SELECT `glpi_contacts_suppliers`.`id`,\n                       `glpi_suppliers`.`id` AS entID,\n                       `glpi_suppliers`.`name` AS name,\n                       `glpi_suppliers`.`website` AS website,\n                       `glpi_suppliers`.`fax` AS fax,\n                       `glpi_suppliers`.`phonenumber` AS phone,\n                       `glpi_suppliers`.`suppliertypes_id` AS type,\n                       `glpi_suppliers`.`is_deleted`,\n                       `glpi_entities`.`id` AS entity\n                FROM `glpi_contacts_suppliers`, `glpi_suppliers`\n                LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id`=`glpi_suppliers`.`entities_id`)\n                WHERE `glpi_contacts_suppliers`.`contacts_id` = '{$instID}'\n                      AND `glpi_contacts_suppliers`.`suppliers_id` = `glpi_suppliers`.`id`" . getEntitiesRestrictRequest(" AND", "glpi_suppliers", '', '', true) . "\n                ORDER BY `glpi_entities`.`completename`, `name`";
     $result = $DB->query($query);
     $suppliers = array();
     $used = array();
     if ($number = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $suppliers[$data['id']] = $data;
             $used[$data['entID']] = $data['entID'];
         }
     }
     if ($canedit) {
         echo "<div class='firstbloc'>";
         echo "<form name='contactsupplier_form{$rand}' id='contactsupplier_form{$rand}'\n                method='post' action='";
         echo Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_1'><th colspan='2'>" . __('Add a supplier') . "</tr>";
         echo "<tr class='tab_bg_2'><td class='center'>";
         echo "<input type='hidden' name='contacts_id' value='{$instID}'>";
         Supplier::dropdown(array('used' => $used, 'entity' => $contact->fields["entities_id"], 'entity_sons' => $contact->fields["is_recursive"]));
         echo "</td><td class='center'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $number) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('num_displayed' => $number, 'container' => 'mass' . __CLASS__ . $rand);
         Html::showMassiveActions($massiveactionparams);
     }
     echo "<table class='tab_cadre_fixehov'>";
     $header_begin = "<tr>";
     $header_top = '';
     $header_bottom = '';
     $header_end = '';
     if ($canedit && $number) {
         $header_top .= "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
         $header_top .= "</th>";
         $header_bottom .= "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
         $header_bottom .= "</th>";
     }
     $header_end .= "<th>" . __('Supplier') . "</th>";
     $header_end .= "<th>" . __('Entity') . "</th>";
     $header_end .= "<th>" . __('Third party type') . "</th>";
     $header_end .= "<th>" . __('Phone') . "</th>";
     $header_end .= "<th>" . __('Fax') . "</th>";
     $header_end .= "<th>" . __('Website') . "</th>";
     $header_end .= "</tr>";
     echo $header_begin . $header_top . $header_end;
     $used = array();
     if ($number > 0) {
         Session::initNavigateListItems('Supplier', sprintf(__('%1$s = %2$s'), Contact::getTypeName(1), $contact->getName()));
         foreach ($suppliers as $data) {
             $ID = $data["id"];
             Session::addToNavigateListItems('Supplier', $data["entID"]);
             $used[$data["entID"]] = $data["entID"];
             $website = $data["website"];
             if (!empty($website)) {
                 $website = $data["website"];
                 if (!preg_match("?https*://?", $website)) {
                     $website = "http://" . $website;
                 }
                 $website = "<a target=_blank href='{$website}'>" . $data["website"] . "</a>";
             }
             echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>";
             if ($canedit) {
                 echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["id"]) . "</td>";
             }
             echo "<td class='center'>";
             echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/supplier.form.php?id=" . $data["entID"] . "'>" . Dropdown::getDropdownName("glpi_suppliers", $data["entID"]) . "</a></td>";
             echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data["entity"]);
             echo "</td>";
             echo "<td class='center'>" . Dropdown::getDropdownName("glpi_suppliertypes", $data["type"]);
             echo "</td>";
             echo "<td class='center' width='80'>" . $data["phone"] . "</td>";
             echo "<td class='center' width='80'>" . $data["fax"] . "</td>";
             echo "<td class='center'>" . $website . "</td>";
             echo "</tr>";
         }
         echo $header_begin . $header_bottom . $header_end;
     }
     echo "</table>";
     if ($canedit && $number) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
 public function showForm($ID, $options = array())
 {
     global $CFG_GLPI;
     if (!$this->canView()) {
         return false;
     }
     if ($ID > 0) {
         $this->check($ID, READ);
     } else {
         // Create item
         $this->check(-1, UPDATE);
         $this->getEmpty();
     }
     $this->initForm($ID, $options);
     $this->showFormHeader($options);
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Name') . " : </td>";
     echo "<td>";
     Html::autocompletionTextField($this, "name");
     echo "</td>";
     echo "<td>" . __('Other') . " : </td>";
     echo "<td>";
     Html::autocompletionTextField($this, "others");
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Supplier') . " : </td>";
     echo "<td>";
     Supplier::dropdown(array('name' => "suppliers_id", 'value' => $this->fields["suppliers_id"], 'entity' => $this->fields["entities_id"]));
     echo "</td>";
     echo "<td>" . __('Rates', 'connections') . " : </td>";
     echo "<td>";
     PluginConnectionsConnectionRate::dropdown(array('name' => "plugin_connections_connectionrates_id", 'value' => $this->fields["plugin_connections_connectionrates_id"], 'entity' => $this->fields["entities_id"]));
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Type of Connections', 'connections') . " : </td><td>";
     PluginConnectionsConnectionType::dropdown(array('name' => "plugin_connections_connectiontypes_id", 'value' => $this->fields["plugin_connections_connectiontypes_id"], 'entity' => $this->fields["entities_id"]));
     echo "</td>";
     echo "<td>" . __('Guaranteed Rates', 'connections') . " : </td>";
     echo "<td>";
     PluginConnectionsGuaranteedConnectionRate::dropdown(array('name' => "plugin_connections_guaranteedconnectionrates_id", 'value' => $this->fields["plugin_connections_guaranteedconnectionrates_id"], 'entity' => $this->fields["entities_id"]));
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Technician in charge of the hardware') . " : </td><td>";
     User::dropdown(array('value' => $this->fields["users_id"], 'entity' => $this->fields["entities_id"], 'right' => 'all'));
     echo "</td>";
     echo "<td>" . __('Associable to a ticket') . " :</td><td>";
     Dropdown::showYesNo('is_helpdesk_visible', $this->fields['is_helpdesk_visible']);
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Group') . " : </td><td>";
     Group::dropdown(array('name' => "groups_id", 'value' => $this->fields["groups_id"], 'entity' => $this->fields["entities_id"]));
     echo "</td>";
     echo "<td>" . __('Last update') . " : </td>";
     echo "<td>" . Html::convDateTime($this->fields["date_mod"]) . "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Comments') . " : </td>";
     echo "<td class='center' colspan='3'>";
     echo "<textarea cols='35' rows='4' name='comment' >" . $this->fields["comment"] . "</textarea>";
     echo "</td>";
     echo "</tr>";
     $this->showFormButtons($options);
     return true;
 }