Example #1
0
 /**
  * Edit a role
  */
 public function edit()
 {
     $param = array('id' => 'edit-role-form', 'model' => 'Role', 'reference' => array('id' => $this->roleId), 'fieldsets' => array('form' => array('nofieldset' => true, new HiddenInput(array('field' => 'removable', 'default' => 1, 'readonly' => true)), new TextInput(array('field' => 'name', 'maxlength' => 32, 'label' => Lang::get('roles.form-name-label'), 'required' => true)), new ColorInput(array('field' => 'color', 'label' => Lang::get('roles.form-color-label'), 'default' => '#000'))), '_submits' => array(new SubmitInput(array('name' => 'valid', 'value' => Lang::get('main.valid-button'))), new DeleteInput(array('name' => 'delete', 'value' => Lang::get('main.delete-button'), 'notDisplayed' => $this->roleId == -1)), new ButtonInput(array('name' => 'cancel', 'value' => Lang::get('main.cancel-button'), 'onclick' => 'app.dialog("close")')))), 'onsuccess' => 'app.dialog("close"); app.load(app.getUri("list-roles"), {selector : "#admin-roles-tab"});');
     foreach (Language::getAll() as $language) {
         $param['fieldsets']['form'][] = new TextInput(array('name' => "translation[{$language->tag}]", "independant" => true, 'required' => $language->tag == LANGUAGE, "label" => Lang::get("roles.role-label-label", array('lang' => $language->tag)), "default" => Lang::exists("roles.role-" . $this->roleId . "-label") ? Lang::get("roles.role-" . $this->roleId . "-label", array(), 0, $language->tag) : ''));
     }
     $form = new Form($param);
     if (!$form->submitted()) {
         return View::make(Theme::getSelected()->getView("dialogbox.tpl"), array('icon' => 'user', 'title' => Lang::get('roles.form-title'), 'page' => $form));
     } else {
         if ($form->submitted() == "delete") {
             $form->delete(Form::NO_EXIT);
             if ($key) {
                 $key->delete();
             }
             return $form->response(Form::STATUS_SUCCESS);
         } else {
             if ($form->check()) {
                 try {
                     $roleId = $form->register(Form::NO_EXIT);
                     // Create the language key for the translations of the role name
                     foreach (App::request()->getBody('translation') as $tag => $translation) {
                         Language::getByTag($tag)->saveTranslations(array('roles' => array("role-{$roleId}-label" => $translation)));
                     }
                     return $form->response(Form::STATUS_SUCCESS);
                 } catch (Exception $e) {
                     return $form->response(Form::STATUS_ERROR, DEBUG_MODE ? $e->getMessage() : "");
                 }
             }
         }
     }
 }
 public function actionCreate()
 {
     $model = new Migration();
     $form = new Form('codegen.MigrationForm', $model);
     if ($form->submitted() && $model->validate()) {
         $res = Yii::app()->db->createCommand("SHOW CREATE TABLE {$model->table}")->queryRow();
         $sql = $res['Create Table'];
         $sql = explode("\n", $sql);
         foreach ($sql as $i => $str) {
             if ($i == 0) {
                 continue;
             }
             $sql[$i] = str_repeat(' ', 14) . $str;
         }
         $sql = implode("\n", $sql);
         $dir = APP_PATH . DS . 'modules' . DS . $model->module . DS . 'migrations' . DS;
         if (!is_dir($dir)) {
             mkdir($dir, 0777);
             chmod($dir, 0777);
         }
         $name = 'm' . date('ymd') . '_' . date('His') . '_' . $model->table . '_create';
         $file = $dir . $name . '.php';
         $params = array('name' => $name, 'table' => $model->table, 'sql' => $sql);
         $code = $this->renderPartial('codegen.views.templates.migration', $params, true);
         file_put_contents($file, $code);
         chmod($file, 0777);
         Yii::app()->user->setFlash('success', t('Создана миграция') . ' ' . $name);
     }
     $this->render('create', array('form' => $form));
 }
Example #3
0
 /**
  * Редактирует свойства сайта
  */
 public function actionSiteSettings()
 {
     //$settingsForm = ;
     $form_array = SiteSettingsForm::form();
     //$form_array['title'] = Yii::t('cms', 'General settings');
     $form_array['id'] = 'SiteSettings';
     $form_array['activeForm'] = Form::ajaxify($form_array['id']);
     $form_array['buttons'] = array('refresh' => array('type' => 'submit', 'label' => Yii::t('cms', 'Save'), 'title' => Yii::t('cms', 'Save and reload the page')));
     $form = new Form($form_array);
     $form->id = $form_array['id'];
     $form->model = clone Yii::app()->settings->model;
     $form->loadData();
     $this->performAjaxValidation($form->model, null, false);
     if ($form->submitted('refresh')) {
         if ($form->model->validate()) {
             Yii::app()->settings->saveAll($form->model->getAttributes());
             echo '1';
         } else {
             echo '0';
         }
         Yii::app()->end();
     }
     $caption = array('icon' => 'settings', 'label' => Yii::t('cms', 'Site settings'));
     $this->render('/form', array('form' => $form, 'caption' => $caption));
 }
 public function actionCreate()
 {
     $model = new Module();
     $form = new Form('codegen.ModuleForm', $model);
     $this->performAjaxValidation($model);
     if ($form->submitted() && $model->validate()) {
         $files = $this->actionGetFiles($model->id, true);
         foreach ($files as $file) {
             $path_info = pathinfo($file);
             if (isset($path_info['extension'])) {
                 mkdir($path_info['dirname'], 0777, true);
                 file_put_contents($file, $this->getCode($model));
                 chmod($file, 0777);
             } else {
                 if (!is_dir($file)) {
                     mkdir($file, 0777, true);
                     chmod($file, 0777);
                 }
             }
         }
         Yii::app()->user->setFlash('success', 'Модуль создан!');
         $this->redirect($_SERVER['REQUEST_URI']);
     }
     $this->render('create', array('form' => $form));
 }
Example #5
0
 public function init()
 {
     parent::init();
     $id = __CLASS__ . $this->params['content']->id;
     $this->params['profileVar'] = $this->urlParam('view');
     $blank = true;
     if (Yii::app()->request->getParam($this->params['profileVar']) !== null) {
         $profile = User::model()->findByPk(intval(Yii::app()->request->getParam($this->params['profileVar'])));
         if ($profile) {
             $this->params['details'] = Yii::app()->controller->widget('zii.widgets.CDetailView', array('data' => $profile, 'attributes' => $this->makeFields($this->params['content']->displayed_fields, $profile)), true);
             $this->params['profile'] = $profile->getAttributes();
             if (Yii::app()->user->hasRole($profile->send_message) && $profile->id != $this->params['user']->id && $profile->email) {
                 $vm = new VirtualModel($this->params['content']->feedback_form, 'FieldSet');
                 $config = $vm->formMap;
                 $config['id'] = sprintf('%x', crc32(serialize(array_keys($this->params['content']->feedback_form))));
                 $config['buttons'] = array('send' => array('type' => 'submit', 'label' => Yii::t('UnitProfiles.main', 'Send')));
                 $config['activeForm'] = Form::ajaxify($config['id']);
                 $config['activeForm']['clientOptions']['validationUrl'] = '/?r=view/widget&pageWidgetId=' . $this->params['pageWidget']->id . '&' . $this->params['profileVar'] . '=' . $profile->id;
                 $config['activeForm']['clientOptions']['afterValidate'] = "js:function(f,d,h){if (!h) {return true;}}";
                 $form = new Form($config, $vm);
                 if (Yii::app()->request->getParam('ajax-validate') !== null) {
                     echo CActiveForm::validate($vm);
                     Yii::app()->end();
                 }
                 if ($form->submitted('send')) {
                     $vm = $form->model;
                     if ($form->validate()) {
                         $cfg = ContentUnit::loadConfig();
                         $viewFileDir = $cfg['UnitProfiles'] . '.profiles.templates.mail.';
                         $labels = $vm->attributeLabels();
                         foreach ($vm->getAttributes() as $attr => $value) {
                             $tpldata['fields'][$labels[$attr]] = $value;
                         }
                         $tpldata['profile'] = $profile->getAttributes();
                         $tpldata['settings'] = Yii::app()->settings->model->getAttributes();
                         $tpldata['page'] = $this->params['content']->getWidgetPageArray();
                         $registerModel = ModelRegister::model()->find('widget_id > 0');
                         $registerWidget = new WidgetRegister();
                         if ($registerUnit) {
                             $tpldata['profileEditUrl'] = $registerModel->getWidgetUrl();
                             $tpldata['profileEditUrlParams'] = $registerWidget->urlParam('do') . '=edit';
                         }
                         Yii::app()->messenger->send('email', $profile->email, '[' . $_SERVER['HTTP_HOST'] . '] ' . Yii::t('UnitProfiles.main', 'Feedback form'), Yii::app()->controller->renderPartial($viewFileDir . 'feedback', $tpldata, true));
                         Yii::app()->user->setFlash('UnitProfilesSend-permanent', Yii::t('UnitProfiles.main', 'Your message was successfully sent'));
                         Yii::app()->controller->refresh();
                     }
                 }
                 $this->params['feedbackForm'] = $form->render();
             }
         } else {
             $this->params['error'] = Yii::t('UnitProfiles.main', 'Profile not found');
         }
         $blank = false;
     }
     if ($blank) {
         $this->prepareTable();
     }
 }
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     $form = new Form('content.MenuForm', $model);
     if ($form->submitted() && $model->save()) {
         $this->redirect($this->createUrl('manage'));
     }
     $this->render('update', ['form' => $form]);
 }
Example #7
0
 public function actionCreateMetric()
 {
     $model = new Metric('create');
     $this->performAjaxValidation($model);
     $form = new Form('regions.metric', $model);
     if ($form->submitted() && $model->appendTo(Metric::getRoot())) {
         //??? o_O
     }
     $this->redirect('/regions/index/index');
 }
Example #8
0
 function submitted()
 {
     if (parent::submitted()) {
         if ($this->isClicked('Clear')) {
             $this->clearData();
         }
         $this->memorizeAll();
         $this->view->js()->reload()->execute();
     }
 }
Example #9
0
 function submitted()
 {
     if (parent::submitted()) {
         if ($this->isClicked('Clear')) {
             $this->clearData();
         }
         $this->memorizeAll();
         return true;
     }
 }
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     $form = new Form('social.LabelForm', $model);
     $this->performAjaxValidation($model);
     if ($form->submitted() && $model->save()) {
         $this->redirect(array('view', 'id' => $model->id));
     }
     $this->render('update', array('form' => $form));
 }
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     $form = new Form('content.PageForm', $model);
     $this->performAjaxValidation($model);
     if ($form->submitted() && $model->save()) {
         $this->redirect(['view', 'id' => $model->id]);
     }
     $this->render('update', ['form' => $form]);
 }
 public function actionCreate()
 {
     $model = new Crud();
     $form = new Form('codegen.CrudForm', $model);
     if ($form->submitted() && $model->validate()) {
         Yii::import('codegen.controllers.FormAdminController');
         FormAdminController::generateAndSaveForm($model->class);
         $params = $model->attributes;
         $params['module'] = AppManager::getModelModule($model->class);
         $controllers_path = 'codegen.views.templates.crud.controllers';
         $controllers_files = glob(Yii::getPathOfAlias($controllers_path) . DS . '*');
         foreach ($controllers_files as $controller_file) {
             $file_name = pathinfo($controller_file, PATHINFO_FILENAME);
             $code = $this->renderPartial($controllers_path . '.' . $file_name, $params, true);
             $file_name = $model->class . $file_name . '.php';
             $dir = MODULES_PATH . $params['module'] . DS . 'controllers' . DS;
             if (!is_dir($dir)) {
                 mkdir($dir, 0777, true);
                 chmod($dir, 0777);
             }
             $file_path = $dir . $file_name;
             file_put_contents($file_path, $code);
             chmod($file_path, 0777);
         }
         $views_path = 'codegen.views.templates.crud.views';
         $views_files = glob(Yii::getPathOfAlias($views_path) . DS . '*' . DS . '*');
         foreach ($views_files as $view_file) {
             $view_file = str_replace(Yii::getPathOfAlias($views_path), '', $view_file);
             $file_name = pathinfo($view_file, PATHINFO_BASENAME);
             $file_code = $this->renderPartial($views_path . str_replace(array(DS, '.php'), array('.', ''), $view_file), $params, true);
             $view_file_path = MODULES_PATH . $params['module'] . DS . 'views' . $view_file;
             $view_file_dir = pathinfo($view_file_path, PATHINFO_DIRNAME);
             $child_dir = pathinfo($view_file_dir, PATHINFO_FILENAME);
             if ($child_dir == 'client') {
                 $view_file_dir = str_replace('client', lcfirst($model->class), $view_file_dir);
             } else {
                 if ($child_dir == 'admin') {
                     $view_file_dir = str_replace('admin', lcfirst($model->class) . 'Admin', $view_file_dir);
                 }
             }
             if (!is_dir($view_file_dir)) {
                 mkdir($view_file_dir, 0777, true);
                 chmod($view_file_dir, 0777);
             }
             $file_path = $view_file_dir . DS . $file_name;
             file_put_contents($file_path, $file_code);
             chmod($file_path, 0777);
         }
         $msg = "Добавьте  в метод adminMenu()  в файле " . ucfirst($params['module']) . "Module.php<br/>\r\n                   'Управление {$params['instrumental']}'    => Yii::app()->createUrl('/{$params['module']}/" . lcfirst($params['class']) . "Admin/manage'), <br/>\r\n                   'Создать {$params['accusative']}' => Yii::app()->createUrl(''/{$params['module']}/" . lcfirst($params['class']) . "Admin/create'),";
         Yii::app()->user->setFlash(Controller::MSG_SUCCESS, 'CRUD создан!');
         Yii::app()->user->setFlash(Controller::MSG_INFO, $msg);
         $this->redirect($_SERVER['REQUEST_URI']);
     }
     $this->render('create', array('form' => $form));
 }
 public function actionStep2()
 {
     $model = new Step2();
     $form = new Form('install.Step2', $model);
     $this->performAjaxValidation($model);
     if ($form->submitted() && $model->validate()) {
         $configs = CMap::mergeArray(Yii::app()->user->getState('install_configs'), $model->getConfigs());
         Yii::app()->user->setState('install_configs', $configs);
         $step1 = Step1::loadFromSession();
         Yii::app()->setComponent('db', $step1->createDbConnection());
         //install modules
         Yii::app()->setModules($model->modules);
         //$step1->deleteDisableModules();
         //migrate
         Yii::app()->getModule('users');
         Yii::app()->executor->migrate('up --module=main');
         foreach (Yii::app()->getModules() as $id => $data) {
             if ($id == 'main') {
                 continue;
             }
             Yii::app()->getModule($id);
             if (is_dir(Yii::getPathOfAlias($id . '.migrations'))) {
                 $response = Yii::app()->executor->migrate('up --module=' . $id);
                 if (stripos($response, 'successfully') === false) {
                     echo $response;
                     die;
                 }
             }
         }
         //create admin user
         $user = new User();
         list($user->name) = explode('@', $model->admin_email);
         $user->name = ucfirst($user->name);
         $user->email = $model->admin_email;
         $user->password = UserIdentity::crypt($model->admin_pass);
         $user->status = User::STATUS_ACTIVE;
         $user->save(false);
         //set admin
         $auth = Yii::app()->authManager;
         $auth->clearAll();
         $auth->createRole('Admin');
         $auth->assign('Admin', $user->id);
         //commands collect
         Yii::app()->executor->addCommandsFromModules(Yii::app()->getModules());
         //run install method
         foreach (Yii::app()->getModules() as $id => $conf) {
             @mkdir(Yii::getPathOfAlias('webroot.upload.' . $id), 0755, true);
             Yii::app()->getModule($id)->install();
         }
         $model->saveInSession();
         //install base modules
         $this->redirect('/install.php?r=/install/install/step3');
     }
     $this->render('step2', array('form' => $form));
 }
 public function actionUpdate($id, $scenario = 'update')
 {
     $model = $this->loadModel($id);
     $model->scenario = $scenario;
     $this->performAjaxValidation($model);
     $form = new Form('main.ParamForm', $model);
     if ($form->submitted() && $model->save()) {
         $this->redirect(array('view', 'id' => $model->id));
     }
     $this->render('update', array('form' => $form));
 }
Example #15
0
 /**
  * Create or edit an user
  */
 public function edit()
 {
     $roles = array_map(function ($role) {
         return $role->getLabel();
     }, Role::getAll('id'));
     $user = User::getByUsername($this->username);
     $param = array('id' => 'user-form', 'upload' => true, 'model' => 'User', 'reference' => array('username' => $this->username), 'fieldsets' => array('general' => array('nofieldset' => true, new TextInput(array('name' => 'username', 'required' => true, 'unique' => true, 'readonly' => $user && $user->id !== App::session()->getUser()->id, 'insert' => !$user || $user->id === App::session()->getUser()->id, 'label' => Lang::get($this->_plugin . '.user-form-username-label'))), new EmailInput(array('name' => 'email', 'required' => true, 'unique' => true, 'readonly' => $user && $user->id !== App::session()->getUser()->id, 'insert' => !$user || $user->id !== App::session()->getUser()->id, 'label' => Lang::get($this->_plugin . '.user-form-email-label'))), new CheckboxInput(array('name' => 'active', 'label' => Lang::get($this->_plugin . '.user-form-active-label'))), new SelectInput(array('name' => 'roleId', 'options' => $roles, 'label' => Lang::get($this->_plugin . '.user-form-roleId-label'))), $user ? null : new PasswordInput(array('name' => 'password', 'required' => true, 'label' => Lang::get($this->_plugin . '.user-form-password-label'), 'encrypt' => array('Hawk\\Crypto', 'saltHash'))), $user ? null : new PasswordInput(array('name' => 'passagain', 'label' => Lang::get($this->_plugin . '.user-form-passagain-label'), 'required' => true, 'compare' => 'password', 'independant' => true)), new HiddenInput(array('name' => 'createTime', 'default' => time()))), '_submits' => array(new SubmitInput(array('name' => 'valid', 'value' => Lang::get('main.valid-button'))), new DeleteInput(array('name' => 'delete', 'value' => Lang::get('main.delete-button'), 'notDisplayed' => !($user && $user->isRemovable()))), new ButtonInput(array('name' => 'cancel', 'value' => Lang::get('main.cancel-button'), 'onclick' => 'app.dialog("close")')))), 'onsuccess' => 'app.dialog("close"); app.lists["admin-users-list"].refresh();');
     $form = new Form($param);
     if (!$form->submitted()) {
         return View::make(Theme::getSelected()->getView("dialogbox.tpl"), array('page' => $form, 'title' => Lang::get($this->_plugin . '.user-form-title'), 'icon' => 'user'));
     } else {
         if ($form->submitted() == "delete") {
             $this->remove();
         } else {
             if ($form->check()) {
                 return $form->register();
             }
         }
     }
 }
 public function actionCreate()
 {
     $model = new AuthItem();
     $model->type = CAuthItem::TYPE_ROLE;
     $form = new Form('rbac.RoleForm', $model);
     $this->performAjaxValidation($model);
     if ($form->submitted() && $model->save()) {
         $this->redirect(array('manage'));
     }
     $this->render('create', array('form' => $form));
 }
Example #17
0
 public function actionCreate()
 {
     $model = new Page(Page::SCENARIO_CREATE);
     $model->type = Page::TYPE_QA;
     $form = new Form('content.PageCForm', $model);
     if ($form->submitted() && $model->validate()) {
         $model->save();
         $this->redirect(['index']);
     }
     $this->render('create', ['form' => $form]);
 }
 public function actionCreate()
 {
     $model = new NewForm();
     $form = new Form('codegen.NewForm', $model);
     if ($form->submitted() && $model->validate()) {
         self::generateAndSaveForm($model->model);
         Yii::app()->user->setFlash(Controller::MSG_SUCCESS, 'Форма создана!');
         $this->redirect($_SERVER['REQUEST_URI']);
     }
     $this->render('create', array('form' => $form));
 }
Example #19
0
 /**
  * Install the application
  */
 public function settings()
 {
     $form = new Form(array('id' => 'install-settings-form', 'labelWidth' => '30em', 'fieldsets' => array('global' => array('legend' => Lang::get('install.settings-global-legend', null, null, $this->language), new TextInput(array('name' => 'title', 'required' => true, 'label' => Lang::get('install.settings-title-label', null, null, $this->language), 'default' => DEFAULT_HTML_TITLE)), new TextInput(array('name' => 'rooturl', 'required' => true, 'label' => Lang::get('install.settings-rooturl-label', null, null, $this->language), 'placeholder' => 'http://', 'default' => getenv('REQUEST_SCHEME') . '://' . getenv('SERVER_NAME'))), new SelectInput(array('name' => 'timezone', 'required' => true, 'options' => array_combine(\DateTimeZone::listIdentifiers(), \DateTimeZone::listIdentifiers()), 'default' => DEFAULT_TIMEZONE, 'label' => Lang::get('install.settings-timezone-label')))), 'database' => array('legend' => Lang::get('install.settings-database-legend', null, null, $this->language), new TextInput(array('name' => 'db[host]', 'required' => true, 'label' => Lang::get('install.settings-db-host-label', null, null, $this->language), 'default' => 'localhost')), new TextInput(array('name' => 'db[username]', 'required' => true, 'label' => Lang::get('install.settings-db-username-label', null, null, $this->language))), new PasswordInput(array('name' => 'db[password]', 'required' => true, 'label' => Lang::get('install.settings-db-password-label', null, null, $this->language), 'pattern' => '/^.*$/')), new TextInput(array('name' => 'db[dbname]', 'required' => true, 'pattern' => '/^\\w+$/', 'label' => Lang::get('install.settings-db-dbname-label', null, null, $this->language))), new TextInput(array('name' => 'db[prefix]', 'default' => 'Hawk', 'pattern' => '/^\\w+$/', 'label' => Lang::get('install.settings-db-prefix-label', null, null, $this->language)))), 'admin' => array('legend' => Lang::get('install.settings-admin-legend', null, null, $this->language), new TextInput(array('name' => 'admin[login]', 'required' => true, 'pattern' => '/^\\w+$/', 'label' => Lang::get('install.settings-admin-login-label', null, null, $this->language))), new EmailInput(array('name' => 'admin[email]', 'required' => true, 'label' => Lang::get('install.settings-admin-email-label', null, null, $this->language))), new PasswordInput(array('name' => 'admin[password]', 'required' => true, 'label' => Lang::get('install.settings-admin-password-label', null, null, $this->language))), new PasswordInput(array('name' => 'admin[passagain]', 'required' => true, 'compare' => 'admin[password]', 'label' => Lang::get('install.settings-admin-passagain-label', null, null, $this->language)))), '_submits' => array(new SubmitInput(array('name' => 'valid', 'value' => Lang::get('install.install-button', null, null, $this->language), 'icon' => 'cog')))), 'onsuccess' => 'location.href = data.rooturl;'));
     if (!$form->submitted()) {
         // Display the form
         $body = View::make(Plugin::current()->getView('settings.tpl'), array('form' => $form));
         return \Hawk\Plugins\Main\MainController::getInstance()->index($body);
     } else {
         // Make the installation
         if ($form->check()) {
             /**
              * Generate Crypto constants
              */
             $salt = Crypto::generateKey(24);
             $key = Crypto::generateKey(32);
             $iv = Crypto::generateKey(16);
             $configMode = 'prod';
             /**
              * Create the database and it tables
              */
             $tmpfile = tempnam(sys_get_temp_dir(), '');
             DB::add('tmp', array(array('host' => $form->getData('db[host]'), 'username' => $form->getData('db[username]'), 'password' => $form->getData('db[password]'))));
             try {
                 DB::get('tmp');
             } catch (DBException $e) {
                 return $form->response(Form::STATUS_ERROR, Lang::get('install.install-connection-error'));
             }
             try {
                 $param = array('{{ $dbname }}' => $form->getData('db[dbname]'), '{{ $prefix }}' => $form->getData('db[prefix]'), '{{ $language }}' => $this->language, '{{ $timezone }}' => $form->getData('timezone'), '{{ $title }}' => Db::get('tmp')->quote($form->getData('title')), '{{ $email }}' => Db::get('tmp')->quote($form->getData('admin[email]')), '{{ $login }}' => Db::get('tmp')->quote($form->getData('admin[login]')), '{{ $password }}' => Db::get('tmp')->quote(Crypto::saltHash($form->getData('admin[password]'), $salt)), '{{ $ip }}' => Db::get('tmp')->quote(App::request()->clientIp()));
                 $sql = strtr(file_get_contents(Plugin::current()->getRootDir() . 'templates/install.sql.tpl'), $param);
                 // file_put_contents($tmpfile, $sql);
                 Db::get('tmp')->query($sql);
                 /**
                  * Create the config file
                  */
                 $param = array('{{ $salt }}' => addcslashes($salt, "'"), '{{ $key }}' => addcslashes($key, "'"), '{{ $iv }}' => addcslashes($iv, "'"), '{{ $configMode }}' => $configMode, '{{ $rooturl }}' => $form->getData('rooturl'), '{{ $host }}' => $form->getData('db[host]'), '{{ $username }}' => $form->getData('db[username]'), '{{ $password }}' => $form->getData('db[password]'), '{{ $dbname }}' => $form->getData('db[dbname]'), '{{ $prefix }}' => $form->getData('db[prefix]'), '{{ $sessionEngine }}' => $form->getData('session'), '{{ $version }}' => $form->getData('version'));
                 $config = strtr(file_get_contents(Plugin::current()->getRootDir() . 'templates/config.php.tpl'), $param);
                 file_put_contents(INCLUDES_DIR . 'config.php', $config);
                 /**
                  * Create etc/dev.php
                  */
                 App::fs()->copy(Plugin::current()->getRootDir() . 'templates/etc-dev.php', ETC_DIR . 'dev.php');
                 /**
                  * Create etc/prod.php
                  */
                 App::fs()->copy(Plugin::current()->getRootDir() . 'templates/etc-prod.php', ETC_DIR . 'prod.php');
                 $form->addReturn('rooturl', $form->getData('rooturl'));
                 return $form->response(Form::STATUS_SUCCESS, Lang::get('install.install-success'));
             } catch (\Exception $e) {
                 return $form->response(Form::STATUS_ERROR, Lang::get('install.install-error'));
             }
         }
     }
 }
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     $model->body = file_get_contents($model->getFilePath());
     $form = new Form('mailer.MailerTemplateForm', $model);
     $this->performAjaxValidation($model);
     if ($form->submitted() && $model->save()) {
         $this->redirect(array('view', 'id' => $model->id));
     }
     $this->render('update', array('form' => $form));
 }
Example #21
0
 public function run()
 {
     $this->controller->layout = $this->layout;
     $model = new Page(ActiveRecord::SCENARIO_CREATE);
     $form = new Form('content.PageForm', $model);
     //$this->getController()->performAjaxValidation($model);
     if ($form->submitted() && $model->save()) {
         $this->controller->redirect(['view', 'id' => $model->id]);
     }
     $this->controller->render('create', ['form' => $form]);
 }
 public function actionCreate()
 {
     $model = new User(User::SCENARIO_LOGIN);
     $form = new Form('users.LoginForm', $model);
     $this->performAjaxValidation($model);
     if ($form->submitted() && $model->validate()) {
         Yii::app()->user->setFlash('success', t('Вы успешно авторизованы'));
         $this->redirect(Yii::app()->user->model->url);
     }
     $this->render('create', array('form' => $form));
 }
Example #23
0
File: Filter.php Project: atk4/atk4
 /**
  * On form submit memorize or forget filtering parameters.
  */
 public function submitted()
 {
     if (parent::submitted()) {
         if (isset($this->reset) && $this->isClicked($this->reset)) {
             $this->forget();
             $this->js(null, $this->view->js()->reload())->reload()->execute();
         } else {
             $this->memorizeAll();
         }
         $this->view->js()->reload()->execute();
     }
 }
Example #24
0
 /**
  * Display the main page of the permission settings
  */
 public function index()
 {
     $permissionGroups = Permission::getAllGroupByPlugin();
     $example = isset($this->roleId) ? array('roleId' => $this->roleId) : array();
     $data = RolePermission::getListByExample(new DBExample($example));
     $values = array();
     foreach ($data as $value) {
         $values[$value->permissionId][$value->roleId] = $value->value;
     }
     $roles = isset($this->roleId) ? array(Role::getById($this->roleId)) : Role::getAll(null, array(), array(), true);
     $param = array('id' => 'permissions-form', 'fieldsets' => array('form' => array(), '_submits' => array(new SubmitInput(array('name' => 'valid', 'value' => Lang::get('main.valid-button'))))));
     foreach ($roles as $role) {
         foreach ($permissionGroups as $group => $permissions) {
             if (Plugin::get($group)) {
                 foreach ($permissions as $permission) {
                     if ($role->id == Role::ADMIN_ROLE_ID) {
                         $default = 1;
                     } elseif (isset($values[$permission->id][$role->id])) {
                         $default = $values[$permission->id][$role->id];
                     } else {
                         $default = 0;
                     }
                     $param['fieldsets']['form'][] = new CheckboxInput(array('name' => "permission-{$permission->id}-{$role->id}", 'disabled' => $role->id == Role::ADMIN_ROLE_ID || $role->id == Role::GUEST_ROLE_ID && !$permission->availableForGuests, 'default' => $default, 'class' => $permission->id == Permission::ALL_PRIVILEGES_ID ? 'select-all' : '', 'nl' => false));
                 }
             }
         }
     }
     $form = new Form($param);
     if (!$form->submitted()) {
         $page = View::make(Plugin::current()->getView("permissions.tpl"), array('permissions' => $permissionGroups, 'fields' => $form->inputs, 'roles' => $roles));
         return NoSidebarTab::make(array('icon' => 'unlock-alt', 'title' => Lang::get('permissions.page-title'), 'page' => $form->wrap($page)));
     } else {
         try {
             foreach ($form->inputs as $name => $field) {
                 if (preg_match('/^permission\\-(\\d+)\\-(\\d+)$/', $name, $match)) {
                     $permissionId = $match[1];
                     $roleId = $match[2];
                     $value = App::request()->getBody($name) ? 1 : 0;
                     if ($roleId != Role::ADMIN_ROLE_ID && !($roleId == Role::GUEST_ROLE_ID && !$permission->availableForGuests)) {
                         $permission = new RolePermission();
                         $permission->set(array('roleId' => $roleId, 'permissionId' => $permissionId, 'value' => $value));
                         $permission->save();
                     }
                 }
             }
             App::logger()->info('Permissions were succesfully updated');
             return $form->response(Form::STATUS_SUCCESS, Lang::get("roles.permissions-update-success"));
         } catch (Exception $e) {
             App::logger()->error('An error occured while updating permissions');
             return $form->response(Form::STATUS_ERROR, DEBUG_MODE ? $e->getMessage() : Lang::get("roles.permissions-update-error"));
         }
     }
 }
Example #25
0
 function submitted()
 {
     if (parent::submitted()) {
         /* Imants: These rows are useless because forgetting is done inside memorizeAll
            if($this->isClicked('Clear')){
                $this->clearData();
            }
            */
         $this->memorizeAll();
         $this->view->js()->reload()->execute();
     }
 }
 public function actionCreate()
 {
     $model = new Model();
     $form = new Form('codegen.ModelForm', $model);
     $this->performAjaxValidation($model);
     if ($form->submitted() && $model->validate()) {
         file_put_contents($model->path, $this->actionGetCode($model->attributes, false));
         @chmod($model->path, 0777);
         Yii::app()->user->setFlash(Controller::MSG_SUCCESS, 'Модель создана!');
         $this->redirect($_SERVER['REQUEST_URI']);
     }
     $this->render('create', array('form' => $form));
 }
 public function actionCreateUsers()
 {
     $model = new MediaAlbum(MediaAlbum::SCENARIO_CREATE_USERS);
     $user = Yii::app()->user->model;
     $model->model_id = get_class($user);
     $model->object_id = $user->id;
     $form = new Form('media.AlbumForm', $model);
     $this->performAjaxValidation($model);
     if ($form->submitted() && $model->save()) {
         $this->redirect(['view', 'id' => $model->id]);
     }
     $this->render('createUsers', ['user' => $user, 'form' => $form]);
 }
Example #28
0
 public function actionUpdate($id)
 {
     $model = Page::model()->findByPk($id);
     if (!$model) {
         $this->pageNotFound();
     }
     $form = new Form('content.PageCForm', $model);
     if ($form->submitted() && $model->save()) {
         $model->updateSectionsRels();
         $this->redirect(['view', 'id' => $model->id]);
     }
     $this->render('update', ['form' => $form]);
 }
 public function actionCreate()
 {
     $model = new MediaAlbum();
     $form = new Form('media.AlbumForm', $model);
     $this->performAjaxValidation($model);
     if ($form->submitted('submit') && !$model->validate()) {
     }
     if ($model->userCanEdit()) {
         $model->save(false);
     } else {
         $this->forbidden();
     }
 }
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     $this->performAjaxValidation($model);
     $form = new Form('main.MetaTagForm', $model);
     if ($form->submitted('submit')) {
         $model = $form->model;
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('update', array('form' => $form));
 }