/** * Displays the authorization assignments for an user. */ public function actionUser() { // Create the user model and attach the required behavior $userClass = $this->module->userClass; $model = CActiveRecord::model($userClass)->findByPk($_GET['id']); $model->attachBehavior('rights', new RightsUserBehavior()); $assignedItems = $this->_authorizer->getAuthItems(null, $model->getId(), null, true); $assignments = array_keys($assignedItems); // Make sure we have items to be selected $selectOptions = Rights::getAuthItemSelectOptions(null, $assignments); if ($selectOptions !== array()) { // Create a from to add a child for the authorization item $form = new CForm(array('elements' => array('itemname' => array('label' => false, 'type' => 'dropdownlist', 'items' => $selectOptions)), 'buttons' => array('submit' => array('type' => 'submit', 'label' => Rights::t('core', 'Assign')))), new AssignmentForm()); // Form is submitted and data is valid, redirect the user if ($form->submitted() === true && $form->validate() === true) { // Update and redirect $this->_authorizer->authManager->assign($form->model->itemname, $model->getId()); $item = $this->_authorizer->authManager->getAuthItem($form->model->itemname); $item = $this->_authorizer->attachAuthItemBehavior($item); Yii::app()->user->setFlash($this->module->flashSuccessKey, Rights::t('core', 'Permission :name assigned.', array(':name' => $item->getNameText()))); $this->redirect(array('assignment/user', 'id' => $model->getId())); } } else { $form = null; } // Create a data provider for listing the assignments $dataProvider = new AuthItemDataProvider('assignments', array('userId' => $model->getId())); // Render the view $this->render('user', array('model' => $model, 'dataProvider' => $dataProvider, 'form' => $form)); }
public function actionTac_vu_khach() { $dangtin = new LoginForm(); $khachhang = new Khachhang(); $form = new CForm('application.views.admin.tac_vu_khach.form_tac_vu_khach', $khachhang); $khachhang->setScenario('dang_tin_khach'); if ($form->submitted('dangtinkhach') && $form->validate()) { $id = $khachhang->idkhach; $arry = explode("_", $id); $username = $arry[0]; if (isset($arry[1])) { $id = $arry[1]; if ($user = Khachhang::model()->TTkhach($id, $username)) { $dangtin->username = $user['ten_dang_nhap']; $dangtin->password = $user['password']; $dangtin->_identity = new UserIdentity($dangtin->username, $dangtin->password); $dangtin->_identity->authenticate(); $dangtin->login(); $this->redirect(Yii::app()->request->baseUrl . '/dang-tin'); } else { $this->__message = "Nhập sai id khách hàng!"; } } else { $this->__message = "Nhập sai cú pháp!"; } } $this->render('tac_vu_khach', array('form' => $form, 'message' => $this->__message)); }
public function actionRegisterconstruct() { $model = new RegisterTestForm(); $form = new CForm("application.views.formconstruct.registerbuilder", $model); if ($form->submitted('register') && $form->validate()) { print "Зарегистрирован удачно"; } $this->render("registerconstruct", array('form' => $form)); }
/** * Displays the order page */ public function actionOrder() { $model = new OrderForm(); $form = new CForm('application.views.site.orderForm', $model); if ($form->submitted('order') && $form->validate()) { $this->redirect(array('site/index')); } else { $this->render('order', array('form' => $form)); } }
public function actionResult() { $model = new SearchForm(); $form = new CForm('application.views.search.form', $model); if ($form->submitted('search') && $form->validate()) { $result = $model->searchResult(); //$this->redirect(array('search/index')); $this->render('index', array('form' => $form, 'result' => $result)); } else { $this->render('index', array('form' => $form)); } }
/** * Action: Index * * @access public * @return void */ public function actionIndex() { // Only go ahead with the logout if the end-user is logged in, if the end-user is a guest then we can skip // the entire logout procedure, and skip to the redirect back home! if (!Yii::app()->user->isGuest) { // Has the "authUser" persistent state been set, which contains the user's true authenticated ID, and is // it different to the user's current ID? if (is_int(Yii::app()->user->getState('authUser')) && Yii::app()->user->getState('authUser') != Yii::app()->user->getState('id') && is_object($authUser = User::model()->findByPk(Yii::app()->user->getState('authUser')))) { $model = new \application\model\form\Logout(); $form = new CForm('application.forms.logout', $model); if ($form->submitted() && $form->validate()) { // Has the user opted to switch back to their original account? if ($model->switch) { // Create a new user identity instance, but since we aren't going to use any credentials to // authenticate the user, we can just pass in empty strings. $identity = new UserIdentity('', ''); // Attempt to load the identitiy of the user defined by the ID in the "authUser" persistent // state. if ($identity->load(Yii::app()->user->getState('authUser')) && Yii::app()->user->login($identity)) { // The original user account was successfully logged in, redirect to the homepage. $this->redirect(Yii::app()->homeUrl); } else { throw new CException(Yii::t('application', 'An error occured whilst attempting to load your original user account. You have been logged out for security reasons.')); } } else { // Log out the current user. Pass bool(false) as an argument to prevent the entire session // from being destroyed, and instead only delete the persistent states that were created // specifically for the user logged in. An example of why this is the behaviour we want is // storing the language selection in a session - if the website visitor selects French as // the language to view the website in (regardless of whether this functionality is actually // implemented), we don't want that session variable destroyed causing the entire website to // switch back to the default language of English just because the user wanted to log out. // Personally I believe that this should be the default behaviour, but it's not. Yii::app()->user->logout(false); $this->redirect(Yii::app()->homeUrl); } } // Render the logout page, so that the end-user may be presented with a choice instead of // automatically logged out (as if the default). $this->render('index', array('form' => $form, 'displayName' => $authUser->displayName)); // End the application here to prevent any redirection. Yii::app()->end(); } else { // Log out the current user. Please refer to the lengthy explaination earlier in this method for why // we pass bool(false). Yii::app()->user->logout(false); } } // We don't want the user to stay on the logout page. Redirect them back to the homepage. $this->redirect(Yii::app()->homeUrl); }
public function actionIndex() { $model = new ConfigForm(); $form = new CForm('application.views.config.form', $model); $model->load(); if ($form->submitted('submit')) { $model->attributes = $_POST['ConfigForm']; if ($model->save()) { Yii::app()->user->setFlash('config', Yii::t('app', 'Your new options have been saved.')); } $this->render('index', array('form' => $form, 'model' => $model, 'result' => $result)); } else { $this->render('index', array('form' => $form)); } }
/** * @param $id * @throws CHttpException */ public function actionUpdate($id) { $model = $this->loadModel($id); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); $formElements = ['title' => 'Update ' . $model->sectionName . ' description', 'elements' => ['<label>Section Name</label><span>' . $model->sectionName . '</span>', 'description' => ['type' => 'textarea']], 'buttons' => ['save' => ['type' => 'submit', 'label' => 'Save']]]; $form = new CForm($formElements, $model); if ($form->submitted('save') && $form->validate()) { if ($model->save()) { Yii::app()->user->setFlash('success', 'Surveillance section description updated successfully'); $this->redirect(['index']); } Yii::app()->user->setFlash('error', 'Surveillance section description not updated successfully,' . ' please contact your administrator'); } $this->render('update', ['model' => $model, 'form' => $form]); }
public function run() { if (!Yii::app()->user->isGuest) { $this->redirect('index.php'); } $form = new CForm('application.views.user.registerForm'); $form['user']->model = new User('register'); $form['profile']->model = new UserProfile(); if ($form->submitted('register') && $form->validate()) { $user = $form['user']->model; $profile = $form['profile']->model; if ($user->save(false)) { $profile->id = $user->id; $profile->save(false); $this->redirect(array('site/index')); } } else { $this->render('register', array('form' => $form)); } }
/** * Đăng tin rao vặt */ public function actionDang_tin($currentPage = 1) { if (Yii::app()->user->name == 'Guest' || !isset(Yii::app()->user->userId)) { $this->redirect(Yii::app()->homeUrl . 'dang-nhap'); } $form = new CForm('application.views.user.rao_vat._form'); $form['tinkhachhang']->model = new Tinkhachhang(); $form['tinraovat']->model = $tinraovat = new Tinraovat(); $noticeMessage = ''; if ($form->submitted('dangtin') && $form->validate()) { $tinkhachhang = $form['tinkhachhang']->model; $tinraovat = $form['tinraovat']->model; //Nếu không đủ tiền để đăng tin sẽ không đăng if ($tinkhachhang->trutien(Tinraovat::CODE_RV)) { $tinkhachhang->ma_loai_tin = Tinraovat::CODE_RV; if ($tinkhachhang->save(false)) { $image = CUploadedFile::getInstance($tinraovat, 'anh'); if ($image) { $newName = md5(microtime(true) . 'xechieuve') . $image->name; $tinraovat->anh = $newName; $image->saveAs(Tinraovat::IMAGE_DIR_RV . $newName); } $tinraovat->ma_tin = $tinkhachhang->ma_tin; $tinraovat->save(false); $this->__message = "Tin bạn đăng đã được hiển thị tại trang rao vặt"; } } else { $this->__message = "Tài khoản của bạn không đủ để đăng tin"; } } $tinraovat = new Tinraovat(); $paginatorRV = new Paginate($currentPage, new Tinkhachhang(), self::LIMITED_REDCORD_RV, ' ma_loai_tin = ' . Tinraovat::CODE_RV); $listTinRV = $tinraovat->listTinRV($paginatorRV); //render view $data = array('form' => $form, 'listTinRV' => $listTinRV, 'paginatorRV' => $paginatorRV, 'urlPaginatorRV' => 'rao_vat/pagedtrv?page=', 'ajaxElementId' => '#tableRV', 'message' => $this->__message); if (Yii::app()->request->isAjaxRequest) { $this->renderPartial('dang_tin', $data); } else { $this->render('dang_tin', $data); } }
public function actionUpdateEvaContext($id) { Yii::log("actionUpdateEvaContext called", "trace", self::LOG_CAT); $this->setPageTitle('Update Evaluation Context'); if (isset($_POST['pageId'])) { SystemController::savePage($this->createUrl('updateEvaContext', ['id' => $id])); } $evaluationHeader = EvaluationHeader::model()->with('evalDetails')->find('t.evalId=:evaId', [':evaId' => $id]); //$this->frameworkId = Yii::app()->session['surDesign']['id']; $dataArray = []; $dataArray['formType'] = 'Update'; $model = new EvalForm(); //print_r(FrameworkContext::model()->getFrameworkSummary($this->frameworkId)); die; $returnArray = self::getElementsAndDynamicAttributes(); $elements = $returnArray['elements']; $model->setRules($returnArray['rules']); $model->setProperties($returnArray['dynamicDataAttributes']); $model->setAttributeLabels($returnArray['labels']); //print_r($model->attributes); die; foreach ($model->attributes as $attributeName => $attributeVal) { $attributeNameAndId = explode('_', $attributeName); foreach ($evaluationHeader->evalDetails as $evaluationData) { if (isset($attributeNameAndId[1]) && $attributeNameAndId[1] == $evaluationData->evalElementsId) { $model->setPropertyName($attributeName, $evaluationData->value); if (DForm::isJson($evaluationData->value)) { $model->setPropertyName($attributeName, json_decode($evaluationData->value)); } break; } } } $elements['buttons'] = ['updateEvaluation' => ['label' => 'Update evaluation context', 'type' => 'submit']]; // generate the elements form $form = new CForm($elements); $form['evaluationHeader']->model = $evaluationHeader; $form['evaContext']->model = $model; if ($form->submitted('updateEvaluation')) { //die('opop'); $evaluationHeader = $form['evaluationHeader']->model; $evaluationHeader->frameworkId = Yii::app()->session['surDesign']['id']; $evaluationHeader->userId = Yii::app()->user->id; $model->setProperties($_POST['EvalForm']); //var_dump($model); die; //save the componentHead values if ($evaluationHeader->save() && $model->save($evaluationHeader->evalId, false)) { // if (isset(Yii::app()->session['evaContext'])) { Yii::app()->session->add('evaContext', ['id' => $evaluationHeader->evalId, 'name' => $evaluationHeader->evaluationName, 'questionId' => $evaluationHeader->questionId]); } Yii::app()->user->setFlash('success', Yii::t("translation", "Evaluation protocol updated successfully")); $this->redirect(['listEvaContext']); return; } Yii::app()->user->setFlash('error', Yii::t("translation", "An error occurred when updating the " . "evaluation context, please try again or contact your administrator if the problem persists")); } $this->docName = 'addEvaContext'; $page = SystemController::getPageContent($this->docName); $this->render('context', ['model' => $model, 'dataArray' => $dataArray, 'form' => $form, 'page' => $page]); }
public function actionForm() { $this->cekLogin('form'); if ($this->isWizard) { $this->backAction = 'division'; } $model = new RegistrationForm(); $model->initComponent($this->rec->id, O::app()->user->id); $form = new CForm(array('elements' => $model->elements, 'buttons' => array('submit-form' => array('type' => 'submit', 'label' => O::t('oprecx', 'Save'))), 'activeForm' => array('class' => 'CActiveForm'), 'attributes' => array('id' => 'reg-form')), $model); if ($form->submitted('save') && $form->validate() && $model->save()) { //if ($this->isWizard) $this->redirect($this->getURL('interview', array('wiz' => 1))); if ($this->afterSave('interview')) { return; } } $this->render('form', array('form' => $form)); }
public function actionUpload() { $model = new BackupUpload(); $form = new CForm('application.models.uploadForm', $model); if ($form->submitted('submit') && $form->validate()) { $form->model->backup = CUploadedFile::getInstance($form->model, 'backup'); $fc = file_get_contents($form->model->backup->tempName); $xml = new SimpleXMLElement($fc, LIBXML_NOCDATA); foreach ($xml->record as $record) { foreach ((array) $record->attributes() as $val) { if (AbuserTrigger::model()->findByAttributes($val) === null) { $tr = new AbuserTrigger(); $tr->attributes = $val; if ($tr->validate()) { $tr->save(); } } } } Yii::app()->user->setFlash('success', 'File Uploaded'); $this->redirect(array('upload')); } $this->render('upload', array('form' => $form)); }
/** * Updates an authorization item. */ public function actionUpdate() { // Get the authorization item $model = $this->loadModel(); // Create the authorization item form $form = new CForm('rights.views.authItem.authItemForm', new AuthItemForm('update')); // Form is submitted and data is valid if ($form->submitted() === true && $form->validate() === true) { // Update the item and load it $this->_authorizer->updateAuthItem($_GET['name'], $form->model->name, $form->model->description, $form->model->bizRule, $form->model->data); $item = $this->_authorizer->authManager->getAuthItem($form->model->name); $item = $this->_authorizer->attachAuthItemBehavior($item); // Set a flash message for updating the item Yii::app()->user->setFlash($this->module->flashSuccessKey, Rights::t('core', ':name updated.', array(':name' => $item->getNameText()))); // Redirect to the correct destination $this->redirect(array(isset($_GET['redirect']) === true ? urldecode($_GET['redirect']) : 'authItem/permissions')); } // Create a form to add children to the authorization item $type = Rights::getValidChildTypes($model->type); $exclude = array($this->module->superuserName); $selectOptions = Rights::getParentAuthItemSelectOptions($model, $type, $exclude); if ($selectOptions !== array()) { // Create the child form $childForm = new CForm(array('elements' => array('name' => array('label' => false, 'type' => 'dropdownlist', 'items' => $selectOptions)), 'buttons' => array('submit' => array('type' => 'submit', 'label' => Rights::t('core', 'Add')))), new AuthChildForm()); // Child form is submitted and data is valid if ($childForm->submitted() === true && $childForm->validate() === true) { // Add the child and load it $this->_authorizer->authManager->addItemChild($_GET['name'], $childForm->model->name); $child = $this->_authorizer->authManager->getAuthItem($childForm->model->name); $child = $this->_authorizer->attachAuthItemBehavior($child); // Set a flash message for adding the child Yii::app()->user->setFlash($this->module->flashSuccessKey, Rights::t('core', 'Child :name added.', array(':name' => $child->getNameText()))); // Reidrect to the same page $this->redirect(array('authItem/update', 'name' => $_GET['name'])); } } else { $childForm = null; } // Set the values for the form fields $form->model->name = $model->name; $form->model->description = $model->description; $form->model->type = $model->type; $form->model->bizRule = $model->bizRule !== 'NULL' ? $model->bizRule : ''; $form->model->data = $model->data !== null ? serialize($model->data) : ''; $parentDataProvider = new AuthItemParentDataProvider($model); $childDataProvider = new AuthItemChildDataProvider($model); // Render the view $this->render('update', array('model' => $model, 'parentDataProvider' => $parentDataProvider, 'childDataProvider' => $childDataProvider, 'form' => $form, 'childForm' => $childForm)); }
public function actionChinh_sua_thong_tin() { $this->_checkLogin(); $form = new CForm('application.views.user.khach_hang._formChinhsuathongtin'); $khachHang = $form->model = Khachhang::model()->findByPk(Yii::app()->user->userId); $pass = $khachHang->password; $khachHang->password = ""; $khachHang->setScenario('update'); $array = array(Yii::app()->user->name, Yii::app()->user->userId); $id = implode("_", $array); $khachHang->id = $id; $anh = $khachHang->anh_dai_dien; if ($form->submitted('chinhsua') && $form->validate()) { $image = CUploadedFile::getInstance($khachHang, 'anh_dai_dien'); if ($image) { //Nếu tồn tại ảnh trong CSDL thì sẽ xóa ảnh cũ trong thư mục ảnh if ($anh) { unlink(Yii::app()->basePath . '/../' . Khachhang::AVARTAR_DIR . $anh); } $newName = md5(microtime(true) . 'xechieuve') . $image->name; $khachHang->anh_dai_dien = $newName; $image->saveAs(Khachhang::AVARTAR_DIR . $newName); } else { $khachHang->anh_dai_dien = $anh; } if (md5($khachHang->password) == $pass) { $khachHang->password = md5($khachHang->password); $khachHang->save(FALSE); $this->__message = "Sửa thông tin thành công!"; } else { $this->__message = "Thất bại,bạn nhập sai mật khẩu bạn cần nhập chính xác mật khẩu hiện tại của bạn!"; } } $form2 = new CForm('application.views.user.khach_hang._formcapnhatpass'); $khachHang2 = $form2->model = Khachhang::model()->findByPk(Yii::app()->user->userId); $khachHang2->setScenario('updatepass'); if ($form2->submitted('doimatkhau') && $form2->validate()) { Khachhang::updatepassword(md5($khachHang2["newPassword"])); $this->__message = "Sửa thông tin thành công!"; } $this->render('chinh_sua_thong_tin', array('form' => $form, 'anh' => $anh, 'form2' => $form2, 'message' => $this->__message)); }
/** * @param WizardEvent $event * @return bool */ public function processSurveillance($event) { $fieldsCriteria = new CDbCriteria(); $fieldsCriteria->condition = 'sectionId=' . $event->sender->getCurrentStep(); $fieldsCriteria->order = '`order` ASC, `parentId` ASC'; $surveillanceFieldsModel = FrameworkFields::model()->findAll($fieldsCriteria); $dForm = new DForm($this->getScenario()); $surveillanceModel = new FrameworkContext(); $elements = $this->getDefaultElements(); if ($event->sender->getCurrentStep() === 1) { $surveillanceModel->userId = Yii::app()->user->id; if ($dForm->scenario == 'update') { $surveillanceModel = FrameworkContext::model()->findByPk(Yii::app()->session['surDesign']['id']); } $elements['elements']['context']['elements'] = self::getElements($surveillanceModel, ['name']); $elements['elements']['contextFields']['elements'][] = '<div class="surHeading">' . '1.' . $event->sender->getCurrentStep() . ' ' . $event->sender->getStepLabel() . '</div>'; } $elements['buttons'] = self::getButtons(['name' => 'next', 'label' => 'Next']); $elements['elements']['context']['type'] = 'form'; //$elements['elements']['contextFields']['elements'] = self::getDefaultElements(); $elements['elements']['contextFields']['type'] = 'form'; // $elements['elements']['context'] = array_merge($elements['elements']['context'], $errorArray); // $elements['elements']['contextFields'] = array_merge($elements['elements']['contextFields'], $errorArray); //$contextFields = $dForm->findAll(); $dynamicDataRules = []; $childCounter = 0; $childCount = 0; $parentFieldId = 0; //print_r($elements); die; $gridFieldIds = []; $specialInputs = array_flip(['checkboxlist', 'radiolist', 'dropdownlist']); foreach ($surveillanceFieldsModel as $field) { //if(!is_null($parentFieldId) && $elements['elements']['contextFields']['elements'][] = '<div class="row">'; if ($field->inputType == 'label') { if ($field->childCount > 0) { $childCount = $field->childCount; $parentFieldId = $field->id; $childCounter++; $elements['elements']['contextFields']['elements'][] = '<fieldset><legend>' . $field->label . '</legend>'; } else { $elements['elements']['contextFields']['elements'][] = CHtml::label($field->label, false); } continue; } if ($field->inputType == 'grid') { $elements['elements']['contextFields']['elements'][] = '<div class="row">'; $elements['elements']['contextFields']['elements'][] = "<fieldset><legend> {$field->label} </legend>"; $elements['elements']['contextFields']['elements'][] = self::generateGridElements($field->id, $dForm); $elements['elements']['contextFields']['elements'][] = '</fieldset>'; $elements['elements']['contextFields']['elements'][] = '</div>'; $gridFieldIds[] = $field->id; continue; } if ($field->gridField) { continue; } $attributeName = $field->inputName . '_' . $field->id; $dForm->setPropertyName($attributeName); //$field->inputName; // $dForm->$attributeName = ''; //$field->inputName; $validation = $field->required ? 'required' : 'safe'; $dynamicDataRules[] = [$attributeName, $validation]; $dForm->setAttributeLabels([$attributeName => isset($field->label) ? $field->label : $dForm->generateAttributeLabel($field->inputName)]); $elements['elements']['contextFields']['elements'][$attributeName] = ['label' => isset($field->label) ? $field->label : $dForm->generateAttributeLabel($field->inputName), 'required' => $field->required, 'type' => $field->inputType, 'hint' => UtilModel::urlToLink($field->description), 'data-field' => $field->id, 'layout' => '{label} {hint} {input} {error}']; if ($field->inputType == 'dropdownlist') { $elements['elements']['contextFields']['elements'][$attributeName]['items'] = Options::model()->getContextFieldOptions($field->id); $elements['elements']['contextFields']['elements'][$attributeName]['prompt'] = 'Choose one'; } if ($field->inputType == 'radiolist') { $elements['elements']['contextFields']['elements'][$attributeName]['separator'] = '<br>'; //'labelOptions'=>array('style'=>'display:inline-block'), $elements['elements']['contextFields']['elements'][$attributeName]['style'] = 'width:1em;'; $elements['elements']['contextFields']['elements'][$attributeName]['template'] = '<span class="radiolist">{input} {label}</span>'; $elements['elements']['contextFields']['elements'][$attributeName]['items'] = Options::model()->getContextFieldOptions($field->id); } if ($field->inputType == 'checkboxlist') { $elements['elements']['contextFields']['elements'][$attributeName]['items'] = Options::model()->getContextFieldOptions($field->id); $elements['elements']['contextFields']['elements'][$attributeName]['class'] = 'checkboxlist'; $elements['elements']['contextFields']['elements'][$attributeName]['title'] = 'title'; $elements['elements']['contextFields']['elements'][] = '<div class="clear"></div>'; } if (isset($specialInputs[$field->inputType]) && empty($field->label)) { $elements['elements']['contextFields']['elements'][$attributeName]['label'] = ''; } if (isset($field->parentId) && $field->parentId == $parentFieldId) { if ($childCount != $childCounter) { //echo $childCounter . '======>' . $childCount . '<br>'; $childCounter++; } else { $elements['elements']['contextFields']['elements'][] = '</fieldset>'; } } $elements['elements']['contextFields']['elements'][] = '</div>'; } //var_dump($elements['elements']['contextFields']); //$dForm->setPropertyNames($dynamicDataAttributes); //$dForm->setAttributeLabels($dynamicLabels); $dForm->setRules($dynamicDataRules); // print_r($elements); die; // var_dump($dForm->getAttributes()); // die; $form = new CForm($elements); if ($event->sender->getCurrentStep() == 1) { $form['context']->model = $surveillanceModel; } $form['contextFields']->model = $dForm; //print_r($form); die; $fieldData = []; //$form->loadData(); if ($form->submitted('next')) { $dForm = $form['contextFields']->model; //print_r($form); die; $transaction = Yii::app()->db->beginTransaction(); try { if (isset($form['context']->model)) { $surveillanceModel = $form['context']->model; $surveillanceModel->save(); Yii::app()->session['surDesign'] = ['id' => $surveillanceModel->frameworkId]; } //var_dump($this->surveillanceId . ' ------>tsergtretgretgerd'); die; if (isset($dForm)) { // This can be refactored later $dataIdArray = []; foreach ($dForm->attributes as $attrName => $attrVal) { $frameworkDataModel = new FrameworkFieldData(); //var_dump($event->getStep()); die; if (is_array($attrVal)) { $attrVal = json_encode($attrVal); } $fieldNameAndId = explode('_', $attrName); $dataId = $dForm->getFieldDataId($fieldNameAndId[1]); //var_dump($dataId); die; $dataIdArray[$dataId] = $dataId; $frameworkDataModel->frameworkId = Yii::app()->session['surDesign']['id']; $frameworkDataModel->frameworkFieldId = $fieldNameAndId[1]; $frameworkDataModel->value = $attrVal; //print_r($frameworkDataModel->getAttribute('value')); die; if (isset($dataId)) { $frameworkDataModel->setIsNewRecord(false); //$frameworkDataModel->id = $dataId; $frameworkDataModel->updateAll(['value' => $frameworkDataModel->value], 'frameworkId=:framework AND frameworkFieldId=:fieldId', [':framework' => $frameworkDataModel->frameworkId, ':fieldId' => $frameworkDataModel->frameworkFieldId]); } else { $frameworkDataModel->save(); } //print_r($fieldData); die; } $transaction->commit(); } } catch (Exception $e) { $transaction->rollback(); Yii::log('Error saving surveillance data: ' . $e->getMessage()); die; } // else { // if($form->validate()) { // // //print_r($dForm->attributes); die; // foreach($dForm->attributes as $attrName => $attrVal) { // if(!empty($attrVal)) { // $fieldNameAndId = explode('_', $attrName); // $fieldData[$fieldNameAndId[0]]['frameworkFieldId'] = $fieldNameAndId[1]; // $val = $attrVal; // if(is_array($attrVal)) { // $val = json_encode($attrVal); // } // $fieldData[$fieldNameAndId[0]]['value'] = $val; // $fieldData[$fieldNameAndId[0]]['id'] = $dForm->getFieldDataId($fieldNameAndId[1]); // // } // } // // } // } //$dForm->fieldId = //$dataToSave = array($dForm->getAttributes()); $dataToSave = [$fieldData]; if ($event->sender->getCurrentStep() == 1) { $event->sender->save($surveillanceModel->getAttributes(), 'surveillanceModel'); } //print_r($event->sender); die; $event->sender->save($dataToSave); //print_r($_SESSION['Wizard.steps']); die; $event->handled = true; return true; } else { //print_r($gridFieldIds); die; $sectionCriteria = new CDbCriteria(); $sectionCriteria->select = 'description'; $sectionCriteria->condition = 'sectionId=' . $event->sender->getCurrentStep(); $sectionInfo = SurveillanceSections::model()->find($sectionCriteria); //print_r($sectionInfo->description); die(); // $this->render($event->step, compact('form')); $this->render('create', compact('form', 'event', 'sectionInfo', 'gridFieldIds')); } }
/** * @param $id * @return void */ public function actionUpdateEvaMethod($id) { Yii::log("actionUpdateEvaMethod called", "trace", self::LOG_CAT); $config = self::getEvaMethodsFormConfig(); $buttonParam = array('name' => 'update', 'label' => 'Update'); $config['buttons'] = ContextController::getButtons($buttonParam, 'admin/listEvaMethods'); $model = EvaMethods::model()->findByPk($id); if (is_null($model)) { Yii::app()->user->setFlash('notice', 'That economic evaluation method does not exist.'); $this->redirect(array('admin/listEvaMethods')); return; } unset($config['buttons']['cancel']); $form = new CForm($config, $model); if ($form->submitted('update') && $form->validate()) { $model = $form->model; if ($model->save(false)) { Yii::app()->user->setFlash('success', 'Economic evaluation method updated successfully'); $this->redirect(array('admin/listEvaMethods')); } Yii::app()->user->setFlash('error', 'An error occurred while updating, please try again or contact ' . 'your administrator if the problem persists'); } $this->render('evaMethods/update', array('form' => $form)); }
/** * actionEditComponent * @access public * @return void */ public function actionEditComponent() { Yii::log("actionEditComponent DesignController called", "trace", self::LOG_CAT); $component = new ComponentHead(); $componentDetails = new ComponentDetails(); $dataArray = []; $dataArray['formType'] = 'Edit'; $model = new DesignForm(); $attributeArray = []; if (empty($_GET['id'])) { Yii::app()->user->setFlash('error', Yii::t("translation", "Please select a component to edit")); $this->redirect(['design/listComponents']); } if (!empty(Yii::app()->session['surDesign'])) { //fetch the form data $fetchComponentData = Yii::app()->db->createCommand()->select('cd.componentDetailId, cd.componentId, cd.subFormId, cd.value, sd.inputName, sd.inputType,ch.componentName, op.optionId, op.label')->from('componentDetails cd')->join('surFormDetails sd', 'sd.subFormId = cd.subFormId')->join('componentHead ch', 'ch.componentId = cd.componentId')->leftJoin('options op', 'op.componentId = sd.subFormId')->where('cd.componentId =' . $_GET['id'])->queryAll(); //print_r($fetchComponentData); //arrange data in array $componentData = []; $returnArray = self::getElementsAndDynamicAttributes(); $returnArray['elements']['buttons'] = ['updateComponent' => ['type' => 'submit', 'label' => 'Update component']]; $elements = $returnArray['elements']; //$model = new ComponentsForm; $model->setProperties($returnArray['dynamicDataAttributes']); $model->setAttributeLabels($returnArray['dynamicLabels']); $model->setRules($returnArray['dynamicRules']); // update the model with the data values and add id foreach ($fetchComponentData as $dat) { $compKey = $dat['inputName'] . "_" . $dat['subFormId']; $componentData[$compKey] = ['value' => $dat['value'], 'id' => $dat['componentDetailId']]; $model->{$compKey} = $dat['value']; // add the component name to the array as well but just once if (empty($componentData['componentName'])) { $componentData['componentName'] = $dat['componentName']; $model->componentName = $dat['componentName']; } } //var_dump($model, $fetchComponentData); die; // generate the components form $form = new CForm($elements, $model); if (Yii::app()->getRequest()->getIsAjaxRequest()) { echo CActiveForm::validate([$model]); Yii::app()->end(); } //validate and save the component data if ($form->submitted('DesignForm') && $form->validate()) { //print_r($form->getModel()); die(); $component->setIsNewRecord(false); $component->componentName = $form->model->componentName; $component->frameworkId = Yii::app()->session['surDesign']['id']; $component->componentId = $_GET['id']; //save the componentHead values $component->save(); $form->model->unsetProperties(['componentName']); //var_dump($form->model); die; $componentId = $_GET['id']; // fetch the form data foreach ($form->model as $key => $val) { $componentDetails = new ComponentDetails(); // record found edit record if (!empty($componentData[$key])) { $componentDetails->setIsNewRecord(false); $componentDetails->componentDetailId = $componentData[$key]['id']; $componentDetails->componentId = $componentId; $componentDetails->value = $val; $componentDetails->save(false); // record not found add new record } else { $componentDetails->setIsNewRecord(true); $componentDetails->componentDetailId = null; $componentDetails->componentId = $componentId; $params = explode("_", $key); $componentDetails->subFormId = $params[1]; $componentDetails->value = $val; $componentDetails->save(); } } Yii::app()->user->setFlash('success', Yii::t("translation", "Component successfully updated")); $this->redirect(['listComponents']); } $this->render('component', ['model' => $model, 'dataArray' => $dataArray, 'form' => $form]); } }
public function actionUpdate() { $model = $this->_loadModel('4ba441778ead0e8f3e000000'); $form = new CForm($this->_buildForm(), $model); if ($form->submitted('save') && $form->validate()) { $model->attributes = $_POST['CatalogForm']; //insert Catalog Yii::import('application.extensions.mp.*'); $manager = new MPCatalogManager(); $manager->updateCatalog($model->attributes); //model->attributes['folders'] should be change to array //model->attributes['tags'] should be change to array //var_dump($model->attributes); die('sukses'); } else { $this->render('update', array('form' => $form)); } }
/** * This action displays a form for crash report upload. */ public function actionUploadFile() { // Check if user is authorized to perform the action $this->checkAuthorization(null, 'pperm_manage_crash_reports'); $model = new CrashReport(); $form = new CForm('application.views.crashReport.uploadForm', $model); if ($form->submitted('upload') && $form->validate()) { $model->fileAttachment = CUploadedFile::getInstance($model, 'fileAttachment'); // This will create a new record in the {{crashreport}} db table // and move the uploaded file to its persistent location. $form->model->save(); } // Display the result $this->render('uploadFile', array('form' => $form)); }
public function actionEntry() { $form = new CForm('application.views.checkIncome.entry_form'); $form['check']->model = new CheckIncome(); $form['income']->model = new Income('check'); if ($form->submitted('entry_form')) { // now the saving! $check = $form['check']->model; $check->incomes = array($form['income']->model); if ($check->withRelated->save(true, array('incomes'))) { $this->redirect(array('view', 'id' => $form['check']->model->id)); } } $this->render('entry', array('form' => $form)); }