/** * Display linked projets to a projet * * @param $ID ID of the projet id * * @return nothing display **/ static function displayLinkedProjetsTo($ID, $withtemplate = '', $notif = false) { global $DB, $CFG_GLPI; $projets = self::getParentProjetsTo($ID); $canupdate = plugin_projet_haveRight('projet', 'w'); $projet = new PluginProjetProjet(); if (is_array($projets) && count($projets)) { foreach ($projets as $linkID => $data) { if ($notif) { return Dropdown::getDropdownName("glpi_plugin_projet_projets", $data['plugin_projet_projets_id']); } else { echo self::getLinkName($data['link']) . " "; if (!$_SESSION['glpiis_ids_visible']) { echo __('ID') . " " . $data['plugin_projet_projets_id'] . " : "; } if ($projet->getFromDB($data['plugin_projet_projets_id'])) { echo $projet->getLink(); if ($canupdate && $withtemplate < 2) { echo " "; Html::showSimpleForm($CFG_GLPI['root_doc'] . '/plugins/projet/front/projet.form.php', 'delete_link', _x('button', 'Delete permanently'), array('delete_link' => 'delete_link', 'id' => $linkID, 'plugin_projet_projets_id' => $ID), $CFG_GLPI["root_doc"] . "/pics/delete.png"); } } } } } }
function showForm($ID, $options = array()) { global $CFG_GLPI; if (!$this->canView()) { return false; } $plugin_projet_projets_id = -1; if (isset($options['plugin_projet_projets_id'])) { $plugin_projet_projets_id = $options['plugin_projet_projets_id']; } $item = new PluginProjetProjet(); if ($item->getFromDB($plugin_projet_projets_id)) { $entities_id = $item->fields["entities_id"]; } if ($ID > 0) { $this->check($ID, 'r'); $plugin_projet_projets_id = $this->fields["plugin_projet_projets_id"]; } else { // Create item $input = array('plugin_projet_projets_id' => $plugin_projet_projets_id, 'entities_id' => $entities_id); $this->check(-1, 'w', $input); } $options["colspan"] = 4; $this->showTabs($options); $this->showFormHeader($options); echo "<input type='hidden' name='plugin_projet_projets_id' value='{$plugin_projet_projets_id}'>"; echo "<tr class='tab_bg_2'>"; echo "<td colspan='2'>" . PluginProjetProjet::getTypeName(2) . "</td><td colspan='2'>"; $link = NOT_AVAILABLE; if ($item->getFromDB($plugin_projet_projets_id)) { $link = $item->getLink(); } echo $link; echo "</td>"; echo "<td>"; echo __('Parent task', 'projet') . "</td><td>"; PluginProjetTask_Task::displayLinkedProjetTasksTo($ID); if ($this->canCreate()) { $rand_linked_projettask = mt_rand(); echo " "; if (!PluginProjetTask_Task::getParentProjetTasksTo($ID)) { echo "<img onClick=\"Ext.get('linkedprojettask{$rand_linked_projettask}').setDisplayed('block')\"\n title=\"" . __('Add') . "\" alt=\"" . __('Add') . "\"\n class='pointer' src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png'>"; } echo "<div style='display:none' id='linkedprojettask{$rand_linked_projettask}'>"; PluginProjetTask_Task::dropdownLinks('_link[link]', isset($values["_link"]) ? $values["_link"]['link'] : ''); echo " "; PluginProjetTask_Task::dropdownParent("_link[plugin_projet_tasks_id_2]", isset($values["_link"]) ? $values["_link"]['plugin_projet_tasks_id_2'] : '', array('id' => $this->fields["id"], 'entities_id' => $this->fields["entities_id"], 'plugin_projet_projets_id' => $plugin_projet_projets_id)); echo "<input type='hidden' name='_link[plugin_projet_tasks_id_1]' value='{$ID}'>\n"; echo " "; echo "</div>"; if (isset($values["_link"]) && !empty($values["_link"]['plugin_projet_tasks_id_2'])) { echo "<script language='javascript'>Ext.get('linkedprojettask{$rand_linked_projettask}').\n setDisplayed('block');</script>"; } } echo "</td>"; echo "<td>"; echo __('Dependent', 'projet') . "</td><td>"; Dropdown::showYesNo("depends", $this->fields["depends"]); echo " "; echo " <img alt='' src='" . $CFG_GLPI["root_doc"] . "/pics/aide.png' onmouseout=\"cleanhide('commentsup')\" onmouseover=\"cleandisplay('commentsup')\">"; echo "<span class='over_link' id='commentsup'>" . nl2br(__('Depends on the tasks children', 'projet')) . "</span>"; echo "</td>"; echo "</tr>"; $width_left = $width_right = "50%"; $cols = 60; $rows = 4; echo "<tr class='tab_bg_1'>"; echo "<td colspan='2'>"; echo __('Name') . "</td><td colspan='2'>"; Html::autocompletionTextField($this, "name", array('size' => "30")); echo "<td >"; echo _n('Type', 'Types', 1) . "</td><td>"; Dropdown::show('PluginProjetTaskType', array('value' => $this->fields["plugin_projet_tasktypes_id"])); echo "</td>"; echo "<td>"; echo __('State') . "</td><td>"; if ($ID > 0) { $this->dropdownState("plugin_projet_taskstates_id", $this->fields["plugin_projet_taskstates_id"], array('depends' => $this->fields["depends"], 'id' => $this->fields["id"], 'plugin_projet_projets_id' => $plugin_projet_projets_id)); } else { Dropdown::show('PluginProjetTaskState', array('value' => $this->fields["plugin_projet_taskstates_id"])); } echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='2'>"; echo _n('Location', 'Locations', 1) . "</td><td colspan='2'>"; Dropdown::show('Location', array('value' => $this->fields["locations_id"])); echo "</td>"; echo "<td>"; echo __('Priority') . "</td><td>"; Ticket::dropdownPriority(array('value' => $this->fields["priority"], 'withmajor' => true)); echo "</td>"; echo "<td>" . __('Progress') . "</td><td>"; $advance = floor($this->fields["advance"]); echo "<select name='advance'>"; if (empty($ID) || $this->fields["depends"] == 0) { for ($i = 0; $i < 101; $i += 5) { echo "<option value='{$i}' "; if ($advance == $i) { echo "selected"; } echo " >{$i}</option>"; } } else { if ($this->fields["depends"] != 0) { for ($i = 0; $i < 100; $i += 5) { echo "<option value='{$i}' "; if ($advance == $i) { echo "selected"; } echo " >{$i}</option>"; } } } echo "</select> %"; echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_3'>"; echo "<td colspan='4'>" . __('Assigned to') . "</td>"; echo "<td colspan='4'>" . __('Planification', 'projet') . "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='4' width='{$width_left}'>"; echo "<table width='100%'>"; echo "<tr>"; echo "<td>" . _n('User', 'Users', 1) . "</td><td>"; $this->dropdownItems($this->fields["plugin_projet_projets_id"], "users_id", array(), $this->fields["users_id"], 'User'); echo "</td></tr>"; echo "<tr><td>" . _n('Group', 'Groups', 1) . "</td><td>"; $this->dropdownItems($this->fields["plugin_projet_projets_id"], "groups_id", array(), $this->fields["groups_id"], 'Group'); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>" . _n('Supplier', 'Suppliers', 1) . "</td><td>"; $this->dropdownItems($this->fields["plugin_projet_projets_id"], "contacts_id", array(), $this->fields["contacts_id"], 'Supplier'); echo "</td>"; echo "</tr>"; echo "</table>"; echo "</td>"; echo "<td colspan='4' width='{$width_right}' valign='top'>"; echo "<table width='100%'>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Effective duration', 'projet') . "</td><td>"; $toadd = array(); for ($i = 9; $i <= 100; $i++) { $toadd[] = $i * HOUR_TIMESTAMP; } Dropdown::showTimeStamp("actiontime", array('min' => 0, 'max' => 8 * HOUR_TIMESTAMP, 'value' => $this->fields["actiontime"], 'addfirstminutes' => true, 'inhours' => true, 'toadd' => $toadd)); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Planning') . "</td>"; echo "<td>"; $plan = new PluginProjetTaskPlanning(); $plan->showFormForTask($plugin_projet_projets_id, $this); echo "</td></tr>"; echo "</table>"; echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_3'>"; $colspan = '8'; if (!empty($ID)) { $colspan = '4'; } echo "<td colspan='" . $colspan . "'>" . __('Description') . "</td>"; if (!empty($ID)) { echo "<td colspan='4'>" . __('Results') . "</td>"; } echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='" . $colspan . "' width='{$width_left}'>"; echo "<table width='100%'>"; echo "<tr>"; echo "<td>"; echo "<textarea name='comment' cols='{$cols}' rows='{$rows}'>" . $this->fields["comment"] . "</textarea>"; echo "</td></tr>"; echo "</table>"; if (!empty($ID)) { echo "</td>"; echo "<td colspan='4' width='{$width_left}'>"; echo "<table width='100%'>"; echo "<tr>"; echo "<td>"; echo "<textarea name='sub' cols='{$cols}' rows='{$rows}'>" . $this->fields["sub"] . "</textarea>"; echo "</td>"; echo "</tr>"; echo "</table>"; echo "</td>"; } echo "</tr>"; echo "<tr class='tab_bg_3'>"; echo "<td colspan='4'>" . __('Others participants', 'projet') . "</td>"; echo "<td colspan='4'>" . __('Affected people', 'projet') . "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='4' width='{$width_left}'>"; echo "<table width='100%'>"; echo "<tr>"; echo "<td>"; echo "<textarea name='others' cols='{$cols}' rows='2'>" . $this->fields["others"] . "</textarea>"; echo "</td>"; echo "</tr>"; echo "</table>"; echo "</td>"; echo "<td colspan='4' width='{$width_right}' valign='top'>"; echo "<table width='100%'>"; echo "<tr>"; echo "<td>"; echo "<textarea name='affect' cols='{$cols}' rows='2'>" . $this->fields["affect"] . "</textarea>"; echo "</td>"; echo "</tr>"; echo "</table>"; echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='2'>" . __('Send email', 'projet') . "</td><td colspan='2'>"; echo "<input type='checkbox' name='send_notification'"; echo " value='1'>"; echo "</td>"; echo "<td colspan='4' align='center'>" . __('Display on the Gantt', 'projet') . " "; Dropdown::showYesNo("show_gantt", $this->fields["show_gantt"]); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='8' align='center'>"; $datestring = __('Last update') . ": "; $date = Html::convDateTime($this->fields["date_mod"]); echo $datestring . $date . "</td>"; echo "</tr>"; $this->showFormButtons($options); $this->addDivForTabs(); return true; }
/** * 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>"; }