public function editpostAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         try {
             $isNew = false;
             $application = $this->getApplication();
             // Test s'il y a un value_id
             if (empty($datas['value_id'])) {
                 throw new Exception($this->_('An error occurred while saving. Please try again later.'));
             }
             // Récupère l'option_value en cours
             $option_value = new Application_Model_Option_Value();
             $option_value->find($datas['value_id']);
             // Récupère l'objet
             $facebook = $option_value->getObject();
             if (!empty($datas['id'])) {
                 $facebook->find($datas['id']);
             } else {
                 $datas['value_id'] = $option_value->getId();
             }
             if ($facebook->getId() and $facebook->getValueId() != $option_value->getId()) {
                 throw new Exception("Une erreur est survenue lors de la sauvegarde de votre galerie vidéos. Merci de réessayer ultérieurement.");
             }
             $facebook->setData($datas)->save();
             $html = array('success' => '1', 'success_message' => $this->_('Info successfully saved'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0);
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }
 public function searchAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         $html = '';
         try {
             // Déclaration des variables
             $categories = array();
             // 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']);
             // Appelle le Wordpress et récupère la réponse
             $wordpress = $option_value->getObject();
             $root_category = $wordpress->getRemoteRootCategory($datas['url']);
             // Test si les données sont OK
             if ($root_category->getChildren()) {
                 // Sauvegarde le Wordpress
                 if (!$wordpress->getId()) {
                     $wordpress->setValueId($datas['value_id']);
                 }
                 $wordpress->setUrl($datas['url'])->save();
                 $html = $this->getLayout()->addPartial('categories_html', 'admin_view_default', 'wordpress/application/edit/categories.phtml')->setCategory($root_category)->setCheckAllCategories(true)->toHtml();
                 $html = array('success' => 1, 'categories_html' => $html);
             } else {
                 throw new Exception($this->_("We are sorry but our Wordpress plugin hasn\\'t been detected on your website. Please be sure it is correctly installed and activated."));
             }
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }
Esempio n. 3
0
 public function editpostAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         $html = '';
         try {
             // Test s'il y a un value_id
             if (empty($datas['value_id'])) {
                 throw new Exception($this->_("An error occurred while saving your videos gallery. Please try again later."));
             }
             // Récupère l'option_value en cours
             $option_value = new Application_Model_Option_Value();
             $option_value->find($datas['value_id']);
             $isNew = true;
             $video = new Media_Model_Gallery_Video();
             if (!empty($datas['id'])) {
                 $video->find($datas['id']);
                 $isNew = false;
             } else {
                 $datas['value_id'] = $option_value->getId();
                 //                    $datas['type_id'] = 'youtube';
             }
             if ($video->getId() and $video->getValueId() != $option_value->getId()) {
                 throw new Exception($this->_("An error occurred while saving your videos gallery. Please try again later."));
             }
             $video->setData($datas)->save();
             $html = array('success' => 1, 'is_new' => (int) $isNew, 'id' => (int) $video->getId(), 'success_message' => $this->_('Videos gallery has been saved successfully'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0);
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }
 public function editpostAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         try {
             $html = '';
             // Test s'il y a une erreur dans la saisie
             if (empty($datas['name']) or empty($datas['number_of_points']) or empty($datas['advantage']) or empty($datas['conditions'])) {
                 throw new Exception($this->_('An error occurred while saving your loyalty card. Please fill all fields in.'));
             }
             // Test s'il y a un value_id
             if (empty($datas['value_id'])) {
                 throw new Exception($this->_('An error occurred while saving your loyalty card.'));
             }
             // Récupère l'option_value en cours
             $option_value = new Application_Model_Option_Value();
             $option_value->find($datas['value_id']);
             $application = $this->getApplication();
             $card = new LoyaltyCard_Model_LoyaltyCard();
             $card->setData($datas)->setValueId($option_value->getId())->save();
             $html = array('success' => '1', 'success_message' => $this->_('Your loyalty card has been saved successfully'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0);
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }
Esempio n. 5
0
 public function editpostAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         try {
             $option_value = new Application_Model_Option_Value();
             $option_value->find($datas['value_id']);
             $datas = $datas['menus'];
             foreach ($datas as $product_id => $data) {
                 $product = new Catalog_Model_Product();
                 if ($id = $this->getRequest()->getParam('id')) {
                     $product->find($id);
                     if ($product->getValueId() != $option_value->getId()) {
                         throw new Exception($this->_('An error occurred while saving. Please try again later.'));
                     }
                 }
                 if (!$product->getId()) {
                     $product->setValueId($option_value->getId());
                 }
                 $pos_datas = array();
                 if (!empty($data['pos'])) {
                     foreach ($data['pos'] as $key => $pos_data) {
                         $pos_datas[$key] = $pos_data;
                     }
                 }
                 if (!empty($data['picture'])) {
                     if (substr($data['picture'], 0, 1) == '/') {
                         unset($data['picture']);
                     } else {
                         $illus_relative_path = '/feature/' . $option_value->getValueId() . '/';
                         $folder = Application_Model_Application::getBaseImagePath() . $illus_relative_path;
                         $file = Core_Model_Directory::getTmpDirectory(true) . '/' . $data['picture'];
                         if (!is_dir($folder)) {
                             mkdir($folder, 0777, true);
                         }
                         if (!copy($file, $folder . $data['picture'])) {
                             throw new exception($this->_('An error occurred while saving your picture. Please try againg later.'));
                         } else {
                             $data['picture'] = $illus_relative_path . $data['picture'];
                         }
                     }
                 }
                 $product->addData($data)->setType('menu');
                 $product->setPosDatas($pos_datas);
                 $product->save();
             }
             $html = array();
             if (!$product->getData('is_deleted')) {
                 $html['menu_id'] = $product->getId();
             }
             $html['success'] = 1;
             $html['success_message'] = $this->_('Set meal successfully saved.');
             $html['message_timeout'] = 2;
             $html['message_button'] = 0;
             $html['message_loader'] = 0;
         } catch (Exception $e) {
             $html = array('message' => $this->_('An error occurred while saving the set meal. Please try again later.'));
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }
 public function lastmessagesAction()
 {
     $data = array();
     if ($device_uid = $this->getRequest()->getParam('device_uid')) {
         $message = new Push_Model_Message();
         $message->findLastPushMessage($device_uid);
         if ($message->getId()) {
             //We read this push
             $message->markAsRead($device_uid, $message->getMessageId());
             if (is_numeric($message->getActionValue())) {
                 $option_value = new Application_Model_Option_Value();
                 $option_value->find($message->getActionValue());
                 $action_url = $option_value->getPath(null, array('value_id' => $option_value->getId()), false);
             } else {
                 $action_url = $message->getActionValue();
             }
             $data["push_message"] = array("title" => $message->getTitle(), "text" => $message->getText(), "cover" => $message->getCoverUrl(), "action_value" => $action_url, "open_webview" => !is_numeric($message->getActionValue()));
         }
         $message = new Push_Model_Message();
         $message->findLastInAppMessage($this->getApplication()->getId(), $device_uid);
         if ($message->getId()) {
             $data["inapp_message"] = array("title" => $message->getTitle(), "text" => $message->getText(), "cover" => $message->getCoverUrl());
         }
     }
     $this->_sendHtml($data);
 }
Esempio n. 7
0
 public function _saveFeed($datas)
 {
     $html = '';
     try {
         // Test s'il y a une erreur dans la saisie
         if (empty($datas['title'])) {
             throw new Exception($this->_('Please enter a title'));
         }
         if (empty($datas['link']) or !Zend_Uri::check($datas['link'])) {
             throw new Exception($this->_('Please enter a valid url'));
         }
         // Test s'il y a un value_id
         if (empty($datas['value_id'])) {
             throw new Exception($this->_('An error occurred while saving your RSS feed'));
         }
         if (!isset($datas['picture'])) {
             $datas['picture'] = 0;
         }
         // Récupère l'option_value en cours
         $option_value = new Application_Model_Option_Value();
         $option_value->find($datas['value_id']);
         $isNew = true;
         $html = '';
         $feed = new Rss_Model_Feed();
         $feeds = new Rss_Model_Feed();
         $feeds = $feeds->findAll(array(), 'position DESC');
         if ($feeds->count() > 0) {
             $last_position = $feeds->seek($feeds->count() - 1)->current()->getPosition();
         } else {
             $last_position = 0;
         }
         // Si un id est passé en paramètre
         if (!empty($datas['feed_id'])) {
             // Charge le flux
             $feed->find($datas['feed_id']);
             // Si le flux existe mais qu'il n'appartient pas à cette option_value
             if ($feed->getId() and $feed->getValueId() != $option_value->getId()) {
                 // Envoi l'erreur
                 throw new Exception($this->_('An error occurred while saving your RSS feed'));
             }
             $isNew = !$feed->getId();
             $last_position = $feed->getPosition();
         }
         if (!empty($last_position)) {
             $datas["position"] = $last_position + 1;
         } else {
             $datas["position"] = 0;
         }
         $feed->setData($datas)->save();
         $html = array('success' => 1, 'success_message' => $this->_('RSS feed successfully saved'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0);
         if ($isNew) {
             $html['row_html'] = $this->getLayout()->addPartial('row_' . $feed->getId(), 'admin_view_default', 'rss/application/feed/edit/row.phtml')->setCurrentFeed($feed)->setCurrentOptionValue($option_value)->toHtml();
         }
     } catch (Exception $e) {
         $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1);
     }
     return $html;
 }
 public function editpostAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         $html = '';
         try {
             // Test s'il y a un value_id
             if (empty($datas['value_id'])) {
                 throw new Exception($this->_('An error occurred while saving. Please try again later.'));
             }
             // Récupère l'option_value en cours
             $option_value = new Application_Model_Option_Value();
             $option_value->find($datas['value_id']);
             // Instancie une nouvelle promotion
             $promotion = new Promotion_Model_Promotion();
             // Test si l'option des réductions spéciales est activée et payée
             if ($id = $this->getRequest()->getParam('id')) {
                 $promotion->find($id);
                 if ($promotion->getValueId() and $promotion->getValueId() != $option_value->getId()) {
                     throw new Exception('An error occurred while saving. Please try again later.');
                 }
             }
             //Vérifs champs
             if (empty($datas['title']) || empty($datas['description']) || empty($datas['title'])) {
                 throw new Exception($this->_('An error occurred while saving your discount. Please fill in all fields'));
                 die;
             }
             if (!isset($datas['is_illimited']) && empty($datas['end_at'])) {
                 throw new Exception($this->_('An error occurred while saving your discount. Please fill in all fields'));
                 die;
             }
             if (!empty($datas['end_at'])) {
                 $date_actuelle = new Zend_Date();
                 $date_modif = new Zend_Date($datas['end_at'], 'y-MM-dd');
                 if ($date_modif < $date_actuelle) {
                     throw new Exception($this->_('Please select an end date greater than the current date.'));
                     die;
                 }
             }
             if (!empty($datas['is_illimited'])) {
                 $datas['end_at'] = null;
             }
             $datas['force_validation'] = !empty($datas['force_validation']);
             $datas['is_unique'] = !empty($datas['is_unique']);
             $datas['owner'] = 1;
             $promotion->setData($datas);
             if (isset($datas['available_for']) and $datas['available_for'] == 'all') {
                 $promotion->resetConditions();
             }
             $promotion->save();
             $html = array('promotion_id' => $promotion->getId(), 'success_message' => $this->_('Discount successfully saved'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0);
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage(), 'url' => '/promotion/admin/list');
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }
 public function editpostAction()
 {
     if ($data = $this->getRequest()->getPost()) {
         try {
             $application = $this->getApplication();
             // Test s'il y a un value_id
             if (empty($data['value_id'])) {
                 throw new Exception($this->_('An error occurred while saving. Please try again later.'));
             }
             // Récupère l'option_value en cours
             $option_value = new Application_Model_Option_Value();
             $option_value->find($data['value_id']);
             $html = '';
             $contact = new Contact_Model_Contact();
             $contact->find($option_value->getId(), 'value_id');
             if (!empty($data['file'])) {
                 $file = pathinfo($data['file']);
                 $filename = $file['basename'];
                 $relative_path = $option_value->getImagePathTo();
                 $folder = Application_Model_Application::getBaseImagePath() . $relative_path;
                 $img_dst = $folder . '/' . $filename;
                 $img_src = Core_Model_Directory::getTmpDirectory(true) . '/' . $filename;
                 if (!is_dir($folder)) {
                     mkdir($folder, 0777, true);
                 }
                 if (!@copy($img_src, $img_dst)) {
                     throw new exception($this->_('An error occurred while saving your picture. Please try again later.'));
                 } else {
                     $data['cover'] = $relative_path . '/' . $filename;
                 }
             } else {
                 if (!empty($data['remove_cover'])) {
                     $data['cover'] = null;
                 }
             }
             $contact->setData($data);
             if ($contact->getStreet() and $contact->getPostcode() and $contact->getCity()) {
                 $latlon = Siberian_Google_Geocoding::getLatLng(array("street" => $contact->getStreet(), "postcode" => $contact->getPostcode(), "city" => $contact->getCity()));
                 if (!empty($latlon[0]) && !empty($latlon[1])) {
                     $contact->setLatitude($latlon[0])->setLongitude($latlon[1]);
                 }
             } else {
                 $contact->setLatitude(null)->setLongitude(null);
             }
             $contact->save();
             $html = array('success' => '1', 'success_message' => $this->_('Info successfully saved'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0);
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }
Esempio n. 10
0
 public function delete()
 {
     $category_option = new Application_Model_Option_Value();
     $option_values = $category_option->findAll(array('folder_category_id' => $this->getId()));
     if ($option_values->count()) {
         foreach ($option_values as $option_value) {
             $option_value->setFolderId(null)->setFolderCategoryId(null)->setFolderCategoryPosition(null)->save();
         }
     }
     foreach ($this->getChildren() as $child) {
         $child->delete();
     }
     return parent::delete();
 }
Esempio n. 11
0
 public function indexAction()
 {
     $layout_id = null;
     $base = true;
     if (!$this->getRequest()->isApplication()) {
         if ($this->getRequest()->isInstalling()) {
             $layout_id = 'installer_installation_index';
         } else {
             if (!$this->getSession()->isLoggedIn()) {
                 $layout_id = 'admin_account_login';
             } else {
                 $layout_id = 'application_customization_design_style_edit';
             }
         }
         $module = substr($layout_id, 0, stripos($layout_id, '_'));
         Core_Model_Translator::addModule($module);
     } else {
         if ($this->getApplication()->getLayoutVisibility() != Application_Model_Layout_Homepage::VISIBILITY_HOMEPAGE and !$this->hasParam("value_id")) {
             $page = $this->getApplication()->getFirstActivePage();
             if (!$page->getId()) {
                 $page = Application_Model_Option_Value::getDummy();
             }
             $this->_redirect($page->getMobileUri(), array('value_id' => $page->getId()));
             return $this;
         } else {
             Core_Model_Translator::addModule("padlock");
         }
     }
     //        } else if($this->getRequest()->isXmlHttpRequest()) {
     //            $base = false;
     //        }
     $this->loadPartials($layout_id);
 }
 public function editpostAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         try {
             $application = $this->getApplication();
             $html = '';
             $isNew = true;
             // Test s'il y a une erreur dans la saisie
             if (empty($datas['store_name'])) {
                 throw new Exception($this->_('Please, choose a store'));
             }
             if (empty($datas['email'])) {
                 throw new Exception($this->_('Please enter a valid email address'));
             }
             // Test s'il y a un value_id
             if (empty($datas['value_id'])) {
                 throw new Exception($this->_('An error occurred during process. Please try again later.'));
             }
             // Récupère l'option_value en cours
             $option_value = new Application_Model_Option_Value();
             $option_value->find($datas['value_id']);
             $booking = new Booking_Model_Booking();
             $store = new Booking_Model_Store();
             $booking->find($datas['value_id'], 'value_id');
             // Si un id est passé en paramètre
             if (!empty($datas['store_id'])) {
                 $store->find($datas['store_id']);
                 if ($store->getId() and $booking->getValueId() != $option_value->getId()) {
                     // Envoi l'erreur
                     throw new Exception($this->_('An error occurred during process. Please try again later.'));
                 }
                 $isNew = !$store->getId();
             }
             $booking->setData($datas)->save();
             unset($datas['value_id']);
             $datas['booking_id'] = $booking->getId();
             $store->setData($datas)->save();
             $html = array('success' => '1', 'success_message' => $this->_('Infos successfully saved'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0);
             if ($isNew) {
                 $html['row_html'] = $this->getLayout()->addPartial('row_' . $store->getId(), 'admin_view_default', 'booking/application/edit/row.phtml')->setCurrentStore($store)->setCurrentOptionValue($option_value)->toHtml();
             }
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }
Esempio n. 13
0
 public function editpostAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         try {
             if (empty($datas['value_id'])) {
                 throw new Exception($this->_('An error occurred while saving the category. Please try again later.'));
             }
             $option_value = new Application_Model_Option_Value();
             $option_value->find($datas['value_id']);
             $html = array();
             $category = new Catalog_Model_Category();
             if (!empty($datas['category_id'])) {
                 $category->find($datas['category_id']);
             }
             $isNew = (bool) (!$category->getId());
             if ($category->getId() and $category->getValueId() != $option_value->getId()) {
                 throw new Exception($this->_('An error occurred while saving the category. Please try again later.'));
             }
             if (!isset($datas['is_active'])) {
                 $datas['is_active'] = 1;
             }
             $datas['value_id'] = $option_value->getId();
             if (!empty($datas['is_deleted']) and $category->getParentId()) {
                 foreach ($category->getProducts() as $product) {
                     $product->setCategoryId($category->getParentId())->save();
                 }
             }
             //                $category->setPosIds(!empty($datas['outlets']) ? $datas['outlets'] : array());
             $category->addData($datas);
             $category->save();
             $html = array('success' => 1, 'is_new' => (int) $isNew, 'parent_id' => $category->getParentId(), 'category_id' => $category->getId(), 'is_deleted' => $category->getIsDeleted() ? 1 : 0);
             if ($isNew) {
                 if ($category->getParentId()) {
                     $html['li_html'] = $this->getLayout()->addPartial('row', 'admin_view_default', 'catalog/application/edit/category/subcategory.phtml')->setCategory($category->getParent())->setSubcategory($category)->setOptionValue($option_value)->toHtml();
                 } else {
                     $html['category_html'] = $this->getLayout()->addPartial('row', 'admin_view_default', 'catalog/application/edit/category.phtml')->setCategory($category)->setOptionValue($option_value)->toHtml();
                 }
             }
         } catch (Exception $e) {
             $html['message'] = $e->getMessage();
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
     return $this;
 }
Esempio n. 14
0
 public function findallAction()
 {
     $data = array("collection" => array());
     $option = $this->getCurrentOptionValue();
     $color = $this->getApplication()->getBlock('background')->getColor();
     $offset = $this->getRequest()->getParam('offset', 0);
     if ($device_uid = $this->getRequest()->getParam('device_uid')) {
         $message = new Push_Model_Message();
         $message->setMessageTypeByOptionValue($this->getCurrentOptionValue()->getOptionId());
         $messages = $message->findByDeviceId($device_uid, $offset);
         $icon_new = $option->getImage()->getCanBeColorized() ? $this->_getColorizedImage($option->getIconId(), $color) : $option->getIconUrl();
         $icon_pencil = $this->_getColorizedImage($this->_getImage("pictos/pencil.png"), $color);
         foreach ($messages as $message) {
             $meta = array("area1" => array("picto" => $icon_pencil, "text" => $message->getFormattedCreatedAt(Zend_Date::DATETIME_MEDIUM)));
             if (!$message->getIsRead()) {
                 $meta["area3"] = array("picto" => $icon_new, "text" => $this->_("New"));
             }
             $picture = $message->getCover() ? Application_Model_Application::getImagePath() . $message->getCover() : null;
             $action_value = null;
             if ($message->getActionValue()) {
                 if (is_numeric($message->getActionValue())) {
                     $option_value = new Application_Model_Option_Value();
                     $option_value->find($message->getActionValue());
                     $action_value = $option_value->getPath(null, array('value_id' => $option_value->getId()), false);
                 } else {
                     $action_value = $message->getActionValue();
                 }
             }
             if ($this->getApplication()->getIcon(74)) {
                 $icon = $this->getApplication()->getIcon(74);
             } else {
                 $icon = null;
             }
             $data["collection"][] = array("id" => $message->getId(), "author" => $message->getTitle(), "message" => $message->getText(), "topic" => $message->getLabel(), "meta" => $meta, "picture" => $picture, "icon" => $icon, "action_value" => $action_value);
         }
         $message->markAsRead($device_uid);
     }
     $data["page_title"] = $this->getCurrentOptionValue()->getTabbarName();
     $data["displayed_per_page"] = Push_Model_Message::DISPLAYED_PER_PAGE;
     $this->_sendHtml($data);
 }
 public function editpostAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         try {
             $application = $this->getApplication();
             // Test s'il y a un value_id
             if (empty($datas['value_id'])) {
                 throw new Exception($this->_('An error occurred while saving your contact informations.'));
             }
             // Récupère l'option_value en cours
             $option_value = new Application_Model_Option_Value();
             $option_value->find($datas['value_id']);
             $html = '';
             $contact = new Contact_Model_Contact();
             $contact->find($option_value->getId(), 'value_id');
             if (!empty($datas['file'])) {
                 $relative_path = '/contact/cover/';
                 $folder = Application_Model_Application::getBaseImagePath() . $relative_path;
                 $file = Core_Model_Directory::getTmpDirectory(true) . '/' . $datas['file'];
                 if (!is_dir($folder)) {
                     mkdir($folder, 0777, true);
                 }
                 if (!copy($file, $folder . $datas['file'])) {
                     throw new exception($this->_('An error occurred while saving your picture. Please try againg later.'));
                 } else {
                     $datas['cover'] = $relative_path . $datas['file'];
                 }
             } else {
                 if (!empty($datas['remove_cover'])) {
                     $datas['cover'] = null;
                 }
             }
             $contact->setData($datas)->save();
             $html = array('success' => '1', 'success_message' => $this->_('Informations successfully saved'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0);
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }
 public function editpostAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         try {
             $application = $this->getApplication();
             // Test s'il y a un value_id
             if (empty($datas['value_id'])) {
                 throw new Exception($this->_('An error occurred while saving. Please try again later.'));
             }
             // Récupère l'option_value en cours
             $option_value = new Application_Model_Option_Value();
             $option_value->find($datas['value_id']);
             if (empty($datas['link']) or !Zend_Uri::check($datas['link'])) {
                 throw new Exception($this->_('Please enter a valid url'));
             }
             // Prépare le weblink
             $html = array();
             $weblink = new Weblink_Model_Type_Mono();
             $weblink->find($option_value->getId(), 'value_id');
             if (!$weblink->getId()) {
                 $weblink->setValueId($datas['value_id']);
             }
             // Affecte l'url au lien
             $weblink->getLink()->setUrl(!empty($datas['link']) ? $datas['link'] : null);
             // Sauvegarde
             $weblink->save();
             $html = array('success' => '1', 'success_message' => $this->_('Link has been successfully saved'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0);
             if (!$weblink->getIsDeleted()) {
                 $html['link'] = $weblink->getLink()->getUrl();
             }
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }
 public function formAction()
 {
     $option_value = new Application_Model_Option_Value();
     if ($this->getRequest()->getParam("option_value_id")) {
         $value_id = $this->getRequest()->getParam("option_value_id");
         $name = $this->getRequest()->getParam("name");
         $event_type = strtolower($this->getRequest()->getParam("event_type"));
         $option_value->find($value_id);
     }
     try {
         $event = new Event_Model_Event();
         if ($id = $this->getRequest()->getParam("id")) {
             $event->find($id);
         }
         switch ($event_type) {
             case 'ical':
                 $template = 'event/application/edit/ical/form.phtml';
                 $block = 'admin_view_default';
                 break;
             case 'fb':
                 $template = 'event/application/edit/facebook/form.phtml';
                 $block = 'admin_view_default';
                 break;
             case 'cstm':
                 $template = 'event/application/edit/custom/form.phtml';
                 $block = 'event_view_application_edit_custom_form';
                 break;
         }
         //            Zend_Debug::dump($this->getRequest()->getParams());die;
         $this->getLayout()->setBaseRender('form', $template, $block)->setCurrentEvent($event)->setOptionValue($option_value)->setName($name)->setEventType($event_type);
         $html = array('form_html' => $this->getLayout()->render(), 'event_type' => $event_type, 'success' => 1);
     } catch (Exception $e) {
         $html = array('message' => $e->getMessage());
     }
     $this->getLayout()->setHtml(Zend_Json::encode($html));
 }
Esempio n. 18
0
 private function __tryToUnlockEverything()
 {
     $current_option = new Application_Model_Option_Value();
     $current_option->find($this->getValueId());
     if ($current_option->getId() and $current_option->getApplication()) {
         $application = $current_option->getApplication();
         $has_another_padlock = false;
         foreach ($application->getOptions() as $option) {
             if ($option->getCode() == $current_option->getCode() and $option->getId() != $current_option->getId() and $option->getData("is_active")) {
                 Zend_Debug::dump($current_option->getData());
                 Zend_Debug::dump($option->getData());
                 $has_another_padlock = true;
             }
         }
         if (!$has_another_padlock) {
             $this->setValueIds(array());
             $application->setRequireToBeLoggedIn(0)->save();
             $this->saveValueIds($application->getId());
         }
     }
 }
Esempio n. 19
0
 public function findAction()
 {
     if ($value_id = $this->getRequest()->getParam('value_id')) {
         $event_id = $this->getRequest()->getParam('event_id');
         if (is_null($event_id)) {
             return $this;
         }
         try {
             $option = $this->getCurrentOptionValue();
             $start_at = new Zend_Date();
             $end_at = new Zend_Date();
             $format = 'y-MM-dd HH:mm:ss';
             $events = $option->getObject()->getEvents(null, true);
             if (!empty($events[$event_id])) {
                 $event = $events[$event_id];
                 $data = array('event' => array());
                 $start_at->set($event->getStartAt(), $format);
                 $end_at->set($event->getEndAt(), $format);
                 $formatted_start_at = $start_at->toString($this->_("MM.dd.y"));
                 $formatted_end_at = $end_at->toString($this->_("MM.dd.y 'at' HH:mm a"));
                 $in_app_page_path = null;
                 if (is_numeric($event->getInAppValueId())) {
                     $option = new Application_Model_Option_Value();
                     $option->find($event->getInAppValueId());
                     if ($option->getId() and $option->isActive() and $option->getAppId() == $this->getApplication()->getId()) {
                         $in_app_page_path = $option->getPath("index");
                     }
                 }
                 $data['event'] = array("id" => $event_id, "title" => $event->getName(), "description" => $event->getDescription(), "address" => $event->getAddress(), "weekday_name" => $start_at->toString(Zend_Date::WEEKDAY_NAME), "start_at" => $formatted_start_at, "end_at" => $formatted_end_at, "ticket_shop_url" => $event->getTicketShopUrl(), "rsvp" => $event->getRsvp(), "websites" => $event->getWebsites(), "in_app_page_path" => $in_app_page_path, "social_sharing_active" => $option->getSocialSharingIsActive());
                 $data["cover"] = array("title" => $event->getName(), "subtitle" => $event->getSubtitle(), "title2" => "{$start_at->toString(Zend_Date::WEEKDAY_NAME)} {$formatted_start_at}", "subtitle2" => array("time" => $event->getStartTimeAt(), "location" => array("label" => $event->getLocationLabel(), "url" => $event->getLocationUrl())), "title3" => "{$end_at->toString(Zend_Date::WEEKDAY_NAME)} {$formatted_end_at}", "picture" => $event->getPicture());
                 $data['page_title'] = $event->getName();
             } else {
                 throw new Exception("Unable to find this event.");
             }
         } catch (Exception $e) {
             $data = array('error' => 1, 'message' => $e->getMessage());
         }
         $this->_sendHtml($data);
     }
 }
 public function editpostAction()
 {
     if ($data = $this->getRequest()->getPost()) {
         try {
             if (empty($data['value_id'])) {
                 throw new Exception($this->_('An error occurred while saving the product. Please try again later.'));
             }
             $option_value = new Application_Model_Option_Value();
             $option_value->find($data['value_id']);
             $html = array();
             $product = new Catalog_Model_Product();
             if (!empty($data['product_id'])) {
                 $product->find($data['product_id']);
             }
             $isNew = (bool) (!$product->getId());
             $isDeleted = !empty($data['is_deleted']);
             if ($product->getId() and $product->getValueId() != $option_value->getId()) {
                 throw new Exception($this->_('An error occurred while saving the product. Please try again later.'));
             }
             if (!$isDeleted) {
                 if (!isset($data['is_active'])) {
                     $data['is_active'] = 1;
                 }
                 $data['value_id'] = $option_value->getValueId();
                 $parent_id = $data['category_id'];
                 if (!empty($data['subcategory_id'])) {
                     $data['category_id'] = $data['subcategory_id'];
                 }
                 if (!empty($data['picture'])) {
                     if (!file_exists(Core_Model_Directory::getTmpDirectory(true) . "/" . $data['picture'])) {
                         unset($data['picture']);
                     } else {
                         $illus_relative_path = $option_value->getImagePathTo();
                         $folder = Application_Model_Application::getBaseImagePath() . $illus_relative_path;
                         $file = pathinfo(Core_Model_Directory::getBasePathTo($data['picture']));
                         $filename = $file['basename'];
                         $img_src = Core_Model_Directory::getTmpDirectory(true) . "/" . $data['picture'];
                         $img_dst = $folder . '/' . $filename;
                         if (!is_dir($folder)) {
                             mkdir($folder, 0777, true);
                         }
                         if (!@copy($img_src, $img_dst)) {
                             throw new exception($this->_('An error occurred while saving your picture. Please try againg later.'));
                         } else {
                             $data['picture'] = $illus_relative_path . '/' . $filename;
                         }
                     }
                 }
             }
             if (!$product->getId() and empty($data['is_multiple']) or $product->getId() and $product->getData('type') != 'format' and isset($data['option'])) {
                 unset($data['option']);
             }
             $product->addData($data);
             $product->save();
             $html = array('success' => 1);
             if (!$isDeleted) {
                 $product_id = $product->getId();
                 $product = new Catalog_Model_Product();
                 $product->find($product_id);
                 $html = array('success' => 1, 'product_id' => $product->getId(), 'parent_id' => $parent_id, 'category_id' => $data['category_id']);
                 $html['product_html'] = $this->getLayout()->addPartial('row', 'admin_view_default', 'catalog/application/edit/category/product.phtml')->setProduct($product)->setOptionValue($option_value)->toHtml();
             }
         } catch (Exception $e) {
             $html['message'] = $e->getMessage();
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }
Esempio n. 21
0
 public function getPage($code)
 {
     $dummy = new Application_Model_Option();
     $dummy->find($code, 'code');
     $page_sought = new Application_Model_Option_Value();
     return $page_sought->find(array('option_id' => $dummy->getId()));
 }
 public function saveradiusAction()
 {
     $html = '';
     if ($data = $this->getRequest()->getPost()) {
         try {
             if (empty($data['radius'])) {
                 throw new Exception($this->_('Radius must be provided.'));
             }
             if (!is_numeric($data['radius'])) {
                 throw new Exception($this->_('Radius must be a valid numeric value.'));
             }
             // Test s'il y a un value_id
             if (empty($data['value_id'])) {
                 throw new Exception($this->_('An error occurred while saving. Please try again later.'));
             }
             // Récupère l'option_value en cours
             $option_value = new Application_Model_Option_Value();
             $option_value->find($data['value_id']);
             // Test s'il y a embrouille entre la value_id en cours de modification et l'application en session
             if (!$option_value->getId() or $option_value->getAppId() != $this->getApplication()->getId()) {
                 throw new Exception($this->_('An error occurred while saving. Please try again later.'));
             }
             $radius = new Comment_Model_Radius();
             $radius->find($data['value_id'], 'value_id');
             if (!$radius->getId()) {
                 $radius->setValueId($data['value_id']);
             }
             $radius->addData($data)->save();
             $html = array('success' => '1', 'success_message' => $this->_('Information successfully saved'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0);
         } catch (Exception $e) {
             $html = array('error' => 1, 'message' => $e->getMessage());
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }
 public function editpostAction()
 {
     if ($data = $this->getRequest()->getPost()) {
         $html = '';
         try {
             // Test s'il y a un value_id
             if (empty($data['value_id'])) {
                 throw new Exception($this->_('An error occurred while saving. Please try again later.'));
             }
             // Récupère l'option_value en cours
             $option_value = new Application_Model_Option_Value();
             $option_value->find($data['value_id']);
             // Instancie une nouvelle promotion
             $promotion = new Promotion_Model_Promotion();
             // Test si l'option des réductions spéciales est activée et payée
             if ($id = $this->getRequest()->getParam('id')) {
                 $promotion->find($id);
                 if ($promotion->getValueId() and $promotion->getValueId() != $option_value->getId()) {
                     throw new Exception('An error occurred while saving. Please try again later.');
                 }
             }
             //Vérifs champs
             if (empty($data['title']) || empty($data['description']) || empty($data['title'])) {
                 throw new Exception($this->_('An error occurred while saving your discount. Please fill in all fields'));
             }
             if (!isset($data['is_illimited']) && empty($data['end_at'])) {
                 throw new Exception($this->_('An error occurred while saving your discount. Please fill in all fields'));
             }
             if (!empty($data['end_at'])) {
                 $date_actuelle = new Zend_Date();
                 $date_modif = new Zend_Date($data['end_at'], 'y-MM-dd');
                 if ($date_modif < $date_actuelle) {
                     throw new Exception($this->_('Please select an end date greater than the current date.'));
                     die;
                 }
             }
             if (!empty($data['is_illimited'])) {
                 $data['end_at'] = null;
             }
             $data['force_validation'] = !empty($data['force_validation']);
             $data['is_unique'] = !empty($data['is_unique']);
             $data['owner'] = 1;
             if (isset($data['available_for']) and $data['available_for'] == 'all') {
                 $promotion->resetConditions();
             }
             if (!empty($data['picture'])) {
                 $filename = pathinfo($data['picture'], PATHINFO_BASENAME);
                 $relative_path = $option_value->getImagePathTo();
                 $folder = Application_Model_Application::getBaseImagePath() . $relative_path;
                 $img_dst = $folder . '/' . $filename;
                 $img_src = Core_Model_Directory::getTmpDirectory(true) . '/' . $filename;
                 if (!is_dir($folder)) {
                     mkdir($folder, 0777, true);
                 }
                 if (!@copy($img_src, $img_dst)) {
                     throw new exception($this->_('An error occurred while saving your picture. Please try again later.'));
                 } else {
                     $data['picture'] = $relative_path . '/' . $filename;
                 }
             } else {
                 if (!empty($data['remove_cover'])) {
                     $data['picture'] = null;
                 }
             }
             $promotion->setData($data);
             $promotion->save();
             if (!empty($data['unlock_code'])) {
                 $dir_image = Core_Model_Directory::getBasePathTo("/images/application/" . $this->getApplication()->getId());
                 if (!is_dir($dir_image)) {
                     mkdir($dir_image, 0775, true);
                 }
                 if (!is_dir($dir_image . "/application")) {
                     mkdir($dir_image . "/application", 0775, true);
                 }
                 if (!is_dir($dir_image . "/application/qrpromotion")) {
                     mkdir($dir_image . "/application/qrpromotion", 0775, true);
                 }
                 $dir_image .= "/application/qrpromotion/";
                 $image_name = $promotion->getId() . "-qrpromotion_qrcode.png";
                 copy('http://api.qrserver.com/v1/create-qr-code/?color=000000&bgcolor=FFFFFF&data=sendback%3A' . $data["unlock_code"] . '&qzone=1&margin=0&size=200x200&ecc=L', $dir_image . $image_name);
             }
             $html = array('promotion_id' => $promotion->getId(), 'success_message' => $this->_('Discount successfully saved'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0);
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage(), 'url' => '/promotion/admin/list');
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }
 public function deletecategoryAction()
 {
     if ($datas = $this->getRequest()->getParams()) {
         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']);
             $parent_id = $category->getParentId();
             $category->delete();
             $value_ids = array();
             $option_value = new Application_Model_Option_Value();
             $option_values = $option_value->findAll(array('a.app_id' => $this->getApplication()->getId()), 'position ASC');
             foreach ($option_values as $option_value) {
                 if ($option_value->getFolderId() or $option_value->getCode() == "folder") {
                     continue;
                 }
                 $value_ids[] = $option_value->getId();
             }
             $html = array('success' => 1, 'parent_id' => $parent_id, 'value_ids' => $value_ids);
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }
Esempio n. 25
0
 protected function _initDesign()
 {
     $detect = new Mobile_Detect();
     $design_codes = array("desktop" => "siberian", "mobile" => "angular");
     Zend_Registry::set("design_codes", $design_codes);
     if (!$this->getRequest()->isInstalling()) {
         if ($this->getRequest()->isApplication()) {
             $apptype = 'mobile';
         } else {
             $apptype = 'desktop';
         }
         if ($detect->isMobile() || $apptype == 'mobile') {
             $device_type = 'mobile';
         } else {
             $device_type = 'desktop';
         }
         if ($this->getRequest()->isApplication()) {
             $code = $design_codes["mobile"];
         } else {
             if ($this->_isInstanceOfBackoffice()) {
                 $code = 'backoffice';
             } else {
                 $code = $design_codes["desktop"];
             }
         }
     } else {
         $apptype = 'desktop';
         $device_type = 'desktop';
         $code = "installer";
     }
     $base_paths = array(APPLICATION_PATH . "/design/email/template/");
     if (!defined("APPLICATION_TYPE")) {
         define("APPLICATION_TYPE", $apptype);
     }
     if (!defined("DEVICE_TYPE")) {
         define("DEVICE_TYPE", $device_type);
     }
     if (!defined("DEVICE_IS_IPHONE")) {
         define("DEVICE_IS_IPHONE", $detect->isIphone() || $detect->isIpad());
     }
     if (!defined("IS_APPLICATION")) {
         define("IS_APPLICATION", $detect->isNative() && $this->getRequest()->isApplication());
     }
     if (!defined("DESIGN_CODE")) {
         define("DESIGN_CODE", $code);
     }
     Core_Model_Directory::setDesignPath("/app/design/{$apptype}/{$code}");
     $resources = array('resources' => array('layout' => array('layoutPath' => APPLICATION_PATH . "/design/{$apptype}/{$code}/template/page")));
     $base_paths[] = APPLICATION_PATH . "/design/{$apptype}/{$code}/template/";
     $bootstrap = Zend_Controller_Front::getInstance()->getParam("bootstrap");
     $bootstrap->setOptions($resources);
     $bootstrap->bootstrap('View');
     $view = $bootstrap->getResource('View');
     $view->doctype('HTML5');
     foreach ($base_paths as $base_path) {
         $view->addBasePath($base_path);
     }
     Core_View_Default::setDevice($detect);
     Application_Controller_Mobile_Default::setDevice($detect);
     if (!$this->getRequest()->isInstalling()) {
         $blocks = array();
         if ($this->getRequest()->isApplication()) {
             $blocks = $this->getRequest()->getApplication()->getBlocks();
         } else {
             if (!$this->_isInstanceOfBackoffice()) {
                 $blocks = $this->getRequest()->getWhiteLabelEditor()->getBlocks();
                 if ($block = $this->getRequest()->getWhiteLabelEditor()->getBlock("area")) {
                     $icon_color = $block->getColor();
                     Application_Model_Option_Value::setEditorIconColor($icon_color);
                 }
             }
         }
         if (!empty($blocks)) {
             Core_View_Default::setBlocks($blocks);
         }
     }
 }
Esempio n. 26
0
 public function deletebackgroundimageAction()
 {
     if ($datas = $this->getRequest()->getParams()) {
         try {
             if (empty($datas['value_id'])) {
                 throw new Exception($this->_('An error occurred while deleting your picture'));
             }
             $option_value = new Application_Model_Option_Value();
             $option_value->find($datas['value_id']);
             if (!$option_value->getId()) {
                 throw new Exception($this->_('An error occurred while deleting your picture'));
             }
             $option_value->setBackgroundImage(null)->save();
             $datas = array('success' => 1, 'background_image_url' => $option_value->reload()->getBackgroundImageUrl());
         } catch (Exception $e) {
             $datas = array('error' => 1, 'message' => $e->getMessage());
         }
         $this->getLayout()->setHtml(Zend_Json::encode($datas));
     }
 }
Esempio n. 27
0
 public function editpostAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         try {
             $isNew = false;
             $application = $this->getApplication();
             // Test s'il y a un value_id
             if (empty($datas['value_id'])) {
                 throw new Exception($this->_('An error occurred while saving. Please try again later.'));
             }
             // Récupère l'option_value en cours
             $option_value = new Application_Model_Option_Value();
             $option_value->find($datas['value_id']);
             $html = array('success' => '1', 'success_message' => $this->_('Link has been successfully saved'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0);
             // Prépare la weblink
             $weblink = $option_value->getObject();
             if (!$weblink->getId()) {
                 $weblink->setValueId($datas['value_id']);
             }
             // S'il y a une cover image
             if (!empty($datas['file'])) {
                 if (!empty($datas['file'])) {
                     $relative_path = '/weblink/cover/';
                     $folder = Application_Model_Application::getBaseImagePath() . $relative_path;
                     $path = Application_Model_Application::getBaseImagePath() . $relative_path;
                     $file = Core_Model_Directory::getTmpDirectory(true) . '/' . $datas['file'];
                     if (!is_dir($path)) {
                         mkdir($path, 0777, true);
                     }
                     if (!copy($file, $folder . $datas['file'])) {
                         throw new exception($this->_('An error occurred while saving your picture. Please try againg later.'));
                     } else {
                         $weblink->setCover($relative_path . $datas['file']);
                     }
                     if (empty($datas['link'])) {
                         $html['success_message'] = $this->_("The image has been successfully saved");
                     }
                 }
             } else {
                 if (!empty($datas['remove_cover'])) {
                     $weblink->setCover(null);
                     if (empty($datas['link'])) {
                         $html['success_message'] = $this->_("The image has been successfully deleted");
                     }
                 }
             }
             // Sauvegarde le weblink
             $weblink->save();
             if (!empty($datas['link'])) {
                 $link_datas = $datas['link'];
                 if (empty($link_datas['url']) or !Zend_Uri::check($link_datas['url'])) {
                     throw new Exception($this->_('Please enter a valid url'));
                 }
                 // Prépare le link
                 $link = new Weblink_Model_Weblink_Link();
                 if (!empty($link_datas['link_id'])) {
                     $link->find($link_datas['link_id']);
                 }
                 $isNew = !$link->getId();
                 $link_datas['weblink_id'] = $weblink->getId();
                 // Test s'il y a un picto
                 if (!empty($link_datas['picto']) and file_exists(Core_Model_Directory::getTmpDirectory(true) . '/' . $link_datas['picto'])) {
                     $relative_path = '/pictos/';
                     $folder = Application_Model_Application::getBaseImagePath() . $relative_path;
                     $path = Application_Model_Application::getBaseImagePath() . $relative_path;
                     $file = Core_Model_Directory::getTmpDirectory(true) . '/' . $link_datas['picto'];
                     if (!is_dir($path)) {
                         mkdir($path, 0777, true);
                     }
                     if (!copy($file, $folder . $link_datas['picto'])) {
                         throw new exception($this->_("An error occurred while saving your picto. Please try againg later."));
                     } else {
                         $link_datas['picto'] = $relative_path . $link_datas['picto'];
                     }
                 }
                 // Sauvegarde le link
                 $link->addData($link_datas)->save();
                 if ($link->getIsDeleted()) {
                     $html['success_message'] = $this->_('Link has been successfully deleted');
                     $html['is_deleted'] = 1;
                 }
             }
             if ($isNew) {
                 $html['row_html'] = $this->getLayout()->addPartial('row_', 'admin_view_default', 'weblink/application/multi/edit/row.phtml')->setCurrentLink($link)->setCurrentOptionValue($option_value)->toHtml();
             }
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }
Esempio n. 28
0
 public function deleteAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         $html = '';
         try {
             // Test s'il y a un value_id
             if (empty($datas['value_id']) or empty($datas['id'])) {
                 throw new Exception($this->_("An error occurred while deleting you images gallery. Please try again later."));
             }
             // Récupère l'option_value en cours
             $option_value = new Application_Model_Option_Value();
             $option_value->find($datas['value_id']);
             $image = new Media_Model_Gallery_Image();
             $image->find($datas['id']);
             $image->delete();
             $html = array('success' => 1);
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }
Esempio n. 29
0
 public function copyCategoryTo($option, $category, $parent_id = null)
 {
     $children = $category->getChildren();
     $category_option = new Application_Model_Option_Value();
     $option_values = $category_option->findAll(array('app_id' => $option->getAppId(), 'folder_category_id' => $category->getId()), array('folder_category_position ASC'));
     $category->setId(null)->setParentId($parent_id)->save();
     foreach ($option_values as $option_value) {
         $option_value->setFolderCategoryId($category->getId())->save();
     }
     foreach ($children as $child) {
         $this->copyCategoryTo($option, $child, $category->getId());
     }
     return $this;
 }
 public function editpostAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         $html = '';
         try {
             $message = new Push_Model_Message();
             $message->setMessageTypeByOptionValue($this->getCurrentOptionValue()->getOptionId());
             $sendNow = false;
             $inputs = array('send_at', 'send_until');
             foreach ($inputs as $input) {
                 if (empty($datas[$input . '_a_specific_datetime'])) {
                     $datas[$input] = null;
                 } else {
                     if (empty($datas[$input])) {
                         throw new Exception($this->_('Please, enter a valid date'));
                     } else {
                         $date = new Zend_Date($datas[$input]);
                         $datas[$input] = $date->toString('y-MM-dd HH:mm:ss');
                     }
                 }
             }
             if (empty($datas['send_at'])) {
                 $sendNow = true;
                 $datas['send_at'] = Zend_Date::now()->toString('y-MM-dd HH:mm:ss');
             }
             if (!empty($datas['send_until']) and $datas['send_at'] > $datas['send_until']) {
                 throw new Exception($this->_("The duration limit must be higher than the sent date"));
             }
             // Récupère l'option_value en cours
             $option_value = new Application_Model_Option_Value();
             if (!empty($datas['file'])) {
                 $file = pathinfo($datas['file']);
                 $filename = $file['basename'];
                 $relative_path = $option_value->getImagePathTo();
                 $folder = Application_Model_Application::getBaseImagePath() . $relative_path;
                 $img_dst = $folder . $filename;
                 $img_src = Core_Model_Directory::getTmpDirectory(true) . '/' . $filename;
                 if (!is_dir($folder)) {
                     mkdir($folder, 0777, true);
                 }
                 if (!@copy($img_src, $img_dst)) {
                     throw new exception($this->_('An error occurred while saving your picture. Please try again later.'));
                 } else {
                     $datas['cover'] = $relative_path . $filename;
                 }
             } else {
                 if (!empty($data['remove_cover'])) {
                     $data['cover'] = null;
                 }
             }
             if (empty($datas['action_value'])) {
                 $datas['action_value'] = null;
             } else {
                 if (!preg_match('/^[0-9]*$/', $datas['action_value'])) {
                     $url = "http://" . $datas['action_value'];
                     if (stripos($datas['action_value'], "http://") !== false || stripos($datas['action_value'], "https://") !== false) {
                         $url = $datas['action_value'];
                     }
                     $datas['action_value'] = file_get_contents("http://tinyurl.com/api-create.php?url=" . urlencode($url));
                 }
             }
             $datas['type_id'] = $message->getMessageType();
             $datas['app_id'] = $this->getApplication()->getId();
             $datas["send_to_all"] = $datas["topic_receiver"] ? 0 : 1;
             $message->setData($datas)->save();
             //PnTopics
             if ($datas["topic_receiver"]) {
                 $topic_data = explode(";", $datas["topic_receiver"]);
                 foreach ($topic_data as $id_topic) {
                     if ($id_topic != "") {
                         $category_message = new Topic_Model_Category_Message();
                         $category_message_data = array("category_id" => $id_topic, "message_id" => $message->getId());
                         $category_message->setData($category_message_data);
                         $category_message->save();
                     }
                 }
             }
             if ($message->getMessageType() == 1) {
                 if ($sendNow) {
                     $c = curl_init();
                     curl_setopt($c, CURLOPT_URL, $this->getUrl('push/message/send', array('message_id' => $message->getId())));
                     curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
                     // Follow the redirects (needed for mod_rewrite)
                     curl_setopt($c, CURLOPT_HEADER, false);
                     // Don't retrieve headers
                     curl_setopt($c, CURLOPT_NOBODY, true);
                     // Don't retrieve the body
                     curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
                     // Return from curl_exec rather than echoing
                     curl_setopt($c, CURLOPT_FRESH_CONNECT, true);
                     // Always ensure the connection is fresh
                     // Timeout super fast once connected, so it goes into async.
                     curl_setopt($c, CURLOPT_TIMEOUT, 10);
                     curl_exec($c);
                     curl_close($c);
                 }
             } else {
                 $message->updateStatus('delivered');
             }
             $html = array('success' => 1, 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0);
             if ($sendNow) {
                 $html['success_message'] = $this->_('Your message has been saved successfully and will be sent in a few minutes');
             } else {
                 $html['success_message'] = $this->_('Your message has been saved successfully and will be sent at the entered date');
             }
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }