当前位置: 首页>>代码示例>>PHP>>正文


PHP CommonDBTM::canCreate方法代码示例

本文整理汇总了PHP中CommonDBTM::canCreate方法的典型用法代码示例。如果您正苦于以下问题:PHP CommonDBTM::canCreate方法的具体用法?PHP CommonDBTM::canCreate怎么用?PHP CommonDBTM::canCreate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CommonDBTM的用法示例。


在下文中一共展示了CommonDBTM::canCreate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: showForItem

 /**
  * Display form to unlock fields and links
  *
  * @param CommonDBTM $item the source item
  **/
 static function showForItem(CommonDBTM $item)
 {
     global $DB;
     $ID = $item->getID();
     $itemtype = $item->getType();
     $header = false;
     //If user doesn't have write right on the item, lock form must not be displayed
     if (!$item->canCreate()) {
         return false;
     }
     echo "<div width='50%'>";
     echo "<form method='post' id='lock_form'\n             name='lock_form' action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
     echo "<input type='hidden' name='id' value='{$ID}'>\n";
     echo "<input type='hidden' name='itemtype' value='{$itemtype}'>\n";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr><th colspan='2''>" . __('Locked items') . "</th></tr>";
     //Use a hook to allow external inventory tools to manage per field lock
     $results = Plugin::doHookFunction('display_locked_fields', array('item' => $item, 'header' => $header));
     $header |= $results['header'];
     //Special locks for computers only
     if ($itemtype == 'Computer') {
         //Locks for items recorded in glpi_computers_items table
         $types = array('Monitor', 'Peripheral', 'Printer');
         foreach ($types as $type) {
             $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID, 'itemtype' => $type);
             $params['FIELDS'] = array('id', 'items_id');
             $first = true;
             foreach ($DB->request('glpi_computers_items', $params) as $line) {
                 $tmp = new $type();
                 $tmp->getFromDB($line['items_id']);
                 $header = true;
                 if ($first) {
                     echo "<tr><th colspan='2'>" . $type::getTypeName(2) . "</th></tr>\n";
                     $first = false;
                 }
                 echo "<tr class='tab_bg_1'><td class='center' width='10'>";
                 echo "<input type='checkbox' name='Computer_Item[" . $line['id'] . "]'></td>";
                 echo "<td class='left' width='95%'>" . $tmp->getName() . "</td>";
                 echo "</tr>\n";
             }
         }
         $types = array('ComputerDisk', 'ComputerVirtualMachine');
         foreach ($types as $type) {
             $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID);
             $params['FIELDS'] = array('id', 'name');
             $first = true;
             foreach ($DB->request(getTableForItemType($type), $params) as $line) {
                 $header = true;
                 if ($first) {
                     echo "<tr><th colspan='2'>" . $type::getTypeName(2) . "</th></tr>\n";
                     $first = false;
                 }
                 echo "<tr class='tab_bg_1'><td class='center' width='10'>";
                 echo "<input type='checkbox' name='" . $type . "[" . $line['id'] . "]'></td>";
                 echo "<td class='left' width='95%'>" . $line['name'] . "</td>";
                 echo "</tr>\n";
             }
         }
         //Software versions
         $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID);
         $first = true;
         $query = "SELECT `csv`.`id` AS `id`,\n                           `sv`.`name` AS `version`,\n                           `s`.`name` AS `software`\n                    FROM `glpi_computers_softwareversions` AS csv\n                    LEFT JOIN `glpi_softwareversions` AS sv\n                       ON (`csv`.`softwareversions_id` = `sv`.`id`)\n                    LEFT JOIN `glpi_softwares` AS s\n                       ON (`sv`.`softwares_id` = `s`.`id`)\n                    WHERE `csv`.`is_deleted` = '1'\n                          AND `csv`.`is_dynamic` = '1'\n                          AND `csv`.`computers_id` = '{$ID}'";
         foreach ($DB->request($query) as $line) {
             $header = true;
             if ($first) {
                 echo "<tr><th colspan='2'>" . Software::getTypeName(2) . "</th></tr>\n";
                 $first = false;
             }
             echo "<tr class='tab_bg_1'><td class='center' width='10'>";
             echo "<input type='checkbox' name='Computer_SoftwareVersion[" . $line['id'] . "]'></td>";
             echo "<td class='left' width='95%'>" . $line['software'] . " " . $line['version'] . "</td>";
             echo "</tr>\n";
         }
         //Software licenses
         $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'computers_id' => $ID);
         $first = true;
         $query = "SELECT `csv`.`id` AS `id`,\n                           `sv`.`name` AS `version`,\n                           `s`.`name` AS `software`\n                    FROM `glpi_computers_softwarelicenses` AS csv\n                    LEFT JOIN `glpi_softwarelicenses` AS sv\n                       ON (`csv`.`softwarelicenses_id` = `sv`.`id`)\n                    LEFT JOIN `glpi_softwares` AS s\n                       ON (`sv`.`softwares_id` = `s`.`id`)\n                    WHERE `csv`.`is_deleted` = '1'\n                          AND `csv`.`is_dynamic` = '1'\n                          AND `csv`.`computers_id` = '{$ID}'";
         foreach ($DB->request($query) as $line) {
             $header = true;
             if ($first) {
                 echo "<tr><th colspan='2'>" . SoftwareLicense::getTypeName(2) . "</th>" . "</tr>\n";
                 $first = false;
             }
             echo "<tr class='tab_bg_1'><td class='center' width='10'>";
             echo "<input type='checkbox' name='Computer_SoftwareLicense[" . $line['id'] . "]'></td>";
             echo "<td class='left' width='95%'>" . $line['software'] . " " . $line['version'] . "</td>";
             echo "</tr>\n";
         }
     }
     $first = true;
     $item = new NetworkPort();
     $params = array('is_dynamic' => 1, 'is_deleted' => 1, 'items_id' => $ID, 'itemtype' => $itemtype);
     $params['FIELDS'] = array('id');
     foreach ($DB->request('glpi_networkports', $params) as $line) {
         $item->getFromDB($line['id']);
//.........这里部分代码省略.........
开发者ID:geldarr,项目名称:hack-space,代码行数:101,代码来源:lock.class.php

示例2: showChildsForItemForm

 /**
  * We can add several single CommonDBChild to a given Item. In such case, we display a "+"
  * button and the fields already entered.
  * This method display the fields
  *
  * @since version 0.84
  *
  * @todo study if we cannot use these methods for the user emails
  * @see showAddChildButtonForItemForm()
  *
  * @param $item         CommonDBTM object the item on which to add the current CommenDBChild
  * @param $field_name   the name of the HTML field inside Item's form
  * @param $canedit      (default NULL) NULL to use default behaviour
  *
  * @return nothing (display only)
  **/
 static function showChildsForItemForm(CommonDBTM $item, $field_name, $canedit = NULL)
 {
     global $DB, $CFG_GLPI;
     $items_id = $item->getID();
     if (is_null($canedit)) {
         if ($item->isNewItem()) {
             if (!$item->canCreate()) {
                 return false;
             }
             $canedit = $item->canUpdate();
         } else {
             if (!$item->can($items_id, 'r')) {
                 return false;
             }
             $canedit = $item->can($items_id, "w");
         }
     }
     $lower_name = strtolower(get_called_class());
     $div_id = "add_" . $lower_name . "_to_" . $item->getType() . "_" . $items_id;
     // To be sure not to load bad datas from this table
     if ($items_id == 0) {
         $items_id = -99;
     }
     $query = "SELECT *\n                FROM `" . static::getTable() . "`\n                WHERE `" . static::$items_id . "` = '" . $item->getID() . "'";
     if (preg_match('/^itemtype/', static::$itemtype)) {
         $query .= " AND `itemtype` = '" . $item->getType() . "'";
     }
     $current_item = new static();
     if ($current_item->maybeDeleted()) {
         $query .= " AND `is_deleted` = '0'";
     }
     $count = 0;
     foreach ($DB->request($query) as $data) {
         $current_item->fields = $data;
         if ($count) {
             echo '<br>';
         }
         $count++;
         $current_item->showChildForItemForm($canedit, $field_name . "[" . $current_item->getID() . "]");
     }
     if ($canedit) {
         echo "<div id='{$div_id}'>";
         // No Child display field
         if ($count == 0) {
             $current_item->getEmpty();
             $current_item->showChildForItemForm($canedit, $field_name . "[-100]");
         }
         echo "</div>";
     }
 }
开发者ID:geldarr,项目名称:hack-space,代码行数:66,代码来源:commondbchild.class.php


注:本文中的CommonDBTM::canCreate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。