コード例 #1
0
 /**
  * IS: Parameter id terdeklarasi
  * FS: Mengirimkan ke viewer: form, poi_id, image
  * Desc: Mengatur aksi yang dilakukan untuk halaman edit
  */
 public function editAction()
 {
     $form = new Admin_Form_ImageForm();
     $gallery_id = $this->_getParam('id');
     $tableImage = new Model_DbTable_Image();
     $tableImageDescription = new Model_DbTable_ImageDescription();
     $this->view->state_edit = TRUE;
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($_POST)) {
             $old_source = $tableImage->getImageSource($gallery_id);
             $old_type = $tableImage->getImageType($gallery_id);
             switch ($_POST['ImageSelect']) {
                 case 'poi':
                     $new_type = 1;
                     break;
                 case 'news':
                     $new_type = 2;
                     break;
             }
             switch ($old_type) {
                 case 1:
                     $old_dir = 'culture';
                     break;
                 case 4:
                     $old_dir = 'news';
                     break;
             }
             $image_upload = FALSE;
             $olduploaddir = UPLOAD_FOLDER . $old_dir . '/';
             $uploaddir = UPLOAD_FOLDER . $_POST['ImageSelect'] . '/';
             $oldthumbdir = $olduploaddir . 'thumbnails/';
             $thumbdir = $uploaddir . 'thumbnails/';
             $uploadfile = $uploaddir . basename($_FILES['ImageUpload']['name']);
             $ext = array('jpg', 'png', 'gif', 'jpeg');
             $extensions = $this->get_file_extension($_FILES['ImageUpload']['name']);
             $update_status = TRUE;
             if ($_FILES['ImageUpload']['name'] != '') {
                 if (!file_exists($uploadfile)) {
                     if ($_FILES['ImageUpload']['size'] <= 2000000) {
                         if (in_array(strtolower($extensions), $ext)) {
                             if (move_uploaded_file($_FILES['ImageUpload']['tmp_name'], $uploadfile)) {
                                 $this->_flash->addMessage("1\\Image successfully uploaded to " . $_POST['ImageSelect'] . " directory!");
                                 $image_upload = TRUE;
                                 $thumbfile = $thumbdir . basename($_FILES['ImageUpload']['name']);
                                 $this->make_thumb($uploadfile, $thumbfile, 150, 130, strtolower($extensions));
                                 if ($old_source != basename($_FILES['ImageUpload']['name'])) {
                                     if (file_exists($uploaddir . $old_source)) {
                                         unlink($uploaddir . $old_source);
                                         unlink($uploaddir . '/thumbnails/' . $old_source);
                                     }
                                 }
                             } else {
                                 $this->_flash->addMessage("2\\Image Upload Failed!");
                                 $update_status = FALSE;
                             }
                         } else {
                             $this->_flash->addMessage("2\\Image Upload Failed! Extensions Error!, Update Canceled");
                             $update_status = FALSE;
                         }
                     } else {
                         $this->_flash->addMessage("2\\Image Upload Failed! Image Size Limit Exceeded, Update Canceled");
                         $update_status = FALSE;
                     }
                 } else {
                     $this->_flash->addMessage("2\\Image Upload Failed! Image with that Name Already Exists!, Update Canceled");
                     $update_status = FALSE;
                 }
             } else {
                 if ($old_type != $new_type) {
                     $uploadfile = $uploaddir . $old_source;
                     $olduploadfile = $olduploaddir . $old_source;
                     if (!file_exists($uploadfile)) {
                         $thumbfile = $thumbdir . $old_source;
                         $oldthumbfile = $oldthumbdir . $old_source;
                         rename($olduploadfile, $uploadfile);
                         rename($oldthumbfile, $thumbfile);
                     } else {
                         $this->_flash->addMessage("2\\Image Upload Failed! Image with that Name Already Exists!");
                     }
                 }
             }
             switch ($_POST['ImageSelect']) {
                 case 'culture':
                     $image_type = 1;
                     break;
                 case 'news':
                     $image_type = 2;
                     break;
             }
             $table_gallery = new Model_DbTable_Image();
             if ($update_status) {
                 if ($_FILES['ImageUpload']['name'] != '') {
                     $new_image = $_FILES['ImageUpload']['name'];
                 } else {
                     $new_image = $old_source;
                 }
                 $input = array('poi_id' => $_POST['poivalue'], 'name' => $_POST['ImageName'], 'source' => $new_image, 'type' => $image_type);
                 $table_gallery->updateImage($input, $gallery_id);
                 $input = array('gallery_id' => $gallery_id, 'language_id' => 1, 'name_language' => $_POST['ImageName'], 'desc_language' => $_POST['ImageDescription']);
                 $table_gallerydesc = new Model_DbTable_ImageDescription();
                 $table_gallerydesc->updateImageDescription($input, $gallery_id);
                 $this->loggingaction('image', 'edit', $gallery_id);
                 $this->_flash->addMessage("1\\Image Update Success!");
             }
         }
         $this->_redirect($this->view->rootUrl('/admin/image/'));
     }
     $data = $tableImage->getImageByIdLang($gallery_id);
     switch ($data['type']) {
         case 0:
             $type_value = 'culture';
             break;
         case 1:
             $type_value = 'culture';
             break;
         case 2:
             $type_value = 'news';
             break;
     }
     if ($data['poi_id'] > 0) {
         $poi_name = $this->view->poiName($data['poi_id']);
     }
     $form->image_name->setValue($data['name_language']);
     $form->image_poi->setValue($poi_name);
     $form->image_description->setValue($data['desc_language']);
     $form->image_type->setValue($type_value);
     $image = $this->view->imageUrl('/upload/' . $type_value . '/thumbnails/' . $data['source']);
     $this->view->poi_id = $data['poi_id'];
     $this->view->image = $image;
     $this->view->form = $form;
 }