/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new MapFloorPlanAnnotation();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['MapFloorPlanAnnotation'])) {
         $model->attributes = $_POST['MapFloorPlanAnnotation'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new MapFloorPlan();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     $model->map_id = $this->_map->id;
     if (isset($_POST['MapFloorPlan'])) {
         $rnd = rand(0, 9999);
         $model->attributes = $_POST['MapFloorPlan'];
         $uploadedFile = CUploadedFile::getInstance($model, 'map_path');
         $fileName = "{$rnd}-{$uploadedFile}";
         // random number + file name
         $model->map_path = $fileName;
         if ($model->save()) {
             $uploadedFile->saveAs(Yii::app()->basePath . '/../maps/' . $fileName);
             include Yii::app()->basePath . '/../SimpleImage.php';
             $image = new SimpleImage();
             $image->load(Yii::app()->basePath . '/../maps/' . $model->map_path);
             if ($model->size == 0) {
                 $image->resize(160, 160);
             } else {
                 if ($model->size == 1) {
                     $image->resize(480, 480);
                 } else {
                     $image->resize(1440, 1440);
                 }
             }
             $image->save(Yii::app()->basePath . '/../maps/' . $model->map_path);
             $MapFloorPlanAnnotationModel = new MapFloorPlanAnnotation();
             $MapFloorPlanAnnotationModel->map_id = $model->map_id;
             $MapFloorPlanAnnotationModel->floor_id = $model->id;
             $MapFloorPlanAnnotationModel->save();
             $this->redirect(array('view', 'id' => $model->id, 'mid' => $model->map_id));
         }
     }
     $this->render('create', array('model' => $model));
 }