static function countForResourceTask(PluginResourcesTask $item) { $types = implode("','", PluginResourcesResource::getTypes()); if (empty($types)) { return 0; } return countElementsInTable('glpi_plugin_resources_tasks_items', "`itemtype` IN ('{$types}')\n AND `plugin_resources_tasks_id` = '" . $item->getID() . "'"); }
/** * Show items links to a resource * * @since version 0.84 * * @param $resource PluginResourcesResource object * * @return nothing (HTML display) **/ public static function showForResource(PluginResourcesResource $resource, $withtemplate = '') { global $DB, $CFG_GLPI; $instID = $resource->fields['id']; if (!$resource->can($instID, 'r')) { return false; } $rand = mt_rand(); $canedit = $resource->can($instID, 'w'); if (empty($withtemplate)) { $withtemplate = 0; } $types = PluginResourcesResource::getTypes(); $plugin = new Plugin(); if ($plugin->isActivated("badges")) { $types[] = 'PluginBadgesBadge'; } $query = "SELECT DISTINCT `itemtype` \n FROM `glpi_plugin_resources_resources_items` \n WHERE `plugin_resources_resources_id` = '{$instID}' \n ORDER BY `itemtype` \n LIMIT " . count($types); $result = $DB->query($query); $number = $DB->numrows($result); if (Session::isMultiEntitiesMode()) { $colsup = 1; } else { $colsup = 0; } if ($canedit && $withtemplate < 2 && $number < 1) { echo "<div class='firstbloc'>"; echo "<form method='post' name='resource_form{$rand}' id='resource_form{$rand}'\n action='" . Toolbox::getItemTypeFormURL("PluginResourcesResource") . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2'><th colspan='" . ($canedit ? 5 + $colsup : 4 + $colsup) . "'>" . __('Add a user') . "</th></tr>"; echo "<tr class='tab_bg_1'><td colspan='" . (3 + $colsup) . "' class='center'>"; echo "<input type='hidden' name='plugin_resources_resources_id' value='{$instID}'>"; echo "<input type='hidden' name='itemtype' value='User'>"; //Dropdown::showAllItems("items_id",0,0,($resource->fields['is_recursive']?-1:$resource->fields['entities_id']),$types); User::dropdown(array('name' => 'items_id', 'entity' => $resource->fields["entities_id"], 'right' => 'all', 'ldap_import' => true)); echo "</td>"; echo "<td colspan='2' class='tab_bg_2'>"; echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $number && $withtemplate < 2) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array(); Html::showMassiveActions(__CLASS__, $massiveactionparams); } echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; if ($canedit && $number && $withtemplate < 2) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Type') . "</th>"; echo "<th>" . __('Name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . __('Serial Number') . "</th>"; echo "<th>" . __('Inventory number') . "</th>"; echo "</tr>"; for ($i = 0; $i < $number; $i++) { $itemType = $DB->result($result, $i, "itemtype"); if (!($item = getItemForItemtype($itemType))) { continue; } if ($item->canView()) { $column = "name"; $itemTable = getTableForItemType($itemType); $query = "SELECT `" . $itemTable . "`.*,\n `glpi_plugin_resources_resources_items`.`id` AS items_id,\n `glpi_plugin_resources_resources_items`.`comment` AS comment,\n `glpi_entities`.`id` AS entity " . " FROM `glpi_plugin_resources_resources_items`, `" . $itemTable . "` LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = `" . $itemTable . "`.`entities_id`) " . " WHERE `" . $itemTable . "`.`id` = `glpi_plugin_resources_resources_items`.`items_id`\n AND `glpi_plugin_resources_resources_items`.`itemtype` = '{$itemType}'\n AND `glpi_plugin_resources_resources_items`.`plugin_resources_resources_id` = '{$instID}' "; if ($itemType != 'User') { $query .= getEntitiesRestrictRequest(" AND ", $itemTable, '', '', $item->maybeRecursive()); } if ($item->maybeTemplate()) { $query .= " AND `" . $itemTable . "`.`is_template` = '0'"; } $query .= " ORDER BY `glpi_entities`.`completename`, `" . $itemTable . "`.`{$column}`"; if ($result_linked = $DB->query($query)) { if ($DB->numrows($result_linked)) { Session::initNavigateListItems($itemType, PluginResourcesResource::getTypeName(2) . " = " . $resource->fields['name']); while ($data = $DB->fetch_assoc($result_linked)) { $item->getFromDB($data["id"]); Session::addToNavigateListItems($itemType, $data["id"]); $ID = ""; if ($itemType == 'User') { $format = formatUserName($data["id"], $data["name"], $data["realname"], $data["firstname"], 1); } else { $format = $data["name"]; } if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) { $ID = " (" . $data["id"] . ")"; } $link = Toolbox::getItemTypeFormURL($itemType); $name = "<a href=\"" . $link . "?id=" . $data["id"] . "\">" . $format; if ($itemType != 'User') { $name .= " " . $ID; } $name .= "</a>"; echo "<tr class='tab_bg_1'>"; $items_id = $data["items_id"]; if ($canedit && $withtemplate < 2) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["items_id"]); /*TODO resolve IT or drop IT ? echo "<img src='".$CFG_GLPI["root_doc"]."/pics/expand.gif' onclick=\"plugin_resources_show_item('comment$items_id$rand',this,'".$CFG_GLPI["root_doc"]."/pics/collapse.gif');\">";*/ echo "</td>"; } echo "<td class='center'>" . $item::getTypeName(1) . "</td>"; echo "<td class='center' " . (isset($data['is_deleted']) && $data['is_deleted'] ? "class='tab_bg_2_2'" : "") . ">" . $name . "</td>"; if (Session::isMultiEntitiesMode()) { if ($itemType != 'User') { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entity']) . "</td>"; } else { echo "<td class='center'>-</td>"; } } echo "<td class='center'>" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-") . "</td>"; echo "<td class='center'>" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . "</td>"; echo "</tr>"; /*TODO resolve IT or drop IT ? echo "<tr class='tab_bg_1'>"; $class = "class='plugin_resources_show'"; if (!isset($data["comment"]) || empty($data["comment"])) { $data["comment"]=''; $class = "class='plugin_resources_hide'"; } echo "<td colspan='6' id='comment$items_id$rand' $class >"; echo "<form method='post' name='updatecomment$items_id$rand' id='updatecomment$items_id$rand' action='".Toolbox::getItemTypeFormURL("PluginResourcesResource")."'>"; echo "<table><tr><td>"; _e('Comments'); echo "<br><textarea cols='150' rows='5' name='comment$items_id' >"; echo $data["comment"]; echo "</textarea><br><br>"; echo "<input type='hidden' name='items_id' value='".$data["items_id"]."'>"; if($canedit && $withtemplate<2) { if (!isset($data["comment"]) || empty($data["comment"])) { echo "<input type='submit' name='updatecomment[".$items_id."]' value=\""._sx('button','Add')."\" class='submit'>"; } else { echo "<input type='submit' name='updatecomment[".$items_id."]' value=\""._sx('button','Update')."\" class='submit'>"; } } echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); echo "</td>"; echo "</tr>";*/ } } } } } echo "</table>"; if ($canedit && $number && $withtemplate < 2) { $paramsma['ontop'] = false; Html::showMassiveActions(__CLASS__, $paramsma); 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 ""; }