Exemple #1
0
 function showForm($target, $ID)
 {
     $this->getFromDB($ID);
     $delay_expired = $this->fields["delay_expired"];
     $delay_whichexpire = $this->fields["delay_whichexpire"];
     echo "<div align='center'>";
     echo "<form method='post' action=\"{$target}\">";
     echo "<table class='tab_cadre_fixe' cellpadding='5'><tr><th>";
     echo __('Time of checking of validity of domains', 'domains') . "</th></tr>";
     echo "<tr class='tab_bg_1'><td><div align='center'>";
     $delay_stamp_first = mktime(0, 0, 0, date("m"), date("d") - $delay_expired, date("y"));
     $delay_stamp_next = mktime(0, 0, 0, date("m"), date("d") + $delay_whichexpire, date("y"));
     $date_first = date("Y-m-d", $delay_stamp_first);
     $date_next = date("Y-m-d", $delay_stamp_next);
     echo "<tr class='tab_bg_1'><td><div align='left'>";
     _e('Domains expired since more', 'domains');
     echo "&nbsp;<input type='text' size='5' name='delay_expired' value=\"{$delay_expired}\">";
     echo "&nbsp;" . _n('Day', 'Days', 2);
     echo "&nbsp;( >" . Html::convdate($date_first) . ")<br>";
     _e('Domains expiring in less than', 'domains');
     echo "&nbsp;<input type='text' size='5' name='delay_whichexpire' value=\"{$delay_whichexpire}\">";
     echo "&nbsp;" . _n('Day', 'Days', 2);
     echo "&nbsp;( <" . Html::convdate($date_next) . ")";
     echo "</td>";
     echo "</tr>";
     echo "<tr><th>";
     echo "<input type='hidden' name='id' value='" . $ID . "'>";
     echo "<div align='center'>";
     echo "<input type='submit' name='update' value=\"" . __s('Post') . "\" class='submit' >";
     echo "</div></th></tr>";
     echo "</table>";
     Html::closeForm();
     echo "</div>";
 }
Exemple #2
0
 /**
  * init Graph : Show Titles / Date selector
  *
  * @params $options ($rand, short_classname, title, desc, delay)
  */
 function initGraph($options)
 {
     global $LANG, $CFG_GLPI;
     $width = $this->width + 100;
     $randname = $options['randname'];
     echo "<div class='center'><div id='fig' style='width:{$width}px'>";
     //Show global title
     if (isset($LANG['plugin_mreporting'][$options['short_classname']]['title'])) {
         echo "<div class='graph_title'>";
         echo $LANG['plugin_mreporting'][$options['short_classname']]['title'];
         echo "</div>";
     }
     //Show graph title
     echo "<div class='graph_title'>";
     $backtrace = debug_backtrace();
     $prev_function = strtolower(str_replace('show', '', $backtrace[1]['function']));
     echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/mreporting/pics/chart-{$prev_function}.png' class='title_pics' />";
     echo $options['title'];
     echo "</div>";
     $desc = '';
     if (!empty($options['desc'])) {
         $desc = $options['desc'];
     }
     if (!empty($options['desc']) && isset($_REQUEST['date1' . $randname]) && isset($_REQUEST['date1' . $randname])) {
         $desc .= " - ";
     }
     if (isset($_REQUEST['date1' . $randname]) && isset($_REQUEST['date1' . $randname])) {
         $desc .= Html::convdate($_REQUEST['date1' . $randname]) . " / " . Html::convdate($_REQUEST['date2' . $randname]);
     }
     echo "<div class='graph_desc'>" . $desc . "</div>";
     //Show date selector
     //using rand for display x graphs on same page
     if (!isset($_REQUEST['date1' . $randname])) {
         $_REQUEST['date1' . $randname] = strftime("%Y-%m-%d", time() - $options['delay'] * 24 * 60 * 60);
     }
     if (!isset($_REQUEST['date2' . $randname])) {
         $_REQUEST['date2' . $randname] = strftime("%Y-%m-%d");
     }
     echo "<div class='graph_navigation'>";
     PluginMreportingMisc::showSelector($_REQUEST['date1' . $randname], $_REQUEST['date2' . $randname], $randname);
     echo "</div>";
     $ex_func = explode($options['short_classname'], $options['randname']);
     if (!is_numeric($ex_func[0])) {
         $classname = $ex_func[0] . $options['short_classname'];
         $functionname = $ex_func[1];
         // We check if a configuration is needed for the graph
         if (method_exists(new $classname(), 'needConfig')) {
             $configs = PluginMreportingConfig::initConfigParams($functionname, $classname);
             $object = new $classname();
             $object->needConfig($configs);
         }
     }
     //Script for graph display
     if ($randname !== false) {
         echo "<div class='graph' id='graph_content{$randname}'>";
         $colors = "'" . implode("', '", PluginMreportingConfig::getColors()) . "'";
         echo "<script type='text/javascript+protovis'>\n            function showGraph{$randname}() {\n               colors = pv.colors({$colors});";
     }
 }
Exemple #3
0
 function showForm($target, $ID)
 {
     if (!$this->getFromDB($ID)) {
         $this->getEmpty();
     }
     $delay_expired = $this->fields["delay_expired"];
     $delay_whichexpire = $this->fields["delay_whichexpire"];
     $date_expired = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - $delay_expired, date("y")));
     $date_whichexpire = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") + $delay_whichexpire, date("y")));
     echo "<div align='center'>";
     echo "<form method='post' action=\"{$target}\">";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr class='tab_bg_1'>";
     echo "<th colspan='4'>";
     _e('Time of checking of validity of the badges', 'badges');
     echo "</th>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>";
     _e('Badges expired for more than ', 'badges');
     echo "</td>";
     echo "<td>";
     echo "&nbsp;<input type='text' size='15' name='delay_expired' value=\"{$delay_expired}\">";
     echo "&nbsp;" . _n('Day', 'Days', 2) . " ( > " . Html::convdate($date_expired) . ")<br>";
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>";
     _e('Badges expiring in less than ', 'badges');
     echo "</td>";
     echo "<td>";
     echo "&nbsp;<input type='text' size='15' name='delay_whichexpire' value=\"{$delay_whichexpire}\">";
     echo "&nbsp;" . _n('Day', 'Days', 2) . " ( < " . Html::convdate($date_whichexpire) . ")<br>";
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td class='center' colspan='4'>";
     echo "<input type='hidden' name='id' value='" . $ID . "'>";
     echo "<input type='submit' name='update' value=\"" . _sx('button', 'Save') . "\" class='submit' >";
     echo "</td>";
     echo "</tr>";
     echo "</table>";
     Html::closeForm();
     echo "</div>";
 }
   /**
    * Show certificates associated to an item
    *
    * @since version 0.84
    *
    * @param $item            CommonDBTM object for which associated certificates must be displayed
    * @param $withtemplate    (default '')
   **/
   static function showForItem(CommonDBTM $item, $withtemplate='') {
      global $DB, $CFG_GLPI;

      $ID = $item->getField('id');

      if ($item->isNewID($ID)) {
         return false;
      }
      if (!Session::haveRight("plugin_certificates", READ)) {
         return false;
      }

      if (!$item->can($item->fields['id'], READ)) {
         return false;
      }

      if (empty($withtemplate)) {
         $withtemplate = 0;
      }

      $canedit       =  $item->canadditem('PluginCertificatesCertificate');
      $rand          = mt_rand();
      $is_recursive  = $item->isRecursive();

      $query = "SELECT `glpi_plugin_certificates_certificates_items`.`id` AS assocID,
                       `glpi_entities`.`id` AS entity,
                       `glpi_plugin_certificates_certificates`.`name` AS assocName,
                       `glpi_plugin_certificates_certificates`.*
                FROM `glpi_plugin_certificates_certificates_items`
                LEFT JOIN `glpi_plugin_certificates_certificates`
                 ON (`glpi_plugin_certificates_certificates_items`.`plugin_certificates_certificates_id`=`glpi_plugin_certificates_certificates`.`id`)
                LEFT JOIN `glpi_entities` ON (`glpi_plugin_certificates_certificates`.`entities_id`=`glpi_entities`.`id`)
                WHERE `glpi_plugin_certificates_certificates_items`.`items_id` = '$ID'
                      AND `glpi_plugin_certificates_certificates_items`.`itemtype` = '".$item->getType()."' ";

      $query .= getEntitiesRestrictRequest(" AND","glpi_plugin_certificates_certificates",'','',true);

      $query .= " ORDER BY `assocName`";

      $result = $DB->query($query);
      $number = $DB->numrows($result);
      $i      = 0;

      $certificates      = array();
      $certificate       = new PluginCertificatesCertificate();
      $used      = array();
      if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
            $certificates[$data['assocID']] = $data;
            $used[$data['id']] = $data['id'];
         }
      }

      if ($canedit && $withtemplate < 2) {
         // Restrict entity for knowbase
         $entities = "";
         $entity   = $_SESSION["glpiactive_entity"];

         if ($item->isEntityAssign()) {
            /// Case of personal items : entity = -1 : create on active entity (Reminder case))
            if ($item->getEntityID() >=0 ) {
               $entity = $item->getEntityID();
            }

            if ($item->isRecursive()) {
               $entities = getSonsOf('glpi_entities',$entity);
            } else {
               $entities = $entity;
            }
         }
         $limit = getEntitiesRestrictRequest(" AND ","glpi_plugin_certificates_certificates",'',$entities,true);
         $q = "SELECT COUNT(*)
               FROM `glpi_plugin_certificates_certificates`
               WHERE `is_deleted` = '0'
               $limit";

         $result = $DB->query($q);
         $nb     = $DB->result($result,0,0);

         echo "<div class='firstbloc'>";       
         
         
         if (Session::haveRight("plugin_certificates", READ)
             && ($nb > count($used))) {
            echo "<form name='certificate_form$rand' id='certificate_form$rand' method='post'
                   action='".Toolbox::getItemTypeFormURL('PluginCertificatesCertificate')."'>";
            echo "<table class='tab_cadre_fixe'>";
            echo "<tr class='tab_bg_1'>";
            echo "<td colspan='4' class='center'>";
            echo "<input type='hidden' name='entities_id' value='$entity'>";
            echo "<input type='hidden' name='is_recursive' value='$is_recursive'>";
            echo "<input type='hidden' name='itemtype' value='".$item->getType()."'>";
            echo "<input type='hidden' name='items_id' value='$ID'>";
            if ($item->getType() == 'Ticket') {
               echo "<input type='hidden' name='tickets_id' value='$ID'>";
            }

            PluginCertificatesCertificate::dropdown(array('entity' => $entities ,
                                                            'used'   => $used));
                                     
            echo "</td><td class='center' width='20%'>";
            echo "<input type='submit' name='additem' value=\"".
                     _sx('button', 'Associate a certificate', 'certificates')."\" class='submit'>";
            echo "</td>";
            echo "</tr>";
            echo "</table>";
            Html::closeForm();
         }

         echo "</div>";
      }

      echo "<div class='spaced'>";
      if ($canedit && $number && ($withtemplate < 2)) {
         Html::openMassiveActionsForm('mass'.__CLASS__.$rand);
         $massiveactionparams = array('num_displayed'  => $number);
         Html::showMassiveActions($massiveactionparams);
      }
      echo "<table class='tab_cadre_fixe'>";

      echo "<tr>";
      if ($canedit && $number && ($withtemplate < 2)) {
         echo "<th width='10'>".Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand)."</th>";
      }
      echo "<th>".__('Name')."</th>";
      if (Session::isMultiEntitiesMode()) {
         echo "<th>".__('Entity')."</th>";
      }
      echo "<th>".__('Type')."</th>";
      echo "<th>".__('DNS name', 'certificates')."</th>";
      echo "<th>".__('DNS suffix', 'certificates')."</th>";
      echo "<th>".__('Creation date')."</th>";
      echo "<th>".__('Expiration date')."</th>";
      echo "<th>".__('Status')."</th>";
      echo "</tr>";
      $used = array();

      if ($number) {

         Session::initNavigateListItems('PluginCertificatesCertificate',
                           //TRANS : %1$s is the itemtype name,
                           //        %2$s is the name of the item (used for headings of a list)
                                        sprintf(__('%1$s = %2$s'),
                                                $item->getTypeName(1), $item->getName()));

         
         foreach  ($certificates as $data) {
            $certificateID        = $data["id"];
            $link         = NOT_AVAILABLE;

            if ($certificate->getFromDB($certificateID)) {
               $link         = $certificate->getLink();
            }

            Session::addToNavigateListItems('PluginCertificatesCertificate', $certificateID);
            
            $used[$certificateID] = $certificateID;
            $assocID      = $data["assocID"];

            echo "<tr class='tab_bg_1".($data["is_deleted"]?"_2":"")."'>";
            if ($canedit && ($withtemplate < 2)) {
               echo "<td width='10'>";
               Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]);
               echo "</td>";
            }
            echo "<td class='center'>$link</td>";
            if (Session::isMultiEntitiesMode()) {
               echo "<td class='center'>".Dropdown::getDropdownName("glpi_entities", $data['entities_id']).
                    "</td>";
            }
            echo "<td class='center'>";
            echo Dropdown::getDropdownName("glpi_plugin_certificates_certificatetypes",
                                          $data["plugin_certificates_certificatetypes_id"]);
            echo "</td>";
            echo "<td class='center'>".$data["dns_name"]."</td>";
            echo "<td class='center'>".$data["dns_suffix"]."</td>";
            echo "<td class='center'>".Html::convdate($data["date_query"])."</td>";
            if ($data["date_expiration"] <= date('Y-m-d') 
                  && !empty($data["date_expiration"])) {
               echo "<td class='center'>";
               echo "<div class='deleted'>".Html::convdate($data["date_expiration"])."</div>";
               echo "</td>";
            } else if (empty($data["date_expiration"])) {
               echo "<td class='center'>".__('Does not expire', 'certificates')."</td>";
            } else {
               echo "<td class='center'>".Html::convdate($data["date_expiration"])."</td>";
            }
            echo "<td class='center'>";
            echo Dropdown::getDropdownName("glpi_plugin_certificates_certificatestates",
                                                $data["plugin_certificates_certificatestates_id"]);
            echo "</td>";
            echo "</tr>";
            $i++;
         }
      }


      echo "</table>";
      if ($canedit && $number && ($withtemplate < 2)) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
      }
      echo "</div>";
   }
Exemple #5
0
 function generatePdf($itemtype, $data, $saveas)
 {
     global $CFG_GLPI, $PDF, $DB;
     $ID = $data["id"];
     //name
     if (!empty($data["name"])) {
         $name_item = Toolbox::decodeFromUtf8($data["name"]);
     } else {
         $name_item = "";
     }
     //user
     if (!empty($data["users_id"])) {
         $user_item = Toolbox::decodeFromUtf8(Html::clean(getUserName($data["users_id"])));
     } else {
         if (!empty($data["groups_id"])) {
             $user_item = Toolbox::decodeFromUtf8(Dropdown::getDropdownName("glpi_groups", $data["groups_id"]));
         } else {
             $user_item = "";
         }
     }
     //fabricant
     if (!empty($data["manufacturers_id"])) {
         $fabricant_item = Toolbox::decodeFromUtf8(Dropdown::getDropdownName("glpi_manufacturers", $data["manufacturers_id"]));
     } else {
         $fabricant_item = "";
     }
     //serial
     if (!empty($data["serial"])) {
         $serial_item = Toolbox::decodeFromUtf8($data["serial"]);
     } else {
         $serial_item = "";
     }
     $class = $itemtype . "Type";
     $item = new $class();
     $typefield = getForeignKeyFieldForTable(getTableForItemType($itemtype . "Type"));
     $item->getFromDB($data[$typefield]);
     if (!empty($typefield) && !empty($item->fields["name"])) {
         $type_item = Toolbox::decodeFromUtf8($item->fields["name"]);
     } else {
         $type_item = "";
     }
     //infocoms
     $ic = new Infocom();
     if ($ic->getfromDBforDevice($itemtype, $ID)) {
         //immobilizationsheets_item
         if (!empty($ic->fields["immo_number"])) {
             $immobilizationsheets_item = Toolbox::decodeFromUtf8($ic->fields["immo_number"]);
         } else {
             $immobilizationsheets_item = "";
         }
         //buy_date
         if (!empty($ic->fields["buy_date"])) {
             $buy_date_item = Toolbox::decodeFromUtf8(Html::convdate($ic->fields["buy_date"]));
         } else {
             $buy_date_item = "";
         }
         //use_date
         if (!empty($ic->fields["use_date"])) {
             $use_date_item = Toolbox::decodeFromUtf8(Html::convdate($ic->fields["use_date"]));
         } else {
             $use_date_item = "";
         }
         //order_number
         if (!empty($ic->fields["order_number"])) {
             $order_number_item = Toolbox::decodeFromUtf8($ic->fields["order_number"]);
         } else {
             $order_number_item = "";
         }
         //value_item
         if (!empty($ic->fields["value"])) {
             $value_item = Toolbox::decodeFromUtf8(Html::clean(Html::formatNumber($ic->fields["value"])));
         } else {
             $value_item = "";
         }
         //sink_time
         if (!empty($ic->fields["sink_time"])) {
             $sink_time_item = Toolbox::decodeFromUtf8(sprintf(_n('%d year', '%d years', $ic->fields["sink_time"]), $ic->fields["sink_time"]));
         } else {
             $sink_time_item = "";
         }
         //sink_type
         if (!empty($ic->fields["sink_type"])) {
             $sink_type_item = Toolbox::decodeFromUtf8(Infocom::getAmortTypeName($ic->fields["sink_type"]));
         } else {
             $sink_type_item = "";
         }
     } else {
         $immobilizationsheets_item = "";
         $buy_date_item = "";
         $use_date_item = "";
         $order_number_item = "";
         $value_item = "";
         $sink_time_item = "";
         $sink_type_item = "";
     }
     //composants
     $devtypes = self::getDeviceTypes();
     if ($itemtype == 'Computer') {
         $device2 = new $devtypes[2]();
         $query2 = "SELECT `deviceprocessors_id`\n                  FROM `" . getTableForItemType('items_' . $devtypes[2]) . "`\n                  WHERE `items_id` = '{$ID}'";
         $result2 = $DB->query($query2);
         $number2 = $DB->numrows($result2);
         $device3 = new $devtypes[3]();
         $query3 = "SELECT SUM(`size`) AS total\n                  FROM `" . getTableForItemType('items_' . $devtypes[3]) . "`\n                  WHERE `items_id` = '{$ID}'";
         $result3 = $DB->query($query3);
         $number3 = $DB->numrows($result3);
         $query3b = "SELECT `devicememories_id`\n                  FROM `" . getTableForItemType('items_' . $devtypes[3]) . "`\n                  WHERE `items_id` = '{$ID}'";
         $result3b = $DB->query($query3b);
         $number3b = $DB->numrows($result3b);
         $device4 = new $devtypes[4]();
         $query4 = "SELECT `deviceharddrives_id`,`capacity`\n                  FROM `" . getTableForItemType('items_' . $devtypes[4]) . "`\n                  WHERE `items_id` = '{$ID}'";
         $result4 = $DB->query($query4);
         $number4 = $DB->numrows($result4);
         $device5 = new $devtypes[6]();
         $query5 = "SELECT `devicedrives_id`\n                  FROM `" . getTableForItemType('items_' . $devtypes[6]) . "`\n                  WHERE `items_id` = '{$ID}'";
         $result5 = $DB->query($query5);
         $number5 = $DB->numrows($result5);
         if ($number2 != 0) {
             while ($data2 = $DB->fetch_array($result2)) {
                 //proc_item
                 if (!empty($data2["deviceprocessors_id"])) {
                     $query_proc = "SELECT `designation`\n                              FROM `glpi_deviceprocessors`\n                              WHERE `id` = '" . $data2["deviceprocessors_id"] . "'";
                     $result_proc = $DB->query($query_proc);
                     $number_proc = $DB->numrows($result_proc);
                     if ($number_proc != 0) {
                         while ($data_proc = $DB->fetch_array($result_proc)) {
                             $proc_item = Toolbox::decodeFromUtf8($data_proc["designation"]);
                         }
                     }
                 }
             }
         } else {
             $proc_item = "";
         }
         if ($number3 != 0) {
             while ($data3 = $DB->fetch_array($result3)) {
                 //ram_item
                 $ram_item = $data3["total"];
             }
         } else {
             $ram_item = "";
         }
         $ram_type_item = "";
         if ($number3b != 0) {
             while ($data3b = $DB->fetch_array($result3b)) {
                 //ram_type_item
                 if (!empty($data3b["devicememories_id"])) {
                     $query_ram = "SELECT `glpi_devicememorytypes`.`name`\n                              FROM `glpi_devicememories`,`glpi_devicememorytypes`\n                              WHERE `glpi_devicememories`.`id` = '" . $data3b["devicememories_id"] . "'\n                              AND `glpi_devicememorytypes`.`id` = `glpi_devicememories`.`devicememorytypes_id` ";
                     $result_ram = $DB->query($query_ram);
                     $number_ram = $DB->numrows($result_ram);
                     if ($number_ram != 0) {
                         while ($data_ram = $DB->fetch_array($result_ram)) {
                             $ram_type_item = Toolbox::decodeFromUtf8($data_ram["name"]);
                         }
                     } else {
                         $ram_type_item = "";
                     }
                 }
             }
         } else {
             $ram_type_item = "";
         }
         $hdd_item = "";
         $hdd_designation_item = "";
         $hdd_interface_item = "";
         if ($number4 != 0) {
             while ($data4 = $DB->fetch_array($result4)) {
                 //hdd_item
                 $hdd_size_item = Toolbox::decodeFromUtf8($data4["capacity"]);
                 if (!empty($data4["deviceharddrives_id"])) {
                     $query_hdd = "SELECT `designation`\n                              FROM `glpi_deviceharddrives`\n                              WHERE `id` = '" . $data4["deviceharddrives_id"] . "'";
                     $result_hdd = $DB->query($query_hdd);
                     $number_hdd = $DB->numrows($result_hdd);
                     if ($number_hdd != 0) {
                         while ($data_hdd = $DB->fetch_array($result_hdd)) {
                             $hdd_designation_item = Toolbox::decodeFromUtf8($data_hdd["designation"]);
                         }
                     } else {
                         $hdd_designation_item = "";
                     }
                     $query_hdd1 = "SELECT `glpi_interfacetypes`.`name`\n                              FROM `glpi_deviceharddrives`,`glpi_interfacetypes`\n                              WHERE `glpi_deviceharddrives`.`id` = '" . $data4["deviceharddrives_id"] . "'\n                              AND `glpi_interfacetypes`.`id` = `glpi_deviceharddrives`.`interfacetypes_id` ";
                     //replace interface by FK_interface 0.72.1
                     $result_hdd1 = $DB->query($query_hdd1);
                     $number_hdd1 = $DB->numrows($result_hdd1);
                     if ($number_hdd1 != 0) {
                         while ($data_hdd1 = $DB->fetch_array($result_hdd1)) {
                             $hdd_interface_item = Toolbox::decodeFromUtf8($data_hdd1["name"]);
                         }
                     }
                 } else {
                     $hdd_interface_item = "";
                 }
                 $hdd_item .= $hdd_designation_item . " " . $hdd_interface_item . " (" . $hdd_size_item . " Mo)";
                 if ($number4 > 1) {
                     $hdd_item .= " - ";
                 }
             }
         } else {
             $hdd_item = "";
         }
         $lecteur_item = "";
         if ($number5 != 0) {
             while ($data5 = $DB->fetch_array($result5)) {
                 //lecteur_item
                 if (!empty($data5["items_id"])) {
                     $query_lecteur = "SELECT `designation`\n                                 FROM `glpi_devicedrives`\n                                 WHERE `id` = '" . $data5["interfacetypes_id"] . "'";
                     $result_lecteur = $DB->query($query_lecteur);
                     $number_lecteur = $DB->numrows($result_lecteur);
                     if ($number_lecteur != 0) {
                         while ($data_lecteur = $DB->fetch_array($result_lecteur)) {
                             $lecteur_item .= Toolbox::decodeFromUtf8($data_lecteur["designation"]);
                             if ($number5 > 1) {
                                 $lecteur_item .= " - ";
                             }
                         }
                     }
                 }
             }
         } else {
             $lecteur_item = "";
         }
         //softwares
         $query6 = "SELECT `glpi_softwares`.`name`,`glpi_softwarelicenses`.`softwareversions_id_buy`,`glpi_softwarelicenses`.`serial`\n                  FROM `glpi_softwarelicenses`\n                  INNER JOIN `glpi_computers_softwarelicenses` ON (`glpi_softwarelicenses`.`id` = `glpi_computers_softwarelicenses`.`softwarelicenses_id` AND `glpi_computers_softwarelicenses`.`computers_id` = '{$ID}') \n                  INNER JOIN `glpi_softwares` ON (`glpi_softwarelicenses`.`softwares_id` = `glpi_softwares`.`id`) ";
         $result6 = $DB->query($query6);
         $number6 = $DB->numrows($result6);
     }
     //Affichage
     //$PDF->addJpegFromFile('../pics/immobilizationsheets.jpg',285,785,32,32);
     //title
     $PDF->ezSetDy(-20);
     $title = array(array('' => Toolbox::decodeFromUtf8(__('IDENTIFICATION IMMOBILIZATION SHEET', 'immobilizationsheets'))));
     $cols = array('' => array('width' => 530, 'justification' => 'center'));
     $PDF->ezTable($title, '', '', array('cols' => $cols, 'showHeadings' => 0, 'fontSize' => 12, 'showLines' => 0, 'shaded' => 2, 'shadeCol' => array(0.8, 0.8, 0.8), 'shadeCol2' => array(0.8, 0.8, 0.8)));
     $PDF->ezSetDy(-10);
     //partie 1
     $PDF->ezSetDy(-20);
     $title1 = array(array('' => Toolbox::decodeFromUtf8(__('I - PART TO BE FILLED BY THE PERSON IN CHARGE FOR THE PURCHASES', 'immobilizationsheets'))));
     $cols = array('' => array('width' => 530, 'justification' => 'left'));
     $PDF->ezTable($title1, '', '', array('cols' => $cols, 'showHeadings' => 0, 'fontSize' => 10, 'showLines' => 0, 'shaded' => 2, 'shadeCol' => array(0.8, 0.8, 0.8), 'shadeCol2' => array(0.8, 0.8, 0.8)));
     $title2 = array(array('' => Toolbox::decodeFromUtf8(__('(transfer the original to the administrator network so computer equipement, the assistant of management in the other cases)', 'immobilizationsheets'))));
     $cols = array('' => array('width' => 530, 'justification' => 'left'));
     $PDF->ezTable($title2, '', '', array('cols' => $cols, 'showHeadings' => 0, 'fontSize' => 8, 'showLines' => 0, 'shaded' => 2, 'shadeCol' => array(0.8, 0.8, 0.8), 'shadeCol2' => array(0.8, 0.8, 0.8)));
     $PDF->ezSetDy(-10);
     //Date mise en service
     $PDF->ezText("<u>" . Toolbox::decodeFromUtf8(__('Startup date')) . "</u> : " . $buy_date_item, 8, array("justification" => "left"));
     $PDF->ezSetDy(-10);
     //ligne1 (entreprise / fournisseur)
     $data1 = array(array('0' => Toolbox::decodeFromUtf8(__('MY ENTERPRISE', 'immobilizationsheets')), '1' => Toolbox::decodeFromUtf8(strtoupper(__('Supplier')))));
     $cols1 = array('0' => array('width' => 265, 'justification' => 'center'), '1' => array('width' => 265, 'justification' => 'center'));
     $PDF->ezTable($data1, '', __('COMPUTER IDENTIFICATION', 'immobilizationsheets'), array('showHeadings' => 0, 'cols' => $cols1));
     //ligne2 (4 / 9)
     $data2 = array(array('0' => Toolbox::decodeFromUtf8(__('Assignment number (si non informatique)', 'immobilizationsheets')), '1' => '', '2' => Toolbox::decodeFromUtf8(__('Brand')), '3' => $fabricant_item));
     $cols2 = array('0' => array('width' => 132.5, 'fontSize' => 8, 'justification' => 'left'), '1' => array('width' => 132.5, 'justification' => 'left'), '2' => array('width' => 132.5, 'justification' => 'left'), '3' => array('width' => 132.5, 'justification' => 'left'));
     $PDF->ezTable($data2, '', '', array('showHeadings' => 0, 'cols' => $cols2, 'fontSize' => 8));
     //ligne3 (5 / 10)
     $data3 = array(array('0' => Toolbox::decodeFromUtf8(__('Invoice number')), '1' => $order_number_item, '2' => Toolbox::decodeFromUtf8(__('Type')), '3' => $type_item));
     $cols3 = array('0' => array('width' => 132.5, 'fontSize' => 8, 'justification' => 'left'), '1' => array('width' => 132.5, 'justification' => 'left'), '2' => array('width' => 132.5, 'justification' => 'left'), '3' => array('width' => 132.5, 'justification' => 'left'));
     $PDF->ezTable($data3, '', '', array('showHeadings' => 0, 'cols' => $cols3, 'fontSize' => 8));
     //ligne4 (6 / 11)
     $data4 = array(array('0' => Toolbox::decodeFromUtf8(__('Value')), '1' => $value_item, '2' => Toolbox::decodeFromUtf8(__('Serial Number')), '3' => $serial_item));
     $cols4 = array('0' => array('width' => 132.5, 'fontSize' => 8, 'justification' => 'left'), '1' => array('width' => 132.5, 'justification' => 'left'), '2' => array('width' => 132.5, 'justification' => 'left'), '3' => array('width' => 132.5, 'justification' => 'left'));
     $PDF->ezTable($data4, '', '', array('showHeadings' => 0, 'cols' => $cols4, 'fontSize' => 8));
     //ligne5 (7 / 12)
     $data5 = array(array('0' => Toolbox::decodeFromUtf8(__('Assignment (client / inv. …)', 'immobilizationsheets')), '1' => '', '2' => Toolbox::decodeFromUtf8(__('Permanent number', 'immobilizationsheets')), '3' => $immobilizationsheets_item));
     $cols5 = array('0' => array('width' => 132.5, 'fontSize' => 8, 'justification' => 'left'), '1' => array('width' => 132.5, 'justification' => 'left'), '2' => array('width' => 132.5, 'justification' => 'left'), '3' => array('width' => 132.5, 'justification' => 'left'));
     $PDF->ezTable($data5, '', '', array('showHeadings' => 0, 'cols' => $cols5, 'fontSize' => 8));
     $PDF->ezSetDy(-10);
     //trigramme
     $data6 = array(array('0' => Toolbox::decodeFromUtf8(__('Trigram and visa of the person in charge', 'immobilizationsheets')), '1' => ''));
     $cols6 = array('0' => array('width' => 430, 'fontSize' => 8, 'justification' => 'right'), '1' => array('width' => 100, 'justification' => 'left'));
     $PDF->ezTable($data6, '', '', array('showHeadings' => 0, 'cols' => $cols6, 'xPos' => 'center', 'xOreintation' => 'right', 'fontSize' => 8));
     //partie 2
     $PDF->ezSetDy(-20);
     $title1 = array(array('' => Toolbox::decodeFromUtf8(__('II - PART TO BE FILLED BY THE NETWORK ADMINISTRATOR', 'immobilizationsheets'))));
     $cols = array('' => array('width' => 530, 'justification' => 'left'));
     $PDF->ezTable($title1, '', '', array('cols' => $cols, 'showHeadings' => 0, 'fontSize' => 10, 'showLines' => 0, 'shaded' => 2, 'shadeCol' => array(0.8, 0.8, 0.8), 'shadeCol2' => array(0.8, 0.8, 0.8)));
     $title2 = array(array('' => Toolbox::decodeFromUtf8(__('(transfer to the assistant of management)', 'immobilizationsheets'))));
     $cols = array('' => array('width' => 530, 'justification' => 'left'));
     $PDF->ezTable($title2, '', '', array('cols' => $cols, 'showHeadings' => 0, 'fontSize' => 8, 'showLines' => 0, 'shaded' => 2, 'shadeCol' => array(0.8, 0.8, 0.8), 'shadeCol2' => array(0.8, 0.8, 0.8)));
     $PDF->ezSetDy(-10);
     //ligne1 (name  / user)
     $data1 = array(array('0' => Toolbox::decodeFromUtf8(__('User name / sector', 'immobilizationsheets')), '1' => $user_item, '2' => Toolbox::decodeFromUtf8(__('Name')), '3' => $name_item));
     $cols1 = array('0' => array('width' => 132.5, 'justification' => 'center'), '1' => array('width' => 132.5, 'justification' => 'center'), '2' => array('width' => 132.5, 'justification' => 'center'), '3' => array('width' => 132.5, 'justification' => 'center'));
     $PDF->ezTable($data1, '', __('PRINCIPAL ASSIGNMENT', 'immobilizationsheets'), array('fontSize' => 8, 'showHeadings' => 0, 'cols' => $cols1));
     $PDF->ezSetDy(-10);
     if ($itemtype == 'Computer') {
         //title config mat?ielle
         $title = array(array('' => Toolbox::decodeFromUtf8(__('HARDWARE CONFIGURATION', 'immobilizationsheets'))));
         $cols = array('' => array('width' => 530, 'justification' => 'center'));
         $PDF->ezTable($title, '', '', array('cols' => $cols, 'showHeadings' => 0, 'fontSize' => 12, 'showLines' => 1));
         $PDF->ezSetDy(-10);
         //ligne1 (processeur  / ram quantit?/ ram type)
         $data1 = array(array('0' => Toolbox::decodeFromUtf8(__('Processor')), '1' => $proc_item, '2' => Toolbox::decodeFromUtf8(__('Memory')), '3' => Toolbox::decodeFromUtf8(__('Quantity', 'immobilizationsheets')), '4' => $ram_item, '5' => Toolbox::decodeFromUtf8(__('Type')), '6' => $ram_type_item));
         $cols1 = array('0' => array('width' => 55, 'justification' => 'center'), '1' => array('width' => 200, 'justification' => 'left'), '2' => array('width' => 55, 'justification' => 'center'), '3' => array('width' => 55, 'justification' => 'center'), '4' => array('width' => 55, 'justification' => 'center'), '5' => array('width' => 55, 'justification' => 'center'), '6' => array('width' => 55, 'justification' => 'center'));
         $PDF->ezTable($data1, '', '', array('fontSize' => 8, 'showHeadings' => 0, 'cols' => $cols1));
         //ligne2 (Disque dur / Lecteur)
         $data1 = array(array('0' => Toolbox::decodeFromUtf8(__('Hard drive')), '1' => $hdd_item, '2' => Toolbox::decodeFromUtf8(__('Drive')), '3' => $lecteur_item));
         $cols1 = array('0' => array('width' => 55, 'justification' => 'center'), '1' => array('width' => 200, 'justification' => 'left'), '2' => array('width' => 55, 'justification' => 'center'), '3' => array('width' => 220, 'justification' => 'center'));
         $PDF->ezTable($data1, '', '', array('fontSize' => 8, 'showHeadings' => 0, 'cols' => $cols1));
         $PDF->ezSetDy(-10);
         //titre suppl?ent
         $PDF->ezText("<u>" . Toolbox::decodeFromUtf8(__('Additional cards or peripherals', 'immobilizationsheets')) . "</u> : ", 8, array("justification" => "left"));
         $PDF->ezSetDy(-10);
         if ($number6 > 0) {
             //title config logicielle
             $title = array(array('' => Toolbox::decodeFromUtf8(__('SOFTWARE CONFIGURATION', 'immobilizationsheets'))));
             $cols = array('' => array('width' => 530, 'justification' => 'center'));
             $PDF->ezTable($title, '', '', array('cols' => $cols, 'showHeadings' => 0, 'fontSize' => 12, 'showLines' => 1));
             $PDF->ezSetDy(-10);
             //titre logiciels
             $PDF->ezText("<u>" . Toolbox::decodeFromUtf8(__('Oem/Delivered software', 'immobilizationsheets')) . "</u> : ", 8, array("justification" => "left"));
             $PDF->ezSetDy(-10);
             //ligne1 (name  / version / licence)
             $data0 = array(array('0' => Toolbox::decodeFromUtf8(__('Name')), '1' => Toolbox::decodeFromUtf8(__('Version')), '2' => Toolbox::decodeFromUtf8(__('License number'))));
             $cols1 = array('0' => array('width' => 240, 'justification' => 'left'), '1' => array('width' => 50, 'justification' => 'center'), '2' => array('width' => 240, 'justification' => 'center'));
             $PDF->ezTable($data0, '', '', array('fontSize' => 8, 'showHeadings' => 0, 'cols' => $cols1));
             while ($data6 = $DB->fetch_array($result6)) {
                 $soft_name_item = $data6["name"];
                 $soft_version_item = Dropdown::getDropdownName("glpi_softwareversions", $data6["softwareversions_id_buy"]);
                 $soft_license_item = $data6["serial"];
                 $data1 = array(array('0' => $soft_name_item, '1' => $soft_version_item, '2' => $soft_license_item));
                 $cols1 = array('0' => array('width' => 240, 'justification' => 'left'), '1' => array('width' => 50, 'justification' => 'center'), '2' => array('width' => 240, 'justification' => 'center'));
                 $PDF->ezTable($data1, '', '', array('fontSize' => 8, 'showHeadings' => 0, 'cols' => $cols1));
             }
             $PDF->ezSetDy(-10);
         }
     }
     //trigramme
     $data6 = array(array('0' => Toolbox::decodeFromUtf8(__('Trigram and visa of the person in charge', 'immobilizationsheets')), '1' => ''));
     $cols6 = array('0' => array('width' => 430, 'fontSize' => 8, 'justification' => 'right'), '1' => array('width' => 100, 'justification' => 'left'));
     $PDF->ezTable($data6, '', '', array('showHeadings' => 0, 'cols' => $cols6, 'xPos' => 'center', 'xOreintation' => 'right', 'fontSize' => 8));
     //partie 3
     $PDF->ezSetDy(-20);
     $title1 = array(array('' => Toolbox::decodeFromUtf8(__('III - PART TO BE FILLED BY THE MANAGEMENT ASSISTANT', 'immobilizationsheets'))));
     $cols = array('' => array('width' => 530, 'justification' => 'left'));
     $PDF->ezTable($title1, '', '', array('cols' => $cols, 'showHeadings' => 0, 'fontSize' => 10, 'showLines' => 0, 'shaded' => 2, 'shadeCol' => array(0.8, 0.8, 0.8), 'shadeCol2' => array(0.8, 0.8, 0.8)));
     $title2 = array(array('' => Toolbox::decodeFromUtf8(__('(for checking, visa and classification)', 'immobilizationsheets'))));
     $cols = array('' => array('width' => 530, 'justification' => 'left'));
     $PDF->ezTable($title2, '', '', array('cols' => $cols, 'showHeadings' => 0, 'fontSize' => 8, 'showLines' => 0, 'shaded' => 2, 'shadeCol' => array(0.8, 0.8, 0.8), 'shadeCol2' => array(0.8, 0.8, 0.8)));
     $PDF->ezSetDy(-20);
     //title
     $title = array(array('' => Toolbox::decodeFromUtf8(__('CALCULATION OF AMORTIZATION', 'immobilizationsheets'))));
     $cols = array('' => array('width' => 530, 'justification' => 'center'));
     $PDF->ezTable($title, '', '', array('cols' => $cols, 'showHeadings' => 0, 'fontSize' => 12, 'showLines' => 1));
     $PDF->ezSetDy(-10);
     //Base d'amortissement
     $amort0 = array(array('0' => Toolbox::decodeFromUtf8(__('Base amortization', 'immobilizationsheets')), '1' => $sink_type_item));
     $cols1 = array('0' => array('width' => 130, 'fontSize' => 8, 'justification' => 'left'), '1' => array('width' => 400, 'justification' => 'left'));
     $PDF->ezTable($amort0, '', '', array('showHeadings' => 0, 'cols' => $cols1, 'fontSize' => 8, 'showLines' => 0));
     $PDF->ezSetDy(-10);
     //Duree d'amortissement
     $amort1 = array(array('0' => Toolbox::decodeFromUtf8(__('Amortization duration')), '1' => $sink_time_item));
     $cols1 = array('0' => array('width' => 130, 'fontSize' => 8, 'justification' => 'left'), '1' => array('width' => 400, 'justification' => 'left'));
     $PDF->ezTable($amort1, '', '', array('showHeadings' => 0, 'cols' => $cols1, 'fontSize' => 8, 'showLines' => 0));
     $PDF->ezSetDy(-10);
     //Date de debut d'amortissement
     $amort2 = array(array('0' => Toolbox::decodeFromUtf8(__('Date of beginning of amortization', 'immobilizationsheets')), '1' => $use_date_item));
     $cols1 = array('0' => array('width' => 130, 'fontSize' => 8, 'justification' => 'left'), '1' => array('width' => 400, 'justification' => 'left'));
     $PDF->ezTable($amort2, '', '', array('showHeadings' => 0, 'cols' => $cols1, 'fontSize' => 8, 'showLines' => 0));
     $PDF->ezSetDy(-10);
     //visa
     $amort1 = array(array('0' => Toolbox::decodeFromUtf8(__('VISA A.G.', 'immobilizationsheets')), '1' => ""));
     $cols6 = array('0' => array('width' => 430, 'fontSize' => 8, 'justification' => 'right'), '1' => array('width' => 100, 'justification' => 'left'));
     $PDF->ezTable($data6, '', '', array('showHeadings' => 0, 'cols' => $cols6, 'xPos' => 'center', 'xOreintation' => 'right', 'fontSize' => 8));
     //end
     $PDF->addInfo('Author', Toolbox::decodeFromUtf8(Html::clean(getUserName(Session::getLoginUserID()))));
     $config = new PluginImmobilizationsheetsConfig();
     if ($config->getFromDB(1)) {
         if ($saveas == 1) {
             if ($config->fields["use_backup"] == 1) {
                 $path = GLPI_DOC_DIR . "/_uploads/";
                 $time_file = date("Y-m-d-H-i-s");
                 $filename = "immo_" . $time_file . "_" . $data["name"] . ".pdf";
                 $filepath = $path . $filename;
                 $fp = fopen($filepath, 'wb');
                 fwrite($fp, $PDF->output());
                 fclose($fp);
                 $doc = new document();
                 $input = array();
                 $input["entities_id"] = $data["entities_id"];
                 $input["name"] = addslashes(self::getTypeName(1) . " " . $data["name"] . " " . $time_file);
                 $input["upload_file"] = $filename;
                 $input["documentcategories_id"] = $config->fields["documentcategories_id"];
                 $input["type"] = "application/pdf";
                 $input["date_mod"] = date("Y-m-d H:i:s");
                 $input["users_id"] = Session::getLoginUserID();
                 $newdoc = $doc->add($input);
                 $docitem = new Document_Item();
                 $docitem->add(array('documents_id' => $newdoc, 'itemtype' => $itemtype, 'items_id' => $ID, 'entities_id' => $input["entities_id"]));
             }
         }
     }
 }
Exemple #6
0
 /**
  * display a specific field value
  *
  * @since version 0.83
  *
  * @param $field     String         name of the field
  * @param $values    String/Array   with the value to display or a Single value
  * @param $options   Array          of options
  *
  * @return return the string to display
  **/
 public static function getSpecificValueToDisplay($field, $values, array $options = array())
 {
     if (!is_array($values)) {
         $values = array($field => $values);
     }
     switch ($field) {
         case 'date_expiration':
             if (empty($values[$field])) {
                 return __('Don\'t expire', 'accounts');
             } else {
                 return Html::convdate($values[$field]);
             }
             break;
     }
     return '';
 }
 /**
  * Show accounts associated to an item
  *
  * @since version 0.84
  *
  * @param $item            CommonDBTM object for which associated accounts must be displayed
  * @param $withtemplate    (default '')
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getField('id');
     if ($item->isNewID($ID)) {
         return false;
     }
     if (!plugin_accounts_haveRight('accounts', 'r')) {
         return false;
     }
     if (!$item->can($item->fields['id'], 'r')) {
         return false;
     }
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     $canedit = $item->canadditem('PluginAccountsAccount');
     $rand = mt_rand();
     $is_recursive = $item->isRecursive();
     $who = Session::getLoginUserID();
     if (count($_SESSION["glpigroups"]) && plugin_accounts_haveRight("my_groups", "r")) {
         $first_groups = true;
         $groups = "";
         foreach ($_SESSION['glpigroups'] as $val) {
             if (!$first_groups) {
                 $groups .= ",";
             } else {
                 $first_groups = false;
             }
             $groups .= "'" . $val . "'";
         }
         $ASSIGN = "( `groups_id` IN ({$groups}) OR `users_id` = '{$who}') ";
     } else {
         // Only personal ones
         $ASSIGN = " `users_id` = '{$who}' ";
     }
     $query = "SELECT `glpi_plugin_accounts_accounts_items`.`id` AS assocID,\n                       `glpi_entities`.`id` AS entity,\n                       `glpi_plugin_accounts_accounts`.`name` AS assocName,\n                       `glpi_plugin_accounts_accounts`.*\n                FROM `glpi_plugin_accounts_accounts_items`\n                LEFT JOIN `glpi_plugin_accounts_accounts`\n                 ON (`glpi_plugin_accounts_accounts_items`.`plugin_accounts_accounts_id`=`glpi_plugin_accounts_accounts`.`id`)\n                LEFT JOIN `glpi_entities` ON (`glpi_plugin_accounts_accounts`.`entities_id`=`glpi_entities`.`id`)\n                WHERE `glpi_plugin_accounts_accounts_items`.`items_id` = '{$ID}'\n                      AND `glpi_plugin_accounts_accounts_items`.`itemtype` = '" . $item->getType() . "' ";
     $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_accounts_accounts", '', '', true);
     if (!plugin_accounts_haveRight("all_users", "r")) {
         $query .= " AND {$ASSIGN} ";
     }
     $query .= " ORDER BY `assocName`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     $accounts = array();
     $account = new PluginAccountsAccount();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $accounts[$data['assocID']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     if ($canedit && $withtemplate < 2) {
         // Restrict entity for knowbase
         $entities = "";
         $entity = $_SESSION["glpiactive_entity"];
         if ($item->isEntityAssign()) {
             /// Case of personal items : entity = -1 : create on active entity (Reminder case))
             if ($item->getEntityID() >= 0) {
                 $entity = $item->getEntityID();
             }
             if ($item->isRecursive()) {
                 $entities = getSonsOf('glpi_entities', $entity);
             } else {
                 $entities = $entity;
             }
         }
         $limit = getEntitiesRestrictRequest(" AND ", "glpi_plugin_accounts_accounts", '', $entities, true);
         $q = "SELECT COUNT(*)\n               FROM `glpi_plugin_accounts_accounts`\n               WHERE `is_deleted` = '0'\n               {$limit}";
         $result = $DB->query($q);
         $nb = $DB->result($result, 0, 0);
         echo "<div class='firstbloc'>";
         if (plugin_accounts_haveRight('accounts', 'r') && $nb > count($used)) {
             echo "<form name='account_form{$rand}' id='account_form{$rand}' method='post'\n                   action='" . Toolbox::getItemTypeFormURL('PluginAccountsAccount') . "'>";
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr class='tab_bg_1'>";
             echo "<td colspan='4' class='center'>";
             echo "<input type='hidden' name='entities_id' value='{$entity}'>";
             echo "<input type='hidden' name='is_recursive' value='{$is_recursive}'>";
             echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
             echo "<input type='hidden' name='items_id' value='{$ID}'>";
             if ($item->getType() == 'Ticket') {
                 echo "<input type='hidden' name='tickets_id' value='{$ID}'>";
             }
             $account->dropdownAccounts("plugin_accounts_accounts_id", $entities, $used);
             echo "</td><td class='center' width='20%'>";
             echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Associate a account', 'accounts') . "\" class='submit'>";
             echo "</td>";
             echo "</tr>";
             echo "</table>";
             Html::closeForm();
         }
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $number && $withtemplate < 2) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('num_displayed' => $number);
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
     }
     echo "<table class='tab_cadre_fixe'>";
     if (Session::isMultiEntitiesMode()) {
         $colsup = 1;
     } else {
         $colsup = 0;
     }
     //hash
     $hashclass = new PluginAccountsHash();
     $hash = 0;
     $restrict = getEntitiesRestrictRequest(" ", "glpi_plugin_accounts_hashes", '', $item->getEntityID(), $hashclass->maybeRecursive());
     $hashes = getAllDatasFromTable("glpi_plugin_accounts_hashes", $restrict);
     if (!empty($hashes)) {
         foreach ($hashes as $hashe) {
             $hash = $hashe["hash"];
             $hash_id = $hashe["id"];
         }
         $alert = '';
     } else {
         $alert = __('There is no encryption key for this entity', 'accounts');
     }
     $aeskey = new PluginAccountsAesKey();
     if ($hash) {
         if (!$aeskey->getFromDBByHash($hash_id) || !$aeskey->fields["name"]) {
             echo "<tr><th colspan='" . (8 + $colsup) . "'>";
             _e('Encryption key', 'accounts');
             echo "<input type='password' name='aescrypted_key' id= 'aescrypted_key' autocomplete='off'>";
             echo "</th></tr>";
         }
     } else {
         echo "<tr><th colspan='" . (8 + $colsup) . "'>";
         echo __('Encryption key', 'accounts') . "<div class='red'>";
         echo $alert;
         echo "</div>";
         echo "</th></tr>";
     }
     echo "<tr>";
     if ($canedit && $number && $withtemplate < 2) {
         echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     }
     echo "<th>" . __('Name') . "</th>";
     if (Session::isMultiEntitiesMode()) {
         echo "<th>" . __('Entity') . "</th>";
     }
     echo "<th>" . __('Login') . "</th>";
     echo "<th>" . __('Password') . "</th>";
     echo "<th>" . __('Affected User', 'accounts') . "</th>";
     echo "<th>" . __('Type') . "</th>";
     echo "<th>" . __('Creation date') . "</th>";
     echo "<th>" . __('Expiration date') . "</th>";
     echo "</tr>";
     $used = array();
     if ($number) {
         Session::initNavigateListItems('PluginAccountsAccount', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         foreach ($accounts as $data) {
             $accountID = $data["id"];
             $link = NOT_AVAILABLE;
             if ($account->getFromDB($accountID)) {
                 $link = $account->getLink();
             }
             Session::addToNavigateListItems('PluginAccountsAccount', $accountID);
             $used[$accountID] = $accountID;
             $assocID = $data["assocID"];
             echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>";
             if ($canedit && $withtemplate < 2) {
                 echo "<td width='10'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]);
                 echo "</td>";
             }
             echo "<td class='center'>{$link}</td>";
             if (Session::isMultiEntitiesMode()) {
                 echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>";
             }
             echo "<td class='center'>" . $data["login"] . "</td>";
             echo "<td class='center'>";
             //hash
             if (isset($hash_id) && $aeskey->getFromDBByHash($hash_id) && $aeskey->fields["name"]) {
                 echo "<input type='hidden' name='aeskey' id= 'aeskey'\n                        value='" . $aeskey->fields["name"] . "' class='' autocomplete='off'>";
                 echo "<input type='hidden' autocomplete='off'\n               name='encrypted_password\${$accountID}' value='" . $data["encrypted_password"] . "'>";
                 echo "<input type='text' name='hidden_password\${$accountID}' value='' size='30' >";
                 echo "<script language='javascript'>\n               var good_hash=\"{$hash}\";\n               var hash=SHA256(SHA256(document.getElementById(\"aeskey\").value));\n               if (hash != good_hash) {\n               document.getElementsByName(\"hidden_password\${$accountID}\").\n               item(0).value=\"" . __s('Wrong encryption key', 'accounts') . "\";\n            } else {\n            document.getElementsByName(\"hidden_password\${$accountID}\").\n            item(0).value=AESDecryptCtr(document.getElementsByName(\"encrypted_password\${$accountID}\").\n            item(0).value,SHA256(document.getElementById(\"aeskey\").value), 256)};</script>";
             } else {
                 $url = $CFG_GLPI["root_doc"] . "/plugins/accounts/front/account.form.php";
                 echo "&nbsp;<input type='button' id='decrypte_link{$accountID}' name='decrypte' value='" . __s('Uncrypt', 'accounts') . "'\n                        class='submit' onclick='return false;'>";
                 echo "<script type='text/javascript'>\n               Ext.get('decrypte_link{$accountID}').on('click', function () {\n\n               Ext.Ajax.request({\n               url: '../plugins/accounts/ajax/get_new_crsf_token.php',\n               success: function(response, opts) {\n               var token = response.responseText;\n               Ext.select('#account_form input[name=_glpi_csrf_token]')\n               .set({'value': token});\n\n            },\n            failure: function(response, opts) {\n            console.log('server-side failure with status code ' + response.status);\n            }\n            });\n\n            var good_hash=\"{$hash}\";\n            var hash=SHA256(SHA256(document.getElementById(\"aescrypted_key\").value));\n            if (hash != good_hash) {\n            alert(\"" . __('Wrong encryption key', 'accounts') . "\");\n                     return false;\n            };\n                     alert(AESDecryptCtr(\"" . $data['encrypted_password'] . "\",\n                     SHA256(document.getElementById(\"aescrypted_key\").value),\n                     256));\n\n                     callAjax(\"{$url}\",\n                     \"{$accountID}\" ,\n                     document.getElementsByName(\"name\").item(0).value,\n                     document.getElementsByName(\"_glpi_csrf_token\").item(0).value);\n\n            });\n            </script>";
             }
             echo "</td>";
             echo "<td class='center'>";
             echo getUsername($data["users_id"]);
             echo "</td>";
             echo "<td class='center'>";
             echo Dropdown::getDropdownName("glpi_plugin_accounts_accounttypes", $data["plugin_accounts_accounttypes_id"]);
             echo "</td>";
             echo "<td class='center'>" . Html::convdate($data["date_creation"]) . "</td>";
             if ($data["date_expiration"] <= date('Y-m-d') && !empty($data["date_expiration"])) {
                 echo "<td class='center'>";
                 echo "<div class='deleted'>" . Html::convdate($data["date_expiration"]) . "</div>";
                 echo "</td>";
             } else {
                 if (empty($data["date_expiration"])) {
                     echo "<td class='center'>" . __('Don\'t expire', 'accounts') . "</td>";
                 } else {
                     echo "<td class='center'>" . Html::convdate($data["date_expiration"]) . "</td>";
                 }
             }
             echo "</tr>";
             $i++;
         }
     }
     echo "</table>";
     if ($canedit && $number && $withtemplate < 2) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
Exemple #8
0
 /**
  * Fonction permettant de dessiner le tableau des informations générales.
  */
 function affiche_tableau($total, $items, $deviceType, $disposal = 0)
 {
     if ($total != 0) {
         /* en-tete */
         $this->CellLabel(false, $this->largeur_grande_cell, Toolbox::decodeFromUtf8($deviceType));
         $this->SetY($this->GetY() + $this->line_height);
         /* En tete tableau. */
         $this->CellEnTeteTableau(false, 45, Toolbox::decodeFromUtf8(__('Name')), 1, 'C', 1);
         $this->CellEnTeteTableau(false, 35, Toolbox::decodeFromUtf8(__('Inventory number')), 1, 'C', 1);
         $this->CellEnTeteTableau(false, 20, Toolbox::decodeFromUtf8(__('Date of purchase')), 1, 'C', 1);
         if ($disposal != 1) {
             $this->CellEnTeteTableau(false, 40, Toolbox::decodeFromUtf8(__('User / Group', 'financialreports')), 1, 'C', 1);
             $this->CellEnTeteTableau(false, 40, Toolbox::decodeFromUtf8(__('Location')), 1, 'C', 1);
         }
         $this->CellEnTeteTableau(false, 40, Toolbox::decodeFromUtf8(__('Model')), 1, 'C', 1);
         $this->CellEnTeteTableau(false, 40, Toolbox::decodeFromUtf8(__('Supplier')), 1, 'C', 1);
         if ($disposal == 1) {
             $this->CellEnTeteTableau(false, 20, Toolbox::decodeFromUtf8(__('HT', 'financialreports')), 1, 'C', 1);
             $this->CellEnTeteTableau(false, 25, Toolbox::decodeFromUtf8(__('Disposal date', 'financialreports')), 1, 'C', 1);
             $this->CellEnTeteTableau(false, 55, Toolbox::decodeFromUtf8(__('Comments')), 1, 'C', 1);
         } else {
             $this->CellEnTeteTableau(false, 20, Toolbox::decodeFromUtf8(__('HT', 'financialreports')), 1, 'C', 1);
         }
         $this->SetY($this->GetY() + $this->line_height);
         /* ligne. */
         $i = 1;
         foreach ($items as $data) {
             $i++;
             $this->SetFondBlanc();
             if ($i % 2) {
                 $this->SetFondTresClair();
             }
             $this->CellLigneTableau(false, 45, $data["ITEM_0"]);
             $this->CellLigneTableau(false, 35, $data["ITEM_2"]);
             $this->CellLigneTableau(false, 20, Html::convdate($data["ITEM_3"]), 1, 'C', 1);
             $this->SetTextBleu();
             $this->CellLigneTableau(false, 40, Toolbox::decodeFromUtf8(formatUserName($data["ITEM_4_3"], $data["ITEM_4"], $data["ITEM_4_2"], $data["ITEM_4_4"])));
             $this->SetTextNoir();
             if ($disposal != 1) {
                 $this->CellLigneTableau(false, 40, Toolbox::decodeFromUtf8($data["ITEM_9"]));
                 $this->CellLigneTableau(false, 40, Toolbox::decodeFromUtf8($data["ITEM_6"]));
             }
             $this->CellLigneTableau(false, 40, Toolbox::decodeFromUtf8($data["ITEM_7"]));
             if ($disposal == 1) {
                 $this->SetTextRouge();
                 $this->CellLigneTableau(false, 20, Html::clean(Html::formatNumber($data["ITEM_8"])), 1, 'R', 1);
                 $this->SetTextNoir();
                 $this->CellLigneTableau(false, 25, Html::convdate($data["ITEM_10"]), 1, 'C', 1);
                 $this->CellLigneTableau(false, 55, Toolbox::decodeFromUtf8($data["ITEM_9"]));
             } else {
                 $this->SetTextRouge();
                 $this->CellLigneTableau(false, 20, Html::clean(Html::formatNumber($data["ITEM_8"])), 1, 'R', 1);
                 $this->SetTextNoir();
             }
             $this->SetY($this->GetY() + $this->line_height);
         }
         /* pied */
         if ($total != -1) {
             $this->CellEnTeteTableau(true, $this->largeur_grande_cell - 20, Toolbox::decodeFromUtf8(__('Total')), 1, 'R', 1);
             $this->SetTextRouge();
             $this->CellEnTeteTableau(false, 20, Html::clean(Html::formatNumber($total)), 1, 'R', 1);
             $this->SetTextNoir();
             $this->SetY($this->GetY() + $this->line_height);
         }
     }
 }
 /**
  * Show accounts associated to an item
  *
  * @since version 0.84
  *
  * @param $item            CommonDBTM object for which associated accounts must be displayed
  * @param $withtemplate    (default '')
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getField('id');
     if ($item->isNewID($ID)) {
         return false;
     }
     if (!Session::haveRight("plugin_accounts", READ)) {
         return false;
     }
     if (!$item->can($item->fields['id'], READ)) {
         return false;
     }
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     $canedit = $item->canadditem('PluginAccountsAccount');
     $rand = mt_rand();
     $is_recursive = $item->isRecursive();
     $who = Session::getLoginUserID();
     if (count($_SESSION["glpigroups"]) && Session::haveRight("plugin_accounts_my_groups", 1)) {
         $first_groups = true;
         $groups = "";
         foreach ($_SESSION['glpigroups'] as $val) {
             if (!$first_groups) {
                 $groups .= ",";
             } else {
                 $first_groups = false;
             }
             $groups .= "'" . $val . "'";
         }
         $ASSIGN = "( `groups_id` IN ({$groups}) OR `users_id` = '{$who}') ";
     } else {
         // Only personal ones
         $ASSIGN = " `users_id` = '{$who}' ";
     }
     $query = "SELECT `glpi_plugin_accounts_accounts_items`.`id` AS assocID,\n                       `glpi_entities`.`id` AS entity,\n                       `glpi_plugin_accounts_accounts`.`name` AS assocName,\n                       `glpi_plugin_accounts_accounts`.*\n                FROM `glpi_plugin_accounts_accounts_items`\n                LEFT JOIN `glpi_plugin_accounts_accounts`\n                 ON (`glpi_plugin_accounts_accounts_items`.`plugin_accounts_accounts_id`=`glpi_plugin_accounts_accounts`.`id`)\n                LEFT JOIN `glpi_entities` ON (`glpi_plugin_accounts_accounts`.`entities_id`=`glpi_entities`.`id`)\n                WHERE `glpi_plugin_accounts_accounts_items`.`items_id` = '{$ID}'\n                      AND `glpi_plugin_accounts_accounts_items`.`itemtype` = '" . $item->getType() . "' ";
     $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_accounts_accounts", '', '', true);
     if (!Session::haveRight("plugin_accounts_see_all_users", 1)) {
         $query .= " AND {$ASSIGN} ";
     }
     $query .= " ORDER BY `assocName`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     $accounts = array();
     $account = new PluginAccountsAccount();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $accounts[$data['assocID']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     if ($canedit && $withtemplate < 2) {
         // Restrict entity for knowbase
         $entities = "";
         $entity = $_SESSION["glpiactive_entity"];
         if ($item->isEntityAssign()) {
             /// Case of personal items : entity = -1 : create on active entity (Reminder case))
             if ($item->getEntityID() >= 0) {
                 $entity = $item->getEntityID();
             }
             if ($item->isRecursive()) {
                 $entities = getSonsOf('glpi_entities', $entity);
             } else {
                 $entities = $entity;
             }
         }
         $limit = getEntitiesRestrictRequest(" AND ", "glpi_plugin_accounts_accounts", '', $entities, true);
         $q = "SELECT COUNT(*)\n               FROM `glpi_plugin_accounts_accounts`\n               WHERE `is_deleted` = '0'\n               {$limit}";
         $result = $DB->query($q);
         $nb = $DB->result($result, 0, 0);
         echo "<div class='firstbloc'>";
         if (Session::haveRight('plugin_accounts', READ) && $nb > count($used)) {
             echo "<form name='account_form{$rand}' id='account_form{$rand}' method='post'\n                   action='" . Toolbox::getItemTypeFormURL('PluginAccountsAccount') . "'>";
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr class='tab_bg_1'>";
             echo "<td colspan='4' class='center'>";
             echo "<input type='hidden' name='entities_id' value='{$entity}'>";
             echo "<input type='hidden' name='is_recursive' value='{$is_recursive}'>";
             echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
             echo "<input type='hidden' name='items_id' value='{$ID}'>";
             if ($item->getType() == 'Ticket') {
                 echo "<input type='hidden' name='tickets_id' value='{$ID}'>";
             }
             PluginAccountsAccount::dropdownAccount(array('entity' => $entities, 'used' => $used));
             echo "</td><td class='center' width='20%'>";
             echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Associate a account', 'accounts') . "\" class='submit'>";
             echo "</td>";
             echo "</tr>";
             echo "</table>";
             Html::closeForm();
         }
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $number && $withtemplate < 2) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('num_displayed' => $number);
         Html::showMassiveActions($massiveactionparams);
     }
     echo "<table class='tab_cadre_fixe'>";
     if (Session::isMultiEntitiesMode()) {
         $colsup = 1;
     } else {
         $colsup = 0;
     }
     //hash
     $hashclass = new PluginAccountsHash();
     $hash = 0;
     $restrict = getEntitiesRestrictRequest(" ", "glpi_plugin_accounts_hashes", '', $item->getEntityID(), $hashclass->maybeRecursive());
     $hashes = getAllDatasFromTable("glpi_plugin_accounts_hashes", $restrict);
     if (!empty($hashes)) {
         foreach ($hashes as $hashe) {
             $hash = $hashe["hash"];
             $hash_id = $hashe["id"];
         }
         $alert = '';
     } else {
         $alert = __('There is no encryption key for this entity', 'accounts');
     }
     $aeskey = new PluginAccountsAesKey();
     echo "<tr><th colspan='" . (8 + $colsup) . "'>";
     if ($hash) {
         if (!$aeskey->getFromDBByHash($hash_id) || !$aeskey->fields["name"]) {
             _e('Encryption key', 'accounts');
             echo "<input type='password' name='aeskey' id='aeskey' autocomplete='off'>";
         } else {
             echo Html::hidden('aeskey', array('value' => $aeskey->fields["name"], 'id' => 'aeskey', 'autocomplete' => 'off'));
         }
     } else {
         echo __('Encryption key', 'accounts');
         echo "<div class='red'>";
         echo $alert;
         echo "</div>";
     }
     echo "<tr>";
     if ($canedit && $number && $withtemplate < 2) {
         echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     }
     echo "<th>" . __('Name') . "</th>";
     if (Session::isMultiEntitiesMode()) {
         echo "<th>" . __('Entity') . "</th>";
     }
     echo "<th>" . __('Login') . "</th>";
     echo "<th>" . __('Password') . "</th>";
     echo "<th>" . __('Affected User', 'accounts') . "</th>";
     echo "<th>" . __('Type') . "</th>";
     echo "<th>" . __('Creation date') . "</th>";
     echo "<th>" . __('Expiration date') . "</th>";
     echo "</tr>";
     $used = array();
     if ($number) {
         Session::initNavigateListItems('PluginAccountsAccount', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         foreach ($accounts as $data) {
             $accountID = $data["id"];
             $link = NOT_AVAILABLE;
             if ($account->getFromDB($accountID)) {
                 $link = $account->getLink();
             }
             Session::addToNavigateListItems('PluginAccountsAccount', $accountID);
             $used[$accountID] = $accountID;
             $assocID = $data["assocID"];
             echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>";
             if ($canedit && $withtemplate < 2) {
                 echo "<td width='10'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]);
                 echo "</td>";
             }
             echo "<td class='center'>{$link}</td>";
             if (Session::isMultiEntitiesMode()) {
                 echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>";
             }
             echo "<td class='center'>" . $data["login"] . "</td>";
             echo "<td class='center'>";
             //hash
             if (isset($hash_id) && $aeskey->getFromDBByHash($hash_id) && $aeskey->fields["name"]) {
                 echo Html::hidden("encrypted_password{$accountID}", array('value' => $data["encrypted_password"], 'id' => "encrypted_password{$accountID}", 'autocomplete' => 'off'));
                 echo "<input type='text' id='hidden_password{$accountID}' value='' size='30' >";
                 echo Html::scriptBlock("\n                  if (!check_hash()) {\n                     \$('#hidden_password{$accountID}')\n                        .after('" . __('Wrong encryption key', 'accounts') . "')\n                        .remove();\n                  } else {\n                     decrypt_password('{$accountID}');\n                  }\n               ");
             } else {
                 $url = $CFG_GLPI["root_doc"] . "/plugins/accounts/front/account.form.php";
                 echo "&nbsp;<input type='button' id='decrypt_link{$accountID}' name='decrypte' value='" . __s('Uncrypt', 'accounts') . "'\n                        class='submit'>";
                 echo Html::hidden("encrypted_password{$accountID}", array('value' => $data["encrypted_password"], 'id' => "encrypted_password{$accountID}", 'autocomplete' => 'off'));
                 echo Html::scriptBlock("\$(document).on('click', '#decrypt_link{$accountID}', function(event) {\n                  if (!check_hash()) {\n                     alert('" . __('Wrong encryption key', 'accounts') . "');\n                  } else {\n                     var decrypted_password = decrypt_password('{$accountID}');\n                     \$('#decrypt_link{$accountID}')\n                        .after(decrypted_password)\n                        .remove();\n                  }\n               });");
             }
             echo "</td>";
             echo "<td class='center'>";
             echo getUsername($data["users_id"]);
             echo "</td>";
             echo "<td class='center'>";
             echo Dropdown::getDropdownName("glpi_plugin_accounts_accounttypes", $data["plugin_accounts_accounttypes_id"]);
             echo "</td>";
             echo "<td class='center'>" . Html::convdate($data["date_creation"]) . "</td>";
             if ($data["date_expiration"] <= date('Y-m-d') && !empty($data["date_expiration"])) {
                 echo "<td class='center'>";
                 echo "<div class='deleted'>" . Html::convdate($data["date_expiration"]) . "</div>";
                 echo "</td>";
             } else {
                 if (empty($data["date_expiration"])) {
                     echo "<td class='center'>" . __('Don\'t expire', 'accounts') . "</td>";
                 } else {
                     echo "<td class='center'>" . Html::convdate($data["date_expiration"]) . "</td>";
                 }
             }
             echo "</tr>";
             $i++;
         }
     }
     echo "</table>";
     echo Html::hidden('good_hash', array('value' => $hash, 'id' => 'good_hash'));
     if ($canedit && $number && $withtemplate < 2) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
Exemple #10
0
 /**
  * Cron action on badges : ExpiredBadges or BadgesWhichExpire
  *
  * @param $task for log, if NULL display
  *
  **/
 static function cronBadgesAlert($task = NULL)
 {
     global $DB, $CFG_GLPI;
     if (!$CFG_GLPI["use_mailing"]) {
         return 0;
     }
     $message = array();
     $cron_status = 0;
     $query_expired = self::queryExpiredBadges();
     $query_whichexpire = self::queryBadgesWhichExpire();
     $querys = array(PluginBadgesNotificationTargetBadge::BadgesWhichExpire => $query_whichexpire, PluginBadgesNotificationTargetBadge::ExpiredBadges => $query_expired);
     $badge_infos = array();
     $badge_messages = array();
     foreach ($querys as $type => $query) {
         $badge_infos[$type] = array();
         if (!empty($query)) {
             foreach ($DB->request($query) as $data) {
                 $entity = $data['entities_id'];
                 $message = $data["name"] . ": " . Html::convdate($data["date_expiration"]) . "<br>\n";
                 $badge_infos[$type][$entity][] = $data;
                 if (!isset($badges_infos[$type][$entity])) {
                     $badge_messages[$type][$entity] = __('Badges at the end of the validity', 'badges') . "<br />";
                 }
                 $badge_messages[$type][$entity] .= $message;
             }
         }
     }
     foreach ($querys as $type => $query) {
         foreach ($badge_infos[$type] as $entity => $badges) {
             Plugin::loadLang('badges');
             if (NotificationEvent::raiseEvent($type, new PluginBadgesBadge(), array('entities_id' => $entity, 'badges' => $badges))) {
                 $message = $badge_messages[$type][$entity];
                 $cron_status = 1;
                 if ($task) {
                     $task->log(Dropdown::getDropdownName("glpi_entities", $entity) . ":  {$message}\n");
                     $task->addVolume(1);
                 } else {
                     Session::addMessageAfterRedirect(Dropdown::getDropdownName("glpi_entities", $entity) . ":  {$message}");
                 }
             } else {
                 if ($task) {
                     $task->log(Dropdown::getDropdownName("glpi_entities", $entity) . ":  Send badges alert failed\n");
                 } else {
                     Session::addMessageAfterRedirect(Dropdown::getDropdownName("glpi_entities", $entity) . ":  Send badges alert failed", false, ERROR);
                 }
             }
         }
     }
     return $cron_status;
 }
Exemple #11
0
function plugin_certificates_giveItem($type,$ID,$data,$num) {
   global $DB;

   $searchopt=&Search::getOptions($type);
   $table=$searchopt[$ID]["table"];
   $field=$searchopt[$ID]["field"];

   switch ($table.'.'.$field) {
      case "glpi_plugin_certificates_certificates.date_expiration" :
         if (empty($data[$num][0]['name']))
            $out=__('Does not expire', 'certificates');
         else
            $out= Html::convdate($data[$num][0]['name']);
         return $out;
         break;
      case "glpi_plugin_certificates_certificates_items.items_id" :
      //$type : item type
         $query_device = "SELECT DISTINCT `itemtype`
                     FROM `glpi_plugin_certificates_certificates_items`
                     WHERE `plugin_certificates_certificates_id` = '".$data['id']."'
                     ORDER BY `itemtype` ";
         $result_device = $DB->query($query_device);
         $number_device = $DB->numrows($result_device);

         $out='';
         $certificate=$data['id'];
         if ($number_device>0) {
            for ($i=0 ; $i < $number_device ; $i++) {
               $column="name";
               $itemtype=$DB->result($result_device, $i, "itemtype");
               
               if (!class_exists($itemtype)) {
                  continue;
               }
               
               $item = new $itemtype();
               if ($item->canView()) {
                  $table_item = getTableForItemType($itemtype);
                  
                  $query = "SELECT `".$table_item."`.*, `glpi_plugin_certificates_certificates_items`.`id` AS items_id, `glpi_entities`.`id` AS entity "
                  ." FROM `glpi_plugin_certificates_certificates_items`, `".$table_item
                  ."` LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = `".$table_item."`.`entities_id`) "
                  ." WHERE `".$table_item."`.`id` = `glpi_plugin_certificates_certificates_items`.`items_id`
                     AND `glpi_plugin_certificates_certificates_items`.`itemtype` = '$itemtype'
                     AND `glpi_plugin_certificates_certificates_items`.`plugin_certificates_certificates_id` = '".$certificate."' "
                  . getEntitiesRestrictRequest(" AND ",$table_item,'','',$item->maybeRecursive());

                  if ($item->maybeTemplate()) {
                     $query.=" AND ".$table_item.".is_template='0'";
                  }
                  $query.=" ORDER BY `glpi_entities`.`completename`, `".$table_item."`.`$column` ";

                  if ($result_linked=$DB->query($query))
                     if ($DB->numrows($result_linked)) {
                        $item = new $itemtype();
                        while ($data_linked = $DB->fetch_assoc($result_linked)) {
                           if ($item->getFromDB($data_linked['id'])) {
                              $out .= $item::getTypeName(1)." - ".$item->getLink()."<br>";
                           }
                        }
                     } else
                        $out.=' ';
               } else
                  $out.=' ';
            }
         }
         return $out;
         break;
   }
   return "";
}
Exemple #12
0
 /**
  * Cron action on badges : ExpiredBadges or BadgesWhichExpire
  *
  * @param $task for log, if NULL display
  *
  * */
 static function cronBadgesReturnAlert($task = NULL)
 {
     global $DB, $CFG_GLPI;
     if (!$CFG_GLPI["use_mailing"]) {
         return 0;
     }
     $message = array();
     $cron_status = 0;
     $query_returnexpire = self::queryBadgesReturnExpire();
     $querys = array(PluginBadgesNotificationTargetBadge::BadgesReturn => $query_returnexpire);
     $badge_infos = array();
     $badge_messages = array();
     foreach ($querys as $type => $query) {
         $badge_infos[$type] = array();
         if (!empty($query)) {
             foreach ($DB->request($query) as $data) {
                 $entity = $data['entities_id'];
                 $message = $data["name"] . "<br>" . __("Arrival date", "badges") . " : " . Html::convdate($data["affectation_date"]) . "<br>\n";
                 $badge_infos[$type][$entity][] = $data;
                 if (!isset($badges_infos[$type][$entity])) {
                     $badge_messages[$type][$entity] = __('Badges at the end of the validity', 'badges') . "<br />";
                 }
                 $badge_messages[$type][$entity] .= $message;
             }
         }
     }
     foreach ($querys as $type => $query) {
         foreach ($badge_infos[$type] as $entity => $badges) {
             Plugin::loadLang('badges');
             // Set badge request fields
             foreach ($badges as $badge) {
                 $badgerequest[] = array('visitor_realname' => $badge['visitor_realname'], 'visitor_firstname' => $badge['visitor_firstname'], 'visitor_society' => $badge['visitor_society'], 'affectation_date' => $badge['affectation_date'], 'requesters_id' => $badge['requesters_id']);
             }
             if (NotificationEvent::raiseEvent($type, new PluginBadgesBadge(), array('entities_id' => $entity, 'badges' => $badges, 'badgerequest' => $badgerequest))) {
                 $message = $badge_messages[$type][$entity];
                 $cron_status = 1;
                 if ($task) {
                     $task->log(Dropdown::getDropdownName("glpi_entities", $entity) . ":  {$message}\n");
                     $task->addVolume(1);
                 } else {
                     Session::addMessageAfterRedirect(Dropdown::getDropdownName("glpi_entities", $entity) . ":  {$message}");
                 }
             } else {
                 if ($task) {
                     $task->log(Dropdown::getDropdownName("glpi_entities", $entity) . ":  Send badges alert failed\n");
                 } else {
                     Session::addMessageAfterRedirect(Dropdown::getDropdownName("glpi_entities", $entity) . ":  Send badges alert failed", false, ERROR);
                 }
             }
         }
     }
     return $cron_status;
 }
Exemple #13
0
 /**
  * Launch export of datas
  *
  * @param $opt
  */
 function export($opt)
 {
     global $LANG;
     switch ($opt['switchto']) {
         default:
         case 'png':
             $graph = new PluginMreportingGraphpng();
             //check the format display charts configured in glpi
             $opt = $this->initParams($opt, true);
             $opt['export'] = 'png';
             $opt['withdata'] = 1;
             break;
         case 'csv':
             $graph = new PluginMreportingGraphcsv();
             $opt['export'] = 'csv';
             $opt['withdata'] = 1;
             break;
         case 'odt':
             $graph = new PluginMreportingGraphpng();
             $opt = $this->initParams($opt, true);
             $opt['export'] = 'odt';
             break;
         case 'odtall':
             $graph = new PluginMreportingGraphpng();
             $opt = $this->initParams($opt, true);
             $opt['export'] = 'odtall';
             break;
     }
     //export all with odt
     if (isset($opt['classname'])) {
         if (isset($opt['check'])) {
             unset($_SESSION['glpi_plugin_mreporting_odtarray']);
             $reports = $this->getAllReports(false, $opt);
             foreach ($reports as $classname => $report) {
                 foreach ($report['functions'] as $func) {
                     foreach ($opt['check'] as $do => $to) {
                         if ($do == $func['function'] . $classname) {
                             //dynamic instanciation of class passed by 'short_classname' GET parameter
                             $class = 'PluginMreporting' . $func['short_classname'];
                             $obj = new $class();
                             $randname = $classname . $func['function'];
                             if (isset($opt['date1']) && isset($opt['date2'])) {
                                 $s = strtotime($opt['date2']) - strtotime($opt['date1']);
                                 // If customExportDates exists in class : we configure the dates
                                 if (method_exists($obj, 'customExportDates')) {
                                     $opt = $obj->customExportDates($opt, $func['function']);
                                 }
                                 $_REQUEST['date1' . $randname] = $opt['date1'];
                                 $_REQUEST['date2' . $randname] = $opt['date2'];
                             }
                             //dynamic call of method passed by 'f_name'
                             //GET parameter with previously instancied class
                             $datas = $obj->{$func}['function']();
                             //show graph (pgrah type determined by
                             //first entry of explode of camelcase of function name
                             $title_func = $LANG['plugin_mreporting'][$func['short_classname']][$func['function']]['title'];
                             $des_func = "";
                             if (isset($LANG['plugin_mreporting'][$func['short_classname']][$func['function']]['desc'])) {
                                 $des_func = $LANG['plugin_mreporting'][$func['short_classname']][$func['function']]['desc'];
                             }
                             if (isset($LANG['plugin_mreporting'][$func['short_classname']][$func['function']]['desc']) && isset($opt['date1']) && isset($opt['date2'])) {
                                 $des_func .= " - ";
                             }
                             if (isset($opt['date1']) && isset($opt['date2'])) {
                                 $des_func .= Html::convdate($opt['date1']) . " / " . Html::convdate($opt['date2']);
                             }
                             $options = array("short_classname" => $func['short_classname'], "f_name" => $func['function'], "class" => $opt['classname'], "gtype" => $func['gtype'], "randname" => $randname, "withdata" => $opt['withdata']);
                             $show_label = 'always';
                             $params = array("raw_datas" => $datas, "title" => $title_func, "desc" => $des_func, "export" => $opt['export'], "opt" => $options);
                             $graph->{'show' . $func['gtype']}($params);
                         }
                     }
                 }
             }
             if (isset($_SESSION['glpi_plugin_mreporting_odtarray']) && !empty($_SESSION['glpi_plugin_mreporting_odtarray'])) {
                 if (PluginMreportingPreference::atLeastOneTemplateExists()) {
                     $template = PluginMreportingPreference::checkPreferenceTemplateValue(Session::getLoginUserID());
                     if ($template) {
                         self::generateOdt($_SESSION['glpi_plugin_mreporting_odtarray']);
                     } else {
                         Html::popHeader($LANG['plugin_mreporting']["export"][0], $_SERVER['PHP_SELF']);
                         echo "<div class='center'><br>" . $LANG['plugin_mreporting']["parser"][2] . "<br><br>";
                         Html::displayBackLink();
                         echo "</div>";
                         Html::popFooter();
                     }
                 } else {
                     Html::popHeader($LANG['plugin_mreporting']["export"][0], $_SERVER['PHP_SELF']);
                     echo "<div class='center'><br>" . $LANG['plugin_mreporting']["parser"][3] . "<br><br>";
                     Html::displayBackLink();
                     echo "</div>";
                     Html::popFooter();
                 }
             }
         } else {
             //no selected data
             Html::popHeader($LANG['plugin_mreporting']["export"][0], $_SERVER['PHP_SELF']);
             echo "<div class='center'><br>" . $LANG['plugin_mreporting']["error"][3] . "<br><br>";
             Html::displayBackLink();
             echo "</div>";
             Html::popFooter();
         }
     } else {
         //dynamic instanciation of class passed by 'short_classname' GET parameter
         $classname = 'PluginMreporting' . $opt['short_classname'];
         $obj = new $classname();
         //dynamic call of method passed by 'f_name' GET parameter with previously instancied class
         $datas = $obj->{$opt}['f_name']();
         //show graph (pgrah type determined by first entry of explode of camelcase of function name
         $title_func = $LANG['plugin_mreporting'][$opt['short_classname']][$opt['f_name']]['title'];
         $des_func = "";
         if (isset($LANG['plugin_mreporting'][$opt['short_classname']][$opt['f_name']]['desc'])) {
             $des_func = $LANG['plugin_mreporting'][$opt['short_classname']][$opt['f_name']]['desc'];
         }
         if (isset($LANG['plugin_mreporting'][$opt['short_classname']][$opt['f_name']]['desc']) && isset($_REQUEST['date1' . $opt['randname']]) && isset($_REQUEST['date2' . $opt['randname']])) {
             $des_func .= " - ";
         }
         if (isset($_REQUEST['date1' . $opt['randname']]) && isset($_REQUEST['date2' . $opt['randname']])) {
             $des_func .= Html::convdate($_REQUEST['date1' . $opt['randname']]) . " / " . Html::convdate($_REQUEST['date2' . $opt['randname']]);
         }
         $show_label = 'always';
         $opt['class'] = $classname;
         $params = array("raw_datas" => $datas, "title" => $title_func, "desc" => $des_func, "export" => $opt['export'], "opt" => $opt);
         $graph->{'show' . $opt['gtype']}($params);
     }
 }
Exemple #14
0
function plugin_projet_giveItem($type, $ID, $data, $num)
{
    global $CFG_GLPI, $DB;
    $searchopt =& Search::getOptions($type);
    $table = $searchopt[$ID]["table"];
    $field = $searchopt[$ID]["field"];
    $output_type = Search::HTML_OUTPUT;
    if (isset($_GET['display_type'])) {
        $output_type = $_GET['display_type'];
    }
    switch ($type) {
        case 'PluginProjetProjet':
            switch ($table . '.' . $field) {
                case "glpi_plugin_projet_projets_projets.plugin_projet_projets_id_1":
                    $out = " ";
                    $split = explode("\$\$\$\$", $data["ITEM_" . $num]);
                    $split2 = explode("\$\$\$\$", $data["ITEM_" . $num . "_2"]);
                    $displayed = array();
                    for ($k = 0; $k < count($split); $k++) {
                        //$linkid = $split2[$k];
                        $linkid = $split[$k] == $data['id'] ? $split2[$k] : $split2[$k];
                        if ($linkid > 0 && $linkid != $data['id'] && !isset($displayed[$linkid])) {
                            $text = $linkid . " - " . Dropdown::getDropdownName('glpi_plugin_projet_projets', $linkid);
                            if (count($displayed)) {
                                $out .= "<br>";
                            }
                            $displayed[$linkid] = $linkid;
                            $out .= $text;
                        }
                    }
                    return $out;
                    break;
                case "glpi_plugin_projet_projets.name":
                    $out = "";
                    if (!empty($data["ITEM_" . $num . "_2"])) {
                        $link = Toolbox::getItemTypeFormURL('PluginProjetProjet');
                        if ($output_type == Search::HTML_OUTPUT) {
                            $out = "<a href=\"" . $link . "?id=" . $data["ITEM_" . $num . "_2"] . "\">";
                        }
                        $out .= $data["ITEM_{$num}"];
                        if ($output_type == Search::HTML_OUTPUT) {
                            if ($_SESSION["glpiis_ids_visible"] || empty($data["ITEM_{$num}"])) {
                                $out .= " (" . $data["ITEM_" . $num . "_2"] . ")";
                            }
                            $out .= "</a>";
                        }
                        if (plugin_projet_haveRight("task", "r") && $output_type == Search::HTML_OUTPUT) {
                            $query_tasks = "SELECT COUNT(`id`) AS nb_tasks\n                                 FROM `glpi_plugin_projet_tasks`\n                                 WHERE `plugin_projet_projets_id` = '" . $data['id'] . "' ";
                            $query_tasks .= "AND `is_deleted` = '0'";
                            $result_tasks = $DB->query($query_tasks);
                            $nb_tasks = $DB->result($result_tasks, 0, "nb_tasks");
                            //select finished tasks
                            $query_states = "SELECT COUNT(`id`) AS nb_tasks\n                                 FROM `glpi_plugin_projet_tasks`\n                                 WHERE `plugin_projet_projets_id` = '" . $data['id'] . "' ";
                            $query_states .= "AND `is_deleted` = '0'";
                            $finished = " `for_dependency` = '1' ";
                            $states = getAllDatasFromTable("glpi_plugin_projet_taskstates", $finished);
                            $tab = array();
                            if (!empty($states)) {
                                foreach ($states as $state) {
                                    $tab[] = $state['id'];
                                }
                            }
                            if (!empty($tab)) {
                                $query_states .= "AND `plugin_projet_taskstates_id` IN (" . implode(',', $tab) . ")";
                            }
                            $result_states = $DB->query($query_states);
                            $is_finished = $DB->result($result_states, 0, "nb_tasks");
                            $out .= "&nbsp;(<a href=\"" . $CFG_GLPI["root_doc"] . "/plugins/projet/front/task.php?plugin_projet_projets_id=" . $data["id"] . "\">";
                            if ($nb_tasks - $is_finished > 0) {
                                $out .= "<span class='red'>";
                                $out .= $nb_tasks - $is_finished . "</span></a>)";
                            } else {
                                $out .= "<span class='green'>";
                                $out .= $nb_tasks . "</span></a>)";
                            }
                        }
                    }
                    return $out;
                    break;
                case "glpi_plugin_projet_projets.date_end":
                    if (!empty($data["ITEM_{$num}"])) {
                        if ($data["ITEM_{$num}"] <= date('Y-m-d') && !empty($data["ITEM_{$num}"])) {
                            $out = "<span class='red'>" . Html::convdate($data["ITEM_{$num}"]) . "</span>";
                        } else {
                            $out = "<span class='green'>" . Html::convdate($data["ITEM_{$num}"]) . "</span>";
                        }
                    } else {
                        $out = "--";
                    }
                    return $out;
                    break;
                case "glpi_plugin_projet_projets.advance":
                    $out = PluginProjetProjet::displayProgressBar('100', $data["ITEM_{$num}"]);
                    return $out;
                    break;
                case "glpi_plugin_projet_projets_items.items_id":
                    $restrict = "`plugin_projet_projets_id` = '" . $data['id'] . "' \n                           ORDER BY `itemtype`, `items_id`";
                    $items = getAllDatasFromTable("glpi_plugin_projet_projets_items", $restrict);
                    $out = '';
                    if (!empty($items)) {
                        foreach ($items as $device) {
                            if (!class_exists($device["itemtype"])) {
                                continue;
                            }
                            $item = new $device["itemtype"]();
                            $item->getFromDB($device["items_id"]);
                            $out .= $item->getTypeName() . " - ";
                            if ($device["itemtype"] == 'User') {
                                if ($output_type == Search::HTML_OUTPUT) {
                                    $link = Toolbox::getItemTypeFormURL('User');
                                    $out .= "<a href=\"" . $link . "?id=" . $device["items_id"] . "\">";
                                }
                                $out .= getUserName($device["items_id"]);
                                if ($output_type == Search::HTML_OUTPUT) {
                                    $out .= "</a>";
                                }
                            } else {
                                $out .= $item->getLink();
                            }
                            $out .= "<br>";
                        }
                    } else {
                        $out = ' ';
                    }
                    return $out;
                    break;
            }
            return "";
            break;
        case 'PluginProjetTask':
            switch ($table . '.' . $field) {
                case "glpi_plugin_projet_tasks_tasks.plugin_projet_tasks_id_1":
                    $out = " ";
                    $split = explode("\$\$\$\$", $data["ITEM_" . $num]);
                    $split2 = explode("\$\$\$\$", $data["ITEM_" . $num . "_2"]);
                    $displayed = array();
                    for ($k = 0; $k < count($split); $k++) {
                        //$linkid = $split2[$k];
                        $linkid = $split[$k] == $data['id'] ? $split2[$k] : $split2[$k];
                        if ($linkid > 0 && $linkid != $data['id'] && !isset($displayed[$linkid])) {
                            $text = $linkid . " - " . Dropdown::getDropdownName('glpi_plugin_projet_tasks', $linkid);
                            if (count($displayed)) {
                                $out .= "<br>";
                            }
                            $displayed[$linkid] = $linkid;
                            $out .= $text;
                        }
                    }
                    return $out;
                    break;
                case "glpi_plugin_projet_tasks.advance":
                    $out = PluginProjetProjet::displayProgressBar('100', $data["ITEM_{$num}"]);
                    return $out;
                    break;
                case "glpi_plugin_projet_tasks.priority":
                    $out = Ticket::getPriorityName($data["ITEM_{$num}"]);
                    return $out;
                    break;
                case 'glpi_plugin_projet_tasks.depends':
                    $out = "";
                    if ($data["ITEM_{$num}"] == 1) {
                        $out .= "<span class='red'>";
                    }
                    $out .= Dropdown::getYesNo($data["ITEM_{$num}"]);
                    if ($data["ITEM_{$num}"] == 1) {
                        $out .= "</span>";
                    }
                    return $out;
                    break;
                case "glpi_plugin_projet_tasks.plugin_projet_projets_id":
                    $out = Dropdown::getdropdownname("glpi_plugin_projet_projets", $data["ITEM_{$num}"]);
                    $out .= " (" . $data["ITEM_{$num}"] . ")";
                    return $out;
                    break;
                case "glpi_plugin_projet_tasks_items.items_id":
                    $restrict = "`plugin_projet_tasks_id` = '" . $data['id'] . "' \n                           ORDER BY `itemtype`, `items_id`";
                    $items = getAllDatasFromTable("glpi_plugin_projet_tasks_items", $restrict);
                    $out = '';
                    if (!empty($items)) {
                        foreach ($items as $device) {
                            $item = new $device["itemtype"]();
                            $item->getFromDB($device["items_id"]);
                            $out .= $item->getTypeName() . " - " . $item->getLink() . "<br>";
                        }
                    }
                    return $out;
                    break;
                case "glpi_contacts.name":
                    if (!empty($data["ITEM_{$num}"])) {
                        $link = Toolbox::getItemTypeFormURL('Contact');
                        $out = "<a href=\"" . $link . "?id=" . $data["ITEM_{$num}"] . "\">";
                        $temp = $data["contacts_name"];
                        $firstname = $data["contacts_firstname"];
                        if (strlen($firstname) > 0) {
                            if ($CFG_GLPI["names_format"] == FIRSTNAME_BEFORE) {
                                $temp = $firstname . " " . $temp;
                            } else {
                                $temp .= " " . $firstname;
                            }
                        }
                        $out .= $temp;
                        if ($_SESSION["glpiis_ids_visible"] || empty($data["ITEM_{$num}"])) {
                            $out .= " (" . $data["ITEM_{$num}"] . ")";
                        }
                        $out .= "</a>";
                    } else {
                        $out = "";
                    }
                    return $out;
                    break;
                case "glpi_plugin_projet_taskplannings.id":
                    if (!empty($data["ITEM_{$num}"])) {
                        $plan = new PluginProjetTaskPlanning();
                        $plan->getFromDB($data["ITEM_{$num}"]);
                        $out = Html::convDateTime($plan->fields["begin"]) . "<br>&nbsp;->&nbsp;" . Html::convDateTime($plan->fields["end"]);
                    } else {
                        $out = __('None');
                    }
                    return $out;
                    break;
            }
            return "";
            break;
    }
    return "";
}
Exemple #15
0
 /**
  * Show domains associated to a supplier
  *
  * @since version 0.84
  *
  * @param $item            CommonDBTM object for which associated domains must be displayed
  * @param $withtemplate    (default '')
  **/
 static function showForSupplier(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getField('id');
     if ($item->isNewID($ID)) {
         return false;
     }
     if (!plugin_domains_haveRight('domains', 'r')) {
         return false;
     }
     if (!$item->can($item->fields['id'], 'r')) {
         return false;
     }
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     $rand = mt_rand();
     $is_recursive = $item->isRecursive();
     $query = "SELECT `glpi_plugin_domains_domains`.`id` AS assocID,\n                       `glpi_entities`.`id` AS entity,\n                       `glpi_plugin_domains_domains`.`name` AS assocName,\n                       `glpi_plugin_domains_domains`.* " . "FROM `glpi_plugin_domains_domains` " . " LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = `glpi_plugin_domains_domains`.`entities_id`) " . " WHERE `suppliers_id` = '{$ID}' " . getEntitiesRestrictRequest(" AND ", "glpi_plugin_domains_domains", '', '', true);
     $query .= " ORDER BY `assocName` ";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     $domains = array();
     $domain = new PluginDomainsDomain();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $domains[$data['assocID']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     echo "<div class='spaced'>";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr>";
     echo "<th>" . __('Name') . "</th>";
     if (Session::isMultiEntitiesMode()) {
         echo "<th>" . __('Entity') . "</th>";
     }
     echo "<th>" . __('Group in charge of the hardware') . "</th>";
     echo "<th>" . __('Supplier') . "</th>";
     echo "<th>" . __('Technician in charge of the hardware') . "</th>";
     echo "<th>" . __('Type') . "</th>";
     echo "<th>" . __('Creation date') . "</th>";
     echo "<th>" . __('Expiration date') . "</th>";
     echo "</tr>";
     $used = array();
     if ($number) {
         Session::initNavigateListItems('PluginDomainsDomain', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         foreach ($domains as $data) {
             $domainID = $data["id"];
             $link = NOT_AVAILABLE;
             if ($domain->getFromDB($domainID)) {
                 $link = $domain->getLink();
             }
             Session::addToNavigateListItems('PluginDomainsDomain', $domainID);
             $used[$domainID] = $domainID;
             $assocID = $data["assocID"];
             echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>";
             echo "<td class='center'>{$link}</td>";
             if (Session::isMultiEntitiesMode()) {
                 echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>";
             }
             echo "<td class='center'>" . Dropdown::getDropdownName("glpi_groups", $data["groups_id_tech"]) . "</td>";
             echo "<td>";
             echo "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/enterprise.form.php?ID=" . $data["suppliers_id"] . "\">";
             echo Dropdown::getDropdownName("glpi_suppliers", $data["suppliers_id"]);
             if ($_SESSION["glpiis_ids_visible"] == 1) {
                 echo " (" . $data["suppliers_id"] . ")";
             }
             echo "</a></td>";
             echo "<td class='center'>" . getUsername($data["users_id_tech"]) . "</td>";
             echo "<td class='center'>" . Dropdown::getDropdownName("glpi_plugin_domains_domaintypes", $data["plugin_domains_domaintypes_id"]) . "</td>";
             echo "<td class='center'>" . Html::convdate($data["date_creation"]) . "</td>";
             if ($data["date_expiration"] <= date('Y-m-d') && !empty($data["date_expiration"])) {
                 echo "<td class='center'><div class='deleted'>" . convdate($data["date_expiration"]) . "</div></td>";
             } else {
                 if (empty($data["date_expiration"])) {
                     echo "<td class='center'>" . __('Does not expire', 'domains') . "</td>";
                 } else {
                     echo "<td class='center'>" . Html::convdate($data["date_expiration"]) . "</td>";
                 }
             }
             echo "</tr>";
             $i++;
         }
     }
     echo "</table>";
     echo "</div>";
 }
 static function showImport($row_num, $item_num, $line, $output_type, $configID, $status, $imported)
 {
     global $DB, $CFG_GLPI;
     $infocom = new Infocom();
     $canedit = Session::haveRight(static::$rightname, UPDATE) && $infocom->canUpdate();
     $config = new PluginManufacturersimportsConfig();
     $config->getFromDB($configID);
     $suppliername = $config->fields["name"];
     $supplierUrl = $config->fields["supplier_url"];
     $supplierId = $config->fields["suppliers_id"];
     $supplierWarranty = $config->fields["warranty_duration"];
     $supplierkey = $config->fields["supplier_key"];
     $supplierclass = "PluginManufacturersimports" . $suppliername;
     $supplier = new $supplierclass();
     $row_num++;
     if ($suppliername) {
         $model = new PluginManufacturersimportsModel();
         $otherSerial = $model->checkIfModelNeeds($line["itemtype"], $line["id"]);
         echo Search::showNewLine($output_type, $row_num % 2);
         $ic = new Infocom();
         $output_check = "";
         if ($canedit && $output_type == Search::HTML_OUTPUT) {
             $sel = "";
             if (isset($_GET["select"]) && $_GET["select"] == "all") {
                 $sel = "checked";
             }
             $output_check = $supplier->showCheckbox($line["id"], $sel, $otherSerial);
         }
         echo Search::showItem($output_type, $output_check, $item_num, $row_num);
         $link = Toolbox::getItemTypeFormURL($line["itemtype"]);
         $ID = "";
         if ($_SESSION["glpiis_ids_visible"] || empty($line["name"])) {
             $ID .= " (" . $line["id"] . ")";
         }
         $output_link = "<a href='" . $link . "?id=" . $line["id"] . "'>" . $line["name"] . $ID . "</a><br>" . $line["model_name"];
         echo Search::showItem($output_type, $output_link, $item_num, $row_num);
         if (Session::isMultiEntitiesMode()) {
             echo Search::showItem($output_type, Dropdown::getDropdownName("glpi_entities", $line['entities_id']), $item_num, $row_num);
         }
         $url = self::selectSupplier($suppliername, $line["serial"], $otherSerial, $supplierkey);
         //serial
         echo Search::showItem($output_type, $line["serial"], $item_num, $row_num);
         //otherserial
         echo $supplier->showItem($output_type, $otherSerial, $item_num, $row_num);
         //display infocoms
         $output_ic = "";
         if ($ic->getfromDBforDevice($line["itemtype"], $line["id"])) {
             $output_ic .= _n('Supplier', 'Suppliers', 1) . ":" . Dropdown::getDropdownName("glpi_suppliers", $ic->fields["suppliers_id"]) . "<br>";
             $output_ic .= __('Date of purchase') . " : " . Html::convdate($ic->fields["buy_date"]) . "<br>";
             $output_ic .= __('Start date of warranty') . ":" . Html::convdate($ic->fields["warranty_date"]) . "<br>";
             if ($ic->fields["warranty_duration"] == -1) {
                 $output_ic .= __('Warranty duration') . ":" . __('Lifelong') . "<br>";
             } else {
                 $output_ic .= __('Warranty duration') . ":" . $ic->fields["warranty_duration"] . " " . __('month') . "<br>";
             }
             $tmpdat = Infocom::getWarrantyExpir($ic->fields["warranty_date"], $ic->fields["warranty_duration"]);
             $output_ic .= sprintf(__('Valid to %s'), $tmpdat);
         } else {
             $output_ic .= "";
         }
         echo Search::showItem($output_type, $output_ic, $item_num, $row_num);
         if ($imported != self::IMPORTED) {
             //display enterprise and warranty selection
             echo "<td>";
             if (Session::isMultiEntitiesMode() && $supplierId) {
                 $item = new Supplier();
                 $item->getFromDB($supplierId);
                 if ($item->fields["is_recursive"] || $item->fields["entities_id"] == $line['entities_id']) {
                     Dropdown::show('Supplier', array('name' => "to_suppliers_id" . $line["id"], 'value' => $supplierId, 'comments' => 0, 'entity' => $line['entities_id']));
                 } else {
                     echo "<span class='plugin_manufacturersimports_import_KO'>";
                     echo __('The choosen supplier is not recursive', 'manufacturersimports') . "</span>";
                     echo "<input type='hidden' name='to_suppliers_id" . $line["id"] . "' value='-1'>";
                 }
             } else {
                 Dropdown::show('Supplier', array('name' => "to_suppliers_id" . $line["id"], 'value' => $supplierId, 'comments' => 0, 'entity' => $line['entities_id']));
             }
             echo "</td>";
             $supplier->showWarrantyItem($line["id"], $supplierWarranty);
         } else {
             //display enterprise and warranty selection
             echo "<td>" . Dropdown::getDropdownName("glpi_suppliers", $ic->fields["suppliers_id"]) . "</td>";
             if ($ic->fields["warranty_duration"] == -1) {
                 echo "<td>" . __('Lifelong') . "</td>";
             } else {
                 echo "<td>" . $ic->fields["warranty_duration"] . "</td>";
             }
         }
         //supplier url
         //url to supplier
         $output_url = "<a href='" . $url . "' target='_blank'>" . __('Manufacturer information', 'manufacturersimports') . "</a>";
         echo Search::showItem($output_type, $output_url, $item_num, $row_num);
         //status
         if ($imported != self::IMPORTED) {
             if ($status != 2) {
                 $output_doc = __('Not yet imported', 'manufacturersimports');
             } else {
                 $output_doc = "<span class='plugin_manufacturersimports_import_KO'>" . __('Problem during the importation', 'manufacturersimports');
                 if (!empty($data["date_import"])) {
                     $output_doc .= " (" . Html::convdate($data["date_import"]) . ")";
                 }
                 $output_doc .= "</span>";
             }
         } else {
             $output_doc = "<span class='plugin_manufacturersimports_import_OK'>" . __('Already imported', 'manufacturersimports');
             if (!empty($line["date_import"])) {
                 $output_doc .= " (" . Html::convdate($line["date_import"]) . ")";
             }
             $output_doc .= "</span>";
         }
         echo Search::showItem($output_type, $output_doc, $item_num, $row_num);
         //no associated doc
         echo $supplier->showDocItem($output_type, $item_num, $row_num, $line["documents_id"]);
     }
 }
 /**
  * Show domains associated to an item
  *
  * @since version 0.84
  *
  * @param $item            CommonDBTM object for which associated domains must be displayed
  * @param $withtemplate    (default '')
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getField('id');
     if ($item->isNewID($ID)) {
         return false;
     }
     if (!plugin_domains_haveRight('domains', 'r')) {
         return false;
     }
     if (!$item->can($item->fields['id'], 'r')) {
         return false;
     }
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     $canedit = $item->canadditem('PluginDomainsDomain');
     $rand = mt_rand();
     $is_recursive = $item->isRecursive();
     $query = "SELECT `glpi_plugin_domains_domains_items`.`id` AS assocID,\n                       `glpi_entities`.`id` AS entity,\n                       `glpi_plugin_domains_domains`.`name` AS assocName,\n                       `glpi_plugin_domains_domains`.*\n                FROM `glpi_plugin_domains_domains_items`\n                LEFT JOIN `glpi_plugin_domains_domains`\n                 ON (`glpi_plugin_domains_domains_items`.`plugin_domains_domains_id`=`glpi_plugin_domains_domains`.`id`)\n                LEFT JOIN `glpi_entities` ON (`glpi_plugin_domains_domains`.`entities_id`=`glpi_entities`.`id`)\n                WHERE `glpi_plugin_domains_domains_items`.`items_id` = '{$ID}'\n                      AND `glpi_plugin_domains_domains_items`.`itemtype` = '" . $item->getType() . "' ";
     $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_domains_domains", '', '', true);
     $query .= " ORDER BY `assocName`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     $domains = array();
     $domain = new PluginDomainsDomain();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $domains[$data['assocID']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     if ($canedit && $withtemplate < 2) {
         // Restrict entity for knowbase
         $entities = "";
         $entity = $_SESSION["glpiactive_entity"];
         if ($item->isEntityAssign()) {
             /// Case of personal items : entity = -1 : create on active entity (Reminder case))
             if ($item->getEntityID() >= 0) {
                 $entity = $item->getEntityID();
             }
             if ($item->isRecursive()) {
                 $entities = getSonsOf('glpi_entities', $entity);
             } else {
                 $entities = $entity;
             }
         }
         $limit = getEntitiesRestrictRequest(" AND ", "glpi_plugin_domains_domains", '', $entities, true);
         $q = "SELECT COUNT(*)\n               FROM `glpi_plugin_domains_domains`\n               WHERE `is_deleted` = '0'\n               {$limit}";
         $result = $DB->query($q);
         $nb = $DB->result($result, 0, 0);
         echo "<div class='firstbloc'>";
         if (plugin_domains_haveRight('domains', 'r') && $nb > count($used)) {
             echo "<form name='domain_form{$rand}' id='domain_form{$rand}' method='post'\n                   action='" . Toolbox::getItemTypeFormURL('PluginDomainsDomain') . "'>";
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr class='tab_bg_1'>";
             echo "<td colspan='4' class='center'>";
             echo "<input type='hidden' name='entities_id' value='{$entity}'>";
             echo "<input type='hidden' name='is_recursive' value='{$is_recursive}'>";
             echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
             echo "<input type='hidden' name='items_id' value='{$ID}'>";
             if ($item->getType() == 'Ticket') {
                 echo "<input type='hidden' name='tickets_id' value='{$ID}'>";
             }
             $domain->dropdownDomains("plugin_domains_domains_id", $entities, $used);
             echo "</td><td class='center' width='20%'>";
             echo "<input type='submit' name='additem' value=\"" . __s('Associate a domain', 'domains') . "\" class='submit'>";
             echo "</td>";
             echo "</tr>";
             echo "</table>";
             Html::closeForm();
         }
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $number && $withtemplate < 2) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('num_displayed' => $number);
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
     }
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr>";
     if ($canedit && $number && $withtemplate < 2) {
         echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     }
     echo "<th>" . __('Name') . "</th>";
     if (Session::isMultiEntitiesMode()) {
         echo "<th>" . __('Entity') . "</th>";
     }
     echo "<th>" . __('Group in charge of the hardware') . "</th>";
     echo "<th>" . __('Supplier') . "</th>";
     echo "<th>" . __('Technician in charge of the hardware') . "</th>";
     echo "<th>" . __('Type') . "</th>";
     echo "<th>" . __('Creation date') . "</th>";
     echo "<th>" . __('Expiration date') . "</th>";
     echo "</tr>";
     $used = array();
     if ($number) {
         Session::initNavigateListItems('PluginDomainsDomain', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         foreach ($domains as $data) {
             $domainID = $data["id"];
             $link = NOT_AVAILABLE;
             if ($domain->getFromDB($domainID)) {
                 $link = $domain->getLink();
             }
             Session::addToNavigateListItems('PluginDomainsDomain', $domainID);
             $used[$domainID] = $domainID;
             $assocID = $data["assocID"];
             echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>";
             if ($canedit && $withtemplate < 2) {
                 echo "<td width='10'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]);
                 echo "</td>";
             }
             echo "<td class='center'>{$link}</td>";
             if (Session::isMultiEntitiesMode()) {
                 echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>";
             }
             echo "<td class='center'>" . Dropdown::getDropdownName("glpi_groups", $data["groups_id_tech"]) . "</td>";
             echo "<td>";
             echo "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/enterprise.form.php?ID=" . $data["suppliers_id"] . "\">";
             echo Dropdown::getDropdownName("glpi_suppliers", $data["suppliers_id"]);
             if ($_SESSION["glpiis_ids_visible"] == 1) {
                 echo " (" . $data["suppliers_id"] . ")";
             }
             echo "</a></td>";
             echo "<td class='center'>" . getUsername($data["users_id_tech"]) . "</td>";
             echo "<td class='center'>" . Dropdown::getDropdownName("glpi_plugin_domains_domaintypes", $data["plugin_domains_domaintypes_id"]) . "</td>";
             echo "<td class='center'>" . Html::convdate($data["date_creation"]) . "</td>";
             if ($data["date_expiration"] <= date('Y-m-d') && !empty($data["date_expiration"])) {
                 echo "<td class='center'><div class='deleted'>" . convdate($data["date_expiration"]) . "</div></td>";
             } else {
                 if (empty($data["date_expiration"])) {
                     echo "<td class='center'>" . __('Does not expire', 'domains') . "</td>";
                 } else {
                     echo "<td class='center'>" . Html::convdate($data["date_expiration"]) . "</td>";
                 }
             }
             echo "</tr>";
             $i++;
         }
     }
     echo "</table>";
     if ($canedit && $number && $withtemplate < 2) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
 /**
  * Cron action on certificates : ExpiredCertificates or CertificatesWhichExpire
  *
  * @param $task for log, if NULL display
  *
  **/
 static function cronCertificatesAlert($task = NULL)
 {
     global $DB, $CFG_GLPI;
     if (!$CFG_GLPI["use_mailing"]) {
         return 0;
     }
     $message = array();
     $cron_status = 0;
     $Certificate = new self();
     $query_expired = self::queryExpiredCertificates();
     $query_whichexpire = self::queryCertificatesWhichExpire();
     $querys = array(Alert::NOTICE => $query_whichexpire, Alert::END => $query_expired);
     $certificate_infos = array();
     $certificate_messages = array();
     foreach ($querys as $type => $query) {
         $certificate_infos[$type] = array();
         foreach ($DB->request($query) as $data) {
             $entity = $data['entities_id'];
             $message = $data["name"] . ": " . Html::convdate($data["date_expiration"]) . "<br>\n";
             $certificate_infos[$type][$entity][] = $data;
             if (!isset($certificates_infos[$type][$entity])) {
                 $certificate_messages[$type][$entity] = __('Certificates expired since more', 'certificates') . "<br />";
             }
             $certificate_messages[$type][$entity] .= $message;
         }
     }
     foreach ($querys as $type => $query) {
         foreach ($certificate_infos[$type] as $entity => $certificates) {
             Plugin::loadLang('certificates');
             if (NotificationEvent::raiseEvent($type == Alert::NOTICE ? "CertificatesWhichExpire" : "ExpiredCertificates", new PluginCertificatesCertificate(), array('entities_id' => $entity, 'certificates' => $certificates))) {
                 $message = $certificate_messages[$type][$entity];
                 $cron_status = 1;
                 if ($task) {
                     $task->log(Dropdown::getDropdownName("glpi_entities", $entity) . ":  {$message}\n");
                     $task->addVolume(1);
                 } else {
                     Session::addMessageAfterRedirect(Dropdown::getDropdownName("glpi_entities", $entity) . ":  {$message}");
                 }
             } else {
                 if ($task) {
                     $task->log(Dropdown::getDropdownName("glpi_entities", $entity) . ":  Send certificates alert failed\n");
                 } else {
                     Session::addMessageAfterRedirect(Dropdown::getDropdownName("glpi_entities", $entity) . ":  Send certificates alert failed", false, ERROR);
                 }
             }
         }
     }
     return $cron_status;
 }
 /**
  * Show for PDF an projet - Hierarchy
  * 
  * @param $pdf object for the output
  * @param $ID of the projet
  */
 static function pdfHierarchyForProjet(PluginPdfSimplePDF $pdf, PluginProjetProjet $appli, $parents = 0)
 {
     global $DB, $CFG_GLPI;
     $ID = $appli->fields['id'];
     if (!$appli->can($ID, "r")) {
         return false;
     }
     if (!plugin_projet_haveRight("projet", "r")) {
         return false;
     }
     $pdf->setColumnsSize(100);
     if ($parents) {
         $pdf->displayTitle('<b>' . __('Parent project', 'projet') . '</b>');
     } else {
         $pdf->displayTitle('<b>' . _n('Child project', 'Child projects', 2, 'projet') . '</b>');
     }
     $first = false;
     $query = "SELECT `" . $appli->gettable() . "`.*  ";
     if ($parents != 0) {
         $parent = "plugin_projet_projets_id_1";
         $child = "plugin_projet_projets_id_2";
     } else {
         $parent = "plugin_projet_projets_id_2";
         $child = "plugin_projet_projets_id_1";
     }
     $query .= " FROM `glpi_plugin_projet_projets`";
     $query .= " LEFT JOIN `glpi_plugin_projet_projets_projets` \n                  ON (`glpi_plugin_projet_projets_projets`.`{$child}` = `glpi_plugin_projet_projets`.`id`)";
     $query .= " WHERE `glpi_plugin_projet_projets_projets`.`{$parent}` = '{$ID}' ";
     if ($appli->maybeTemplate()) {
         $LINK = " AND ";
         if ($first) {
             $LINK = " ";
             $first = false;
         }
         $query .= $LINK . "`" . $appli->getTable() . "`.`is_template` = '0' ";
     }
     // Add is_deleted if item have it
     if ($appli->maybeDeleted()) {
         $LINK = " AND ";
         if ($first) {
             $LINK = " ";
             $first = false;
         }
         $query .= $LINK . "`" . $appli->getTable() . "`.`is_deleted` = '0' ";
     }
     $LINK = " AND ";
     $query .= getEntitiesRestrictRequest(" AND ", $appli->gettable(), '', '', $appli->maybeRecursive());
     $query .= " ORDER BY `" . $appli->gettable() . "`.`name`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     if (!$number) {
         $pdf->displayLine(__('No item found'));
     } else {
         if (Session::isMultiEntitiesMode()) {
             $pdf->setColumnsSize(17, 17, 17, 17, 16, 16);
             $pdf->displayTitle('<b><i>' . __('Name'), __('Entity'), __('Progress'), _n('State', 'States', 1), __('Start date'), __('End date') . '</i></b>');
         } else {
             $pdf->setColumnsSize(20, 17, 17, 17, 17);
             $pdf->displayTitle('<b><i>' . __('Name'), __('Progress'), _n('State', 'States', 1), __('Start date'), __('End date') . '</i></b>');
         }
         while ($data = $DB->fetch_array($result)) {
             $items_id_display = "";
             if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) {
                 $items_id_display = " (" . $data["id"] . ")";
             }
             $name = $data["name"] . $items_id_display;
             $entity = Html::clean(Dropdown::getDropdownName("glpi_entities", $data['entities_id']));
             if (Session::isMultiEntitiesMode()) {
                 $pdf->setColumnsSize(17, 17, 17, 17, 16, 16);
                 $pdf->displayLine($name, $entity, PluginProjetProjet::displayProgressBar('100', $data["advance"], array("simple" => true)), Html::clean(Dropdown::getDropdownName("glpi_plugin_projet_projetstates", $data['plugin_projet_projetstates_id'])), Html::convdate($data["date_begin"]), Html::convdate($data["date_end"]));
             } else {
                 $pdf->setColumnsSize(20, 17, 17, 17, 17);
                 $pdf->displayLine($name, PluginProjetProjet::displayProgressBar('100', $data["advance"], array("simple" => true)), Html::clean(Dropdown::getDropdownName("glpi_plugin_projet_projetstates", $data['plugin_projet_projetstates_id'])), Html::convdate($data["date_begin"]), Html::convdate($data["date_end"]));
             }
         }
     }
     $pdf->displaySpace();
 }
 function afficheTableau($date, $display, $output_type, $itemtable, $end_display, $start, $nbcols, $titre, $total, $items, $locations_id)
 {
     global $DB, $CFG_GLPI;
     $first = true;
     $deleted = 0;
     $master_total = 0;
     $master_total += $total;
     if ($total != 0) {
         if ($output_type == Search::HTML_OUTPUT) {
             echo "<br>";
             echo Search::showHeader($output_type, $end_display - $start + 1, $nbcols, 1);
         } else {
             echo Search::showNewLine($output_type);
             echo Search::showEndLine($output_type);
         }
         echo Search::showNewLine($output_type);
         //tr
         if ($output_type == Search::HTML_OUTPUT) {
             if ($total != -1) {
                 echo "<th>" . $titre . "</th><th><font color='red'>" . Html::formatNumber($total) . " " . _n('Euro', 'Euros', 2, 'financialreports') . "</font></th><th>";
             } else {
                 echo "<th>" . $titre . "</th><th></th><th>";
             }
             if ($_SESSION[$display]) {
                 $status = "false";
             } else {
                 $status = "true";
             }
             echo "<a href='" . $CFG_GLPI["root_doc"] . "/plugins/financialreports/front/financialreport.php?" . $display . "=" . $status . "&date=" . $date . "&locations_id=" . $locations_id . "'>";
             if ($_SESSION[$display]) {
                 echo __('Hide', 'financialreports');
             } else {
                 echo __('Display', 'financialreports');
             }
             echo "</a>";
             if ($itemtable != 'disposal') {
                 echo "</th><th colspan='4'><th>";
             } else {
                 echo "</th><th colspan='3'><th>";
             }
         } else {
             echo Search::showHeaderItem($output_type, $titre, $header_num);
             //th
             echo Search::showHeaderItem($output_type, __('Total'), $header_num);
             if ($total != -1) {
                 echo Search::showHeaderItem($output_type, Html::formatNumber($total) . " " . _n('Euro', 'Euros', 2, 'financialreports'), $header_num);
             }
         }
         echo Search::showEndLine($output_type);
         //tr
         echo Search::showNewLine($output_type);
         $header_num = 1;
         echo Search::showHeaderItem($output_type, __('Name'), $header_num);
         echo Search::showHeaderItem($output_type, __('Inventory number'), $header_num);
         echo Search::showHeaderItem($output_type, __('Date of purchase'), $header_num);
         if ($itemtable != 'disposal') {
             echo Search::showHeaderItem($output_type, __('User / Group', 'financialreports'), $header_num);
             echo Search::showHeaderItem($output_type, __('Location'), $header_num);
         }
         echo Search::showHeaderItem($output_type, __('Model'), $header_num);
         echo Search::showHeaderItem($output_type, __('Supplier'), $header_num);
         if ($itemtable == 'disposal') {
             echo Search::showHeaderItem($output_type, __('Disposal date', 'financialreports'), $header_num);
             echo Search::showHeaderItem($output_type, __('Comments'), $header_num);
         } else {
             echo Search::showHeaderItem($output_type, __('Purchase Price HT in', 'financialreports') . " " . _n('Euro', 'Euros', 2, 'financialreports'), $header_num);
         }
         // End Line for column headers
         echo Search::showEndLine($output_type);
         $row_num = 1;
         if ($_SESSION[$display]) {
             foreach ($items as $data) {
                 $row_num++;
                 $item_num = 1;
                 echo Search::showNewLine($output_type, $row_num % 2);
                 //name
                 $link = Toolbox::getItemTypeFormURL($data["TYPE"]);
                 $output_iddev = "<a href='" . $link . "?id=" . $data["id"] . "'>" . $data["ITEM_0"] . ($_SESSION["glpiis_ids_visible"] ? " (" . $data["id"] . ")" : "") . "</a>";
                 echo Search::showItem($output_type, $output_iddev, $item_num, $row_num);
                 //otherserial
                 echo Search::showItem($output_type, $data["ITEM_2"], $item_num, $row_num);
                 //buy_date
                 echo Search::showItem($output_type, Html::convdate($data["ITEM_3"]), $item_num, $row_num);
                 if ($itemtable != 'disposal') {
                     //user
                     $username_computer = formatUserName($data["ITEM_4_3"], $data["ITEM_4"], $data["ITEM_4_2"], $data["ITEM_4_4"]);
                     $output_iduser = "******" . $CFG_GLPI["root_doc"] . "/front/user.form.php?id=" . $data["ITEM_4_3"] . "'>" . $username_computer . "</a>";
                     if ($data["ITEM_4_3"] && $data["ITEM_5"]) {
                         $output_iduser .= " / <a href='" . $CFG_GLPI["root_doc"] . "/front/group.form.php?id=" . $data["ITEM_5_1"] . "'>" . $data["ITEM_5"] . ($_SESSION["glpiis_ids_visible"] ? " (" . $data["ITEM_5_1"] . ")" : "") . "</a>";
                     } else {
                         if (!isset($data["ITEM_4_3"]) && $data["ITEM_5"]) {
                             $output_iduser = "******" . $CFG_GLPI["root_doc"] . "/front/group.form.php?id=" . $data["ITEM_5_1"] . "'>" . $data["ITEM_5"] . ($_SESSION["glpiis_ids_visible"] ? " (" . $data["ITEM_5_1"] . ")" : "") . "</a>";
                         } else {
                             if (!isset($data["ITEM_4_3"]) && !isset($data["ITEM_5"])) {
                                 $output_iduser = __('In stock / available', 'financialreports');
                             }
                         }
                     }
                     echo Search::showItem($output_type, $output_iduser, $item_num, $row_num);
                     //location
                     echo Search::showItem($output_type, $data["ITEM_9"], $item_num, $row_num);
                 }
                 //model
                 echo Search::showItem($output_type, $data["ITEM_6"], $item_num, $row_num);
                 //manufacturer
                 echo Search::showItem($output_type, $data["ITEM_7"], $item_num, $row_num);
                 if ($itemtable == 'disposal') {
                     //comments
                     echo Search::showItem($output_type, Html::convdate($data["ITEM_10"]), $item_num, $row_num);
                     echo Search::showItem($output_type, nl2br($data["ITEM_9"]), $item_num, $row_num);
                 } else {
                     //value
                     if ($output_type == Search::HTML_OUTPUT) {
                         $ouput_value = "<font color='red'>" . Html::formatNumber($data["ITEM_8"]) . "</font>";
                     } else {
                         $ouput_value = Html::formatNumber($data["ITEM_8"]);
                     }
                     echo Search::showItem($output_type, $ouput_value, $item_num, $row_num);
                 }
                 echo Search::showEndLine($output_type);
             }
         }
         echo Search::showFooter($output_type);
     }
     return $master_total;
 }
Exemple #21
0
 /**
  * init Graph : Show Titles / Date selector
  *
  * @params $options ($rand, short_classname, title, desc, delay)
  */
 function initGraph($options)
 {
     global $LANG, $CFG_GLPI;
     //if ($options['export']=="odt" || $options['export']=="odtall") {
     //$this->width = $this->width - 100;
     //}
     $randname = $options['randname'];
     if (!$options['export']) {
         $width = $this->width + 100;
         if (!isset($_REQUEST['date1' . $randname])) {
             $_REQUEST['date1' . $randname] = strftime("%Y-%m-%d", time() - $options['delay'] * 24 * 60 * 60);
         }
         if (!isset($_REQUEST['date2' . $randname])) {
             $_REQUEST['date2' . $randname] = strftime("%Y-%m-%d");
         }
         $backtrace = debug_backtrace();
         $prev_function = strtolower(str_replace('show', '', $backtrace[1]['function']));
         echo "<div class='center'><div id='fig' style='width:{$width}px'>";
         if (isset($LANG['plugin_mreporting'][$options['short_classname']]['title'])) {
             echo "<div class='graph_title'>";
             echo $LANG['plugin_mreporting'][$options['short_classname']]['title'];
             echo "</div>";
         }
         echo "<div class='graph_title'>";
         echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/mreporting/pics/chart-{$prev_function}.png' class='title_pics' />";
         echo $options['title'];
         echo "</div>";
         $desc = '';
         if (!empty($options['desc'])) {
             $desc = $options['desc'];
         }
         if (!empty($options['desc']) && isset($_REQUEST['date1' . $randname]) && isset($_REQUEST['date1' . $randname])) {
             $desc .= " - ";
         }
         if (isset($_REQUEST['date1' . $randname]) && isset($_REQUEST['date1' . $randname])) {
             $desc .= Html::convdate($_REQUEST['date1' . $randname]) . " / " . Html::convdate($_REQUEST['date2' . $randname]);
         }
         echo "<div class='graph_desc'>" . $desc . "</div>";
         echo "<div class='graph_navigation'>";
         PluginMreportingMisc::showSelector($_REQUEST['date1' . $randname], $_REQUEST['date2' . $randname], $randname);
         echo "</div>";
     }
     if ($options['export'] != "odt" && $options['export'] != "odtall") {
         echo "<div class='graph' id='graph_content{$randname}'>";
     }
 }
 static function isInError($type, $ID, $contents = null)
 {
     $msgerr = "";
     $date = date("Y-m-d");
     echo "<td>";
     echo "<span class='plugin_manufacturersimports_import_KO'>";
     echo __('Import failed', 'manufacturersimports') . " (";
     echo Html::convdate($date) . ")</span></td>";
     $temp = new PluginManufacturersimportsLog();
     $temp->deleteByCriteria(array('itemtype' => $type, 'items_id' => $ID));
     //insert base locale
     $values["import_status"] = 2;
     $values["items_id"] = $ID;
     $values["itemtype"] = $type;
     $values["date_import"] = $date;
     $log = new PluginManufacturersimportsLog();
     $log->add($values);
     if (!empty($contents)) {
         $msgerr = __('Connection failed/data download from manufacturer web site', 'manufacturersimports');
     }
     echo "<td>{$msgerr}</td>";
 }
 /**
  * Show projet for a ticket / problem
  *
  * @param $item Ticket or Problem object
  **/
 static function showForHelpdesk($item)
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getField('id');
     if (!$item->can($ID, 'r')) {
         return false;
     }
     $canedit = $item->can($ID, 'w');
     $rand = mt_rand();
     echo "<form name='projetlink_form{$rand}' id='projetlink_form{$rand}' method='post'\n             action='";
     echo Toolbox::getItemTypeFormURL("PluginProjetProjet") . "'>";
     echo "<div class='center'><table class='tab_cadre_fixehov'>";
     echo "<tr><th colspan='7'>" . _n('Project', 'Projects', 2, 'projet') . "&nbsp;-&nbsp;";
     echo "<a href='" . Toolbox::getItemTypeFormURL('PluginProjetProjet') . "?helpdesk_id={$ID}&helpdesk_itemtype=" . $item->gettype() . "'>";
     $nav = "";
     if ($item->gettype() == "Ticket") {
         _e('Create a project from this ticket', 'projet');
         $nav = _n('Ticket', 'Tickets', 2);
     } else {
         _e('Create a project from this problem', 'projet');
         $nav = _n('Problem', 'Problems', 2);
     }
     echo "</a>";
     echo "</th></tr>";
     $query = "SELECT `glpi_plugin_projet_projets_items`.`id` AS items_id,\n                     `glpi_plugin_projet_projets`.* " . " FROM `glpi_plugin_projet_projets_items`,`glpi_plugin_projet_projets` " . " LEFT JOIN `glpi_entities` \n         ON (`glpi_entities`.`id` = `glpi_plugin_projet_projets`.`entities_id`) " . " WHERE `glpi_plugin_projet_projets_items`.`items_id` = '" . $ID . "' \n       AND `glpi_plugin_projet_projets_items`.`itemtype` = '" . $item->gettype() . "' \n       AND `glpi_plugin_projet_projets_items`.`plugin_projet_projets_id` = `glpi_plugin_projet_projets`.`id`  \n       AND `glpi_plugin_projet_projets`.`is_template` = '0' ";
     $query .= "ORDER BY `glpi_plugin_projet_projets`.`name`";
     $result = $DB->query($query);
     $used = array();
     if ($DB->numrows($result) > 0) {
         PluginProjetProjet::commonListHeader(Search::HTML_OUTPUT, $canedit);
         Session::initNavigateListItems('PluginProjetProjet', $nav . " = " . $item->fields["name"]);
         $i = 0;
         while ($data = $DB->fetch_array($result)) {
             $used[$data['id']] = $data['id'];
             Session::addToNavigateListItems('PluginProjetProjet', $data["id"]);
             echo "<tr class='tab_bg_1" . ($data["is_deleted"] == '1' ? "_2" : "") . "'>";
             if ($canedit && (in_array($data['entities_id'], $_SESSION['glpiactiveentities']) || $data["is_recursive"])) {
                 echo "<td class='center'>";
                 echo "<a href='" . $CFG_GLPI["root_doc"] . "/plugins/projet/front/projet.form.php?id=" . $data["id"] . "'>" . $data["name"];
                 if ($_SESSION["glpiis_ids_visible"]) {
                     echo " (" . $data["id"] . ")";
                 }
                 echo "</a></td>";
             } else {
                 echo "<td class='center'>" . $data["name"];
                 if ($_SESSION["glpiis_ids_visible"]) {
                     echo " (" . $data["id"] . ")";
                 }
                 echo "</td>";
             }
             if (Session::isMultiEntitiesMode()) {
                 echo "<td class='center'>";
                 echo Dropdown::getDropdownName("glpi_entities", $data['entities_id']);
                 echo "</td>";
             }
             echo "<td align='center'>" . $data["description"] . "</td>";
             echo "<td align='center'>";
             echo PluginProjetProjet::displayProgressBar('100', $data["advance"]);
             echo "</td>";
             echo "<td class='center'>" . Html::convdate($data["date_begin"]) . "</td>";
             if ($data["date_end"] <= date('Y-m-d') && !empty($data["date_end"])) {
                 echo "<td class='center'>";
                 echo "<span class='red'>" . Html::convdate($data["date_end"]) . "</span></td>";
             } else {
                 echo "<td class='center'>";
                 echo "<span class='green'>" . Html::convdate($data["date_end"]) . "</span></td>";
             }
             if ($canedit) {
                 echo "<td class='center tab_bg_2'>";
                 Html::showSimpleForm($CFG_GLPI['root_doc'] . '/plugins/projet/front/projet.form.php', 'deletedevice', _x('button', 'Delete permanently'), array('id' => $data['items_id']));
                 echo "</td>";
             }
             echo "</tr>";
             $i++;
         }
     }
     if ($canedit) {
         echo "<tr class='tab_bg_2'><td class='right'  colspan='6'>";
         echo "<input type='hidden' name='items_id' value='{$ID}'>";
         echo "<input type='hidden' name='itemtype' value='" . $item->gettype() . "'>";
         echo "<input type='hidden' name='helpdesk_itemtype' value='" . $item->gettype() . "'>";
         Dropdown::show('PluginProjetProjet', array('used' => $used, 'entity' => $item->getEntityID(), 'name' => 'plugin_projet_projets_id'));
         echo "</td><td class='center'>";
         echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</td></tr>";
     }
     echo "</table></div>";
     /*if ($canedit) {
          Html::openArrowMassives("projetlink_form$rand", true);
          Html::closeArrowMassives(array('delete' => _sx('button','Delete'));
       }*/
     Html::closeForm();
 }