function showForm($ID, $options = array()) { if (!$this->canView()) { return false; } $plugin_resources_resources_id = -1; if (isset($options['plugin_resources_resources_id'])) { $plugin_resources_resources_id = $options['plugin_resources_resources_id']; } $item = new PluginResourcesResource(); if ($item->getFromDB($plugin_resources_resources_id)) { $entities_id = $item->fields["entities_id"]; } if ($ID > 0) { $this->check($ID, 'r'); $plugin_resources_resources_id = $this->fields["plugin_resources_resources_id"]; } else { // Create item $input = array('plugin_resources_resources_id' => $plugin_resources_resources_id, 'entities_id' => $entities_id); $this->check(-1, 'w', $input); } $this->showTabs($options); $this->showFormHeader($options); echo "<input type='hidden' name='plugin_resources_resources_id' value='{$plugin_resources_resources_id}'>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . PluginResourcesResource::getTypeName(2) . " </td><td>"; $user = PluginResourcesResource::getResourceName($plugin_resources_resources_id, 2); $out = "<a href='" . $user['link'] . "'>"; $out .= $user["name"]; if ($_SESSION["glpiis_ids_visible"]) { $out .= " (" . $plugin_resources_resources_id . ")"; } $out .= "</a>"; echo $out; echo "</td>"; echo "<td colspan='2'>"; echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'><td>" . __('Name') . "</td>"; echo "<td>"; Html::autocompletionTextField($this, "name", array('size' => "50")); echo "</td>"; echo "<td>" . PluginResourcesTaskType::getTypeName(1) . "</td><td>"; Dropdown::show('PluginResourcesTaskType', array('value' => $this->fields["plugin_resources_tasktypes_id"])); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Technician') . "</td><td>"; User::dropdown(array('name' => "users_id", 'value' => $this->fields["users_id"], 'right' => 'interface')); echo "</td>"; echo "<td>" . __('Planning') . "</td>"; echo "<td>"; $plan = new PluginResourcesTaskPlanning(); $plan->showFormForTask($plugin_resources_resources_id, $this); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Group') . "</td><td>"; Dropdown::show('Group', array('value' => $this->fields["groups_id"])); echo "</td>"; echo "<td>" . __('Carried out task', 'resources') . "</td><td>"; Dropdown::showYesNo("is_finished", $this->fields["is_finished"]); echo "</td>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Effective duration', 'resources') . "</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><td colspan='2'></td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='4'>" . __('Comments') . "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'><td colspan='4'>"; echo "<textarea cols='130' rows='4' name='comment' >" . $this->fields["comment"] . "</textarea>"; echo "<input type='hidden' name='withtemplate' value=\"" . $options['withtemplate'] . "\" >"; echo "</td></tr>"; $this->showFormButtons($options); $this->addDivForTabs(); return true; }
// Send UTF8 Headers header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); Session::checkLoginUser(); if (isset($_REQUEST["table"]) && isset($_REQUEST["value"])) { // Security if (!TableExists($_REQUEST['table'])) { exit; } switch ($_REQUEST["table"]) { case "glpi_plugin_resources_resources": if ($_REQUEST['value'] == 0) { $tmpname['link'] = $CFG_GLPI['root_doc'] . "/plugins/resources/front/resource.php"; $tmpname['comment'] = ""; } else { $tmpname = PluginResourcesResource::getResourceName($_REQUEST["value"], 2); } echo $tmpname["comment"]; if (isset($_REQUEST['withlink'])) { echo "<script type='text/javascript' >\n"; echo "Ext.get('" . $_REQUEST['withlink'] . "').dom.href='" . $tmpname['link'] . "';"; echo "</script>\n"; } break; default: if ($_REQUEST["value"] > 0) { $tmpname = Dropdown::getDropdownName($_REQUEST["table"], $_REQUEST["value"], 1); echo $tmpname["comment"]; } } }
static function displayItemTitle($itemclass) { $text = ""; if (isset($itemclass->fields["name"]) && !empty($itemclass->fields["name"])) { $plugin = new Plugin(); if ($plugin->isActivated("resources") && $itemclass->getType() == 'PluginResourcesResource') { $text .= PluginResourcesResource::getResourceName($itemclass->getID()); } else { $text .= $itemclass->fields["name"]; } } if ($_SESSION['glpiactiveprofile']['interface'] != 'central') { $text .= PluginPositionsInfo::getCallValue($itemclass, true); } return $text; }
static function createTicket($data) { $result = false; $tt = new TicketTemplate(); // Create ticket based on ticket template and entity informations of ticketrecurrent if ($tt->getFromDB($data['tickettemplates_id'])) { // Get default values for ticket $input = Ticket::getDefaultValues($data['entities_id']); // Apply tickettemplates predefined values $ttp = new TicketTemplatePredefinedField(); $predefined = $ttp->getPredefinedFields($data['tickettemplates_id'], true); if (count($predefined)) { foreach ($predefined as $predeffield => $predefvalue) { $input[$predeffield] = $predefvalue; } } // Set date to creation date $createtime = date('Y-m-d H:i:s'); $input['date'] = $createtime; // Compute due_date if predefined based on create date if (isset($predefined['due_date'])) { $input['due_date'] = Html::computeGenericDateTimeSearch($predefined['due_date'], false, $createtime); } // Set entity $input['entities_id'] = $data['entities_id']; $input['actiontime'] = $data['actiontime']; $res = new PluginResourcesResource(); if ($res->getFromDB($data['plugin_resources_resources_id'])) { $input['users_id_recipient'] = $res->fields['users_id_recipient']; $input['_users_id_requester'] = $res->fields['users_id_recipient']; if (isset($res->fields['users_id'])) { $input['_users_id_observer'] = $res->fields['users_id']; } $input['_users_id_assign'] = Session::getLoginUserID(); $input["itemtype"] = "PluginResourcesResource"; $input["items_id"] = $data['plugin_resources_resources_id']; $input["name"] .= addslashes(" " . PluginResourcesResource::getResourceName($data['plugin_resources_resources_id'])); } //TODO : ADD checklist lists or add config into plugin ? $input["content"] .= addslashes("\n\n"); $input['status'] = Ticket::CLOSED; $ticket = new Ticket(); $input = Toolbox::addslashes_deep($input); if ($tid = $ticket->add($input)) { $msg = __('Create a end treatment ticket', 'resources') . " OK - ({$tid})"; // Success $result = true; } else { $msg = __('Failed operation'); // Failure } } else { $msg = __('No selected element or badly defined operation'); // Not defined } if ($tid) { $changes[0] = 0; $changes[1] = ''; $changes[2] = addslashes($msg); Log::history($data['plugin_resources_resources_id'], "PluginResourcesResource", $changes, '', Log::HISTORY_LOG_SIMPLE_MESSAGE); } return $result; }
if (isset($_POST["on_change"]) && !empty($_POST["on_change"])) { echo " onChange='" . $_POST["on_change"] . "'"; } echo ">"; if ($_POST['searchText'] != $CFG_GLPI["ajax_wildcard"] && $DB->numrows($result) == $CFG_GLPI["dropdown_max"]) { echo "<option value='0'>--" . __('Limited view') . "--</option>"; } if ($_POST['all'] == 0) { echo "<option value='0'>" . Dropdown::EMPTY_VALUE . "</option>"; } else { if ($_POST['all'] == 1) { echo "<option value='0'>[" . __('All') . "]</option>"; } } if (isset($_POST['value'])) { $output = PluginResourcesResource::getResourceName($_POST['value']); if (!empty($output) && $output != " ") { echo "<option selected value='" . $_POST['value'] . "'>" . $output . "</option>"; } } if (count($users)) { foreach ($users as $ID => $output) { echo "<option value='{$ID}' title=\"" . Html::cleanInputText($output . " - " . $logins[$ID]) . "\">" . Toolbox::substr($output, 0, $_SESSION["glpidropdown_chars_limit"]) . "</option>"; } } echo "</select>"; if (isset($_POST["comment"]) && $_POST["comment"]) { $paramscomment = array('value' => '__VALUE__', 'table' => "glpi_plugin_resources_resources"); if (isset($_POST['update_link'])) { $paramscomment['withlink'] = "comment_link_" . $_POST["myname"] . $_POST["rand"]; }
function plugin_resources_giveItem($type, $ID, $data, $num) { global $CFG_GLPI, $DB; $searchopt =& Search::getOptions($type); $table = $searchopt[$ID]["table"]; $field = $searchopt[$ID]["field"]; $output_type = Search::HTML_OUTPUT; if (isset($_GET['display_type'])) { $output_type = $_GET['display_type']; } switch ($type) { case 'PluginResourcesResource': switch ($table . '.' . $field) { case "glpi_plugin_resources_resources.name": if (!empty($data["ITEM_" . $num . "_2"])) { $link = Toolbox::getItemTypeFormURL('PluginResourcesResource'); $out = ""; if ($output_type == Search::HTML_OUTPUT) { $out = "<a href=\"" . $link . "?id=" . $data["ITEM_" . $num . "_2"] . "\">"; } $out .= $data["META_{$num}"]; if ($output_type == Search::HTML_OUTPUT) { if ($_SESSION["glpiis_ids_visible"] || empty($data["META_{$num}"])) { $out .= " (" . $data["ITEM_" . $num . "_2"] . ")"; } $out .= "</a>"; } if (plugin_resources_haveRight("task", "r") && $output_type == Search::HTML_OUTPUT) { $query_tasks = "SELECT COUNT(`id`) AS nb_tasks,SUM(`is_finished`) AS is_finished\n FROM `glpi_plugin_resources_tasks`\n WHERE `plugin_resources_resources_id` = '" . $data['id'] . "'\n AND `is_deleted` = '0'"; $result_tasks = $DB->query($query_tasks); $nb_tasks = $DB->result($result_tasks, 0, "nb_tasks"); $is_finished = $DB->result($result_tasks, 0, "is_finished"); $out .= " (<a href=\"" . $CFG_GLPI["root_doc"] . "/plugins/resources/front/task.php?plugin_resources_resources_id=" . $data["id"] . "\">"; if ($nb_tasks - $is_finished > 0) { $out .= "<span class='plugin_resources_date_over_color'>"; $out .= $nb_tasks - $is_finished . "</span></a>)"; } else { $out .= "<span class='plugin_resources_date_day_color'>"; $out .= $nb_tasks . "</span></a>)"; } } } return $out; break; case "glpi_plugin_resources_resources.date_end": if ($data["ITEM_{$num}"] <= date('Y-m-d') && !empty($data["ITEM_{$num}"])) { $out = "<span class='plugin_resources_date_color'>" . Html::convDate($data["ITEM_{$num}"]) . "</span>"; } else { if (empty($data["ITEM_{$num}"])) { $out = __('Not defined', 'resources'); } else { $out = Html::convDate($data["ITEM_{$num}"]); } } return $out; break; case "glpi_plugin_resources_resources_items.items_id": $restrict = "`plugin_resources_resources_id` = '" . $data['id'] . "'\n ORDER BY `itemtype`, `items_id`"; $items = getAllDatasFromTable("glpi_plugin_resources_resources_items", $restrict); $out = ''; if (!empty($items)) { foreach ($items as $device) { if (!class_exists($device["itemtype"])) { continue; } $item = new $device["itemtype"](); $item->getFromDB($device["items_id"]); $out .= $item->getTypeName() . " - "; if ($device["itemtype"] == 'User') { if ($output_type == Search::HTML_OUTPUT) { $link = Toolbox::getItemTypeFormURL('User'); $out .= "<a href=\"" . $link . "?id=" . $device["items_id"] . "\">"; } $out .= getUserName($device["items_id"]); if ($output_type == Search::HTML_OUTPUT) { $out .= "</a>"; } } else { $out .= $item->getLink(); } $out .= "<br>"; } } else { $out = ' '; } return $out; break; case "glpi_plugin_resources_resources.quota": if (!empty($data["ITEM_{$num}"])) { $out = floatval($data["ITEM_{$num}"]); } return $out; break; } return ""; break; case 'PluginResourcesTask': switch ($table . '.' . $field) { case "glpi_plugin_resources_resources.name": $out = ""; if (!empty($data["ITEM_" . $num . "_2"])) { $user = PluginResourcesResource::getResourceName($data["ITEM_" . $num . "_2"], 2); $out = "<a href='" . $user['link'] . "'>"; $out .= $user["name"]; if ($_SESSION["glpiis_ids_visible"] || empty($user["name"])) { $out .= " (" . $data["ITEM_" . $num . "_2"] . ")"; } $out .= "</a>"; } return $out; break; case 'glpi_plugin_resources_tasks.is_finished': $status = PluginResourcesTask::getStatus($data["ITEM_{$num}"]); return "<img src=\"" . $CFG_GLPI["root_doc"] . "/plugins/resources/pics/" . $data["ITEM_{$num}"] . ".png\"\n alt='{$status}' title='{$status}'> {$status}"; break; case "glpi_plugin_resources_tasks_items.items_id": $restrict = "`plugin_resources_tasks_id` = '" . $data['id'] . "'\n ORDER BY `itemtype`, `items_id`"; $items = getAllDatasFromTable("glpi_plugin_resources_tasks_items", $restrict); $out = ''; if (!empty($items)) { foreach ($items as $device) { $item = new $device["itemtype"](); $item->getFromDB($device["items_id"]); $out .= $item->getTypeName() . " - " . $item->getLink() . "<br>"; } } return $out; break; case "glpi_plugin_resources_taskplannings.id": if (!empty($data["ITEM_{$num}"])) { $plan = new PluginResourcesTaskPlanning(); $plan->getFromDB($data["ITEM_{$num}"]); $out = Html::convDateTime($plan->fields["begin"]) . "<br> -> " . Html::convDateTime($plan->fields["end"]); } else { $out = __('None'); } return $out; break; } return ""; break; case 'User': switch ($table . '.' . $field) { case "glpi_plugin_resources_recipients.name": $out = getUserName($data["ITEM_" . $num . "_2"]); return $out; break; case "glpi_plugin_resources_recipients_leaving.name": $out = getUserName($data["ITEM_" . $num . "_2"]); return $out; break; case "glpi_plugin_resources_managers.name": $out = getUserName($data["ITEM_" . $num . "_2"]); return $out; break; } return ""; break; case 'PluginResourcesResourceResting': switch ($table . '.' . $field) { case "glpi_plugin_resources_resources.name": if (!empty($data["id"])) { $link = Toolbox::getItemTypeFormURL('PluginResourcesResourceResting'); $out = "<a href=\"" . $link . "?id=" . $data["id"] . "\">"; $out .= $data["ITEM_{$num}"]; if ($_SESSION["glpiis_ids_visible"] || empty($data["ITEM_{$num}"])) { $out .= " (" . $data["id"] . ")"; } $out .= "</a>"; } return $out; break; } return ""; break; case 'PluginResourcesResourceHoliday': switch ($table . '.' . $field) { case "glpi_plugin_resources_resources.name": if (!empty($data["id"])) { $link = Toolbox::getItemTypeFormURL('PluginResourcesResourceHoliday'); $out = "<a href=\"" . $link . "?id=" . $data["id"] . "\">"; $out .= $data["ITEM_{$num}"]; if ($_SESSION["glpiis_ids_visible"] || empty($data["ITEM_{$num}"])) { $out .= " (" . $data["id"] . ")"; } $out .= "</a>"; } return $out; break; } return ""; break; case 'PluginResourcesDirectory': switch ($table . '.' . $field) { case "glpi_plugin_resources_managers.name": $out = ""; if (!empty($data["ITEM_" . $num . "_2"])) { $out = getUserName($data["ITEM_" . $num . "_2"]); } return $out; break; } return ""; break; case 'PluginResourcesEmployment': switch ($table . '.' . $field) { case "glpi_plugin_resources_resources.name": $out = ""; if (!empty($data["ITEM_" . $num . "_2"])) { $user = PluginResourcesResource::getResourceName($data["ITEM_" . $num . "_2"], 2); $out = "<a href='" . $user['link'] . "'>"; $out .= $user["name"]; if ($_SESSION["glpiis_ids_visible"] || empty($user["name"])) { $out .= " (" . $data["ITEM_" . $num . "_2"] . ")"; } $out .= "</a>"; } return $out; break; } return ""; break; } return ""; }