public function addfeatureAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         try {
             // Test s'il y a un value_id
             if (empty($datas['value_id'])) {
                 throw new Exception($this->_('An error occurred while saving'));
             }
             // Récupère l'option_value en cours
             $option_value = new Application_Model_Option_Value();
             $option_value->find($datas['value_id']);
             $category = new Folder_Model_Category();
             $category->find($datas['category_id'], 'category_id');
             // Récupère l'option_value en cours
             $category_option_value = new Application_Model_Option_Value();
             $category_option_value->find($datas['category_value_id']);
             $next_positon = $category_option_value->getNextFolderCategoryPosition($datas['category_id']);
             $option_folder = new Application_Model_Option();
             $option_folder->find(array('code' => 'folder'));
             $option_folder_id = $option_folder->getOptionId();
             if ($category_option_value->getFolderCategoryId() == $datas['category_id'] || $category_option_value->getOptionId() == $option_folder_id) {
                 throw new Exception($this->_('You cannot add this feature'));
             }
             $category_option_value->setFolderId($datas['value_id'])->setFolderCategoryPosition($next_positon)->setFolderCategoryId($category->getCategoryId())->save();
             $html = array('success' => 1, 'folder_id' => $datas['value_id']);
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage());
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }
 public function setbackgroundimageAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         try {
             $option_value = new Application_Model_Option_Value();
             $option_value->find($datas['option_id']);
             if (!$option_value->getId()) {
                 throw new Exception($this->_("An error occurred while saving your picture. Please try againg later."));
             }
             // Récupère l'option
             $option = new Application_Model_Option();
             $option->find($option_value->getOptionId());
             $save_path = '/feature/' . $option->getId() . '/background/';
             $relative_path = Application_Model_Application::getImagePath() . $save_path;
             $folder = Application_Model_Application::getBaseImagePath() . $save_path;
             $datas['dest_folder'] = $folder;
             $uploader = new Core_Model_Lib_Uploader();
             $file = $uploader->savecrop($datas);
             $option_value->setBackgroundImage($save_path . $file)->save();
             $datas = array('success' => 1, 'file' => $relative_path . $file);
         } catch (Exception $e) {
             $datas = array('error' => 1, 'message' => $e->getMessage());
         }
         $this->getLayout()->setHtml(Zend_Json::encode($datas));
     }
 }