Exemple #1
0
 function deleteAction()
 {
     $id = AF::get($_POST, 'id', 0);
     $modelsID = explode(',', $id);
     $errors = FALSE;
     foreach ($modelsID as $id) {
         $model = new Shipcat();
         $model->model_uset_id = $this->user->user_id;
         if ($model->fillFromDbPk($id)) {
             $model->delete($id);
         } else {
             $errors = TRUE;
         }
         if ($model->getErrors()) {
             $errors = TRUE;
         }
         unset($model);
     }
     if (isset($_POST['ajax'])) {
         AF::setJsonHeaders('json');
         if ($errors) {
             Message::echoJsonError(__('shipcat_not_deleted'));
         } else {
             $countE = AF::get($_POST, 'countE', 100000);
             if (count($modelsID) >= $countE) {
                 $link = AF::link(array('shipcats' => 'view'));
                 Message::echoJsonRedirect($link);
             } else {
                 Message::echoJsonSuccess(__('shipcat_deleted'));
             }
         }
     }
     $this->redirect();
 }
Exemple #2
0
 function updateAction()
 {
     $model = new Shipping();
     // Uncomment the following line if AJAX validation is needed
     $this->performAjaxValidation($model);
     if (isset($_POST['model']) && $_POST['model'] == 'Shipping') {
         if (isset($_POST['ajax'])) {
             $model->fillFromArray($_POST, FALSE);
             $model->user_id_updated = $this->user->user_id;
             $model->updated = 'NOW():sql';
             $model->model_uset_id = $this->user->user_id;
             if ($model->save()) {
                 Message::echoJsonSuccess(__('shipping_updated'));
             } else {
                 Message::echoJsonError(__('shipping_no_updated'));
             }
             die;
         }
         $model->save();
         $this->redirect();
         die;
     }
     $id = AF::get($this->params, 'id', FALSE);
     if (!$id) {
         throw new AFHttpException(0, 'no_id');
     }
     if (!$model->cache()->findByPk($id)) {
         throw new AFHttpException(0, 'incorrect_id');
     }
     $shipcats = Shipcat::model()->cache()->findAllInArray();
     Assets::js('jquery.form');
     $this->addToPageTitle('Update Shipping');
     $this->render('update', array('model' => $model, 'shipcats' => $shipcats));
 }
Exemple #3
0
 public function cacheCreateFilter($models)
 {
     $array = array('shipcat_id', 'stext');
     $r = $this->checkCacheSearchFields($array);
     if ($r === false) {
         false;
     }
     $returnArray = array();
     $shipcatsID = $this->searchFields['shipcat_id'] ? explode(',', $this->searchFields['shipcat_id']) : null;
     $shipCats = Shipcat::model()->cache()->findAllInArray();
     foreach ($models as $k => $model) {
         $bool = true;
         if ($this->searchFields['stext']) {
             $string = $model['shipping_id'] . $model['shipping_name'];
             $pos = strpos($string, $this->searchFields['stext']);
             if ($pos === false) {
                 $bool = false;
             }
         }
         if ($shipcatsID) {
             if (!in_array($model['shipcat_id'], $shipcatsID)) {
                 $bool = false;
             }
         }
         if ($bool) {
             $model['shipcat_name'] = isset($shipCats[$model['shipcat_id']]['shipcat_name']) ? $shipCats[$model['shipcat_id']]['shipcat_name'] : '';
             $returnArray[] = $model;
         }
     }
     return $returnArray;
 }