/**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  */
 public function actionUpdate()
 {
     if (!isset($_GET['rem'])) {
         $back_url = $_POST['back_url'] ? $_POST['back_url'] : rurl();
         setState('back_url', $back_url);
     }
     $action =& $_GET['action'];
     $top_leaf_id =& $_GET['top_leaf_id'];
     $model = $this->loadModel();
     if (isset($_POST['Article'])) {
         $model->attributes = $_POST['Article'];
         $model->update_time = date("Y-m-d H:i:s");
         if ($model->save()) {
             if (count($_POST['category_article_ids']) > 0) {
                 ManyCategoryArticle::model()->deleteAllByAttributes(array('article_id' => $model->id));
                 foreach ($_POST['category_article_ids'] as $m_category_id) {
                     $_model = new ManyCategoryArticle();
                     $_model->article_id = $model->id;
                     $_model->category_id = $m_category_id;
                     $_model->save();
                 }
             }
             $str = Yii::t('cp', 'Data saved success On ') . Time::now();
             Yii::app()->user->setFlash('success', $str);
             $this->redirect(array('update', 'id' => $model->id, 'action' => $action, 'top_leaf_id' => $top_leaf_id, 'rem' => 0));
         }
     }
     $leaf_tree =& $this->getTree($top_leaf_id);
     $top_leaf = Category::Model()->findByPk($top_leaf_id);
     $this->path = Category::model()->getPath($model->category_id, $top_leaf->id);
     $this->render('update', array('action' => $action, 'model' => $model, 'top_leaf' => $top_leaf, 'leaf_tree' => $leaf_tree));
 }
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  */
 public function actionUpdate()
 {
     $action =& $_GET['action'];
     $top_leaf_id =& $_GET['top_leaf_id'];
     $model = $this->loadModel();
     if (isset($_POST['Attachment'])) {
         $model->attributes = $_POST['Attachment'];
         if ($model->save()) {
             if (isset($_GET['ajax'])) {
                 //echo 'update attachment suc';
                 if ($model->is_image()) {
                     $resize_w = $_POST['resize_w'];
                     $resize_h = $_POST['resize_h'];
                     if (is_array($resize_w) && count($resize_w) > 0) {
                         for ($i = 0; $i < count($resize_w); $i++) {
                             if (is_numeric($resize_w[$i]) && is_numeric($resize_h[$i])) {
                                 $image = Yii::app()->image->load(ATMS_SAVE_DIR . $model->path . '_' . $model->w . '_' . $model->h . '.' . $model->extension);
                                 list($y, $m, $d, $iname) = explode('/', $model->path);
                                 $_path = ATMS_SAVE_DIR . $y . '/' . $m . '/' . $d . '/' . $iname . '_' . $resize_w[$i] . '_' . $resize_h[$i] . '.' . $model->extension;
                                 $image->resize($resize_w[$i], $resize_h[$i]);
                                 $image->save($_path);
                                 if (isset($tips)) {
                                     $tips .= str_pad($resize_w[$i], 4, "_", STR_PAD_LEFT) . '*' . str_pad($resize_h[$i], 4, "_", STR_PAD_RIGHT) . ',';
                                 } else {
                                     $tips = str_pad($resize_w[$i], 4, "_", STR_PAD_LEFT) . '*' . str_pad($resize_h[$i], 4, "_", STR_PAD_RIGHT) . ',';
                                 }
                             }
                         }
                         if (isset($tips)) {
                             $model->tips .= $tips;
                             $model->save();
                         }
                     }
                 }
             } else {
                 $str = 'Data Updated Suc On ' . Time::now();
                 Yii::app()->user->setFlash('success', $str);
                 $this->redirect(array('update', 'id' => $model->id, 'action' => $action, 'top_leaf_id' => $top_leaf_id));
             }
         }
     }
     $top_leaf = Category::Model()->findByPk($top_leaf_id);
     $leaf_tree =& $this->getTree($top_leaf_id);
     $this->path = Category::model()->getPath($model->category_id, $top_leaf->id);
     $this->render('update', array('model' => $model, 'leaf_tree' => $leaf_tree, 'action' => $action, 'top_leaf' => $top_leaf), false, true);
 }