Ejemplo n.º 1
0
 public function addAction()
 {
     // web page title
     $this->view->title = "Ajout d'une sous-catégorie";
     $lang = $this->_getParam('lang');
     if (!$lang) {
         $this->_registry->currentEditLanguage = $this->_defaultEditLanguage;
         $langId = $this->_defaultEditLanguage;
     } else {
         $langId = Cible_FunctionsGeneral::getLanguageID($lang);
         $this->_registry->currentEditLanguage = $langId;
     }
     // variables
     $returnAction = $this->_getParam('return');
     $baseDir = $this->view->baseUrl();
     $cancelUrl = $baseDir . "/" . $this->_moduleTitle . "/" . $this->_name . "/" . $this->_defaultAction . "/";
     if ($returnAction) {
         $returnUrl = $this->_moduleTitle . "/" . $this->_name . "/" . $returnAction;
     } else {
         $returnUrl = $this->_moduleTitle . "/" . $this->_name . "/" . $this->_defaultAction;
     }
     if ($this->view->aclIsAllowed($this->_moduleTitle, 'edit', true)) {
         $imageSrc = $this->view->baseUrl() . "/icons/image_non_ disponible.jpg";
         if ($this->_request->isPost()) {
             $formData = $this->_request->getPost();
             if (isset($formData[$this->_imageSrc]) && $formData[$this->_imageSrc] != "") {
                 if ($formData[$this->_imageSrc] != "") {
                     $imageSrc = $this->_rootImgPath . "tmp/mcith/mcith_" . $formData[$this->_imageSrc];
                 }
             }
         }
         // generate the form
         $form = new FormSubCategories(array('moduleName' => $this->_moduleTitle . '/' . $this->_name, 'baseDir' => $baseDir, 'cancelUrl' => $cancelUrl, 'imageSrc' => $imageSrc, 'imgField' => $this->_imageSrc, 'dataId' => '', 'isNewImage' => true));
         $this->view->form = $form;
         if ($this->_request->isPost()) {
             $formData = $this->_request->getPost();
             if ($form->isValid($formData)) {
                 $formattedName = Cible_FunctionsGeneral::formatValueForUrl($formData['SCI_Name']);
                 $formData['SCI_ValUrl'] = $formattedName;
                 $oSubCategories = new SubCategoriesObject();
                 $recordID = $oSubCategories->insert($formData, $langId);
                 /* IMAGES */
                 //                    mkdir($this->_imageFolder . $recordID)
                 //                            or die("Could not make directory");
                 //                    mkdir($this->_imageFolder . $recordID . "/tmp")
                 //                            or die("Could not make directory");
                 if ($form->getValue($this->_imageSrc) != '') {
                     $config = Zend_Registry::get('config')->toArray();
                     $srcOriginal = $this->_imageFolder . "tmp/" . $form->getValue($this->_imageSrc);
                     $originalMaxHeight = $config[$this->_moduleTitle]['image']['original']['maxHeight'];
                     $originalMaxWidth = $config[$this->_moduleTitle]['image']['original']['maxWidth'];
                     $originalName = str_replace($form->getValue($this->_imageSrc), $originalMaxWidth . 'x' . $originalMaxHeight . '_' . $form->getValue($this->_imageSrc), $form->getValue($this->_imageSrc));
                     $srcMedium = $this->_imageFolder . "tmp/medium_" . $form->getValue($this->_imageSrc);
                     $mediumMaxHeight = $config[$this->_moduleTitle]['image']['medium']['maxHeight'];
                     $mediumMaxWidth = $config[$this->_moduleTitle]['image']['medium']['maxWidth'];
                     if ($mediumMaxHeight > 0 && $mediumMaxWidth > 0) {
                         $mediumName = str_replace($form->getValue($this->_imageSrc), $mediumMaxWidth . 'x' . $mediumMaxHeight . '_' . $form->getValue($this->_imageSrc), $form->getValue($this->_imageSrc));
                         copy($srcOriginal, $srcMedium);
                     }
                     $srcThumb = $this->_imageFolder . "tmp/thumb_" . $form->getValue($this->_imageSrc);
                     $thumbMaxHeight = $config[$this->_moduleTitle]['image']['thumb']['maxHeight'];
                     $thumbMaxWidth = $config[$this->_moduleTitle]['image']['thumb']['maxWidth'];
                     $thumbName = str_replace($form->getValue($this->_imageSrc), $thumbMaxWidth . 'x' . $thumbMaxHeight . '_' . $form->getValue($this->_imageSrc), $form->getValue($this->_imageSrc));
                     copy($srcOriginal, $srcThumb);
                     Cible_FunctionsImageResampler::resampled(array('src' => $srcOriginal, 'maxWidth' => $originalMaxWidth, 'maxHeight' => $originalMaxHeight));
                     Cible_FunctionsImageResampler::resampled(array('src' => $srcThumb, 'maxWidth' => $thumbMaxWidth, 'maxHeight' => $thumbMaxHeight));
                     if ($mediumMaxHeight > 0 && $mediumMaxWidth > 0) {
                         Cible_FunctionsImageResampler::resampled(array('src' => $srcMedium, 'maxWidth' => $mediumMaxWidth, 'maxHeight' => $mediumMaxHeight));
                         rename($srcMedium, $this->_imageFolder . $recordID . "/" . $mediumName);
                     }
                     rename($srcOriginal, $this->_imageFolder . $recordID . "/" . $originalName);
                     rename($srcThumb, $this->_imageFolder . $recordID . "/" . $thumbName);
                 }
                 $this->_redirect($returnUrl);
             } else {
                 $form->populate($formData);
             }
         }
     }
 }