コード例 #1
0
ファイル: AdminController.php プロジェクト: xl602/X2CRM
 /**
  * Edit a previously created dropdown
  */
 public function actionEditDropdown()
 {
     $model = new Dropdowns();
     // TODO: validate dropdown select client-side
     if (isset($_POST['Dropdowns']['id']) && ctype_digit($_POST['Dropdowns']['id'])) {
         $model = Dropdowns::model()->findByPk($_POST['Dropdowns']['id']);
         if (!isset($model)) {
             throw new CHttpException(404, Yii::t('app', 'Dropdown could not be found'));
         }
         if ($model->id == Actions::COLORS_DROPDOWN_ID) {
             if (AuxLib::issetIsArray($_POST['Dropdowns']['values']) && AuxLib::issetIsArray($_POST['Dropdowns']['labels']) && count($_POST['Dropdowns']['values']) === count($_POST['Dropdowns']['labels'])) {
                 if (AuxLib::issetIsArray($_POST['Admin']) && isset($_POST['Admin']['enableColorDropdownLegend'])) {
                     Yii::app()->settings->enableColorDropdownLegend = $_POST['Admin']['enableColorDropdownLegend'];
                     Yii::app()->settings->save();
                 }
                 $options = array_combine($_POST['Dropdowns']['values'], $_POST['Dropdowns']['labels']);
                 $temp = array();
                 foreach ($options as $value => $label) {
                     if ($value != "") {
                         $temp[$value] = $label;
                     }
                 }
                 $model->options = json_encode($temp);
                 $model->save();
             }
         } else {
             $model->attributes = $_POST['Dropdowns'];
             $temp = array();
             if (is_array($model->options) && count($model->options) > 0) {
                 foreach ($model->options as $option) {
                     if ($option != "") {
                         $temp[$option] = $option;
                     }
                 }
                 $model->options = json_encode($temp);
                 if ($model->save()) {
                 }
             }
         }
     }
     $this->redirect('manageDropDowns');
 }