Пример #1
0
 public function actionAddAjax()
 {
     if (!isset(Yii::app()->user->storeID)) {
         $data['message'] = '<div class="alert alert-success">Store not found. </div>';
         echo json_encode($data);
         exit;
     }
     $model = new ServiceType();
     $model->s_store_id = Yii::app()->user->storeID;
     if (isset($_POST['ServiceType'])) {
         $model->attributes = $_POST['ServiceType'];
         $data = array();
         $mss = '';
         if (count($data) == 0) {
             $model->pk_s_id = '-1';
             $model->i_flag_sync = 1;
             $model->i_flag_deleted = 0;
             $model->i_disable = 0;
             if ($model->save()) {
                 $model->pk_s_id = 'SV' . $model->id;
                 if ($model->save()) {
                     $data['option'] = '<option selected="selected" value ="' . $model->pk_s_id . '">' . $model->s_name . '</option>';
                     $data['message'] = '<div class="alert alert-success">Success! Type Service Created. </div>';
                 } else {
                     $model->delete();
                     $data['message'] = '<div class="alert alert-danger">Error! Please try again later.</div>';
                 }
             } else {
                 $data['message'] = json_encode($model->errors);
                 //'<div class="alert alert-danger">Error! Please try again later2.</div>';
             }
         }
         echo json_encode($data);
     }
 }
Пример #2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new ServiceType();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['ServiceType'])) {
         $model->attributes = $_POST['ServiceType'];
         if ($model->save()) {
             if (!empty($_POST['yt1'])) {
                 Yii::app()->user->setFlash('serviceType-created', "¡El tipo de servicio <b><i>&quot;{$model->description}&quot;</i></b> fue creado exitosamente!");
                 $model = new ServiceType();
             } else {
                 $this->redirect(array('view', 'id' => $model->id));
             }
         }
     }
     $this->render('create', array('model' => $model));
 }