• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP getAncestorsOf函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中getAncestorsOf函数的典型用法代码示例。如果您正苦于以下问题:PHP getAncestorsOf函数的具体用法?PHP getAncestorsOf怎么用?PHP getAncestorsOf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: testSonsAncestors

 /**
  * @covers ::getSonsOf
  * @covers ::getAncestorsOf
  */
 public function testSonsAncestors()
 {
     $ent0 = getItemByTypeName('Entity', '_test_root_entity');
     $this->assertEquals('Root entity > _test_root_entity', $ent0->getField('completename'));
     $ent1 = getItemByTypeName('Entity', '_test_child_1');
     $this->assertEquals('Root entity > _test_root_entity > _test_child_1', $ent1->getField('completename'));
     $ent2 = getItemByTypeName('Entity', '_test_child_2');
     $this->assertEquals('Root entity > _test_root_entity > _test_child_2', $ent2->getField('completename'));
     $this->assertEquals([0], array_keys(getAncestorsOf('glpi_entities', $ent0->getID())));
     $this->assertEquals([0], array_values(getAncestorsOf('glpi_entities', $ent0->getID())));
     $this->assertEquals([$ent0->getID(), $ent1->getID(), $ent2->getID()], array_keys(getSonsOf('glpi_entities', $ent0->getID())));
     $this->assertEquals([$ent0->getID(), $ent1->getID(), $ent2->getID()], array_values(getSonsOf('glpi_entities', $ent0->getID())));
     $this->assertEquals([0, $ent0->getID()], array_keys(getAncestorsOf('glpi_entities', $ent1->getID())));
     $this->assertEquals([0, $ent0->getID()], array_values(getAncestorsOf('glpi_entities', $ent1->getID())));
     $this->assertEquals([$ent1->getID()], array_keys(getSonsOf('glpi_entities', $ent1->getID())));
     $this->assertEquals([$ent1->getID()], array_values(getSonsOf('glpi_entities', $ent1->getID())));
     $this->assertEquals([0, $ent0->getID()], array_keys(getAncestorsOf('glpi_entities', $ent2->getID())));
     $this->assertEquals([0, $ent0->getID()], array_values(getAncestorsOf('glpi_entities', $ent2->getID())));
     $this->assertEquals([$ent2->getID()], array_keys(getSonsOf('glpi_entities', $ent2->getID())));
     $this->assertEquals([$ent2->getID()], array_values(getSonsOf('glpi_entities', $ent2->getID())));
 }
开发者ID:btry,项目名称:glpi,代码行数:25,代码来源:EntityTest.php


示例2: showMyView

 /**
  * Show the central personal view
  *
  *
  **/
 static function showMyView()
 {
     global $LANG, $DB;
     $showticket = haveRight("show_all_ticket", "1") || haveRight("show_assign_ticket", "1");
     echo "<table class='tab_cadre_central'>";
     if ($DB->isSlave() && !$DB->first_connection) {
         echo "<tr><th colspan='2'><br>";
         displayTitle(GLPI_ROOT . "/pics/warning.png", $LANG['setup'][809], $LANG['setup'][809]);
         echo "</th></tr>";
     }
     echo "<tr><td class='top'><table>";
     if (haveRight('validate_ticket', 1)) {
         echo "<tr><td class='top' width='450px'><br>";
         Ticket::showCentralList(0, "tovalidate", false);
         echo "</td></tr>";
     }
     echo "<tr><td class='top' width='450px'>";
     Ticket::showCentralList(0, "toapprove", false);
     echo "</td></tr>";
     echo "<tr><td class='top' width='450px'>";
     Ticket::showCentralList(0, "requestbyself", false);
     echo "</td></tr>";
     if ($showticket) {
         echo "<tr><td class='top' width='450px'>";
         Ticket::showCentralList(0, "process", false);
         echo "</td></tr>";
         echo "<tr><td class='top' width='450px'>";
         Ticket::showCentralList(0, "waiting", false);
         echo "</td></tr>";
     }
     echo "</table></td>";
     echo "<td class='top'><table><tr>";
     echo "<td class='top' width='450px'><br>";
     Planning::showCentral(getLoginUserID());
     echo "</td></tr>";
     echo "<tr><td class='top' width='450px'>";
     Reminder::showListForCentral();
     echo "</td></tr>";
     if (haveRight("reminder_public", "r")) {
         echo "<tr><td class='top' width='450px'>";
         Reminder::showListForCentral($_SESSION["glpiactive_entity"]);
         $entities = array_reverse(getAncestorsOf("glpi_entities", $_SESSION["glpiactive_entity"]));
         foreach ($entities as $entity) {
             Reminder::showListForCentral($entity, true);
         }
         foreach ($_SESSION["glpiactiveentities"] as $entity) {
             if ($entity != $_SESSION["glpiactive_entity"]) {
                 Reminder::showListForCentral($entity, false);
             }
         }
         echo "</td></tr>";
     }
     echo "</table></td></tr></table>";
 }
开发者ID:ryukansent,项目名称:Thesis-SideB,代码行数:59,代码来源:central.class.php


示例3: copySingleSoftware

 /**
  * Copy (if needed) One software to the destination entity
  *
  * @param $ID of the software
  *
  * @return $ID of the new software (could be the same)
  **/
 function copySingleSoftware($ID)
 {
     global $DB;
     if (isset($this->already_transfer['Software'][$ID])) {
         return $this->already_transfer['Software'][$ID];
     }
     $soft = new Software();
     if ($soft->getFromDB($ID)) {
         if ($soft->fields['is_recursive'] && in_array($soft->fields['entities_id'], getAncestorsOf("glpi_entities", $this->to))) {
             // no need to copy
             $newsoftID = $ID;
         } else {
             $query = "SELECT *\n                      FROM `glpi_softwares`\n                      WHERE `entities_id` = " . $this->to . "\n                            AND `name` = '" . addslashes($soft->fields['name']) . "'";
             if ($data = $DB->request($query)->next()) {
                 $newsoftID = $data["id"];
             } else {
                 // create new item (don't check if move possible => clean needed)
                 unset($soft->fields['id']);
                 $input = $soft->fields;
                 $input['entities_id'] = $this->to;
                 unset($soft->fields);
                 $newsoftID = $soft->add($input);
             }
         }
         $this->addToAlreadyTransfer('Software', $ID, $newsoftID);
         return $newsoftID;
     }
     return -1;
 }
开发者ID:ryukansent,项目名称:Thesis-SideB,代码行数:36,代码来源:transfer.class.php


示例4: testTree

   /**
    * sons / ancestors for CommonTreeDropdown
    */
   public function testTree() {

      $entity = $this->sharedFixture['entity'][0];
      $loc = new Location();

      // A
      $id[0] = $loc->add(array('entities_id'  => $entity,
                               'locations_id' => 0,
                               'name'         => 'A'));
      $this->assertGreaterThan(0, $id[0]);

      // A > AA
      $id[1] = $loc->add(array('entities_id'  => $entity,
                               'locations_id' => $id[0],
                               'name'         => 'AA'));
      $this->assertGreaterThan(0, $id[1]);
      $this->assertTrue($loc->getFromDB($id[1]));
      $this->assertEquals('A > AA', $loc->fields['completename']);

      // A > BB
      $id[2] = $loc->add(array('entities_id'  => $entity,
                               'locations_id' => $id[0],
                               'name'         => 'BB'));
      $this->assertGreaterThan(0, $id[2]);
      $this->assertTrue($loc->getFromDB($id[2]));
      $this->assertEquals('A > BB', $loc->fields['completename']);

      // Sons of A (A, AA, BB)
      $sons = getSonsOf('glpi_locations',$id[0]);
      $this->assertEquals(3, count($sons));
      $this->assertArrayHasKey($id[0], $sons);
      $this->assertArrayHasKey($id[1], $sons);
      $this->assertArrayHasKey($id[2], $sons);

      // Ancestors of A (none)
      $parent = getAncestorsOf('glpi_locations', $id[0]);
      $this->assertEquals(0, count($parent));

      // Ancestors of AA (A)
      $parent = getAncestorsOf('glpi_locations', $id[1]);
      $this->assertEquals(1, count($parent));
      $this->assertArrayHasKey($id[0], $parent);

      // Ancestors of BB (none)
      $parent = getAncestorsOf('glpi_locations', $id[2]);
      $this->assertEquals(1, count($parent));
      $this->assertArrayHasKey($id[0], $parent);

      // B
      $id[3] = $loc->add(array('entities_id'  => $entity,
                               'locations_id' => 0,
                               'name'         => 'B'));
      $this->assertGreaterThan(0, $id[3]);

      // B > CC
      $id[4] = $loc->add(array('entities_id'  => $entity,
                               'locations_id' => $id[3],
                               'name'         => 'CC'));
      $this->assertGreaterThan(0, $id[4]);
      $this->assertTrue($loc->getFromDB($id[4]));
      $this->assertEquals('B > CC', $loc->fields['completename']);

      $sons = getSonsOf('glpi_locations',$id[3]);
      $this->assertEquals(2, count($sons));
      $this->assertArrayHasKey($id[4], $sons);

      // B > CC > XXX
      $id[5] = $loc->add(array('entities_id'  => $entity,
                               'locations_id' => $id[4],
                               'name'         => 'XXX'));
      $this->assertGreaterThan(0, $id[5]);
      $this->assertTrue($loc->getFromDB($id[5]));
      $this->assertEquals('B > CC > XXX', $loc->fields['completename']);

      // B > CC => A > CC
      $res = $loc->update(array('id'           => $id[4],
                                'locations_id' => $id[0]));
      $this->assertTrue($res);
      $this->assertTrue($loc->getFromDB($id[4]));
      $this->assertEquals('A > CC', $loc->fields['completename']);

      // B > CC > XXX => A > CC > XXX
      $this->assertTrue($loc->getFromDB($id[5]));
      $this->assertEquals('A > CC > XXX', $loc->fields['completename']);

      // New parent of CC (A)
      $parent = getAncestorsOf('glpi_locations', $id[4]);
      $this->assertEquals(1, count($parent));
      $this->assertArrayHasKey($id[0], $parent);

      // New sons of B (only B)
      $sons = getSonsOf('glpi_locations',$id[3]);
      $this->assertEquals(1, count($sons));
      $this->assertArrayHasKey($id[3], $sons);

      // New sons of A (A, AA, BB, CC)
      $sons = getSonsOf('glpi_locations',$id[0]);
//.........这里部分代码省略.........
开发者ID:KaneoGmbH,项目名称:glpi,代码行数:101,代码来源:TreeCache.php


示例5: dropdownMyDevices

 /**
  * Make a select box for Ticket my devices
  *
  * @param $userID          User ID for my device section (default 0)
  * @param $entity_restrict restrict to a specific entity (default -1)
  * @param $itemtype        of selected item (default 0)
  * @param $items_id        of selected item (default 0)
  *
  * @return nothing (print out an HTML select box)
  **/
 static function dropdownMyDevices($userID = 0, $entity_restrict = -1, $itemtype = 0, $items_id = 0)
 {
     global $DB, $CFG_GLPI;
     if ($userID == 0) {
         $userID = Session::getLoginUserID();
     }
     $rand = mt_rand();
     $already_add = array();
     if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware"] & pow(2, self::HELPDESK_MY_HARDWARE)) {
         $my_devices = "";
         $my_item = $itemtype . '_' . $items_id;
         // My items
         foreach ($CFG_GLPI["linkuser_types"] as $itemtype) {
             if (($item = getItemForItemtype($itemtype)) && parent::isPossibleToAssignType($itemtype)) {
                 $itemtable = getTableForItemType($itemtype);
                 $query = "SELECT *\n                             FROM `{$itemtable}`\n                             WHERE `users_id` = '{$userID}'";
                 if ($item->maybeDeleted()) {
                     $query .= " AND `is_deleted` = '0' ";
                 }
                 if ($item->maybeTemplate()) {
                     $query .= " AND `is_template` = '0' ";
                 }
                 if (in_array($itemtype, $CFG_GLPI["helpdesk_visible_types"])) {
                     $query .= " AND `is_helpdesk_visible` = '1' ";
                 }
                 $query .= getEntitiesRestrictRequest("AND", $itemtable, "", $entity_restrict, $item->maybeRecursive()) . "\n                         ORDER BY `name` ";
                 $result = $DB->query($query);
                 $nb = $DB->numrows($result);
                 if ($DB->numrows($result) > 0) {
                     $type_name = $item->getTypeName($nb);
                     while ($data = $DB->fetch_assoc($result)) {
                         $output = $data["name"];
                         if (empty($output) || $_SESSION["glpiis_ids_visible"]) {
                             $output = sprintf(__('%1$s (%2$s)'), $output, $data['id']);
                         }
                         $output = sprintf(__('%1$s - %2$s'), $type_name, $output);
                         if ($itemtype != 'Software') {
                             if (!empty($data['serial'])) {
                                 $output = sprintf(__('%1$s - %2$s'), $output, $data['serial']);
                             }
                             if (!empty($data['otherserial'])) {
                                 $output = sprintf(__('%1$s - %2$s'), $output, $data['otherserial']);
                             }
                         }
                         $my_devices .= "<option title=\"{$output}\" value='" . $itemtype . "_" . $data["id"] . "' " . ($my_item == $itemtype . "_" . $data["id"] ? "selected" : "") . ">" . Toolbox::substr($output, 0, $_SESSION["glpidropdown_chars_limit"]) . "</option>";
                         $already_add[$itemtype][] = $data["id"];
                     }
                 }
             }
         }
         if (!empty($my_devices)) {
             $my_devices = "<optgroup label=\"" . __s('My devices') . "\">" . $my_devices . "</optgroup>";
         }
         // My group items
         if (Session::haveRight("show_group_hardware", "1")) {
             $group_where = "";
             $query = "SELECT `glpi_groups_users`.`groups_id`, `glpi_groups`.`name`\n                            FROM `glpi_groups_users`\n                            LEFT JOIN `glpi_groups`\n                              ON (`glpi_groups`.`id` = `glpi_groups_users`.`groups_id`)\n                            WHERE `glpi_groups_users`.`users_id` = '{$userID}' " . getEntitiesRestrictRequest("AND", "glpi_groups", "", $entity_restrict, true);
             $result = $DB->query($query);
             $first = true;
             if ($DB->numrows($result) > 0) {
                 while ($data = $DB->fetch_assoc($result)) {
                     if ($first) {
                         $first = false;
                     } else {
                         $group_where .= " OR ";
                     }
                     $a_groups = getAncestorsOf("glpi_groups", $data["groups_id"]);
                     $a_groups[$data["groups_id"]] = $data["groups_id"];
                     $group_where .= " `groups_id` IN (" . implode(',', $a_groups) . ") ";
                 }
                 $tmp_device = "";
                 foreach ($CFG_GLPI["linkgroup_types"] as $itemtype) {
                     if (($item = getItemForItemtype($itemtype)) && parent::isPossibleToAssignType($itemtype)) {
                         $itemtable = getTableForItemType($itemtype);
                         $query = "SELECT *\n                                    FROM `{$itemtable}`\n                                    WHERE ({$group_where}) " . getEntitiesRestrictRequest("AND", $itemtable, "", $entity_restrict, $item->maybeRecursive());
                         if ($item->maybeDeleted()) {
                             $query .= " AND `is_deleted` = '0' ";
                         }
                         if ($item->maybeTemplate()) {
                             $query .= " AND `is_template` = '0' ";
                         }
                         $result = $DB->query($query);
                         if ($DB->numrows($result) > 0) {
                             $type_name = $item->getTypeName();
                             if (!isset($already_add[$itemtype])) {
                                 $already_add[$itemtype] = array();
                             }
                             while ($data = $DB->fetch_assoc($result)) {
                                 if (!in_array($data["id"], $already_add[$itemtype])) {
                                     $output = '';
//.........这里部分代码省略.........
开发者ID:gaforeror,项目名称:glpi,代码行数:101,代码来源:ticket.class.php


示例6: replayDictionnaryOnOneSoftware

 /**
  * Replay dictionnary on one software
  *
  * @param &$new_softs      array containing new softwares already computed
  * @param $res_rule        array of rule results
  * @param $ID                    ID of the software
  * @param $entity                working entity ID
  * @param $name                  softwrae name
  * @param $manufacturer          manufacturer name
  * @param &$soft_ids       array containing replay software need to be dustbined
  **/
 function replayDictionnaryOnOneSoftware(array &$new_softs, array $res_rule, $ID, $entity, $name, $manufacturer, array &$soft_ids)
 {
     global $DB;
     $input["name"] = $name;
     $input["manufacturer"] = $manufacturer;
     $input["entities_id"] = $entity;
     if (empty($res_rule)) {
         $res_rule = $this->processAllRules($input, array(), array());
     }
     $soft = new Software();
     if (isset($res_rules['_ignore_import']) && $res_rules['_ignore_import'] == 1) {
         $soft->putInTrash($ID, __('Software deleted by GLPI dictionary rules'));
         return;
     }
     //Software's name has changed or entity
     if (isset($res_rule["name"]) && $res_rule["name"] != $name || !isset($res_rule["name"]) && isset($res_rule['new_entities_id']) && in_array($res_rule['new_entities_id'], getAncestorsOf('glpi_entities', $entity))) {
         if (isset($res_rule["name"])) {
             $new_name = $res_rule["name"];
         } else {
             $new_name = addslashes($name);
         }
         if (isset($res_rule["manufacturer"]) && $res_rule["manufacturer"]) {
             $manufacturer = $res_rule["manufacturer"];
         } else {
             $manufacturer = addslashes($manufacturer);
         }
         //New software not already present in this entity
         if (!isset($new_softs[$entity][$new_name])) {
             // create new software or restore it from dustbin
             $new_software_id = $soft->addOrRestoreFromTrash($new_name, $manufacturer, $entity, '', true);
             $new_softs[$entity][$new_name] = $new_software_id;
         } else {
             $new_software_id = $new_softs[$entity][$new_name];
         }
         // Move licenses to new software
         $this->moveLicenses($ID, $new_software_id);
     } else {
         $new_software_id = $ID;
         $res_rule["id"] = $ID;
         if (isset($res_rule["manufacturer"]) && $res_rule["manufacturer"]) {
             $res_rule["manufacturers_id"] = Dropdown::importExternal('Manufacturer', $res_rule["manufacturer"]);
             unset($res_rule["manufacturer"]);
         }
         $soft->update($res_rule);
     }
     // Add to software to deleted list
     if ($new_software_id != $ID) {
         $soft_ids[] = $ID;
     }
     //Get all the different versions for a software
     $result = $DB->query("SELECT *\n                            FROM `glpi_softwareversions`\n                            WHERE `softwares_id` = '{$ID}'");
     while ($version = $DB->fetch_assoc($result)) {
         $input["version"] = addslashes($version["name"]);
         $old_version_name = $input["version"];
         if (isset($res_rule["version"]) && $res_rule["version"] != '') {
             $new_version_name = $res_rule["version"];
         } else {
             $new_version_name = $version["name"];
         }
         if ($ID != $new_software_id || $new_version_name != $old_version_name) {
             $this->moveVersions($ID, $new_software_id, $version["id"], $old_version_name, $new_version_name, $entity);
         }
     }
 }
开发者ID:geldarr,项目名称:hack-space,代码行数:75,代码来源:ruledictionnarysoftwarecollection.class.php


示例7: canRelationItem

 /**
  * @since version 0.84
  *
  * @param $method
  * @param $methodNotItem
  * @param $check_entity            (true by default)
  * @param $forceCheckBoth boolean  force check both items (false by default)
  *
  * @return boolean
  **/
 function canRelationItem($method, $methodNotItem, $check_entity = true, $forceCheckBoth = false)
 {
     $OneWriteIsEnough = !$forceCheckBoth && (static::HAVE_SAME_RIGHT_ON_ITEM == static::$checkItem_1_Rights || static::HAVE_SAME_RIGHT_ON_ITEM == static::$checkItem_2_Rights);
     try {
         $item1 = NULL;
         $can1 = $this->canConnexityItem($method, $methodNotItem, static::$checkItem_1_Rights, static::$itemtype_1, static::$items_id_1, $item1);
         if ($OneWriteIsEnough) {
             $view1 = $this->canConnexityItem($method, $methodNotItem, static::HAVE_VIEW_RIGHT_ON_ITEM, static::$itemtype_1, static::$items_id_1, $item1);
         }
     } catch (CommonDBConnexityItemNotFound $e) {
         if (static::$mustBeAttached_1 && !static::isAttach1Valid($this->fields)) {
             return false;
         }
         $can1 = true;
         $view1 = true;
         $check_entity = false;
         // If no item, then, we cannot check entities
     }
     try {
         $item2 = NULL;
         $can2 = $this->canConnexityItem($method, $methodNotItem, static::$checkItem_2_Rights, static::$itemtype_2, static::$items_id_2, $item2);
         if ($OneWriteIsEnough) {
             $view2 = $this->canConnexityItem($method, $methodNotItem, static::HAVE_VIEW_RIGHT_ON_ITEM, static::$itemtype_2, static::$items_id_2, $item2);
         }
     } catch (CommonDBConnexityItemNotFound $e) {
         if (static::$mustBeAttached_2 && !static::isAttach2Valid($this->fields)) {
             return false;
         }
         $can2 = true;
         $view2 = true;
         $check_entity = false;
         // If no item, then, we cannot check entities
     }
     if ($OneWriteIsEnough) {
         if (!$can1 && !$can2 || $can1 && !$view2 || $can2 && !$view1) {
             return false;
         }
     } else {
         if (!$can1 || !$can2) {
             return false;
         }
     }
     // Check coherency of entities
     if ($check_entity && static::$check_entity_coherency) {
         // If one of both extremity is not valid => not allowed !
         // (default is only to check on create and update not for view and delete)
         if (!$item1 instanceof CommonDBTM || !$item2 instanceof CommonDBTM) {
             return false;
         }
         if ($item1->isEntityAssign() && $item2->isEntityAssign()) {
             $entity1 = $item1->getEntityID();
             $entity2 = $item2->getEntityID();
             if ($entity1 == $entity2) {
                 return true;
             }
             if ($item1->isRecursive() && in_array($entity1, getAncestorsOf("glpi_entities", $entity2))) {
                 return true;
             }
             if ($item2->isRecursive() && in_array($entity2, getAncestorsOf("glpi_entities", $entity1))) {
                 return true;
             }
             return false;
         }
     }
     return true;
 }
开发者ID:paisdelconocimiento,项目名称:glpi-smartcities,代码行数:76,代码来源:commondbrelation.class.php


示例8: showForm

 /**
  * Print the Software / license form
  *
  * @param $ID        integer  Id of the version or the template to print
  * @param $options   array    of possible options:
  *     - target form target
  *     - softwares_id ID of the software for add process
  *
  * @return true if displayed  false if item not found or not right to display
  **/
 function showForm($ID, $options = array())
 {
     global $CFG_GLPI;
     $softwares_id = -1;
     if (isset($options['softwares_id'])) {
         $softwares_id = $options['softwares_id'];
     }
     if (!Session::haveRight("software", "w")) {
         return false;
     }
     if ($ID < 0) {
         // Create item
         $this->fields['softwares_id'] = $softwares_id;
         $this->fields['number'] = 1;
         $soft = new Software();
         if ($soft->getFromDB($softwares_id) && in_array($_SESSION['glpiactive_entity'], getAncestorsOf('glpi_entities', $soft->getEntityID()))) {
             $options['entities_id'] = $soft->getEntityID();
         }
     }
     $this->initForm($ID, $options);
     $this->showTabs($options);
     $this->showFormHeader($options);
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . Software::getTypeName(1) . "</td>";
     echo "<td>";
     if ($ID > 0) {
         $softwares_id = $this->fields["softwares_id"];
     } else {
         echo "<input type='hidden' name='softwares_id' value='{$softwares_id}'>";
     }
     echo "<a href='software.form.php?id=" . $softwares_id . "'>" . Dropdown::getDropdownName("glpi_softwares", $softwares_id) . "</a>";
     echo "</td>";
     echo "<td>" . __('Type') . "</td>";
     echo "<td>";
     SoftwareLicenseType::dropdown(array('value' => $this->fields["softwarelicensetypes_id"]));
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Name') . "</td>";
     echo "<td>";
     Html::autocompletionTextField($this, "name");
     echo "</td>";
     echo "<td>" . __('Serial number') . "</td>";
     echo "<td>";
     Html::autocompletionTextField($this, "serial");
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Purchase version') . "</td>";
     echo "<td>";
     SoftwareVersion::dropdown(array('name' => "softwareversions_id_buy", 'softwares_id' => $this->fields["softwares_id"], 'value' => $this->fields["softwareversions_id_buy"]));
     echo "</td>";
     echo "<td>" . __('Inventory number') . "</td>";
     echo "<td>";
     Html::autocompletionTextField($this, "otherserial");
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Version in use') . "</td>";
     echo "<td>";
     SoftwareVersion::dropdown(array('name' => "softwareversions_id_use", 'softwares_id' => $this->fields["softwares_id"], 'value' => $this->fields["softwareversions_id_use"]));
     echo "</td>";
     echo "<td rowspan='" . ($ID > 0 ? '4' : '3') . "' class='middle'>" . __('Comments') . "</td>";
     echo "<td class='center middle' rowspan='" . ($ID > 0 ? '4' : '3') . "'>";
     echo "<textarea cols='45' rows='5' name='comment' >" . $this->fields["comment"] . "</textarea>";
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . _x('quantity', 'Number') . "</td>";
     echo "<td>";
     Dropdown::showInteger("number", $this->fields["number"], 1, 1000, 1, array(-1 => __('Unlimited')));
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Expiration') . "</td>";
     echo "<td>";
     Html::showDateFormItem('expire', $this->fields["expire"]);
     Alert::displayLastAlert('SoftwareLicense', $ID);
     echo "</td></tr>\n";
     if ($ID > 0) {
         echo "<tr class='tab_bg_1'>";
         echo "<td>" . __('Last update') . "</td>";
         echo "<td>" . ($this->fields["date_mod"] ? Html::convDateTime($this->fields["date_mod"]) : __('Never'));
         echo "</td></tr>";
     }
     $this->showFormButtons($options);
     $this->addDivForTabs();
     return true;
 }
开发者ID:gaforeror,项目名称:glpi,代码行数:94,代码来源:softwarelicense.class.php


示例9: searchNetworks

 /**
  * Search networks relative to a given network
  *
  * @param $relation        type of relation ("is contained by", "equals" or "contains")
  *                         regarding the networks given as parameter
  * @param $condition array of elements to select the good arrays (see Parameters above)
  *    - fields : the fields of the network we wish to retrieve (single field or array of
  *               fields). This parameter will impact the result of the function
  *    - address (see \ref parameterType) : the address for the query
  *    - netmask (see \ref parameterType) : the netmask for the query
  *    - exclude IDs : the IDs to exclude from the query (for instance, $this->getID())
  *    - where : filters to add to the SQL request
  *
  * @param $entityID        the entity on which the selection should occur (-1 => the current active
  *                         entity) (default -1)
  * @param $recursive       set to false to only search in current entity, otherwise, all visible
  *                         entities will be search (true by default)
  * @param $version         version of IP to look (only use when using arrays or string as input for
  *                         address or netmask n(default 0)
  *
  * @return array of networks found. If we want request several field, the return value will be
  *                 an array of array
  *
  * \warning The order of the elements inside the result are ordered from the nearest one to the
  *          further. (ie. 0.0.0.0 is the further of whatever network if you lool for ones that
  *          contains the current network.
  **/
 static function searchNetworks($relation, $condition, $entityID = -1, $recursive = true, $version = 0)
 {
     global $DB;
     if (empty($relation)) {
         return false;
     }
     if (empty($condition["fields"])) {
         $fields = 'id';
     } else {
         $fields = $condition["fields"];
     }
     if (!is_array($fields)) {
         $fields = array($fields);
     }
     $FIELDS = "`" . implode("`, `", $fields) . "`";
     $startIndex = $version == 4 ? 3 : 1;
     $addressDB = array('address_0', 'address_1', 'address_2', 'address_3');
     $netmaskDB = array('netmask_0', 'netmask_1', 'netmask_2', 'netmask_3');
     $WHERE = "";
     if (isset($condition["address"]) && isset($condition["netmask"])) {
         $addressPa = new IPAddress($condition["address"]);
         // Check version equality ...
         if ($version != $addressPa->getVersion()) {
             if ($version != 0) {
                 return false;
             }
             $version = $addressPa->getVersion();
         }
         $netmaskPa = new IPNetmask($condition["netmask"], $version);
         // Get the array of the adresses
         $addressPa = $addressPa->getBinary();
         $netmaskPa = $netmaskPa->getBinary();
         // Check the binary is valid
         if (!is_array($addressPa) || count($addressPa) != 4) {
             return false;
         }
         if (!is_array($netmaskPa) || count($netmaskPa) != 4) {
             return false;
         }
         $startIndex = $version == 4 ? 3 : 0;
         if ($relation == "equals") {
             for ($i = $startIndex; $i < 4; ++$i) {
                 $WHERE .= " AND (`" . $addressDB[$i] . "` & '" . $netmaskPa[$i] . "')=\n                               ('" . $addressPa[$i] . "' & '" . $netmaskPa[$i] . "')\n                           AND ('" . $netmaskPa[$i] . "' = `" . $netmaskDB[$i] . "`)";
             }
         } else {
             for ($i = $startIndex; $i < 4; ++$i) {
                 if ($relation == "is contained by") {
                     $globalNetmask = "'" . $netmaskPa[$i] . "'";
                 } else {
                     $globalNetmask = "`" . $netmaskDB[$i] . "`";
                 }
                 $WHERE .= " AND (`" . $addressDB[$i] . "` & {$globalNetmask})=\n                               ('" . $addressPa[$i] . "' & {$globalNetmask})\n                           AND ('" . $netmaskPa[$i] . "' & `" . $netmaskDB[$i] . "`)={$globalNetmask}";
             }
         }
     }
     $WHERE = "`version`='{$version}' {$WHERE}";
     if ($entityID < 0) {
         $entityID = $_SESSION['glpiactive_entity'];
     }
     $entitiesID = array();
     switch ($relation) {
         case "is contained by":
             $ORDER_ORIENTATION = 'ASC';
             if ($recursive) {
                 $entitiesID = getSonsOf('glpi_entities', $entityID);
             }
             break;
         case "contains":
             $ORDER_ORIENTATION = 'DESC';
             if ($recursive) {
                 $entitiesID = getAncestorsOf('glpi_entities', $entityID);
             }
             break;
//.........这里部分代码省略.........
开发者ID:kipman,项目名称:glpi,代码行数:101,代码来源:ipnetwork.class.php


示例10: Infocom

 if (isset($searchopt[$_POST["id_field"]])) {
     /// Infocoms case
     if (!isPluginItemType($_POST["itemtype"]) && Search::isInfocomOption($_POST["itemtype"], $_POST["id_field"])) {
         $ic = new Infocom();
         $link_entity_type = -1;
         /// Specific entity item
         if ($searchopt[$_POST["id_field"]]["table"] == "glpi_suppliers") {
             $ent = new Supplier();
             if ($ent->getFromDB($_POST[$_POST["field"]])) {
                 $link_entity_type = $ent->fields["entities_id"];
             }
         }
         foreach ($_POST["item"] as $key => $val) {
             if ($val == 1) {
                 if ($item->getFromDB($key)) {
                     if ($link_entity_type < 0 || $link_entity_type == $item->getEntityID() || $ent->fields["is_recursive"] && in_array($link_entity_type, getAncestorsOf("glpi_entities", $item->getEntityID()))) {
                         // Add infocom if not exists
                         if (!$ic->getFromDBforDevice($_POST["itemtype"], $key)) {
                             $input2["items_id"] = $key;
                             $input2["itemtype"] = $_POST["itemtype"];
                             unset($ic->fields);
                             $ic->add($input2);
                             $ic->getFromDBforDevice($_POST["itemtype"], $key);
                         }
                         $id = $ic->fields["id"];
                         unset($ic->fields);
                         $ic->update(array('id' => $id, $_POST["field"] => $_POST[$_POST["field"]]));
                     }
                 }
             }
         }
开发者ID:ryukansent,项目名称:Thesis-SideB,代码行数:31,代码来源:massiveaction.php


示例11: post_updateItem

 function post_updateItem($history = 1)
 {
     $ID = $this->getID();
     $changeParent = in_array($this->getForeignKeyField(), $this->updates);
     $this->regenerateTreeUnderID($ID, in_array('name', $this->updates), $changeParent);
     $this->recursiveCleanSonsAboveID($ID);
     if ($changeParent) {
         $oldParentID = $this->oldvalues[$this->getForeignKeyField()];
         $newParentID = $this->fields[$this->getForeignKeyField()];
         $oldParentNameID = '';
         $newParentNameID = '';
         $parent = clone $this;
         if ($oldParentID > 0) {
             $this->recursiveCleanSonsAboveID($oldParentID);
             if ($history) {
                 if ($parent->getFromDB($oldParentID)) {
                     $oldParentNameID = $parent->getNameID();
                 }
                 $changes[0] = '0';
                 $changes[1] = addslashes($this->getNameID());
                 $changes[2] = '';
                 Log::history($oldParentID, $this->getType(), $changes, $this->getType(), Log::HISTORY_DELETE_SUBITEM);
             }
         }
         if ($newParentID > 0) {
             if ($history) {
                 if ($parent->getFromDB($newParentID)) {
                     $newParentNameID = $parent->getNameID();
                 }
                 $changes[0] = '0';
                 $changes[1] = '';
                 $changes[2] = addslashes($this->getNameID());
                 Log::history($newParentID, $this->getType(), $changes, $this->getType(), Log::HISTORY_ADD_SUBITEM);
             }
         }
         if ($history) {
             $changes[0] = '0';
             $changes[1] = $oldParentNameID;
             $changes[2] = $newParentNameID;
             Log::history($ID, $this->getType(), $changes, $this->getType(), Log::HISTORY_UPDATE_SUBITEM);
         }
         getAncestorsOf(getTableForItemType($this->getType()), $ID);
     }
 }
开发者ID:korial29,项目名称:glpi,代码行数:44,代码来源:commontreedropdown.class.php


示例12: canUnrecurs

 /**
  * Can I change recusvive flag to false
  * check if there is "linked" object in another entity
  *
  * May be overloaded if needed
  *
  * @return booleen
  **/
 function canUnrecurs()
 {
     global $DB, $CFG_GLPI;
     $ID = $this->fields['id'];
     if ($ID < 0 || !$this->fields['is_recursive']) {
         return true;
     }
     $entities = "('" . $this->fields['entities_id'] . "'";
     foreach (getAncestorsOf("glpi_entities", $this->fields['entities_id']) as $papa) {
         $entities .= ",'{$papa}'";
     }
     $entities .= ")";
     $RELATION = getDbRelations();
     if ($this instanceof CommonTreeDropdown) {
         $f = getForeignKeyFieldForTable($this->getTable());
         if (countElementsInTable($this->getTable(), "`{$f}`='{$ID}' AND entities_id NOT IN {$entities}") > 0) {
             return false;
         }
     }
     if (isset($RELATION[$this->getTable()])) {
         foreach ($RELATION[$this->getTable()] as $tablename => $field) {
             $itemtype = getItemTypeForTable($tablename);
             $item = new $itemtype();
             if ($item->isEntityAssign()) {
                 // 1->N Relation
                 if (is_array($field)) {
                     foreach ($field as $f) {
                         if (countElementsInTable($tablename, "`{$f}`='{$ID}' AND entities_id NOT IN {$entities}") > 0) {
                             return false;
                         }
                     }
                 } else {
                     if (countElementsInTable($tablename, "`{$field}`='{$ID}' AND entities_id NOT IN {$entities}") > 0) {
                         return false;
                     }
                 }
             } else {
                 foreach ($RELATION as $othertable => $rel) {
                     // Search for a N->N Relation with devices
                     if ($othertable == "_virtual_device" && isset($rel[$tablename])) {
                         $devfield = $rel[$tablename][0];
                         // items_id...
                         $typefield = $rel[$tablename][1];
                         // itemtype...
                         $sql = "SELECT DISTINCT `{$typefield}` AS itemtype\n                             FROM `{$tablename}`\n                             WHERE `{$field}`='{$ID}'";
                         $res = $DB->query($sql);
                         // Search linked device of each type
                         if ($res) {
                             while ($data = $DB->fetch_assoc($res)) {
                                 $itemtype = $data["itemtype"];
                                 $itemtable = getTableForItemType($itemtype);
                                 $item = new $itemtype();
                                 if ($item->isEntityAssign()) {
                                     if (countElementsInTable(array($tablename, $itemtable), "`{$tablename}`.`{$field}`='{$ID}'\n                                                        AND `{$tablename}`.`{$typefield}`='{$itemtype}'\n                                                        AND `{$tablename}`.`{$devfield}`=`{$itemtable}`.id\n                                                        AND `{$itemtable}`.`entities_id`\n                                                             NOT IN {$entities}") > '0') {
                                         return false;
                                     }
                                 }
                             }
                         }
                         // Search for another N->N Relation
                     } else {
                         if ($othertable != $this->getTable() && isset($rel[$tablename])) {
                             $itemtype = getItemTypeForTable($othertable);
                             $item = new $itemtype();
                             if ($item->isEntityAssign()) {
                                 if (is_array($rel[$tablename])) {
                                     foreach ($rel[$tablename] as $otherfield) {
                                         if (countElementsInTable(array($tablename, $othertable), "`{$tablename}`.`{$field}`='{$ID}'\n                                                        AND `{$tablename}`.`{$otherfield}`\n                                                                  =`{$othertable}`.id\n                                                        AND `{$othertable}`.`entities_id`\n                                                                  NOT IN {$entities}") > '0') {
                                             return false;
                                         }
                                     }
                                 } else {
                                     $otherfield = $rel[$tablename];
                                     if (countElementsInTable(array($tablename, $othertable), "`{$tablename}`.`{$field}`={$ID}\n                                                     AND `{$tablename}`.`{$otherfield}`=`{$othertable}`.id\n                                                     AND `{$othertable}`.`entities_id`\n                                                               NOT IN {$entities}") > '0') {
                                         return false;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // Doc links to this item
     if ($this->getType() > 0 && countElementsInTable(array('glpi_documents_items', 'glpi_documents'), "`glpi_documents_items`.`items_id`='{$ID}'\n                                   AND `glpi_documents_items`.`itemtype`=" . $this->getType() . "\n                                   AND `glpi_documents_items`.`documents_id`=`glpi_documents`.`id`\n                                   AND `glpi_documents`.`entities_id` NOT IN {$entities}") > '0') {
         return false;
     }
     // TODO : do we need to check all relations in $RELATION["_virtual_device"] for this item
     return true;
 }
开发者ID:ryukansent,项目名称:Thesis-SideB,代码行数:99,代码来源:commondbtm.class.php


示例13: haveAccessToEntity

 /**
  * Check if you could access (read) to the entity of id = $ID
  *
  * @param $ID                    ID of the entity
  * @param $is_recursive boolean  if recursive item (default 0)
  *
  * @return Boolean : read access to entity
  **/
 static function haveAccessToEntity($ID, $is_recursive = 0)
 {
     // Quick response when passing wrong ID : default value of getEntityID is -1
     if ($ID < 0) {
         return false;
     }
     if (!isset($_SESSION['glpiactiveentities'])) {
         return false;
     }
     if (!$is_recursive) {
         return in_array($ID, $_SESSION['glpiactiveentities']);
     }
     if (in_array($ID, $_SESSION['glpiactiveentities'])) {
         return true;
     }
     /// Recursive object
     foreach ($_SESSION['glpiactiveentities'] as $ent) {
         if (in_array($ID, getAncestorsOf("glpi_entities", $ent))) {
 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP getAnnotatedAlbumTitle函数代码示例发布时间:2022-05-15
下一篇:
PHP getAllUsers函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap