/** * Lists all models. */ public function actionIndex() { $model = new Category(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Category'])) { $model->attributes = $_POST['Category']; if (!Yii::app()->user->isSuperadmin()) { $model->wlabel_id = Yii::app()->user->getWhiteLabelId(); } // set correct sort order if ($model->sort_order == '') { $model->sort_order = $model->getNextSortOrder($model->parent_category_id, $model->wlabel_id); } $logoFile = CUploadedFile::getInstance($model, 'icon'); if ($logoFile != null) { $newFileName = uniqid(rand()) . '.' . Utils::getFileExtension($logoFile->name); $model->icon = $newFileName; } if ($model->parent_category_id == 0) { $model->parent_category_id = null; } if ($model->save()) { if ($logoFile != null) { $logoFile->saveAs(Yii::app()->user->getFullPathToImages(Yii::app()->params['categoryIcon']) . $newFileName); } $this->redirect(array('index')); } } if (isset($_GET['Category'])) { $model->attributes = $_GET['Category']; } $openCategoryId = ''; if (isset($_GET['open_cat_id'])) { $openCategoryId = $_GET['open_cat_id']; } if (isset($_GET['move']) && $_GET['move'] != '' && isset($_GET['cat_id'])) { // move category up or down if ($model->moveCategory($_GET['cat_id'], $_GET['move'])) { $this->redirect(array('index', 'open_cat_id' => $openCategoryId)); } } $this->render('index', array('model' => $model, 'openCategoryId' => $openCategoryId)); }