Ejemplo n.º 1
0
 /**
  * Show for PDF an resources : tasks informations
  * 
  * @param $pdf object for the output
  * @param $ID of the resources
  */
 static function pdfForProjet(PluginPdfSimplePDF $pdf, PluginProjetProjet $appli)
 {
     global $DB;
     $ID = $appli->fields['id'];
     if (!$appli->can($ID, "r")) {
         return false;
     }
     if (!plugin_projet_haveRight("projet", "r")) {
         return false;
     }
     $query = "SELECT * \n               FROM `glpi_plugin_projet_tasks` \n               WHERE `plugin_projet_projets_id` = '{$ID}'\n               AND `is_deleted` ='0'";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = $j = 0;
     $pdf->setColumnsSize(100);
     if ($number > 0) {
         $pdf->displayTitle('<b>' . _n('Associated task', 'Associated tasks', 2, 'projet') . '</b>');
         $pdf->setColumnsSize(14, 14, 14, 14, 16, 14, 14);
         $pdf->displayTitle('<b><i>' . __('Name'), _n('Type', 'Types', 1), __('Description'), __('Duration'), __('Planning'), _n('User', 'Users', 1), _n('Group', 'Groups', 1) . '</i></b>');
         $i++;
         while ($j < $number) {
             $tID = $DB->result($result, $j, "id");
             $actiontime_ID = $DB->result($result, $j, "actiontime");
             $actiontime = '';
             $units = Toolbox::getTimestampTimeUnits($actiontime_ID);
             $hour = $units['hour'];
             $minute = $units['minute'];
             if ($hour) {
                 $actiontime = sprintf(__('%1$d hours'), $hour);
             }
             if ($minute || !$hour) {
                 $actiontime .= sprintf(__('%1$d minutes'), $minute);
             }
             $restrict = " `plugin_projet_tasks_id` = '" . $tID . "' ";
             $plans = getAllDatasFromTable("glpi_plugin_projet_taskplannings", $restrict);
             if (!empty($plans)) {
                 foreach ($plans as $plan) {
                     $planification = Html::convDateTime($plan["begin"]) . "&nbsp;->&nbsp;" . Html::convDateTime($plan["end"]);
                 }
             } else {
                 $planification = __('None');
             }
             $users_id = $DB->result($result, $j, "users_id");
             $managers = Html::clean(getUserName($users_id));
             $name = $DB->result($result, $j, "name");
             $task_type = $DB->result($result, $j, "plugin_projet_tasktypes_id");
             $comment = $DB->result($result, $j, "comment");
             $groups_id = $DB->result($result, $j, "groups_id");
             $pdf->displayLine(Html::clean($name), Html::clean(Dropdown::getDropdownName("glpi_plugin_projet_tasktypes", $task_type)), $comment, $actiontime, Html::clean($planification), $managers, Html::clean(Dropdown::getDropdownName("glpi_groups", $groups_id)));
             $j++;
         }
     } else {
         $pdf->displayLine(__('No item found'));
     }
     $pdf->displaySpace();
 }
Ejemplo n.º 2
0
 /**
  * Show for PDF an projet
  * 
  * @param $pdf object for the output
  * @param $ID of the projet
  */
 static function pdfGanttForProjet(PluginPdfSimplePDF $pdf, PluginProjetProjet $appli)
 {
     global $CFG_GLPI, $gtitle, $gdata, $gconst, $gdate_begin, $gdate_end;
     $ID = $appli->fields['id'];
     if (!$appli->can($ID, "r")) {
         return false;
     }
     if (!plugin_projet_haveRight("projet", "r")) {
         return false;
     }
     //nom
     $gantt_p_name = $appli->fields["name"];
     //type de gantt
     $int = hexdec(PluginProjetProjetState::getStatusColor($appli->fields["plugin_projet_projetstates_id"]));
     $gantt_p_bgcolor = array(0xff & $int >> 0x10, 0xff & $int >> 0x8, 0xff & $int);
     $gantt_p_date_begin = date("Y-m-d");
     $gantt_p_date_end = date("Y-m-d");
     if (!empty($appli->fields["date_begin"])) {
         $gantt_p_date_begin = $appli->fields["date_begin"];
     }
     if (!empty($appli->fields["date_end"])) {
         $gantt_p_date_end = $appli->fields["date_end"];
     }
     $gdata[] = array("type" => 'group', "projet" => $ID, "name" => $gantt_p_name, "date_begin" => $gantt_p_date_begin, "date_end" => $gantt_p_date_end, "advance" => $appli->fields["advance"], "bg_color" => $gantt_p_bgcolor);
     PluginProjetTask::showTaskTreeGantt(array('plugin_projet_projets_id' => $ID));
     if (!empty($gdate_begin) && !empty($gdate_end)) {
         $gtitle = $gtitle . "<DateBeg> / <DateEnd>";
         $gdate_begin = date("Y", $gdate_begin) . "-" . date("m", $gdate_begin) . "-" . date("d", $gdate_begin);
         $gdate_end = date("Y", $gdate_end) . "-" . date("m", $gdate_end) . "-" . date("d", $gdate_end);
     }
     $ImgName = self::writeGantt($gtitle, $gdata, $gconst, $gdate_begin, $gdate_end);
     $image = GLPI_PLUGIN_DOC_DIR . "/projet/" . $ImgName;
     $pdf->newPage();
     $pdf->setColumnsSize(100);
     $pdf->displayTitle('<b>' . __('Gantt', 'projet') . '</b>');
     $size = GetImageSize($image);
     $src_w = $size[0];
     $src_h = $size[1];
     $pdf->addPngFromFile($image, $src_w / 2, $src_h / 2);
     $pdf->displaySpace();
     unlink($image);
 }
Ejemplo n.º 3
0
 /**
  * Show for PDF an projet - associated devices
  * 
  * @param $pdf object for the output
  * @param $appli object of the projet
  */
 static function pdfForProjet(PluginPdfSimplePDF $pdf, PluginProjetProjet $appli, $material = false)
 {
     global $DB, $CFG_GLPI;
     $ID = $appli->fields['id'];
     if (!$appli->can($ID, "r")) {
         return false;
     }
     if (!plugin_projet_haveRight("projet", "r")) {
         return false;
     }
     $pdf->setColumnsSize(100);
     if ($material) {
         $pdf->displayTitle('<b>' . _n('Associated item', 'Associated items', 2) . '</b>');
     } else {
         $pdf->displayTitle('<b>' . __('Unknown project task', 'projet') . '</b>');
     }
     if ($material) {
         $select = "'User','Group','Supplier','Contract'";
         $in = "NOT IN";
     } else {
         $select = "'User','Group','Supplier'";
         $in = "IN";
     }
     $query = "SELECT DISTINCT `itemtype` \n               FROM `glpi_plugin_projet_projets_items` \n               WHERE `plugin_projet_projets_id` = '{$ID}' \n               AND `itemtype` {$in} (" . $select . ")\n               ORDER BY `itemtype` ";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     if (Session::isMultiEntitiesMode()) {
         $pdf->setColumnsSize(12, 27, 25, 18, 18);
         $pdf->displayTitle('<b><i>' . _n('Type', 'Types', 2), __('Name'), __('Entity'), __('Serial number'), __('Inventory number') . '</i></b>');
     } else {
         $pdf->setColumnsSize(25, 31, 22, 22);
         $pdf->displayTitle('<b><i>' . _n('Type', 'Types', 2), __('Name'), __('Serial number'), __('Inventory number') . '</i></b>');
     }
     if (!$number) {
         $pdf->displayLine(__('No item found'));
     } else {
         for ($i = 0; $i < $number; $i++) {
             $type = $DB->result($result, $i, "itemtype");
             if (!($item = getItemForItemtype($type))) {
                 continue;
             }
             if ($item->canView()) {
                 $column = "name";
                 $table = getTableForItemType($type);
                 $items = new $type();
                 $query = "SELECT `" . $table . "`.*, `glpi_entities`.`id` AS entity " . " FROM `glpi_plugin_projet_projets_items`, `" . $table . "` LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = `" . $table . "`.`entities_id`) " . " WHERE `" . $table . "`.`id` = `glpi_plugin_projet_projets_items`.`items_id` \n                  AND `glpi_plugin_projet_projets_items`.`itemtype` = '{$type}' \n                  AND `glpi_plugin_projet_projets_items`.`plugin_projet_projets_id` = '{$ID}' ";
                 if ($type != 'User') {
                     $query .= getEntitiesRestrictRequest(" AND ", $table, '', '', $items->maybeRecursive());
                 }
                 if ($items->maybeTemplate()) {
                     $query .= " AND `" . $table . "`.`is_template` = '0'";
                 }
                 $query .= " ORDER BY `glpi_entities`.`completename`, `" . $table . "`.`{$column}`";
                 if ($result_linked = $DB->query($query)) {
                     if ($DB->numrows($result_linked)) {
                         while ($data = $DB->fetch_assoc($result_linked)) {
                             if (!$items->getFromDB($data["id"])) {
                                 continue;
                             }
                             $items_id_display = "";
                             if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) {
                                 $items_id_display = " (" . $data["id"] . ")";
                             }
                             if ($type == 'User') {
                                 $name = Html::clean(getUserName($data["id"])) . $items_id_display;
                             } else {
                                 $name = $data["name"] . $items_id_display;
                             }
                             if ($type != 'User') {
                                 $entity = Html::clean(Dropdown::getDropdownName("glpi_entities", $data['entity']));
                             } else {
                                 $entity = "-";
                             }
                             if (Session::isMultiEntitiesMode()) {
                                 $pdf->setColumnsSize(12, 27, 25, 18, 18);
                                 $pdf->displayLine($items->getTypeName(), $name, $entity, isset($data["serial"]) ? "" . $data["serial"] . "" : "-", isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-");
                             } else {
                                 $pdf->setColumnsSize(25, 31, 22, 22);
                                 $pdf->displayTitle($items->getTypeName(), $name, isset($data["serial"]) ? "" . $data["serial"] . "" : "-", isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-");
                             }
                         }
                         // Each device
                     }
                 }
                 // numrows device
             }
             // type right
         }
         // each type
     }
     $pdf->displaySpace();
     // numrows type
 }
Ejemplo n.º 4
0
 /**
  * Show for PDF an projet - Hierarchy
  * 
  * @param $pdf object for the output
  * @param $ID of the projet
  */
 static function pdfHierarchyForProjet(PluginPdfSimplePDF $pdf, PluginProjetProjet $appli, $parents = 0)
 {
     global $DB, $CFG_GLPI;
     $ID = $appli->fields['id'];
     if (!$appli->can($ID, "r")) {
         return false;
     }
     if (!plugin_projet_haveRight("projet", "r")) {
         return false;
     }
     $pdf->setColumnsSize(100);
     if ($parents) {
         $pdf->displayTitle('<b>' . __('Parent project', 'projet') . '</b>');
     } else {
         $pdf->displayTitle('<b>' . _n('Child project', 'Child projects', 2, 'projet') . '</b>');
     }
     $first = false;
     $query = "SELECT `" . $appli->gettable() . "`.*  ";
     if ($parents != 0) {
         $parent = "plugin_projet_projets_id_1";
         $child = "plugin_projet_projets_id_2";
     } else {
         $parent = "plugin_projet_projets_id_2";
         $child = "plugin_projet_projets_id_1";
     }
     $query .= " FROM `glpi_plugin_projet_projets`";
     $query .= " LEFT JOIN `glpi_plugin_projet_projets_projets` \n                  ON (`glpi_plugin_projet_projets_projets`.`{$child}` = `glpi_plugin_projet_projets`.`id`)";
     $query .= " WHERE `glpi_plugin_projet_projets_projets`.`{$parent}` = '{$ID}' ";
     if ($appli->maybeTemplate()) {
         $LINK = " AND ";
         if ($first) {
             $LINK = " ";
             $first = false;
         }
         $query .= $LINK . "`" . $appli->getTable() . "`.`is_template` = '0' ";
     }
     // Add is_deleted if item have it
     if ($appli->maybeDeleted()) {
         $LINK = " AND ";
         if ($first) {
             $LINK = " ";
             $first = false;
         }
         $query .= $LINK . "`" . $appli->getTable() . "`.`is_deleted` = '0' ";
     }
     $LINK = " AND ";
     $query .= getEntitiesRestrictRequest(" AND ", $appli->gettable(), '', '', $appli->maybeRecursive());
     $query .= " ORDER BY `" . $appli->gettable() . "`.`name`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     if (!$number) {
         $pdf->displayLine(__('No item found'));
     } else {
         if (Session::isMultiEntitiesMode()) {
             $pdf->setColumnsSize(17, 17, 17, 17, 16, 16);
             $pdf->displayTitle('<b><i>' . __('Name'), __('Entity'), __('Progress'), _n('State', 'States', 1), __('Start date'), __('End date') . '</i></b>');
         } else {
             $pdf->setColumnsSize(20, 17, 17, 17, 17);
             $pdf->displayTitle('<b><i>' . __('Name'), __('Progress'), _n('State', 'States', 1), __('Start date'), __('End date') . '</i></b>');
         }
         while ($data = $DB->fetch_array($result)) {
             $items_id_display = "";
             if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) {
                 $items_id_display = " (" . $data["id"] . ")";
             }
             $name = $data["name"] . $items_id_display;
             $entity = Html::clean(Dropdown::getDropdownName("glpi_entities", $data['entities_id']));
             if (Session::isMultiEntitiesMode()) {
                 $pdf->setColumnsSize(17, 17, 17, 17, 16, 16);
                 $pdf->displayLine($name, $entity, PluginProjetProjet::displayProgressBar('100', $data["advance"], array("simple" => true)), Html::clean(Dropdown::getDropdownName("glpi_plugin_projet_projetstates", $data['plugin_projet_projetstates_id'])), Html::convdate($data["date_begin"]), Html::convdate($data["date_end"]));
             } else {
                 $pdf->setColumnsSize(20, 17, 17, 17, 17);
                 $pdf->displayLine($name, PluginProjetProjet::displayProgressBar('100', $data["advance"], array("simple" => true)), Html::clean(Dropdown::getDropdownName("glpi_plugin_projet_projetstates", $data['plugin_projet_projetstates_id'])), Html::convdate($data["date_begin"]), Html::convdate($data["date_end"]));
             }
         }
     }
     $pdf->displaySpace();
 }
Ejemplo n.º 5
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>";
     }
 }