public static function online() { $session = Session::model()->cache(0)->findAll(); $result = array(); if (isset($session)) { $t = 0; $g = 0; $b = 0; $u = 0; $a = 0; foreach ($session as $val) { $result['users'][] = array('id' => $val->user_id, 'ip' => $val->ip_address, 'user_agent' => $val->user_agent, 'avatar' => $val->user_avatar, 'type' => $val->user_type); if ($val->user_type == 1) { $u++; } elseif ($val->user_type == 2) { $a++; } elseif ($val->user_type == 3) { $b++; } else { $g++; } $t++; } $result['totals'] = array('all' => $t, 'guest' => $g, 'admin' => $a, 'users' => $u, 'bot' => $b); } return $result; }
/** * Updates timestamps of session records */ public static function setUpSessions($sessions) { foreach ($sessions as $session) { $model = Session::model()->findByAttributes($session); $model->lastUpdated = time(); $model->save(); } }
/** * 以Ip地址为标志,查看当前用户是否有登陆 */ public function checkLoginStatus() { $criteria = new CDbCriteria(); $criteria->addSearchCondition('data', UtilNet::getClientIp()); $model = Session::model()->find($criteria); if ($model) { return true; } else { return false; } }
protected function updateAuthStatus() { if (!Ibos::app()->request->getIsAjaxRequest()) { if ($this->account["allowshare"] != 1 && !$this->getIsGuest()) { $criteria = array("condition" => sprintf("`uid` = %d", $this->uid)); $session = Session::model()->fetch($criteria); if ($session && $session["sid"] != Ibos::app()->setting->get("sid")) { Ibos::app()->getRequest()->getCookies()->remove($this->getStateKeyPrefix()); Ibos::app()->getSession()->destroy(); } } parent::updateAuthStatus(); } }
public function testCleanUpSessions() { Yii::app()->cache->flush(); // Prepare expected data: $sessionCounts = array('session1' => 1, 'session2' => 1, 'session3' => 0); foreach (array_keys($sessionCounts) as $alias) { $sessionIds[$alias] = $this->session($alias)->id; } $defaultTimeout = 60; Yii::app()->settings->timeout = $defaultTimeout; Session::cleanUpSessions(); // Session 1 shoud still be there // Sessions 2 and 3 should be gone foreach ($sessionCounts as $alias => $count) { $this->assertEquals((int) $count, Session::model()->countByAttributes(array('id' => $sessionIds[$alias])), "{$alias} did not get deleted"); } }
/** * Load a Session */ public function actionLoad($sessionHash, $documentID = null) { $session = Session::model()->find('hash=:signature', [':signature' => $sessionHash]); /* @var $session Session */ $documents = []; if ($session) { if ($documentID) { $document = Document::model()->findByAttributes(['sessionID' => $session->ID, 'ID' => $documentID]); if ($document) { $documents[] = $document; } } else { $documents = $session->documents; } } $this->sendResponse(200, CJSON::encode(['sessionID' => $session->ID, 'documents' => $documents]), 'application/json'); }
public function loadModelByExamId($id) { $model = Session::model()->findByAttributes(array('exam_id' => $id)); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionToggleVisibility() { $id = $_SESSION['sessionId']; $session = Session::model()->findByAttributes(array('id' => $id)); if (isset($session)) { if ($session->status < 0) { $session->status = 0; } $session->status = !$session->status; $session->save(); SessionLog::logSession(Yii::app()->user->getName(), $id, $session->status ? "visible" : "invisible"); } $this->redirect($_GET['redirect']); }
public function actionViewDialog() { $this->layout = false; if (isset($_REQUEST['session'])) { $session = Session::model()->findByPk($_REQUEST['session']); $this->render('dialogs/viewDialog', array('model' => $session)); } }
public function SignUp($session = null, $quantity = 1, $creditCard = null) { $transaction = $this->dbConnection->beginTransaction(); try { $user = User::model()->findByPk(Yii::app()->user->id); if ($this->Create_User_ID == $user->User_ID) { throw new Exception("Can't sign up for own experience."); } $userToExperience = new UserToExperience(); $userToExperience->User_ID = $user->User_ID; $userToExperience->Experience_ID = $this->Experience_ID; if ($session == null) { $existing = UserToExperience::model()->find('User_ID=:User_ID AND Experience_ID=:Experience_ID', array(':User_ID' => $user->User_ID, ':Experience_ID' => $this->Experience_ID)); } else { $existing = UserToExperience::model()->find('User_ID=:User_ID AND Session_ID=:Session_ID AND Experience_ID=:Experience_ID', array(':User_ID' => $user->User_ID, ':Session_ID' => $session, ':Experience_ID' => $this->Experience_ID)); $userToExperience->Session_ID = $session; } if ($this->MaxPerPerson != null) { if ($quantity > $this->MaxPerPerson) { throw new Exception("Quantity exceeds limit."); } } $userToExperience->Quantity = $quantity; if ($existing != null && !$this->MultipleAllowed) { throw new Exception("Can't sign up multiple times."); } $confirmationCode = $this->code; if (isset($this->Price) && $this->Price != null && $this->Price > 0) { $amount = $quantity * $this->Price; $scheduledFor = strtotime('+' . Yii::app()->params["PaymentDelay"] . ' days'); if ($session != null) { $sessionModel = Session::model()->findByPk($session); $start = strtotime($sessionModel->Start); if ($start < time()) { throw new Exception("Session starts in the past."); } if ($start < $scheduledFor) { $scheduledFor = $start; } } $payment = new Payment(); $payment->Experience_ID = $this->Experience_ID; $payment->CreditCard_ID = $creditCard; $payment->BankAccount_ID = $this->createUser->bankAccount->BankAccount_ID; $payment->Amount = $amount; $payment->Batch_ID = uniqid(); $payment->ScheduledFor = date('Y-m-d H:i:s', $scheduledFor); $payment->Status = PaymentStatus::Scheduled; $payment->save(); $confirmationCode = $payment->code; } $userToExperience->save(); $userName = CHtml::link($user->fullName, array('user/view', 'id' => $user->User_ID)); $experienceName = CHtml::link($this->Name, array('experience/view', 'id' => $this->Experience_ID)); Message::SendNotification($this->Create_User_ID, "{$userName} has joined your experience \"{$experienceName}\"."); // Notify the enrollees foreach ($this->enrolled as $enrollee) { if ($enrollee->User_ID != $user->User_ID) { $userName = CHtml::link($user->fullName, array('user/view', 'id' => $user->User_ID)); $experienceName = CHtml::link($this->Name, array('experience/view', 'id' => $this->Experience_ID)); Message::SendNotification($enrollee->User_ID, "{$userName} has also joined the experience \"{$experienceName}\"."); } } if (!is_numeric($quantity)) { $quantity = 1; } $models = array('model' => $this, 'confirmationCode' => $confirmationCode, 'quantity' => $quantity); Mail::Instance()->SendTemplate($user->Email, 'Signup Confirmation', '/experience/_emailConfirmation', $models); $transaction->commit(); } catch (Exception $e) { $transaction->rollback(); return false; } return true; }
public function actionResults() { $student_id = Yii::app()->request->getQuery("student_id", NULL); $current = Current::model()->find('student_id=:student_id', array(':student_id' => $student_id)); $all_sessions = Session::model()->findAll('mod_id=:mod_id', array(':mod_id' => $current->mod_id)); $all = array(); foreach ($all_sessions as $key0 => $session) { $session_id = $session->session_id; $session_listenings = SessionListening::model()->findAll('session_id=:session_id', array(':session_id' => $session_id)); $all[$key0]["session_id"] = $session->session_id; $all[$key0]["session_name"] = $session->session_name; $all[$key0]["session_order"] = $session->session_order; $all[$key0]["mod_id"] = $session->mod_id; $all[$key0]["listenings"] = array(); foreach ($session_listenings as $key => $session_listening) { $temp_listening_id = $session_listening->listening_id; $listening = Listening::model()->find('listening_id=:listening_id', array(':listening_id' => $temp_listening_id)); $all[$key0]["listenings"][$key] = array('listening_id' => $listening->listening_id, 'listening_name' => $listening->listening_name, 'listening_repeat_number' => $listening->listening_repeat_number, 'listening_learning_guide_availability' => $listening->listening_learning_guide_availability); $criteria = new CDbCriteria(); $criteria->addCondition("listening_id=:listening_id"); //$criteria->order='RAND()'; $criteria->params = array(':listening_id' => $listening->listening_id); $questions = Question::model()->findAll($criteria); //$questions=Question::model()->findAll('listening_id=:listening_id',array('listening_id'=>$listening->listening_id)); foreach ($questions as $key2 => $question) { $all[$key0]["listenings"][$key]['questions'][$key2] = array('question_id' => $question->question_id, 'question_body' => $question->question_body, 'question_correct_answer_id' => $question->question_correct_answer_id); $criteria = new CDbCriteria(); $criteria->addCondition("question_id=:question_id"); //$criteria->order='RAND()'; $criteria->params = array(':question_id' => $question->question_id); $answers = Answer::model()->findAll($criteria); //$answers=Answer::model()->findAll('question_id=:question_id',array(':question_id'=>$question->question_id)); foreach ($answers as $key3 => $answer) { $all[$key0]["listenings"][$key]['questions'][$key2]['answers'][$key3] = array('answer_id' => $answer->answer_id, 'answer_body' => $answer->answer_body); } } } } $this->render('results', array('all' => $all, 'student_id' => $student_id)); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Session the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Session::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public static function getOnlineStatus($uid) { static $userOnline = array(); if (empty($userOnline[$uid])) { $user = Session::model()->fetchByUid($uid); if ($user) { $userOnline[$uid] = $user["invisible"]; } } return isset($userOnline[$uid]) ? intval($userOnline[$uid]) : -1; }
public static function cleanUpSessions() { Session::model()->deleteAll('lastUpdated < :cutoff', array(':cutoff' => time() - Yii::app()->params->admin->timeout)); }
</script> <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> </p> </div> </div> </div> <div class="col-lg-4"> <div class="panel panel-default"> <div class="panel-heading"> <i class="fa fa-users fa-fw"></i> Zalogowani użytkownicy </div> <!-- /.panel-heading --> <div class="panel-body"> <div class="list-group"> <?php $activeUsers = Session::model()->findAll(); foreach ($activeUsers as $Data) { if ($Data->user_id != 0) { echo '<a href="#" class="list-group-item"> <i class="fa fa-user fa-fw"></i> ' . $Data->user->firstname . ' <span class="text-muted small"><em> (' . $Data->username . ')</em></span> <span class="pull-right text-muted small"><em>' . $Data->user_ip . '</em> </span> </a>'; } } ?> </div> <?php if (Yii::app()->user->isAdmin()) { echo '<a href="admin/users" class="btn btn-default btn-block">Zarządzaj użytkownikami</a>';
private function checkAccess() { if (!isset($this->_user["uid"]) || $this->_user["uid"] == 0) { $this->_access = 0; } else { $this->_session = Session::model()->findByAttributes(array("uid" => $this->_user["uid"])); $this->_access = 1; } }
/** * Load configuration that cannot be put in config/main */ public function beginRequest() { $t0 = microtime(true); if ($this->owner->request->getPathInfo() == 'notifications/getMessages') { // skip all the loading if this is a chat/notification update $timezone = $this->owner->db->createCommand()->select('timeZone')->from('x2_profile')->where('id=1')->queryScalar(); // set the timezone to the admin's if (!isset($timezone)) { $timezone = 'UTC'; } date_default_timezone_set($timezone); return; } Yii::import('application.controllers.x2base'); Yii::import('application.models.*'); Yii::import('application.components.*'); // Yii::import('application.components.ERememberFiltersBehavior'); // Yii::import('application.components.EButtonColumnWithClearFilters'); // $this->owner->messages->forceTranslation = true; $this->owner->messages->onMissingTranslation = array(new TranslationLogger(), 'log'); $this->owner->params->admin = CActiveRecord::model('Admin')->findByPk(1); $this->owner->params->profile = CActiveRecord::model('ProfileChild')->findByPk($this->owner->user->getId()); // die( var_dump($this->owner->request->getPathInfo())); //->getRoute(); if (!$this->owner->user->isGuest) { // use the admin's profile as default $this->owner->params->profile = CActiveRecord::model('ProfileChild')->findByPk($this->owner->user->getId()); $session = Session::model()->findByAttributes(array('user' => $this->owner->user->getName())); if (isset($session)) { if (time() - $session->lastUpdated > $this->owner->params->admin->timeout) { $session->delete(); $this->owner->user->logout(); } else { $session->lastUpdated = time(); $session->save(); } } else { $this->owner->user->logout(); // $this->redirect(Yii::app()->controller->createUrl('site/logout')); } if (!is_null($this->owner->user->getId()) && $this->owner->user->getName() != 'admin') { $this->owner->params->roles = $this->owner->db->createCommand()->select('roleId')->from('x2_role_to_user')->where('type="user" AND userId=' . $this->owner->user->getId())->queryColumn(); $this->owner->params->groups = $this->owner->db->createCommand()->select('groupId')->from('x2_group_to_user')->where('userId=' . $this->owner->user->getId())->queryColumn(); $groupRoles = Yii::app()->db->createCommand()->select('x2_role_to_user.roleId')->from('x2_group_to_user')->join('x2_role_to_user', 'x2_role_to_user.userId=x2_group_to_user.groupId AND x2_group_to_user.userId="' . Yii::app()->user->getId() . '" AND type="group"')->queryColumn(); // foreach($this->owner->params->groups as $groupId) { // lookup roles for all the user's groups // $groupRoles += $this->owner->db->createCommand() // ->select('roleId') // ->from('x2_role_to_user') // ->where('type="group" AND userId='.$groupId)->queryColumn(); // } $this->owner->params->roles = array_unique($this->owner->params->roles + $groupRoles); // combine all the roles, remove duplicates } } $modules = $this->owner->modules; $arr = array(); foreach (scandir('protected/modules') as $module) { if (file_exists("protected/modules/{$module}/register.php")) { $arr[$module] = ucfirst($module); Yii::import("application.modules.{$module}.models.*"); } } foreach ($arr as $key => $module) { $record = Modules::model()->findByAttributes(array('name' => $key)); if (isset($record) && $record->visible) { $modules[] = $key; } } $this->owner->setModules($modules); $adminProf = ProfileChild::model()->findByPk(1); // set currency $this->owner->params->currency = $this->owner->params->admin->currency; // set language if (!empty($this->owner->params->profile->language)) { $this->owner->language = $this->owner->params->profile->language; } else { if (isset($adminProf)) { $this->owner->language = $adminProf->language; } else { $this->owner->language = ''; } } // set timezone if (!empty($this->owner->params->profile->timeZone)) { date_default_timezone_set($this->owner->params->profile->timeZone); } elseif (!empty($adminProf->timeZone)) { date_default_timezone_set($adminProf->timeZone); } else { date_default_timezone_set('UTC'); } $logo = Media::model()->findByAttributes(array('associationId' => 1, 'associationType' => 'logo')); if (isset($logo)) { $this->owner->params->logo = $logo->fileName; } setlocale(LC_ALL, 'en_US.UTF-8'); // die(microtime(true)-$t0); }
public function actionLogout() { $user = User::model()->findByPk(Yii::app()->user->getId()); if (isset($user)) { $user->lastLogin = time(); $session = Session::model()->findByAttributes(array('user' => $user->username)); if (isset($session)) { $session->delete(); } $user->save(); } Yii::app()->user->logout(); $this->redirect(Yii::app()->homeUrl); }
/** * Ajax action to retrieve the modification data for a given session. */ public function actionGetSessionTimestamps() { if (isset($_POST['session_id'])) { if ($session = Session::model()->findByPk($_POST['session_id'])) { $ex = explode(' ', $session->last_modified_date); $last_modified_date = $ex[0]; $last_modified_time = $ex[1]; $user = User::model()->findByPk($session->last_modified_user_id); echo 'Modified on ' . Helper::convertMySQL2NHS($last_modified_date) . ' at ' . $last_modified_time . ' by ' . $user->first_name . ' ' . $user->last_name; } } }
?> <li class="accaunt-contacts__item accaunt-site"><a href="http://<?php echo $model->url; ?> " class="accaunt-contacts__link" target="_blank"><?php echo $model->url; ?> </a></li> <?php } ?> </ul> </div> <article class="col-8 accaunt_description"> <?php $m = Session::model()->findByAttributes(array('user_id' => $model->id)); if (is_object($m)) { ?> <div class="online-status">ONLINE</div> <?php } ?> <?php if ($model->about != '') { ?> <h6>Описание</h6> <div class="accaunt_description__scroll-block nano"> <div class="nano-content"> <div style="max-width: 593px;word-break: break-word;"><?php echo $model->about; ?>
public function delete() { return Session::model()->deleteBySession($this->var); }
/** * This function checks if the XML-RPC session key is valid. If yes returns true, otherwise false and sends an error message with error code 1 * * @access protected * @param string $sSessionKey Auth credentials * @return bool */ protected function _checkSessionKey($sSessionKey) { $criteria = new CDbCriteria(); $criteria->condition = 'expire < ' . time(); Session::model()->deleteAll($criteria); $oResult = Session::model()->findByPk($sSessionKey); if (is_null($oResult)) { return false; } else { $this->_jumpStartSession($oResult->data); return true; } }
public function actionPushQuestionnaireEnd() { $student_id = Yii::app()->request->getPost("student_id", NULL); $session_id = Yii::app()->request->getPost("session_id", NULL); /* next session */ $session = Session::model()->find('session_id=:session_id', array(':session_id' => $session_id)); $mod_id = $session->mod_id; $next_order = $session->session_order + 1; $next_session = Session::model()->find('mod_id=:mod_id AND session_order=:session_order', array(':mod_id' => $mod_id, ':session_order' => $next_order)); $current = Current::model()->find('student_id=:student_id', array(':student_id' => $student_id)); //error_log(print_r($current,1)); //error_log("\n"); //error_log(print_r($next_session,1)); if ($this->getMaxOrder($student_id) < $next_order) { } if ($current && $next_session) { $session_listening = SessionListening::model()->find('session_id=:session_id', array('session_id' => $next_session->session_id)); $current->session_id = $next_session->session_id; if ($current->save()) { $current->listening_id = $session_listening->listening_id; $current->save(); } } $end_questionnaire_answer = Yii::app()->request->getPost("end_questionnaire_answer", NULL); $questionnaire = Questionnaire::model()->find('student_id=:student_id AND session_id=:session_id', array(':student_id' => $student_id, ':session_id' => $session_id)); if ($questionnaire) { $questionnaire->end_questionnaire_answer = $end_questionnaire_answer; if (!$questionnaire->save()) { $this->renderJSON($questionnaire->getErrors()); } else { $this->renderJSON(array('status' => 1, 'message' => 'Successfully saved!')); } } else { $this->renderJSON(array('status' => 0, 'message' => 'Given Questionnaire could not be found!')); } }
public function actionOnline() { x2base::cleanUpSessions(); $sessions = Session::model()->findAll(); $usernames = array(); $users = array(); foreach ($sessions as $session) { $usernames[] = $session->user; } foreach ($usernames as $username) { $user = User::model()->findByAttributes(array('username' => $username)); $users[] = $user->firstName . " " . $user->lastName; } $this->render('online', array('users' => $users)); }
/** * An AJAX called function to allow the admin to forcibly end a session, * logging the user out. * @param $id The ID of the session. */ public function actionEndSession($id) { echo Session::model()->deleteByPk($id); }
public function isUserOnline($user_id) { $session = Session::model()->find(array('condition' => '`t`.`user_id`=:uid', 'params' => array(':uid' => $user_id))); if (isset($session)) { if (Yii::app()->controller instanceof AdminController) { return '<span class="status_available" style="position:static" title="' . Yii::t('default', 'ONLINE') . '"></span>'; } else { return true; } } else { if (Yii::app()->controller instanceof AdminController) { return '<span class="status_off" style="position:static" title="' . Yii::t('default', 'OFFLINE') . '"></span>'; } else { return false; } } }