/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Session::find(); $query->select('s.name as service,u.name as username,u1.name as mentorname,mbb.user_id,mbb.mentor_id,mbb.service_id,mbb.id,mbb.type,mbb.status,mbb.datetime_from as date, mbb.datetime_from as time,mbb.booking_hrs,mbb.paid_from'); $query->leftjoin('users as u', 'u.id=mbb.user_id'); $query->leftJoin('users as u1', 'u1.id=mbb.mentor_id'); $query->leftjoin('ms_service as s', 's.id=mbb.service_id'); $query->where('mbb.type = "book" AND mbb.status != "C"'); $query->orderBy('mbb.id DESC'); $query->from('mbb as mbb '); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]); $this->load($params); $dataProvider->sort->attributes['username'] = ['asc' => ['u.name' => SORT_ASC], 'desc' => ['u.name' => SORT_DESC]]; $dataProvider->sort->attributes['service'] = ['asc' => ['s.name' => SORT_ASC], 'desc' => ['s.name' => SORT_DESC]]; $dataProvider->sort->attributes['mentorname'] = ['asc' => ['u1.name' => SORT_ASC], 'desc' => ['u1.name' => SORT_DESC]]; $dataProvider->sort->attributes['date'] = ['asc' => ['mbb.datetime_from' => SORT_ASC], 'desc' => ['mbb.datetime_from' => SORT_DESC]]; $dataProvider->sort->attributes['time'] = ['asc' => ['mbb.datetime_from' => SORT_ASC], 'desc' => ['mbb.datetime_from' => SORT_DESC]]; if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['mbb.mentor_id' => $this->mentor_id, 'datetime_from' => $this->datetime_from, 'mbb.service_id' => $this->service_id, 'hourly_fee' => $this->hourly_fee, 'total_fee' => $this->total_fee, 'created_at' => $this->created_at]); $query->andFilterWhere(['like', 'mbb.type', $this->type])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'mbb.status', $this->status])->andFilterWhere(['like', 'u.name', $this->username])->andFilterWhere(['like', 'u1.name', $this->mentorname])->andFilterWhere(['like', 's.name', $this->service])->andFilterWhere(['like', 'mbb.datetime_from', $this->date])->andFilterWhere(['like', 'mbb.datetime_from', $this->time])->andFilterWhere(['like', 'mbb.booking_hrs', $this->booking_hrs])->andFilterWhere(['like', 'mbb.paid_from', $this->paid_from]); return $dataProvider; }
public static function logStat() { if (Yii::$app->user->isGuest && !Yii::$app->session->has('stat')) { $model = Session::find()->where(['id' => Yii::$app->session->id])->one(); if ($model === null) { $model = new Session(); $model->id = Yii::$app->session->id; $model->ip = Yii::$app->request->userIP; $model->user_agent = Yii::$app->request->userAgent; $model->created = $model->modified = time(); $model->save(); } Session::updateAll(['status' => 0], 'modified < :time', [':time' => time() - 15 * 60]); Yii::$app->session->set('stat', true); } }
public function actionIndex() { $cateCount = Category::find()->count(); $productCount = Product::find()->count(); $onlineCount = Session::find()->where(['status' => 1])->count(); $userCount = Session::find()->count(); return $this->render('index', ['cateCount' => $cateCount, 'productCount' => $productCount, 'onlineCount' => $onlineCount, 'userCount' => $userCount]); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { // $user = User::getAuthUser(); if ($user->canCreateSessions(Input::get('team_id'))) { $validator = Validator::make($request->all(), ['topic' => 'required', 'date' => 'required']); if ($validator->fails()) { return response()->json(['message' => $validator->messages()], 400); } Session::create(Input::all()); } else { return response()->json(['message' => 'You do not have permission to create a session for this team'], 400); } }
<?php //namespace app\core; use app\models\Cookie; use app\models\Config; use app\models\Session; use app\models\User; use app\classes\DB; session_start(); $GLOBALS['config'] = ['mysql' => ['host' => '127.0.0.1', 'username' => 'root', 'password' => 'root', 'db' => 'test'], 'remember' => ['cookie_name' => 'hash', 'cookie_expiry' => 604800], 'session' => ['session_name' => 'root', 'token_name' => 'token']]; spl_autoload_register(function ($class) { require_once 'classes/' . $class . '.php'; }); require_once "functions/sanitize.php"; if (Cookie::exists(Config::get('remember/cookie_name')) && !Session::exists(Config::get('session/session_name'))) { $hash = Cookie::get(Config::get('remember/cookie_name')); $hashCheck = DB::connect()->get('users_session', ['hash', '=', $hash]); if ($hashCheck->count()) { $user = new User($hashCheck->first()->user_id); $user->login(); } }
/** * Finds the Session model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Session the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Session::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public static function createRecord($data) { $data['organization_id'] = \Session::get('user_organization'); return self::create($data); }
$ctrl = isset($_GET['ctrl']) ? $_GET['ctrl'] : 'News'; $act = isset($_GET['act']) ? $_GET['act'] : 'All'; $classController = 'app\\controllers\\' . $ctrl . 'Controller'; //require __DIR__ . '/classes/DB.php'; $controller = new $classController(); $method = "action" . $act; $controller->{$method}(); if (require_once 'core/init.php') { echo 1; } use app\models\Session; use app\models\User; use app\classes\DB; $user = DB::connect(); if (Session::exists('home')) { echo "<p><b>" . Session::flash('home') . "</b></p>"; } $user = new User(); if ($user->isLoggedIn()) { ?> <p>Hello, <a href="profile.php?user=<?php echo escape($user->data()->username); ?> "><?php echo $user->data()->username; ?> </a></p> <ul> <li>You can <a href="logout.php">log out</a> here!</li> <li>You can <a href="update.php">update</a> your profile here!</li> <li>You can <a href="changepassword.php">change password</a> here!</li>
public function actionSave() { $session = new Session(); $user = Yii::$app->user->identity; $cart = Cart::getCurrentCart(); $cart->processCart(); if ($cart->total > 0) { return $this->actionCharge(); } $cart->status = Cart::CART_SOLD; $cart->save(); $session->addSuccess(Yii::t('app', 'Congratulations, you\'ve completed your order!')); $cart_lines = []; foreach ($cart->items as $item) { $cart_lines[] = $item->ticket->group->event->name . ': ' . $item->ticket->name . ' x' . $item->quantity . ' @ ' . $item->ticket->ticket_price . ' each'; } $cart_details = implode("\n", $cart_lines); $email = new Email(); $email->to_name = $user->name; $email->to_email = $user->email; $email->subject = "Your Tixty Purchase"; $message = <<<EOT Hi {$user->name}!! You just bought {$cart->quantity} tickets for a total of {$cart->total} - details below. Thanks, Tixty --- {$cart_details} EOT; $email->body = nl2br($message); $email->save(); $email->send(); $email = new Email(); $email->to_name = "Tixty"; $email->to_email = \Yii::$app->params['adminEmail']; $email->subject = "Tixty Purchase #{$cart->id}"; $message = <<<EOT {$user->name} just bought {$cart->quantity} tickets for a total of {$cart->total} - details below. Tixty --- {$cart_details} EOT; $email->body = nl2br($message); $email->save(); $email->send(); return $this->redirect('index'); }
public function cleanUp() { $items = $this->getItems()->all(); $items_removed = false; foreach ($items as $item) { $ticket = Ticket::findOne($item->ticket_id); if (!$ticket->isAvailable()) { $this->removeItem($item->ticket_id); $items_removed = true; } else { if ($ticket->getAvailableQuantity() !== false && $item->quantity > $ticket->getAvailableQuantity()) { $this->updateItem($item->ticket_id, $ticket->getAvailableQuantity()); $items_removed = true; } } } if ($items_removed) { $session = new Session(); $session->addError(Yii::t('app', 'Unavailable tickets removed')); } }
public function getSessionByEnseignant($id_Enseignant) { return Session::join("Session_Medecin", "Session_Medecin.id_Session", "=", "Session.id_Session")->where("Session_Medecin.id_Enseignant", "=", $id_Enseignant)->get(); }
/** * Check if the hash is valid to get the user linked to the hash * * @param Request $request * @return Bool */ protected function setSessionUser(Request $request) { $hash = $request->header('X-SESSION-ID'); $session = Session::whereHash($hash)->first(); if (!$session) { return false; } $this->hash = $hash; $this->user = $session->user; return true; }
use app\models\CartItems; use app\models\Session; use yii\helpers\Url; use yii\helpers\Html; $this->title = Yii::t('app', 'Your cart'); $cartItems = CartItems::find()->where(['cart_id' => $cart->id]); $cart->processCart(); $dataProvider = new yii\data\ActiveDataProvider(['query' => $cartItems]); $formatter = \Yii::$app->formatter; ?> <h1><?php echo Html::encode($this->title); ?> </h1> <?php $session = new Session(); $errors = $session->getErrors(); $session->clearErrors(); foreach ($errors as $e) { ?> <div class="alert alert-danger"><h2><?php echo $e; ?> </h2></div><?php } $successes = $session->getSuccesses(); $session->clearSuccesses(); foreach ($successes as $e) { ?> <div class="alert alert-success"><h2><?php echo $e;
public function logout() { $this->_db->delete('users_session', ['user_id', '=', $this->data()->id]); Session::delete($this->_sessionName); Cookie::delete($this->_cookieName); }
public function postEditSchedule(int $id) { $file = fopen(request()->file('schedule_file')->getRealPath(), 'r'); $l = 0; while ($line = fgetcsv($file)) { if ($l++ === 0) { continue; } //skipping headers Session::create(['title' => $line[0], 'description' => $line[1], 'begin' => $line[2], 'end' => $line[3], 'event_id' => $id]); } $total = $l - 1; //skipping header if ($total > 0) { \Session::flash('success', __('One activity was imported.', 'A total of %d activities were imported.', $total)); } else { \Session::flash('warning', _('No activity was found in the file.')); } return $this->edit('schedule', $id); }
function validAccess($id) { $row = \DB::table('tb_groups_access')->where('module_id', '=', $id)->where('group_id', '=', \Session::get('gid'))->get(); if (count($row) >= 1) { $row = $row[0]; if ($row->access_data != '') { $data = json_decode($row->access_data, true); } else { $data = array(); } return $data; } else { return false; } }
public function init() { Session::logStat(); }