public function actionEdit()
 {
     if (\yii::$app->user->can('UserAccountEdit')) {
         $model = $this->findModel(\Yii::$app->user->identity->id);
         if ($model->load(Yii::$app->request->post())) {
             if ($model->ValidateAndSave()) {
                 Yii::$app->getSession()->setFlash('success', 'Account changed !');
                 //  echo 1;
                 return $this->redirect(['account/my']);
             } elseif (Yii::$app->request->isAjax) {
                 Yii::$app->response->format = Response::FORMAT_JSON;
                 return ActiveForm::validate($model);
             }
         } else {
             //      echo 'cannot save !';
             //      die();
             if (\Yii::$app->request->isAjax) {
                 return $this->renderAjax('edit', ['model' => $model]);
             } else {
                 return $this->render('edit', ['model' => $model]);
             }
         }
     } else {
         throw new \yii\web\NotAcceptableHttpException('No Permission to edit my data');
     }
 }
Esempio n. 2
0
 protected function performAjaxValidation(Model $model)
 {
     if (\Yii::$app->request->isAjax && $model->load(\Yii::$app->request->post())) {
         \Yii::$app->response->format = Response::FORMAT_JSON;
         echo json_encode(ActiveForm::validate($model));
         \Yii::$app->end();
     }
 }
 public function actionIndex()
 {
     $model = new LoginForm();
     if (Yii::$app->request->isAjax) {
         $model->load($_POST);
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if ($model->load(Yii::$app->request->post()) && $model->login()) {
         return $this->goBack();
     } else {
         return $this->render('index', ['model' => $model]);
     }
 }
Esempio n. 4
0
 /**
  * 
  * @return type
  * @throws base\ErrorException
  */
 public function run($id)
 {
     $request = Yii::$app->getRequest();
     if (!$request->isAjax) {
         throw new NotFoundHttpException();
     }
     if ($id) {
         $model = $this->findModel($id);
     } else {
         $model = new $this->modelClass();
     }
     $model->load($request->post());
     Yii::$app->response->format = Response::FORMAT_JSON;
     return ActiveForm::validate($model);
 }
 public function actionEntry()
 {
     $model = new EntryForm();
     if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->get())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if ($model->load(Yii::$app->request->get()) && $model->validate()) {
         // valid data received in $model
         // do something meaningful here about $model ...
         return $this->render('entry-confirm', ['model' => $model]);
     } else {
         // either the page is initially displayed or there is some validation error
         return $this->render('entry', ['model' => $model]);
     }
 }
Esempio n. 6
0
 /**
  * Login user.
  */
 public function actionIndex()
 {
     if (!Yii::$app->user->isGuest) {
         $this->goHome();
     }
     $model = new LoginForm();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             if ($model->login()) {
                 return $this->goHome();
             }
         } elseif (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         }
     }
     return $this->render('index', ['model' => $model]);
 }
Esempio n. 7
0
 public function actionInfo($id = '')
 {
     $model = new QueryForm();
     if (Yii::$app->request->isAjax && \Yii::$app->request->post('ajax', '') == 'info-form' && $model->load(Yii::$app->request->post())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             $model->save();
             Yii::$app->end();
         } else {
             echo json_encode(['code' => -1, 'msg' => json_encode($model->errors, JSON_UNESCAPED_UNICODE)], JSON_UNESCAPED_UNICODE);
             Yii::$app->end();
         }
     }
     $model->update($id);
     return $this->render('info', ['model' => $model]);
 }
Esempio n. 8
0
 public function actionIndex()
 {
     if (Yii::$app->user->isGuest) {
         $this->redirect('/user/sign-in/login', 200);
     }
     $searchModel = new PartnerSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     $model = new LoginForm();
     if (Yii::$app->request->isAjax) {
         $model->load($_POST);
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if ($model->load(Yii::$app->request->post()) && $model->login()) {
         return $this->goBack();
     } else {
         return $this->render('index', ['model' => $model]);
     }
 }
Esempio n. 9
0
 public function actionUserEdit($user_id)
 {
     $user = User::findOne($user_id);
     $user->scenario = 'settings';
     AdminUser::CorrectUserInfo($user);
     $countries = User::getAllCountries(explode('-', Yii::$app->language)[0]);
     // Вивід помилок Ajax валідації
     if (Yii::$app->request->isAjax && $user->load(Yii::$app->request->post())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($user);
     }
     if ($user->load(\Yii::$app->request->post()) && $user->validate()) {
         AdminUser::changePhone($user);
         var_dump($user['telephone_1']);
         AdminUser::correctSite($user['site']);
         $user->save();
         $this->redirect('/admin/user?page=1');
     }
     return $this->render('user_edit', ['user' => $user, 'countries' => $countries]);
 }
 /**
  * Creates a new OrdersTransport model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new OrdersTransportAffiliated();
     $config = new \app\models\Config_system();
     $id = $config->autoId_order("orders_transport_affiliated", "order_id", 5);
     $newId = substr(date("Y"), -2) . "T-" . $id;
     if ($model->load(Yii::$app->request->post())) {
         // Yii::$app->response->format = Response::FORMAT_JSON;
         if (Yii::$app->request->post('orders-transport-affiliated', null)) {
             $model->scenario = 'orders-transport-affiliated';
             return ActiveForm::validate($model);
         }
         if ($model->load(Yii::$app->request->post())) {
             $model->create_date = date("Y-m-d H:i:s");
             $model->save();
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         return $this->render('create', ['model' => $model, 'order_id' => $newId]);
     }
 }
Esempio n. 11
0
 public function actionCreate()
 {
     $model = new Proveedores();
     $modelsContactos = [new ProveedoresContacto()];
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $modelsContactos = Model::createMultiplepcontacto(ProveedoresContacto::classname());
         Model::loadMultiple($modelsContactos, Yii::$app->request->post());
         // ajax validation
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ArrayHelper::merge(ActiveForm::validateMultiple($modelsContactos), ActiveForm::validate($model));
         }
         // validate all models
         $valid = $model->validate();
         $valid = Model::validateMultiple($modelsContactos, ['nombre', 'apellido', 'celular', 'telefono', 'email']) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     foreach ($modelsContactos as $modelsContacto) {
                         $modelsContacto->proveedorid = $model->proveedor_id;
                         if (!($flag = $modelsContacto->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['index']);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
         //return $this->redirect(['view', 'id' => $model->proveedor_id]);
     } else {
         return $this->render('create', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new ProveedoresContacto()] : $modelsContactos]);
     }
 }
Esempio n. 12
0
 /**
  * 物流进度
  * @return type
  */
 public function actionRate()
 {
     $p_param = \Yii::$app->request->get();
     if (isset($p_param['id'])) {
         echo '<p>该功能未开放</p><button type="button" class="btn btn-danger" data-dismiss="modal">关闭</button>';
         \Yii::$app->end();
     }
     $model = new SearchProcessForm();
     if (\Yii::$app->request->isAjax && $model->load(\Yii::$app->request->post())) {
         \Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if ($model->load(\Yii::$app->request->post()) && $model->validate()) {
         $this->refresh();
         if ($resultR) {
             \Yii::$app->session->setFlash('success', '更新成功');
             $this->redirect('/public/notices.html');
             \Yii::$app->end();
         }
     } else {
         return $this->render('product_rate', ['model' => $model]);
     }
 }
Esempio n. 13
0
 /**
  * Creates a new Parameter model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $models = [new Parameter()];
     if (Yii::$app->request->post()) {
         $models = Model::createMultiple(Parameter::classname());
         Model::loadMultiple($models, Yii::$app->request->post());
         // ajax validation
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ActiveForm::validateMultiple($models);
         }
         // validate all models
         $valid = Model::validateMultiple($models);
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 $flag = true;
                 foreach ($models as $model) {
                     if (!($flag = $model->save(false))) {
                         $transaction->rollBack();
                         break;
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     Yii::$app->session->setFlash('alert', ['options' => ['class' => 'alert-success'], 'body' => Yii::t('backend', 'Your data has been successfully saved')]);
                     return $this->redirect(['index']);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
                 Yii::$app->session->setFlash('alert', ['options' => ['class' => 'alert-danger'], 'body' => Yii::t('backend', 'Your data can\'t be saved')]);
                 return $this->redirect(['index']);
             }
         }
     }
     return $this->render('create', ['models' => empty($models) ? [new Parameter()] : $models]);
 }
Esempio n. 14
0
 public function actionFingerEmpSave()
 {
     if (!Yii::$app->user->isGuest) {
         $model = new Kar_finger();
         if ($model->load(Yii::$app->request->post())) {
             //$model->CREATED_BY = Yii::$app->user->identity->username;
             //$model->CREATED_AT = date('Y-m-d H:i:s');
             $model->save();
             return $this->redirect(['index']);
         } else {
             return ActiveForm::validate($model);
         }
     }
 }
 /**
  * Updates an existing MeetingDetails model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $modelMeetingSchedules = $model->meetingSchedules;
     if ($model->load(Yii::$app->request->post())) {
         $oldIDs = ArrayHelper::map($modelMeetingSchedules, 'id', 'id');
         $modelMeetingSchedules = Model::createMultiple(MeetingSchedules::classname(), $modelMeetingSchedules);
         Model::loadMultiple($modelMeetingSchedules, Yii::$app->request->post());
         $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelMeetingSchedules, 'id', 'id')));
         // ajax validation
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ArrayHelper::merge(ActiveForm::validateMultiple($modelMeetingSchedules), ActiveForm::validate($model));
         }
         $model->date = \DateTime::createFromFormat('m-d-Y', $model->date)->format('Y-m-d');
         // validate all models
         $valid = $model->validate();
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     if (!empty($deletedIDs)) {
                         MeetingSchedules::deleteAll(['id' => $deletedIDs]);
                     }
                     foreach ($modelMeetingSchedules as $modelMeetingSchedule) {
                         if (empty($modelMeetingSchedule->congress_id)) {
                             $modelMeetingSchedule->meeting_id = $model->id;
                             $modelMeetingSchedule->congress_id = $model->congress_id;
                             $modelMeetingSchedule->isNewRecord = true;
                         }
                         if ($modelMeetingSchedule->attendee_id > 0 || $modelMeetingSchedule->ol_attendee_id > 0) {
                             $flag = $modelMeetingSchedule->save(false);
                         }
                     }
                     $postData = \Yii::$app->request->post();
                     $olAttendeeData = isset($postData['OlAttendees']) ? $postData['OlAttendees'] : [];
                     foreach ($olAttendeeData as $olAttendeeInfo) {
                         //   print_r($olAttendeeInfo);
                         if (!empty($olAttendeeInfo['name']) && (!isset($olAttendeeInfo['id']) || empty($olAttendeeInfo['id']))) {
                             $olAttendeeModel = new \backend\models\OlAttendees();
                             $olAttendeeModel->user_type_id = 1;
                             $parts = explode(" ", $olAttendeeInfo['name']);
                             $lastname = array_pop($parts);
                             $firstname = implode(" ", $parts);
                             $olAttendeeModel->first_name = $firstname;
                             $olAttendeeModel->last_name = $lastname;
                             $olAttendeeModel->name = $olAttendeeInfo['name'];
                             $olAttendeeModel->ol_bio = $olAttendeeInfo['ol_bio'];
                             $olAttendeeModel->ol_phone_no = $olAttendeeInfo['ol_phone_no'];
                             $olAttendeeModel->ol_email = $olAttendeeInfo['ol_email'];
                             $olAttendeeModel->is_active = 1;
                             $olAttendeeModel->isNewRecord = true;
                             if ($olAttendeeModel->validate()) {
                                 if ($flag = $olAttendeeModel->save(false)) {
                                     $olAttendeeId = $olAttendeeModel->id;
                                     $meetingScheduleModel = new MeetingSchedules();
                                     $meetingScheduleModel->meeting_id = $model->id;
                                     $meetingScheduleModel->congress_id = $model->congress_id;
                                     $meetingScheduleModel->ol_attendee_id = $olAttendeeId;
                                     $meetingScheduleModel->isNewRecord = true;
                                     $flag = $meetingScheduleModel->save(false);
                                     if (!$flag) {
                                         $transaction->rollBack();
                                         break;
                                     }
                                 }
                             }
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $model->id]);
                 }
             } catch (\Exception $e) {
                 $transaction->rollBack();
             }
         }
     } else {
         //Meeting date should be between congress start date and end date
         $congressDetail = CongressDetails::findOne($model->congress_id);
         $congressStartDate = \DateTime::createFromFormat('Y-m-d', $congressDetail->start_date)->format('m-d-Y');
         $congressEndDate = \DateTime::createFromFormat('Y-m-d', $congressDetail->end_date)->format('m-d-Y');
         return $this->render('update', ['model' => $model, 'modelMeetingSchedules' => empty($modelMeetingSchedules) ? [new MeetingSchedules()] : $modelMeetingSchedules, 'congressStartDate' => $congressStartDate, 'congressEndDate' => $congressEndDate]);
     }
 }
Esempio n. 16
0
 /**
  * Performs the AJAX validation.
  * @param BbiiMessage $model the model to be validated
  */
 protected function performAjaxValidation($model)
 {
     if (isset(\Yii::$app->request->post()['ajax']) && \Yii::$app->request->post()['ajax'] === 'message-form') {
         echo ActiveForm::validate($model);
         \Yii::$app->end();
     }
 }
Esempio n. 17
0
 public function actionUpdateD($id)
 {
     $modelTransaksi = $this->findModel($id);
     $modelsTransaksiItem = $modelTransaksi->addresses;
     if ($modelTransaksi->load(Yii::$app->request->post())) {
         $oldIDs = ArrayHelper::map($modelsTransaksiItem, 'id', 'id');
         $modelsTransaksiItem = Model::createMultiple(TransaksiItem::classname(), $modelsTransaksiItem);
         Model::loadMultiple($modelsTransaksiItem, Yii::$app->request->post());
         $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsTransaksiItem, 'id', 'id')));
         // ajax validation
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ArrayHelper::merge(ActiveForm::validateMultiple($modelsTransaksiItem), ActiveForm::validate($modelTransaksi));
         }
         // validate all models
         $valid = $modelTransaksi->validate();
         $valid = Model::validateMultiple($modelsTransaksiItem) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $modelTransaksi->save(false)) {
                     if (!empty($deletedIDs)) {
                         TransaksiItem::deleteAll(['id' => $deletedIDs]);
                     }
                     foreach ($modelsTransaksiItem as $modelAddress) {
                         $modelAddress->customer_id = $modelTransaksi->id;
                         if (!($flag = $modelAddress->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $modelTransaksi->id]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     }
     return $this->render('_formD', ['modelTransaksi' => $modelTransaksi, 'modelsTransaksiItem' => empty($modelsTransaksiItem) ? [new Address()] : $modelsTransaksiItem]);
 }
Esempio n. 18
0
 /**
  * Редактирование данных
  *
  * @param $user_id
  */
 public function actionEditData($user_id)
 {
     $userModel = $this->loadModel($user_id);
     $formModel = new EditUserForm();
     $formModel->role = $userModel->role;
     $formModel->activated = $userModel->activated;
     $formModel->vote_balance = $userModel->profile->vote_balance;
     $formModel->balance = $userModel->profile->balance;
     $formModel->phone = $userModel->profile->phone;
     if ($userModel->profile->protected_ip && is_array($userModel->profile->protected_ip)) {
         $formModel->protected_ip = implode("\r\n", $userModel->profile->protected_ip);
     }
     if (request()->isPostRequest && isset($_POST['EditUserForm'])) {
         $formModel->setAttributes($_POST['EditUserForm']);
         if ($errors = ActiveForm::validate($formModel)) {
             $this->ajax['msg'] = $errors;
         } else {
             $transaction = db()->beginTransaction();
             try {
                 $userModel->role = $formModel->role;
                 $userModel->activated = $formModel->activated;
                 $userModel->profile->vote_balance = $formModel->vote_balance;
                 $userModel->profile->balance = $formModel->balance;
                 $userModel->profile->phone = $formModel->phone;
                 $userModel->profile->protected_ip = $formModel->protected_ip;
                 $userModel->save(FALSE);
                 $userModel->profile->save(FALSE);
                 $transaction->commit();
                 $this->ajax['status'] = TRUE;
                 $this->ajax['msg'] = Yii::t('backend', 'Данные сохранены');
             } catch (Exception $e) {
                 $transaction->rollback();
                 $this->ajax['msg'] = $e->getMessage();
             }
         }
     } else {
         // get
         $this->ajax['status'] = TRUE;
         $this->ajax['view'] = $this->renderPartial('//users/view/edit-data-form', array('formModel' => $formModel, 'userModel' => $userModel), TRUE);
     }
     echo json_encode($this->ajax);
 }
Esempio n. 19
0
 /**
  * Ajax call for change, move or merge topic
  */
 public function actionChangeTopic()
 {
     $json = array();
     if (isset(\Yii::$app->request->post()['BbiiTopic'])) {
         $model = BbiiTopic::find(\Yii::$app->request->post()['BbiiTopic']['id']);
         $move = false;
         $merge = false;
         $sourceTopicId = \Yii::$app->request->post()['BbiiTopic']['id'];
         $sourceForumId = $model->forum_id;
         if ($model->forum_id != \Yii::$app->request->post()['BbiiTopic']['forum_id']) {
             $move = true;
             $targetForumId = \Yii::$app->request->post()['BbiiTopic']['forum_id'];
         }
         if (!empty(\Yii::$app->request->post()['BbiiTopic']['merge']) && \Yii::$app->request->post()['BbiiTopic']['id'] != \Yii::$app->request->post()['BbiiTopic']['merge']) {
             $merge = true;
             $targetTopicId = \Yii::$app->request->post()['BbiiTopic']['merge'];
         }
         $model->load(\Yii::$app->request->post()['BbiiTopic']);
         if ($model->validate()) {
             $json['success'] = 'yes';
             if ($merge || $move) {
                 $numberOfPosts = BbiiPost::find()->where(['topic_id' => $sourceTopicId])->approved()->count();
                 if ($move) {
                     BbiiPost::find()->updateAll(array('forum_id' => $targetForumId), $criteria);
                     $forum = BbiiForum::find($sourceForumId);
                     $forum->updateCounters(array('num_topics' => -1));
                     $forum->updateCounters(array('num_posts' => -$numberOfPosts));
                     $forum = BbiiForum::find($targetForumId);
                     $forum->updateCounters(array('num_topics' => 1));
                     $forum->updateCounters(array('num_posts' => $numberOfPosts));
                     $this->resetLastForumPost($sourceForumId);
                     $this->resetLastForumPost($targetForumId);
                 }
                 if ($merge) {
                     BbiiPost::find()->updateAll(array('topic_id' => $targetTopicId), $criteria);
                     if ($move) {
                         $forum = BbiiForum::find($targetForumId);
                     } else {
                         $forum = BbiiForum::find($sourceForumId);
                     }
                     $forum->updateCounters(array('num_topics' => -1));
                     $topic = BbiiTopic::find($targetTopicId);
                     $topic->updateCounters(array('num_replies' => $numberOfPosts));
                     $model->delete();
                 } else {
                     $model->save();
                 }
             } else {
                 // no move or merge involved
                 $model->save();
             }
         } else {
             $json['error'] = json_decode(ActiveForm::validate($model));
         }
     }
     echo json_encode($json);
     \Yii::$app->end();
 }
Esempio n. 20
0
 /**
  * Creates a new Faer model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($categoria = 0, $subcategoria = 0, $convocatoria = 0)
 {
     $model = new Faer();
     if (!isset($categoria) && $categoria == 0) {
         $categoria = 1;
     }
     $model->categoria = $categoria;
     if (!isset($subcategoria) && $subcategoria == 0) {
         $subcategoria = 1;
     }
     $model->subcategoria = $subcategoria;
     if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['/detalle-proyecto/create', 'numero' => $model->numero]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Esempio n. 21
0
 public function actionCreate($tipo)
 {
     $model = new Comunicado();
     $modelsContactos = [new ComunicadosContactos()];
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $modelsContactos = Model::createMultipleccontacto(ComunicadosContactos::classname());
         Model::loadMultiple($modelsContactos, Yii::$app->request->post());
         // ajax validation
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ArrayHelper::merge(ActiveForm::validateMultiple($modelsContactos), ActiveForm::validate($model));
         }
         // validate all models
         $valid = $model->validate();
         $valid = Model::validateMultiple($modelsContactos, ['nombre', 'cargo', 'telefono', 'correo']) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     foreach ($modelsContactos as $modelsContacto) {
                         $modelsContacto->dependenciaid = $model->dependencia_id;
                         if (!($flag = $modelsContacto->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect([\common\models\Refactor::TipoComunicadobyVista($model->tipocomunicado_id), 'id' => $model->tipocomunicado_id]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     } else {
         return $this->render($tipo, ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new ComunicadosContactos()] : $modelsContactos]);
     }
 }
Esempio n. 22
0
Pjax::begin([
    'id'=>'pjax-form','timeout'=>false,
]);
?>
    <?php 
if (Yii::$app->request->isAjax) {
    echo \app\widgets\Alert::widget();
}
?>
    <?php 
$form = ActiveForm::begin(['options' => ['data-pjax' => true]]);
 public function actionSimpan()
 {
     if (!Yii::$app->user->isGuest) {
         $model = new Pembukuan();
         $nw = Yii::$app->esmcode->kode_ref();
         //print_r($nw);
         //die();
         if ($model->load(Yii::$app->request->post())) {
             $model->SRC_DSC_REF = $nw;
             $model->SRC = Yii::$app->user->identity->warga;
             $model->CREATED_BY = Yii::$app->user->identity->username;
             $model->CREATED_AT = date('Y-m-d H:i:s');
             $model->save();
             return $this->redirect(['index']);
         } else {
             return ActiveForm::validate($model);
         }
     }
 }
Esempio n. 24
0
 public function actionEditPhoto($photo_id)
 {
     $model = ClubPhoto::findOne($photo_id);
     if (Club::isGuest($model->club_id, Yii::$app->user->getId())) {
         return $this->redirect("/club{$model->club_id}");
     }
     $request = Yii::$app->request;
     if ($request->isAjax && $model->load($request->post())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if ($model->load($request->post()) && $model->validate()) {
         $model->save();
         \Yii::$app->getSession()->setFlash('notify', 'Фотографія успішно редагована!');
         return $this->redirect("/club-photo" . $photo_id);
     }
     $date = explode(' ', $model->date);
     $date = explode('-', $date[0]);
     $photoSrc = '/img/club/photos/' . $date[0] . '/' . $date[1] . '/' . $date[2] . '/original_' . $model->src;
     return $this->render('edit-photo', ['model' => $model, 'photoSrc' => $photoSrc]);
 }
Esempio n. 25
0
 /**
  * Updates an existing Product model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $product = $this->findModel($id);
     $product->setScenario('product-update');
     $ingredients = $product->ingredients;
     if ($product->load(Yii::$app->request->post())) {
         $oldIDs = ArrayHelper::map($ingredients, 'id', 'id');
         $ingredients = Model::createMultiple(Ingredients::classname(), $ingredients);
         Model::loadMultiple($ingredients, Yii::$app->request->post());
         $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($ingredients, 'id', 'id')));
         // ajax validation
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ArrayHelper::merge(ActiveForm::validateMultiple($ingredients), ActiveForm::validate($product));
         }
         $product->seen = 0;
         $product->sold = 0;
         $product->user_id = 0;
         // change to admin id or user id
         $product->created_by = Yii::$app->user->identity->username;
         $product->created_date = date('Y-m-d h:m:s');
         $product->modified_by = Yii::$app->user->identity->username;
         $product->modified_date = date('Y-m-d h:m:s');
         $product->status = Status::STATUS_ACTIVE;
         // validate all models
         $valid = $product->validate();
         foreach ($ingredients as $detail) {
             $fields = array('ingredient');
             $valid = $detail->validate($fields) && $valid;
         }
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $product->save(false)) {
                     if (!empty($deletedIDs)) {
                         //Ingredients::updateAll(array( 'status' => Status::STATUS_DELETED ), 'id IN ( ' . implode(",", $deletedIDs) .')' );
                         Ingredients::deleteAll(['id' => $deletedIDs]);
                     }
                     foreach ($ingredients as $ingredient) {
                         $ingredient->created_by = Yii::$app->user->identity->username;
                         $ingredient->created_date = date('Y-m-d h:m:s');
                         $ingredient->modified_by = Yii::$app->user->identity->username;
                         $ingredient->modified_date = date('Y-m-d h:m:s');
                         $ingredient->status = Status::STATUS_ACTIVE;
                         $ingredient->product_id = $product->id;
                         if (!($flag = $ingredient->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                     $product->files = UploadedFile::getInstances($product, 'files');
                     if ($product->files) {
                         foreach ($product->files as $file) {
                             $productPhoto = new ProductPhoto();
                             $imageName = $file->baseName . substr(md5(rand()), 0, 7);
                             $productPhoto->caption = $imageName;
                             $productPhoto->product_id = $product->id;
                             $productPhoto->product_photo_order = 0;
                             $productPhoto->created_by = Yii::$app->user->identity->username;
                             $productPhoto->created_date = date('Y-m-d h:m:s');
                             $productPhoto->modified_by = Yii::$app->user->identity->username;
                             $productPhoto->modified_date = date('Y-m-d h:m:s');
                             $productPhoto->status = Status::STATUS_ACTIVE;
                             $productPhoto->image_path = 'uploads/product/' . $imageName . '.' . $file->extension;
                             if (!($flag = $productPhoto->save(false))) {
                                 $transaction->rollBack();
                                 break;
                             } else {
                                 $file->saveAs('uploads/product/' . $imageName . '.' . $file->extension);
                             }
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $product->id]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     } else {
         return $this->render('create', ['product' => $product, 'ingredients' => empty($ingredients) ? [new Ingredients()] : $ingredients]);
     }
 }
Esempio n. 26
0
 public function actionSimpan()
 {
     $model = new Kategori();
     if ($model->load(Yii::$app->request->post())) {
         $nw = Yii::$app->esmcode->kdKategori();
         $model->KD_KATEGORI = $nw;
         $model->CREATED_BY = Yii::$app->user->identity->username;
         $model->CREATED_AT = date('Y-m-d H:i:s');
         $model->save();
         //                    print_r($model);
         //                    die();
         return $this->redirect(['index']);
     } else {
         return ActiveForm::validate($model);
     }
 }
Esempio n. 27
0
						    <?php 
echo $form->field($model, 'Nama')->textInput(['maxlength' => true]);
?>

						    <?php 
echo $form->field($model, 'Roles_ID')->textInput();
?>

						    <div class="form-group">
						        <?php 
echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
						    </div>

						    <?php 
ActiveForm::end();
?>

						</div>
                    </div>

                    </div>
                </div>
            </div>
    </div>
</div>

<div class="roles-update">

    <h1><?php 
echo Html::encode($this->title);
Esempio n. 28
0
 /**
  * [[@doctodo method_description:generate]].
  *
  * @return unknown
  */
 public function generate()
 {
     if (empty($this->_items)) {
         return '';
     }
     $result = [];
     $formOptions = ['options' => ['class' => ''], 'enableClientValidation' => false];
     if (Yii::$app->request->isAjax) {
         Html::addCssClass($formOptions['options'], 'ajax');
     }
     if ($this->hasFile() && !isset($formOptions['options']['enctype'])) {
         $formOptions['options']['enctype'] = 'multipart/form-data';
     }
     list($this->form, $formStartRow) = ActiveForm::begin($formOptions, false);
     $result[] = $formStartRow;
     // $result[] = Html::beginForm('', 'post', array('class' => $this->class));
     $result[] = Html::beginTag('div', ['class' => '']);
     foreach ($this->_items as $item) {
         $result[] = $item->generate();
     }
     //if (!Yii::$app->request->isAjax) {
     $result[] = Html::beginTag('div', ['class' => 'row form-group submit-group']);
     $result[] = Html::beginTag('div', ['class' => 'col-sm-12']);
     $result[] = Html::submitButton('Save', ['class' => 'btn btn-primary']);
     $result[] = Html::endTag('div');
     $result[] = Html::endTag('div');
     //}
     $result[] = Html::endTag('div');
     $result[] = ActiveForm::end(false);
     return implode("\n", $result);
 }
Esempio n. 29
0
 /**
  * Updates an existing Dealership model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdatedealer($id)
 {
     $modelDealership = $this->findModel($id);
     $modelsShowroom = $modelDealership->Showroomes;
     if ($modelDealership->load(Yii::$app->request->post())) {
         $oldIDs = ArrayHelper::map($modelsShowroom, 'id', 'id');
         $modelsShowroom = Model::createMultiple(Showroom::classname(), $modelsShowroom);
         Model::loadMultiple($modelsShowroom, Yii::$app->request->post());
         $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsShowroom, 'id', 'id')));
         // ajax validation
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ArrayHelper::merge(ActiveForm::validateMultiple($modelsShowroom), ActiveForm::validate($modelDealership));
         }
         // validate all models
         $valid = $modelDealership->validate();
         $valid = $modelDealeraccount->validate();
         $valid = Model::validateMultiple($modelsShowroom) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if (($flag = $modelDealership->save(false)) && ($flag = $modelDealeraccount->save(false))) {
                     if (!empty($deletedIDs)) {
                         Showroom::deleteAll(['id' => $deletedIDs]);
                     }
                     foreach ($modelsShowroom as $modelShowroom) {
                         $modelShowroom->Dealership_id = $modelDealership->id;
                         if (!($flag = $modelShowroom->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $modelDealership->id]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     }
     return $this->render('update', ['modelDealership' => $modelDealership, 'modelsShowroom' => empty($modelsShowroom) ? [new Showroom()] : $modelsShowroom, 'modelsService' => empty($modelsService) ? [new Service()] : $modelsService]);
 }
Esempio n. 30
0
VISTA
---------------------------------------

<?php 
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
?>

<?php 
echo $form->field($model, 'file')->fileInput();
?>

=======================================================================================================================

MODELO
---------------------------------------

public $file;

public function rules()
{
        return [
            .....
            [['file'], 'file'],
            .....
        ];
}

public function attributeLabels()
    {
        return [