/**
    * Show items links to a certificate
    *
    * @since version 0.84
    *
    * @param $certificate PluginCertificatesCertificate object
    *
    * @return nothing (HTML display)
    **/
   public static function showForCertificate(PluginCertificatesCertificate $certificate) {
      global $DB,$CFG_GLPI;
      
//      $certif=new PluginCertificatesCertificate();

      $instID = $certificate->fields['id'];
      if (!$certificate->can($instID, READ)){
         return false;
      }
      $canedit=$certificate->can($instID, UPDATE);
      $rand=mt_rand();

      $query = "SELECT DISTINCT `itemtype`
            FROM `glpi_plugin_certificates_certificates_items`
            WHERE `plugin_certificates_certificates_id` = '".$instID."'
            ORDER BY `itemtype`
            LIMIT ".count(PluginCertificatesCertificate::getTypes(true));

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

      if (Session::isMultiEntitiesMode()) {
         $colsup=1;
      } else {
         $colsup=0;
      }

      if ($canedit) {
         echo "<div class='firstbloc'>";
         echo "<form method='post' name='certificates_form$rand'
         id='certificates_form$rand'  action='".Toolbox::getItemTypeFormURL("PluginCertificatesCertificate")."'>";

         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_2'><th colspan='".($canedit?(5+$colsup):(4+$colsup))."'>".
            __('Add an item')."</th></tr>";

         echo "<tr class='tab_bg_1'><td colspan='".(3+$colsup)."' class='center'>";
         Dropdown::showAllItems("items_id",0,0,($certificate->fields['is_recursive']?-1:$certificate->fields['entities_id']),
            PluginCertificatesCertificate::getTypes());
         echo "</td><td colspan='2' class='center' class='tab_bg_1'>";
         echo "<input type='hidden' name='plugin_certificates_certificates_id' value='$instID'>";
         echo "<input type='submit' name='additem' value=\""._sx('button','Add')."\" 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();
         Html::showMassiveActions($massiveactionparams);
      }
      echo "<table class='tab_cadre_fixe'>";
      echo "<tr>";

      if ($canedit && $number) {
         echo "<th width='10'>".Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand)."</th>";
      }

      echo "<th>".__('Type')."</th>";
      echo "<th>".__('Name')."</th>";
      if (Session::isMultiEntitiesMode())
         echo "<th>".__('Entity')."</th>";
      echo "<th>".__('Serial number')."</th>";
      echo "<th>".__('Inventory number')."</th>";
      echo "</tr>";

      for ($i=0 ; $i < $number ; $i++) {
         $itemtype=$DB->result($result, $i, "itemtype");

         if (!($item = getItemForItemtype($itemtype))) {
            continue;
         }

         if ($item->canView()) {
            $column="name";

            $itemTable = getTableForItemType($itemtype);
            $query = " SELECT `".$itemTable."`.*,
                              `glpi_plugin_certificates_certificates_items`.`id` AS items_id,
                              `glpi_entities`.id AS entity "
                     ." FROM `glpi_plugin_certificates_certificates_items`, `".$itemTable
                     ."` LEFT JOIN `glpi_entities`
                     ON (`glpi_entities`.`id` = `".$itemTable."`.`entities_id`) "
                     ." WHERE `".$itemTable."`.`id` = `glpi_plugin_certificates_certificates_items`.`items_id`
                     AND `glpi_plugin_certificates_certificates_items`.`itemtype` = '$itemtype'
                     AND `glpi_plugin_certificates_certificates_items`.`plugin_certificates_certificates_id` = '$instID' "
                     . getEntitiesRestrictRequest(" AND ",$itemTable,'','',$item->maybeRecursive());

            if ($item->maybeTemplate()) {
               $query.=" AND ".$itemTable.".is_template='0'";
            }

            $query.=" ORDER BY `glpi_entities`.`completename`, `".$itemTable."`.`$column` ";

            if ($result_linked=$DB->query($query)){
               if ($DB->numrows($result_linked)) {

                  Session::initNavigateListItems($itemtype,PluginCertificatesCertificate::getTypeName(2)." = ".$certificate->fields['name']);

                  while ($data=$DB->fetch_assoc($result_linked)) {

                     $item->getFromDB($data["id"]);

                     Session::addToNavigateListItems($itemtype,$data["id"]);

                     $ID="";

                     if ($_SESSION["glpiis_ids_visible"]||empty($data["name"]))
                        $ID= " (".$data["id"].")";

                     $link=Toolbox::getItemTypeFormURL($itemtype);
                     $name= "<a href=\"".$link."?id=".$data["id"]."\">"
                        .$data["name"]."$ID</a>";

                     echo "<tr class='tab_bg_1'>";

                     if ($canedit) {
                        echo "<td width='10'>";
                        Html::showMassiveActionCheckBox(__CLASS__, $data["items_id"]);
                        echo "</td>";
                     }
                     echo "<td class='center'>".$item->getTypeName(1)."</td>";

                     echo "<td class='center' ".(isset($data['is_deleted'])&&$data['is_deleted']?"class='tab_bg_2_2'":"").
                        ">".$name."</td>";
                     if (Session::isMultiEntitiesMode())
                        echo "<td class='center'>".Dropdown::getDropdownName("glpi_entities",$data['entity'])."</td>";
                     echo "<td class='center'>".(isset($data["serial"])? "".$data["serial"]."" :"-")."</td>";
                     echo "<td class='center'>".(isset($data["otherserial"])? "".$data["otherserial"]."" :"-")."</td>";

                     echo "</tr>";
                  }
               }
            }
         }
      }
      echo "</table>";

      if ($canedit && $number) {
         $paramsma['ontop'] =false;
         Html::showMassiveActions($paramsma);
         Html::closeForm();
      }
      echo "</div>";

   }