Beispiel #1
0
function plugin_init_shellcommands()
{
    global $PLUGIN_HOOKS, $CFG_GLPI;
    $PLUGIN_HOOKS['csrf_compliant']['shellcommands'] = true;
    $PLUGIN_HOOKS['change_profile']['shellcommands'] = array('PluginShellcommandsProfile', 'changeProfile');
    //Clean Plugin on Profile delete
    $PLUGIN_HOOKS['pre_item_purge']['shellcommands'] = array('Profile' => array('PluginShellcommandsProfile', 'purgeProfiles'));
    if (Session::getLoginUserID()) {
        Plugin::registerClass('PluginShellcommandsProfile', array('addtabon' => 'Profile'));
        if (plugin_shellcommands_haveRight("shellcommands", "r")) {
            $PLUGIN_HOOKS['menu_entry']['shellcommands'] = 'front/shellcommand.php';
            $PLUGIN_HOOKS['submenu_entry']['shellcommands']['add'] = 'front/shellcommand.form.php';
            $PLUGIN_HOOKS['submenu_entry']['shellcommands']['search'] = 'front/shellcommand.php';
            $PLUGIN_HOOKS['use_massive_action']['shellcommands'] = 1;
        }
        $PLUGIN_HOOKS['use_massive_action']['shellcommands'] = 1;
        $PLUGIN_HOOKS['post_init']['shellcommands'] = 'plugin_shellcommands_postinit';
    }
}
 /**
  * Show shellcommands associated to an item
  *
  * @since version 0.84
  *
  * @param $item            CommonDBTM object for which associated shellcommands 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_shellcommands_haveRight('shellcommands', 'r')) {
         return false;
     }
     if (!$item->can($item->fields['id'], 'r')) {
         return false;
     }
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     $canedit = $item->canadditem('PluginShellcommandsShellcommand');
     $rand = mt_rand();
     $is_recursive = $item->isRecursive();
     $query = "SELECT `glpi_plugin_shellcommands_shellcommands_items`.`id` AS assocID,\n                       `glpi_entities`.`id` AS entity,\n                       `glpi_plugin_shellcommands_shellcommands`.`name` AS assocName,\n                       `glpi_plugin_shellcommands_shellcommands`.*\n                FROM `glpi_plugin_shellcommands_shellcommands_items`\n                LEFT JOIN `glpi_plugin_shellcommands_shellcommands`\n                 ON (`glpi_plugin_shellcommands_shellcommands_items`.`plugin_shellcommands_shellcommands_id`=`glpi_plugin_shellcommands_shellcommands`.`id`)\n                LEFT JOIN `glpi_entities` ON (`glpi_plugin_shellcommands_shellcommands`.`entities_id`=`glpi_entities`.`id`)\n                WHERE `glpi_plugin_shellcommands_shellcommands_items`.`itemtype` = '" . $item->getType() . "' \n                  AND !`glpi_plugin_shellcommands_shellcommands`.`is_deleted`";
     $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_shellcommands_shellcommands", '', '', true);
     $query .= " ORDER BY `assocName`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     $shells = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $shells[$data['assocID']] = $data;
         }
     }
     echo "<div class='spaced'>";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr>";
     echo "<th>" . __('Associated Commands', 'shellcommands') . "</th>";
     echo "</tr>";
     if ($number) {
         Session::initNavigateListItems('PluginShellcommandsShellcommand', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         $selectCommandName[0] = Dropdown::EMPTY_VALUE;
         $countCommand = self::countForItem($item, array('type' => 'ALL'));
         foreach ($shells as $data) {
             if (isset($countCommand[$data['link'] . $data['id']])) {
                 $selectCommandName[$data['link'] . '-' . $data['id']] = $data['assocName'];
             }
         }
         echo "<tr class='tab_bg_2'>\n               <td class='center'>" . PluginShellcommandsShellcommand::getTypeName(1) . " ";
         $randSelect = Dropdown::showFromArray("name", $selectCommandName);
         echo " <span id='command_name{$randSelect}'></span></td>";
         echo "</tr>";
         Ajax::updateItemOnSelectEvent("dropdown_name{$randSelect}", "command_name{$randSelect}", $CFG_GLPI["root_doc"] . "/plugins/shellcommands/ajax/dropdownCommand.php", array('idtable' => $item->getType(), 'value' => '__VALUE__', 'itemID' => $ID, 'countItem' => 1, 'itemtype' => $item->getType(), 'myname' => "command_name"));
     }
     echo "</table>";
     echo "</div>";
 }
 public static function canView()
 {
     return plugin_shellcommands_haveRight('shellcommands', 'r');
 }