public function actionAdd() { MainUtil::checkLicenseLimit(); if (EnvUtil::submitCheck("userSubmit")) { $origPass = filter_input(INPUT_POST, "password", FILTER_SANITIZE_STRING); $_POST["salt"] = StringUtil::random(6); $_POST["password"] = !empty($origPass) ? md5(md5($origPass) . $_POST["salt"]) : ""; $_POST["createtime"] = TIMESTAMP; $_POST["guid"] = StringUtil::createGuid(); $this->dealWithSpecialParams(); $data = User::model()->create(); $newId = User::model()->add($data, true); if ($newId) { UserCount::model()->add(array("uid" => $newId)); $ip = Ibos::app()->setting->get("clientip"); UserStatus::model()->add(array("uid" => $newId, "regip" => $ip, "lastip" => $ip)); UserProfile::model()->add(array("uid" => $newId)); if (!empty($_POST["auxiliarydept"])) { $deptIds = StringUtil::getId($_POST["auxiliarydept"]); $this->handleAuxiliaryDept($newId, $deptIds, $_POST["deptid"]); } if (!empty($_POST["auxiliarypos"])) { $posIds = StringUtil::getId($_POST["auxiliarypos"]); $this->handleAuxiliaryPosition($newId, $posIds, $_POST["positionid"]); } $newUser = User::model()->fetchByPk($newId); $users = UserUtil::loadUser(); $users[$newId] = UserUtil::wrapUserInfo($newUser); User::model()->makeCache($users); OrgUtil::update(); OrgUtil::hookSyncUser($newId, $origPass, 1); $this->success(Ibos::lang("Save succeed", "message"), $this->createUrl("user/index")); } else { $this->error(Ibos::lang("Add user failed"), $this->createUrl("user/index")); } } else { $deptid = ""; $manager = ""; $account = Ibos::app()->setting->get("setting/account"); if ($account["mixed"]) { $preg = "[0-9]+[A-Za-z]+|[A-Za-z]+[0-9]+"; } else { $preg = "^[A-Za-z0-9\\!\\@\\#\$\\%\\^\\&\\*\\.\\~]{" . $account["minlength"] . ",32}\$"; } if ($deptid = EnvUtil::getRequest("deptid")) { $deptid = StringUtil::wrapId(EnvUtil::getRequest("deptid"), "d"); $manager = StringUtil::wrapId(Department::model()->fetchManagerByDeptid(EnvUtil::getRequest("deptid")), "u"); } $this->setPageTitle(Ibos::lang("Add user")); $this->setPageState("breadCrumbs", array(array("name" => Ibos::lang("Organization"), "url" => $this->createUrl("department/index")), array("name" => Ibos::lang("User manager"), "url" => $this->createUrl("user/index")), array("name" => Ibos::lang("Add user")))); $this->render("add", array("deptid" => $deptid, "manager" => $manager, "passwordLength" => $account["minlength"], "preg" => $preg)); } }
public function getCreditSidebar($lang = array()) { $data["lang"] = $lang; $data["creditFormulaExp"] = strip_tags(Ibos::app()->setting->get("setting/creditsformulaexp")); $extcredits = Ibos::app()->setting->get("setting/extcredits"); if (!empty($extcredits)) { $user = UserCount::model()->fetchByPk($this->getUid()); foreach ($extcredits as $index => &$ext) { if (!empty($ext)) { $ext["value"] = $user["extcredits" . $index]; } } } $data["userCount"] = UserCount::model()->fetchByPk($this->getUid()); $data["extcredits"] = $extcredits; $data["user"] = $this->getUser(); return $this->renderPartial("application.modules.user.views.home.creditSidebar", $data, true); }
<?php printf("<h3>Личный кабинет пользователя %s.</h3>", Yii::App()->user->name); printf("<h3>Баланс: %s\$</h3>", UserCount::getBalance(Yii::app()->user->id)); ?> <?php $this->widget('zii.widgets.CMenu', array('items' => array(array('label' => 'Создать статью', 'url' => array('/page/create'), 'visible' => !Yii::app()->user->isGuest), array('label' => 'Просмотр статей', 'url' => array('/page/userpage'), 'visible' => !Yii::app()->user->isGuest), array('label' => 'Выход', 'url' => array('/site/logout'), 'visible' => !Yii::app()->user->isGuest), array('label' => 'Вход', 'url' => array('/site/login'), 'visible' => Yii::app()->user->isGuest)))); ?> <h3>Просмотр статей</h3> <?php $this->widget('zii.widgets.grid.CGridView', array('id' => 'page-grid', 'dataProvider' => $dataProvider, 'columns' => array('title', 'text', 'symbols' => array('name' => 'Количество символов', 'value' => 'UserCount::getSymbols($data->id)'), 'publish' => array('name' => 'Опубликованно', 'value' => '($data->publish == 1)?"Да":"Нет"'), 'coins' => array('name' => 'Вознаграждение', 'value' => 'UserCount::getReward($data->id)."$"'), array('class' => 'CButtonColumn'))));
<h3>Просмотр статьи</h3> <?php $this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('title', 'text', 'symbols' => array('name' => 'Кол-во символов', 'value' => UserCount::getSymbols($model->id)), 'publish' => array('name' => 'Опубликованно', 'value' => $model->publish == 1 ? "Да" : "Нет"), 'username' => array('name' => 'Автор', 'value' => $model->user->username)))); ?> <br> <b><?php echo CHtml::submitButton('Назад', array('submit' => array('userpage', 'id' => $model->user_id))); ?> </b> <b><?php echo CHtml::submitButton($model->publish ? 'Снять с публикации' : 'Опубликовать', array('submit' => array('publish', 'id' => $model->id))); ?> </b> <b><?php echo CHtml::submitButton('Удалить', array('submit' => array('delete', 'id' => $model->id))); ?> </b>
public function updateSession() { static $updated = false; if (!$updated) { $global = Ibos::app()->setting->toArray(); if (!Ibos::app()->user->isGuest) { if (isset($global["cookie"]["ulastactivity"])) { $userLastActivity = StringUtil::authCode($global["cookie"]["ulastactivity"], "DECODE"); } else { $userLastActivity = UserUtil::getUserProfile("lastactivity"); MainUtil::setCookie("ulastactivity", StringUtil::authCode($userLastActivity, "ENCODE"), 31536000); } } $onlineTimeSpan = 10; $lastOnlineUpdate = $this->var["lastolupdate"]; $onlineTimeOffset = $lastOnlineUpdate ? $lastOnlineUpdate : $userLastActivity; $allowUpdateOnlineTime = $onlineTimeSpan * 60 < TIMESTAMP - $onlineTimeOffset; if (!Ibos::app()->user->isGuest && $allowUpdateOnlineTime) { $updateStatus = OnlineTime::model()->updateOnlineTime(Ibos::app()->user->uid, $onlineTimeSpan, $onlineTimeSpan, TIMESTAMP); if ($updateStatus === false) { $onlineTime = new OnlineTime(); $onlineTime->uid = Ibos::app()->user->uid; $onlineTime->thismonth = $onlineTimeSpan; $onlineTime->total = $onlineTimeSpan; $onlineTime->lastupdate = $global["timestamp"]; $onlineTime->save(); } $this->setKey("lastolupdate", TIMESTAMP); } $this->var["invisible"] = UserUtil::getUserProfile("invisible"); foreach ($this->var as $key => $value) { if (Ibos::app()->user->hasState($key) && $key != "lastactivity") { $this->setKey($key, Ibos::app()->user->{$key}); } } Ibos::app()->session->update(); if (!Ibos::app()->user->isGuest) { $updateStatusField = array("lastip" => $global["clientip"], "lastactivity" => TIMESTAMP, "lastvisit" => TIMESTAMP, "invisible" => 1); if (21600 < TIMESTAMP - $userLastActivity) { if ($onlineTimeSpan && 43200 < TIMESTAMP - $userLastActivity) { $onlineTime = OnlineTime::model()->fetchByPk(Ibos::app()->user->uid); UserCount::model()->updateByPk(Ibos::app()->user->uid, array("oltime" => round(intval($onlineTime["total"]) / 60))); } MainUtil::setCookie("ulastactivity", StringUtil::authCode(TIMESTAMP, "ENCODE"), 31536000); UserStatus::model()->updateByPk(Ibos::app()->user->uid, $updateStatusField); } } $updated = true; } return $updated; }
public function countCredit($uid, $update = true) { $credits = 0; $creditsformula = Ibos::app()->setting->get("setting/creditsformula"); if ($uid && !empty($creditsformula)) { $user = UserCount::model()->fetchByPk($uid); eval("\$credits = round(" . $creditsformula . ");"); if ($uid == $uid) { if ($update && $user["credits"] != $credits) { User::model()->updateCredits($uid, $credits); Ibos::app()->user->setState("credits", $credits); } } elseif ($update) { User::model()->updateCredits($uid, $credits); } } return $credits; }
protected function getIndexData() { $allCreditRankList = User::model()->fetchAllCredit(); $curRanking = array_search($this->getUid(), $allCreditRankList); $totalRanking = count($allCreditRankList); $rankPercent = (double) 100 - round(($curRanking + 1) / $totalRanking, 2) * 100; $ranklist = array(); $top6 = array_slice($allCreditRankList, 0, 6); foreach ($top6 as $uid) { $ranklist[] = User::model()->fetchByUid($uid); } if (!empty($ranklist) && $ranklist[0]["uid"] == $this->getUid()) { $isTop = true; } else { $isTop = false; } $extcredits = Ibos::app()->setting->get("setting/extcredits"); $userCount = UserCount::model()->fetchByPk($this->getUid()); $user = $this->getUser(); $data = array("curRanking" => $curRanking + 1, "totalRanking" => $totalRanking, "rankPercent" => $rankPercent, "ranklist" => $ranklist, "isTop" => $isTop, "user" => $user, "extcredits" => $extcredits, "userCount" => $userCount, "contacts" => $this->getColleagues($user)); if ($this->getIsMe()) { $data["securityRating"] = $this->getSecurityRating(); $logTableId = Log::getLogTableId(); $con = sprintf("`level` = 'login' AND `category` = 'module.user.%d'", $this->getUid()); $data["history"] = Log::fetchAllByList($logTableId, $con, 4, 0); } return $data; }
private function addUser() { if (Ibos::app()->request->isAjaxRequest) { $fields = array("username", "password", "realname", "mobile", "deptid", "positionid", "email"); if (empty($_POST["username"]) || empty($_POST["password"])) { $this->ajaxReturn(array("isSuccess" => false, "msg" => Ibos::lang("Username or password not empty"))); } foreach ($fields as $field) { if (isset($_POST[$field]) && !empty($_POST[$field])) { $_POST[$field] = StringUtil::filterDangerTag($_POST[$field]); } } $salt = StringUtil::random(6); $userData = array("salt" => $salt, "username" => $_POST["username"], "password" => !empty($_POST["password"]) ? md5(md5($_POST["password"]) . $salt) : "", "realname" => $_POST["realname"], "mobile" => $_POST["mobile"], "createtime" => TIMESTAMP, "deptid" => intval($_POST["deptid"]), "positionid" => intval($_POST["positionid"]), "email" => $_POST["email"]); $newId = User::model()->add($userData, true); if ($newId) { UserCount::model()->add(array("uid" => $newId)); $ip = Ibos::app()->setting->get("clientip"); UserStatus::model()->add(array("uid" => $newId, "regip" => $ip, "lastip" => $ip)); UserProfile::model()->add(array("uid" => $newId)); $newUser = User::model()->fetchByPk($newId); $users = UserUtil::loadUser(); $users[$newId] = UserUtil::wrapUserInfo($newUser); User::model()->makeCache($users); OrgUtil::update(); $res["isSuccess"] = true; } else { $res["isSuccess"] = false; $res["msg"] = Ibos::lang("Add user failed"); } $this->ajaxReturn($res); } }