예제 #1
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (!$model) {
         $this->redirect('?r=jmuser');
         return;
     }
     $errorMessage = "";
     $routeCount = Jmroute::getRouteCount($model->wave);
     $extra = json_decode($model->extra, true);
     if (isset($_POST['LoginForm'])) {
         $extra = $_POST['Extra'];
         $form = $_POST['LoginForm'];
         $translate = $model->attributeLabels();
         $errorMessage = "";
         /*
                     foreach ($form as $k => $v) {
            $model->$k = $v;
            if (empty($v)) {
                $fieldName = isset($translate[$k]) ? $translate[$k]:$k;
                $errorMessage = "所有信息均为必填,缺少信息: " . $fieldName;
            }
                     }
                     foreach (Jmuser::extraFields() as $idx => $f) {
            if (empty($extra[$f])) {
                $fieldName = isset($translate[$f]) ? $translate[$f]:$f;
                $errorMessage = "所有信息均为必填,缺少信息: {$fieldName}" ;
            }
                     }
                     foreach (Jmuser::paperFields() as $idx => $f) {
            if (empty($_POST['Paper'][$f])) {
                $fieldName = isset($translate[$f]) ? $translate[$f]:$f;
                $errorMessage = "所有信息均为必填,缺少信息: {$fieldName}" ;
            }
                     }
         */
         $model->extra = json_encode($_POST['Extra']);
         $model->paper = json_encode($_POST['Paper']);
         if (empty($errorMessage)) {
             $luxian = $extra['luxian'];
             if ($routeCount[$luxian] <= 0) {
                 $errorMessage = "路线选择失败";
             } else {
                 if ($model->save()) {
                     Jmroute::setRoute($model->wave, $id, $_POST['Extra']['luxian']);
                     $this->redirect('?r=jmuser');
                     return;
                 }
                 $errorMessage = "保存失败 :(";
             }
         }
     }
     $model->extra = json_decode($model->extra, true);
     $model->paper = json_decode($model->paper, true);
     $this->renderPartial('update', array('user' => $model, 'error' => $errorMessage, 'route' => $routeCount, 'submit' => strtolower(Yii::app()->getUser()->getName()) != "zhongmai"));
 }
예제 #2
0
 public function actionP4()
 {
     $id = strtoupper(Yii::app()->getUser()->getName());
     $model = Jmuser::model()->findByPk($id);
     if (!$model) {
         $this->redirect('?r=site');
         return;
     }
     $errorMessage = "";
     $routeCount = Jmroute::getRouteCount($model->wave);
     $extra = json_decode($model->extra, true);
     if (isset($_POST['LoginForm'])) {
         $extra = $_POST['Extra'];
         $form = $_POST['LoginForm'];
         $translate = $model->attributeLabels();
         foreach ($form as $k => $v) {
             $model->{$k} = $v;
             if (empty($v)) {
                 $fieldName = isset($translate[$k]) ? $translate[$k] : $k;
                 $errorMessage = "所有信息均为必填,缺少信息: " . $fieldName;
             }
         }
         foreach (Jmuser::extraFields() as $idx => $f) {
             if (empty($extra[$f])) {
                 $fieldName = isset($translate[$f]) ? $translate[$f] : $f;
                 $errorMessage = "所有信息均为必填,缺少信息: {$fieldName}";
             }
         }
         $model->extra = json_encode($extra);
         if (empty($errorMessage)) {
             $luxian = $extra['luxian'];
             if ($routeCount[$luxian] <= 0) {
                 $errorMessage = "路线选择失败";
             } else {
                 if ($model->save()) {
                     Jmroute::setRoute($model->wave, $id, $extra['luxian']);
                     $this->redirect('?r=site/p5');
                     return;
                 }
                 $errorMessage = "保存失败 :(";
             }
         }
     }
     $model->extra = $extra;
     $this->renderPartial('p4', array('user' => $model, 'error' => $errorMessage, 'route' => $routeCount));
 }