public function __get($param) { switch ($param) { case 'name_support': return trim($this->name . ' ' . $this->surname); break; case 'user_groups_id': $userGroups = erLhcoreClassModelGroupUser::getList(array('filter' => array('user_id' => $this->id))); $this->user_groups_id = array(); if (!empty($userGroups)) { foreach ($userGroups as $userGroup) { $this->user_groups_id[] = $userGroup->group_id; } } return $this->user_groups_id; break; case 'lastactivity': $db = ezcDbInstance::get(); $stmt = $db->prepare('SELECT last_activity FROM lh_userdep WHERE user_id = :user_id LIMIT 1'); $stmt->bindValue(':user_id', $this->id, PDO::PARAM_INT); $stmt->execute(); $this->lastactivity = (int) $stmt->fetchColumn(); return $this->lastactivity; break; case 'has_photo': return $this->filename != ''; break; case 'photo_path': $this->photo_path = ($this->filepath != '' ? erLhcoreClassSystem::instance()->wwwDir() : erLhcoreClassSystem::instance()->wwwImagesDir()) . '/' . $this->filepath . $this->filename; return $this->photo_path; break; case 'file_path_server': return $this->filepath . $this->filename; break; case 'lastactivity_front': $this->lastactivity_front = ''; if ($this->lastactivity > 0) { $this->lastactivity_front = date(erLhcoreClassModule::$dateDateHourFormat); } return $this->lastactivity_front; break; case 'lastactivity_ago': $this->lastactivity_ago = ''; if ($this->lastactivity > 0) { $periods = array("s.", "m.", "h.", "d.", "w.", "m.", "y.", "dec."); $lengths = array("60", "60", "24", "7", "4.35", "12", "10"); $difference = time() - $this->lastactivity; for ($j = 0; $difference >= $lengths[$j] && $j < count($lengths) - 1; $j++) { $difference /= $lengths[$j]; } $difference = round($difference); $this->lastactivity_ago = "{$difference} {$periods[$j]}"; } return $this->lastactivity_ago; break; default: break; } }
public static function loginBySSO($params) { $settings = (include 'extension/singlesignon/settings/settings.ini.php'); // Try to find operator by our logins if (isset($params[$settings['attr_map']['username']][0])) { $username = $params[$settings['attr_map']['username']][0]; if (erLhcoreClassModelUser::userExists($username)) { $user = array_shift(erLhcoreClassModelUser::getUserList(array('limit' => 1, 'filter' => array('username')))); erLhcoreClassUser::instance()->setLoggedUser($user->id); } else { $user = new erLhcoreClassModelUser(); foreach ($settings['attr_map'] as $attr => $ssoAttr) { $user->{$attr} = $params[$settings['attr_map'][$attr]][0]; } foreach ($settings['default_attributes'] as $attr => $value) { $user->{$attr} = $value; } $user->password = sha1(erLhcoreClassModelForgotPassword::randomPassword() . rand(0, 1000) . microtime()); $user->saveThis(); // Set that users sees all pending chats erLhcoreClassModelUserSetting::setSetting('show_all_pending', 1, $user->id); // Set default departments erLhcoreClassUserDep::addUserDepartaments($settings['default_departments'], $user->id, $user); // Cleanup if previously existed erLhcoreClassModelGroupUser::removeUserFromGroups($user->id); // Assign user to default group foreach ($settings['default_user_groups'] as $group_id) { $groupUser = new erLhcoreClassModelGroupUser(); $groupUser->group_id = $group_id; $groupUser->user_id = $user->id; $groupUser->saveThis(); } erLhcoreClassUser::instance()->setLoggedUser($user->id); } return true; } else { throw new Exception('Username field not found'); } }
public function setUserGroups() { erLhcoreClassModelGroupUser::removeUserFromGroups($this->id); foreach ($this->user_groups_id as $group_id) { $groupUser = new erLhcoreClassModelGroupUser(); $groupUser->group_id = $group_id; $groupUser->user_id = $this->id; $groupUser->saveThis(); } }
chmod($UserData->file_path_server, 0644); } } } if (count($Errors) == 0) { // Update password if neccesary if ($form->hasInputField('Password') && $form->hasInputField('Password1') && $form->Password != '') { $UserData->setPassword($form->Password); } $UserData->email = $form->Email; $UserData->name = $form->Name; erLhcoreClassUser::getSession()->update($UserData); erLhcoreClassUserDep::setHideOnlineStatus($UserData); erLhcoreClassModelGroupUser::removeUserFromGroups($UserData->id); foreach ($UserData->user_groups_id as $group_id) { $groupUser = new erLhcoreClassModelGroupUser(); $groupUser->group_id = $group_id; $groupUser->user_id = $UserData->id; $groupUser->saveThis(); } $CacheManager = erConfigClassLhCacheConfig::getInstance(); $CacheManager->expireCache(); if (isset($_POST['Save_account'])) { erLhcoreClassModule::redirect('user/userlist'); exit; } else { $tpl->set('updated', true); } } else { $tpl->set('errors', $Errors); }
foreach ($_POST['AssignedID'] as $AssignedID) { $group_user = erLhcoreClassModelGroupUser::fetch($AssignedID); $group_user->removeThis(); } } if (isset($_POST['Remove_role_from_group']) && isset($_POST['AssignedID']) && count($_POST['AssignedID']) > 0) { if (!isset($_POST['csfr_token']) || !$currentUser->validateCSFRToken($_POST['csfr_token'])) { erLhcoreClassModule::redirect('user/userlist'); exit; } foreach ($_POST['AssignedID'] as $AssignedID) { erLhcoreClassGroupRole::deleteGroupRole($AssignedID); } } $pages = new lhPaginator(); $pages->items_total = erLhcoreClassModelGroupUser::getCount(array('filter' => array('group_id' => $Group->id))); $pages->setItemsPerPage(20); $pages->serverURL = erLhcoreClassDesign::baseurl('user/editgroup') . '/' . $Group->id; $pages->paginate(); $tpl->set('pages', $pages); if ($pages->items_total > 0) { $tpl->set('users', erLhcoreClassModelGroupUser::getList(array('filter' => array('group_id' => $Group->id), 'offset' => $pages->low, 'limit' => $pages->items_per_page))); } else { $tpl->set('users', array()); } if (isset($_GET['adduser'])) { $tpl->set('adduser', 'true'); } $tpl->set('group', $Group); $Result['content'] = $tpl->fetch(); $Result['path'] = array(array('url' => erLhcoreClassDesign::baseurl('system/configuration'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('user/editgroup', 'System configuration')), array('url' => erLhcoreClassDesign::baseurl('user/grouplist'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('user/editgroup', 'Groups')), array('title' => erTranslationClassLhTranslation::getInstance()->getTranslation('user/editgroup', 'Group edit') . ' - ' . $Group->name));