public function actionSettings() { array_pop($_POST); $arr = $_POST; if (Yii::app()->user->isGuest) { $this->message(0, Yii::t('default', 'loginfirst'), Yii::app()->createUrl('site/login'), 1); } $uid = zmf::uid(); foreach ($arr as $key => $val) { $_k = zmf::filterInput($key, 't', 1); $_v = zmf::filterInput($val, 't', 1); $sinfo = UserSetting::model()->findByAttributes(array('stype' => $_k), "uid='{$uid}'"); $model = new UserSetting(); if (!$sinfo) { $_input = array('uid' => $uid, 'stype' => $_k, 'svalue' => $_v); $model->attributes = $_input; if ($model->validate()) { $model->save(); } } elseif ($sinfo->svalue != $_v) { $model->updateByPk($sinfo->id, array('svalue' => $_v)); } } zmf::setFCache("userSettings{$uid}", $arr); $this->redirect(array('users/config')); }
/** * Create new user * * @param array $data, POST data * @return int $id, current id of created user */ public function saveLoginDataTab(array $data){ $userObj = new UserLogin(); $userObj->setUsername($data['userFirstTab_username']); $userObj->setEmail($data['userFirstTab_email']); $userObj->setRoleId($data['userFirstTab_userrole']); $userObj->setPassword($data['userFirstTab_password']); $userObj->save(); $id = $userObj->getId(); $userData = new UserData(); $userData->setUserId($id); $userData->setFirstname($data['userFirstTab_firstname']); $userData->setLastname($data['userFirstTab_lastname']); $userData->save(); $userSetting= new UserSetting(); $userSetting->setUserId($id); $userSetting->setEmailformat($data['userFirstTab_emailformat']); $userSetting->setEmailtype($data['userFirstTab_emailtype']); $userSetting->setLanguage($data['userFirstTab_language']); $userSetting->setFirstlogin(1); $userSetting->save(); return $id; }
/** * Lists all models. */ public function actionIndex() { $url = parse_url(app()->request->getHostInfo(), PHP_URL_HOST); $currentWorkflow = $this->api('Cms.Workflow.getByUrl', array('url' => $url)); $workflowId = 0; $workflows = array(); $workflow = $this->getWorkflow(); if (is_object($workflow)) { $workflowId = $workflow->id; } else { $workflow = $currentWorkflow; //get workflow by url if (is_object($currentWorkflow)) { $workflowId = $currentWorkflow->id; } } //find all workflows if (is_object($workflow)) { //init setting params for current workflow $this->api('Xpress.Settings.sync', array('workflowId' => $workflow->id)); $workflows = Workflow::model()->findAll('site_id=:site_id', array(':site_id' => $workflow->site_id)); if (count($workflows)) { $workflows = CHtml::listData($workflows, 'id', 'name'); } } $model = new SettingParam('search'); $model->unsetAttributes(); // clear any default values if (isset($_POST['SettingParam'])) { $model->attributes = $_POST['SettingParam']; } elseif (isset($_GET['module'])) { $model->module = $_GET['module']; if (in_array($model->module, array('Xpress', 'Admin'))) { $model->module = 'System'; } } else { $model->module = 'System'; } $model->visible = 1; $model->workflow_id = $workflowId; $dataProvider = $model->search(); $dataProvider->pagination = false; $modules = $model->getModules(); $data = $dataProvider->getData(); //override setting use user_setting $customizable = array(); if (count($data)) { foreach ($data as $i => $row) { /** var CActiveRecord $row */ if ($row->customizable) { //load data from user_setting $custom = UserSetting::model()->findByAttributes(array('param_name' => $row->name, 'user_id' => Yii::app()->user->id)); if (is_object($custom)) { $data[$i]->value = $custom->value; } else { $custom = new UserSetting(); $custom->user_id = Yii::app()->user->id; $custom->param_name = $row->name; } $customizable[] = $custom; } } } $paramForm = $this->createWidget('Admin.components.ParamForm', array('params' => $data, 'config' => null)); //TODO: load module param definitions into $config // save new values if (Yii::app()->request->IsPostRequest) { //save User Settings to user_setting if (is_array($customizable) && count($customizable)) { foreach ($customizable as $custom) { if ($custom instanceof UserSetting && isset($_POST[$custom->param_name])) { $custom->value = $_POST[$custom->param_name]; if (!$custom->save()) { Yii::log(CVarDumper::dumpAsString($custom->getErrors()), CLogger::LEVEL_ERROR, 'Admin.Setting'); } //force not save global setting unset($_POST[$custom->param_name]); } } } $paramForm->saveParams($_POST, ParamForm::TO_SETTING_TABLE); //update Settings Class if ($currentWorkflow->id == $workflowId && isset($_POST['SettingParam'], $_POST['SettingParam']['module'])) { $module = $_POST['SettingParam']['module']; if ($module == 'module_system') { $module = ''; } $this->api('Xpress.Settings.db2php', array('module' => $module)); } //update parameters to global and other workflows foreach ($paramForm->params as $param) { if (isset($_POST['sync_global'])) { $this->api('Xpress.SettingParam.syncValue', array('attrs' => $param->attributes)); //update cache file global $this->api('Xpress.Settings.db2php', array('module' => $param->module, 'path' => cachePath(true))); } if (isset($_POST['sync_other'])) { $this->api('Xpress.SettingParam.syncValueToOther', array('attrs' => $param->attributes)); } } //TODO: need fix validate in ParamForm //errorHandler()->getErrorMessages(); } $this->render('index', array('modules' => $modules, 'module' => $model->module, 'form' => $paramForm, 'workflowId' => $workflowId, 'workflows' => $workflows)); }