isRecursive() public method

Can be overloaded (ex : infocom)
public isRecursive ( ) : boolean
return boolean
Exemplo n.º 1
0
 /**
  * @param $item   CommonDBTM object
  **/
 static function showActivationFormForItem(CommonDBTM $item)
 {
     if (!self::canUpdate()) {
         return false;
     }
     if ($item->getID()) {
         // Recursive type case => need entity right
         if ($item->isRecursive()) {
             if (!Session::haveAccessToEntity($item->fields["entities_id"])) {
                 return false;
             }
         }
     } else {
         return false;
     }
     $ri = new self();
     echo "<div>";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr><th colspan='2'>" . __('Reserve an item') . "</th></tr>";
     echo "<tr class='tab_bg_1'>";
     if ($ri->getFromDBbyItem($item->getType(), $item->getID())) {
         echo "<td class='center'>";
         //Switch reservation state
         if ($ri->fields["is_active"]) {
             Html::showSimpleForm(static::getFormURL(), 'update', __('Make unavailable'), array('id' => $ri->fields['id'], 'is_active' => 0));
         } else {
             Html::showSimpleForm(static::getFormURL(), 'update', __('Make available'), array('id' => $ri->fields['id'], 'is_active' => 1));
         }
         echo '</td><td>';
         Html::showSimpleForm(static::getFormURL(), 'purge', __('Prohibit reservations'), array('id' => $ri->fields['id']), '', '', array(__('Are you sure you want to return this non-reservable item?'), __('That will remove all the reservations in progress.')));
         echo "</td>";
     } else {
         echo "<td class='center'>";
         Html::showSimpleForm(static::getFormURL(), 'add', __('Authorize reservations'), array('items_id' => $item->getID(), 'itemtype' => $item->getType(), 'entities_id' => $item->getEntityID(), 'is_recursive' => $item->isRecursive()));
         echo "</td>";
     }
     echo "</tr></table>";
     echo "</div>";
 }
Exemplo n.º 2
0
 /**
  * Show resource associated to an item
  *
  * @since version 0.84
  *
  * @param $item            CommonDBTM object for which associated resource 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_resources_haveRight('resources', 'r')) {
         return false;
     }
     if (!$item->can($item->fields['id'], 'r')) {
         return false;
     }
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     $canedit = $item->canadditem('PluginResourcesResource');
     $rand = mt_rand();
     $is_recursive = $item->isRecursive();
     $query = "SELECT `glpi_plugin_resources_resources_items`.`id` AS assocID,\n                       `glpi_entities`.`id` AS entity,\n                       `glpi_plugin_resources_resources`.`name` AS assocName,\n                       `glpi_plugin_resources_resources`.*\n                FROM `glpi_plugin_resources_resources_items`\n                LEFT JOIN `glpi_plugin_resources_resources`\n                 ON (`glpi_plugin_resources_resources_items`.`plugin_resources_resources_id`=`glpi_plugin_resources_resources`.`id`)\n                LEFT JOIN `glpi_entities` ON (`glpi_plugin_resources_resources`.`entities_id`=`glpi_entities`.`id`)\n                WHERE `glpi_plugin_resources_resources_items`.`items_id` = '{$ID}'\n                      AND `glpi_plugin_resources_resources_items`.`itemtype` = '" . $item->getType() . "' ";
     $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_resources_resources", '', '', true);
     $query .= " ORDER BY `assocName`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     $resources = array();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $resources[$data['assocID']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     $resource = new PluginResourcesResource();
     $more = true;
     if ($item->getType() == "User" && $number != 0) {
         $more = false;
     }
     if ($canedit && $withtemplate < 2 && $more) {
         // 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_resources_resources", '', $entities, true);
         $q = "SELECT COUNT(*)\n               FROM `glpi_plugin_resources_resources`\n               WHERE `is_deleted` = '0'\n               AND `is_template` = '0' ";
         if ($item->getType() != 'User') {
             $q .= " {$limit}";
         }
         $result = $DB->query($q);
         $nb = $DB->result($result, 0, 0);
         echo "<div class='firstbloc'>";
         if (plugin_resources_haveRight('resources', 'r') && $nb > count($used)) {
             echo "<form name='resource_form{$rand}' id='resource_form{$rand}' method='post'\n                   action='" . Toolbox::getItemTypeFormURL('PluginResourcesResource') . "'>";
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr class='tab_bg_1'>";
             echo "<td colspan='4' class='center'>";
             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}'>";
             }
             PluginResourcesResource::dropdown(array('entity' => $entities, 'used' => $used));
             echo "</td><td class='center' width='20%'>";
             echo "<input type='submit' name='additem' value=\"" . __s('Associate a resource', 'resources') . "\" 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;
     }
     echo "<tr>";
     if ($canedit && $number && $withtemplate < 2) {
         echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     }
     echo "<th>" . __('Name') . "</th>";
     echo "<th>" . __('First name') . "</th>";
     if (Session::isMultiEntitiesMode()) {
         echo "<th>" . __('Entity') . "</th>";
     }
     echo "<th>" . __('Location') . "</th>";
     echo "<th>" . PluginResourcesContractType::getTypeName(1) . "</th>";
     echo "<th>" . PluginResourcesDepartment::getTypeName(1) . "</th>";
     echo "<th>" . __('Arrival date', 'resources') . "</th>";
     echo "<th>" . __('Departure date', 'resources') . "</th>";
     echo "</tr>";
     $used = array();
     $resourceID = 0;
     if ($number) {
         Session::initNavigateListItems('PluginResourcesResource', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         foreach ($resources as $data) {
             $resourceID = $data["id"];
             $link = NOT_AVAILABLE;
             if ($resource->getFromDB($resourceID)) {
                 $link = $resource->getLink();
             }
             Session::addToNavigateListItems('PluginResourcesResource', $resourceID);
             $used[$resourceID] = $resourceID;
             $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>";
             echo "<td class='center'>" . $data['firstname'] . "</td>";
             if (Session::isMultiEntitiesMode()) {
                 echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>";
             }
             echo "<td class='center'>";
             echo Dropdown::getDropdownName("glpi_locations", $data["locations_id"]);
             echo "</td>";
             echo "<td class='center'>";
             echo Dropdown::getDropdownName("glpi_plugin_resources_contracttypes", $data["plugin_resources_contracttypes_id"]);
             echo "</td>";
             echo "<td class='center'>";
             echo Dropdown::getDropdownName("glpi_plugin_resources_departments", $data["plugin_resources_departments_id"]);
             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='plugin_resources_date_color'>";
                 echo Html::convDate($data["date_end"]);
                 echo "</span>";
                 echo "</td>";
             } else {
                 if (empty($data["date_end"])) {
                     echo "<td class='center'>" . __('Not defined', 'resources') . "</td>";
                 } else {
                     echo "<td class='center'>" . Html::convDate($data["date_end"]) . "</td>";
                 }
             }
             echo "</tr>";
             $i++;
         }
     }
     echo "</table>";
     if ($canedit && $number && $withtemplate < 2) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
     if ($item->getType() == "User") {
         $PluginResourcesEmployee = new PluginResourcesEmployee();
         $PluginResourcesEmployee->showForm($resourceID, $ID, 0);
     }
 }
 /**
  * Show webapplications associated to an item
  *
  * @since version 0.84
  *
  * @param $item            CommonDBTM object for which associated webapplications 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_webapplications", READ)) {
         return false;
     }
     if (!$item->can($item->fields['id'], READ)) {
         return false;
     }
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     $canedit = $item->canadditem('PluginWebapplicationsWebapplication');
     $rand = mt_rand();
     $is_recursive = $item->isRecursive();
     $query = "SELECT `glpi_plugin_webapplications_webapplications_items`.`id` AS assocID,\n                       `glpi_entities`.`id` AS entity,\n                       `glpi_plugin_webapplications_webapplications`.`name` AS assocName,\n                       `glpi_plugin_webapplications_webapplications`.*\n                FROM `glpi_plugin_webapplications_webapplications_items`\n                LEFT JOIN `glpi_plugin_webapplications_webapplications`\n                 ON (`glpi_plugin_webapplications_webapplications_items`.`plugin_webapplications_webapplications_id`=`glpi_plugin_webapplications_webapplications`.`id`)\n                LEFT JOIN `glpi_entities` ON (`glpi_plugin_webapplications_webapplications`.`entities_id`=`glpi_entities`.`id`)\n                WHERE `glpi_plugin_webapplications_webapplications_items`.`items_id` = '{$ID}'\n                      AND `glpi_plugin_webapplications_webapplications_items`.`itemtype` = '" . $item->getType() . "' ";
     $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_webapplications_webapplications", '', '', true);
     $query .= " ORDER BY `assocName`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     $webs = array();
     $web = new PluginWebapplicationsWebapplication();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $webs[$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_webapplications_webapplications", '', $entities, true);
         $q = "SELECT COUNT(*)\n               FROM `glpi_plugin_webapplications_webapplications`\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_webapplications", READ) && $nb > count($used)) {
             echo "<form name='webapplication_form{$rand}' id='webapplication_form{$rand}' method='post'\n                   action='" . Toolbox::getItemTypeFormURL('PluginWebapplicationsWebapplication') . "'>";
             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}'>";
             }
             PluginWebapplicationsWebapplication::dropdownWebapplication(array('entity' => $entities, 'used' => $used));
             echo "</td><td class='center' width='20%'>";
             echo "<input type='submit' name='additem' value=\"" . __s('Associate a web application', 'webapplications') . "\" 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>" . PluginWebapplicationsWebapplicationType::getTypeName(1) . "</th>";
     echo "<th>" . __('URL') . "</th>";
     echo "<th>" . __('Server') . "</th>";
     echo "<th>" . __('Language') . "</th>";
     echo "<th>" . __('Version') . "</th>";
     echo "<th>" . __('Comments') . "</th>";
     echo "</tr>";
     $used = array();
     if ($number) {
         Session::initNavigateListItems('PluginWebapplicationsWebapplication', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         foreach ($webs as $data) {
             $webID = $data["id"];
             $link = NOT_AVAILABLE;
             if ($web->getFromDB($webID)) {
                 $link = $web->getLink();
             }
             Session::addToNavigateListItems('PluginWebapplicationsWebapplication', $webID);
             $used[$webID] = $webID;
             $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>" . Dropdown::getDropdownName("glpi_plugin_webapplications_webapplicationtypes", $data["plugin_webapplications_webapplicationtypes_id"]) . "</td>";
             $link = Toolbox::substr($data["address"], 0, 30) . "...";
             echo "<td class='center'>" . "<a href=\"" . str_replace("&", "&amp;", $data["address"]) . "\" target=\"_blank\">" . "<u>" . $link . "</u></a></td>";
             echo "<td>" . Dropdown::getDropdownName("glpi_plugin_webapplications_webapplicationservertypes", $data["plugin_webapplications_webapplicationservertypes_id"]) . "</td>";
             echo "<td>" . Dropdown::getDropdownName("glpi_plugin_webapplications_webapplicationtechnics", $data["plugin_webapplications_webapplicationtechnics_id"]) . "</td>";
             echo "<td>" . $data["version"] . "</td>";
             echo "<td>" . $data["comment"] . "</td>";
             echo "</tr>";
             $i++;
         }
     }
     echo "</table>";
     if ($canedit && $number && $withtemplate < 2) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
Exemplo n.º 4
0
 /**
  * @since version 0.90
  *
  * @param $item
  * @param $withtemplate    (default '')
  * @param $options         array
  *
  * @return boolean
  **/
 static function showAddFormForItem(CommonDBTM $item, $withtemplate = '', $options = array())
 {
     global $DB, $CFG_GLPI;
     //default options
     $params['rand'] = mt_rand();
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $val) {
             $params[$key] = $val;
         }
     }
     if (!$item->can($item->fields['id'], READ)) {
         return false;
     }
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     // find documents already associated to the item
     $doc_item = new self();
     $used_found = $doc_item->find("`items_id` = '" . $item->getID() . "'\n                                    AND `itemtype` = '" . $item->getType() . "'");
     $used = array_keys($used_found);
     $used = array_combine($used, $used);
     if ($item->canAddItem('Document') && $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_documents", '', $entities, true);
         $q = "SELECT COUNT(*)\n               FROM `glpi_documents`\n               WHERE `is_deleted` = '0'\n               {$limit}";
         $result = $DB->query($q);
         $nb = $DB->result($result, 0, 0);
         if ($item->getType() == 'Document') {
             $used[$item->getID()] = $item->getID();
         }
         echo "<div class='firstbloc'>";
         echo "<form name='documentitem_form" . $params['rand'] . "' id='documentitem_form" . $params['rand'] . "' method='post' action='" . Toolbox::getItemTypeFormURL('Document') . "' enctype=\"multipart/form-data\">";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2'><th colspan='5'>" . __('Add a document') . "</th></tr>";
         echo "<tr class='tab_bg_1'>";
         echo "<td class='center'>";
         _e('Heading');
         echo "</td><td width='20%'>";
         DocumentCategory::dropdown(array('entity' => $entities));
         echo "</td>";
         echo "<td class='right'>";
         echo "<input type='hidden' name='entities_id' value='{$entity}'>";
         echo "<input type='hidden' name='is_recursive' value='" . $item->isRecursive() . "'>";
         echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
         echo "<input type='hidden' name='items_id' value='" . $item->getID() . "'>";
         if ($item->getType() == 'Ticket') {
             echo "<input type='hidden' name='tickets_id' value='" . $item->getID() . "'>";
         }
         echo Html::file(array('multiple' => true));
         echo "</td><td class='left'>(" . Document::getMaxUploadSize() . ")&nbsp;</td>";
         echo "<td class='center' width='20%'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add a new file') . "\"\n                class='submit'>";
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
         if (Document::canView() && $nb > count($used)) {
             echo "<form name='document_form" . $params['rand'] . "' id='document_form" . $params['rand'] . "' method='post' action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr class='tab_bg_1'>";
             echo "<td colspan='4' class='center'>";
             echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
             echo "<input type='hidden' name='items_id' value='" . $item->getID() . "'>";
             if ($item->getType() == 'Ticket') {
                 echo "<input type='hidden' name='tickets_id' value='" . $item->getID() . "'>";
                 echo "<input type='hidden' name='documentcategories_id' value='" . $CFG_GLPI["documentcategories_id_forticket"] . "'>";
             }
             Document::dropdown(array('entity' => $entities, 'used' => $used));
             echo "</td><td class='center' width='20%'>";
             echo "<input type='submit' name='add' value=\"" . _sx('button', 'Associate an existing document') . "\" 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>";
   }
Exemplo n.º 6
0
 /**
  * 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>";
 }
 /**
  * Show rack associated to an item
  *
  * @since version 0.84
  *
  * @param $item            CommonDBTM object for which associated rack must be displayed
  * @param $withtemplate    (default '')
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getField('id');
     if ($item->isNewID($ID) || !self::canView() || !$item->can($item->fields['id'], READ)) {
         return false;
     }
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     $canedit = $item->canadditem('PluginRacksRack');
     $rand = mt_rand();
     $is_recursive = $item->isRecursive();
     $itemtype = $item->getType() . "Model";
     $query = "SELECT `glpi_plugin_racks_racks_items`.`id` AS assocID,\n                       `glpi_plugin_racks_racks_items`.`faces_id`,\n                       `glpi_plugin_racks_racks_items`.`position`,\n                       `glpi_entities`.`id` AS entity,\n                       `glpi_plugin_racks_racks`.`name` AS assocName,\n                       `glpi_plugin_racks_racks`.*\n                FROM `glpi_plugin_racks_racks_items`\n                LEFT JOIN `glpi_plugin_racks_racks`\n                 ON (`glpi_plugin_racks_racks_items`.`plugin_racks_racks_id`=`glpi_plugin_racks_racks`.`id`)\n                LEFT JOIN `glpi_entities` ON (`glpi_plugin_racks_racks`.`entities_id`=`glpi_entities`.`id`)\n                WHERE `glpi_plugin_racks_racks_items`.`items_id` = '{$ID}'\n                      AND `glpi_plugin_racks_racks_items`.`itemtype` = '" . $itemtype . "' ";
     $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_racks_racks", '', '', true);
     $query .= " ORDER BY `assocName`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     $racks = array();
     $rack = new PluginRacksRack();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $racks[$data['assocID']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     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>" . __('Disposition', 'racks') . "</th>";
     echo "<th>" . __('Position', 'racks') . "</th>";
     echo "<th>" . __('Location') . "</th>";
     echo "<th>" . __('Place', 'racks') . "</th>";
     echo "<th>" . __('Manufacturer') . "</th>";
     echo "</tr>";
     $used = array();
     if ($number) {
         Session::initNavigateListItems('PluginRacksRack', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         foreach ($racks as $data) {
             $rackID = $data["id"];
             $link = NOT_AVAILABLE;
             if ($rack->getFromDB($rackID)) {
                 $link = $rack->getLink();
             }
             Session::addToNavigateListItems('PluginRacksRack', $rackID);
             $used[$rackID] = $rackID;
             $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>";
             }
             if ($data["faces_id"] == PluginRacksRack::FRONT_FACE) {
                 $faces_id = __('Front', 'racks');
             } else {
                 $faces_id = _x('Rack enclosure', 'Back', 'racks');
             }
             echo "<td class='center'>" . $faces_id . "</td>";
             echo "<td class='center'>" . $data["position"] . "</td>";
             echo "<td>" . Dropdown::getDropdownName("glpi_locations", $data["locations_id"]) . "</td>";
             echo "<td class='center'>" . Dropdown::getDropdownName("glpi_plugin_racks_roomlocations", $data["plugin_racks_roomlocations_id"], 0) . "</td>";
             echo "<td>" . Dropdown::getDropdownName("glpi_manufacturers", $data["manufacturers_id"]) . "</td>";
             echo "</tr>";
             $i++;
         }
     }
     echo "</table>";
     if ($canedit && $number && $withtemplate < 2) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
 /**
  * Show shellcommands associated to an item
  *
  * @since version 0.84
  *
  * @param $item            CommonDBTM object for which associated shellcommands must be displayed
  * @param $withtemplate    (default '')
  * */
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getField('id');
     if ($item->isNewID($ID)) {
         return false;
     }
     if (!self::canView()) {
         return false;
     }
     if (!$item->can($item->fields['id'], READ)) {
         return false;
     }
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     $width = 200;
     $canedit = $item->canadditem('PluginShellcommandsShellcommand');
     $rand = mt_rand();
     $is_recursive = $item->isRecursive();
     $query = "SELECT `glpi_plugin_shellcommands_shellcommands_items`.`id` AS assocID,\n                       `glpi_entities`.`id` AS entity,\n                       `glpi_plugin_shellcommands_shellcommands`.`name` AS assocName,\n                       `glpi_plugin_shellcommands_shellcommands`.*\n                FROM `glpi_plugin_shellcommands_shellcommands_items`\n                LEFT JOIN `glpi_plugin_shellcommands_shellcommands`\n                 ON (`glpi_plugin_shellcommands_shellcommands_items`.`plugin_shellcommands_shellcommands_id`=`glpi_plugin_shellcommands_shellcommands`.`id`)\n                LEFT JOIN `glpi_entities` ON (`glpi_plugin_shellcommands_shellcommands`.`entities_id`=`glpi_entities`.`id`)\n                WHERE `glpi_plugin_shellcommands_shellcommands_items`.`itemtype` = '" . $item->getType() . "' \n                  AND !`glpi_plugin_shellcommands_shellcommands`.`is_deleted`";
     $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_shellcommands_shellcommands", '', '', true);
     $query .= " ORDER BY `assocName`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     $shells = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $shells[$data['assocID']] = $data;
         }
     }
     echo "<div class='spaced'>";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr>";
     echo "<th>" . __('Associated Commands', 'shellcommands') . "</th>";
     echo "</tr>";
     if ($number) {
         Session::initNavigateListItems('PluginShellcommandsShellcommand', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         $selectCommandName[0] = Dropdown::EMPTY_VALUE;
         //         $countCommand = self::countForItem($item, array('type' => 'ALL'));
         foreach ($shells as $data) {
             //            if(isset($countCommand[$data['link'].$data['id']]))
             $selectCommandName[$data['link'] . '-' . $data['id']] = $data['assocName'];
         }
         echo "<tr class='tab_bg_2'>\n               <td class='center'>" . PluginShellcommandsShellcommand::getTypeName(1) . " ";
         $randSelect = Dropdown::showFromArray("name", $selectCommandName, array('width' => $width));
         echo "<span id='command_name{$randSelect}'></span></td>";
         echo "</tr>";
         Ajax::updateItemOnSelectEvent("dropdown_name{$randSelect}", "command_name{$randSelect}", $CFG_GLPI["root_doc"] . "/plugins/shellcommands/ajax/dropdownCommandValue.php", array('idtable' => $item->getType(), 'width' => $width, 'value' => '__VALUE__', 'itemID' => $ID, 'countItem' => 1, 'itemtype' => $item->getType(), 'toupdate' => 'shellcommand_result', 'command_type' => 'PluginShellcommandsShellcommand', 'myname' => "command_name"));
     }
     echo "</table>";
     echo "</div>";
     echo "<div class='spaced' id='shellcommand_result'></div>";
 }
Exemplo n.º 9
0
 /**
  * Prints a direct connection to a computer
  *
  * @param $item                     CommonDBTM object: the Monitor/Phone/Peripheral/Printer
  * @param $withtemplate    integer  withtemplate param (default '')
  *
  * @return nothing (print out a table)
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     // Prints a direct connection to a computer
     global $DB;
     $comp = new Computer();
     $ID = $item->getField('id');
     if (!$item->can($ID, READ)) {
         return false;
     }
     $canedit = $item->canEdit($ID);
     $rand = mt_rand();
     // Is global connection ?
     $global = $item->getField('is_global');
     $used = array();
     $compids = array();
     $crit = array('FIELDS' => array('id', 'computers_id', 'is_dynamic'), 'itemtype' => $item->getType(), 'items_id' => $ID, 'is_deleted' => 0);
     foreach ($DB->request('glpi_computers_items', $crit) as $data) {
         $compids[$data['id']] = $data['computers_id'];
         $dynamic[$data['id']] = $data['is_dynamic'];
         $used['Computer'][] = $data['computers_id'];
     }
     $number = count($compids);
     if ($canedit && ($global || !$number)) {
         echo "<div class='firstbloc'>";
         echo "<form name='computeritem_form{$rand}' id='computeritem_form{$rand}' method='post'\n                action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2'><th colspan='2'>" . __('Connect a computer') . "</th></tr>";
         echo "<tr class='tab_bg_1'><td class='right'>";
         echo "<input type='hidden' name='items_id' value='{$ID}'>";
         echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
         if ($item->isRecursive()) {
             self::dropdownConnect('Computer', $item->getType(), "computers_id", getSonsOf("glpi_entities", $item->getEntityID()), 0, $used);
         } else {
             self::dropdownConnect('Computer', $item->getType(), "computers_id", $item->getEntityID(), 0, $used);
         }
         echo "</td><td class='center'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Connect') . "\" class='submit'>";
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $number) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('num_displayed' => $number, 'specific_actions' => array('purge' => _x('button', 'Disconnect')), 'container' => 'mass' . __CLASS__ . $rand);
         Html::showMassiveActions($massiveactionparams);
     }
     echo "<table class='tab_cadre_fixehov'>";
     if ($number > 0) {
         $header_begin = "<tr>";
         $header_top = '';
         $header_bottom = '';
         $header_end = '';
         if ($canedit) {
             $header_top .= "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
             $header_top .= "</th>";
             $header_bottom .= "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
             $header_bottom .= "</th>";
         }
         $header_end .= "<th>" . __('Name') . "</th>";
         if (Plugin::haveImport()) {
             $header_end .= "<th>" . __('Automatic inventory') . "</th>";
         }
         $header_end .= "<th>" . __('Entity') . "</th>";
         $header_end .= "<th>" . __('Serial number') . "</th>";
         $header_end .= "<th>" . __('Inventory number') . "</th>";
         $header_end .= "</tr>";
         echo $header_begin . $header_top . $header_end;
         foreach ($compids as $key => $compid) {
             $comp->getFromDB($compid);
             echo "<tr class='tab_bg_1'>";
             if ($canedit) {
                 echo "<td width='10'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $key);
                 echo "</td>";
             }
             echo "<td " . ($comp->getField('is_deleted') ? "class='tab_bg_2_2'" : "") . ">" . $comp->getLink() . "</td>";
             if (Plugin::haveImport()) {
                 echo "<td>" . Dropdown::getYesNo($dynamic[$key]) . "</td>";
             }
             echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $comp->getField('entities_id'));
             echo "</td>";
             echo "<td class='center'>" . $comp->getField('serial') . "</td>";
             echo "<td class='center'>" . $comp->getField('otherserial') . "</td>";
             echo "</tr>";
         }
         echo $header_begin . $header_bottom . $header_end;
     } else {
         echo "<tr><td class='tab_bg_1 b'><i>" . __('Not connected') . "</i>";
         echo "</td></tr>";
     }
     echo "</table>";
     if ($canedit && $number) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
Exemplo n.º 10
0
 /**
  * Show routetables associated to an item
  *
  * @since version 0.84
  *
  * @param $item            CommonDBTM object for which associated routetables 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_routetables_haveRight('routetables', 'r')) {
         return false;
     }
     if (!$item->can($item->fields['id'], 'r')) {
         return false;
     }
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     $canedit = $item->canadditem('PluginRoutetablesRoutetable');
     $rand = mt_rand();
     $is_recursive = $item->isRecursive();
     $query = "SELECT `glpi_plugin_routetables_routetables_items`.`id` AS assocID,\n                       `glpi_entities`.`id` AS entity,\n                       `glpi_plugin_routetables_routetables`.`name` AS assocName,\n                       `glpi_plugin_routetables_routetables`.*\n                FROM `glpi_plugin_routetables_routetables_items`\n                LEFT JOIN `glpi_plugin_routetables_routetables`\n                 ON (`glpi_plugin_routetables_routetables_items`.`plugin_routetables_routetables_id`=`glpi_plugin_routetables_routetables`.`id`)\n                LEFT JOIN `glpi_entities` ON (`glpi_plugin_routetables_routetables`.`entities_id`=`glpi_entities`.`id`)\n                WHERE `glpi_plugin_routetables_routetables_items`.`items_id` = '{$ID}'\n                      AND `glpi_plugin_routetables_routetables_items`.`itemtype` = '" . $item->getType() . "' ";
     $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_routetables_routetables", '', '', false);
     $query .= " ORDER BY `assocName`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     $routetables = array();
     $routetable = new PluginRoutetablesRoutetable();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $routetables[$data['id']] = $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_routetables_routetables", '', $entities, false);
         $q = "SELECT COUNT(*)\n               FROM `glpi_plugin_routetables_routetables`\n               WHERE `is_deleted` = '0'\n               {$limit}";
         $result = $DB->query($q);
         $nb = $DB->result($result, 0, 0);
         echo "<div class='firstbloc'>";
         if (plugin_routetables_haveRight('routetables', 'r') && $nb > count($used)) {
             echo "<form name='routetable_form{$rand}' id='routetable_form{$rand}' method='post'\n                   action='" . Toolbox::getItemTypeFormURL('PluginRoutetablesRoutetable') . "'>";
             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}'>";
             }
             $routetable->dropdownRouteTables("plugin_routetables_routetables_id", $entities, $used);
             echo "</td><td class='center' width='20%'>";
             echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Associate a routing table', 'routetables') . "\" 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>" . __('Network') . "</th>";
     echo "<th>" . __('Subnet mask') . "</th>";
     echo "<th>" . __('Gateway') . "</th>";
     echo "<th>" . __('Metric', 'routetables') . "</th>";
     echo "<th>" . __('Interface') . "</th>";
     echo "<th>" . __('Persistance', 'routetables') . "</th>";
     echo "<th>" . __('Comments') . "</th>";
     echo "</tr>";
     $used = array();
     if ($number) {
         Session::initNavigateListItems('PluginRoutetablesRoutetable', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         foreach ($routetables as $data) {
             $routetableID = $data["id"];
             $link = NOT_AVAILABLE;
             if ($routetable->getFromDB($routetableID)) {
                 $link = $routetable->getLink();
             }
             Session::addToNavigateListItems('PluginRoutetablesRoutetable', $routetable);
             $used[$routetableID] = $routetableID;
             $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["destination"] . "</td>";
             echo "<td class='center'>" . $data["netmask"] . "</td>";
             echo "<td class='center'>" . $data["gateway"] . "</td>";
             echo "<td class='center'>" . $data["metric"] . "</td>";
             echo "<td class='center'>" . $data["interface"] . "</td>";
             echo "<td class='center'>" . Dropdown::getYesNo($data["persistence"]) . "</td>";
             echo "<td class='center'>" . $data["comment"] . "</td>";
             echo "</tr>";
             $i++;
         }
     }
     echo "</table>";
     if ($canedit && $number && $withtemplate < 2) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
Exemplo n.º 11
0
 /**
  * Is the object recursive
  *
  * @return boolean
  **/
 function isRecursive()
 {
     // Case of Duplicate Entity info to child
     if (parent::maybeRecursive()) {
         return parent::isRecursive();
     }
     if (preg_match('/^itemtype/', $this->itemtype)) {
         $type = $this->fields[$this->itemtype];
     } else {
         $type = $this->itemtype;
     }
     if (class_exists($type)) {
         $item = new $type();
         if ($item->getFromDB($this->fields[$this->items_id])) {
             return $item->isRecursive();
         }
     }
     return false;
 }
Exemplo n.º 12
0
 /**
  * Prints a direct connection to a computer
  *
  * @param $item the Monitor/Phone/Peripheral/Printer
  *
  * @return nothing (print out a table)
  */
 static function showForItem(CommonDBTM $item)
 {
     // Prints a direct connection to a computer
     global $DB, $LANG;
     $comp = new Computer();
     $target = $comp->getFormURL();
     $ID = $item->getField('id');
     if (!$item->can($ID, "r")) {
         return false;
     }
     $canedit = $item->can($ID, "w");
     // Is global connection ?
     $global = $item->getField('is_global');
     $used = array();
     $compids = array();
     $crit = array('FIELDS' => array('id', 'computers_id'), 'itemtype' => $item->getType(), 'items_id' => $ID);
     foreach ($DB->request('glpi_computers_items', $crit) as $data) {
         $compids[$data['id']] = $data['computers_id'];
     }
     echo "<div class='spaced'><table width='50%' class='tab_cadre_fixe'>";
     echo "<tr><th colspan='2'>";
     if (count($compids) == 0) {
         echo $LANG['connect'][4];
     } else {
         if (count($compids) == 1) {
             echo $LANG['connect'][3] . "&nbsp;:&nbsp;" . count($compids);
         } else {
             echo $LANG['connect'][2] . "&nbsp;:&nbsp;" . count($compids);
         }
     }
     echo "</th></tr>";
     if (count($compids) > 0) {
         foreach ($compids as $key => $compid) {
             $comp->getFromDB($compid);
             echo "<tr><td class='b tab_bg_1" . ($comp->getField('is_deleted') ? "_2" : "") . "'>";
             echo $LANG['help'][25] . "&nbsp;:&nbsp;" . $comp->getLink() . "</td>";
             echo "<td class='tab_bg_2" . ($comp->getField('is_deleted') ? "_2" : "") . " center b'>";
             if ($canedit) {
                 echo "<a href=\"{$target}?disconnect=1&amp;computers_id={$compid}&amp;id={$key}\">" . $LANG['buttons'][10] . "</a>";
             } else {
                 echo "&nbsp;";
             }
             $used[] = $compid;
         }
     } else {
         echo "<tr><td class='tab_bg_1 b'>" . $LANG['help'][25] . "&nbsp;:&nbsp;";
         echo "<i>" . $LANG['connect'][1] . "</i></td>";
         echo "<td class='tab_bg_2' class='center'>";
         if ($canedit) {
             echo "<form method='post' action=\"{$target}\">";
             echo "<input type='hidden' name='items_id' value='{$ID}'>";
             echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
             if ($item->isRecursive()) {
                 self::dropdownConnect('Computer', $item->getType(), "computers_id", getSonsOf("glpi_entities", $item->getEntityID()), 0, $used);
             } else {
                 self::dropdownConnect('Computer', $item->getType(), "computers_id", $item->getEntityID(), 0, $used);
             }
             echo "<input type='submit' name='connect' value=\"" . $LANG['buttons'][9] . "\"\n                   class='submit'>";
             echo "</form>";
         } else {
             echo "&nbsp;";
         }
     }
     if ($global && count($compids) > 0) {
         echo "</td></tr>";
         echo "<tr><td class='tab_bg_1'>&nbsp;</td>";
         echo "<td class='tab_bg_2' class='center'>";
         if ($canedit) {
             echo "<form method='post' action=\"{$target}\">";
             echo "<input type='hidden' name='items_id' value='{$ID}'>";
             echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
             if ($item->isRecursive()) {
                 self::dropdownConnect('Computer', $item->getType(), "computers_id", getSonsOf("glpi_entities", $item->getEntityID()), 0, $used);
             } else {
                 self::dropdownConnect('Computer', $item->getType(), "computers_id", $item->getEntityID(), 0, $used);
             }
             echo "<input type='submit' name='connect' value=\"" . $LANG['buttons'][9] . "\"\n                   class='submit'>";
             echo "</form>";
         } else {
             echo "&nbsp;";
         }
     }
     echo "</td></tr>";
     echo "</table></div>";
 }
Exemplo n.º 13
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>";
 }
Exemplo n.º 14
0
 /**
  * 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>";
 }
Exemplo n.º 15
0
 /**
  * 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>";
 }
Exemplo n.º 16
0
 /**
  * Show projet associated to an item
  *
  * @since version 0.84
  *
  * @param $item            CommonDBTM object for which associated projet 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_projet_haveRight('projet', 'r')) {
         return false;
     }
     if (!$item->can($item->fields['id'], 'r')) {
         return false;
     }
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     $canedit = $item->canadditem('PluginProjetProjet');
     $rand = mt_rand();
     $is_recursive = $item->isRecursive();
     $query = "SELECT `glpi_plugin_projet_projets_items`.`id` AS assocID,\n                       `glpi_entities`.`id` AS entity,\n                       `glpi_plugin_projet_projets`.`name` AS assocName,\n                       `glpi_plugin_projet_projets`.*\n                FROM `glpi_plugin_projet_projets_items`\n                LEFT JOIN `glpi_plugin_projet_projets`\n                 ON (`glpi_plugin_projet_projets_items`.`plugin_projet_projets_id`=`glpi_plugin_projet_projets`.`id`)\n                LEFT JOIN `glpi_entities` ON (`glpi_plugin_projet_projets`.`entities_id`=`glpi_entities`.`id`)\n                WHERE `glpi_plugin_projet_projets_items`.`items_id` = '{$ID}'\n                      AND `glpi_plugin_projet_projets_items`.`itemtype` = '" . $item->getType() . "' ";
     $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_projet_projets", '', '', true);
     $query .= " ORDER BY `assocName`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     $projets = array();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $projets[$data['assocID']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     $projet = new PluginProjetProjet();
     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_projet_projets", '', $entities, true);
         $q = "SELECT COUNT(*)\n               FROM `glpi_plugin_projet_projets`\n               WHERE `is_deleted` = '0'\n               AND `is_template` = '0' ";
         if ($item->getType() != 'User') {
             $q .= " {$limit}";
         }
         $result = $DB->query($q);
         $nb = $DB->result($result, 0, 0);
         echo "<div class='firstbloc'>";
         if (plugin_projet_haveRight('projet', 'r') && $nb > count($used)) {
             echo "<form name='projet_form{$rand}' id='projet_form{$rand}' method='post'\n                   action='" . Toolbox::getItemTypeFormURL('PluginProjetProjet') . "'>";
             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}'>";
             }
             if ($item->getType() != 'User') {
                 $projet->dropdownProjet("plugin_projet_projets_id", $entities, $used);
             } else {
                 $strict_entities = Profile_User::getUserEntities($ID, true);
                 if (!Session::haveAccessToOneOfEntities($strict_entities) && !isViewAllEntities()) {
                     $canedit = false;
                 }
                 if (countElementsInTableForEntity("glpi_plugin_projet_projets", $strict_entities) > count($used)) {
                     Dropdown::show('PluginProjetProjet', array('name' => "plugin_projet_projets_id", 'used' => $used, 'entity' => $strict_entities));
                 }
             }
             echo "</td><td class='center' width='20%'>";
             echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Associate a project', 'projet') . "\" 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;
     }
     if ($item->getType() == "Group" || $item->getType() == "User") {
         echo "<tr><th colspan='" . (7 + $colsup) . "'>" . _n('Associated project', 'Associated projects', 2, 'projet') . ":</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>" . __('Description') . "</th>";
     echo "<th>" . __('Progress') . "</th>";
     echo "<th>" . __('Start date') . "</th>";
     echo "<th>" . __('End date') . "</th>";
     echo "</tr>";
     $used = array();
     if ($number) {
         Session::initNavigateListItems('PluginProjetProjet', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         foreach ($projets as $data) {
             $projetID = $data["id"];
             $link = NOT_AVAILABLE;
             if ($projet->getFromDB($projetID)) {
                 $link = $projet->getLink();
             }
             Session::addToNavigateListItems('PluginProjetProjet', $projetID);
             $used[$projetID] = $projetID;
             $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 align='center'>" . Html::resume_text($data["description"], 250) . "</td>";
             echo "<td align='center'>" . PluginProjetProjet::displayProgressBar('100', $data["advance"]) . "</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'><span class='red'>" . Html::convdate($data["date_end"]) . "</span></td>";
             } else {
                 echo "<td class='center'><span class='green'>" . Html::convdate($data["date_end"]) . "</span></td>";
             }
             echo "</tr>";
             $i++;
         }
     }
     echo "</table>";
     if ($canedit && $number && $withtemplate < 2) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }