示例#1
0
 static function showMinimalList($params = array())
 {
     global $DB, $CFG_GLPI;
     $item = new self();
     $itemtype = $item->getType();
     $itemtable = $item->getTable();
     // Default values of parameters
     $p['link'] = array();
     //
     $p['field'] = array();
     //
     $p['contains'] = array();
     //
     $p['searchtype'] = array();
     //
     $p['sort'] = '1';
     //
     $p['order'] = 'ASC';
     //
     $p['start'] = 0;
     //
     $p['is_deleted'] = 0;
     $p['id'] = 0;
     $p['export_all'] = 0;
     $p['link2'] = '';
     //
     $p['contains2'] = '';
     //
     $p['field2'] = '';
     //
     $p['itemtype2'] = '';
     $p['searchtype2'] = '';
     $p['withtemplate'] = 0;
     foreach ($params as $key => $val) {
         $p[$key] = $val;
     }
     if (isset($_POST["start"])) {
         $p['start'] = $_POST["start"];
     } else {
         $p['start'] = 0;
     }
     if (isset($_POST["sort"])) {
         $p['sort'] = $_POST["sort"];
     } else {
         $p['sort'] = 1;
     }
     if (isset($_POST["order"]) && $_POST["order"] == "DESC") {
         $p['order'] = "DESC";
     } else {
         $p['order'] = "ASC";
     }
     $PluginProjetProjet = new PluginProjetProjet();
     $PluginProjetProjet->getFromDB($p['id']);
     $canedit = $PluginProjetProjet->can($p['id'], 'w');
     // Manage defautll seachtype value : for bookmark compatibility
     if (count($p['contains'])) {
         foreach ($p['contains'] as $key => $val) {
             if (!isset($p['searchtype'][$key])) {
                 $p['searchtype'][$key] = 'contains';
             }
         }
     }
     if (is_array($p['contains2']) && count($p['contains2'])) {
         foreach ($p['contains2'] as $key => $val) {
             if (!isset($p['searchtype2'][$key])) {
                 $p['searchtype2'][$key] = 'contains';
             }
         }
     }
     $target = Toolbox::getItemTypeSearchURL($itemtype);
     $limitsearchopt = Search::getCleanedOptions($itemtype);
     $LIST_LIMIT = $_SESSION['glpilist_limit'];
     // Set display type for export if define
     $output_type = Search::HTML_OUTPUT;
     if (isset($_GET['display_type'])) {
         $output_type = $_GET['display_type'];
         // Limit to 10 element
         if ($_GET['display_type'] == Search::GLOBAL_SEARCH) {
             $LIST_LIMIT = Search::GLOBAL_DISPLAY_COUNT;
         }
     }
     $entity_restrict = $item->isEntityAssign();
     // Get the items to display
     $toview = Search::addDefaultToView($itemtype);
     // Add items to display depending of personal prefs
     $displaypref = DisplayPreference::getForTypeUser($itemtype, Session::getLoginUserID());
     if (count($displaypref)) {
         foreach ($displaypref as $val) {
             array_push($toview, $val);
         }
     }
     // Add searched items
     if (count($p['field']) > 0) {
         foreach ($p['field'] as $key => $val) {
             if (!in_array($val, $toview) && $val != 'all' && $val != 'view') {
                 array_push($toview, $val);
             }
         }
     }
     // Add order item
     if (!in_array($p['sort'], $toview)) {
         array_push($toview, $p['sort']);
     }
     // Clean toview array
     $toview = array_unique($toview);
     foreach ($toview as $key => $val) {
         if (!isset($limitsearchopt[$val])) {
             unset($toview[$key]);
         }
     }
     $toview_count = count($toview);
     //// 1 - SELECT
     $query = "SELECT " . Search::addDefaultSelect($itemtype);
     // Add select for all toview item
     foreach ($toview as $key => $val) {
         $query .= Search::addSelect($itemtype, $val, $key, 0);
     }
     $query .= "`" . $itemtable . "`.`id` AS id ";
     //// 2 - FROM AND LEFT JOIN
     // Set reference table
     $query .= " FROM `" . $itemtable . "`";
     // Init already linked tables array in order not to link a table several times
     $already_link_tables = array();
     // Put reference table
     array_push($already_link_tables, $itemtable);
     // Add default join
     $COMMONLEFTJOIN = Search::addDefaultJoin($itemtype, $itemtable, $already_link_tables);
     $query .= $COMMONLEFTJOIN;
     $searchopt = array();
     $searchopt[$itemtype] =& Search::getOptions($itemtype);
     // Add all table for toview items
     foreach ($toview as $key => $val) {
         $query .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$val]["table"], $searchopt[$itemtype][$val]["linkfield"], 0, 0, $searchopt[$itemtype][$val]["joinparams"]);
     }
     // Search all case :
     if (in_array("all", $p['field'])) {
         foreach ($searchopt[$itemtype] as $key => $val) {
             // Do not search on Group Name
             if (is_array($val)) {
                 $query .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$key]["table"], $searchopt[$itemtype][$key]["linkfield"], 0, 0, $searchopt[$itemtype][$key]["joinparams"]);
             }
         }
     }
     $query .= " WHERE `" . $itemtable . "`.`plugin_projet_projets_id` = '" . $p['id'] . "'";
     $query .= " AND `" . $itemtable . "`.`is_deleted` = '" . $p['is_deleted'] . "' ";
     //// 7 - Manage GROUP BY
     $GROUPBY = "";
     // Meta Search / Search All / Count tickets
     if (in_array('all', $p['field'])) {
         $GROUPBY = " GROUP BY `" . $itemtable . "`.`id`";
     }
     if (empty($GROUPBY)) {
         foreach ($toview as $key2 => $val2) {
             if (!empty($GROUPBY)) {
                 break;
             }
             if (isset($searchopt[$itemtype][$val2]["forcegroupby"])) {
                 $GROUPBY = " GROUP BY `" . $itemtable . "`.`id`";
             }
         }
     }
     $query .= $GROUPBY;
     //// 4 - ORDER
     $ORDER = " ORDER BY `id` ";
     foreach ($toview as $key => $val) {
         if ($p['sort'] == $val) {
             $ORDER = Search::addOrderBy($itemtype, $p['sort'], $p['order'], $key);
         }
     }
     $query .= $ORDER;
     // Get it from database
     if ($result = $DB->query($query)) {
         $numrows = $DB->numrows($result);
         $globallinkto = Search::getArrayUrlLink("field", $p['field']) . Search::getArrayUrlLink("link", $p['link']) . Search::getArrayUrlLink("contains", $p['contains']) . Search::getArrayUrlLink("field2", $p['field2']) . Search::getArrayUrlLink("contains2", $p['contains2']) . Search::getArrayUrlLink("itemtype2", $p['itemtype2']) . Search::getArrayUrlLink("link2", $p['link2']);
         $parameters = "sort=" . $p['sort'] . "&order=" . $p['order'] . $globallinkto;
         if ($output_type == Search::GLOBAL_SEARCH) {
             if (class_exists($itemtype)) {
                 echo "<div class='center'><h2>" . $item::getTypeName();
                 // More items
                 if ($numrows > $p['start'] + Search::GLOBAL_DISPLAY_COUNT) {
                     echo " <a href='{$target}?{$parameters}'>" . __('All') . "</a>";
                 }
                 echo "</h2></div>\n";
             } else {
                 return false;
             }
         }
         if ($p['start'] < $numrows) {
             if ($output_type == Search::HTML_OUTPUT && !$p['withtemplate']) {
                 echo "<div align='center'>";
                 echo "<a href='" . $CFG_GLPI["root_doc"] . "/plugins/projet/front/task.php?contains%5B0%5D=" . $p['id'] . "&field%5B0%5D=23&sort=1&is_deleted=0&start=0'>" . _x('button', 'Search') . "</a><br>";
                 echo "</div>";
             }
             // Pager
             if ($output_type == Search::HTML_OUTPUT) {
                 // HTML display - massive modif
                 $search_config = "";
                 if ($item->canCreate() && $canedit) {
                     $tmp = " class='pointer' onClick=\"var w = window.open('" . $CFG_GLPI["root_doc"] . "/front/popup.php?popup=search_config&amp;itemtype=" . $itemtype . "' ,'glpipopup', " . "'height=400, width=1000, top=100, left=100, scrollbars=yes' ); w.focus();\"";
                     $search_config = "<img alt='" . __('Select default items to show') . "' title='" . __('Select default items to show') . "' src='" . $CFG_GLPI["root_doc"] . "/pics/options_search.png' ";
                     $search_config .= $tmp . ">";
                 }
                 //echo Search::showHeaderItem($output_type,$search_config,$header_num,"",0,$p['order']);
             }
             if ($output_type == Search::HTML_OUTPUT) {
                 Html::printAjaxPager(self::getTypeName(2), $p['start'], $numrows, $search_config);
                 echo "<br>";
             }
             // Define begin and end var for loop
             // Search case
             $begin_display = $p['start'];
             $end_display = $p['start'] + $LIST_LIMIT;
             // Export All case
             if ($p['export_all']) {
                 $begin_display = 0;
                 $end_display = $numrows;
             }
             //massive action
             $sel = "";
             if (isset($_GET["select"]) && $_GET["select"] == "all") {
                 $sel = "checked";
             }
             if ($item->canCreate() && $canedit && $output_type == Search::HTML_OUTPUT && $p['withtemplate'] != 2) {
                 Html::openMassiveActionsForm('massform' . $itemtype);
                 $massiveactionparams = array('num_displayed' => $end_display - $begin_display, 'fixed' => true, 'is_deleted' => $p['is_deleted']);
                 Html::showMassiveActions($itemtype, $massiveactionparams);
             }
             // Add toview elements
             $nbcols = $toview_count;
             if ($output_type == Search::HTML_OUTPUT) {
                 // HTML display - massive modif
                 $nbcols++;
             }
             // Display List Header
             echo Search::showHeader($output_type, $end_display - $begin_display + 1, $nbcols, 1);
             $header_num = 1;
             // Display column Headers for toview items
             $headers_line = '';
             $headers_line_top = '';
             $headers_line_bottom = '';
             echo Search::showNewLine($output_type);
             if ($output_type == Search::HTML_OUTPUT && $item->canCreate() && $canedit) {
                 // HTML display - massive modif
                 $headers_line_top .= Search::showHeaderItem($output_type, Html::getCheckAllAsCheckbox('massform' . $itemtype), $header_num, "", 0, $p['order']);
                 $headers_line_bottom .= Search::showHeaderItem($output_type, Html::getCheckAllAsCheckbox('massform' . $itemtype), $header_num, "", 0, $p['order']);
             }
             // Display column Headers for toview items
             foreach ($toview as $key => $val) {
                 $linkto = '';
                 if (!isset($searchopt[$itemtype][$val]['nosort']) || !$searchopt[$itemtype][$val]['nosort']) {
                     $linkto = "javascript:reloadTab('sort=" . $val . "&amp;order=" . ($p['order'] == "ASC" ? "DESC" : "ASC") . "&amp;start=" . $p['start'] . $globallinkto . "')";
                 }
                 $headers_line .= Search::showHeaderItem($output_type, $searchopt[$itemtype][$val]["name"], $header_num, $linkto, $p['sort'] == $val, $p['order']);
             }
             // End Line for column headers
             $headers_line .= Search::showEndLine($output_type);
             $headers_line_top .= $headers_line;
             $headers_line_bottom .= $headers_line;
             echo $headers_line_top;
             $DB->data_seek($result, $p['start']);
             // Define begin and end var for loop
             // Search case
             $i = $begin_display;
             // Init list of items displayed
             if ($output_type == Search::HTML_OUTPUT) {
                 Session::initNavigateListItems($itemtype, PluginProjetProjet::getTypeName(2) . " = " . (empty($PluginProjetProjet->fields['name']) ? "(" . $p['id'] . ")" : $PluginProjetProjet->fields['name']));
             }
             // Num of the row (1=header_line)
             $row_num = 1;
             // Display Loop
             while ($i < $numrows && $i < $end_display) {
                 $item_num = 1;
                 $data = $DB->fetch_array($result);
                 $i++;
                 $row_num++;
                 echo Search::showNewLine($output_type, $i % 2);
                 Session::addToNavigateListItems($itemtype, $data['id']);
                 $tmpcheck = "";
                 if ($item->canCreate() && $canedit && $output_type == Search::HTML_OUTPUT && $p['withtemplate'] != 2) {
                     $sel = "";
                     $tmpcheck = "<input type='checkbox' name='item[" . $data["id"] . "]' value='1' {$sel}>";
                 }
                 echo Search::showItem($output_type, $tmpcheck, $item_num, $row_num, "width='10'");
                 foreach ($toview as $key => $val) {
                     echo Search::showItem($output_type, Search::giveItem($itemtype, $val, $data, $key), $item_num, $row_num, Search::displayConfigItem($itemtype, $val, $data, $key));
                 }
                 echo Search::showEndLine($output_type);
             }
             // Close Table
             $title = "";
             // Create title
             if ($output_type == Search::PDF_OUTPUT_PORTRAIT || $output_type == Search::PDF_OUTPUT_LANDSCAPE) {
                 $title .= __('Tasks list', 'projet');
             }
             // Display footer
             echo Search::showFooter($output_type, $title);
             //massive action
             if ($item->canCreate() && $canedit && $output_type == Search::HTML_OUTPUT && $p['withtemplate'] != 2) {
                 $massiveactionparams['ontop'] = false;
                 Html::showMassiveActions($itemtype, $massiveactionparams);
                 // End form for delete item
                 Html::closeForm();
             } else {
                 echo "</table></div>";
             }
             // Pager
             if ($output_type == Search::HTML_OUTPUT) {
                 echo "<br>";
                 Html::printAjaxPager(self::getTypeName(2), $p['start'], $numrows);
             }
         } else {
             echo Search::showError($output_type);
         }
     }
 }
 function prepareInputForAdd($input)
 {
     $projet = new PluginProjetProjet();
     if (!isset($input['plugin_projet_projets_id_1']) || !isset($input['plugin_projet_projets_id_2']) || $input['plugin_projet_projets_id_2'] == $input['plugin_projet_projets_id_1'] || !$projet->getFromDB($input['plugin_projet_projets_id_1']) || !$projet->getFromDB($input['plugin_projet_projets_id_2'])) {
         return false;
     }
     if (!isset($input['link'])) {
         $input['link'] = self::LINK_TO;
     }
     return $input;
 }
示例#3
0
 function showFormForTask($projet, PluginProjetTask $task)
 {
     global $CFG_GLPI;
     $PluginProjetProjet = new PluginProjetProjet();
     $PluginProjetProjet->getFromDB($projet);
     $taskid = $task->getField('id');
     if ($taskid > 0 && $this->getFromDBbyTask($taskid)) {
         if ($this->canCreate()) {
             echo "<script type='text/javascript' >\n";
             echo "function showPlan" . $taskid . "(){\n";
             echo "Ext.get('plan').setDisplayed('none');";
             $params = array('form' => 'followups', 'id' => $this->fields["id"], 'begin' => $this->fields["begin"], 'end' => $this->fields["end"], 'entity' => $PluginProjetProjet->fields["entities_id"]);
             Ajax::updateItemJsCode('viewplan', $CFG_GLPI["root_doc"] . "/plugins/projet/ajax/planning.php", $params);
             echo "}";
             echo "</script>\n";
             echo "<div id='plan' onClick='showPlan" . $taskid . "()'>\n";
             echo "<span class='showplan'>";
         }
         if ($this->fields["begin"] && $this->fields["end"]) {
             echo Html::convDateTime($this->fields["begin"]) . "&nbsp;->&nbsp;" . Html::convDateTime($this->fields["end"]);
         } else {
             _e('Plan this task');
         }
         if ($this->canCreate()) {
             echo "</span>";
             echo "</div>\n";
             echo "<div id='viewplan'></div>\n";
         }
     } else {
         if ($this->canCreate()) {
             echo "<script type='text/javascript' >\n";
             echo "function showPlanUpdate(){\n";
             echo "Ext.get('plan').setDisplayed('none');";
             $params = array('form' => 'followups', 'entity' => $_SESSION["glpiactive_entity"]);
             Ajax::UpdateItemJsCode('viewplan', $CFG_GLPI["root_doc"] . "/plugins/projet/ajax/planning.php", $params);
             echo "};";
             echo "</script>";
             echo "<div id='plan'  onClick='showPlanUpdate()'>\n";
             echo "<span class='showplan'>" . __('Plan this task') . "</span>";
             echo "</div>\n";
             echo "<div id='viewplan'></div>\n";
         } else {
             _e('None');
         }
     }
 }
示例#4
0
 function pre_deleteItem()
 {
     global $CFG_GLPI;
     if ($CFG_GLPI["use_mailing"] && isset($this->input['delete'])) {
         $projet = new PluginProjetProjet();
         $options = array('followups_id' => $this->fields["id"]);
         if ($projet->getFromDB($this->fields["plugin_projet_projets_id"])) {
             NotificationEvent::raiseEvent("delete_followup", $projet, $options);
         }
     }
     return true;
 }
示例#5
0
 /**
  * Show projet associated to an item
  *
  * @since version 0.84
  *
  * @param $item            CommonDBTM object for which associated projet must be displayed
  * @param $withtemplate    (default '')
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getField('id');
     if ($item->isNewID($ID)) {
         return false;
     }
     if (!plugin_projet_haveRight('projet', 'r')) {
         return false;
     }
     if (!$item->can($item->fields['id'], 'r')) {
         return false;
     }
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     $canedit = $item->canadditem('PluginProjetProjet');
     $rand = mt_rand();
     $is_recursive = $item->isRecursive();
     $query = "SELECT `glpi_plugin_projet_projets_items`.`id` AS assocID,\n                       `glpi_entities`.`id` AS entity,\n                       `glpi_plugin_projet_projets`.`name` AS assocName,\n                       `glpi_plugin_projet_projets`.*\n                FROM `glpi_plugin_projet_projets_items`\n                LEFT JOIN `glpi_plugin_projet_projets`\n                 ON (`glpi_plugin_projet_projets_items`.`plugin_projet_projets_id`=`glpi_plugin_projet_projets`.`id`)\n                LEFT JOIN `glpi_entities` ON (`glpi_plugin_projet_projets`.`entities_id`=`glpi_entities`.`id`)\n                WHERE `glpi_plugin_projet_projets_items`.`items_id` = '{$ID}'\n                      AND `glpi_plugin_projet_projets_items`.`itemtype` = '" . $item->getType() . "' ";
     $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_projet_projets", '', '', true);
     $query .= " ORDER BY `assocName`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     $projets = array();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $projets[$data['assocID']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     $projet = new PluginProjetProjet();
     if ($canedit && $withtemplate < 2) {
         // Restrict entity for knowbase
         $entities = "";
         $entity = $_SESSION["glpiactive_entity"];
         if ($item->isEntityAssign()) {
             /// Case of personal items : entity = -1 : create on active entity (Reminder case))
             if ($item->getEntityID() >= 0) {
                 $entity = $item->getEntityID();
             }
             if ($item->isRecursive()) {
                 $entities = getSonsOf('glpi_entities', $entity);
             } else {
                 $entities = $entity;
             }
         }
         $limit = getEntitiesRestrictRequest(" AND ", "glpi_plugin_projet_projets", '', $entities, true);
         $q = "SELECT COUNT(*)\n               FROM `glpi_plugin_projet_projets`\n               WHERE `is_deleted` = '0'\n               AND `is_template` = '0' ";
         if ($item->getType() != 'User') {
             $q .= " {$limit}";
         }
         $result = $DB->query($q);
         $nb = $DB->result($result, 0, 0);
         echo "<div class='firstbloc'>";
         if (plugin_projet_haveRight('projet', 'r') && $nb > count($used)) {
             echo "<form name='projet_form{$rand}' id='projet_form{$rand}' method='post'\n                   action='" . Toolbox::getItemTypeFormURL('PluginProjetProjet') . "'>";
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr class='tab_bg_1'>";
             echo "<td colspan='4' class='center'>";
             echo "<input type='hidden' name='entities_id' value='{$entity}'>";
             echo "<input type='hidden' name='is_recursive' value='{$is_recursive}'>";
             echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
             echo "<input type='hidden' name='items_id' value='{$ID}'>";
             if ($item->getType() == 'Ticket') {
                 echo "<input type='hidden' name='tickets_id' value='{$ID}'>";
             }
             if ($item->getType() != 'User') {
                 $projet->dropdownProjet("plugin_projet_projets_id", $entities, $used);
             } else {
                 $strict_entities = Profile_User::getUserEntities($ID, true);
                 if (!Session::haveAccessToOneOfEntities($strict_entities) && !isViewAllEntities()) {
                     $canedit = false;
                 }
                 if (countElementsInTableForEntity("glpi_plugin_projet_projets", $strict_entities) > count($used)) {
                     Dropdown::show('PluginProjetProjet', array('name' => "plugin_projet_projets_id", 'used' => $used, 'entity' => $strict_entities));
                 }
             }
             echo "</td><td class='center' width='20%'>";
             echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Associate a project', 'projet') . "\" class='submit'>";
             echo "</td>";
             echo "</tr>";
             echo "</table>";
             Html::closeForm();
         }
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $number && $withtemplate < 2) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('num_displayed' => $number);
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
     }
     echo "<table class='tab_cadre_fixe'>";
     if (Session::isMultiEntitiesMode()) {
         $colsup = 1;
     } else {
         $colsup = 0;
     }
     if ($item->getType() == "Group" || $item->getType() == "User") {
         echo "<tr><th colspan='" . (7 + $colsup) . "'>" . _n('Associated project', 'Associated projects', 2, 'projet') . ":</th></tr>";
     }
     echo "<tr>";
     if ($canedit && $number && $withtemplate < 2) {
         echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     }
     echo "<th>" . __('Name') . "</th>";
     if (Session::isMultiEntitiesMode()) {
         echo "<th>" . __('Entity') . "</th>";
     }
     echo "<th>" . __('Description') . "</th>";
     echo "<th>" . __('Progress') . "</th>";
     echo "<th>" . __('Start date') . "</th>";
     echo "<th>" . __('End date') . "</th>";
     echo "</tr>";
     $used = array();
     if ($number) {
         Session::initNavigateListItems('PluginProjetProjet', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         foreach ($projets as $data) {
             $projetID = $data["id"];
             $link = NOT_AVAILABLE;
             if ($projet->getFromDB($projetID)) {
                 $link = $projet->getLink();
             }
             Session::addToNavigateListItems('PluginProjetProjet', $projetID);
             $used[$projetID] = $projetID;
             $assocID = $data["assocID"];
             echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>";
             if ($canedit && $withtemplate < 2) {
                 echo "<td width='10'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]);
                 echo "</td>";
             }
             echo "<td class='center'>{$link}</td>";
             if (Session::isMultiEntitiesMode()) {
                 echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>";
             }
             echo "<td align='center'>" . Html::resume_text($data["description"], 250) . "</td>";
             echo "<td align='center'>" . PluginProjetProjet::displayProgressBar('100', $data["advance"]) . "</td>";
             echo "<td class='center'>" . Html::convdate($data["date_begin"]) . "</td>";
             if ($data["date_end"] <= date('Y-m-d') && !empty($data["date_end"])) {
                 echo "<td class='center'><span class='red'>" . Html::convdate($data["date_end"]) . "</span></td>";
             } else {
                 echo "<td class='center'><span class='green'>" . Html::convdate($data["date_end"]) . "</span></td>";
             }
             echo "</tr>";
             $i++;
         }
     }
     echo "</table>";
     if ($canedit && $number && $withtemplate < 2) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
示例#6
0
 function showItemFromPlugin($instID, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     $PluginProjetTask = new PluginProjetTask();
     if ($PluginProjetTask->getFromDB($instID)) {
         $plugin_projet_projets_id = $PluginProjetTask->fields["plugin_projet_projets_id"];
         $PluginProjetProjet = new PluginProjetProjet();
         $PluginProjetProjet->getFromDB($plugin_projet_projets_id);
         $canedit = $PluginProjetProjet->can($plugin_projet_projets_id, 'w');
         $query = "SELECT `items_id`, `itemtype` \n               FROM `" . $this->getTable() . "` \n               WHERE `plugin_projet_tasks_id` = '{$instID}' \n               ORDER BY `itemtype` ";
         $result = $DB->query($query);
         $number = $DB->numrows($result);
         echo "<form method='post' name='addtaskitem' action=\"./task.form.php\">";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr>";
         echo "<th colspan='" . ($canedit ? 3 : 2) . "'>" . _n('Associated item', 'Associated items', 2);
         echo "</th></tr>";
         echo "<tr><th>" . _n('Type', 'Types', 2) . "</th>";
         echo "<th>" . __('Name') . "</th>";
         if ($canedit && $this->canCreate() && $withtemplate < 2) {
             echo "<th>&nbsp;</th>";
         }
         echo "</tr>";
         $used = array();
         if ($number != "0") {
             for ($i = 0; $i < $number; $i++) {
                 $type = $DB->result($result, $i, "itemtype");
                 $items_id = $DB->result($result, $i, "items_id");
                 if (!class_exists($type)) {
                     continue;
                 }
                 $item = new $type();
                 if ($item->canView()) {
                     $table = getTableForItemType($type);
                     $query = "SELECT `" . $table . "`.*, `" . $this->getTable() . "`.`id` as items_id \n                        FROM `" . $this->getTable() . "` \n                        INNER JOIN `" . $table . "` ON (`" . $table . "`.`id` = `" . $this->getTable() . "`.`items_id`) \n                        WHERE `" . $this->getTable() . "`.`itemtype` = '" . $type . "' \n                        AND `" . $this->getTable() . "`.`items_id` = '" . $items_id . "' \n                        AND `" . $this->getTable() . "`.`plugin_projet_tasks_id` = '{$instID}' ";
                     $query .= "ORDER BY `" . $table . "`.`name` ";
                     $result_linked = $DB->query($query);
                     if ($DB->numrows($result_linked)) {
                         while ($data = $DB->fetch_assoc($result_linked)) {
                             $ID = "";
                             $itemID = $data["id"];
                             $used[] = $itemID;
                             if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) {
                                 $ID = " (" . $data["id"] . ")";
                             }
                             $itemname = $data["name"];
                             if ($type == 'User') {
                                 $itemname = getUserName($itemID);
                             }
                             $link = Toolbox::getItemTypeFormURL($type);
                             $name = "<a href=\"" . $link . "?id=" . $data["id"] . "\">" . $itemname . "{$ID}</a>";
                             echo "<tr class='tab_bg_1'>";
                             echo "<td class='center'>" . $item->getTypeName() . "</td>";
                             echo "<td class='center' " . (isset($data['is_deleted']) && $data['is_deleted'] == '1' ? "class='tab_bg_2_2'" : "") . ">" . $name . "</td>";
                             if ($canedit && $this->canCreate() && $withtemplate < 2) {
                                 echo "<td class='center tab_bg_2'>";
                                 Html::showSimpleForm($CFG_GLPI['root_doc'] . '/plugins/projet/front/task.form.php', 'deletetaskitem', _x('button', 'Delete permanently'), array('id' => $data['items_id']));
                                 echo "</td>";
                             }
                             echo "</tr>";
                         }
                     }
                 }
             }
         }
         if ($canedit && $this->canCreate() && $withtemplate < 2) {
             echo "<tr class='tab_bg_1'><td colspan='2' class='right'>";
             echo "<input type='hidden' name='plugin_projet_tasks_id' value='{$instID}'>";
             $this->dropdownTaskItems($plugin_projet_projets_id, "item_item", $used);
             echo "</td>";
             echo "<td class='center' colspan='2' class='tab_bg_2'>";
             echo "<input type='submit' name='addtaskitem' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
             echo "</td></tr>";
             echo "</table></div>";
         } else {
             echo "</table></div>";
         }
         Html::closeForm();
         echo "<br>";
     }
 }