public function do_add() { $txt = Loader::helper('text'); $valt = Loader::helper('validation/token'); $gName = $txt->sanitize($_POST['gName']); $gDescription = $_POST['gDescription']; if (!$gName) { $this->error->add(t("Name required.")); } if (!$valt->validate('add_or_update_group')) { $this->error->add($valt->getErrorMessage()); } $g1 = Group::getByName($gName); if ($g1 instanceof Group) { if ((!is_object($g)) || $g->getGroupID() != $g1->getGroupID()) { $this->error->add(t('A group named "%s" already exists', $g1->getGroupName())); } } if (!$this->error->has()) { $g = Group::add($gName, $_POST['gDescription']); $this->checkExpirationOptions($g); $this->redirect('/dashboard/users/groups', 'group_added'); } }
protected function attemptAuthentication() { $user = parent::attemptAuthentication(); $userInfo = \UserInfo::getByID($user->getUserID()); $extractor = $this->getExtractor(); $roles = $extractor->getExtra('roles'); // sync groups with roles if (is_array($roles)) { $groupIds = array(); foreach ($roles as $role) { $roleApplicationCode = $role['role_application']['application_code']; if ($roleApplicationCode == \Config::get('auth.worldskills.roles_application_code')) { $roleName = $role['name']; // check for entity role and append entity name if (isset($role['ws_entity'])) { $roleName = $roleName . ' - ' . $role['ws_entity']['name']['text']; } // check if group exists $group = \Group::getByName($roleName); if (!is_object($group)) { // add missing groups $group = \Group::add($roleName, ''); } $groupIds[] = $group->getGroupID(); } } // remove duplicate groups $groupIds = array_unique($groupIds); // update groups of user $userInfo->updateGroups($groupIds); } // login user again to make sure groups are reloaded return \User::loginByUserID($user->getUserID()); }
/** * {@inheritdoc} */ public function add(array $children) { $allowed = ['loader' => null, 'field' => null]; if (array_diff_key($children, $allowed)) { throw new \InvalidArgumentException("Only 'loader' and 'field' keys are available."); } return parent::add($children); }
function &sphereScene($level, &$center, $radius) { $sphere = new Sphere($center, $radius); if ($level == 1) { return $sphere; } else { $scene = new Group(new Sphere($center, 3.0 * $radius)); $scene->add($sphere); $rn = 3.0 * $radius / sqrt(12.0); for ($dz = -1; $dz <= 1; $dz += 2) { for ($dx = -1; $dx <= 1; $dx += 2) { $c2 = newVector($center[0] - $dx * $rn, $center[1] + $rn, $center[2] - $dz * $rn); $scene->add(Scene::sphereScene($level - 1, $c2, $radius / 2.0)); } } return $scene; } }
public function testUserPointActionWithGroup() { $g = \Group::add('Test Group', 'Test Group Description'); Action::add('test_action', t('Test Action'), 4, $g); $action = Action::getByHandle('test_action'); /* @var $action \Concrete\Core\User\Point\Action\Action */ $this->assertInstanceOf('\\Concrete\\Core\\User\\Point\\Action\\Action', $action); $this->assertEquals(4, $action->getUserPointActionDefaultPoints()); $this->assertInstanceOf('\\Concrete\\Core\\User\\Group\\Group', $action->getUserPointActionBadgeGroupObject()); $this->assertEquals($g->getGroupID(), $action->getUserPointActionBadgeGroupObject()->getGroupID()); }
public function doAddGroup() { $group = new StdClass(); $group->number = Data::get('number', '', Data::STR); $group->letter = Data::get('letter', '', Data::STR); $a = (object) array('success' => false, 'message' => ''); if ($group->id = Group::add($group)) { $a->message = 'Класс успешно добавлен!'; $a->object = $group; $a->success = true; } else { $a->message = 'Ошибка при добавлении класса'; } return $a; }
public function do_add() { $txt = $this->app->make('helper/text'); $valt = $this->app->make('helper/validation/token'); $gName = $txt->sanitize($this->request->post('gName')); $gDescription = $this->request->post('gDescription'); if (!$gName) { $this->error->add(t("Name required.")); } if (!$valt->validate('add_or_update_group')) { $this->error->add($valt->getErrorMessage()); } if ($this->request->post('gIsBadge')) { if (!$this->post('gBadgeDescription')) { $this->error->add(t('You must specify a description for this badge. It will be displayed publicly.')); } } $parentGroup = null; if ($this->request->post('gParentNodeID')) { $parentGroupNode = TreeNode::getByID($this->request->post('gParentNodeID')); if ($parentGroupNode instanceof GroupTreeNode) { $parentGroup = $parentGroupNode->getTreeNodeGroupObject(); } } if (is_object($parentGroup)) { $pp = new \Permissions($parentGroup); if (!$pp->canAddSubGroup()) { $this->error->add(t('You do not have permission to add a group beneath %s', $parentGroup->getGroupDisplayName())); } } if (!$this->error->has()) { $g = ConcreteGroup::add($gName, $this->request->post('gDescription'), $parentGroup); $this->checkExpirationOptions($g); $this->checkBadgeOptions($g); $this->checkAutomationOptions($g); $this->redirect('/dashboard/users/groups', 'group_added'); } $this->view(); }
include ROOT . '/lib/includeForAjax.php'; requireStrictRoute(); $response = array(); $response['error'] = 0; $response['message'] = ''; $name = $_POST['name']; if(empty($name)) { $response['error'] = -1; $response['message'] = _t('잘못된 접근입니다.'); } else { if (!isAdmin()) { $response['error'] = 1; $response['message'] = _t('관리자만이 이 기능을 사용할 수 있습니다.'); } else { requireComponent('Bloglounge.Data.Groups'); if(!Group::add($name)) { $response['error'] = 2; $response['message'] = _t('그룹추가를 실패하였습니다.'); } else { $response['message'] = $name; } } } func::printRespond($response); ?>
private function installGroups() { /* * It looks like you can't associate groups with a package, so whatever * you install here will remain after you uninstall */ $bpAdmins = Group::getByName("Boilerplate Admins"); if (!is_object($bpAdmins)) { $bpAdmins = Group::add("Boilerplate Admins", "Sample group for the boilerplate package."); } }
You should have received a copy of the GNU General Public License along with GLPI. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ /** @file * @brief */ include '../inc/includes.php'; Session::checkRight("group", READ); if (empty($_GET["id"])) { $_GET["id"] = ""; } $group = new Group(); if (isset($_POST["add"])) { $group->check(-1, CREATE, $_POST); if ($newID = $group->add($_POST)) { Event::log($newID, "groups", 4, "setup", sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"])); if ($_SESSION['glpibackcreated']) { Html::redirect($group->getFormURL() . "?id=" . $newID); } } Html::back(); } else { if (isset($_POST["purge"])) { $group->check($_POST["id"], PURGE); if ($group->isUsed() && empty($_POST["forcepurge"])) { Html::header($group->getTypeName(1), $_SERVER['PHP_SELF'], "admin", "group", str_replace('glpi_', '', $group->getTable())); $group->showDeleteConfirmForm($_SERVER['PHP_SELF']); Html::footer(); } else { $group->delete($_POST, 1);
if (Tools::getValue('action') == 'loadFilterInfo') { die($obj->loadFilterInfo(Tools::getValue('idfilter'))); } if (Tools::getValue('action') == 'deleteFilter') { die($obj->deleteFilter(Tools::getValue('idfilter'))); } if (Tools::getValue('action') == 'newGroup') { $grp = new Group(); $name = array(); $languages = Language::getLanguages(false); foreach ($languages as $language) { $name[$language['id_lang']] = Tools::getValue('name'); } $grp->name = $name; $grp->price_display_method = 0; $grp->add(); echo (int) $grp->id; exit; } if (Tools::getValue('action') == 'addGroup') { $sql = $obj->getQuery($_POST, true); if (!$sql) { die(false); } $rows = Db::getInstance()->ExecuteS($sql); if (!is_array($rows)) { die(false); } if (Tools::getValue('mode') == 'rep') { foreach ($rows as $row) { Db::getInstance()->Execute('DELETE FROM ' . _DB_PREFIX_ . 'customer_group WHERE id_customer = ' . (int) $row[$obj->ll(47)]);
protected function customerImportOne($info, $default_language_id, $id_lang, $shop_is_feature_active, $force_ids, $validateOnly = false) { AdminImportController::setDefaultValues($info); if ($force_ids && isset($info['id']) && (int) $info['id']) { $customer = new Customer((int) $info['id']); } else { if (array_key_exists('id', $info) && (int) $info['id'] && Customer::customerIdExistsStatic((int) $info['id'])) { $customer = new Customer((int) $info['id']); } else { $customer = new Customer(); } } $customer_exist = false; $autodate = true; if (array_key_exists('id', $info) && (int) $info['id'] && Customer::customerIdExistsStatic((int) $info['id']) && Validate::isLoadedObject($customer)) { $current_id_customer = (int) $customer->id; $current_id_shop = (int) $customer->id_shop; $current_id_shop_group = (int) $customer->id_shop_group; $customer_exist = true; $customer_groups = $customer->getGroups(); $addresses = $customer->getAddresses((int) Configuration::get('PS_LANG_DEFAULT')); } // Group Importation if (isset($info['group']) && !empty($info['group'])) { foreach (explode($this->multiple_value_separator, $info['group']) as $key => $group) { $group = trim($group); if (empty($group)) { continue; } $id_group = false; if (is_numeric($group) && $group) { $my_group = new Group((int) $group); if (Validate::isLoadedObject($my_group)) { $customer_groups[] = (int) $group; } continue; } $my_group = Group::searchByName($group); if (isset($my_group['id_group']) && $my_group['id_group']) { $id_group = (int) $my_group['id_group']; } if (!$id_group) { $my_group = new Group(); $my_group->name = array($id_lang => $group); if ($id_lang != $default_language_id) { $my_group->name = $my_group->name + array($default_language_id => $group); } $my_group->price_display_method = 1; if (!$validateOnly) { $my_group->add(); if (Validate::isLoadedObject($my_group)) { $id_group = (int) $my_group->id; } } } if ($id_group) { $customer_groups[] = (int) $id_group; } } } elseif (empty($info['group']) && isset($customer->id) && $customer->id) { $customer_groups = array(0 => Configuration::get('PS_CUSTOMER_GROUP')); } if (isset($info['date_add']) && !empty($info['date_add'])) { $autodate = false; } AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $customer); if ($customer->passwd) { $customer->passwd = Tools::encrypt($customer->passwd); } $id_shop_list = explode($this->multiple_value_separator, $customer->id_shop); $customers_shop = array(); $customers_shop['shared'] = array(); $default_shop = new Shop((int) Configuration::get('PS_SHOP_DEFAULT')); if ($shop_is_feature_active && $id_shop_list) { foreach ($id_shop_list as $id_shop) { if (empty($id_shop)) { continue; } $shop = new Shop((int) $id_shop); $group_shop = $shop->getGroup(); if ($group_shop->share_customer) { if (!in_array($group_shop->id, $customers_shop['shared'])) { $customers_shop['shared'][(int) $id_shop] = $group_shop->id; } } else { $customers_shop[(int) $id_shop] = $group_shop->id; } } } else { $default_shop = new Shop((int) Configuration::get('PS_SHOP_DEFAULT')); $default_shop->getGroup(); $customers_shop[$default_shop->id] = $default_shop->getGroup()->id; } //set temporary for validate field $customer->id_shop = $default_shop->id; $customer->id_shop_group = $default_shop->getGroup()->id; if (isset($info['id_default_group']) && !empty($info['id_default_group']) && !is_numeric($info['id_default_group'])) { $info['id_default_group'] = trim($info['id_default_group']); $my_group = Group::searchByName($info['id_default_group']); if (isset($my_group['id_group']) && $my_group['id_group']) { $info['id_default_group'] = (int) $my_group['id_group']; } } $my_group = new Group($customer->id_default_group); if (!Validate::isLoadedObject($my_group)) { $customer->id_default_group = (int) Configuration::get('PS_CUSTOMER_GROUP'); } $customer_groups[] = (int) $customer->id_default_group; $customer_groups = array_flip(array_flip($customer_groups)); // Bug when updating existing user that were csv-imported before... if (isset($customer->date_upd) && $customer->date_upd == '0000-00-00 00:00:00') { $customer->date_upd = date('Y-m-d H:i:s'); } $res = false; if (($field_error = $customer->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $customer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) { $res = true; foreach ($customers_shop as $id_shop => $id_group) { $customer->force_id = (bool) $force_ids; if ($id_shop == 'shared') { foreach ($id_group as $key => $id) { $customer->id_shop = (int) $key; $customer->id_shop_group = (int) $id; if ($customer_exist && ((int) $current_id_shop_group == (int) $id || in_array($current_id_shop, ShopGroup::getShopsFromGroup($id)))) { $customer->id = (int) $current_id_customer; $res &= $validateOnly || $customer->update(); } else { $res &= $validateOnly || $customer->add($autodate); if (!$validateOnly && isset($addresses)) { foreach ($addresses as $address) { $address['id_customer'] = $customer->id; unset($address['country'], $address['state'], $address['state_iso'], $address['id_address']); Db::getInstance()->insert('address', $address, false, false); } } } if ($res && !$validateOnly && isset($customer_groups)) { $customer->updateGroup($customer_groups); } } } else { $customer->id_shop = $id_shop; $customer->id_shop_group = $id_group; if ($customer_exist && (int) $id_shop == (int) $current_id_shop) { $customer->id = (int) $current_id_customer; $res &= $validateOnly || $customer->update(); } else { $res &= $validateOnly || $customer->add($autodate); if (!$validateOnly && isset($addresses)) { foreach ($addresses as $address) { $address['id_customer'] = $customer->id; unset($address['country'], $address['state'], $address['state_iso'], $address['id_address']); Db::getInstance()->insert('address', $address, false, false); } } } if ($res && !$validateOnly && isset($customer_groups)) { $customer->updateGroup($customer_groups); } } } } if (isset($customer_groups)) { unset($customer_groups); } if (isset($current_id_customer)) { unset($current_id_customer); } if (isset($current_id_shop)) { unset($current_id_shop); } if (isset($current_id_shop_group)) { unset($current_id_shop_group); } if (isset($addresses)) { unset($addresses); } if (!$res) { $this->errors[] = sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be ' . ($validateOnly ? 'validated' : 'saved')), $info['email'], isset($info['id']) && !empty($info['id']) ? $info['id'] : 'null'); $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError(); } }
/** Generate bigdump : generate items for an entity * * @param $ID_entity entity ID **/ function generate_entity($ID_entity) { global $MAX, $DB, $percent, $FIRST, $LAST, $MAX_KBITEMS_BY_CAT, $MAX_DISK, $DOCUMENTS, $NET_PORT, $NET_LOC; regenerateTreeCompleteName("glpi_entities"); $current_year = date("Y"); // DOMAIN $items = array("SP2MI", "CAMPUS"," IUT86", "PRESIDENCE", "CEAT", "D'omaine"); $dp = new Domain(); $FIRST["domain"] = getMaxItem("glpi_domains")+1; for ($i=0 ; $i<$MAX['domain'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "domain $ID_entity '$i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'entities_id' => $ID_entity, 'is_recursive' => 1, 'comment' => "comment $val"))); } $LAST["domain"] = getMaxItem("glpi_domains"); // STATUS $items = array("Reparation", "En stock", "En fonction", "Retour SAV", "En attente d'"); $dp = new State(); $FIRST["state"] = getMaxItem("glpi_states")+1; for ($i=0 ; $i<$MAX['state'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "State $ID_entity '$i"; } $state_id = $dp->add(toolbox::addslashes_deep(array('name' => $val, 'entities_id' => $ID_entity, 'is_recursive' => 1, 'comment' => "comment $val"))); // generate sub status for ($j=0 ; $j<$MAX['state'] ; $j++) { $val2 = "Sub $val $j"; $dp->add(toolbox::addslashes_deep(array('name' => $val2, 'entities_id' => $ID_entity, 'is_recursive' => 1, 'states_id' => $state_id, 'comment' => "comment $val"))); } } $LAST["state"] = getMaxItem("glpi_states"); // glpi_groups $FIRST["groups"] = getMaxItem("glpi_groups")+1; $group = new Group(); for ($i=0 ; $i<$MAX['groups'] ; $i++) { $gID = $group->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "group d'$i", 'comment' => "comment group d'$i", 'is_assign' => 0))); // Generate sub group for ($j=0 ; $j<$MAX['groups'] ; $j++) { $group->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "subgroup d'$j", 'comment' => "comment subgroup d'$j of group $i", 'groups_id' => $gID, 'is_assign' => 0))); } } $LAST["groups"] = getMaxItem("glpi_groups"); $FIRST["techgroups"] = $LAST["groups"]+1; for ($i=0 ; $i<$MAX['groups'] ; $i++) { $group->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "tech group d'$i", 'comment' => "comment tech group d'$i"))); } $LAST["techgroups"] = getMaxItem("glpi_groups"); regenerateTreeCompleteName("glpi_groups"); // glpi_users $FIRST["users_sadmin"] = getMaxItem("glpi_users")+1; $user = new User(); $gu = new Group_User(); for ($i=0 ; $i<$MAX['users_sadmin'] ; $i++) { $users_id = $user->add(toolbox::addslashes_deep( array('name' => "sadmin$i-$ID_entity", 'password' => "sadmin'$i", 'password2' => "sadmin'$i", 'phone' => "tel $i", 'phone2' => "tel2 $i", 'mobile' => "mobile $i", 'realname' => "sadmin '$i name", 'firstname' => "sadmin '$i firstname", 'comment' => "comment' $i", 'usertitles_id' => mt_rand(0,$MAX['user_title']), 'usercategories_id' => mt_rand(0,$MAX['user_type']), '_profiles_id' => 4, '_entities_id' => $ID_entity, '_is_recursive' => 1 ))); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['groups'], $LAST['groups']))); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['techgroups'], $LAST['techgroups']))); } $LAST["users_sadmin"] = getMaxItem("glpi_users"); $FIRST["users_admin"] = getMaxItem("glpi_users")+1; for ($i=0 ; $i<$MAX['users_admin'] ; $i++) { $users_id = $user->add(toolbox::addslashes_deep( array('name' => "admin$i-$ID_entity", 'password' => "admin'$i", 'password2' => "admin'$i", 'phone' => "tel $i", 'phone2' => "tel2 $i", 'mobile' => "mobile $i", 'realname' => "admin$i 'name", 'firstname' => "admin$i 'firstname", 'comment' => "comment '$i", 'usertitles_id' => mt_rand(0,$MAX['user_title']), 'usercategories_id' => mt_rand(0,$MAX['user_type']), '_profiles_id' => 3, '_entities_id' => $ID_entity, '_is_recursive' => 1))); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['groups'], $LAST['groups']), 'is_manager' => 1, 'is_delegate' => 1)); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['techgroups'], $LAST['techgroups']), 'is_manager' => 1, 'is_delegate' => 1)); } $LAST["users_admin"] = getMaxItem("glpi_users"); $FIRST["users_normal"] = getMaxItem("glpi_users")+1; for ($i=0 ; $i<$MAX['users_normal'] ; $i++) { $users_id = $user->add(toolbox::addslashes_deep( array('name' => "normal$i-$ID_entity", 'password' => "normal'$i", 'password2' => "normal'$i", 'phone' => "tel $i", 'phone2' => "tel2 $i", 'mobile' => "mobile $i", 'realname' => "normal$i 'name", 'firstname' => "normal$i 'firstname", 'comment' => "comment '$i", 'usertitles_id' => mt_rand(0,$MAX['user_title']), 'usercategories_id' => mt_rand(0,$MAX['user_type']), '_profiles_id' => 2, '_entities_id' => $ID_entity, '_is_recursive' => 1))); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['groups'], $LAST['groups']))); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['techgroups'], $LAST['techgroups']))); } $LAST["users_normal"] = getMaxItem("glpi_users"); $FIRST["users_postonly"] = getMaxItem("glpi_users")+1; for ($i=0 ; $i<$MAX['users_postonly'] ; $i++) { $users_id = $user->add(toolbox::addslashes_deep( array('name' => "postonly$i-$ID_entity", 'password' => "postonly'$i", 'password2' => "postonly'$i", 'phone' => "tel $i", 'phone2' => "tel2 $i", 'mobile' => "mobile $i", 'realname' => "postonly$i 'name", 'firstname' => "postonly$i 'firstname", 'comment' => "comment' $i", 'usertitles_id' => mt_rand(0,$MAX['user_title']), 'usercategories_id' => mt_rand(0,$MAX['user_type']), '_profiles_id' => 1, '_entities_id' => $ID_entity, '_is_recursive' => 1))); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['groups'], $LAST['groups']))); } $LAST["users_postonly"] = getMaxItem("glpi_users"); $FIRST["kbcategories"] = getMaxItem("glpi_knowbaseitemcategories")+1; $kbc = new KnowbaseItemCategory(); for ($i=0 ; $i<max(1,pow($MAX['kbcategories'],1/3)) ; $i++) { $newID = $kbc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "entity ' categorie $i", 'comment' => "comment ' categorie $i"))); for ($j=0 ; $j<mt_rand(0,pow($MAX['kbcategories'],1/2)) ; $j++) { $newID2 = $kbc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "entity s-categorie '$j", 'comment' => "comment s-categorie '$j", 'knowbaseitemcategories_id' => $newID))); for ($k=0 ; $k<mt_rand(0,pow($MAX['kbcategories'],1/2)) ; $k++) { $newID2 = $kbc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "entity ss-categorie' $k", 'comment' => "comment ss-categorie' $k", 'knowbaseitemcategories_id' => $newID2))); } } } $query = "OPTIMIZE TABLE `glpi_knowbaseitemcategories`"; $DB->query($query) or die("PB REQUETE ".$query); regenerateTreeCompleteName("glpi_knowbaseitemcategories"); $LAST["kbcategories"] = getMaxItem("glpi_knowbaseitemcategories"); // LOCATIONS $added = 0; $FIRST["locations"] = getMaxItem("glpi_locations")+1; $loc = new Location(); for ($i=0 ; $i<pow($MAX['locations'],1/5)&&$added<$MAX['locations'] ; $i++) { $added++; $newID = $loc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "location' $i", 'comment' => "comment 'location $i", 'building' => "building $i"))); for ($j=0 ; $j<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $j++) { $added++; $newID2 = $loc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "s-location '$j", 'comment' => "comment s-location '$j", 'building' => "building $i", 'room' => "stage '$j", 'locations_id' => $newID))); for ($k=0 ; $k<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $k++) { $added++; $newID3 = $loc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "ss-location '$k", 'comment' => "comment ss-location' $k", 'building' => "building $i", 'room' => "part' $k", 'locations_id' => $newID2))); for ($l=0 ; $l<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $l++) { $added++; $newID4 = $loc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "sss-location' $l", 'comment' => "comment sss-location' $l", 'building' => "building $i", 'room' => "room' $l", 'locations_id' => $newID3))); for ($m=0 ; $m<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $m++) { $added++; $newID5 = $loc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "ssss-location' $m", 'comment' => "comment ssss-location' $m", 'building' => "building $i", 'room' => "room' $l-$m", 'locations_id' => $newID4))); } } } } } $query = "OPTIMIZE TABLE `glpi_locations`"; $DB->query($query) or die("PB REQUETE ".$query); regenerateTreeCompleteName("glpi_locations"); $LAST["locations"]=getMaxItem("glpi_locations"); // Task categories $added = 0; $FIRST["taskcategory"] = getMaxItem("glpi_taskcategories")+1; $tc = new TaskCategory(); for ($i=0 ; $i<pow($MAX['taskcategory'],1/5)&&$added<$MAX['taskcategory'] ; $i++) { $added++; $newID = $tc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "ent$ID_entity taskcategory' $i", 'comment' => "comment ent$ID_entity taskcategory' $i"))); for ($j=0 ; $j<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $j++) { $newID2 = $tc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "ent$ID_entity taskcategory' $i", 'comment' => "comment ent$ID_entity taskcategory' $i", 'taskcategories_id' => $newID))); $added++; } } $query = "OPTIMIZE TABLE `glpi_taskcategories`"; $DB->query($query) or die("PB REQUETE ".$query); regenerateTreeCompleteName("glpi_taskcategories"); $LAST["taskcategory"] = getMaxItem("glpi_taskcategories"); $ic = new ItilCategory(); // Specific ticket categories $newID = $ic->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "category for entity' $ID_entity", 'comment' => "comment category for entity' $ID_entity", 'users_id' => mt_rand($FIRST['users_sadmin'],$LAST['users_admin']), 'groups_id' => mt_rand($FIRST['techgroups'],$LAST['techgroups']), 'tickettemplates_id_incident' => 1, 'tickettemplates_id_demand' => 1))); for ($i=0 ; $i<max(1,pow($MAX['tracking_category'],1/3)) ; $i++) { $ic->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "scategory for entity' $ID_entity", 'comment' => "comment scategory for entity' $ID_entity", 'users_id' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin']), 'groups_id' => mt_rand($FIRST['techgroups'], $LAST['techgroups']), 'tickettemplates_id_incident' => 1, 'tickettemplates_id_demand' => 1, 'itilcategories_id' => $newID))); } regenerateTreeCompleteName("glpi_itilcategories"); $FIRST["solutiontypes"] = getMaxItem("glpi_solutiontypes")+1; $items = array("d'après KB"); $st = new SolutionType(); for ($i=0 ; $i<$MAX['solutiontypes'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type de solution ' $i"; } $st->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val", 'entities_id' => $ID_entity, 'is_recursive' => 1))); } $LAST["solutiontypes"] = getMaxItem("glpi_solutiontypes"); $FIRST["solutiontemplates"] = getMaxItem("glpi_solutiontemplates")+1; $nb_items = mt_rand(0,$MAX['solutiontemplates']); $st = new SolutionTemplate(); for ($i=0 ; $i<$nb_items ; $i++) { $st-> add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "solution' $i-$ID_entity", 'content' => "content solution' $i-$ID_entity", 'solutiontypes_id' => mt_rand(0,$MAX['solutiontypes']), 'comment' => "comment solution' $i-$ID_entity"))); } $LAST["solutiontemplates"] = getMaxItem("glpi_solutiontemplates"); // Add Specific questions $k = 0; $FIRST["kbitems"] = getMaxItem("glpi_knowbaseitems")+1; $ki = new KnowbaseItem(); $eki = new Entity_KnowbaseItem(); for ($i=$FIRST['kbcategories'] ; $i<=$LAST['kbcategories'] ; $i++) { $nb = mt_rand(0,$MAX_KBITEMS_BY_CAT); for ($j=0 ; $j<$nb ; $j++) { $k++; $newID = $ki->add(toolbox::addslashes_deep( array('knowbaseitemcategories_id' => $i, 'name' => "Entity' $ID_entity Question $k", 'answer' => "Answer' $k".Toolbox::getRandomString(50), 'is_faq' => mt_rand(0,1), 'users_id' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin'])))); $eki->add(array('entities_id' => $ID_entity, 'knowbaseitems_id' => $newID, 'is_recursive' => 0)); } } // Add global questions for ($i=$FIRST['kbcategories'] ; $i<=$LAST['kbcategories'] ; $i++) { $nb = mt_rand(0,$MAX_KBITEMS_BY_CAT); for ($j=0 ; $j<$nb ; $j++) { $k++; $newID = $ki->add(toolbox::addslashes_deep( array('knowbaseitemcategories_id' => $i, 'name' => "Entity' $ID_entity Recursive Question $k", 'answer' => "Answer' $k".Toolbox::getRandomString(50), 'is_faq' => mt_rand(0,1), 'users_id' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin'])))); $eki->add(array('entities_id' => $ID_entity, 'knowbaseitems_id' => $newID, 'is_recursive' => 1)); } } $LAST["kbitems"] = getMaxItem("glpi_knowbaseitems"); // Ajout documents specific $FIRST["document"] = getMaxItem("glpi_documents")+1; $doc = new Document(); for ($i=0 ; $i<$MAX['document'] ; $i++) { $link = ""; if (mt_rand(0,100)<50) { $link = "http://linktodoc/doc$i"; } $docID = $doc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 0, 'name' => "document' $i-$ID_entity", 'documentcategories_id' => mt_rand(1,$MAX['rubdocs']), 'comment' => "commen't $i", 'link' => $link, 'notepad' => "notes document' $i"))); $DOCUMENTS[$docID] = $ID_entity."-0"; } // Global ones for ($i=0 ; $i<$MAX['document']/2 ; $i++) { $link = ""; if (mt_rand(0,100)<50) { $link = "http://linktodoc/doc$i"; } $docID = $doc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "Recursive document' $i-$ID_entity", 'documentcategories_id' => mt_rand(1,$MAX['rubdocs']), 'comment' => "comment' $i", 'link' => $link, 'notepad' => "notes document' $i"))); $DOCUMENTS[$docID] = $ID_entity."-1"; } $LAST["document"] = getMaxItem("glpi_documents"); // Ajout budgets specific $FIRST["budget"] = getMaxItem("glpi_budgets")+1; $b = new Budget(); for ($i=0 ; $i<$MAX['budget'] ; $i++) { $date1 = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28)); $date2 = $date1+MONTH_TIMESTAMP*12*mt_rand(1,4); // + entre 1 et 4 ans $b->add(toolbox::addslashes_deep( array('name' => "budget' $i-$ID_entity", 'entities_id' => $ID_entity, 'is_recusive' => 0, 'comment' => "comment' $i-$ID_entity", 'begin_date' => date("Y-m-d",intval($date1)), 'end_date' => date("Y-m-d",intval($date2))))); } $LAST["budget"] = getMaxItem("glpi_budgets"); // GLobal ones for ($i=0 ; $i<$MAX['document']/2 ; $i++) { $date1 = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28)); $date2 = $date1+MONTH_TIMESTAMP*12*mt_rand(1,4); // + entre 1 et 4 ans $b->add(toolbox::addslashes_deep( array('name' => "Recursive budget' $i-$ID_entity", 'entities_id' => $ID_entity, 'is_recusive' => 1, 'comment' => "comment' $i-$ID_entity", 'begin_date' => date("Y-m-d",intval($date1)), 'end_date' => date("Y-m-d",intval($date2))))); } $LAST["document"] = getMaxItem("glpi_documents"); // glpi_suppliers $items = array("DELL", "IBM", "ACER", "Microsoft", "Epson", "Xerox", "Hewlett Packard", "Nikon", "Targus", "LG", "Samsung", "Lexmark"); $FIRST["enterprises"] = getMaxItem("glpi_suppliers")+1; $ent = new Supplier(); // Global ones for ($i=0 ; $i<$MAX['enterprises']/2 ; $i++) { if (isset($items[$i])) { $val = "Recursive ".$items[$i]; } else { $val = "Recursive enterprise_".$i."_ID_entity"; } $entID = $ent->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "Recursive' $val-$ID_entity", 'suppliertypes_id' => mt_rand(1,$MAX['enttype']), 'address' => "address' $i", 'postcode' => "postcode $i", 'town' => "town' $i", 'state' => "state' $i", 'country' => "country $i", 'website' => "http://www.$val.com/", 'fax' => "fax $i", 'email' => "info@ent$i.com", 'notepad' => "notes enterprises' $i"))); addDocuments('Supplier', $entID); } // Specific ones for ($i=0 ; $i<$MAX['enterprises'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "enterprise_".$i."_ID_entity"; } $entID = $ent->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 0, 'name' => "'$val-$ID_entity", 'suppliertypes_id' => mt_rand(1,$MAX['enttype']), 'address' => "address' $i", 'postcode' => "postcode $i", 'town' => "town' $i", 'state' => "state' $i", 'country' => "country $i", 'website' => "http://www.$val.com/", 'fax' => "fax $i", 'email' => "info@ent$i.com", 'notepad' => "notes supplier' $i", 'comment' => "comment supplier' $i"))); addDocuments('Supplier', $entID); } $LAST["enterprises"] = getMaxItem("glpi_suppliers"); // Ajout contracts $FIRST["contract"] = getMaxItem("glpi_contracts")+1; $c = new Contract(); $cs = new Contract_Supplier(); $cc = new ContractCost(); // Specific for ($i=0 ; $i<$MAX['contract'] ; $i++) { $date = mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28); $contractID = $c->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 0, 'name' => "contract' $i-$ID_entity", 'num' => "num' $i", 'contracttypes_id' => mt_rand(1,$MAX['contract_type']), 'begin_date' => $date, 'duration' => mt_rand(1,36), 'notice' => mt_rand(1,3), 'periodicity' => mt_rand(1,36), 'billing' => mt_rand(1,36), 'comment' => "comment' $i", 'accounting_number' => "compta num' $i", 'renewal' => 1))); addDocuments('Contract', $contractID); // Add an enterprise $cs->add(array('contracts_id' => $contractID, 'suppliers_id' => mt_rand($FIRST["enterprises"], $LAST["enterprises"]))); // Add a cost $cc->add(toolbox::addslashes_deep( array('contracts_id' => $contractID, 'cost' => mt_rand(100,10000), 'name' => "Initial 'cost", 'begin_date' => $date, 'budgets_id' => mt_rand($FIRST['budget'], $LAST['budget'])))); } for ($i=0 ; $i<$MAX['contract']/2 ; $i++) { $date = mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28); $contractID = $c->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "Recursive contract' $i-$ID_entity", 'num' => "num' $i", 'cost' => mt_rand(100,10000), 'contracttypes_id' => mt_rand(1,$MAX['contract_type']), 'begin_date' => $date, 'duration' => mt_rand(1,36), 'notice' => mt_rand(1,3), 'periodicity' => mt_rand(1,36), 'billing' => mt_rand(1,36), 'comment' => "comment' $i", 'accounting_number' => "compta num' $i", 'renewal' => 1))); addDocuments('Contract', $contractID); // Add an enterprise $cs->add(array('contracts_id' => $contractID, 'suppliers_id' => mt_rand($FIRST["enterprises"], $LAST["enterprises"]))); } $LAST["contract"] = getMaxItem("glpi_contracts"); // Ajout contacts $prenoms = array("Jean", "John", "Louis", "Pierre", "Auguste", "Albert", "Julien", "Guillaume", "Bruno", "Maurice", "Francois", "Laurent", "Richard", "Henri", "Clement", "d'avy"); $noms = array("Dupont", "Smith", "Durand", "Martin", "Dubois", "Dufour", "Dupin", "Duval", "Petit", "Grange", "Bernard", "Bonnet", "Richard", "Leroy", "Dumont", "Fontaine", "d'orleans"); $FIRST["contacts"] = getMaxItem("glpi_contacts")+1; $c = new Contact(); $cs = new Contact_Supplier(); for ($i=0 ; $i<$MAX['contacts'] ; $i++) { if (isset($noms[$i])) { $val = $noms[$i]; } else { $val = "name $i"; } if (isset($prenoms[$i])) { $val2 = $prenoms[$i]; } else { $val2 = "firstname $i"; } $contactID = $c->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 0, 'name' => "$val-$ID_entity", 'firstname' => $val2, 'contacttypes_id' => mt_rand(1,$MAX['contact_type']), 'usertitles_id' => mt_rand(0,$MAX['user_title']), 'phone' => "phone $i", 'phone2' => "phone2 $i", 'mobile' => "mobile $i", 'fax' => "fax $i", 'email' => "email $i", 'address' => "address' $i", 'postcode' => "postcode $i", 'town' => "town' $i", 'state' => "state' $i", 'country' => "country $i", 'comment' => "Comment' $i"))); // Link with enterprise $cs->add(array('contacts_id' => $contactID, 'suppliers_id' => mt_rand($FIRST['enterprises'],$LAST['enterprises']))); } for ($i=0 ; $i<$MAX['contacts']/2 ; $i++) { if (isset($items[$i])) { $val = "Recursive ".$items[$i]; } else { $val = "Recursive contact $i"; } $contactID = $c->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 0, 'name' => "$val'-$ID_entity", 'contacttypes_id' => mt_rand(1,$MAX['contact_type']), 'usertitles_id' => mt_rand(0,$MAX['user_title']), 'phone' => "phone $i", 'phone2' => "phone2 $i", 'mobile' => "mobile $i", 'fax' => "fax $i", 'email' => "email $i", 'address' => "address' $i", 'postcode' => "postcode $i", 'town' => "town' $i", 'state' => "state' $i", 'country' => "country $i", 'comment' => "Comment' $i"))); // Link with enterprise $cs->add(array('contacts_id' => $contactID, 'suppliers_id' => mt_rand($FIRST['enterprises'],$LAST['enterprises']))); } $LAST["contacts"] = getMaxItem("glpi_contacts"); // TYPE DE CONSOMMABLES $FIRST["type_of_consumables"] = getMaxItem("glpi_consumableitems")+1; $ci = new Consumableitem(); for ($i=0 ; $i<$MAX['type_of_consumables'] ; $i++) { $consID = $ci->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => mt_rand(0,1), 'name' => "consumable type' $i", 'ref' => "ref d' $i", 'locations_id' => mt_rand($FIRST["locations"], $LAST['locations']), 'consumableitemtypes_id' => mt_rand(0,$MAX['consumable_type']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'users_id_tech' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin']), 'groups_id_tech' => mt_rand($FIRST["groups"], $LAST["groups"]), 'comment' => "comment' $i", 'notepad' => "notes consumableitem' $i", 'alarm_threshold' => mt_rand(0,10)))); addDocuments('ConsumableItem', $consID); // AJOUT INFOCOMS addInfocoms('ConsumableItem', $consID, $ID_entity); // Ajout consommable en stock $c = new Consumable(); for ($j=0 ; $j<mt_rand(0,$MAX['consumables_stock']) ; $j++) { $date = mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28); $ID = $c->add(array('entities_id' => $ID_entity, 'consumableitems_id' => $consID, 'date_in' => $date)); // AJOUT INFOCOMS addInfocoms('Consumable', $ID, $ID_entity); } // Ajout consommable donne for ($j=0 ; $j<mt_rand(0,$MAX['consumables_given']) ; $j++) { $date = mt_rand(2000,$current_year-1)."-".mt_rand(1,12)."-".mt_rand(1,28); $ID = $c->add(array('entities_id' => $ID_entity, 'consumableitems_id' => $consID, 'date_in' => $date, 'date_out' => date("Y-m-d"))); // AJOUT INFOCOMS addInfocoms('Consumable', $ID, $ID_entity); } } $LAST["type_of_consumables"] = getMaxItem("glpi_consumableitems"); // TYPE DE CARTOUCHES $FIRST["type_of_cartridges"] = getMaxItem("glpi_cartridgeitems")+1; $ct = new CartridgeItem(); for ($i=0 ; $i<$MAX['type_of_cartridges'] ; $i++) { $cartID = $ct->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => mt_rand(0,1), 'name' => "cartridge ' type $i", 'ref' => "ref '$i", 'locations_id' => mt_rand($FIRST["locations"], $LAST['locations']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'users_id_tech' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin']), 'groups_id_tech' => mt_rand($FIRST["groups"], $LAST["groups"]), 'comment' => "comment '$i", 'notepad' => "notes cartridgeitem '$i", 'alarm_threshold' => mt_rand(0,10)))); addDocuments('CartridgeItem', $cartID); // AJOUT INFOCOMS addInfocoms('CartridgeItem', $cartID, $ID_entity); $c = new Cartridge(); $cipm = new CartridgeItem_PrinterModel(); // Ajout cartouche en stock for ($j=0 ; $j<mt_rand(0,$MAX['cartridges_stock']) ; $j++) { $date = mt_rand(2000,$current_year-1)."-".mt_rand(1,12)."-".mt_rand(1,28); $ID = $c->add(array('entities_id' => $ID_entity, 'cartridgeitems_id' => $cartID, 'date_in' => $date)); // AJOUT INFOCOMS addInfocoms('Cartridge', $ID, $ID_entity); } // Assoc printer type to cartridge type $cipm->add(array('cartridgeitems_id' => $cartID, 'printermodels_id' => mt_rand(1,$MAX['type_printers']), )); } $LAST["type_of_cartridges"] = getMaxItem("glpi_cartridgeitems"); // Networking $NET_LOC = array(); $FIRST["networking"] = getMaxItem("glpi_networkequipments")+1; $FIRST["printers"] = getMaxItem("glpi_printers")+1; $ne = new NetworkEquipment(); $p = new Printer(); $np = new Netpoint(); $c = new Cartridge(); foreach ($DB->request('glpi_locations') as $data) { $i = $data["id"]; $techID = mt_rand($FIRST['users_sadmin'],$LAST['users_admin']); $gtechID = mt_rand($FIRST["techgroups"],$LAST["techgroups"]); $infoIP = getNextIP(); $domainID = mt_rand($FIRST['domain'],$LAST['domain']); $networkID = mt_rand(1,$MAX['network']); // insert networking $netwID = $ne->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "networking '$i-$ID_entity", 'ram' => mt_rand(32,256), 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact '$i", 'contact_num' => "num '$i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'comment' => "comment '$i", 'locations_id' => $i, 'domains_id' => $domainID, 'networks_id' => $networkID, 'networkequipmenttypes_id' => mt_rand(1,$MAX['type_networking']), 'networkequipmentmodels_id' => mt_rand(1,$MAX['model_networking']), 'networkequipmentfirmwares_id' => mt_rand(1,$MAX['firmware']), 'manufacturers_id' => mt_rand(1,$MAX['enterprises']), 'mac' => getNextMAC(), 'ip' => $infoIP["ip"], 'notepad' => "notes networking '$i", 'users_id' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin']), 'groups_id' => mt_rand($FIRST["groups"], $LAST["groups"]), 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); $NET_LOC[$data['id']] = $netwID; addDocuments('NetworkEquipment', $netwID); addContracts('NetworkEquipment', $netwID); // AJOUT INFOCOMS addInfocoms('NetworkEquipment', $netwID, $ID_entity); // Link with father addNetworkEthernetPort('NetworkEquipment', $netwID, $ID_entity, $i); // Ajout imprimantes reseaux : 1 par loc + connexion d un matos reseau + ajout de cartouches // Add trackings addTracking('NetworkEquipment', $netwID, $ID_entity); $typeID = mt_rand(1,$MAX['type_printers']); $modelID = mt_rand(1,$MAX['model_printers']); $recur = mt_rand(0,1); $printID = $p->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => $recur, 'name' => "printer of loc '$i", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact '$i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'have_serial' => mt_rand(0,1), 'have_parallel' => mt_rand(0,1), 'have_usb' => mt_rand(0,1), 'have_wifi' => mt_rand(0,1), 'have_ethernet' => mt_rand(0,1), 'comment' => "comment' $i", 'memory_size' => mt_rand(0,128), 'locations_id' => $i, 'domains_id' => $domainID, 'networks_id' => $networkID, 'printertypes_id' => $typeID, 'printermodels_id' => $modelID, 'manufacturers_id' => mt_rand(1,$MAX['enterprises']), 'is_global' => 1, 'notepad' => "notes printers '$i", 'users_id' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin']), 'groups_id' => mt_rand($FIRST["groups"], $LAST["groups"]), 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); addDocuments('Printer', $printID); addContracts('Printer', $printID); // Add trackings addTracking('Printer', $printID, $ID_entity); // AJOUT INFOCOMS addInfocoms('Printer', $printID, $ID_entity, $recur); // Add Cartouches // Get compatible cartridge $query = "SELECT `cartridgeitems_id` FROM `glpi_cartridgeitems_printermodels` WHERE `printermodels_id` = '$typeID'"; $result2 = $DB->query($query) or die("PB REQUETE ".$query); if ($DB->numrows($result2)>0) { $ctypeID = $DB->result($result2,0,0) or die (" PB RESULT ".$query); $printed = 0; $oldnb = mt_rand(1,$MAX['cartridges_by_printer']); $date1 = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28)); $date2 = time(); $inter = abs(round(($date2-$date1)/$oldnb)); // Add old cartridges for ($j=0 ; $j<$oldnb ; $j++) { $printed += mt_rand(0,5000); $c->add(array('entities_id' => $ID_entity, 'cartridgeitems_id' => $ctypeID, 'printers_id' => $printID, 'date_in' => date("Y-m-d",$date1), 'date_use' => date("Y-m-d",$date1+$j*$inter), 'date_out' => date("Y-m-d",$date1+($j+1)*$inter), 'pages' => $printed)); } // Add current cartridges $c->add(array('entities_id' => $ID_entity, 'cartridgeitems_id' => $ctypeID, 'printers_id' => $printID, 'date_in' => $date, 'date_use' => date("Y-m-d",$date2))); } $iface = mt_rand(1,$MAX['iface']); // Add networking ports addNetworkEthernetPort('Printer', $printID, $ID_entity, $i); } unset($NET_LOC); $LAST["networking"] = getMaxItem("glpi_networkequipments"); //////////// INVENTORY // glpi_computers $FIRST["computers"] = getMaxItem("glpi_computers")+1; $FIRST["monitors"] = getMaxItem("glpi_monitors")+1; $FIRST["phones"] = getMaxItem("glpi_phones")+1; $FIRST["peripherals"] = getMaxItem("glpi_peripherals")+1; $c = new Computer(); $mon = new Monitor(); $cdevmb = new Item_DeviceMotherBoard(); $cdevproc = new Item_DeviceProcessor(); $cdevmem = new Item_DeviceMemory(); $cdevhd = new Item_DeviceHardDrive(); $cdevnc = new Item_DeviceNetworkCard(); $cdevdr = new Item_DeviceDrive(); $cdevcon = new Item_DeviceControl(); $cdevgc = new Item_DeviceGraphicCard(); $cdevsc = new Item_DeviceSoundCard(); $cdevpci = new Item_DevicePci(); $cdevcase = new Item_DeviceCase(); $cdevps = new Item_DevicePowerSupply(); $cdisk = new ComputerDisk(); $np = new Netpoint(); $ci = new Computer_Item(); $phone = new Phone(); $print = new Printer(); $periph = new Peripheral(); $cart = new Cartridge(); for ($i=0 ; $i<$MAX['computers'] ; $i++) { $loc = mt_rand($FIRST["locations"],$LAST['locations']); $techID = mt_rand($FIRST['users_sadmin'],$LAST['users_admin']); $userID = mt_rand($FIRST['users_normal'],$LAST['users_postonly']); $groupID = mt_rand($FIRST["groups"],$LAST["groups"]); $gtechID = mt_rand($FIRST["techgroups"],$LAST["techgroups"]); $domainID = mt_rand($FIRST['domain'],$LAST['domain']); $networkID = mt_rand(1,$MAX['network']); $compID = $c->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "computer ' $i-$ID_entity", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact' $i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'comment' => "comment' $i", 'operatingsystems_id' => mt_rand(1,$MAX['os']), 'operatingsystemversions_id' => mt_rand(1,$MAX['os_version']), 'operatingsystemservicepacks_id' => mt_rand(1,$MAX['os_sp']), 'os_license_number' => "os sn $i", 'os_licenseid' => "os id $i", 'autoupdatesystems_id' => mt_rand(1,$MAX['os_sp']), 'locations_id' => $loc, 'domains_id' => $domainID, 'networks_id' => $networkID, 'computertypes_id' => mt_rand(1,$MAX['type_computers']), 'computermodels_id' => mt_rand(1,$MAX['model']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'is_global' => 1, 'notepad' => "notes computer '$i", 'users_id' => $userID, 'groups_id' => $groupID, 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0), 'uuid' => Toolbox::getRandomString(30) ))); addDocuments('Computer', $compID); addContracts('Computer', $compID); $NET_PORT['Computer'][$compID] = 0; // Add trackings addTracking('Computer', $compID, $ID_entity); // Add reservation addReservation('Computer', $compID, $ID_entity); // AJOUT INFOCOMS addInfocoms('Computer', $compID, $ID_entity); // ADD DEVICE $cdevmb->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15))); $max = mt_rand(1,4); $devid = mt_rand(1,$MAX['device']); for($nb = 0; $nb<$max; $nb++) { $cdevproc->addDevices(1, 'Computer', $compID, $devid, array('serial' => Toolbox::getRandomString(15))); } $max = mt_rand(1,4); $devid = mt_rand(1,$MAX['device']); for($nb = 0; $nb<$max; $nb++) { $cdevmem->addDevices(1, 'Computer', $compID, $devid, array('serial' => Toolbox::getRandomString(15))); } $max = mt_rand(1,2); $devid = mt_rand(1,$MAX['device']); for($nb = 0; $nb<$max; $nb++) { $cdevhd->addDevices(1, 'Computer', $compID, $devid, array('serial' => Toolbox::getRandomString(15))); } $cdevnc->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15), 'mac' => getNextMAC())); $cdevdr->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15))); $cdevcon->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15))); $cdevgc->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15))); $cdevsc->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15))); $max = mt_rand(1,4); for($nb = 0; $nb<$max; $nb++) { $cdevpci->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15))); } $cdevcase->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial'=> Toolbox::getRandomString(15))); $max = mt_rand(1,2); $devid = mt_rand(1,$MAX['device']); for($nb = 0; $nb<$max; $nb++) { $cdevps->addDevices(1, 'Computer', $compID, $devid, array('serial' => Toolbox::getRandomString(15))); } // insert disk $nb_disk = mt_rand(1,$MAX_DISK); for ($j=1 ; $j<=$nb_disk ; $j++) { $totalsize = mt_rand(10000,1000000); $freesize = mt_rand(0,$totalsize); $cdisk->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'computers_id' => $compID, 'name' => "disk '$j", 'device' => "/dev/disk$j", 'mountpoint' => "/mnt/disk$j", 'filesystems_id' => mt_rand(1,10), 'totalsize' => $totalsize, 'freesize' => $freesize))); } // Add networking ports addNetworkEthernetPort('Computer', $compID, $ID_entity, $loc); // Ajout d'un ecran sur l'ordi $monID = $mon->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "monitor' $i-$ID_entity", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact' $i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'comment' => "comment' $i", 'size' => mt_rand(14,22), 'have_micro' => mt_rand(0,1), 'have_speaker' => mt_rand(0,1), 'have_subd' => mt_rand(0,1), 'have_bnc' => mt_rand(0,1), 'have_dvi' => mt_rand(0,1), 'have_pivot' => mt_rand(0,1), 'have_hdmi' => mt_rand(0,1), 'have_displayport' => mt_rand(0,1), 'locations_id' => $loc, 'monitortypes_id' => mt_rand(1,$MAX['type_monitors']), 'monitormodels_id' => mt_rand(1,$MAX['model_monitors']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'notepad' => "notes monitor' $i", 'users_id' => $userID, 'groups_id' => $groupID, 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); addDocuments('Monitor', $monID); addContracts('Monitor', $monID); // Add trackings addTracking('Monitor', $monID, $ID_entity); // AJOUT INFOCOMS addInfocoms('Monitor', $monID, $ID_entity); $ci->add(array('itemtype' => 'Monitor', 'items_id' => $monID, 'computers_id' => $compID, )); // Ajout d'un telephhone avec l'ordi $telID = $phone->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "phone' $i-$ID_entity", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact' $i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'comment' => "comment' $i", 'firmware' => Toolbox::getRandomString(10), 'brand' => "brand' $i", 'phonepowersupplies_id' => mt_rand(0,$MAX['phone_power']), 'number_line' => Toolbox::getRandomString(10), 'have_headset' => mt_rand(0,1), 'have_hp' => mt_rand(0,1), 'locations_id' => $loc, 'phonetypes_id' => mt_rand(1,$MAX['type_phones']), 'phonemodels_id' => mt_rand(1,$MAX['model_phones']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'notepad' => "notes phone' $i", 'users_id' => $userID, 'groups_id' => $groupID, 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); addDocuments('Phone', $telID); addContracts('Phone', $telID); // Add trackings addTracking('Phone', $telID, $ID_entity); // AJOUT INFOCOMS addInfocoms('Phone', $telID, $ID_entity); $ci->add(array('itemtype' => 'Phone', 'items_id' => $telID, 'computers_id' => $compID)); // Ajout des periphs externes en connection directe while (mt_rand(0,100)<$percent['peripherals']) { $periphID = $periph->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "periph of comp' $i-$ID_entity", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact' $i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'comment' => "comment' $i", 'brand' => "brand' $i", 'locations_id' => $loc, 'phonetypes_id' => mt_rand(1,$MAX['type_peripherals']), 'phonemodels_id' => mt_rand(1,$MAX['model_peripherals']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'notepad' => "notes peripheral' $i", 'users_id' => $userID, 'groups_id' => $groupID, 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); addDocuments('Peripheral', $periphID); addContracts('Peripheral', $periphID); // Add trackings addTracking('Peripheral', $periphID, $ID_entity); // Add connection $ci->add(array('itemtype' => 'Peripheral', 'items_id' => $periphID, 'computers_id' => $compID)); } // Ajout d'une imprimante connection directe pour X% des computers + ajout de cartouches if (mt_rand(0,100)<=$percent['printer']) { // Add printer $typeID = mt_rand(1,$MAX['type_printers']); $modelID = mt_rand(1,$MAX['model_printers']); $printID = $p->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "printer of comp' $i-$ID_entity", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact' $i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'have_serial' => mt_rand(0,1), 'have_parallel' => mt_rand(0,1), 'have_usb' => mt_rand(0,1), 'have_wifi' => mt_rand(0,1), 'have_ethernet' => mt_rand(0,1), 'comment' => "comment' $i", 'memory_size' => mt_rand(0,128), 'locations_id' => $loc, 'domains_id' => $domainID, 'networks_id' => $networkID, 'printertypes_id' => $typeID, 'printermodels_id' => $modelID, 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'notepad' => "notes printers '$i", 'users_id' => mt_rand($FIRST['users_postonly'], $LAST['users_postonly']), 'groups_id' => mt_rand($FIRST["groups"], $LAST["groups"]), 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); addDocuments('Printer', $printID); addContracts('Printer', $printID); // Add trackings addTracking('Printer', $printID, $ID_entity); // Add connection $ci->add(array('itemtype' => 'Printer', 'items_id' => $printID, 'computers_id' => $compID)); // AJOUT INFOCOMS addInfocoms('Printer', $printID, $ID_entity); // Add Cartouches // Get compatible cartridge $query = "SELECT `cartridgeitems_id` FROM `glpi_cartridgeitems_printermodels` WHERE `printermodels_id` = '$typeID'"; $result = $DB->query($query) or die("PB REQUETE ".$query); if ($DB->numrows($result)>0) { $ctypeID = $DB->result($result,0,0) or die (" PB RESULT ".$query); $printed = 0; $oldnb = mt_rand(1,$MAX['cartridges_by_printer']); $date1 = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28)); $date2 = time(); $inter = round(($date2-$date1)/$oldnb); // Add old cartridges for ($j=0 ; $j<$oldnb ; $j++) { $printed += mt_rand(0,5000); $cart->add(array('entities_id' => $ID_entity, 'cartridgeitems_id' => $ctypeID, 'printers_id' => $printID, 'date_in' => date("Y-m-d",$date1), 'date_use' => date("Y-m-d",$date1+$j*$inter), 'date_out' => date("Y-m-d",$date1+($j+1)*$inter), 'pages' => $printed)); } // Add current cartridges $cart->add(array('entities_id' => $ID_entity, 'cartridgeitems_id' => $ctypeID, 'printers_id' => $printID, 'date_in' => date("Y-m-d",$date1), 'date_use' => date("Y-m-d",$date2))); } } } $LAST["computers"] = getMaxItem("glpi_computers"); $LAST["monitors"] = getMaxItem("glpi_monitors"); $LAST["phones"] = getMaxItem("glpi_phones"); // Add global peripherals $periph = new Peripheral(); $ci = new Computer_Item(); for ($i=0 ; $i<$MAX['global_peripherals'] ; $i++) { $techID = mt_rand($FIRST['users_sadmin'],$LAST['users_admin']); $gtechID = mt_rand($FIRST["techgroups"],$LAST["techgroups"]); $periphID = $periph->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "periph '$i-$ID_entity", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact' $i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'comment' => "comment' $i", 'brand' => "brand' $i", 'locations_id' => $loc, 'phonetypes_id' => mt_rand(1,$MAX['type_peripherals']), 'phonemodels_id' => mt_rand(1,$MAX['model_peripherals']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'is_global' => 1, 'notepad' => "notes peripheral' $i", 'users_id' => mt_rand($FIRST['users_normal'], $LAST['users_normal']), 'groups_id' => mt_rand($FIRST["groups"], $LAST["groups"]), 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); addDocuments('Peripheral', $periphID); addContracts('Peripheral', $periphID); // Add trackings addTracking('Peripheral', $periphID, $ID_entity); // Add reservation addReservation('Peripheral', $periphID, $ID_entity); // AJOUT INFOCOMS addInfocoms('Peripheral', $periphID, $ID_entity); // Add connections $val = mt_rand(1,$MAX['connect_for_peripherals']); for ($j=1 ; $j<$val ; $j++) { $ci->add(array('itemtype' => 'Peripheral', 'items_id' => $periphID, 'computers_id' => mt_rand($FIRST["computers"],$LAST['computers']))); } } $LAST["peripherals"] = getMaxItem("glpi_peripherals"); $FIRST["software"] = getMaxItem("glpi_softwares")+1; // Ajout logiciels + licences associees a divers PCs $items = array(array("Open'Office", "1.1.4", "2.0", "2.0.1"), array("Microsoft Office", "95", "97", "XP", "2000", "2003", "2007"), array("Acrobat Reader", "6.0", "7.0", "7.04"), array("Gimp", "2.0", "2.2"), array("InkScape", "0.4")); $soft = new Software(); $softvers = new SoftwareVersion(); $softlic = new SoftwareLicense(); $csv = new Computer_SoftwareVersion(); $csl = new Computer_SoftwareLicense(); for ($i=0 ; $i<$MAX['software'] ; $i++) { if (isset($items[$i])) { $name = $items[$i][0]; } else { $name = "software '$i"; } $loc = mt_rand(1,$MAX['locations']); $techID = mt_rand($FIRST['users_sadmin'],$LAST['users_admin']); $gtechID = mt_rand($FIRST["techgroups"],$LAST["techgroups"]); $recursive = mt_rand(0,1); $softID = $soft->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => $recursive, 'name' => $name, 'comment' => "comment '$i", 'locations_id' => $loc, 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'notepad' => "notes software '$i", 'users_id' => mt_rand($FIRST['users_admin'], $LAST['users_admin']), 'groups_id' => mt_rand($FIRST["groups"], $LAST["groups"]), 'is_helpdesk_visible' => 1, 'softwarecategories_id' => mt_rand(1,$MAX['softwarecategory']) ))); addDocuments('Software', $softID); addContracts('Software', $softID); // Add trackings addTracking('Software', $softID, $ID_entity); // AJOUT INFOCOMS addInfocoms('Software', $softID, $ID_entity); // Add versions $FIRST["version"] = getMaxItem("glpi_softwareversions")+1; if (isset($items[$i])) { $val2 = count($items[$i]); } else { $val2 = mt_rand(1,$MAX['softwareversions']+1); } for ($j=1 ; $j<=$val2 ; $j++) { if (isset($items[$i])) { $version = $items[$i][mt_rand(1,count($items[$i])-1)]; } else { $version = "$j.0"; } $os = mt_rand(1,$MAX['os']); $versID = $softvers->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => $recursive, 'softwares_id' => $softID, 'name' => $version, 'comment' => "comment '$version", 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0), 'operatingsystems_id' => $os))); $val3 = min($LAST["computers"]-$FIRST['computers'], mt_rand(1,$MAX['softwareinstall'])); $comp_id = mt_rand($FIRST["computers"], $LAST['computers']); for ($k=0 ; $k<$val3 ; $k++) { $comp_id++; if ($comp_id>$LAST["computers"]) { $comp_id = $FIRST["computers"]; } $csv->add(array('computers_id' => $comp_id, 'softwareversions_id' => $versID)); } } $LAST["version"] = getMaxItem("glpi_softwareversions"); // Add licenses $val2 = mt_rand(1,$MAX['softwarelicenses']); for ($j=0 ; $j<$val2 ; $j++) { $softwareversions_id_buy = mt_rand($FIRST["version"],$LAST["version"]); $softwareversions_id_use = mt_rand($softwareversions_id_buy,$LAST["version"]); $nbused = min($LAST["computers"]-$FIRST['computers'], mt_rand(1,$MAX['softwareinstall'])); $licID = $softlic->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => $recursive, 'softwares_id' => $softID, 'number' => $nbused, 'softwarelicensetypes_id' => mt_rand(1,$MAX['licensetype']), 'name' => "license '$j", 'serial' => "serial $j", 'otherserial' => "otherserial $j", 'comment' => "comment license '$j", 'softwareversions_id_buy' => $softwareversions_id_buy, 'softwareversions_id_use' => $softwareversions_id_use))); $comp_id = mt_rand($FIRST["computers"], $LAST['computers']); for ($k=0 ; $k<$nbused ; $k++) { $comp_id++; if ($comp_id>$LAST["computers"]) { $comp_id = $FIRST["computers"]; } $csl->add(array('computers_id' => $comp_id, 'softwarelicenses_id' => $licID)); } } } $LAST["software"] = getMaxItem("glpi_softwares"); }
public static function add_group() { if (Auth::check()) { $name = $_POST['name']; $status = $_POST['status']; if (isset($name) && isset($status) && (!empty($name) && !empty($status))) { $getResponse = get_object_vars(Group::where("group_name='{$name}'")); if (!$getResponse['data']) { $ob = new Group(); $ob->group_name = $name; $ob->statut = $status; if ($ob->add()) { echo "ok"; } else { echo "Erreur au niveau du modification"; } } } } else { $redirection = Config::get('app.base_url') . Config::get('panel.route') . "/users"; header("Location: {$redirection}"); } }
} if (!$valt->validate('add_or_update_group')) { $error[] = $valt->getErrorMessage(); } $g1 = Group::getByName($gName); if ($g1 instanceof Group) { if ((!is_object($g)) || $g->getGroupID() != $g1->getGroupID()) { $error[] = t('A group named "%s" already exists', $g1->getGroupName()); } } if (count($error) == 0) { if ($_POST['add']) { $g = Group::add($gName, $_POST['gDescription']); checkExpirationOptions($g); $this->controller->redirect('/dashboard/users/groups?created=1'); } else if (is_object($g)) { $g->update($gName, $_POST['gDescription']); checkExpirationOptions($g); $this->controller->redirect('/dashboard/users/groups?updated=1'); } exit; } } if ($_GET['created']) { $message = t("Group Created."); } else if ($_GET['updated']) {
$roomArray = Room::Search($building, $day, $hour, $size, $computer, $beamer, $pool, $looseSeating, $video); echo json_encode($roomArray); }); // === GROUPS === $app->put('/groups', function ($request, $response, $args) { $put = json_decode($request->getBody()); // make it a PHP associative array $putArray = get_object_vars($put); $members = array(); $tmpMembers = $putArray['users']; foreach ($tmpMembers as $tmpmember) { $member = get_object_vars($tmpmember); $members[] = new User($member['mtklNr'], '', '', ''); } $group = new Group(null, $putArray['name'], $putArray['owner'], $members, $putArray['groupImage']); $group->add(); echo json_encode($group); }); $app->get('/groups', function ($request, $response, $args) { $groups = Group::getAllGroups(); echo json_encode($groups); }); $app->get('/groups/{id}', function ($request, $response, $args) { $group = Group::getGroupById($args['id']); echo json_encode($group); }); $app->get('/groups/{id}/meetings', function ($request, $response, $args) { $meetings = Group::getAllMeetingsOfGroup($args['id']); echo json_encode($meetings); }); $app->post('/groups/{id}', function ($request, $response, $args) {
protected function importTaskPermissions(SimpleXMLElement $sx) { if (isset($sx->taskpermissions)) { foreach($sx->taskpermissions->taskpermission as $tp) { $pkg = ContentImporter::getPackageObject($tp['package']); $tpa = TaskPermission::addTask($tp['handle'], $tp['name'], $tp['description'], $pkg); if (isset($tp->access)) { foreach($tp->access->children() as $ch) { if ($ch->getName() == 'group') { $g = Group::getByName($ch['name']); if (!is_object($g)) { $g = Group::add($g['name'], $g['description']); } $tpa->addAccess($g); } } } } } }
return self::all(); } } class Test { } /** @section Обработка запросов */ $response = array(); $method = strtolower(_::str('method')); switch ($method) { /** @subsection Обработка запросов к Api */ case 'student.add': $response = Student::add(_::str('login'), _::str('password')); break; case 'group.add': $response = Group::add(_::str('name'), _::str('description')); break; case 'group.all': $response = Page::all(); break; case 'group.get': $response = Group::get(_::int('group')); break; case 'group.student': $response = Group::student(_::int('group'), _::int('student')); break; case 'group.notify': $response = Group::notify(_::int('group'), _::int('author'), _::str('header'), _::str('text')); break; case 'page.add': $response = Page::add(_::str('title'), _::raw('text'), _::int('author'));
public function add_users() { // insert the default groups // create the groups our site users // specify the ID's since auto increment may not always be +1 $g1 = Group::add(tc("GroupName", "Guest"), tc("GroupDescription", "The guest group represents unregistered visitors to your site."), GUEST_GROUP_ID); $g2 = Group::add(tc("GroupName", "Registered Users"), tc("GroupDescription", "The registered users group represents all user accounts."), REGISTERED_GROUP_ID); $g3 = Group::add(tc("GroupName", "Administrators"), "", ADMIN_GROUP_ID); // insert admin user into the user table if (defined('INSTALL_USER_PASSWORD')) { Loader::library('3rdparty/phpass/PasswordHash'); $hasher = new PasswordHash(PASSWORD_HASH_COST_LOG2, PASSWORD_HASH_PORTABLE); $uPassword = INSTALL_USER_PASSWORD; $uPasswordEncrypted = $hasher->HashPassword($uPassword); } else { $uPasswordEncrypted = INSTALL_USER_PASSWORD_HASH; } $uEmail = INSTALL_USER_EMAIL; UserInfo::addSuperUser($uPasswordEncrypted, $uEmail); $u = User::getByUserID(USER_SUPER_ID, true, false); Loader::library('mail/importer'); MailImporter::add(array('miHandle' => 'private_message')); }
/** * Import a group from OCS table. * * @param $value string : Value of the new dropdown. * @param $entities_id int : entity in case of specific dropdown * * @return integer : dropdown id. **/ static function importGroup($value, $entities_id) { global $DB; if (empty($value)) { return 0; } $query2 = "SELECT `id`\n FROM `glpi_groups`\n WHERE `name` = '{$value}'\n AND `entities_id` = '{$entities_id}'"; $result2 = $DB->query($query2); if ($DB->numrows($result2) == 0) { $group = new Group(); $input["name"] = $value; $input["entities_id"] = $entities_id; return $group->add($input); } $line2 = $DB->fetch_array($result2); return $line2["id"]; }
protected function importPermissions(SimpleXMLElement $sx) { if (isset($sx->permissionkeys)) { foreach($sx->permissionkeys->permissionkey as $pk) { $pkc = PermissionKeyCategory::getByHandle((string) $pk['category']); $pkg = ContentImporter::getPackageObject($pk['package']); $txt = Loader::helper('text'); $className = $txt->camelcase($pkc->getPermissionKeyCategoryHandle()); $c1 = $className . 'PermissionKey'; $pkx = call_user_func(array($c1, 'import'), $pk); if (isset($pk->access)) { foreach($pk->access->children() as $ch) { if ($ch->getName() == 'group') { $g = Group::getByName($ch['name']); if (!is_object($g)) { $g = Group::add($g['name'], $g['description']); } $pae = GroupPermissionAccessEntity::getOrCreate($g); $pa = PermissionAccess::create($pkx); $pa->addListItem($pae); $pt = $pkx->getPermissionAssignmentObject(); $pt->assignPermissionAccess($pa); } } } } } }
public function add_users() { // insert the default groups // create the groups our site users // have to add these in the right order so their IDs get set // starting at 1 w/autoincrement $g1 = Group::add(t("Guest"), t("The guest group represents unregistered visitors to your site.")); $g2 = Group::add(t("Registered Users"), t("The registered users group represents all user accounts.")); $g3 = Group::add(t("Administrators"), ""); // insert admin user into the user table if (defined('INSTALL_USER_PASSWORD')) { $uPassword = INSTALL_USER_PASSWORD; $uPasswordEncrypted = User::encryptPassword($uPassword, PASSWORD_SALT); } else { $uPasswordEncrypted = INSTALL_USER_PASSWORD_HASH; } $uEmail = INSTALL_USER_EMAIL; UserInfo::addSuperUser($uPasswordEncrypted, $uEmail); $u = User::getByUserID(USER_SUPER_ID, true, false); Loader::library('mail/importer'); MailImporter::add(array('miHandle' => 'private_message')); }
/** * Function: import_chyrp * Chyrp importing. */ public function import_chyrp() { if (empty($_POST)) { redirect("/admin/?action=import"); } if (!Visitor::current()->group->can("add_post")) { show_403(__("Access Denied"), __("You do not have sufficient privileges to import content.")); } if (isset($_FILES['posts_file']) and $_FILES['posts_file']['error'] == 0) { if (!($posts = simplexml_load_file($_FILES['posts_file']['tmp_name'])) or $posts->generator != "Chyrp") { Flash::warning(__("Chyrp Posts export file is invalid."), "/admin/?action=import"); } } if (isset($_FILES['pages_file']) and $_FILES['pages_file']['error'] == 0) { if (!($pages = simplexml_load_file($_FILES['pages_file']['tmp_name'])) or $pages->generator != "Chyrp") { Flash::warning(__("Chyrp Pages export file is invalid."), "/admin/?action=import"); } } if (ini_get("memory_limit") < 20) { ini_set("memory_limit", "20M"); } $trigger = Trigger::current(); $visitor = Visitor::current(); $sql = SQL::current(); function media_url_scan(&$value) { $config = Config::current(); $regexp_url = preg_quote($_POST['media_url'], "/"); if (preg_match_all("/{$regexp_url}([^\\.\\!,\\?;\"\\'<>\\(\\)\\[\\]\\{\\}\\s\t ]+)\\.([a-zA-Z0-9]+)/", $value, $media)) { foreach ($media[0] as $matched_url) { $filename = upload_from_url($matched_url); $value = str_replace($matched_url, $config->url . $config->uploads_path . $filename, $value); } } } if (isset($_FILES['groups_file']) and $_FILES['groups_file']['error'] == 0) { $import = YAML::load($_FILES['groups_file']['tmp_name']); foreach ($import["groups"] as $name => $permissions) { if (!$sql->count("groups", array("name" => $name))) { $trigger->call("import_chyrp_group", Group::add($name, (array) $permissions)); } } foreach ($import["permissions"] as $id => $name) { if (!$sql->count("permissions", array("id" => $id))) { $sql->insert("permissions", array("id" => $id, "name" => $name)); } } } if (isset($_FILES['users_file']) and $_FILES['users_file']['error'] == 0) { $users = YAML::load($_FILES['users_file']['tmp_name']); foreach ($users as $login => $user) { $group_id = $sql->select("groups", "id", array("name" => $user["group"]), "id DESC")->fetchColumn(); $group = $group_id ? $group_id : $config->default_group; if (!$sql->count("users", array("login" => $login))) { $user = User::add($login, $user["password"], $user["email"], $user["full_name"], $user["website"], $group, $user["joined_at"]); } $trigger->call("import_chyrp_user", $user); } } if (isset($_FILES['posts_file']) and $_FILES['posts_file']['error'] == 0) { foreach ($posts->entry as $entry) { $chyrp = $entry->children("http://chyrp.net/export/1.0/"); $login = $entry->author->children("http://chyrp.net/export/1.0/")->login; $user_id = $sql->select("users", "id", array("login" => $login), "id DESC")->fetchColumn(); $data = xml2arr($entry->content); $data["imported_from"] = "chyrp"; if (!empty($_POST['media_url'])) { array_walk_recursive($data, "media_url_scan"); } $post = Post::add($data, $chyrp->clean, Post::check_url($chyrp->url), $chyrp->feather, $user_id ? $user_id : $visitor->id, (bool) (int) $chyrp->pinned, $chyrp->status, datetime($entry->published), $entry->updated == $entry->published ? null : datetime($entry->updated), "", false); $trigger->call("import_chyrp_post", $entry, $post); } } if (isset($_FILES['pages_file']) and $_FILES['pages_file']['error'] == 0) { foreach ($pages->entry as $entry) { $chyrp = $entry->children("http://chyrp.net/export/1.0/"); $attr = $entry->attributes("http://chyrp.net/export/1.0/"); $login = $entry->author->children("http://chyrp.net/export/1.0/")->login; $user_id = $sql->select("users", "id", array("login" => $login), "id DESC")->fetchColumn(); $page = Page::add($entry->title, $entry->content, $user_id ? $user_id : $visitor->id, $attr->parent_id, (bool) (int) $chyrp->show_in_list, $chyrp->list_order, $chyrp->clean, Page::check_url($chyrp->url), datetime($entry->published), $entry->updated == $entry->published ? null : datetime($entry->updated)); $trigger->call("import_chyrp_page", $entry, $page); } } Flash::notice(__("Chyrp content successfully imported!"), "/admin/?action=import"); }
private function manageTicket($closed = true) { global $DB, $CFG_GLPI; $DB->connect(); $_SESSION['glpiactive_entity'] = 0; $CFG_GLPI['root_doc'] = "http://127.0.0.1/fusion0.83/"; $plugin = new Plugin(); $plugin->getFromDBbyDir("timelineticket"); $plugin->activate($plugin->fields['id']); Plugin::load("timelineticket"); Session::loadLanguage("en_GB"); $ticket = new Ticket(); $group = new Group(); $group_ticket = new Group_Ticket(); $GLPIlog = new GLPIlogs(); $ticket_User = new Ticket_User(); $_SESSION['plugin_timelineticket_date'] = array(); $group->add(array('name' => 'grtech1')); $group->add(array('name' => 'grtech2')); // * 01/ $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s"); $a_storedate = array('1' => $_SESSION["glpi_currenttime"]); $input = array(); $input['name'] = 'Pb with the ticket'; $input['content'] = 'I have a problem with the ticket'; $tickets_id = $ticket->add($input); $GLPIlog->testSQLlogs('01/'); $GLPIlog->testPHPlogs('01/'); // * 02/ sleep(2); // * 03/ $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s"); $a_storedate[3] = $_SESSION["glpi_currenttime"]; $input = array(); $input['id'] = $tickets_id; $input['_itil_assign']['_type'] = 'group'; $input['_itil_assign']['groups_id'] = 1; $ticket->update($input); $input['_itil_assign']['_type'] = 'user'; $input['_itil_assign']['users_id'] = 2; $ticket->update($input); $GLPIlog->testSQLlogs('03/'); $GLPIlog->testPHPlogs('03/'); $a_db = getAllDatasFromTable('glpi_groups_tickets'); $a_ref = array(); $a_ref[1] = array('id' => '1', 'tickets_id' => '1', 'groups_id' => '1', 'type' => '2'); $this->assertEquals($a_ref, $a_db, 'May have ticket assigned to group1'); $a_db = getAllDatasFromTable('glpi_tickets_users'); $a_ref = array(); $a_ref[1] = array('id' => '1', 'tickets_id' => '1', 'users_id' => '2', 'type' => '1', 'use_notification' => '1', 'alternative_email' => ''); $a_ref[2] = array('id' => '2', 'tickets_id' => '1', 'users_id' => '2', 'type' => '2', 'use_notification' => '1', 'alternative_email' => ''); $this->assertEquals($a_ref, $a_db, 'May have ticket assigned to user 2 (glpi)'); // * 04/ sleep(2); // * 05/ $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s"); $a_storedate[5] = $_SESSION["glpi_currenttime"]; $input = array(); $input['id'] = $tickets_id; $input['status'] = Ticket::WAITING; $ticket->update($input); $GLPIlog->testSQLlogs('05/'); $GLPIlog->testPHPlogs('05/'); $ticket->getFromDB(1); $this->assertEquals('waiting', $ticket->fields['status'], 'May have status waiting'); // * 06/ sleep(1); // * 07/ $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s"); $a_storedate[7] = $_SESSION["glpi_currenttime"]; $input = array(); $input['id'] = 2; $input['itickets_id'] = $tickets_id; $ticket_User->check($input['id'], 'w'); $ticket_User->delete($input); $input = array(); $input['id'] = 1; $input['itickets_id'] = $tickets_id; $group_ticket->check($input['id'], 'w'); $group_ticket->delete($input); $GLPIlog->testSQLlogs('07/'); $GLPIlog->testPHPlogs('07/'); $a_db = getAllDatasFromTable('glpi_groups_tickets'); $this->assertEquals(array(), $a_db, 'May have no group assigned'); // * 08/ sleep(1); // * 09/ $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s"); $a_storedate[9] = $_SESSION["glpi_currenttime"]; $input = array(); $input['id'] = $tickets_id; $input['_itil_assign']['_type'] = 'group'; $input['_itil_assign']['groups_id'] = 2; $ticket->update($input); $GLPIlog->testSQLlogs('09/'); $GLPIlog->testPHPlogs('09/'); $a_db = getAllDatasFromTable('glpi_groups_tickets'); $a_ref = array(); $a_ref[2] = array('id' => '2', 'tickets_id' => '1', 'groups_id' => '2', 'type' => '2'); $this->assertEquals($a_ref, $a_db, 'May have ticket assigned to group2'); $ticket->getFromDB(1); $this->assertEquals('assign', $ticket->fields['status'], '(09/) Status is assign'); // * 10/ sleep(1); // * 11/ $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s"); $a_storedate[11] = $_SESSION["glpi_currenttime"]; $input = array(); $input['id'] = $tickets_id; $input['status'] = Ticket::WAITING; $ticket->update($input); $input = array(); $input['id'] = $tickets_id; $input['_itil_assign']['_type'] = 'user'; $input['_itil_assign']['users_id'] = 4; $ticket->update($input); $GLPIlog->testSQLlogs('11/'); $GLPIlog->testPHPlogs('11/'); // * 12/ sleep(1); // * 13/ $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s"); $a_storedate[13] = $_SESSION["glpi_currenttime"]; $input = array(); $input['id'] = $tickets_id; $input['_itil_assign']['_type'] = 'group'; $input['_itil_assign']['groups_id'] = 1; $ticket->update($input); $input['_itil_assign']['_type'] = 'user'; $input['_itil_assign']['users_id'] = 2; $ticket->update($input); $GLPIlog->testSQLlogs('13/'); $GLPIlog->testPHPlogs('13/'); $ticket->getFromDB(1); $this->assertEquals('waiting', $ticket->fields['status'], '(13/)May have always status waiting'); // * 14/ $input = array(); $input['id'] = 2; $input['itickets_id'] = $tickets_id; $group_ticket->check($input['id'], 'w'); $group_ticket->delete($input); $GLPIlog->testSQLlogs('14/'); $GLPIlog->testPHPlogs('14/'); $a_db = getAllDatasFromTable('glpi_groups_tickets'); $a_ref = array(); $a_ref[3] = array('id' => '3', 'tickets_id' => '1', 'groups_id' => '1', 'type' => '2'); $this->assertEquals($a_ref, $a_db, '(14/) May have ticket assigned to group1'); $ticket->getFromDB(1); $this->assertEquals('waiting', $ticket->fields['status'], '(14/) Status is waiting'); // * 15/ sleep(2); // * 16/ $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s"); $a_storedate[16] = $_SESSION["glpi_currenttime"]; $input = array(); $input['id'] = $tickets_id; $input['status'] = Ticket::ASSIGNED; $ticket->update($input); $GLPIlog->testSQLlogs('16/'); $GLPIlog->testPHPlogs('16/'); // * 17/ sleep(1); // * 18/ $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s"); $a_storedate[18] = $_SESSION["glpi_currenttime"]; $input = array(); $input['id'] = $tickets_id; $input['solution'] = "solution"; $ticket->update($input); $GLPIlog->testSQLlogs('18/'); $GLPIlog->testPHPlogs('18/'); $ticket->getFromDB(1); $this->assertEquals('solved', $ticket->fields['status'], '(18/) Status is solved'); if ($closed) { // * 19/ sleep(1); // * 20/ $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s"); $a_storedate[20] = $_SESSION["glpi_currenttime"]; $fup = new TicketFollowup(); $input = array(); $input['tickets_id'] = $tickets_id; $input['add_close'] = 'add_close'; $fup->add($input); $GLPIlog->testSQLlogs('20/'); $GLPIlog->testPHPlogs('20/'); $ticket->getFromDB(1); $this->assertEquals('closed', $ticket->fields['status'], '(19/) Status is closed'); } self::$storedate = $a_storedate; }
/** Converts an array of parameters into a query string to be appended to a URL. * * @param $group_dn dn of the group to import * @param $options array for * - authldaps_id * - entities_id where group must to be imported * - is_recursive * * @return nothing **/ static function ldapImportGroup($group_dn, $options = array()) { $config_ldap = new self(); $res = $config_ldap->getFromDB($options['authldaps_id']); $ldap_users = array(); $group_dn = $group_dn; // we prevent some delay... if (!$res) { return false; } //Connect to the directory $ds = $config_ldap->connect(); if ($ds) { $group_infos = self::getGroupByDn($ds, stripslashes($group_dn)); $group = new Group(); if ($options['type'] == "groups") { return $group->add(array("name" => addslashes($group_infos["cn"][0]), "ldap_group_dn" => addslashes($group_infos["dn"]), "entities_id" => $options['entities_id'], "is_recursive" => $options['is_recursive'])); } return $group->add(array("name" => addslashes($group_infos["cn"][0]), "ldap_field" => $config_ldap->fields["group_field"], "ldap_value" => addslashes($group_infos["dn"]), "entities_id" => $options['entities_id'], "is_recursive" => $options['is_recursive'])); } return false; }
public function customerImport() { $customer_exist = false; $this->receiveTab(); $handle = $this->openCsvFile(); $default_language_id = (int) Configuration::get('PS_LANG_DEFAULT'); $id_lang = Language::getIdByIso(Tools::getValue('iso_lang')); if (!Validate::isUnsignedId($id_lang)) { $id_lang = $default_language_id; } AdminImportController::setLocale(); for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++) { if (Tools::getValue('convert')) { $line = $this->utf8EncodeArray($line); } $info = AdminImportController::getMaskedRow($line); AdminImportController::setDefaultValues($info); if (Tools::getValue('forceIDs') && isset($info['id']) && (int) $info['id']) { $customer = new Customer((int) $info['id']); } else { if (array_key_exists('id', $info) && (int) $info['id'] && Customer::customerIdExistsStatic((int) $info['id'])) { $customer = new Customer((int) $info['id']); } else { $customer = new Customer(); } } if (array_key_exists('id', $info) && (int) $info['id'] && Customer::customerIdExistsStatic((int) $info['id'])) { $current_id_customer = $customer->id; $current_id_shop = $customer->id_shop; $current_id_shop_group = $customer->id_shop_group; $customer_exist = true; $customer_groups = $customer->getGroups(); $addresses = $customer->getAddresses((int) Configuration::get('PS_LANG_DEFAULT')); } // Group Importation if (isset($info['group']) && !empty($info['group'])) { foreach (explode($this->multiple_value_separator, $info['group']) as $key => $group) { $group = trim($group); if (empty($group)) { continue; } $id_group = false; if (is_numeric($group) && $group) { $my_group = new Group((int) $group); if (Validate::isLoadedObject($my_group)) { $customer_groups[] = (int) $group; } continue; } $my_group = Group::searchByName($group); if (isset($my_group['id_group']) && $my_group['id_group']) { $id_group = (int) $my_group['id_group']; } if (!$id_group) { $my_group = new Group(); $my_group->name = array($id_lang => $group); if ($id_lang != $default_language_id) { $my_group->name = $my_group->name + array($default_language_id => $group); } $my_group->price_display_method = 1; $my_group->add(); if (Validate::isLoadedObject($my_group)) { $id_group = (int) $my_group->id; } } if ($id_group) { $customer_groups[] = (int) $id_group; } } } elseif (empty($info['group']) && isset($customer->id) && $customer->id) { $customer_groups = array(0 => Configuration::get('PS_CUSTOMER_GROUP')); } AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $customer); if ($customer->passwd) { $customer->passwd = Tools::encrypt($customer->passwd); } $id_shop_list = explode($this->multiple_value_separator, $customer->id_shop); $customers_shop = array(); $customers_shop['shared'] = array(); $default_shop = new Shop((int) Configuration::get('PS_SHOP_DEFAULT')); if (Shop::isFeatureActive() && $id_shop_list) { foreach ($id_shop_list as $id_shop) { if (empty($id_shop)) { continue; } $shop = new Shop((int) $id_shop); $group_shop = $shop->getGroup(); if ($group_shop->share_customer) { if (!in_array($group_shop->id, $customers_shop['shared'])) { $customers_shop['shared'][(int) $id_shop] = $group_shop->id; } } else { $customers_shop[(int) $id_shop] = $group_shop->id; } } } else { $default_shop = new Shop((int) Configuration::get('PS_SHOP_DEFAULT')); $default_shop->getGroup(); $customers_shop[$default_shop->id] = $default_shop->getGroup()->id; } //set temporally for validate field $customer->id_shop = $default_shop->id; $customer->id_shop_group = $default_shop->getGroup()->id; if (isset($info['id_default_group']) && !empty($info['id_default_group']) && !is_numeric($info['id_default_group'])) { $info['id_default_group'] = trim($info['id_default_group']); $my_group = Group::searchByName($info['id_default_group']); if (isset($my_group['id_group']) && $my_group['id_group']) { $info['id_default_group'] = (int) $my_group['id_group']; } } $my_group = new Group($customer->id_default_group); if (!Validate::isLoadedObject($my_group)) { $customer->id_default_group = (int) Configuration::get('PS_CUSTOMER_GROUP'); } $customer_groups[] = (int) $customer->id_default_group; $customer_groups = array_flip(array_flip($customer_groups)); $res = true; if (($field_error = $customer->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $customer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) { foreach ($customers_shop as $id_shop => $id_group) { $customer->force_id = (bool) Tools::getValue('forceIDs'); if ($id_shop == 'shared') { foreach ($id_group as $key => $id) { $customer->id_shop = (int) $key; $customer->id_shop_group = (int) $id; if ($customer_exist && ($current_id_shop_group == $id || in_array($current_id_shop, ShopGroup::getShopsFromGroup($id)))) { $customer->id = $current_id_customer; $res &= $customer->update(); } else { $res &= $customer->add(); if (isset($addresses)) { foreach ($addresses as $address) { $address['id_customer'] = $customer->id; unset($address['country'], $address['state'], $address['state_iso'], $address['id_address']); Db::getInstance()->insert('address', $address); } } } if ($res && isset($customer_groups)) { $customer->updateGroup($customer_groups); } } } else { $customer->id_shop = $id_shop; $customer->id_shop_group = $id_group; if ($customer_exist && $id_shop == $current_id_shop) { $customer->id = $current_id_customer; $res &= $customer->update(); } else { $res &= $customer->add(); if (isset($addresses)) { foreach ($addresses as $address) { $address['id_customer'] = $customer->id; unset($address['country'], $address['state'], $address['state_iso'], $address['id_address']); Db::getInstance()->insert('address', $address); } } } if ($res && isset($customer_groups)) { $customer->updateGroup($customer_groups); } } } } unset($customer_groups); $customer_exist = false; if (!$res) { $this->errors[] = sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $info['email'], isset($info['id']) && !empty($info['id']) ? $info['id'] : 'null'); $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError(); } } $this->closeCsvFile($handle); }
/** * Add a new group. Requires login. * * @param string $groupname * @return Group or Error */ function addGroup($groupname) { $g = new Group(); $group = $g->add($groupname); return $group; }
<?php include 'Auth.php'; include 'Group.php'; include 'User.php'; $userGroup = new Group('Backend Users'); $adminGroup = new Group('Admin Users'); $managerGroup = new Group('Managers'); $user1 = new User('jaceju'); $user2 = new User('johnwu'); $user3 = new User('justinlin'); $adminGroup->add($user1); $adminGroup->add($user2); $managerGroup->add($user3); $userGroup->add($adminGroup); $userGroup->add($managerGroup); $userGroup->display();
{ public function __construct($code, $name) { parent::__construct($code, $name); } //Leafクラスは歯止めになるから、持つべきでないメソッドはこんな感じでオーバーライドする public function add(OrganizationEntry $entry) { throw new Exception('method not allowed'); } } /** * Client */ $root_entry = new Group("001", "本社"); $root_entry->add(new Employee("00101", "CEO")); $root_entry->add(new Employee("00102", "CTO")); $group1 = new Group("010", "○○支店"); $group1->add(new Employee("01001", "支店長")); $group1->add(new Employee("01002", "佐々木")); $group1->add(new Employee("01003", "鈴木")); $group1->add(new Employee("01003", "吉田")); $group2 = new Group("110", "△△営業所"); $group2->add(new Employee("11001", "川村")); $group1->add($group2); $root_entry->add($group1); $group3 = new Group("020", "××支店"); $group3->add(new Employee("02001", "萩原")); $group3->add(new Employee("02002", "田島")); $group3->add(new Employee("02002", "白井")); $root_entry->add($group3);
/** * Import a group from OCS table. * * @param $value string : Value of the new dropdown. * @param $entities_id int : entity in case of specific dropdown * * @return integer : dropdown id. * */ static function importGroup($value, $entities_id) { global $DB; if (empty($value)) { return 0; } $query = "SELECT `id`\n FROM `glpi_groups`\n WHERE `name` = '{$value}' "; $query .= getEntitiesRestrictRequest(' AND ', 'glpi_groups', '', $entities_id, true); $result = $DB->query($query); if ($DB->numrows($result) == 0) { $group = new Group(); $input["name"] = $value; $input["entities_id"] = $entities_id; return $group->add($input); } $line = $DB->fetch_array($result); return $line["id"]; }