Exemplo n.º 1
0
function plugin_accounts_MassiveActionsDisplay($options = array())
{
    $PluginAccountsAccount = new PluginAccountsAccount();
    if (in_array($options['itemtype'], PluginAccountsAccount::getTypes(true))) {
        $PluginAccountsAccount->dropdownAccounts("plugin_accounts_accounts_id");
        echo "<input type=\"submit\" name=\"massiveaction\" class=\"submit\" value='" . _sx('button', 'Post') . "'>";
    }
    return "";
}
Exemplo n.º 2
0
 /**
  * Show items links to a account
  *
  * @since version 0.84
  *
  * @param $PluginAccountsAccount PluginAccountsAccount object
  *
  * @return nothing (HTML display)
  **/
 public static function showForAccount(PluginAccountsAccount $account)
 {
     global $DB;
     $instID = $account->fields['id'];
     if (!$account->can($instID, "r")) {
         return false;
     }
     $canedit = $account->can($instID, 'w');
     $query = "SELECT DISTINCT `itemtype`\n      FROM `glpi_plugin_accounts_accounts_items`\n      WHERE `plugin_accounts_accounts_id` = '{$instID}'\n      ORDER BY `itemtype`\n      LIMIT " . count(PluginAccountsAccount::getTypes(true));
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $rand = mt_rand();
     if ($canedit) {
         echo "<div class='firstbloc'>";
         echo "<form name='accountitem_form{$rand}' id='accountitem_form{$rand}' method='post'\n         action='" . Toolbox::getItemTypeFormURL("PluginAccountsAccount") . "'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2'><th colspan='2'>" . __('Add an item') . "</th></tr>";
         echo "<tr class='tab_bg_1'><td class='right'>";
         Dropdown::showAllItems("items_id", 0, 0, $account->fields['is_recursive'] ? -1 : $account->fields['entities_id'], PluginAccountsAccount::getTypes(), false, true);
         echo "</td><td class='center'>";
         echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "<input type='hidden' name='plugin_accounts_accounts_id' value='{$instID}'>";
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $number) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array();
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
     }
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr>";
     if ($canedit && $number) {
         echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     }
     echo "<th>" . __('Type') . "</th>";
     echo "<th>" . __('Name') . "</th>";
     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";
             if ($itemtype == 'Ticket') {
                 $column = "id";
             }
             $itemtable = getTableForItemType($itemtype);
             $query = "SELECT `{$itemtable}`.*,\n            `glpi_plugin_accounts_accounts_items`.`id` AS IDD, ";
             if ($itemtype == 'KnowbaseItem') {
                 $query .= "-1 AS entity\n               FROM `glpi_plugin_accounts_accounts_items`, `{$itemtable}`\n               " . KnowbaseItem::addVisibilityJoins() . "\n               WHERE `{$itemtable}`.`id` = `glpi_plugin_accounts_accounts_items`.`items_id`\n               AND ";
             } else {
                 $query .= "`glpi_entities`.`id` AS entity\n               FROM `glpi_plugin_accounts_accounts_items`, `{$itemtable}` ";
                 if ($itemtype != 'Entity') {
                     $query .= "LEFT JOIN `glpi_entities`\n                              ON (`glpi_entities`.`id` = `{$itemtable}`.`entities_id`) ";
                 }
                 $query .= "WHERE `{$itemtable}`.`id` = `glpi_plugin_accounts_accounts_items`.`items_id`\n               AND ";
             }
             $query .= "`glpi_plugin_accounts_accounts_items`.`itemtype` = '{$itemtype}'\n            AND `glpi_plugin_accounts_accounts_items`.`plugin_accounts_accounts_id` = '{$instID}' ";
             if ($itemtype == 'KnowbaseItem') {
                 if (Session::getLoginUserID()) {
                     $query = "AND " . KnowbaseItem::addVisibilityRestrict();
                 } else {
                     // Anonymous access
                     if (Session::isMultiEntitiesMode()) {
                         $query = " AND (`glpi_entities_knowbaseitems`.`entities_id` = '0'\n                              AND `glpi_entities_knowbaseitems`.`is_recursive` = '1')";
                     }
                 }
             } else {
                 $query .= getEntitiesRestrictRequest(" AND ", $itemtable, '', '', $item->maybeRecursive());
             }
             if ($item->maybeTemplate()) {
                 $query .= " AND `{$itemtable}`.`is_template` = '0'";
             }
             if ($itemtype == 'KnowbaseItem') {
                 $query .= " ORDER BY `{$itemtable}`.`{$column}`";
             } else {
                 $query .= " ORDER BY `glpi_entities`.`completename`, `{$itemtable}`.`{$column}`";
             }
             if ($itemtype == 'SoftwareLicense') {
                 $soft = new Software();
             }
             if ($result_linked = $DB->query($query)) {
                 if ($DB->numrows($result_linked)) {
                     while ($data = $DB->fetch_assoc($result_linked)) {
                         if ($itemtype == 'Ticket') {
                             $data["name"] = sprintf(__('%1$s: %2$s'), __('Ticket'), $data["id"]);
                         }
                         if ($itemtype == 'SoftwareLicense') {
                             $soft->getFromDB($data['softwares_id']);
                             $data["name"] = sprintf(__('%1$s - %2$s'), $data["name"], $soft->fields['name']);
                         }
                         $linkname = $data["name"];
                         if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) {
                             $linkname = sprintf(__('%1$s (%2$s)'), $linkname, $data["id"]);
                         }
                         $link = Toolbox::getItemTypeFormURL($itemtype);
                         $name = "<a href=\"" . $link . "?id=" . $data["id"] . "\">" . $linkname . "</a>";
                         echo "<tr class='tab_bg_1'>";
                         if ($canedit) {
                             echo "<td width='10'>";
                             Html::showMassiveActionCheckBox(__CLASS__, $data["IDD"]);
                             echo "</td>";
                         }
                         echo "<td class='center'>" . $item->getTypeName(1) . "</td>";
                         echo "<td " . (isset($data['is_deleted']) && $data['is_deleted'] ? "class='tab_bg_2_2'" : "") . ">" . $name . "</td>";
                         echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entity']);
                         echo "</td>";
                         echo "<td class='center'>" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-") . "</td>";
                         echo "<td class='center'>" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . "</td>";
                         echo "</tr>";
                     }
                 }
             }
         }
     }
     echo "</table>";
     if ($canedit && $number) {
         $paramsma['ontop'] = false;
         Html::showMassiveActions(__CLASS__, $paramsma);
         Html::closeForm();
     }
     echo "</div>";
 }
Exemplo n.º 3
0
function plugin_accounts_MassiveActions($type)
{
    if (in_array($type, PluginAccountsAccount::getTypes(true))) {
        return array('PluginAccountsAccount' . MassiveAction::CLASS_ACTION_SEPARATOR . "add_item" => __('Associate to account', 'accounts'));
    }
    return array();
}