function add($user_id, $cause) { if (strlen(trim($cause))) { $userModel = new UserModel(); $currentUser = Project::getUser()->getDbUser(); $userModel->load($user_id); if ($userModel->id) { $banHistoryModel = new BanHistoryModel(); $paramModel = new ParamModel(); $n_warnings_to_ban = $paramModel->getParam("UserController", "N_WARNINGS_TO_BAN"); $t_ban_time_sec = $paramModel->getParam("UserController", "T_BAN_TIME_SEC"); $count_user_warnings = $this->getUserWarningCount($user_id); $this->clear(); $this->user_id = (int) $user_id; $this->cause = $cause; $warning_id = $this->save(); if ($userModel->warnings_fromlast_ban + 1 >= $n_warnings_to_ban) { // пора банить $subject = "Ваш аккаун заблокирован в системе Next24.ru"; $userModel->warnings_fromlast_ban = 0; $userModel->banned = 1; $userModel->banned_date = time(); $banHistoryModel->ban($user_id, $currentUser->id, $warning_id, date("Y-m-d H:i:s", time() + $t_ban_time_sec)); } else { $userModel->warnings_fromlast_ban = $userModel->warnings_fromlast_ban + 1; $subject = "Администратор Next24.ru установил Вам предупреждение"; } $userModel->save(); $url_referer = $_SERVER['HTTP_REFERER']; $this->sendMessage((int) $user_id, $subject, $cause, $url_referer); return $warning_id; } } return 0; }
function SaveAction() { $request = Project::getRequest(); $user_id = (int) Project::getUser()->getDbUser()->id; $model = new UserModel(); $model->load($request->id); $do_save = true; $this->_view->clearFlashMessages(); if (!strlen(trim($request->login))) { $this->_view->addFlashMessage(FM::ERROR, "Не заполнено поле логин"); $do_save = false; } if ($request->unbann) { $ban_model = new BanHistoryModel(); $ban_model->unban($request->id, $user_id); } if ($request->bann) { if (strlen($request->warning)) { $ban_date = $request->ban_date; if (strlen($ban_date) && strtotime($ban_date) > time()) { $warning_model = new WarningModel(); $warning_id = $warning_model->add($request->id, $request->warning); $ban_model = new BanHistoryModel(); $ban_model->ban($request->id, $user_id, $warning_id, $request->ban_date); } else { $this->_view->addFlashMessage(FM::ERROR, "Неверная дата бана"); $do_save = false; } } else { $this->_view->addFlashMessage(FM::ERROR, "Не заполнено предупреждение"); $do_save = false; } } if ($do_save) { $this->_view->clearFlashMessages(); $model->login = $request->login; $model->user_type_id = $request->user_group; if ($request->bann) { $model->banned = 1; $model->banned_date = strtotime($request->ban_date); } else { $model->banned = 0; } $ban_date = $request->ban_date; if (strlen($ban_date)) { //$ban_model = new Ban } $id = $model->save(); $model = new UserTypeModel(); $info = array(); $info['group_list'] = $model->loadAll(); $info['edit_controller'] = null; $info['edit_action'] = 'Edit'; $this->makeUserList($info); $this->_view->AjaxList($info); } $this->_view->ajax(); }