static function showForItemtype($type) {
      global $DB;

      if (!Session::haveRight("profile", READ)) {
         return false;
      }
      self::installRights();
      $canedit = Session::haveRight("profile", UPDATE);

      echo "<form action='" . self::getFormUrl() . "' method='post'>";
      echo "<table class='tab_cadre_fixe'>";
      $itemtype = $type->fields['itemtype'];
      echo "<tr><th colspan='2' align='center'><strong>";
      echo __("Rights assignment").":&nbsp;";
      echo $itemtype::getTypeName();
      echo "</strong></th></tr>";

      echo "<tr><td class='genericobject_type_profiles'>";
      $rights = array();
      foreach (getAllDatasFromTable(getTableForItemtype("Profile")) as $profile) {
         $prof = new Profile();
         $prof->getFromDB($profile['id']);
         $right = self::getProfileforItemtype($profile['id'], $itemtype);
         $label = $profile['name'];
         $rights = array(
            array(
               'label' => $label,
               'itemtype' => $itemtype,
               'field' =>  self::getProfileNameForItemtype($itemtype),
               'html_field' => "profile_" . $profile['id'],
            )
         );
         $prof->displayRightsChoiceMatrix(
            $rights
         );
      }
      echo "</td></tr>";
      echo "<input type='hidden' name='itemtype' value='".$itemtype."'>";

      if ($canedit) {
         echo "<tr class='tab_bg_1'>";
         echo "<td align='center' colspan='2'>";
         echo "<input type='submit' name='update_all_rights' value=\"" .
            _sx('button', 'Post') . "\" class='submit'>";
         echo "</td></tr>";
      }


      echo "</table>";
      Html::closeForm();
   }
Exemple #2
0
 /**
  * @since version 0.84
  *
  * @param $field
  * @param $values
  * @param $options   array
  **/
 static function getSpecificValueToDisplay($field, $values, array $options = array())
 {
     if (!is_array($values)) {
         $values = array($field => $values);
     }
     switch ($field) {
         case 'global_validation':
             return TicketValidation::getStatus($values[$field]);
         case 'type':
             return self::getTicketTypeName($values[$field]);
         case 'items_id':
             if (isset($values['itemtype'])) {
                 if (isset($options['comments']) && $options['comments']) {
                     $tmp = Dropdown::getDropdownName(getTableForItemtype($values['itemtype']), $values[$field], 1);
                     return sprintf(__('%1$s %2$s'), $tmp['name'], Html::showToolTip($tmp['comment'], array('display' => false)));
                 }
                 return Dropdown::getDropdownName(getTableForItemtype($values['itemtype']), $values[$field]);
             }
             break;
     }
     return parent::getSpecificValueToDisplay($field, $values, $options);
 }
Exemple #3
0
         </td>
         <td colspan="3">
            <div id="div_show_condition"<?php 
echo $hide;
?>
>
               <?php 
// ===============================================================
// TODO : Mettre en place l'interface multi-conditions
// Ci-dessous une solution temporaire qui affiche uniquement la 1ere condition
$sql = "SELECT `show_field`, `show_condition`, `show_value`\n                       FROM glpi_plugin_formcreator_questions_conditions\n                       WHERE `plugin_formcreator_questions_id` = {$question_id}\n                       LIMIT 0, 1";
$result = $GLOBALS['DB']->query($sql);
list($show_field, $show_condition, $show_value) = $GLOBALS['DB']->fetch_array($result);
// ===============================================================
$table_question = getTableForItemtype('PluginFormcreatorQuestion');
$table_section = getTableForItemtype('PluginFormcreatorSection');
$questions_tab = array();
$sql = "SELECT q.`id`, q.`name`\n                       FROM {$table_question} q\n                       LEFT JOIN {$table_section} s ON q.`plugin_formcreator_sections_id` = s.`id`\n                       WHERE s.`plugin_formcreator_forms_id` = {$form_id}\n                       AND q.`id` != {$question_id}\n                       ORDER BY s.`order`, q.`order`";
$result = $GLOBALS['DB']->query($sql);
while ($line = $GLOBALS['DB']->fetch_array($result)) {
    $questions_tab[$line['id']] = strlen($line['name']) < 30 ? $line['name'] : substr($line['name'], 0, strrpos(substr($line['name'], 0, 30), ' ')) . '...';
}
echo '<div id="div_show_condition_field">';
Dropdown::showFromArray('show_field', $questions_tab, array('value' => $show_field));
echo '</div>';
echo '<div id="div_show_condition_operator">';
Dropdown::showFromArray('show_condition', array('==' => '=', '!=' => '&ne;', '<' => '&lt;', '>' => '&gt;', '<=' => '&le;', '>=' => '&ge;'), array('value' => $show_condition, 'rand' => $rand));
echo '</div>';
?>

               <div id="div_show_condition_value">
     Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/form.form.php?id=' . $_POST['plugin_formcreator_forms_id']);
     // Delete a Question
 } elseif (isset($_POST["delete"])) {
     $question->check($_POST['id'], 'd');
     $question->delete($_POST);
     // Set a Question required
 } elseif (isset($_POST["set_required"])) {
     global $DB;
     $question->check($_POST['id'], 'w');
     $table = getTableForItemtype('PluginFormcreatorQuestion');
     $DB->query("UPDATE {$table} SET `required` = " . $_POST['value'] . " WHERE id = " . $_POST['id']);
     // Move a Question
 } elseif (isset($_POST["move"])) {
     global $DB;
     $question->check($_POST['id'], 'd');
     $table = getTableForItemtype('PluginFormcreatorQuestion');
     $result = $DB->query("SELECT `order`, `plugin_formcreator_sections_id` FROM {$table} WHERE id = " . $_POST['id']);
     list($order, $section_id) = $DB->fetch_array($result);
     if ($_POST["way"] == 'up') {
         $result = $DB->query("SELECT `id`, `order` FROM {$table} WHERE `order` < {$order} AND plugin_formcreator_sections_id = {$section_id} ORDER BY `order` DESC LIMIT 0, 1");
         if ($DB->numrows($result) != 0) {
             list($id2, $order2) = $DB->fetch_array($result);
             $DB->query("UPDATE {$table} SET `order` = {$order2} WHERE `id` = " . (int) $_POST['id']);
             $DB->query("UPDATE {$table} SET `order` = {$order} WHERE `id` = {$id2}");
         }
     } else {
         $result = $DB->query("SELECT `id`, `order` FROM {$table} WHERE `order` > {$order} AND plugin_formcreator_sections_id = {$section_id} ORDER BY `order` ASC LIMIT 0, 1");
         if ($DB->numrows($result) != 0) {
             list($id2, $order2) = $DB->fetch_array($result);
             $DB->query("UPDATE {$table} SET `order` = {$order2} WHERE `id` = " . (int) $_POST['id']);
             $DB->query("UPDATE {$table} SET `order` = {$order} WHERE `id` = {$id2}");
 /**
  * Get costs summary values
  *
  * @param $type    string  type
  * @param $ID      integer ID of the ticket
  *
  * @return array of costs and actiontime
  **/
 static function getCostsSummary($type, $ID)
 {
     global $DB;
     $query = "SELECT *\n                FROM `" . getTableForItemtype($type) . "`\n                WHERE `" . static::$items_id . "` = '{$ID}'\n                ORDER BY `begin_date`";
     $tab = array('totalcost' => 0, 'actiontime' => 0, 'costfixed' => 0, 'costtime' => 0, 'costmaterial' => 0);
     foreach ($DB->request($query) as $data) {
         $tab['actiontime'] += $data['actiontime'];
         $tab['costfixed'] += $data['cost_fixed'];
         $tab['costmaterial'] += $data['cost_material'];
         $tab['costtime'] += $data['actiontime'] * $data['cost_time'] / HOUR_TIMESTAMP;
         $tab['totalcost'] += self::computeTotalCost($data['actiontime'], $data['cost_time'], $data['cost_fixed'], $data['cost_material']);
     }
     foreach ($tab as $key => $val) {
         $tab[$key] = Html::formatNumber($val);
     }
     return $tab;
 }
Exemple #6
0
 /**
  * @since version 0.84
  *
  * @param $field
  * @param $values
  * @param $options   array
  **/
 static function getSpecificValueToDisplay($field, $values, array $options = array())
 {
     if (!is_array($values)) {
         $values = array($field => $values);
     }
     switch ($field) {
         case 'items_id':
             if (strpos($values[$field], "_") !== false) {
                 $item_itemtype = explode("_", $values[$field]);
                 $values['itemtype'] = $item_itemtype[0];
                 $values[$field] = $item_itemtype[1];
             }
             if (isset($values['itemtype'])) {
                 if (isset($options['comments']) && $options['comments']) {
                     $tmp = Dropdown::getDropdownName(getTableForItemtype($values['itemtype']), $values[$field], 1);
                     return sprintf(__('%1$s %2$s'), $tmp['name'], Html::showToolTip($tmp['comment'], array('display' => false)));
                 }
                 return Dropdown::getDropdownName(getTableForItemtype($values['itemtype']), $values[$field]);
             }
             break;
     }
     return parent::getSpecificValueToDisplay($field, $values, $options);
 }
 static function getSearchOptionsToAdd()
 {
     $tab = array();
     $tab['validation'] = __('Approval');
     $tab[51]['table'] = getTableForItemtype(static::$itemtype);
     $tab[51]['field'] = 'validation_percent';
     $tab[51]['name'] = __('Minimum validation required');
     $tab[51]['datatype'] = 'number';
     $tab[51]['unit'] = '%';
     $tab[51]['min'] = 0;
     $tab[51]['max'] = 100;
     $tab[51]['step'] = 50;
     $tab[52]['table'] = getTableForItemtype(static::$itemtype);
     $tab[52]['field'] = 'global_validation';
     $tab[52]['name'] = __('Approval');
     $tab[52]['searchtype'] = 'equals';
     $tab[52]['datatype'] = 'specific';
     $tab[53]['table'] = static::getTable();
     $tab[53]['field'] = 'comment_submission';
     $tab[53]['name'] = __('Request comments');
     $tab[53]['datatype'] = 'text';
     $tab[53]['forcegroupby'] = true;
     $tab[53]['massiveaction'] = false;
     $tab[53]['joinparams'] = array('jointype' => 'child');
     $tab[54]['table'] = static::getTable();
     $tab[54]['field'] = 'comment_validation';
     $tab[54]['name'] = __('Approval comments');
     $tab[54]['datatype'] = 'text';
     $tab[54]['forcegroupby'] = true;
     $tab[54]['massiveaction'] = false;
     $tab[54]['joinparams'] = array('jointype' => 'child');
     $tab[55]['table'] = static::getTable();
     $tab[55]['field'] = 'status';
     $tab[55]['datatype'] = 'specific';
     $tab[55]['name'] = __('Approval status');
     $tab[55]['searchtype'] = 'equals';
     $tab[55]['forcegroupby'] = true;
     $tab[55]['massiveaction'] = false;
     $tab[55]['joinparams'] = array('jointype' => 'child');
     $tab[56]['table'] = static::getTable();
     $tab[56]['field'] = 'submission_date';
     $tab[56]['name'] = __('Request date');
     $tab[56]['datatype'] = 'datetime';
     $tab[56]['forcegroupby'] = true;
     $tab[56]['massiveaction'] = false;
     $tab[56]['joinparams'] = array('jointype' => 'child');
     $tab[57]['table'] = static::getTable();
     $tab[57]['field'] = 'validation_date';
     $tab[57]['name'] = __('Approval date');
     $tab[57]['datatype'] = 'datetime';
     $tab[57]['forcegroupby'] = true;
     $tab[57]['massiveaction'] = false;
     $tab[57]['joinparams'] = array('jointype' => 'child');
     $tab[58]['table'] = 'glpi_users';
     $tab[58]['field'] = 'name';
     $tab[58]['name'] = __('Requester');
     $tab[58]['datatype'] = 'itemlink';
     if (static::$itemtype == 'Ticket') {
         $tab[58]['right'] = 'create_ticket_validate';
     } else {
         $tab[58]['right'] = 'create_validate';
     }
     $tab[58]['forcegroupby'] = true;
     $tab[58]['massiveaction'] = false;
     $tab[58]['joinparams'] = array('beforejoin' => array('table' => static::getTable(), 'joinparams' => array('jointype' => 'child')));
     $tab[59]['table'] = 'glpi_users';
     $tab[59]['field'] = 'name';
     $tab[59]['linkfield'] = 'users_id_validate';
     $tab[59]['name'] = __('Approver');
     $tab[59]['datatype'] = 'itemlink';
     if (static::$itemtype == 'Ticket') {
         $tab[58]['right'] = array('validate_request', 'validate_incident');
     } else {
         $tab[58]['right'] = 'validate';
     }
     $tab[59]['forcegroupby'] = true;
     $tab[59]['massiveaction'] = false;
     $tab[59]['joinparams'] = array('beforejoin' => array('table' => static::getTable(), 'joinparams' => array('jointype' => 'child')));
     return $tab;
 }
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::showMassiveActionsSubForm()
  **/
 static function showMassiveActionsSubForm(MassiveAction $ma)
 {
     global $CFG_GLPI;
     switch ($ma->getAction()) {
         case 'Generate':
             $formcreator = new self();
             $formcreator->showFormMassiveAction($ma);
             return true;
             break;
         case 'Pedido':
             /*
             				Dropdown::show('PluginFormcreatorForm', array(
             'name'      => "plugin_formcreator_forms_id",
             'entity'    => $_SESSION['glpiactive_entity']
             ));
             */
             $table = getTableForItemtype('PluginFormcreatorForm');
             $sections = array();
             $sql = "SELECT `id`, `name`\n\t\t\t\t\t\t\tFROM {$table}\n\t\t\t\t\t\t\tWHERE entities_id = " . $_SESSION['glpiactive_entity'] . "\n\t\t\t\t\t\t\tORDER BY `name`";
             $result = $GLOBALS['DB']->query($sql);
             while ($section = $GLOBALS['DB']->fetch_array($result)) {
                 $sections[$section['id']] = $section['name'];
             }
             $sections = array("0" => "----") + $sections;
             Dropdown::showFromArray('plugin_formcreator_forms_id', $sections, array());
             echo Html::submit(_x('button', 'Post'), array('name' => 'massiveaction'));
             return true;
             break;
     }
     return parent::showMassiveActionsSubForm($ma);
 }
 function get_tickets($from_date, $to_date, $date_fmt)
 {
     global $DEBUG_SQL;
     $response = array();
     $range_date = array();
     if (!is_null($from_date)) {
         $range_date_start = new DateTime($from_date->format('Y-m-d'));
     } else {
         $range_date_start = null;
     }
     $range_date_end = new DateTime($to_date->format('Y-m-d'));
     \Toolbox::logDebug($range_date_start, $range_date_end);
     // TODO: build dates filler at the end. If from_date is null it should
     // take the date from the first ticket created
     // while($range_date_start < $range_date_end) {
     //     $range_date[] = self::format_dates($range_date_start->format('Y-m-d'),$date_fmt);
     //     $range_date_start->add(DateInterval::createFromDateString('1 day'));
     // }
     $current_entity = $_SESSION['glpiactive_entity_name'];
     $entities_restrict = getEntitiesRestrictRequest('', getTableForItemtype('Ticket'), '', '', false, false);
     $filter = array();
     // TODO: Handle 'until' types of request.
     // Check if $from_date is null and get everything before $to_date
     if (is_null($from_date)) {
         $filter[] = " AND ( " . "    (date <= '" . $to_date->format('Y-m-d') . "')" . ") AND is_deleted = 0";
     } else {
         $filter[] = " AND ( " . " (date between '" . $from_date->format('Y-m-d') . "'" . " and '" . $to_date->format('Y-m-d') . "')" . " OR (solvedate between '" . $from_date->format('Y-m-d') . "'" . " and '" . $to_date->format('Y-m-d') . "')" . " OR (closedate between '" . $from_date->format('Y-m-d') . "'" . " and '" . $to_date->format('Y-m-d') . "')" . ") AND is_deleted = 0";
     }
     // $filter[] =
     //     " AND ( ".
     //     "date < '".$to_date->format('Y-m-d')."'".
     //     ")";
     $filter[] = " AND " . $entities_restrict;
     array_unshift($filter, '1');
     $tickets = $this->factories['tickets']->find(implode("\n", $filter), "id ASC");
     // Get Categories
     $categories = $this->factories['categories']->find(implode("\n", array("1 ")));
     $category_ids = array_keys($categories);
     $solutiontypes = $this->factories['solution_types']->find();
     $response['result'] = array();
     $result =& $response['result'];
     $category = null;
     foreach ($tickets as $ticket) {
         $category_id = $ticket['itilcategories_id'];
         $solutiontypes_id = $tickets['solutiontypes_id'];
         $solutiontype = null;
         if ($solutiontypes_id > 0) {
             $solutiontype = $solutiontypes[$solutiontypes_id]['name'];
         } else {
             $solutiontype = __('None');
         }
         if (!array_key_exists($category_id, $categories)) {
             $category = "N/A";
             $category_names = array("N/A");
         } else {
             $category = $categories[$category_id];
             //TODO: make the following configurable.
             $category_names = explode(" > ", $category['completename']);
         }
         $type = null;
         switch ($ticket['type']) {
             case Ticket::INCIDENT_TYPE:
                 $type = 'incident';
                 break;
             case Ticket::DEMAND_TYPE:
                 $type = 'request';
                 break;
         }
         $result[] = array('id' => $ticket['id'], 'date_opened' => self::format_dates($ticket['date'], $date_fmt), 'date_solved' => self::format_dates($ticket['solvedate'], $date_fmt), 'date_closed' => self::format_dates($ticket['closedate'], $date_fmt), 'status_code' => $ticket['status'], 'status' => Ticket::getStatus($ticket['status']), 'category' => $category_names, 'category_id' => $category_id, 'impact' => Ticket::getImpactName($ticket['impact']), 'priority' => Ticket::getPriorityName($ticket['priority']), 'urgency' => Ticket::getUrgencyName($ticket['urgency']), 'solve_delay_stat' => intval($ticket['solve_delay_stat']), 'type' => $type, 'type_name' => Ticket::getTicketTypeName($ticket['type']), 'solution_type' => $solutiontype);
     }
     $response['metadata'] = array('count' => count($result), 'from_date' => !is_null($from_date) ? $from_date->format('c') : null, 'to_date' => $to_date->format('c'), 'current_entity' => $current_entity, 'range_dates' => array_values(array_unique($range_date)));
     $response['_debug'] = array('entities_restrict' => $entities_restrict, 'filter' => $filter, 'DEBUG_SQL' => $DEBUG_SQL);
     return $response;
 }
 public static function displayValue($value, $values)
 {
     return Dropdown::getDropdownName(getTableForItemtype($values), $value);
 }
 static function showInstrucciontecnica($item, $instID, $itemtype)
 {
     global $DB, $CFG_GLPI;
     $objeto = $item->getType();
     $appli = new $objeto();
     $appli->getFromDB($item->fields['id']);
     //$canedit = $appli->can($appli->fields['id'],'w');
     $canedit = $appli->canCreate();
     //$canedit = Session::haveRight('update_ticket', 1);
     echo "<div class='center'>";
     echo "<form name='form_pedido' id='form_pedido' method='post' action='../plugins/formcreator/front/instruccion.form.php'>";
     echo "<table class='tab_cadre_fixe'>";
     echo "<th colspan=2>" . __('Informacion del pedido', 'Informacion del pedido') . "</th>";
     echo "<tr>";
     echo "<th>" . __('Pedido de catalogo', 'Pedido de catalogo') . "&nbsp;:" . "</th>";
     echo "<td>";
     if ($canedit) {
         //Dropdown::show('PluginFormcreatorForm', array('name'  => 'peticion_id',
         //							  'value'  => $instID));
         $table = getTableForItemtype('PluginFormcreatorForm');
         $sections = array();
         $sql = "SELECT `id`, `name`\n\t\t\t\t\t\t\tFROM {$table}\n\t\t\t\t\t\t\tORDER BY `name`";
         $result = $GLOBALS['DB']->query($sql);
         while ($section = $GLOBALS['DB']->fetch_array($result)) {
             $sections[$section['id']] = $section['name'];
         }
         $sections = array("0" => "----") + $sections;
         Dropdown::showFromArray('peticion_id', $sections, array('value' => $instID));
     } else {
         echo Dropdown::getDropdownName("glpi_plugin_formcreator_forms", $instID);
     }
     echo "</td>";
     //-----------------------------
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td colspan='2' align = 'center'>";
     echo "<input type='submit' name='actualizarPedido' value='Actualizar' class='submit'>";
     echo "</td></tr>";
     echo "</table>";
     echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
     echo "<input type='hidden' name='tickets_id' value='" . $item->fields['id'] . "'>";
     //echo "</form>";
     Html::closeForm();
     echo "</div>";
     echo "<div class='center'>";
     echo "<table class='tab_cadre_fixehov'>";
     $query = "SELECT DISTINCT `itemtype`\n\t\t\t\t\tFROM `glpi_documents_items`\n\t\t\t\t\tWHERE `items_id` = '{$instID}' AND `itemtype` = '{$itemtype}'\n\t\t\t\t\tORDER BY `itemtype`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     if (Session::isMultiEntitiesMode()) {
         $colsup = 1;
     } else {
         $colsup = 0;
     }
     if ($number > 0) {
         echo "<tr><th>" . __('Heading') . "</th>";
         echo "<th>" . __('Name') . "</th>";
         echo "<th>" . __('Web link') . "</th>";
         echo "<th>" . __('File') . "</th>";
         echo "<th>" . __('Entity') . "</th>";
         echo "</tr>";
     }
     for ($i = 0; $i < $number; $i++) {
         $type = $DB->result($result, $i, "itemtype");
         if (!class_exists($type)) {
             continue;
         }
         $item = new $type();
         if ($canedit) {
             //if ($item->canView()) {
             $column = "name";
             $query1 = "SELECT glpi_documents.*, glpi_documents_items.id AS IDD, glpi_entities.id AS entity\n\t\t\t\tFROM glpi_documents_items, glpi_documents LEFT JOIN glpi_entities ON (glpi_entities.id = glpi_documents.entities_id)\n\t\t\t\tWHERE glpi_documents.id = glpi_documents_items.documents_id\n\t\t\t\t\tAND glpi_documents_items.itemtype = '" . $itemtype . "'\n\t\t\t\t\tAND glpi_documents_items.items_id = " . $instID . "\n\t\t\t\t\tAND glpi_documents.is_deleted = 0\n\t\t\t\tORDER BY glpi_entities.completename, glpi_documents.name";
             if ($result_linked1 = $DB->query($query1)) {
                 if ($DB->numrows($result_linked1)) {
                     $document = new Document();
                     while ($data = $DB->fetch_assoc($result_linked1)) {
                         $item->getFromDB($data["id"]);
                         Session::addToNavigateListItems($type, $data["id"]);
                         $ID = "";
                         $downloadlink = NOT_AVAILABLE;
                         if ($document->getFromDB($data["id"])) {
                             $downloadlink = $document->getDownloadLink();
                         }
                         if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) {
                             $ID = " (" . $data["id"] . ")";
                         }
                         $name = __('Informacion de pedido', 'Informacion de pedido');
                         //item->getLink();
                         echo "<tr class='tab_bg_1'>";
                         // echo "<td class='center'>".$name."</td>";
                         echo "<td class='center'>" . Dropdown::getDropdownName("glpi_documentcategories", $data["documentcategories_id"]);
                         echo "</td>";
                         $nombre = $data['name'];
                         echo "<td class='center' " . (isset($data['deleted']) && $data['deleted'] ? "class='tab_bg_2_2'" : "") . ">" . $nombre . "</td>";
                         echo "<td class='center'>";
                         if (!empty($data["link"])) {
                             echo "<a target=_blank href='" . formatOutputWebLink($data["link"]) . "'>" . $data["link"];
                             echo "</a>";
                         } else {
                             echo "&nbsp;";
                         }
                         echo "</td>";
                         echo "<td class='center'>{$downloadlink}</td>";
                         if (Session::isMultiEntitiesMode()) {
                             echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entity']) . "</td>";
                         }
                         echo "</tr>";
                     }
                 }
             }
         }
     }
     echo "</table>";
     echo "</div>";
 }