svn.diff

Fichier SVN contenant un premier prototype relativement fonctionnel - webmyster, 07/10/2013 02:17 PM

Download (88.5 KB)

View differences:

ajax/dropdownMassiveAction.php (working copy)
38 38

  
39 39

  
40 40
if (isset($_POST["action"]) && ($_POST["action"] != '-1')
41
    && isset($_POST["itemtype"]) && !empty($_POST["itemtype"])) {
42
    if (!isset($_POST['is_deleted'])) {
41
    && (!empty($_POST["item"]))) {
42
   if (!isset($_POST['is_deleted'])) {
43 43
      $_POST['is_deleted'] = 0;
44
    }
44
   }
45 45

  
46
   if (!($item = getItemForItemtype($_POST['itemtype']))) {
47
      exit();
48
   }
49 46
   $checkitem = NULL;
50

  
51 47
   if (isset($_POST['check_itemtype'])) {
52 48
      if (!($checkitem = getItemForItemtype($_POST['check_itemtype']))) {
53 49
         exit();
......
56 52
         if (!$checkitem->getFromDB($_POST['check_items_id'])) {
57 53
            exit();
58 54
         }
59
      echo "<input type='hidden' name='check_items_id' value='".$_POST["check_items_id"]."'>";
55
         echo Html::Hidden('check_items_id', array('value' => $_POST["check_items_id"]));
60 56
      }
61
      echo "<input type='hidden' name='check_itemtype' value='".$_POST["check_itemtype"]."'>";
57
      echo Html::Hidden('check_itemtype', array('value' => $_POST["check_itemtype"]));
62 58
   }
63 59

  
64
   $actions = $item->getAllMassiveActions($_POST['is_deleted'], $checkitem);
60

  
61
   $items = array();
62
   $action_items = array();
63
   foreach ($_POST['item'] as $itemtype => $values) {
64
      if ((empty($_POST['itemtype'])) || ($itemtype == $_POST['itemtype'])) {
65
         if ($item = getItemForItemtype($itemtype)) {
66
            $items[$itemtype] = $item;
67
            $actions = MassiveActions::getAllMassiveActions($item, $_POST['is_deleted'],
68
                                                            $checkitem);
69
            if (isset($actions[$_POST['action']])) {
70
               $action_items[$itemtype] = $item;
71
            }
72
         }
73
      }
74
   }
75

  
65 76
   if (!isset($_POST['specific_action']) || !$_POST['specific_action']) {
66
      echo "<input type='hidden' name='specific_action' value='0'>";
67
      if (!isset($actions[$_POST['action']])) {
77
      // If it is not a specific action, then, it must be a standard action !
78
      if (count($action_items) == 0) {
68 79
         Html::displayRightError();
69 80
         exit();
70 81
      }
82
      $specific_action = 0;
83
      $items           = $action_items;
71 84
   } else {
72
      if (!isset($actions[$_POST['action']])) {
73
         echo "<input type='hidden' name='specific_action' value='1'>";
85
      if (count($action_items) > 0) {
86
         // Even it is a specific action, it is a standard action if it is available
87
         // For instance, when limiting the display of possible action through specific
88
         $specific_action = 0;
89
         $items           = $action_items;
74 90
      } else {
75
         echo "<input type='hidden' name='specific_action' value='0'>";
91
         $specific_action = 1;
76 92
      }
77 93
   }
78 94

  
79
   echo "<input type='hidden' name='action' value='".$_POST["action"]."'>";
80
   echo "<input type='hidden' name='itemtype' value='".$_POST["itemtype"]."'>";
81
   echo "<input type='hidden' name='is_deleted' value='".$_POST["is_deleted"]."'>";
82
   echo '&nbsp;';
95
   if (count($items) == 0) {
96
      exit();
97
   }
83 98

  
84
   // Plugin specific actions
99
   foreach ($_POST['item'] as $itemtype => $items_ids) {
100
      if (!isset($items[$itemtype])) {
101
         unset($_POST['item'][$itemtype]);
102
      }
103
   }
104

  
105
   echo Html::hidden('action', array('value' => $_POST['action']));
106
   echo Html::hidden('specific_action', array('value' => $specific_action));
107
   echo Html::hidden('is_deleted', array('value' => $_POST['is_deleted']));
108

  
85 109
   $split = explode('_',$_POST["action"]);
86 110

  
87 111
   if (($split[0] == 'plugin') && isset($split[1])) {
88 112
      // Normalized name plugin_name_action
89 113
      // Allow hook from any plugin on any (core or plugin) type
90
      Plugin::doOneHook($split[1], 'MassiveActionsDisplay',
91
                        array('itemtype' => $_POST["itemtype"],
92
                              'action'   => $_POST["action"]));
114
      $plugin_input = array('action'   => $_POST['action']);
115
      if (!empty($_POST['itemtype'])) {
116
         $plugin_input['itemtype'] = $_POST['itemtype'];
117
      }
93 118

  
119
      Plugin::doOneHook($split[1], 'MassiveActionsDisplay', $plugin_input);
120

  
94 121
//    } else if ($plug=isPluginItemType($_POST["itemtype"])) {
95 122
      // non-normalized name
96 123
      // hook from the plugin defining the type
97 124
//       Plugin::doOneHook($plug['plugin'], 'MassiveActionsDisplay', $_POST["itemtype"],
98 125
//                         $_POST["action"]);
99 126
   } else {
100
      $item->showMassiveActionsParameters($_POST);
127
      MassiveActions::showSubForm($_POST);
101 128
   }
102 129
}
103 130
?>
ajax/massiveaction.php (working copy)
39 39

  
40 40
Session::checkLoginUser();
41 41

  
42
if (isset($_POST['item'])) {
42 43

  
43
if (isset($_POST['itemtype']) && isset($_POST['container'])) {
44
   if (!($item = getItemForItemtype($_POST['itemtype']))) {
45
      exit();
46
   }
47 44
   if (!isset($_POST['is_deleted'])) {
48 45
      $_POST['is_deleted'] = 0;
49 46
   }
47

  
50 48
   $checkitem = NULL;
51 49
   if (isset($_POST['check_itemtype'])) {
52 50
      $checkitem = new $_POST['check_itemtype']();
......
54 52
         $checkitem->getFromDB($_POST['check_items_id']);
55 53
      }
56 54
   }
57
   echo "<div width='90%' class='center'><br>";
58
   $formname = 'massform'.$_POST['itemtype'].mt_rand();
59
   Html::openMassiveActionsForm($formname);
60
   echo "<script type='text/javascript'>";
61
   echo "var items = $('[id=".$_POST['container']."] [id*=massaction_item_]:checked').each(function( index ) {
62
                     $('<input>').attr({
63
                     type: 'hidden',
64
                     name: $(this).attr('name'),
65
                     value: 1
66
                     }).appendTo('#$formname');
67
         });";
68
   echo "</script>";
69
   $params = array('action' => '__VALUE__');
70
   foreach ($_POST as $key => $val) {
71
      $params[$key] = $val;
55

  
56
   $actions = array();
57
   foreach ($_POST['item'] as $itemtype => $values) {
58
      if ($item = getItemForItemtype($itemtype)) {
59
         $actions = array_merge($actions,
60
                                MassiveActions::getAllMassiveActions($item, $_POST['is_deleted'],
61
                                                                     $checkitem));
62
      } else {
63
         unset($_POST['item'][$itemtype]);
64
      }
72 65
   }
73 66

  
74
   $params['specific_action'] = 0;
75
   $actions                   = $item->getAllMassiveActions($_POST['is_deleted'], $checkitem);
67
   if (count($actions) == 0) {
68
      exit();
69
   }
70

  
71
   echo "<div width='90%' class='center'><br>";
72
   Html::openMassiveActionsForm();
73
   $params = array('action'           => '__VALUE__',
74
                   'item'             => $_POST['item'],
75
                   'specific_action'  => 0);
76

  
76 77
   if (isset($_POST['specific_actions'])
77 78
       && is_array($_POST['specific_actions'])
78 79
       && count($_POST['specific_actions'])) {
......
85 86
      $actions = $specific_actions;
86 87
   }
87 88

  
89

  
88 90
   if (count($actions)) {
89
      if (isset($params['hidden']) && count($params['hidden'])) {
91
      if (isset($params['hidden']) && is_array($params['hidden'])) {
90 92
         foreach ($params['hidden'] as $key => $val) {
91
            echo "<input type='hidden' name=\"$key\" value=\"$val\">";
93
            Html::hidden($key, array('value' => $val));
92 94
         }
93 95

  
94 96
      }
front/massiveaction.php (working copy)
44 44
   }
45 45
}
46 46

  
47
if (!isset($_POST["itemtype"])
48
    || !($item = getItemForItemtype($_POST["itemtype"]))
49
    || !isset($_POST['is_deleted'])) {
50
   exit();
51
}
52

  
53 47
$checkitem = NULL;
54 48
if (isset($_POST['check_itemtype'])) {
55 49
   if (!($checkitem = getItemForItemtype($_POST['check_itemtype']))) {
......
62 56
   }
63 57
}
64 58

  
65
$actions = $item->getAllMassiveActions($_POST['is_deleted'], $checkitem);
66
if (!isset($_POST['specific_action']) || !$_POST['specific_action']) {
67
   if (!isset($actions[$_POST['action']])) {
68
      Html::displayRightError();
69
      exit();
70
   }
71
} else {
72
   // No standard massive action for specific one
73
   if (isset($actions[$_POST['action']])) {
74
      Html::displayRightError();
75
      exit();
76
   }
77
}
78

  
79 59
Html::popHeader(__('Bulk modification'), $_SERVER['PHP_SELF']);
80 60

  
81 61
if (isset($_GET['multiple_actions'])) {
......
90 70
}
91 71

  
92 72
if (isset($_POST["action"])
93
    && isset($_POST["itemtype"])
94 73
    && isset($_POST["item"])
95 74
    && count($_POST["item"])) {
96 75

  
97 76
   /// Save selection
98
   if (!isset($_SESSION['glpimassiveactionselected'][$_POST["itemtype"]])
99
       || (count($_SESSION['glpimassiveactionselected'][$_POST["itemtype"]]) == 0)) {
100
      $_SESSION['glpimassiveactionselected'][$_POST["itemtype"]] = array();
101
      foreach ($_POST["item"] as $key => $val) {
102
         if ($val == 1) {
103
            $_SESSION['glpimassiveactionselected'][$_POST["itemtype"]][$key] = $key;
77
   foreach ($_POST['item'] as $itemtype => $items_ids) {
78
      if (!isset($_SESSION['glpimassiveactionselected'][$itemtype])
79
          || (count($_SESSION['glpimassiveactionselected'][$itemtype]) == 0)) {
80
         $_SESSION['glpimassiveactionselected'][$itemtype] = array();
81
         foreach ($items_ids as $items_id) {
82
            $_SESSION['glpimassiveactionselected'][$itemtype][$items_id] = $items_id;
104 83
         }
105 84
      }
106 85
   }
......
113 92
   $nbok      = 0;
114 93
   $nbnoright = 0;
115 94
   $nbko      = 0;
116
   $res = $item->executeMassiveActions($_POST);
95
   $res = MassiveActions::executeMassiveActions($_POST);
117 96

  
118 97
   if (is_array($res)
119 98
         && isset($res['ok'])
config/define.php (working copy)
286 286
                                     'show_count_on_tabs', 'show_jobs_at_login', 'task_private',
287 287
                                     'use_flat_dropdowntree');
288 288

  
289

  
290
// list des trucs dont je ne sais pas quoi faire :
291
// duplicate : array(Rule, Calendar)
292
// install : array(Computer, Computer_SoftwareLicense)
293
//
294
// TODO: transform export action to export_rule ?
295
// TODO: transform reset action to reset_crontask ?
296
// TODO: transform give action to give_consumable ?
297
// TODO: transform import action to import_ldap ?
298
// TODO: transform sync action to sync_ldap ?
299

  
300
// TODO: move unaffect to CommonDBRelation
301
// TODO: clear unlock_Printer, unlock_Monitor ... to Lock class
302
$CFG_GLPI['massive_action_itemtype'] = array(
303
                                             'activate_infocoms'         => 'MassiveActions',
304
                                             'add_actor'                 => 'CommonITILObject',
305
                                             'add_contact_supplier'      => 'Contact_Supplier',
306
                                             'add_contract_item'         => 'Contract',
307
                                             'add_delegatee_group'       => 'Group_User',
308
                                             'add_document'              => 'Document',
309
                                             'add_document_item'         => 'Document',
310
                                             'add_followup'              => 'Ticket',
311
                                             'add_supervisor_group'      => 'Group_User',
312
                                             'add_task'                  => 'CommonITILObject',
313
                                             'add_transfer_list'         => 'MassiveActions',
314
                                             'add_user_group'            => 'Group_User',
315
                                             'add_userprofile'           => 'User',
316
                                             'assign_vlan'               => 'NetworkPort',
317
                                             'change_authtype'           => 'User',
318
                                             'changegroup'               => 'Group',
319
                                             'compute_software_category' => 'Software',
320
                                             'connect'                   => 'Computer_Item',
321
                                             'delete'                    => 'MassiveActions',
322
                                             'delete_email'              => 'NotImportedEmail',
323
                                             'delete_for_user'           => 'DisplayPreference',
324
                                             'disconnect'                => 'Computer_Item',
325
                                             'export'                    => 'Rule',
326
                                             'force_user_ldap_update'    => 'User',
327
                                             'give'                      => 'Consumable',
328
                                             'import'                    => 'AuthLDAP',
329
                                             'import_email'              => 'NotImportedEmail',
330
                                             'import_group'              => 'AuthLDAP',
331
                                             'link_ticket'               => 'Ticket',
332
                                             'merge'                     => 'CommonDropdown',
333
                                             'mergesoftware'             => 'Software',
334
                                             'move_license'              => 'Computer_SoftwareLicense',
335
                                             'move_port'                 => 'NetworkPort',
336
                                             'move_rule'                 => 'Rule',
337
                                             'move_under'                => 'CommonTreeDropdown',
338
                                             'move_version'              => 'Computer_SoftwareVersion',
339
                                             'purge'                     => 'MassiveActions',
340
                                             'purge_item_but_devices'    => 'MassiveActions',
341
                                             'remove_contract_item'      => 'Contract',
342
                                             'remove_document'           => 'Document',
343
                                             'remove_document_item'      => 'Document',
344
                                             'replay_dictionnary'        => 'Software',
345
                                             'reset'                     => 'CronTask',
346
                                             'restore'                   => 'MassiveActions',
347
                                             'sendmail'                  => 'QueuedMail',
348
                                             'solveticket'               => 'Problem_Ticket',
349
                                             'submit_validation'         => 'Ticket',
350
                                             'sync'                      => 'AuthLDAP',
351
                                             'transform_to'              => 'NetworkPortMigration',
352
                                             'update'                    => 'MassiveActions',
353
                                             'updatepages'               => 'Cartridge',
354
                                             'unaffect'                  => 'MassiveActions',
355
                                             'unassign_vlan'             => 'NetworkPort',
356
                                             'uninstall'                 => 'Cartridge',
357
                                             'unlock'                    => 'Lock',
358
                                             );
359

  
360

  
361

  
289 362
?>
inc/massiveactions.class.php (revision 0)
1
<?php
2
/*
3
 * @version $Id: massiveactions.class.php 21200 2013-06-27 08:05:30Z webmyster $
4
 -------------------------------------------------------------------------
5
 GLPI - Gestionnaire Libre de Parc Informatique
6
 Copyright (C) 2003-2013 by the INDEPNET Development Team.
7

  
8
 http://indepnet.net/   http://glpi-project.org
9
 -------------------------------------------------------------------------
10

  
11
 LICENSE
12

  
13
 This file is part of GLPI.
14

  
15
 GLPI is free software; you can redistribute it and/or modify
16
 it under the terms of the GNU General Public License as published by
17
 the Free Software Foundation; either version 2 of the License, or
18
 (at your option) any later version.
19

  
20
 GLPI is distributed in the hope that it will be useful,
21
 but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 GNU General Public License for more details.
24

  
25
 You should have received a copy of the GNU General Public License
26
 along with GLPI. If not, see <http://www.gnu.org/licenses/>.
27
 --------------------------------------------------------------------------
28
 */
29

  
30
if (!defined('GLPI_ROOT')) {
31
   die("Sorry. You can't access directly to this file");
32
}
33

  
34

  
35
/** @file
36
 * @brief
37
 *
38
 * @since version 0.85
39
 *
40
**/
41

  
42
class MassiveActions {
43

  
44
   static function getItemtypeFromInput(array &$input, $display_selector = false) {
45
      global $CFG_GLPI;
46

  
47
      if (!empty($input['itemtype'])) {
48
         return $input['itemtype'];
49
      }
50

  
51
      if (isset($input['item']) && is_array($input['item'])) {
52
         $keys = array_keys($input['item']);
53
         if (count($keys) == 1) {
54
            return $keys[0];
55
         }
56

  
57
         if ($display_selector) {
58
            $itemtypes = array(-1 => Dropdown::EMPTY_VALUE);
59
            foreach ($keys as $itemtype) {
60
               $itemtypes[$itemtype] = $itemtype::getTypeName(2);
61
            }
62

  
63
            _e('Select the type of the item on which applying this action')."<br>\n";
64

  
65
            $rand   = Dropdown::showFromArray('itemtype', $itemtypes);
66

  
67
            echo "<br><br>";
68

  
69
            $params             = $input;
70
            $params['itemtype'] = '__VALUE__';
71
            Ajax::updateItemOnSelectEvent("dropdown_itemtype$rand", "show_itemtype$rand",
72
                                          $_SERVER['REQUEST_URI'], $params);
73

  
74
            echo "<span id='show_itemtype$rand'>&nbsp;</span>\n";
75
            exit();
76
         }
77
      }
78

  
79
     return false;
80
   }
81

  
82

  
83
   static function addHiddenItemsFromInput($input) {
84
      if (isset($input['item']) && is_array($input['item'])) {
85
         foreach ($input['item'] as $itemtype => $items_ids) {
86
            foreach ($items_ids as $items_id => $val) {
87
               echo Html::hidden('item['.$itemtype.'][]', array('value' => $items_id));
88
            }
89
         }
90
      }
91
   }
92

  
93

  
94
   /**
95
    * Get the standard massive actions
96
    *
97
    * This must not be overloaded in Class
98
    * @param $is_deleted massive action for deleted items ?   (default 0)
99
    * @param $checkitem link item to check right              (default NULL)
100
    *
101
    * @return an array of massive actions
102
   **/
103
   static function getAllMassiveActions(CommonDBTM $item, $is_deleted=0, $checkitem=NULL) {
104
      global $CFG_GLPI, $PLUGIN_HOOKS;
105

  
106
      $itemtype = $item->getType();
107

  
108
      if (!is_null($checkitem)) {
109
         $canupdate = $checkitem->canUpdate();
110
         $candelete = $checkitem->canDelete();
111
         $canpurge  = $checkitem->canPurge();
112
      } else {
113
         $canupdate = $itemtype::canUpdate();
114
         $candelete = $itemtype::canDelete();
115
         $canpurge  = $itemtype::canPurge();
116
      }
117

  
118
      $actions  = array();
119

  
120
      if ($is_deleted) {
121
         if ($canpurge) {
122
            if (in_array($itemtype, Item_Devices::getConcernedItems())) {
123
               $actions['purge_item_but_devices'] = _x('button',
124
                                                       'Delete permanently but keep devices');
125
               $actions['purge']                  = _x('button',
126
                                                       'Delete permanently and remove devices');
127
            } else {
128
               $actions['purge']   = _x('button', 'Delete permanently');
129
            }
130
         }
131

  
132
         if ( $canpurge) {
133
            $actions['restore'] = _x('button', 'Restore');
134
         }
135

  
136
      } else {
137
         if ($canupdate
138
             || (in_array($itemtype, $CFG_GLPI["infocom_types"])
139
                 && Infocom::canUpdate())) {
140

  
141
            //TRANS: select action 'update' (before doing it)
142
            $actions['update'] = _x('button', 'Update');
143
         }
144

  
145
         if (in_array($itemtype, $CFG_GLPI["infocom_types"])
146
             && Infocom::canCreate()) {
147
            $actions['activate_infocoms'] = __('Enable the financial and administrative information');
148
         }
149

  
150
         if ($item instanceof CommonDBChild) {
151
            if (!$itemtype::$mustBeAttached) {
152
               $actions['unaffect'] = __('Dissociate');
153
            }
154
         }
155
         if ($item instanceof CommonDBRelation) {
156
            if ((!$itemtype::$mustBeAttached_1) || (!$itemtype::$mustBeAttached_2)) {
157
               $actions['unaffect'] = __('Dissociate');
158
            }
159
         }
160

  
161
         // do not take into account is_deleted if items may be dynamic
162
         if ($item->maybeDeleted()
163
             && !$item->useDeletedToLockIfDynamic()) {
164
            if ($candelete) {
165
               $actions['delete'] = _x('button', 'Put in dustbin');
166
            }
167
         } else if ($canpurge){
168
            $actions['purge'] = _x('button', 'Delete permanently');
169
         }
170

  
171
         if (in_array($itemtype,$CFG_GLPI["document_types"])) {
172
            if (Document::canView()) {
173
               $actions['add_document']    = _x('button', 'Add a document');
174
               $actions['remove_document'] = _x('button', 'Remove a document');
175
            }
176
         }
177

  
178
         if (in_array($itemtype,$CFG_GLPI["contract_types"])) {
179
            if (Contract::canUpdate()) {
180
               $actions['add_contract_to_item']      = _x('button', 'Add a contract');
181
               $actions['remove_contract_from_item'] = _x('button', 'Remove a contract');
182
            }
183
         }
184
         // Specific actions
185
         $actions += $item->getSpecificMassiveActions($checkitem);
186
         // Plugin Specific actions
187
         if (isset($PLUGIN_HOOKS['use_massive_action'])) {
188
            foreach ($PLUGIN_HOOKS['use_massive_action'] as $plugin => $val) {
189
               $plug_actions = Plugin::doOneHook($plugin,'MassiveActions',$itemtype);
190

  
191
               if (count($plug_actions)) {
192
                  $actions += $plug_actions;
193
               }
194
            }
195
         }
196
      }
197
      //Add unlock if needed
198
      $actions += Lock::getUnlockMassiveActions($itemtype);
199

  
200
      // Manage forbidden actions
201
      $forbidden_actions = $item->getForbiddenStandardMassiveAction();
202
      if (is_array($forbidden_actions) && count($forbidden_actions)) {
203
         foreach ($forbidden_actions as $actiontodel) {
204
            if (isset($actions[$actiontodel])) {
205
               unset($actions[$actiontodel]);
206
            }
207
         }
208
      }
209
      return $actions;
210
   }
211

  
212

  
213
   static function showMassiveActionsSubForm(array $input) {
214
      global $CFG_GLPI;
215

  
216
      switch ($input['action']) {
217
         case 'update' :
218
            $itemtype = self::getItemtypeFromInput($input, true);
219
            if ($itemtype === false) {
220
               exit();
221
            }
222
            self::addHiddenItemsFromInput($input);
223
            // Specific options for update fields
224
            if (!isset($input['options'])) {
225
               $input['options'] = array();
226
            }
227
            $group          = "";
228
            $show_all       = true;
229
            $show_infocoms  = true;
230

  
231
            if (in_array($itemtype, $CFG_GLPI["infocom_types"])
232
                && (!$itemtype::canUpdate()
233
                    || !Infocom::canUpdate())) {
234
               $show_all      = false;
235
               $show_infocoms = Infocom::canUpdate();
236
            }
237
            $searchopt = Search::getCleanedOptions($itemtype, 'w');
238

  
239
            $values = array(0 => Dropdown::EMPTY_VALUE);
240

  
241
            foreach ($searchopt as $key => $val) {
242
               if (!is_array($val)) {
243
                  $group = $val;
244
               } else {
245
                  // No id and no entities_id massive action and no first item
246
                  if (($val["field"] != 'id')
247
                      && ($key != 1)
248
                     // Permit entities_id is explicitly activate
249
                      && (($val["linkfield"] != 'entities_id')
250
                          || (isset($val['massiveaction']) && $val['massiveaction']))) {
251

  
252
                     if (!isset($val['massiveaction']) || $val['massiveaction']) {
253

  
254
                        if ($show_all) {
255
                           $values[$group][$key] = $val["name"];
256
                        } else {
257
                           // Do not show infocom items
258
                           if (($show_infocoms
259
                                && Search::isInfocomOption($itemtype, $key))
260
                               || (!$show_infocoms
261
                                   && !Search::isInfocomOption($itemtype, $key))) {
262
                              $values[$group][$key] = $val["name"];
263
                           }
264
                        }
265
                     }
266
                  }
267
               }
268
            }
269

  
270
            $rand = Dropdown::showFromArray('id_field', $values);
271

  
272
            $paramsmassaction = array('id_field' => '__VALUE__',
273
                                      'itemtype' => $itemtype,
274
                                      'options'  => $input['options']);
275

  
276
            foreach ($input as $key => $val) {
277
               if (preg_match("/extra_/",$key,$regs)) {
278
                  $paramsmassaction[$key] = $val;
279
               }
280
            }
281
            Ajax::updateItemOnSelectEvent("dropdown_id_field$rand", "show_massiveaction_field",
282
                                          $CFG_GLPI["root_doc"]."/ajax/dropdownMassiveActionField.php",
283
                                          $paramsmassaction);
284

  
285
            echo "<br><br><span id='show_massiveaction_field'>&nbsp;</span>\n";
286
            return true;
287
            break;
288
      }
289
   }
290

  
291

  
292
   static function showSubForm(array $input) {
293
      global $CFG_GLPI;
294

  
295
      if (!isset($input["item"]) || (count($input["item"]) == 0) || (empty($input['action']))) {
296
        return false;
297
      }
298

  
299
      if (isset($CFG_GLPI['massive_action_itemtype'][$input['action']])) {
300
         $itemtype = $CFG_GLPI['massive_action_itemtype'][$input['action']];
301
         if (method_exists($itemtype, 'processMassiveActions')) {
302
            // The class respects new Massive Action framework !
303

  
304
            if (method_exists($itemtype, 'showMassiveActionsSubForm')) {
305
               // But it may not require specific sub form !
306
               $itemtype::showMassiveActionsSubForm($input);
307
            }
308

  
309
            return true;
310
        }
311
      } else {
312
         $itemtype = self::getItemtypeFromInput($input, true);
313
      }
314

  
315
      if ($itemtype === false) {
316
         exit();
317
      }
318

  
319
      self::addHiddenItemsFromInput($input);
320
      $input['itemtype'] = $itemtype;
321
      $item = new $itemtype();
322
      if (!$item->showSpecificMassiveActionsParameters($input)) {
323
         echo "<input type='submit' name='massiveaction' class='submit' value='".
324
            __s('Post')."'>\n";
325
      }
326
      return false;
327
   }
328

  
329
   /**
330
    * Execute standard massive actions for all passed items
331
    *
332
    * This must not be overloaded in Class
333
    * @param $input array of input datas
334
    *
335
    * @return an array of results (ok, ko, noright counts, may include REDIRECT field to set REDIRECT page)
336
   **/
337
   static function executeMassiveActions(array $input) {
338
      global $CFG_GLPI;
339

  
340
      if (!isset($input["item"]) || (count($input["item"]) == 0) || (empty($input['action']))) {
341
         return false;
342
      }
343

  
344
      if (isset($CFG_GLPI['massive_action_itemtype'][$input['action']])) {
345
         $itemtype = $CFG_GLPI['massive_action_itemtype'][$input['action']];
346
         if (method_exists($itemtype, 'processMassiveActions')) {
347
            // The class respects new Massive Action framework !
348
            $itemtype::processMassiveActions($input);
349
            return true;
350
         }
351
      } else {
352
         $itemtype = self::getItemtypeFromInput($input, false);
353
      }
354

  
355
      /*
356
        TODO !
357
            // Plugin specific actions
358
            $split = explode('_',$input["action"]);
359
            $res   = '';
360
            if ($split[0] == 'plugin' && isset($split[1])) {
361
               // Normalized name plugin_name_action
362
               // Allow hook from any plugin on any (core or plugin) type
363
               $res = Plugin::doOneHook($split[1], 'MassiveActionsProcess', $input);
364

  
365
//            } else if ($plug=isPluginItemType($input["itemtype"])) {
366
               // non-normalized name
367
               // hook from the plugin defining the type
368
//               $res = Plugin::doOneHook($plug['plugin'], 'MassiveActionsProcess', $input);
369
            } else {
370
               $res = $item->doSpecificMassiveActions($input);
371
            }
372
       */
373

  
374
      if (($itemtype === false) || (!isset($input['item'][$itemtype]))
375
          || (!($item = getItemForItemtype($_POST["itemtype"])))) {
376
         return;
377
      }
378

  
379
      $res = array('ok'      => 0,
380
                   'ko'      => 0,
381
                   'noright' => 0);
382

  
383

  
384
      $input['itemtype'] = $itemtype;
385
      $input['item']     = $input['item'][$itemtype];
386

  
387
      $checkitem = NULL;
388
      if (isset($input['check_itemtype'])) {
389
         if ($checkitem = getItemForItemtype($input['check_itemtype'])) {
390
            if (isset($input['check_items_id'])) {
391
               $checkitem->getFromDB($input['check_items_id']);
392
            }
393
         }
394
      }
395
      $actions = MassiveActions::getAllMassiveActions($item, $input['is_deleted'], $checkitem);
396

  
397
      if ($input['specific_action'] || isset($actions[$input['action']])) {
398
         if ($tmpres = $item->doMassiveActions($input)) {
399
            $res['ok']      += $tmpres['ok'];
400
            $res['ko']      += $tmpres['ko'];
401
            $res['noright'] += $tmpres['noright'];
402
         }
403
      } else {
404
         $res['noright'] += count($input['item']);
405
      }
406
   }
407

  
408
   static function processMassiveActions(array $input) {
409
      global $CFG_GLPI;
410

  
411
      if (!isset($input["item"]) || (count($input["item"]) == 0)) {
412
         return false;
413
      }
414

  
415
      $res = array('ok'      => 0,
416
                   'ko'      => 0,
417
                   'noright' => 0);
418

  
419
      switch ($input['action']) {
420

  
421
         /*
422
           TODO!
423
         case "add_transfer_list" :
424
            if (!isset($_SESSION['glpitransfer_list'])) {
425
               $_SESSION['glpitransfer_list'] = array();
426
            }
427
            if (!isset($_SESSION['glpitransfer_list'][$input["itemtype"]])) {
428
               $_SESSION['glpitransfer_list'][$input["itemtype"]] = array();
429
            }
430
            foreach ($input["item"] as $key => $val) {
431
               if ($val == 1) {
432
                  $_SESSION['glpitransfer_list'][$input["itemtype"]][$key] = $key;
433
                  $res['ok']++;
434
               }
435
            }
436
            $res['REDIRECT'] = $CFG_GLPI['root_doc'].'/front/transfer.action.php';
437
            break;
438
         */
439

  
440
         case "delete" :
441
            foreach ($input["item"] as $itemtype => $items_ids) {
442
               if (!($item = getItemForItemtype($itemtype))) {
443
                  continue;
444
               }
445
               foreach ($items_ids as $items_id) {
446
                  if ($item->can($items_id, DELETE)) {
447
                     if ($item->delete(array("id" => $items_id))) {
448
                        $res['ok']++;
449
                     } else {
450
                        $res['ko']++;
451
                        $res['messages'][] = $item->getErrorMessage(ERROR_ON_ACTION);
452
                     }
453
                  } else {
454
                     $res['noright']++;
455
                     $res['messages'][] = $item->getErrorMessage(ERROR_RIGHT);
456
                  }
457
               }
458
            }
459
            break;
460

  
461
         case 'purge_item_but_devices':
462
         case 'purge' :
463
            foreach ($input["item"] as $itemtype => $items_ids) {
464
               if (!($item = getItemForItemtype($itemtype))) {
465
                  continue;
466
               }
467
               foreach ($items_ids as $items_id) {
468
                  if ($item->can($items_id, PURGE)) {
469
                     $force = 1;
470
                     // Only mark deletion for
471
                     if ($item->maybeDeleted()
472
                        && $item->useDeletedToLockIfDynamic()
473
                        && $item->isDynamic()) {
474
                        $force = 0;
475
                     }
476
                     $delete_array = array('id' => $items_id);
477
                     if ($input['action'] == 'purge_item_but_devices') {
478
                        $delete_array['keep_devices'] = true;
479
                     }
480
                     if ($item->delete($delete_array, $force)) {
481
                        $res['ok']++;
482
                     } else {
483
                        $res['ko']++;
484
                        $res['messages'][] = $item->getErrorMessage(ERROR_ON_ACTION);
485
                     }
486
                  } else {
487
                     $res['noright']++;
488
                     $res['messages'][] = $item->getErrorMessage(ERROR_RIGHT);
489
                  }
490
               }
491
            }
492
            break;
493

  
494
         case 'unaffect' :
495
            foreach ($input["item"] as $itemtype => $items_ids) {
496
               if (!($item = getItemForItemtype($itemtype))) {
497
                  continue;
498
               }
499
               foreach ($items_ids as $items_id) {
500
                  if ($item->can($items_id, UPDATE)) {
501
                     if ($item instanceof CommonDBRelation) {
502
                        if ($item->affectRelation($items_id, $input['peer'])) {
503
                           $res['ok']++;
504
                        } else {
505
                           $res['ko']++;
506
                           $res['messages'][] = $item->getErrorMessage(ERROR_ON_ACTION);
507
                        }
508
                     } elseif ($item instanceof CommonDBChild) {
509
                        if ($item->affectChild($items_id)) {
510
                           $res['ok']++;
511
                        } else {
512
                           $res['ko']++;
513
                           $res['messages'][] = $item->getErrorMessage(ERROR_ON_ACTION);
514
                        }
515
                     }
516
                  } else {
517
                     $res['noright']++;
518
                     $res['messages'][] = $item->getErrorMessage(ERROR_RIGHT);
519
                  }
520
               }
521
            }
522
            break;
523

  
524
         case "restore" :
525
            foreach ($input["item"] as $itemtype => $items_ids) {
526
               if (!($item = getItemForItemtype($itemtype))) {
527
                  continue;
528
               }
529
               foreach ($items_ids as $items_id) {
530
                  if ($item->can($items_id, PURGE)) {
531
                     if ($item->restore(array("id" => $items_id))) {
532
                        $res['ok']++;
533
                     } else {
534
                        $res['ko']++;
535
                        $res['messages'][] = $item->getErrorMessage(ERROR_ON_ACTION);
536
                     }
537
                  } else {
538
                     $res['noright']++;
539
                     $res['messages'][] = $item->getErrorMessage(ERROR_RIGHT);
540
                  }
541
               }
542
            }
543
            break;
544

  
545
         case "update" :
546
            // TODO : ameliore le code derrier pour ne plus remodifier $input !
547
            $itemtype = self::getItemtypeFromInput($input, false);
548
            $input['itemtype'] = $itemtype;
549
            $input['item'] = $input['item'][$itemtype];
550
            $searchopt = Search::getCleanedOptions($input["itemtype"],'w');
551
            if (isset($searchopt[$input["id_field"]]) && ($item = getItemForItemtype($itemtype))) {
552
               /// Infocoms case
553
               if (!isPluginItemType($input["itemtype"]) && false
554
                   && Search::isInfocomOption($input["itemtype"], $input["id_field"])) {
555
                  // TODO : update to add infocom !
556
                  $ic = new Infocom();
557
                  $link_entity_type = -1;
558
                  /// Specific entity item
559
                  if ($searchopt[$input["id_field"]]["table"] == "glpi_suppliers") {
560
                     $ent = new Supplier();
561
                     if ($ent->getFromDB($input[$input["field"]])) {
562
                        $link_entity_type = $ent->fields["entities_id"];
563
                     }
564
                  }
565
                  foreach ($input["item"] as $items_id => $val) {
566
                     if ($val == 1) {
567
                        if ($item->getFromDB($items_id)) {
568
                           if (($link_entity_type < 0)
569
                              || ($link_entity_type == $item->getEntityID())
570
                              || ($ent->fields["is_recursive"]
571
                                 && in_array($link_entity_type, getAncestorsOf("glpi_entities",
572
                                             $item->getEntityID())))) {
573
                              $input2["items_id"] = $items_id;
574
                              $input2["itemtype"] = $input["itemtype"];
575

  
576
                              if ($ic->can(-1,'w',$input2)) {
577
                                 // Add infocom if not exists
578
                                 if (!$ic->getFromDBforDevice($input["itemtype"],$items_id)) {
579
                                    $input2["items_id"] = $items_id;
580
                                    $input2["itemtype"] = $input["itemtype"];
581
                                    unset($ic->fields);
582
                                    $ic->add($input2);
583
                                    $ic->getFromDBforDevice($input["itemtype"], $items_id);
584
                                 }
585
                                 $id = $ic->fields["id"];
586
                                 unset($ic->fields);
587
                                 if ($ic->update(array('id'   => $id,
588
                                                      $input["field"]
589
                                                            => $input[$input["field"]]))) {
590
                                    $res['ok']++;
591
                                 } else {
592
                                    $res['ko']++;
593
                                    $res['messages'][] = $item->getErrorMessage(ERROR_ON_ACTION);
594
                                 }
595
                              } else {
596
                                 $res['noright']++;
597
                                 $res['messages'][] = $item->getErrorMessage(ERROR_RIGHT);
598
                              }
599
                           } else {
600
                              $res['ko']++;
601
                              $res['messages'][] = $item->getErrorMessage(ERROR_COMPAT);
602
                           }
603
                        } else {
604
                           $res['ko']++;
605
                           $res['messages'][] = $item->getErrorMessage(ERROR_NOT_FOUND);
606
                        }
607
                     }
608
                  }
609

  
610
               } else { /// Not infocoms
611
                  Toolbox::logDebug('Yop !');
612
                  $link_entity_type = array();
613
                  /// Specific entity item
614
                  $itemtable = getTableForItemType($input["itemtype"]);
615

  
616
                  Toolbox::logDebug('Yop !');
617

  
618
                  $itemtype2 = getItemTypeForTable($searchopt[$input["id_field"]]["table"]);
619
                  if ($item2 = getItemForItemtype($itemtype2)) {
620

  
621
                     if (($input["id_field"] != 80) // No entities_id fields
622
                        && ($searchopt[$input["id_field"]]["table"] != $itemtable)
623
                        && $item2->isEntityAssign()
624
                        && $item->isEntityAssign()) {
625
                        if ($item2->getFromDB($input[$input["field"]])) {
626
                           if (isset($item2->fields["entities_id"])
627
                              && ($item2->fields["entities_id"] >= 0)) {
628

  
629
                              if (isset($item2->fields["is_recursive"])
630
                                 && $item2->fields["is_recursive"]) {
631
                                 $link_entity_type = getSonsOf("glpi_entities",
632
                                                               $item2->fields["entities_id"]);
633
                              } else {
634
                                 $link_entity_type[] = $item2->fields["entities_id"];
635
                              }
636
                           }
637
                        }
638
                     }
639
                  }
640

  
641
                  Toolbox::logDebug($input['item']);
642

  
643
                  foreach ($input["item"] as $items_id) {
644
                     if ($item->can($items_id,'w')
645
                         && $item->canMassiveAction($input['action'], $input['field'],
646
                                                    $input[$input["field"]])) {
647
                        if ((count($link_entity_type) == 0)
648
                            || in_array($item->fields["entities_id"], $link_entity_type)) {
649
                           if ($item->update(array('id'   => $items_id,
650
                                                   $input["field"]
651
                                                   => $input[$input["field"]]))) {
652
                              $res['ok']++;
653
                           } else {
654
                              $res['ko']++;
655
                              $res['messages'][] = $item->getErrorMessage(ERROR_ON_ACTION);
656
                           }
657
                        } else {
658
                           $res['ko']++;
659
                           $res['messages'][] = $item->getErrorMessage(ERROR_COMPAT);
660
                        }
661
                     } else {
662
                        $res['noright']++;
663
                        $res['messages'][] = $item->getErrorMessage(ERROR_RIGHT);
664
                     }
665
                  }
666
               }
667
            }
668
            break;
669

  
670
            /*
671
              TODO !
672
         case "activate_infocoms" :
673
               $ic = new Infocom();
674
               if ($ic->canCreate()) {
675
                  foreach ($input["item"] as $items_id => $val) {
676
                     $input = array('itemtype' => $input['itemtype'],
677
                                    'items_id' => $items_id);
678
                     if (!$ic->getFromDBforDevice($input['itemtype'], $items_id)) {
679
                           if ($ic->can(-1,'w',$input)) {
680
                              if ($ic->add($input)) {
681
                                 $res['ok']++;
682
                              } else {
683
                                 $res['ko']++;
684
                                 $res['messages'][] = $item->getErrorMessage(ERROR_ON_ACTION);
685
                              }
686
                           } else {
687
                              $res['noright']++;
688
                              $res['messages'][] = $item->getErrorMessage(ERROR_RIGHT);
689
                           }
690
                     } else {
691
                        $res['ko']++;
692
                        $res['messages'][] = $item->getErrorMessage(ERROR_NOT_FOUND);
693
                     }
694
                  }
695
               }
696
            break;
697
            */
698
      }
699
      return $res;
700
   }
701
}
702
?>
inc/item_devices.class.php (working copy)
61 61
   static $rightname = 'device';
62 62

  
63 63

  
64
   static function getTypeName($nb=0) {
65

  
66
      $device_type = static::getDeviceType();
67
      //TRANS: %s is the type of the component
68
      return sprintf(__('Item - %s link'), $device_type::getTypeName($nb));
69

  
70
   }
71

  
72

  
64 73
   function getForbiddenStandardMassiveAction() {
65 74

  
66 75
      $forbidden   = parent::getForbiddenStandardMassiveAction();
67
      $forbidden[] = 'update';
76

  
77
      if (count(static::getSpecificities()) == 0) {
78
         $forbidden[] = 'update';
79
      }
80

  
68 81
      return $forbidden;
82

  
69 83
   }
70 84

  
71 85

  
......
447 461
      }
448 462

  
449 463
      if ($options['canedit']) {
464
         /*
450 465
         if ($item instanceof CommonDevice) {
451 466
            $content = '&nbsp;';
452 467
         } else {
......
466 481
            $content = array(array('function'   => 'Html::showMassiveActions',
467 482
                                   'parameters' => array(static::getType(), $massiveactionparams)));
468 483
         }
484
         */
485
         $content = "&nbsp;";
469 486
         $delete_one  = $table_group->addHeader('one', $content, $delete_column, $previous_column);
470 487
      }
471 488

  
inc/commondbtm.class.php (working copy)
3007 3007

  
3008 3008

  
3009 3009
   /**
3010
    * Display options add action button for massive actions
3011
    *
3012
    * @since version 0.84
3013
    *
3014
    * This must not be overloaded in Class
3015
    *
3016
    * @param $input array of input datas
3017
    *
3018
    * @return nothing display
3019
   **/
3020
   function showMassiveActionsParameters($input=array()) {
3021
      global $CFG_GLPI;
3022

  
3023
      switch ($input['action']) {
3024
         case "add_contract_item" :
3025
            if ($input['itemtype'] == 'Contract') {
3026
               Dropdown::showSelectItemFromItemtypes(array('itemtype_name'
3027
                                                                   => 'item_itemtype',
3028
                                                           'itemtypes'
3029
                                                                    => $CFG_GLPI["contract_types"],
3030
                                                           'checkright'
3031
                                                                    => true));
3032
               echo "<br><br><input type='submit' name='massiveaction' class='submit' value='".
3033
                              _sx('button', 'Add')."'>";
3034
            } else {
3035
               Contract::dropdown(array('name' => "contracts_id"));
3036
               echo "<br><br><input type='submit' name='massiveaction' class='submit' value='".
3037
                              _sx('button', 'Add')."'>";
3038
            }
3039
            break;
3040

  
3041
         case "remove_contract_item" :
3042
            if ($input['itemtype'] == 'Contract') {
3043
               Dropdown::showSelectItemFromItemtypes(array('itemtype_name'
3044
                                                                   => 'item_itemtype',
3045
                                                           'itemtypes'
3046
                                                                    => $CFG_GLPI["contract_types"],
3047
                                                           'checkright'
3048
                                                                    => true));
3049
               echo "<br><br><input type='submit' name='massiveaction' class='submit' value='".
3050
                              _sx('button', 'Delete permanently')."'>";
3051
            } else {
3052
               Contract::dropdown(array('name' => "contracts_id"));
3053
               echo "<br><br><input type='submit' name='massiveaction' class='submit' value='".
3054
                              _sx('button', 'Delete permanently')."'>";
3055
            }
3056
            break;
3057

  
3058
         case "add_document" :
3059
            Document::dropdown(array('name' => 'documents_id'));
3060
            echo "<br><br><input type='submit' name='massiveaction' class='submit' value='".
3061
                           _sx('button', 'Add')."'>";
3062
            break;
3063

  
3064
         case "remove_document" :
3065
            Document::dropdown(array('name' => 'documents_id'));
3066
            echo "<br><br><input type='submit' name='massiveaction' class='submit' value='".
3067
                           _sx('button', 'Delete permanently')."'>";
3068
            break;
3069

  
3070
         case 'unaffect':
3071
            if ($this instanceof CommonDBRelation) {
3072
               if ((!static::$mustBeAttached_1) && (!static::$mustBeAttached_2)) {
3073
                  $values = array();
3074
                  if ((empty(static::$itemtype_1))
3075
                      || (preg_match('/^itemtype/', static::$itemtype_1))) {
3076
                     $values[0] = __('First Item');
3077
                  } else {
3078
                     $itemtype_1 = static::$itemtype_1;
3079
                     $values[0] = $itemtype_1::getTypeName(2);
3080
                  }
3081
                  if ((empty(static::$itemtype_2))
3082
                      || (preg_match('/^itemtype/', static::$itemtype_2))) {
3083
                     $values[1] = __('Second Item');
3084
                  } else {
3085
                     $itemtype_2 = static::$itemtype_2;
3086
                     $values[1] = $itemtype_2::getTypeName(2);
3087
                  }
3088
                  Dropdown::showFromArray('peer', $values);
3089
               } elseif (!static::$mustBeAttached_1) {
3090
                  echo "<input type='hidden' name='peer' value='0'>";
3091
               } elseif (!static::$mustBeAttached_2) {
3092
                  echo "<input type='hidden' name='peer' value='1'>";
3093
               }
3094
            }
3095
            echo "<br><br><input type='submit' name='massiveaction' class='submit' value='".
3096
                           __('Dissociate')."'>";
3097
            break;
3098

  
3099
         case "update" :
3100
            // Specific options for update fields
3101
            if (!isset($input['options'])) {
3102
               $input['options'] = array();
3103
            }
3104
            $group          = "";
3105
            $show_all       = true;
3106
            $show_infocoms  = true;
3107

  
3108
            if (in_array($input["itemtype"], $CFG_GLPI["infocom_types"])
3109
                && (!static::canUpdate()
3110
                    || !Infocom::canUpdate())) {
3111
               $show_all      = false;
3112
               $show_infocoms = Infocom::canUpdate();
3113
            }
3114
            $searchopt = Search::getCleanedOptions($input["itemtype"], 'w');
3115

  
3116
            $values = array(0 => Dropdown::EMPTY_VALUE);
3117

  
3118
            foreach ($searchopt as $key => $val) {
3119
               if (!is_array($val)) {
3120
                  $group = $val;
3121
               } else {
3122
                  // No id and no entities_id massive action and no first item
3123
                  if (($val["field"] != 'id')
3124
                      && ($key != 1)
3125
                     // Permit entities_id is explicitly activate
3126
                      && (($val["linkfield"] != 'entities_id')
3127
                          || (isset($val['massiveaction']) && $val['massiveaction']))) {
3128

  
3129
                     if (!isset($val['massiveaction']) || $val['massiveaction']) {
3130

  
3131
                        if ($show_all) {
3132
                           $values[$group][$key] = $val["name"];
3133
                        } else {
3134
                           // Do not show infocom items
3135
                           if (($show_infocoms
3136
                                && Search::isInfocomOption($input["itemtype"], $key))
3137
                               || (!$show_infocoms
3138
                                   && !Search::isInfocomOption($input["itemtype"], $key))) {
3139
                              $values[$group][$key] = $val["name"];
3140
                           }
3141
                        }
3142
                     }
3143
                  }
3144
               }
3145
            }
3146

  
3147
            $rand = Dropdown::showFromArray('id_field', $values);
3148

  
3149
            $paramsmassaction = array('id_field' => '__VALUE__',
3150
                                      'itemtype' => $input["itemtype"],
3151
                                      'options'  => $input['options']);
3152

  
3153
            foreach ($input as $key => $val) {
3154
               if (preg_match("/extra_/",$key,$regs)) {
3155
                  $paramsmassaction[$key] = $val;
3156
               }
3157
            }
3158
            Ajax::updateItemOnSelectEvent("dropdown_id_field$rand", "show_massiveaction_field",
3159
                                          $CFG_GLPI["root_doc"]."/ajax/dropdownMassiveActionField.php",
3160
                                          $paramsmassaction);
3161

  
3162
            echo "<br><br><span id='show_massiveaction_field'>&nbsp;</span>\n";
3163
            break;
3164

  
3165
         default :
3166
            if (!$this->showSpecificMassiveActionsParameters($input)) {
3167
               echo "<input type='submit' name='massiveaction' class='submit' value='".
3168
                      __s('Post')."'>\n";
3169
            }
3170
      }
3171

  
3172
      return false;
3173
   }
3174

  
3175

  
3176
   /**
3177 3010
    * Display specific options add action button for massive actions
3178 3011
    *
3179 3012
    * This may be overloaded in Class
......
3187 3020
   }
3188 3021

  
3189 3022

  
3190

  
3191 3023
   /**
3192
    * Execute standard massive actions for all passed items
3193
    *
3194
    * @since version 0.85
3195
    *
3196
    * This must not be overloaded in Class
3197
    * @param $input array of input datas
3198
    *
3199
    * @return an array of results (ok, ko, noright counts, may include REDIRECT field to set REDIRECT page)
3200
   **/
3201
   function executeMassiveActions($input = array()) {
3202

  
3203
      if (!isset($input["item"]) || (count($input["item"]) == 0)) {
3204
         return false;
3205
      }
3206

  
3207
      $res = array('ok'      => 0,
3208
                   'ko'      => 0,
3209
                   'noright' => 0);
3210

  
3211
      $items = $input['item'];
3212
      $inititemtype = $input['itemtype'];
3213
      foreach ($items as $itemtype => $data) {
3214
         $input['itemtype'] = $itemtype;
3215
         $input['item']     = $data;
3216

  
3217
         // Check if action is available for this itemtype
3218
         $actionok = false;
3219
         if ($item = getItemForItemtype($itemtype)) {
3220
            $checkitem = NULL;
3221
            if (isset($input['check_itemtype'])) {
3222
               if ($checkitem = getItemForItemtype($input['check_itemtype'])) {
3223
                  if (isset($input['check_items_id'])) {
3224
                     $checkitem->getFromDB($input['check_items_id']);
3225
                  }
3226
               }
3227
            }
3228
            $actions = $item->getAllMassiveActions($input['is_deleted'], $checkitem);
3229

  
3230
            if ($input['specific_action'] || isset($actions[$input['action']])) {
3231
               $actionok = true;
3232
            } else {
3233
               $res['noright'] += count($input['item']);
3234
            }
3235
         }
3236

  
3237
         if ($actionok) {
3238
            if ($tmpres = $item->doMassiveActions($input)) {
3239
               $res['ok']      += $tmpres['ok'];
3240
               $res['ko']      += $tmpres['ko'];
3241
               $res['noright'] += $tmpres['noright'];
3242
            }
3243
         } else {
3244
            $res['noright'] += count($input['item']);
3245
         }
3246
      }
3247
   }
3248

  
3249
   /**
3250
    * Do the standard massive actions
3251
    *
3252
    * @since version 0.84
3253
    *
3254
    * This must not be overloaded in Class
3255
    * @param $input array of input datas
3256
    *
3257
    * @return an array of results (ok, ko, noright counts, may include REDIRECT field to set REDIRECT page)
3258
   **/
3259
   function doMassiveActions($input=array()) {
3260
      global $CFG_GLPI;
3261

  
3262
      if (!isset($input["item"]) || (count($input["item"]) == 0)) {
3263
         return false;
3264
      }
3265

  
3266
      $res = array('ok'      => 0,
3267
                   'ko'      => 0,
3268
                   'noright' => 0);
3269

  
3270
      switch ($input['action']) {
3271
         case 'add_document' :
3272
         case 'remove_document' :
3273
            $doc = new Document;
3274
            return $doc->doSpecificMassiveActions($input);
3275

  
3276
         case 'add_contract_item' :
3277
         case 'remove_contract_item' :
3278
            $contract = new Contract;
3279
            return $contract->doSpecificMassiveActions($input);
3280

  
3281
         case "add_transfer_list" :
3282
            if (!isset($_SESSION['glpitransfer_list'])) {
3283
               $_SESSION['glpitransfer_list'] = array();
3284
            }
3285
            if (!isset($_SESSION['glpitransfer_list'][$input["itemtype"]])) {
3286
               $_SESSION['glpitransfer_list'][$input["itemtype"]] = array();
3287
            }
3288
            foreach ($input["item"] as $key => $val) {
3289
               if ($val == 1) {
3290
                  $_SESSION['glpitransfer_list'][$input["itemtype"]][$key] = $key;
3291
                  $res['ok']++;
3292
               }
3293
            }
3294
            $res['REDIRECT'] = $CFG_GLPI['root_doc'].'/front/transfer.action.php';
3295
            break;
3296

  
3297
         case "delete" :
3298
            foreach ($input["item"] as $key => $val) {
3299
               if ($val == 1) {
3300
                  if ($this->can($key, DELETE)) {
3301
                     if ($this->delete(array("id" => $key))) {
3302
                        $res['ok']++;
3303
                     } else {
3304
                        $res['ko']++;
3305
                        $res['messages'][] = $this->getErrorMessage(ERROR_ON_ACTION);
3306
                     }
3307
                  } else {
3308
                     $res['noright']++;
3309
                     $res['messages'][] = $this->getErrorMessage(ERROR_RIGHT);
3310
                  }
3311
               }
3312
            }
3313
            break;
3314

  
3315
         case 'purge_item_but_devices':
3316
         case 'purge' :
3317
            foreach ($input["item"] as $key => $val) {
3318
               if ($val == 1) {
3319
                  if ($this->can($key, PURGE)) {
3320
                     $force = 1;
3321
                     // Only mark deletion for
3322
                     if ($this->maybeDeleted()
3323
                        && $this->useDeletedToLockIfDynamic()
3324
                        && $this->isDynamic()) {
3325
                        $force = 0;
3326
                     }
3327
                     $delete_array = array('id' => $key);
3328
                     if ($input['action'] == 'purge_item_but_devices') {
3329
                        $delete_array['keep_devices'] = true;
3330
                     }
3331
                     if ($this->delete($delete_array, $force)) {
3332
                        $res['ok']++;
3333
                     } else {
3334
                        $res['ko']++;
3335
                        $res['messages'][] = $this->getErrorMessage(ERROR_ON_ACTION);
3336
                     }
3337
                  } else {
3338
                     $res['noright']++;
3339
                     $res['messages'][] = $this->getErrorMessage(ERROR_RIGHT);
3340
                  }
3341
               }
3342
            }
3343
            break;
3344

  
3345
         case 'unaffect' :
3346
            foreach ($input["item"] as $key => $val) {
3347
               if ($val == 1) {
3348
                  if ($this->can($key, UPDATE)) {
3349
                     if ($this instanceof CommonDBRelation) {
3350
                        if ($this->affectRelation($key, $input['peer'])) {
3351
                           $res['ok']++;
3352
                        } else {
3353
                           $res['ko']++;
3354
                           $res['messages'][] = $this->getErrorMessage(ERROR_ON_ACTION);
3355
                        }
3356
                     } elseif ($this instanceof CommonDBChild) {
3357
                        if ($this->affectChild($key)) {
3358
                           $res['ok']++;
3359
                        } else {
3360
                           $res['ko']++;
3361
                           $res['messages'][] = $this->getErrorMessage(ERROR_ON_ACTION);
3362
                        }
3363
                     }
3364
                  } else {
3365
                     $res['noright']++;
3366
                     $res['messages'][] = $this->getErrorMessage(ERROR_RIGHT);
3367
                  }
3368
               }
3369
            }
3370
            break;
3371

  
3372
         case "restore" :
3373
            foreach ($input["item"] as $key => $val) {
3374
               if ($val == 1) {
3375
                  if ($this->can($key, PURGE)) {
3376
                     if ($this->restore(array("id" => $key))) {
3377
                        $res['ok']++;
3378
                     } else {
3379
                        $res['ko']++;
3380
                        $res['messages'][] = $this->getErrorMessage(ERROR_ON_ACTION);
3381
                     }
3382
                  } else {
3383
                     $res['noright']++;
3384
                     $res['messages'][] = $this->getErrorMessage(ERROR_RIGHT);
3385
                  }
3386
               }
3387
            }
3388
            break;
3389

  
3390
         case "update" :
3391
            $searchopt = Search::getCleanedOptions($input["itemtype"],'w');
3392
            if (isset($searchopt[$input["id_field"]])) {
3393
               /// Infocoms case
3394
               if (!isPluginItemType($input["itemtype"])
3395
                  && Search::isInfocomOption($input["itemtype"], $input["id_field"])) {
3396

  
3397
                  $ic = new Infocom();
3398
                  $link_entity_type = -1;
3399
                  /// Specific entity item
3400
                  if ($searchopt[$input["id_field"]]["table"] == "glpi_suppliers") {
3401
                     $ent = new Supplier();
3402
                     if ($ent->getFromDB($input[$input["field"]])) {
3403
                        $link_entity_type = $ent->fields["entities_id"];
3404
                     }
3405
                  }
3406
                  foreach ($input["item"] as $key => $val) {
3407
                     if ($val == 1) {
3408
                        if ($this->getFromDB($key)) {
3409
                           if (($link_entity_type < 0)
3410
                              || ($link_entity_type == $this->getEntityID())
3411
                              || ($ent->fields["is_recursive"]
3412
                                 && in_array($link_entity_type, getAncestorsOf("glpi_entities",
3413
                                             $this->getEntityID())))) {
3414
                              $input2["items_id"] = $key;
3415
                              $input2["itemtype"] = $input["itemtype"];
3416

  
3417
                              if ($ic->can(-1,'w',$input2)) {
3418
                                 // Add infocom if not exists
3419
                                 if (!$ic->getFromDBforDevice($input["itemtype"],$key)) {
3420
                                    $input2["items_id"] = $key;
3421
                                    $input2["itemtype"] = $input["itemtype"];
3422
                                    unset($ic->fields);
3423
                                    $ic->add($input2);
3424
                                    $ic->getFromDBforDevice($input["itemtype"], $key);
3425
                                 }
3426
                                 $id = $ic->fields["id"];
3427
                                 unset($ic->fields);
3428
                                 if ($ic->update(array('id'   => $id,
3429
                                                      $input["field"]
3430
                                                            => $input[$input["field"]]))) {
3431
                                    $res['ok']++;
3432
                                 } else {
3433
                                    $res['ko']++;
3434
                                    $res['messages'][] = $this->getErrorMessage(ERROR_ON_ACTION);
3435
                                 }
3436
                              } else {
3437
                                 $res['noright']++;
3438
                                 $res['messages'][] = $this->getErrorMessage(ERROR_RIGHT);
3439
                              }
3440
                           } else {
3441
                              $res['ko']++;
3442
                              $res['messages'][] = $this->getErrorMessage(ERROR_COMPAT);
3443
                           }
3444
                        } else {
3445
                           $res['ko']++;
3446
                           $res['messages'][] = $this->getErrorMessage(ERROR_NOT_FOUND);
3447
                        }
3448
                     }
3449
                  }
3450

  
3451
               } else { /// Not infocoms
3452

  
3453
                  $link_entity_type = array();
3454
                  /// Specific entity item
3455
                  $itemtable = getTableForItemType($input["itemtype"]);
3456

  
3457
                  $itemtype2 = getItemTypeForTable($searchopt[$input["id_field"]]["table"]);
3458
                  if ($item2 = getItemForItemtype($itemtype2)) {
3459

  
3460
                     if (($input["id_field"] != 80) // No entities_id fields
3461
                        && ($searchopt[$input["id_field"]]["table"] != $itemtable)
3462
                        && $item2->isEntityAssign()
3463
                        && $this->isEntityAssign()) {
3464
                        if ($item2->getFromDB($input[$input["field"]])) {
3465
                           if (isset($item2->fields["entities_id"])
3466
                              && ($item2->fields["entities_id"] >= 0)) {
3467

  
3468
                              if (isset($item2->fields["is_recursive"])
3469
                                 && $item2->fields["is_recursive"]) {
3470
                                 $link_entity_type = getSonsOf("glpi_entities",
3471
                                                               $item2->fields["entities_id"]);
3472
                              } else {
3473
                                 $link_entity_type[] = $item2->fields["entities_id"];
3474
                              }
3475
                           }
3476
                        }
3477
                     }
3478
                  }
3479

  
3480
                  foreach ($input["item"] as $key => $val) {
3481
                     if ($val == 1) {
3482
                        if ($this->can($key,'w')
3483
                           && $this->canMassiveAction($input['action'], $input['field'],
3484
                                                      $input[$input["field"]])) {
3485
                           if ((count($link_entity_type) == 0)
3486
                              || in_array($this->fields["entities_id"], $link_entity_type)) {
3487
                              if ($this->update(array('id'   => $key,
3488
                                                      $input["field"]
3489
                                                            => $input[$input["field"]]))) {
3490
                                 $res['ok']++;
3491
                              } else {
3492
                                 $res['ko']++;
3493
                                 $res['messages'][] = $this->getErrorMessage(ERROR_ON_ACTION);
3494
                              }
3495
                           } else {
3496
                              $res['ko']++;
3497
                              $res['messages'][] = $this->getErrorMessage(ERROR_COMPAT);
3498
                           }
3499
                        } else {
3500
                           $res['noright']++;
3501
                           $res['messages'][] = $this->getErrorMessage(ERROR_RIGHT);
3502
                        }
3503
                     }
3504
                  }
3505
               }
3506
            }
3507
            break;
3508

  
3509
         case "activate_infocoms" :
3510
               $ic = new Infocom();
3511
               if ($ic->canCreate()) {
3512
                  foreach ($input["item"] as $key => $val) {
3513
                     $input = array('itemtype' => $input['itemtype'],
3514
                                    'items_id' => $key);
3515
                     if (!$ic->getFromDBforDevice($input['itemtype'], $key)) {
3516
                           if ($ic->can(-1,'w',$input)) {
3517
                              if ($ic->add($input)) {
3518
                                 $res['ok']++;
3519
                              } else {
3520
                                 $res['ko']++;
3521
                                 $res['messages'][] = $this->getErrorMessage(ERROR_ON_ACTION);
3522
                              }
3523
                           } else {
3524
                              $res['noright']++;
3525
                              $res['messages'][] = $this->getErrorMessage(ERROR_RIGHT);
3526
                           }
3527
                     } else {
3528
                        $res['ko']++;
3529
                        $res['messages'][] = $this->getErrorMessage(ERROR_NOT_FOUND);
3530
                     }
3531
                  }
3532
               }
3533
            break;
3534

  
3535
         //Lock management
3536
         case 'unlock_Printer' :
3537
         case 'unlock_Monitor' :
3538
         case 'unlock_NetworkPort' :
3539
         case 'unlock_NetworkName' :
3540
         case 'unlock_IPAddress' :
3541
         case 'unlock_ComputerDisk' :
3542
         case 'unlock_ComputerVirtualMachine' :
3543
         case 'unlock_Peripheral' :
3544
         case 'unlock_SoftwareVersion' :
3545
            $itemtype = Lock::getItemTypeForMassiveAction($input["action"]);
3546
            if ($itemtype) {
3547
               $res = Lock::unlockItems($itemtype, $this->getType(), $input["item"]);
3548
            }
3549
            break;
3550

  
3551
         case 'unlock_Device' :
3552
            foreach (Item_Devices::getDeviceTypes() as $itemtype) {
3553
               $res = Lock::unlockItems($itemtype, $this->getType(), $input["item"]);
3554
            }
3555
            break;
3556

  
3557
         default :
3558
            // Plugin specific actions
3559
            $split = explode('_',$input["action"]);
3560
            $res   = '';
3561
            if ($split[0] == 'plugin' && isset($split[1])) {
3562
               // Normalized name plugin_name_action
3563
               // Allow hook from any plugin on any (core or plugin) type
3564
               $res = Plugin::doOneHook($split[1], 'MassiveActionsProcess', $input);
3565

  
3566
//            } else if ($plug=isPluginItemType($input["itemtype"])) {
3567
               // non-normalized name
3568
               // hook from the plugin defining the type
3569
//               $res = Plugin::doOneHook($plug['plugin'], 'MassiveActionsProcess', $input);
3570
            } else {
3571
               $res = $this->doSpecificMassiveActions($input);
3572
            }
3573
            break;
3574
      }
3575
      return $res;
3576
   }
3577

  
3578

  
3579
   /**
3580 3024
    * Do the specific massive actions
3581 3025
    *
3582 3026
    * @since version 0.84
3027
    * @deprecated by CommonDBTM::processMassiveActions()
3583 3028
    *
3584 3029
    * This may be overloaded in Class
3585 3030
    * @param $input array of input datas
......
3592 3037

  
3593 3038

  
3594 3039
   /**
3595
    * Get the standard massive actions
3596
    *
3597
    * @since version 0.84
3598
    *
3599
    * This must not be overloaded in Class
3600
    * @param $is_deleted massive action for deleted items ?   (default 0)
3601
    * @param $checkitem link item to check right              (default NULL)
3602
    *
3603
    * @return an array of massive actions
3604
   **/
3605
   function getAllMassiveActions($is_deleted=0, $checkitem=NULL) {
3606
      global $CFG_GLPI, $PLUGIN_HOOKS;
3607

  
3608
      if (!is_null($checkitem)) {
3609
         $canupdate = $checkitem->canUpdate();
3610
         $candelete = $checkitem->canDelete();
3611
         $canpurge  = $checkitem->canPurge();
3612
      } else {
3613
         $canupdate = static::canUpdate();
3614
         $candelete = static::canDelete();
3615
         $canpurge  = static::canPurge();
3616
      }
3617

  
3618
      $itemtype = $this->getType();
3619
      $actions  = array();
3620

  
3621
      if ($is_deleted) {
3622
         if ($canpurge) {
3623
            if (in_array($this->getType(), Item_Devices::getConcernedItems())) {
3624
               $actions['purge_item_but_devices'] = _x('button',
3625
                                                       'Delete permanently but keep devices');
3626
               $actions['purge']                  = _x('button',
3627
                                                       'Delete permanently and remove devices');
3628
            } else {
3629
               $actions['purge']   = _x('button', 'Delete permanently');
3630
            }
3631
         }
3632

  
3633
         if ( $canpurge) {
3634
            $actions['restore'] = _x('button', 'Restore');
3635
         }
3636

  
3637
      } else {
3638
         if ($canupdate
3639
             || (in_array($itemtype, $CFG_GLPI["infocom_types"])
3640
                 && Infocom::canUpdate())) {
3641

  
3642
            //TRANS: select action 'update' (before doing it)
3643
            $actions['update'] = _x('button', 'Update');
3644
         }
3645

  
3646
         if (in_array($itemtype, $CFG_GLPI["infocom_types"])
3647
             && Infocom::canCreate()) {
3648
            $actions['activate_infocoms'] = __('Enable the financial and administrative information');
3649
         }
3650

  
3651
         if ($this instanceof CommonDBChild) {
3652
            if (!static::$mustBeAttached) {
3653
               $actions['unaffect'] = __('Dissociate');
3654
            }
3655
         }
3656
         if ($this instanceof CommonDBRelation) {
3657
            if ((!static::$mustBeAttached_1) || (!static::$mustBeAttached_2)) {
3658
               $actions['unaffect'] = __('Dissociate');
3659
            }
3660
         }
3661

  
3662
         // do not take into account is_deleted if items may be dynamic
3663
         if ($this->maybeDeleted()
3664
             && !$this->useDeletedToLockIfDynamic()) {
3665
            if ($candelete) {
3666
               $actions['delete'] = _x('button', 'Put in dustbin');
3667
            }
3668
         } else if ($canpurge){
3669
            $actions['purge'] = _x('button', 'Delete permanently');
3670
         }
3671

  
3672
         if (in_array($itemtype,$CFG_GLPI["document_types"])) {
3673
            if (Document::canView()) {
3674
               $actions['add_document']    = _x('button', 'Add a document');
3675
               $actions['remove_document'] = _x('button', 'Remove a document');
3676
            }
3677
         }
3678

  
3679
         if (in_array($itemtype,$CFG_GLPI["contract_types"])) {
3680
            if (Contract::canUpdate()) {
3681
               $actions['add_contract_item']    = _x('button', 'Add a contract');
3682
               $actions['remove_contract_item'] = _x('button', 'Remove a contract');
3683
            }
3684
         }
3685
         // Specific actions
3686
         $actions += $this->getSpecificMassiveActions($checkitem);
3687
         // Plugin Specific actions
3688
         if (isset($PLUGIN_HOOKS['use_massive_action'])) {
3689
            foreach ($PLUGIN_HOOKS['use_massive_action'] as $plugin => $val) {
3690
               $plug_actions = Plugin::doOneHook($plugin,'MassiveActions',$itemtype);
3691

  
3692
               if (count($plug_actions)) {
3693
                  $actions += $plug_actions;
3694
               }
3695
            }
3696
         }
3697
      }
3698
      //Add unlock if needed
3699
      $actions += Lock::getUnlockMassiveActions($itemtype);
3700

  
3701
      // Manage forbidden actions
3702
      $forbidden_actions = $this->getForbiddenStandardMassiveAction();
3703
      if (is_array($forbidden_actions) && count($forbidden_actions)) {
3704
         foreach ($forbidden_actions as $actiontodel) {
3705
            if (isset($actions[$actiontodel])) {
3706
               unset($actions[$actiontodel]);
3707
            }
3708
         }
3709
      }
3710
      return $actions;
3711
   }
3712

  
3713

  
3714
   /**
3715 3040
    * Get the standard massive actions which are forbidden
3716 3041
    *
3717 3042
    * @since version 0.84
inc/search.class.php (working copy)
926 926
            }
927 927
            $showmassiveactions = false;
928 928
            if ($itemtype != 'AllAssets') {
929
               $showmassiveactions = count($item->getAllMassiveActions($p['is_deleted']));
929
               $showmassiveactions = count(MassiveActions::getAllMassiveActions($item,
930
                                                                                $p['is_deleted']));
930 931
               if ($showmassiveactions
931 932
                   && ($output_type == self::HTML_OUTPUT)) {
932 933
                  Html::openMassiveActionsForm('massform'.$itemtype);
inc/networkname.class.php (working copy)
81 81

  
82 82

  
83 83
   /**
84
    * TODO : move it to common actions !
84 85
    * @see CommonDBTM::doSpecificMassiveActions()
85 86
   **/
86 87
   function doSpecificMassiveActions($input=array()) {
inc/plugin.class.php (working copy)
1025 1025
         }
1026 1026
      }
1027 1027

  
1028
      if (isset($attrib['massive_action_itemtype'])
1029
          && is_array($attrib['massive_action_itemtype'])) {
1030
         foreach ($attrib['massive_action_itemtype'] as $action) {
1031
            // Don't override core massive actions !
1032
            if (!isset($CFG_GLPI['massive_action_itemtype'][$action])) {
1033
               $CFG_GLPI['massive_action_itemtype'][$action] = $itemtype;
1034
            }
1035
         }
1036
      }
1037

  
1028 1038
      if (isset($attrib['addtabon'])) {
1029 1039
         if (!is_array($attrib['addtabon'])) {
1030 1040
            $attrib['addtabon'] = array($attrib['addtabon']);
inc/contract.class.php (working copy)
157 157
    *
158 158
    * @since version 0.85
159 159
    *
160
    * @see CommonDBTM::showMassiveActionsSubForm()
161
   **/
162
   static function showMassiveActionsSubForm(array $input) {
163
      global $CFG_GLPI;
164

  
165
      $itemtypes = array_keys($input['item']);
166
      if (count($itemtypes) == 1) {
167
         $select_for_contract = ($itemtypes[0] == 'Contract');
168
      } else {
169
         if (in_array('Contract', $itemtypes)) {
170
            if (isset($input['select_for_contract'])) {
171
               $select_for_contract = ($input['select_for_contract'] == 1);
172
            } else {
173
               _e("Attach an item to the selected contracts ?");
174
               $rand = Dropdown::showYesNo('select_for_contract');
175

  
176
               echo "<br><br>";
177

  
178
               $params                        = $input;
179
               $params['select_for_contract'] = '__VALUE__';
180
               Ajax::updateItemOnSelectEvent("dropdown_select_for_contract$rand",
181
                                             "show_select_for_contract$rand",
182
                                             $_SERVER['REQUEST_URI'], $params);
183

  
184
               echo "<span id='show_select_for_contract$rand'>&nbsp;</span>\n";
185
               exit();
186
            }
187
         } else {
188
            $select_for_contract = false;
189
         }
190
      }
191

  
192
      switch ($input['action']) {
193
         case "add_contract_item" :
194
            self::addHiddenItemsFromInput($input);
195
            if ($select_for_contract) {
196
               Dropdown::showSelectItemFromItemtypes(array('itemtype_name'
197
                                                                   => 'item_itemtype',
198
                                                           'itemtypes'
199
                                                                    => $CFG_GLPI["contract_types"],
200
                                                           'checkright'
201
                                                                    => true));
202
               echo "<br><br><input type='submit' name='massiveaction' class='submit' value='".
203
                              _sx('button', 'Add')."'>";
204
            } else {
205
               Contract::dropdown(array('name' => "contracts_id"));
206
               echo "<br><br><input type='submit' name='massiveaction' class='submit' value='".
207
                              _sx('button', 'Add')."'>";
208
            }
209

  
210
         case "remove_contract_item" :
211
            self::addHiddenItemsFromInput($input);
212
            if ($select_for_contract) {
213
               Dropdown::showSelectItemFromItemtypes(array('itemtype_name'
214
                                                                   => 'item_itemtype',
215
                                                           'itemtypes'
216
                                                                    => $CFG_GLPI["contract_types"],
217
                                                           'checkright'
218
                                                                    => true));
219
               echo "<br><br><input type='submit' name='massiveaction' class='submit' value='".
220
                              _sx('button', 'Delete permanently')."'>";
221
            } else {
222
               Contract::dropdown(array('name' => "contracts_id"));
223
               echo "<br><br><input type='submit' name='massiveaction' class='submit' value='".
224
                              _sx('button', 'Delete permanently')."'>";
225
            }
226
            break;
227
      }
228
   }
229

  
230

  
231
   /**
232
    *
233
    * @since version 0.85
234
    *
160 235
    * @see CommonDBTM::doSpecificMassiveActions()
161 236
   **/
162 237
   function doSpecificMassiveActions($input=array()) {
inc/lock.class.php (working copy)
361 361

  
362 362
      if ($item = getItemForItemtype($infos['type'])) {
363 363

  
364
         foreach ($items as $id => $value) {
365
            if ($value == 1) {
366
               $infos['condition'][$infos['field']] = $id;
367
               foreach ($DB->request($infos['table'], $infos['condition']) as $data) {
368
                  // Restore without history
369
                  if ($item->restore(array('id' => $data['id']))) {
370
                     $ok++;
371
                  } else {
372
                     $ko++;
373
                     $messages[] = $this->getErrorMessage(ERROR_ON_ACTION);
374
                  }
364
         foreach ($items as $id) {
365
            $infos['condition'][$infos['field']] = $id;
366
            foreach ($DB->request($infos['table'], $infos['condition']) as $data) {
367
               // Restore without history
368
               if ($item->restore(array('id' => $data['id']))) {
369
                  $ok++;
370
               } else {
371
                  $ko++;
372
                  $messages[] = $this->getErrorMessage(ERROR_ON_ACTION);
375 373
               }
376 374
            }
377 375
         }
......
392 390
   **/
393 391
   static function getUnlockMassiveActions($itemtype) {
394 392

  
393
      if ($itemtype::canUpdate() &&
394
          (in_array($itemtype, array('Computer', 'Printer', 'NetworkEquipment')))) {
395
         return array('unlock'   => __('Unlock an element attached'));
396
      }
397
      return array();
395 398
      if (Session::haveRight('computer', UPDATE)
396 399
          && ($itemtype == 'Computer')) {
397 400

  
......
429 432
   }
430 433

  
431 434

  
435
   static function showMassiveActionsSubForm(array $input) {
436
      switch ($input['action']) {
437
         case 'unlock':
438
            MassiveActions::addHiddenItemsFromInput($input);
439
            $types = array('Monitor'                => _n('Monitor', 'Monitors', 2),
440
                           'Peripheral'             => _n('Device', 'Devices', 2),
441
                           'Printer'                => _n('Printer', 'Printers', 2),
442
                           'SoftwareVersion'        => _n('Version', 'Versions', 2),
443
                           'NetworkPort'            => _n('Network port', 'Network ports', 2),
444
                           'NetworkName'            => _n('Network name', 'Network names', 2),
445
                           'IPAddress'              => _n('IP address', 'IP addresses', 2),
446
                           'ComputerDisk'           => _n('Volume', 'Volumes', 2),
447
                           'Device'                 => _n('Component', 'Components', 2),
448
                           'ComputerVirtualMachine' => _n('Virtual machine', 'Virtual machines', 2));
449

  
450
            _e('Select the type of the item that must be unlock');
451

  
452
            echo "<br><br>\n";
453

  
454
            Dropdown::showFromArray('attached_item', $types, array('multiple' => true,
455
                                                                   'size'     => 5));
456

  
457
            echo "<br><br>\n";
458

  
459
            echo "<input type='submit' name='massiveaction' class='submit' value='".
460
               __s('Post')."'>\n";
461

  
462
            break;
463
      }
464
   }
465

  
466

  
467
   static function processMassiveActions(array $input) {
468

  
469
      $res = array('ok'      => 0,
470
                   'ko'      => 0,
471
                   'noright' => 0);
472

  
473
      switch ($input['action']) {
474
         case 'unlock':
475
            if (($device_pos = array_search ('Device', $input['attached_item'])) !== false) {
476
               unset($input['attached_item'][$device_pos]);
477
               foreach (Item_Devices::getDeviceTypes() as $item_device) {
478
                  $input['attached_item'][] = $item_device;
479
               }
480
            }
481
            Toolbox::logDebug($input);
482
            foreach ($input['attached_item'] as $attached_item) {
483
               foreach ($input['item'] as $itemtype => $items_ids) {
484
                  $tmpres         = Lock::unlockItems($attached_item, $itemtype, $items_ids);
485
                  $res['ok']      += $tmpres['ok'];
486
                  $res['ko']      += $tmpres['ko'];
487
               }
488
            }
489
            break;
490
      }
491
   }
492

  
493

  
432 494
   /**
433 495
    * Get infos to build an SQL query to get locks fields in a table
434 496
    *
inc/html.class.php (working copy)
2405 2405
         }
2406 2406
      }
2407 2407

  
2408
      $p['extraparams']['itemtype'] = $itemtype;
2409 2408
      $url                          = $CFG_GLPI['root_doc']."/ajax/massiveaction.php";
2410
      if ($p['container']) {
2411
         $p['extraparams']['container'] = $p['container'];
2412
      }
2413 2409
      if ($p['is_deleted']) {
2414 2410
         $p['extraparams']['is_deleted'] = 1;
2415 2411
      }
......
2457 2453
             || (isset($p['forcecreate']) && $p['forcecreate'])) {
2458 2454
            echo "<div id='massiveactioncontent$identifier'></div>";
2459 2455

  
2456
            if (!empty($p['container'])) {
2457
               $js_modal_fields = "                  var items = $('[id=";
2458
               $js_modal_fields .= $p['container'];
2459
               $js_modal_fields .= "] [id*=massaction_item_]:checked')";
2460
               $js_modal_fields .= ".each(function( index ) {\n";
2461
               $js_modal_fields .= "                    fields[$(this).attr('name')] = 1;\n";
2462
               $js_modal_fields .= "        });";
2463
            } else {
2464
               $js_modal_fields = '';
2465
            }
2466

  
2460 2467
            Ajax::createModalWindow('massiveaction_window'.$identifier,
2461 2468
                                    $url,
2462
                                    array('title'       => $p['title'],
2463
                                          'container'   => 'massiveactioncontent'.$identifier,
2464
                                          'extraparams' => $p['extraparams'],
2465
                                          'width'       => $p['width'],
2466
                                          'height'      => $p['height'],));
2469
                                    array('title'                 => $p['title'],
2470
                                          'container'             => 'massiveactioncontent'.$identifier,
2471
                                          'extraparams'           => $p['extraparams'],
2472
                                          'width'                 => $p['width'],
2473
                                          'height'                => $p['height'],
2474
                                          'js_modal_fields' => $js_modal_fields));
2467 2475
         }
2468 2476
         echo "<table class='tab_glpi' width='$width'><tr>";
2469 2477
         if ($p['display_arrow']) {
inc/document.class.php (working copy)
690 690
                                   'itemtypes'       => $CFG_GLPI["document_types"],
691 691
                                   'checkright'      => true);
692 692
      switch ($input['action']) {
693
         case "add_document" :
694
            Document::dropdown(array('name' => 'documents_id'));
695
            echo "<br><br><input type='submit' name='massiveaction' class='submit' value='".
696
                           _sx('button', 'Add')."'>";
697
            break;
698

  
693 699
         case "add_document_item" :
694 700
            Dropdown::showSelectItemFromItemtypes($showAllItemsOptions);
695 701
            echo "<br><br><input type='submit' name='massiveaction' class='submit' value='".
696 702
                           _sx('button', 'Add')."'>";
697 703
            return true;
698 704

  
705
         case "remove_document" :
706
            Document::dropdown(array('name' => 'documents_id'));
707
            echo "<br><br><input type='submit' name='massiveaction' class='submit' value='".
708
                           _sx('button', 'Delete permanently')."'>";
709
            break;
710

  
699 711
         case "remove_document_item" :
700 712
            Dropdown::showSelectItemFromItemtypes($showAllItemsOptions);
701 713
            echo "<br><br><input type='submit' name='massiveaction' class='submit' value='".
702 714
                           _sx('button', 'Delete permanently')."'>";
703 715
            return true;
704 716

  
705
         default :
706
            return parent::showSpecificMassiveActionsParameters($input);
707 717
      }
708
      return false;
718
      return parent::showSpecificMassiveActionsParameters($input);
709 719
   }
710 720

  
711 721

  
inc/ajax.class.php (working copy)
65 65
                     'container'   => '',
66 66
                     'title'       => '',
67 67
                     'extraparams' => array(),
68
                     'display'     => true);
68
                     'display'     => true,
69
                     'js_modal_fields' => '');
69 70

  
70 71
      if (count($options)) {
71 72
         foreach ($options as $key => $val) {
......
74 75
            }
75 76
         }
76 77
      }
78

  
77 79
      $out  = "<script type='text/javascript'>\n";
78 80
      $out .= "var $name=";
79 81
      if (!empty($param['container'])) {
......
88 90
         modal: ".($param['modal']?'true':'false').",\n
89 91
         title: \"".addslashes($param['title'])."\",\n
90 92
         open: function (){\n
91
            $(this).load('$url'";
93
            fields = ";
92 94
      if (is_array($param['extraparams']) && count($param['extraparams'])) {
93
         $out .= ", ".json_encode($param['extraparams'],JSON_FORCE_OBJECT);
95
         $out .= json_encode($param['extraparams'],JSON_FORCE_OBJECT);
96
      } else {
97
         $out .= '{}';
94 98
      }
95
      $out .= ");\n}\n
99
      $out .= ";\n";
100
      if (!empty($param['js_modal_fields'])) {
101
         $out .= $param['js_modal_fields']."\n";
102
      }
103
      $out .= "            $(this).load('$url', fields);\n}\n
96 104
         });\n";
97 105
      $out .= "</script>";
98 106