/** * Вывод всех банов */ public function actionIndex() { if (Yii::app()->request->isAjaxRequest && isset($_POST['server'])) { if ($_POST['server'] == 0) { Yii::app()->end('$("#Bans_admin_nick").html("<option value=\\"0\\">Не выбрано</option>");'); } $amxadmins = Amxadmins::model()->with('servers')->findAll('`address` = :addr', array(':addr' => $_POST['server'])); $js = "<option>Любой админ</option>"; foreach ($amxadmins as $admin) { $js .= "<option value=\"{$admin->steamid}\">{$admin->nickname}</option>"; } Yii::app()->end("\$('#Bans_admin_nick').html('{$js}')"); } $model = new Bans('search'); $model->unsetAttributes(); if (isset($_GET['Bans'])) { $model->attributes = $_GET['Bans']; } $select = "((ban_created+(ban_length*60)) > UNIX_TIMESTAMP() OR ban_length = 0) AND `expired` = 0"; $dataProvider = new CActiveDataProvider('Bans', array('criteria' => array('condition' => Yii::app()->config->auto_prune ? $select : null, 'order' => '`ban_created` DESC'), 'pagination' => array('pageSize' => Yii::app()->config->bans_per_page))); // Проверяем IP посетителя, есть ли он в активных банах $check = Bans::model()->count("`player_ip` = :ip AND " . $select, array(':ip' => Prefs::getRealIp())); $this->render('index', array('dataProvider' => $dataProvider, 'model' => $model, 'check' => $check > 0 ? true : false)); }
protected function beforeSave() { $removePwd = filter_input(INPUT_POST, 'removePwd', FILTER_VALIDATE_BOOLEAN); if ($removePwd) { $this->password = ''; } if ($this->isNewRecord) { $this->created = time(); if ($this->password && $this->scenario != 'buy') { $this->password = md5($this->password); } if ($this->flags != 'a' && !$this->password) { $this->flags .= 'e'; } $this->expired = $this->days != 0 ? $this->days * 86400 + time() : 0; } else { if ($this->password) { $this->password = md5($this->password); } else { $oldadmin = Amxadmins::model()->findByPk($this->id); if ($oldadmin->password && !$removePwd) { $this->password = $oldadmin->password; } elseif ($this->flags != 'a') { $this->flags .= 'e'; } } if ($this->expired == 0) { $this->expired = time(); } switch ($this->addtake) { case '1': $this->expired = $this->expired - $this->change * 86400; $this->days = $this->days - $this->change; break; case '0': $this->expired = $this->expired + $this->change * 86400; $this->days = $this->days + $this->change; break; default: $this->expired = 0; $this->days = 0; } } return parent::beforeSave(); }
/** * Загрузка модели по ID * Если не найдено, выводим эксепшн * @param integer ID админа */ public function loadModel($id) { $model = Amxadmins::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
/** *Главная страница серверов */ public function actionIndex() { $model = new Serverinfo('search'); $model->unsetAttributes(); if (isset($_GET['Serverinfo'])) { $model->attributes = $_GET['Serverinfo']; } $allbans = Bans::model()->cache(600)->count(); $activebans = Bans::model()->cache(600)->count('((ban_created+(ban_length*60)) > :time OR ban_length = 0) AND `expired` = 0', array(':time' => time())); $permbans = Bans::model()->cache(600)->count('ban_length = 0'); $this->render('index', array('servers' => Serverinfo::model()->cache(600)->findAll(array('order' => '`hostname` ASC')), 'info' => array('bancount' => $allbans, 'actbans' => $activebans, 'permbans' => $permbans, 'tempbans' => $activebans - $permbans, 'admins' => Amxadmins::model()->cache(600)->count(), 'serversCount' => Serverinfo::model()->cache(600)->count()))); }