Example #1
0
 function prepareInputForAdd($input)
 {
     $task = new PluginProjetTask();
     if (!isset($input['plugin_projet_tasks_id_1']) || !isset($input['plugin_projet_tasks_id_2']) || $input['plugin_projet_tasks_id_2'] == $input['plugin_projet_tasks_id_1'] || !$task->getFromDB($input['plugin_projet_tasks_id_1']) || !$task->getFromDB($input['plugin_projet_tasks_id_2'])) {
         return false;
     }
     if (!isset($input['link'])) {
         $input['link'] = self::LINK_TO;
     }
     return $input;
 }
 function post_updateItem($history = 1)
 {
     global $CFG_GLPI;
     $fup = new PluginProjetTask();
     $fup->getFromDB($this->input["plugin_projet_tasks_id"]);
     $timestart = strtotime($this->input["begin"]);
     $timeend = strtotime($this->input["end"]);
     $updates2[] = "actiontime";
     $fup->fields["actiontime"] = $timeend - $timestart;
     $updates2[] = "plugin_projet_taskstates_id";
     $fup->fields["plugin_projet_taskstates_id"] = PluginProjetTaskState::getStatusForPlanning();
     $fup->updateInDB($updates2);
 }
Example #3
0
 function doSpecificMassiveActions($input = array())
 {
     $res = array('ok' => 0, 'ko' => 0, 'noright' => 0);
     $projet_item = new PluginProjetProjet_Item();
     switch ($input['action']) {
         case "Transfert":
             if ($input['itemtype'] == 'PluginProjetProjet') {
                 foreach ($input["item"] as $key => $val) {
                     if ($val == 1) {
                         $PluginProjetTask = new PluginProjetTask();
                         $restrict = "`plugin_projet_projets_id` = '" . $key . "'";
                         $tasks = getAllDatasFromTable("glpi_plugin_projet_tasks");
                         if (!empty($tasks)) {
                             foreach ($tasks as $task) {
                                 $PluginProjetTask->getFromDB($task["id"]);
                                 $tasktype = PluginProjetTaskType::transfer($PluginProjetTask->fields["plugin_projet_tasktypes_id"], $input['entities_id']);
                                 if ($tasktype > 0) {
                                     $values["id"] = $task["id"];
                                     $values["plugin_projet_tasktypes_id"] = $tasktype;
                                     $PluginProjetTask->update($values);
                                 }
                                 $values["id"] = $task["id"];
                                 $values["entities_id"] = $input['entities_id'];
                                 $PluginProjetTask->update($values);
                             }
                         }
                         unset($values);
                         $values["id"] = $key;
                         $values["entities_id"] = $input['entities_id'];
                         if ($this->update($values)) {
                             $res['ok']++;
                         } else {
                             $res['ko']++;
                         }
                     }
                 }
             }
             break;
         case "Install":
             foreach ($input["item"] as $key => $val) {
                 if ($val == 1) {
                     $values = array('plugin_projet_projets_id' => $key, 'items_id' => $input["item_item"], 'itemtype' => $input['typeitem']);
                     if ($projet_item->add($values)) {
                         $res['ok']++;
                     } else {
                         $res['ko']++;
                     }
                 }
             }
             break;
         case "Desinstall":
             foreach ($input["item"] as $key => $val) {
                 if ($val == 1) {
                     if ($projet_item->deleteItemByProjetAndItem($key, $input['item_item'], $input['typeitem'])) {
                         $res['ok']++;
                     } else {
                         $res['ko']++;
                     }
                 }
             }
             break;
         default:
             return parent::doSpecificMassiveActions($input);
             break;
     }
     return $res;
 }
Example #4
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>";
     }
 }