コード例 #1
0
ファイル: Helper.php プロジェクト: Comsa-Veurne/modules
 /**
  * Validate the form
  */
 private function validateForm()
 {
     //--is the form submitted?
     if ($this->frm->isSubmitted()) {
         //--no errors?
         if ($this->frm->isCorrect()) {
             //--Get the field
             $filImage = $this->frm->getField('images');
             //--Check if the field is filled in
             if ($filImage->isFilled()) {
                 // image extension and mime type
                 //$filImage->isAllowedExtension(array('jpg', 'png', 'gif', 'jpeg'), BackendLanguage::err('JPGGIFAndPNGOnly'));
                 //$filImage->isAllowedMimeType(array('image/jpg', 'image/png', 'image/gif', 'image/jpeg'), BackendLanguage::err('JPGGIFAndPNGOnly'));
                 //--Add media to database
                 if (is_int($this->addFile())) {
                     //--If media is added, redirect to the tabMedia
                     //SpoonHTTP::redirect(BackendModel::createURLForAction($this->action, $this->module) . "&id=" . $this->id . "&report=media-added#tabMedia");
                 }
             }
             //--Check if the image-array is not empty.
             if (!empty($this->mediaItems['images'])) {
                 //--Get folders
                 $folders = BackendModel::getThumbnailFolders(FRONTEND_FILES_PATH . '/Media/Images', true);
                 //--Loop the images
                 foreach ($this->mediaItems['images'] as $row) {
                     //--Check if the delete parameter is filled in.
                     if (\SpoonFilter::getPostValue("image-" . $row["id"], null, "") == "Y") {
                         //--Delete images from the database
                         $db = BackendModel::getContainer()->get('database');
                         $db->delete("media_modules", "id=?", array($row["id"]));
                         /*
                                                     $image = $this->get((int)$row["id"]);
                         
                                                     if(!empty($image))
                                                     {
                                                         foreach($folders as $folder)
                                                         {
                                                             //--delete the image
                                                             \SpoonFile::delete($folder['path'] . '/' . $row['filename']);
                                                         }
                         
                                                         //--Delete images from the database
                                                         $db = BackendModel::getContainer()->get('database');
                                                         $db->delete("media_modules", "media_id=?", array($row["id"]));
                                                         $db->delete("media", "id=?", array($row["id"]));
                                                     }*/
                     }
                     //--Update text
                     if (\SpoonFilter::getPostValue("text-" . $row["id"], null, "")) {
                         $value = array();
                         $value["text"] = \SpoonFilter::getPostValue("text-" . $row["id"], null, "");
                         $db = BackendModel::getContainer()->get('database');
                         $db->update("media_modules", $value, 'id=' . $row['id']);
                     }
                 }
             }
             if (!empty($this->mediaItems['files'])) {
                 //--Get folders
                 $folder = FRONTEND_FILES_PATH . '/Media/Files';
                 //--Loop the images
                 foreach ($this->mediaItems['files'] as $row) {
                     //--Check if the delete parameter is filled in.
                     if (\SpoonFilter::getPostValue("file-" . $row["id"], null, "") == "Y") {
                         //--Delete images from the database
                         $db = BackendModel::getContainer()->get('database');
                         $db->delete("media_modules", "id=?", array($row["id"]));
                         /*
                                                     $image = $this->get((int)$row["id"]);
                         
                                                     if(!empty($image))
                                                     {
                                                         foreach($folders as $folder)
                                                         {
                                                             //--delete the image
                                                             \SpoonFile::delete($folder['path'] . '/' . $row['filename']);
                                                         }
                         
                                                         //--Delete images from the database
                                                         $db = BackendModel::getContainer()->get('database');
                                                         $db->delete("media_modules", "media_id=?", array($row["id"]));
                                                         $db->delete("media", "id=?", array($row["id"]));
                                                     }*/
                     }
                     //--Update text
                     if (\SpoonFilter::getPostValue("text-" . $row["id"], null, "")) {
                         $value = array();
                         $value["text"] = \SpoonFilter::getPostValue("text-" . $row["id"], null, "");
                         $db = BackendModel::getContainer()->get('database');
                         $db->update("media_modules", $value, 'id=' . $row['id']);
                     }
                 }
             }
         }
     }
 }