Esempio n. 1
0
 function showForm($ID, $options = array())
 {
     global $CFG_GLPI;
     $this->initForm($ID, $options);
     $this->showTabs($options);
     $this->showFormHeader($options);
     echo "<tr class='tab_bg_1'><td>" . __('Name') . "</td>";
     echo "<td>";
     $opt = array();
     if (isset($options['helpdesk_id']) && !empty($options['helpdesk_id'])) {
         $help = new $options['helpdesk_itemtype']();
         if ($help->getFromDB($options['helpdesk_id'])) {
             $opt['value'] = $help->fields["name"];
             echo "<input type='hidden' name='helpdesk_id' value='" . $options['helpdesk_id'] . "'>";
             echo "<input type='hidden' name='helpdesk_itemtype' value='" . $options['helpdesk_itemtype'] . "'>";
         }
     }
     Html::autocompletionTextField($this, "name", $opt);
     echo "</td>";
     //Projet parent
     echo "<td>" . __('Parent project', 'projet') . "</td>";
     echo "<td>";
     PluginProjetProjet_Projet::displayLinkedProjetsTo($ID, $options['withtemplate']);
     if ($this->canCreate() && $options['withtemplate'] < 2) {
         $rand_linked_projet = mt_rand();
         echo "&nbsp;";
         if (!PluginProjetProjet_Projet::getParentProjetsTo($ID)) {
             echo "<img onClick=\"Ext.get('linkedprojet{$rand_linked_projet}').setDisplayed('block')\"\n                       title=\"" . _x('button', 'Add') . "\" alt=\"" . _x('button', 'Add') . "\"\n                       class='pointer' src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png'>";
         }
         echo "<div style='display:none' id='linkedprojet{$rand_linked_projet}'>";
         PluginProjetProjet_Projet::dropdownLinks('_link[link]', isset($values["_link"]) ? $values["_link"]['link'] : '');
         echo "&nbsp;";
         PluginProjetProjet_Projet::dropdownParent("_link[plugin_projet_projets_id_2]", isset($values["_link"]) ? $values["_link"]['plugin_projet_projets_id_2'] : '', array('id' => $this->fields["id"], 'entities_id' => $this->fields["entities_id"]));
         echo "<input type='hidden' name='_link[plugin_projet_projets_id_1]' value='{$ID}'>\n";
         echo "&nbsp;";
         echo "</div>";
         if (isset($values["_link"]) && !empty($values["_link"]['plugin_projet_projets_id_2'])) {
             echo "<script language='javascript'>Ext.get('linkedprojet{$rand_linked_projet}').\n                   setDisplayed('block');</script>";
         }
     }
     echo "</td></tr>";
     echo "<tr class='tab_bg_2'><td colspan='2'>" . _n('Responsible', 'Responsibles', 2, 'projet') . "</td>";
     echo "<td colspan='2'>" . __('Planification', 'projet') . "</td></tr>";
     echo "<tr class='tab_bg_1'><td>" . __('User') . "</td><td>";
     User::dropdown(array('value' => $this->fields["users_id"], 'entity' => $this->fields["entities_id"], 'right' => 'all'));
     echo "</td>";
     echo "<td>" . __('Start date') . "</td><td>";
     Html::showDateFormItem("date_begin", $this->fields["date_begin"], true, true);
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'><td>" . __('Group') . "</td><td>";
     Dropdown::show('Group', array('value' => $this->fields["groups_id"], 'entity' => $this->fields["entities_id"]));
     echo "</td>";
     echo "<td>" . __('End date') . "</td><td>";
     Html::showDateFormItem("date_end", $this->fields["date_end"], true, true);
     echo "</td></tr>";
     echo "<tr class='tab_bg_2'><td>" . __('Estimated duration', 'projet');
     echo "</td>";
     echo "<td>";
     $toadd = array();
     for ($i = 9; $i <= 100; $i++) {
         $toadd[] = $i * DAY_TIMESTAMP;
     }
     Dropdown::showTimeStamp("estimatedtime", array('min' => 0, 'max' => 8 * DAY_TIMESTAMP, 'value' => $this->fields["estimatedtime"], 'addfirstminutes' => false, 'inhours' => false, 'toadd' => $toadd));
     echo "</td>\n";
     echo "<td>" . __('Effective duration', 'projet') . "&nbsp;";
     Html::showToolTip(nl2br(__('Total of effective duration of project tasks', 'projet')));
     echo "</td>";
     echo "<td>" . self::getProjectForecast($ID) . "</td></tr>";
     echo "<tr class='tab_bg_2'><td>";
     echo __('Estimated duration', 'projet') . "&nbsp;" . __('in hours', 'projet');
     echo "</td><td>";
     $time = floor($this->fields["estimatedtime"]);
     $out = Html::formatNumber($time / HOUR_TIMESTAMP, 2);
     echo sprintf(_n('%s hour', '%s hours', $out), $out);
     echo "</td><td>" . __('Linked tickets duration', 'projet') . "&nbsp;";
     Html::showToolTip(nl2br(__('Total of duration of linked tickets for project', 'projet')));
     echo "</td>";
     echo "<td>" . self::getProjectDuration($ID) . "</td></tr>";
     //status
     echo "<tr class='tab_bg_1'><td>" . __('State') . "</td><td>";
     Dropdown::show('PluginProjetProjetState', array('value' => $this->fields["plugin_projet_projetstates_id"]));
     echo "</td>";
     echo "<td>" . __('Display on the global Gantt', 'projet') . "</td><td>";
     Dropdown::showYesNo("show_gantt", $this->fields["show_gantt"]);
     echo "</td></tr>";
     //advance
     echo "<tr class='tab_bg_1'><td>" . __('Progress') . "</td><td>";
     $advance = floor($this->fields["advance"]);
     echo "<select name='advance'>";
     for ($i = 0; $i < 101; $i += 5) {
         echo "<option value='{$i}' ";
         if ($advance == $i) {
             echo "selected";
         }
         echo " >{$i}</option>";
     }
     echo "</select> %";
     echo "<td>" . __('Associable to a ticket') . "</td><td>";
     Dropdown::showYesNo('is_helpdesk_visible', $this->fields['is_helpdesk_visible']);
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'><td colspan='4'>" . __('Comments') . "</td></tr>";
     echo "<tr class='tab_bg_1'><td colspan='4'>";
     $value = $this->fields["comment"];
     if (isset($options['helpdesk_id']) && !empty($options['helpdesk_id'])) {
         $help = new $options['helpdesk_itemtype']();
         if ($help->getFromDB($options['helpdesk_id'])) {
             $value = $help->fields["content"];
         }
     }
     echo "<textarea cols='130' rows='4' name='comment' >" . $value . "</textarea>";
     echo "<input type='hidden' name='withtemplate' value='" . $options['withtemplate'] . "'>";
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'><td colspan='4'>" . __('Description') . "</td></tr>";
     echo "<tr class='tab_bg_1'><td colspan='4'>";
     echo "<textarea cols='130' rows='4' name='description' >" . $this->fields["description"] . "</textarea>";
     echo "</td></tr>";
     echo "<tr class='tab_bg_1 center'>";
     echo "<td>" . __('Send email', 'projet') . "</td><td>";
     echo "<input type='checkbox' name='send_notification' checked = true";
     echo " value='1'>";
     echo "</td>";
     echo "<td colspan='2'></td>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>";
     if ((!isset($options['withtemplate']) || $options['withtemplate'] == 0) && !empty($this->fields['template_name'])) {
         echo "<span class='small_space'>";
         printf(__('Created from the template %s'), $this->fields['template_name']);
         echo "</span>";
     } else {
         echo "&nbsp;";
     }
     echo "</td><td colspan='4'>";
     if (isset($options['withtemplate']) && $options['withtemplate']) {
         //TRANS: %s is the datetime of insertion
         printf(__('Created on %s'), Html::convDateTime($_SESSION["glpi_currenttime"]));
     } else {
         //TRANS: %s is the datetime of update
         printf(__('Last update on %s'), Html::convDateTime($this->fields["date_mod"]));
     }
     echo "</td></tr>\n";
     echo "</tr>";
     $this->showFormButtons($options);
     $this->addDivForTabs();
     return true;
 }
 function getDatasForTemplate($event, $options = array())
 {
     global $CFG_GLPI, $DB;
     if ($event == 'AlertExpiredTasks') {
         $this->datas['##projet.entity##'] = Dropdown::getDropdownName('glpi_entities', $options['entities_id']);
         $this->datas['##lang.projet.entity##'] = __('Entity');
         $this->datas['##projet.action##'] = __('Outdated tasks', 'projet');
         $this->datas['##lang.task.name##'] = __('Name');
         $this->datas['##lang.task.type##'] = __('Type');
         $this->datas['##lang.task.users##'] = __('User');
         $this->datas['##lang.task.groups##'] = __('Group');
         $this->datas['##lang.task.datebegin##'] = __('Start date');
         $this->datas['##lang.task.dateend##'] = __('End date');
         $this->datas['##lang.task.planned##'] = __('Used for planning', 'projet');
         $this->datas['##lang.task.realtime##'] = __('Effective duration', 'projet');
         $this->datas['##lang.task.comment##'] = __('Comments');
         $this->datas['##lang.task.projet##'] = PluginProjetProjet::getTypeName(1);
         foreach ($options['tasks'] as $id => $task) {
             $tmp = array();
             $tmp['##task.name##'] = $task['name'];
             $tmp['##task.type##'] = Dropdown::getDropdownName('glpi_plugin_projet_tasktypes', $task['plugin_projet_tasktypes_id']);
             $tmp['##task.users##'] = Html::clean(getUserName($task['users_id']));
             $tmp['##task.groups##'] = Dropdown::getDropdownName('glpi_groups', $task['groups_id']);
             $restrict = " `plugin_projet_tasks_id` = '" . $task['id'] . "' ";
             $plans = getAllDatasFromTable("glpi_plugin_projet_taskplannings", $restrict);
             if (!empty($plans)) {
                 foreach ($plans as $plan) {
                     $tmp['##task.datebegin##'] = Html::convDateTime($plan["begin"]);
                     $tmp['##task.dateend##'] = Html::convDateTime($plan["end"]);
                 }
             } else {
                 $tmp['##task.datebegin##'] = '';
                 $tmp['##task.dateend##'] = '';
             }
             $tmp['##task.planned##'] = '';
             $tmp['##task.realtime##'] = Ticket::getActionTime($task["actiontime"]);
             $comment = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br/>", $task['comment']));
             $tmp['##task.comment##'] = Html::clean($comment);
             $tmp['##task.projet##'] = Dropdown::getDropdownName('glpi_plugin_projet_projets', $task['plugin_projet_projets_id']);
             $this->datas['tasks'][] = $tmp;
         }
     } else {
         $events = $this->getAllEvents();
         $this->datas['##lang.projet.title##'] = $events[$event];
         $this->datas['##lang.projet.entity##'] = __('Entity');
         $this->datas['##projet.entity##'] = Dropdown::getDropdownName('glpi_entities', $this->obj->getField('entities_id'));
         $this->datas['##projet.id##'] = $this->obj->getField("id");
         $this->datas['##lang.projet.name##'] = __('Name');
         $this->datas['##projet.name##'] = $this->obj->getField("name");
         $this->datas['##lang.projet.datebegin##'] = __('Start date');
         $this->datas['##projet.datebegin##'] = Html::convDate($this->obj->getField('date_begin'));
         $this->datas['##lang.projet.dateend##'] = __('End date');
         $this->datas['##projet.dateend##'] = Html::convDate($this->obj->getField('date_end'));
         $this->datas['##lang.projet.users##'] = __('User');
         $this->datas['##projet.users##'] = Html::clean(getUserName($this->obj->getField("users_id")));
         $this->datas['##lang.projet.groups##'] = __('Group');
         $this->datas['##projet.groups##'] = Dropdown::getDropdownName('glpi_groups', $this->obj->getField('groups_id'));
         $this->datas['##lang.projet.status##'] = __('State');
         $this->datas['##projet.status##'] = Dropdown::getDropdownName('glpi_plugin_projet_projetstates', $this->obj->getField('plugin_projet_projetstates_id'));
         $this->datas['##lang.projet.parent##'] = __('Parent project', 'projet');
         $this->datas['##projet.parent##'] = PluginProjetProjet_Projet::displayLinkedProjetsTo($this->obj->getField('id'), true);
         $this->datas['##lang.projet.advance##'] = __('Progress');
         $this->datas['##projet.advance##'] = PluginProjetProjet::displayProgressBar('100', $this->obj->getField('advance'), array('simple' => true));
         $this->datas['##lang.projet.gantt##'] = __('Display on the global Gantt', 'projet');
         $this->datas['##projet.gantt##'] = Dropdown::getYesNo($this->obj->getField('show_gantt'));
         $this->datas['##lang.projet.comment##'] = __('Comments');
         $comment = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br/>", $this->obj->getField("comment")));
         $this->datas['##projet.comment##'] = Html::clean($comment);
         $this->datas['##lang.projet.description##'] = __('Description');
         $description = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br/>", $this->obj->getField("description")));
         $this->datas['##projet.description##'] = Html::clean($description);
         $this->datas['##lang.projet.helpdesk##'] = __('Associable to a ticket');
         $this->datas['##projet.helpdesk##'] = Dropdown::getYesNo($this->obj->getField('is_helpdesk_visible'));
         $this->datas['##lang.projet.url##'] = __('URL');
         $this->datas['##projet.url##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=plugin_projet_" . $this->obj->getField("id"));
         //old values infos
         if (isset($this->target_object->oldvalues) && !empty($this->target_object->oldvalues) && $event == 'update') {
             $this->datas['##lang.update.title##'] = __('Modifications', 'projet');
             $tmp = array();
             if (isset($this->target_object->oldvalues['name'])) {
                 if (empty($this->target_object->oldvalues['name'])) {
                     $tmp['##update.name##'] = "---";
                 } else {
                     $tmp['##update.name##'] = $this->target_object->oldvalues['name'];
                 }
             }
             if (isset($this->target_object->oldvalues['date_begin'])) {
                 if (empty($this->target_object->oldvalues['date_begin'])) {
                     $tmp['##update.datebegin##'] = "---";
                 } else {
                     $tmp['##update.datebegin##'] = Html::convDate($this->target_object->oldvalues['date_begin']);
                 }
             }
             if (isset($this->target_object->oldvalues['date_end'])) {
                 if (empty($this->target_object->oldvalues['date_end'])) {
                     $tmp['##update.dateend##'] = "---";
                 } else {
                     $tmp['##update.dateend##'] = Html::convDate($this->target_object->oldvalues['date_end']);
                 }
             }
             if (isset($this->target_object->oldvalues['users_id'])) {
                 if (empty($this->target_object->oldvalues['users_id'])) {
                     $tmp['##update.users##'] = "---";
                 } else {
                     $tmp['##update.users##'] = Html::clean(getUserName($this->target_object->oldvalues['users_id']));
                 }
             }
             if (isset($this->target_object->oldvalues['groups_id'])) {
                 if (empty($this->target_object->oldvalues['groups_id'])) {
                     $tmp['##update.groups##'] = "---";
                 } else {
                     $tmp['##update.groups##'] = Dropdown::getDropdownName('glpi_groups', $this->target_object->oldvalues['groups_id']);
                 }
             }
             if (isset($this->target_object->oldvalues['plugin_projet_projetstates_id'])) {
                 if (empty($this->target_object->oldvalues['plugin_projet_projetstates_id'])) {
                     $tmp['##update.status##'] = "---";
                 } else {
                     $tmp['##update.status##'] = Dropdown::getDropdownName('glpi_plugin_projet_projetstates', $this->target_object->oldvalues['plugin_projet_projetstates_id']);
                 }
             }
             if (isset($this->target_object->oldvalues['plugin_projet_projets_id'])) {
                 if (empty($this->target_object->oldvalues['plugin_projet_projets_id'])) {
                     $tmp['##update.plugin_projet_projets_id##'] = "---";
                 } else {
                     $tmp['##update.plugin_projet_projets_id##'] = Dropdown::getDropdownName('glpi_plugin_projet_projets', $this->target_object->oldvalues['plugin_projet_projets_id']);
                 }
             }
             if (isset($this->target_object->oldvalues['advance'])) {
                 if (empty($this->target_object->oldvalues['advance'])) {
                     $tmp['##update.advance##'] = "---";
                 } else {
                     $tmp['##update.advance##'] = PluginProjetProjet::displayProgressBar('100', $this->target_object->oldvalues['advance'], array('simple' => true));
                 }
             }
             if (isset($this->target_object->oldvalues['comment'])) {
                 if (empty($this->target_object->oldvalues['comment'])) {
                     $tmp['##update.comment##'] = "---";
                 } else {
                     $comment = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br/>", $this->target_object->oldvalues['comment']));
                     $tmp['##update.comment##'] = Html::clean($comment);
                 }
             }
             if (isset($this->target_object->oldvalues['description'])) {
                 if (empty($this->target_object->oldvalues['description'])) {
                     $tmp['##update.description##'] = "---";
                 } else {
                     $description = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br/>", $this->target_object->oldvalues['description']));
                     $tmp['##update.description##'] = Html::clean($description);
                 }
             }
             if (isset($this->target_object->oldvalues['show_gantt'])) {
                 if (empty($this->target_object->oldvalues['show_gantt'])) {
                     $tmp['##update.gantt##'] = "---";
                 } else {
                     $tmp['##update.gantt##'] = Dropdown::getYesNo($this->target_object->oldvalues['show_gantt']);
                 }
             }
             if (isset($this->target_object->oldvalues['is_helpdesk_visible'])) {
                 if (empty($this->target_object->oldvalues['is_helpdesk_visible'])) {
                     $tmp['##update.helpdesk##'] = "---";
                 } else {
                     $tmp['##update.helpdesk##'] = Dropdown::getYesNo($this->target_object->oldvalues['is_helpdesk_visible']);
                 }
             }
             $this->datas['updates'][] = $tmp;
         }
         // Projet followup
         $restrict = "`plugin_projet_projets_id`='" . $this->obj->getField('id') . "'";
         if (isset($options['followups_id']) && $options['followups_id']) {
             $restrict .= " AND `glpi_plugin_projet_followups`.`id` = '" . $options['followups_id'] . "'";
         }
         $restrict .= " ORDER BY `date` DESC";
         $followups = getAllDatasFromTable('glpi_plugin_projet_followups', $restrict);
         $this->datas['##lang.followup.description##'] = __('Content');
         $this->datas['##lang.followup.date##'] = __('Date');
         $this->datas['##lang.followup.recipient##'] = __('Writer');
         if (!empty($followups)) {
             $this->datas['##lang.followup.title##'] = _n('Associated followup', 'Associated followups', 2, 'projet');
             foreach ($followups as $followup) {
                 $tmp = array();
                 $tmp['##followup.recipient##'] = Html::clean(getUserName($followup['users_id']));
                 $tmp['##followup.date##'] = Html::convDate($followup['date']);
                 $content = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br/>", $followup['content']));
                 $tmp['##followup.description##'] = Html::clean($content);
                 $this->datas['followups'][] = $tmp;
             }
         }
         //task infos
         $restrict = "`plugin_projet_projets_id`='" . $this->obj->getField('id') . "'";
         if (isset($options['tasks_id']) && $options['tasks_id']) {
             $restrict .= " AND `glpi_plugin_projet_tasks`.`id` = '" . $options['tasks_id'] . "'";
         }
         $restrict .= " ORDER BY `name` DESC";
         $tasks = getAllDatasFromTable('glpi_plugin_projet_tasks', $restrict);
         $this->datas['##lang.task.title##'] = _n('Associated task', 'Associated tasks', 2, 'projet');
         $this->datas['##lang.task.name##'] = __('Name');
         $this->datas['##lang.task.users##'] = __('User');
         $this->datas['##lang.task.groups##'] = __('Group');
         $this->datas['##lang.task.contacts##'] = __('Supplier');
         $this->datas['##lang.task.type##'] = __('Type');
         $this->datas['##lang.task.status##'] = __('State');
         $this->datas['##lang.task.advance##'] = __('Progress');
         $this->datas['##lang.task.priority##'] = __('Priority');
         $this->datas['##lang.task.comment##'] = __('Comments');
         $this->datas['##lang.task.sub##'] = __('Results');
         $this->datas['##lang.task.others##'] = __('Others participants', 'projet');
         $this->datas['##lang.task.affect##'] = __('Affected people', 'projet');
         $this->datas['##lang.task.parenttask##'] = __('Parent task', 'projet');
         $this->datas['##lang.task.gantt##'] = __('Display on the Gantt', 'projet');
         $this->datas['##lang.task.depends##'] = __('Dependent', 'projet');
         $this->datas['##lang.task.realtime##'] = __('Effective duration', 'projet');
         $this->datas['##lang.task.location##'] = __('Location');
         $this->datas['##lang.task.projet##'] = _n('Project', 'Projects', 2, 'projet');
         if (!empty($tasks)) {
             $this->datas['##task.title##'] = _n('Associated task', 'Associated tasks', 2, 'projet');
             foreach ($tasks as $task) {
                 $tmp = array();
                 $tmp['##task.name##'] = $task['name'];
                 $tmp['##task.users##'] = Html::clean(getUserName($task['users_id']));
                 $tmp['##task.groups##'] = Dropdown::getDropdownName('glpi_groups', $task['groups_id']);
                 $tmp['##task.contacts##'] = Dropdown::getDropdownName('glpi_contacts', $task['contacts_id']);
                 $tmp['##task.type##'] = Dropdown::getDropdownName('glpi_plugin_projet_tasktypes', $task['plugin_projet_tasktypes_id']);
                 $tmp['##task.status##'] = Dropdown::getDropdownName('glpi_plugin_projet_taskstates', $task['plugin_projet_taskstates_id']);
                 $tmp['##task.advance##'] = PluginProjetProjet::displayProgressBar('100', $task['advance'], array('simple' => true));
                 $tmp['##task.priority##'] = Ticket::getPriorityName($task['priority']);
                 $comment = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br/>", $task['comment']));
                 $tmp['##task.comment##'] = Html::clean($comment);
                 $sub = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br/>", $task['sub']));
                 $tmp['##task.sub##'] = Html::clean($sub);
                 $others = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br/>", $task['others']));
                 $tmp['##task.others##'] = Html::clean($others);
                 $affect = stripslashes(str_replace(array('\\r\\n', '\\n', '\\r'), "<br/>", $task['affect']));
                 $tmp['##task.affect##'] = Html::clean($affect);
                 $tmp['##task.parenttask##'] = PluginProjetTask_Task::displayLinkedProjetTasksTo($task['id'], true);
                 $tmp['##task.gantt##'] = Dropdown::getYesNo($task['show_gantt']);
                 $tmp['##task.depends##'] = Dropdown::getYesNo($task['depends']);
                 $tmp['##task.realtime##'] = Ticket::getActionTime($task["actiontime"]);
                 $tmp['##task.location##'] = Dropdown::getDropdownName('glpi_locations', $task['locations_id']);
                 $tmp['##task.projet##'] = Dropdown::getDropdownName('glpi_plugin_projet_projets', $task['plugin_projet_projets_id']);
                 $this->datas['tasks'][] = $tmp;
             }
         }
     }
 }