widget.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. require_once(__DIR__.SLASH.'Glpi.class.php');
  3. global $conf,$myUser;
  4. $service = urldecode($widget->data('service'));
  5. $newHours = $widget->data('newHours');
  6. $newHours = empty($newHours) || !is_numeric($newHours) ? 24: $newHours;
  7. $login = $conf->get('glpi_login');
  8. $password = $conf->get('glpi_password');
  9. $glpi = new GLPI($conf->get('glpi_host'));
  10. $glpi->connect($login,$password);
  11. ?>
  12. <div class="widget-glpi">
  13. <?php if(empty($service)) : ?>
  14. <div class="text-center mt-5"><h2 class="text-muted"><i class="fa fas fa-headset"></i> Aucun service spécifié</h2><p>Veuillez configurer ce widget</p></div>
  15. <?php else:
  16. $url = parse_url($service);
  17. $tickets = array();
  18. if(isset($url['query'])){
  19. parse_str($url['query'], $parameters);
  20. $query = '';
  21. if(!empty($url['query'])){
  22. if(!isset($parameters['sort'])){
  23. $parameters['sort'] = 15;
  24. $parameters['order'] = 'DESC';
  25. }
  26. $query = http_build_query($parameters);
  27. }
  28. $glpi->searchOptions();
  29. $tickets = $glpi->searchTickets($query) ;
  30. }
  31. ?>
  32. <ul>
  33. <?php
  34. $newTreshold = strtotime('-'.$newHours.'hour');
  35. foreach($tickets as $ticket):
  36. $date = strtotime($ticket['date']);
  37. ?>
  38. <li class="glpi-ticket <?php echo ($date>$newTreshold)?'glpi-ticket-new':'' ?>">
  39. <i class="fas fa-fire-alt right text-warning glpi-new"></i>
  40. <a href="<?php echo $conf->get('glpi_host'); ?>/front/ticket.form.php?id=<?php echo $ticket['id']; ?>">
  41. <small class="text-muted"><i class="far fa-clock"></i> <?php echo complete_date($date).' '.date('H:i',$date); ?></small><br>
  42. <small class="glpi-firm"><i class="fas fa-user-tie"></i> <?php echo str_replace(array('- > ',' > '),' <i class="fas fa-angle-right text-black-50"></i> ',$ticket['firm']); ?></small><br>
  43. <p class="text-dark"><?php echo $ticket['subject']; ?></p>
  44. </a>
  45. </li>
  46. <?php endforeach; ?>
  47. </ul>
  48. <?php endif; ?>
  49. </div>