/** * Show resource associated to an item * * @since version 0.84 * * @param $item CommonDBTM object for which associated resource 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_resources_haveRight('resources', 'r')) { return false; } if (!$item->can($item->fields['id'], 'r')) { return false; } if (empty($withtemplate)) { $withtemplate = 0; } $canedit = $item->canadditem('PluginResourcesResource'); $rand = mt_rand(); $is_recursive = $item->isRecursive(); $query = "SELECT `glpi_plugin_resources_resources_items`.`id` AS assocID,\n `glpi_entities`.`id` AS entity,\n `glpi_plugin_resources_resources`.`name` AS assocName,\n `glpi_plugin_resources_resources`.*\n FROM `glpi_plugin_resources_resources_items`\n LEFT JOIN `glpi_plugin_resources_resources`\n ON (`glpi_plugin_resources_resources_items`.`plugin_resources_resources_id`=`glpi_plugin_resources_resources`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_plugin_resources_resources`.`entities_id`=`glpi_entities`.`id`)\n WHERE `glpi_plugin_resources_resources_items`.`items_id` = '{$ID}'\n AND `glpi_plugin_resources_resources_items`.`itemtype` = '" . $item->getType() . "' "; $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_resources_resources", '', '', true); $query .= " ORDER BY `assocName`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; $resources = array(); $used = array(); if ($numrows = $DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $resources[$data['assocID']] = $data; $used[$data['id']] = $data['id']; } } $resource = new PluginResourcesResource(); $more = true; if ($item->getType() == "User" && $number != 0) { $more = false; } if ($canedit && $withtemplate < 2 && $more) { // 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_resources_resources", '', $entities, true); $q = "SELECT COUNT(*)\n FROM `glpi_plugin_resources_resources`\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_resources_haveRight('resources', 'r') && $nb > count($used)) { echo "<form name='resource_form{$rand}' id='resource_form{$rand}' method='post'\n action='" . Toolbox::getItemTypeFormURL('PluginResourcesResource') . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='4' class='center'>"; 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}'>"; } PluginResourcesResource::dropdown(array('entity' => $entities, 'used' => $used)); echo "</td><td class='center' width='20%'>"; echo "<input type='submit' name='additem' value=\"" . __s('Associate a resource', 'resources') . "\" 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; } echo "<tr>"; if ($canedit && $number && $withtemplate < 2) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Name') . "</th>"; echo "<th>" . __('First name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . __('Location') . "</th>"; echo "<th>" . PluginResourcesContractType::getTypeName(1) . "</th>"; echo "<th>" . PluginResourcesDepartment::getTypeName(1) . "</th>"; echo "<th>" . __('Arrival date', 'resources') . "</th>"; echo "<th>" . __('Departure date', 'resources') . "</th>"; echo "</tr>"; $used = array(); $resourceID = 0; if ($number) { Session::initNavigateListItems('PluginResourcesResource', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName())); foreach ($resources as $data) { $resourceID = $data["id"]; $link = NOT_AVAILABLE; if ($resource->getFromDB($resourceID)) { $link = $resource->getLink(); } Session::addToNavigateListItems('PluginResourcesResource', $resourceID); $used[$resourceID] = $resourceID; $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>"; echo "<td class='center'>" . $data['firstname'] . "</td>"; if (Session::isMultiEntitiesMode()) { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>"; } echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_locations", $data["locations_id"]); echo "</td>"; echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_plugin_resources_contracttypes", $data["plugin_resources_contracttypes_id"]); echo "</td>"; echo "<td class='center'>"; echo Dropdown::getDropdownName("glpi_plugin_resources_departments", $data["plugin_resources_departments_id"]); echo "</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'>"; echo "<span class='plugin_resources_date_color'>"; echo Html::convDate($data["date_end"]); echo "</span>"; echo "</td>"; } else { if (empty($data["date_end"])) { echo "<td class='center'>" . __('Not defined', 'resources') . "</td>"; } else { echo "<td class='center'>" . Html::convDate($data["date_end"]) . "</td>"; } } echo "</tr>"; $i++; } } echo "</table>"; if ($canedit && $number && $withtemplate < 2) { $massiveactionparams['ontop'] = false; Html::showMassiveActions(__CLASS__, $massiveactionparams); Html::closeForm(); } echo "</div>"; if ($item->getType() == "User") { $PluginResourcesEmployee = new PluginResourcesEmployee(); $PluginResourcesEmployee->showForm($resourceID, $ID, 0); } }
function showResourcesToRemove() { global $CFG_GLPI; if (countElementsInTable($this->getTable()) > 0) { echo "<div align='center'>"; echo "<form method='post' action=\"" . $CFG_GLPI["root_doc"] . "/plugins/resources/front/resource.remove.php\">"; echo "<table class='plugin_resources_wizard' style='margin-top:1px;'>"; echo "<tr>"; echo "<td class='plugin_resources_wizard_left_area' valign='top'>"; echo "<div class='plugin_resources_presentation_logo'>"; echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/resources/pics/removeresource.png' alt='removeresource' /></div>"; echo "</td>"; echo "<td class='plugin_resources_wizard_right_area' style='width:500px' valign='top'>"; echo "<div class='plugin_resources_wizard_title'>"; _e('Declare a departure', 'resources'); echo "</div>"; echo "<table>"; echo "<table>"; echo "<tr class='plugin_resources_wizard_explain'>"; echo "<td style='width:40%'>" . self::getTypeName(1) . "</td>"; echo "<td class='left'>"; PluginResourcesResource::dropdown(array('name' => 'plugin_resources_resources_id', 'entity' => $_SESSION['glpiactiveentities'])); echo "</td></tr>"; echo "<tr class='plugin_resources_wizard_explain'><td>"; echo __('Departure date', 'resources') . "</td>"; echo "<td class='left'>"; Html::showDateFormItem("date_end", $_POST["date_end"], true, true); echo "</td></tr>"; echo "<tr class='plugin_resources_wizard_explain'><td>"; echo PluginResourcesLeavingReason::getTypeName(1) . "</td>"; echo "<td class='left'>"; Dropdown::show('PluginResourcesLeavingReason', array('entity' => $_SESSION['glpiactiveentities'])); echo "</td></tr>"; echo "</table>"; echo "</div></td>"; echo "</tr>"; echo "<tr><td class='plugin_resources_wizard_button' colspan='2'>"; echo "<div class='next'>"; echo "<input type='submit' name='removeresources' value=\"" . __s('Declare a departure', 'resources') . "\" class='submit'>"; echo "</div>"; echo "</td></tr></table>"; Html::closeForm(); echo "</div>"; } else { echo "<div align='center'>" . __('No item found') . "</div>"; } }
function showForm($ID, $options = array()) { global $CFG_GLPI; $this->initForm($ID, $options); echo "<div align='center'>"; echo "<form method='post' action=\"" . $CFG_GLPI["root_doc"] . "/plugins/resources/front/resourceresting.form.php\">"; echo "<table class='plugin_resources_wizard' style='margin-top:1px;'>"; echo "<tr>"; echo "<td class='plugin_resources_wizard_left_area' valign='top'>"; echo "<div class='plugin_resources_presentation_logo'>"; echo "<img src='../pics/newresting.png' alt='newresting' /></div>"; echo "</td>"; echo "<td class='plugin_resources_wizard_right_area' style='width:500px' valign='top'>"; $title = __('Declare a non contract period', 'resources'); if ($ID > 0) { $title = __('Detail of non contract period', 'resources'); } echo "<div class='plugin_resources_wizard_title'>"; echo $title; echo "</div>"; echo "<table>"; echo "<tr class='plugin_resources_wizard_explain'>"; echo "<td>" . PluginResourcesResource::getTypeName(1) . "</td>"; echo "<td class='left'>"; PluginResourcesResource::dropdown(array('name' => 'plugin_resources_resources_id', 'value' => $this->fields["plugin_resources_resources_id"], 'entity' => $_SESSION['glpiactiveentities'])); echo "</td></tr>"; echo "<tr class='plugin_resources_wizard_explain'><td>"; echo __('Begin date') . "</td>"; echo "<td class='left'>"; Html::showDateFormItem("date_begin", $this->fields["date_begin"], true, true); echo "</td></tr>"; echo "<tr class='plugin_resources_wizard_explain'><td>"; echo __('End date') . "</td>"; echo "<td class='left'>"; Html::showDateFormItem("date_end", $this->fields["date_end"], true, true); echo "</td></tr>"; echo "<tr class='plugin_resources_wizard_explain'><td>"; echo __('Agency concerned', 'resources') . "</td>"; echo "<td class='left'>"; Dropdown::show('Location', array('value' => $this->fields["locations_id"])); echo "</td></tr>"; echo "<tr class='plugin_resources_wizard_explain'><td>"; echo __('At home', 'resources') . "</td>"; echo "<td class='left'>"; Dropdown::showYesNo('at_home', $this->fields['at_home']); echo "</td>"; echo "</tr>"; echo "<tr class='plugin_resources_wizard_explain'><td colspan='2'>"; echo __('Comments') . "</td></tr>"; echo "<tr class='plugin_resources_wizard_explain'><td colspan='2'>"; echo "<textarea cols='70' rows='4' name='comment' >" . $this->fields["comment"] . "</textarea>"; echo "</td></tr>"; echo "</table>"; echo "</div></td>"; echo "</tr>"; echo "<tr><td class='plugin_resources_wizard_button' colspan='2'>"; echo "<div class='preview'>"; echo "<a href=\"./resourceresting.form.php\">"; _e('Declare a non contract period', 'resources'); echo "</a>"; echo " / <a href=\"./resourceresting.php\">"; _e('List of non contract periods', 'resources'); echo "</a>"; echo "</div>"; echo "<div class='next'>"; if ($ID > 0) { echo "<input type='hidden' name='id' value='" . $ID . "' />"; echo "<input type='hidden' name='plugin_resources_resources_id' value='" . $this->fields["plugin_resources_resources_id"] . "' />"; echo "<input type='submit' name='updaterestingresources' value=\"" . _sx('button', 'Update') . "\" class='submit' />"; echo " <input type='submit' name='deleterestingresources' value=\"" . _sx('button', 'Delete permanently') . "\" class='submit' />"; } else { echo "<input type='submit' name='addrestingresources' value='" . _sx('button', 'Add') . "' class='submit' />"; } echo "</div>"; echo "</td></tr></table>"; Html::closeForm(); echo "</div>"; }
function plugin_resources_MassiveActionsDisplay($options = array()) { switch ($options['action']) { case "plugin_resources_add_item": if (in_array($options['itemtype'], PluginResourcesResource::getTypes())) { PluginResourcesResource::dropdown(); echo " <input type=\"submit\" name=\"massiveaction\" class=\"submit\" value=\"" . _sx('button', 'Post') . "\" >"; } break; case "plugin_resources_generate_resources": echo "<table class='tab_cadre'>"; // ContractType echo "<tr>"; echo "<td>" . __("Contract type") . "</td>"; echo "<td>"; PluginResourcesDepartment::getTypeName(1) . "</td><td>"; Dropdown::show('PluginResourcesContractType', array('name' => "plugin_resources_contracttypes_id")); echo "</td>"; echo "</tr>"; echo "<tr>"; // Recipient echo "<td>"; echo __('Resource manager', 'resources') . "</td>"; echo "<td width='70%'>"; User::dropdown(array('name' => "users_id_recipient", 'entity' => $_SESSION['glpiactive_entity'], 'right' => 'all')); echo "<td>"; echo "</tr>"; // Department echo "<tr>"; echo "<td>"; echo PluginResourcesDepartment::getTypeName(1) . "</td><td>"; Dropdown::show('PluginResourcesDepartment', array('name' => "plugin_resources_departments_id")); echo "</td>"; echo "</tr>"; echo "</table>"; echo " <input type=\"submit\" name=\"massiveaction\" class=\"submit\" value=\"" . _sx('button', 'Post') . "\" >"; break; default: break; } return ""; }