itilsolution.class.php.patch

tsmr, 03/10/2021 11:51 AM

Download (4.34 KB)

View differences:

itilsolution.class.php (working copy)
195 195
         }
196 196
      }
197 197
   }
198

  
199

  
200
   /**
201
    * show warning message
202
    *
203
    * @param $params
204
    *
205
    * @return bool
206
    */
207
   static function checkWarnings($params) {
208
      global $DB;
209

  
210
      $ticket = $params['options']['item'];
211

  
212
      $config = PluginBehaviorsConfig::getInstance();
213

  
214
      // Check is the connected user is a tech
215
      if (!is_numeric(Session::getLoginUserID(false))
216
          || !Session::haveRight('ticket', UPDATE)) {
217
         return false; // No check
218
      }
219

  
220

  
221
      // Wand to solve/close the ticket
222
      $dur     = (isset($ticket->fields['actiontime'])
223
         ? $ticket->fields['actiontime']
224
         : 0);
225
      $cat    = (isset($ticket->fields['itilcategories_id'])
226
         ? $ticket->fields['itilcategories_id']
227
         : 0);
228
      $loc    = (isset($ticket->fields['locations_id'])
229
         ? $ticket->fields['locations_id']
230
         : 0);
231

  
232
      $warnings = [];
233
      // Wand to solve/close the ticket
234
      if ($config->getField('is_ticketrealtime_mandatory')) {
235
         if ($dur == 0) {
236
            $warnings[] = __("Duration is mandatory before ticket is solved/closed",
237
                             'behaviors');
238
         }
239
      }
240
      if ($config->getField('is_ticketcategory_mandatory')) {
241
         if ($cat == 0) {
242
            $warnings[] = __("Category is mandatory before ticket is solved/closed",
243
                             'behaviors');
244
         }
245
      }
246
      if ($config->getField('is_tickettech_mandatory')) {
247
         if (($ticket->countUsers(CommonITILActor::ASSIGN) == 0)
248
             && !isset($input["_itil_assign"]['users_id'])
249
             && !$config->getField('ticketsolved_updatetech')) {
250
            $warnings[] = __("Technician assigned is mandatory before ticket is solved/closed",
251
                             'behaviors');
252
         }
253
      }
254
      if ($config->getField('is_tickettechgroup_mandatory')) {
255
         if (($ticket->countGroups(CommonITILActor::ASSIGN) == 0)
256
             && !isset($input["_itil_assign"]['groups_id'])) {
257
            $warnings[] = __("Group of technicians assigned is mandatory before ticket is solved/closed",
258
                             'behaviors');
259
         }
260
      }
261
      if ($config->getField('is_ticketlocation_mandatory')) {
262
         if ($loc == 0) {
263
            $warnings[] = __("Location is mandatory before ticket is solved/closed",
264
                             'behaviors');
265
         }
266
      }
267
      $nb = 0;
268
      if ($config->getField('is_tickettasktodo')) {
269
         foreach ($DB->request('glpi_tickettasks',
270
                               ['tickets_id' => $ticket->getField('id')]) as $task) {
271
            if ($task['state'] == 1) {
272
               $nb++;
273
            }
274
         }
275
         if ($nb > 0) {
276
            $warnings[] = __("You cannot solve/close a ticket with task do to",
277
                             'behaviors');
278
         }
279
      }
280
      return $warnings;
281
   }
282

  
283

  
284
   /**
285
    * Displaying message solution
286
    *
287
    * @param $params
288
    *
289
    * @return bool
290
    */
291
   static function messageWarningSolution($params) {
292

  
293
      if (isset($params['item'])) {
294
         $item = $params['item'];
295
         if ($item->getType() == 'ITILSolution') {
296

  
297
            $warnings = self::checkWarnings($params);
298
            if (count($warnings)) {
299
               echo "<div class='warning' style='display: flow-root;'>";
300
               echo "<i class='fa fa-exclamation-triangle fa-5x'></i>";
301
               echo "<ul><li>" . implode('</li><li>', $warnings) . "</li></ul>";
302
               echo "<div class='sep'></div>";
303
               echo "</div>";
304
            }
305
         }
306

  
307
      }
308
   }
309

  
310
   /**
311
    * Displaying Add solution button or not
312
    *
313
    * @param $params
314
    *
315
    * @return bool
316
    */
317
   static function deleteAddSolutionButtton($params) {
318

  
319
      if (isset($params['item'])) {
320
         $item = $params['item'];
321
         if ($item->getType() == 'ITILSolution') {
322
            $warnings = self::checkWarnings($params);
323
            if (count($warnings)) {
324
               $params['options']['canedit'] = false;
325
               return $params;
326
            }
327
         }
328
      }
329
   }
198 330
}