/**
  * 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 (isset($_POST['AdminRadioModel'])) {
         //echo '<pre>';print_r($_POST);exit;
         $model->attributes = $_POST['AdminRadioModel'];
         if (isset($_POST['AdminRadioModel']['time_point'])) {
             $time_point = implode(',', $_POST['AdminRadioModel']['time_point']);
             $model->setAttribute('time_point', $time_point);
         } else {
             $model->setAttribute('time_point', 1);
         }
         if (isset($_POST['AdminRadioModel']['day_week'])) {
             $day_week = implode(',', $_POST['AdminRadioModel']['day_week']);
             $model->setAttribute('day_week', $day_week);
         } else {
             $model->setAttribute('day_week', 1);
         }
         if (isset($_POST['AdminRadioModel']['weather_code'])) {
             $weather_code = implode(',', $_POST['AdminRadioModel']['weather_code']);
             $model->setAttribute('weather_code', $weather_code);
         } else {
             $model->setAttribute('weather_code', '');
         }
         if (isset($_POST['AdminRadioModel']['daytotime'])) {
             $dayToTime = json_encode($_POST['AdminRadioModel']['daytotime']);
             $model->setAttribute('day_to_time', $dayToTime);
         } else {
             $model->setAttribute('day_to_time', '');
         }
         if ($model->save()) {
             $res = Yii::app()->db->createCommand("DELETE FROM radio_weather WHERE radio_id=" . intval($model->id))->execute();
             if (isset($_POST['AdminRadioModel']['weather_id'])) {
                 $radioWModel = new AdminRadioWeatherModel();
                 $sql = "INSERT INTO radio_weather(radio_id, weather_id) VALUES";
                 foreach ($_POST['AdminRadioModel']['weather_id'] as $w) {
                     $radioId = $model->id;
                     $sqlArr[] = "('{$radioId}','{$w}')";
                 }
                 $sql .= implode(',', $sqlArr);
                 $sql .= "ON DUPLICATE KEY UPDATE radio_id = '{$radioId}'";
                 $res = Yii::app()->db->createCommand($sql)->execute();
             }
             if (isset($_POST['tmp_file_path']) && $_POST['tmp_file_path'] != '') {
                 $tmpFile = _APP_PATH_ . DS . "data" . DS . "tmp" . DS . $_POST['tmp_file_path'];
                 if (file_exists($tmpFile)) {
                     //$this->moveFile($model->id, $model->type, $tmpFile);
                     $res = AvatarHelper::processAvatar($model, $tmpFile);
                 }
             }
             if (isset($_POST['yt0']) && ($_POST['yt0'] = 'Save')) {
                 $this->redirect(array('view', 'id' => $model->id));
             } else {
                 $this->redirect(array('update', 'id' => $model->id));
             }
         }
     }
     $this->render('update', array('model' => $model));
 }