예제 #1
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));
     }
 }
예제 #2
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 {
             $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));
     }
 }
예제 #4
0
 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);
 }
 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));
     }
 }
예제 #6
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;
 }
예제 #7
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;
 }
 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));
     }
 }
예제 #9
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());
         }
     }
 }
 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));
     }
 }
예제 #11
0
 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));
     }
 }
예제 #12
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);
 }
예제 #13
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);
     }
 }
예제 #14
0
 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 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));
     }
 }
예제 #19
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));
     }
 }
예제 #20
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 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']);
             $isNew = true;
             $save = true;
             $image = new Media_Model_Gallery_Image();
             if (!empty($datas['id'])) {
                 $image->find($datas['id']);
                 $isNew = false;
                 $id = $datas['id'];
             } else {
                 $id = 'new';
                 $datas['value_id'] = $option_value->getId();
             }
             if ($image->getId() and $image->getValueId() != $option_value->getId()) {
                 throw new Exception("An error occurred while saving your images gallery. Please try again later.");
             }
             if (!empty($datas['param_instagram'])) {
                 $instagram = new Media_Model_Gallery_Image_Instagram();
                 $userId = $instagram->getUserId($datas['param_instagram']);
                 if (!$userId) {
                     throw new Exception($this->_("The entered name is not a valid Instagram user."));
                 }
                 $datas['type_id'] = 'instagram';
             } elseif (!empty($datas['param'])) {
                 $datas['type_id'] = 'picasa';
             } else {
                 $datas['type_id'] = 'custom';
             }
             $html = array('success' => 1, 'is_new' => (int) $isNew);
             if (empty($datas['type_id']) or $datas['type_id'] == 'picasa') {
                 $image->setTypeId('picasa');
                 $image->getTypeInstance()->setParam($datas['param']);
                 if (empty($datas['album_id'])) {
                     $albums = $image->getTypeInstance()->findAlbums();
                 }
                 if (!empty($albums)) {
                     $html['albums'] = $albums;
                     $save = false;
                 }
                 $datas['type'] = !empty($datas['album_id']) || !empty($albums) ? 'album' : 'search';
             }
             if ($save) {
                 $image->setData($datas)->save();
                 $html['id'] = (int) $image->getId();
                 $html['is_new'] = (int) $isNew;
                 $html['success_message'] = $this->_("Images gallery has been saved successfully");
                 $html['message_timeout'] = 2;
                 $html['message_button'] = 0;
                 $html['message_loader'] = 0;
                 if (isset($datas['images']['list_' . $id])) {
                     foreach ($datas['images']['list_' . $id] as $key => $info) {
                         $gallery = new Media_Model_Gallery_Image_Custom();
                         if (!empty($info['image_id'])) {
                             $gallery->find($info['image_id']);
                         }
                         if (!empty($info['delete'])) {
                             $gallery->delete();
                             continue;
                         }
                         if (!$gallery->getId()) {
                             $gallery->setGalleryId($image->getId());
                         }
                         if (!empty($info['path'])) {
                             $filename = $info['path'];
                             $img_src = Core_Model_Directory::getTmpDirectory(true) . '/' . $filename;
                             if (file_exists($img_src)) {
                                 $relative_path = $option_value->getImagePathTo();
                                 $folder = Application_Model_Application::getBaseImagePath() . $relative_path;
                                 $img_dst = $folder . '/' . $filename;
                                 if (!is_dir($folder)) {
                                     mkdir($folder, 0777, true);
                                 }
                                 if (!@rename($img_src, $img_dst)) {
                                     throw new Exception("An error occurred while saving your images gallery. Please try again later.");
                                 }
                                 $gallery->setUrl($relative_path . '/' . $filename);
                             }
                         }
                         $gallery->setTitle(!empty($info['title']) ? $info['title'] : null)->setDescription(!empty($info['description']) ? $info['description'] : null)->save();
                     }
                 }
             }
         } 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']);
             // 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.'));
             }
             // Prépare le weblink
             $html = array();
             $padlock = $option_value->getObject();
             if (!$padlock->getId()) {
                 $padlock->setValueId($datas['value_id']);
             }
             $value_ids = array();
             if (!empty($datas['app_is_locked'])) {
                 $application->setRequireToBeLoggedIn(1);
             } else {
                 $value_ids = !empty($datas['value_ids']) ? $datas['value_ids'] : array();
                 $application->setRequireToBeLoggedIn(0);
             }
             $unlock_by = null;
             if (!empty($datas['type_ids'])) {
                 sort($datas['type_ids']);
                 $unlock_by = join("|", $datas['type_ids']);
             }
             $unlock_code = null;
             if (isset($datas["qrcode_unlock_code"])) {
                 $unlock_code = $datas["qrcode_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/padlock")) {
                     mkdir($dir_image . "/application/padlock", 0775, true);
                 }
                 $dir_image .= "/application/padlock/";
                 $image_name = "padlock_qrcode.png";
                 copy('http://api.qrserver.com/v1/create-qr-code/?color=000000&bgcolor=FFFFFF&data=sendback%3A' . $datas["qrcode_unlock_code"] . '&qzone=1&margin=0&size=200x200&ecc=L', $dir_image . $image_name);
             }
             $this->getApplication()->setUnlockBy($unlock_by)->setUnlockCode($unlock_code)->save();
             $allow_everyone = (int) (!empty($datas['allow_all_customers_to_access_locked_features']));
             $application->setData('allow_all_customers_to_access_locked_features', $allow_everyone)->save();
             $padlock->setAppId($application->getId())->setValueIds($value_ids)->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->getResponse()->setBody(Zend_Json::encode($html))->sendResponse();
         die;
     }
 }
예제 #22
0
 public function deleteAction()
 {
     if ($data = $this->getRequest()->getPost()) {
         $html = array();
         try {
             // Test s'il y a un value_id
             if (empty($data['option_value_id']) or empty($data['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['option_value_id']);
             if (!$option_value->getId()) {
                 throw new Exception($this->_('An error occurred while saving. Please try again later.'));
             }
             $page = new Cms_Model_Application_Page();
             $page->find($data["id"]);
             if (!$page->getId() or $page->getValueId() != $option_value->getId() or $option_value->getAppId() != $this->getApplication()->getId()) {
                 throw new Exception($this->_('An error occurred while saving your page.'));
             }
             $page->delete();
             $html = array('success' => 1, 'success_message' => $this->_('Page successfully deleted'), '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));
     }
 }
예제 #23
0
 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));
     }
 }
예제 #24
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 page.'));
             }
             // Récupère l'option_value en cours
             $option_value = new Application_Model_Option_Value();
             $option_value->find($datas['value_id']);
             $page = new Cms_Model_Application_Page();
             $page->find($option_value->getId(), 'value_id');
             // Traitement des images des blocks
             $blocks = !empty($datas['block']) && is_array($datas['block']) ? $datas['block'] : array();
             $image_path = '/cms/block/';
             $base_image_path = $this->getApplication()->getBaseImagePath() . $image_path;
             if (!is_dir($base_image_path)) {
                 mkdir($base_image_path, 0777, true);
             }
             foreach ($blocks as $k => $block) {
                 if ($block["type"] == "image" && !empty($block['image_url'])) {
                     foreach ($block['image_url'] as $index => $image_url) {
                         //déjà enregistrée
                         if (substr($image_url, 0, 1) != '/') {
                             if (!empty($image_url) and file_exists(Core_Model_Directory::getTmpDirectory(true) . '/' . $image_url)) {
                                 rename(Core_Model_Directory::getTmpDirectory(true) . '/' . $image_url, $base_image_path . $image_url);
                                 $blocks[$k]['image_url'][$index] = $image_path . $image_url;
                             }
                         } else {
                             //                                $img = explode('/', $image_url);
                             //                                $img = $img[count($img) - 1];
                             //                                $blocks[$k]['image_url'][$index] = $image_path . $img;
                             $blocks[$k]['image_url'][$index] = $image_url;
                         }
                     }
                     foreach ($block['image_fullsize_url'] as $index => $image_url) {
                         //déjà enregistrée
                         if (substr($image_url, 0, 1) != '/') {
                             if (!empty($image_url) and file_exists(Core_Model_Directory::getTmpDirectory(true) . '/' . $image_url)) {
                                 rename(Core_Model_Directory::getTmpDirectory(true) . '/' . $image_url, $base_image_path . $image_url);
                                 $blocks[$k]['image_fullsize_url'][$index] = $image_path . $image_url;
                             }
                         } else {
                             //                                $img = explode('/', $image_url);
                             //                                $img = $img[count($img) - 1];
                             //                                $blocks[$k]['image_fullsize_url'][$index] = $image_path . $img;
                             $blocks[$k]['image_fullsize_url'][$index] = $image_url;
                         }
                     }
                 }
                 if (($block["type"] == "text" || $block["type"] == "video") && !empty($block['image'])) {
                     //déjà enregistrée
                     if (substr($block['image'], 0, 1) != '/') {
                         if (!empty($block['image']) and file_exists(Core_Model_Directory::getTmpDirectory(true) . '/' . $block['image'])) {
                             rename(Core_Model_Directory::getTmpDirectory(true) . '/' . $block['image'], $base_image_path . $block['image']);
                             $blocks[$k]['image'] = $image_path . $block['image'];
                         }
                     } else {
                         //                            $img = explode('/', $block['image']);
                         //                            $img = $img[count($img) - 1];
                         //                            $blocks[$k]['image'] = $image_path . $img;
                         $blocks[$k]['image'] = $block['image'];
                     }
                 }
             }
             $datas['block'] = $blocks;
             // Sauvegarde
             $page->setData($datas)->save();
             $html = array('success' => 1, 'success_message' => $this->_('Page 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));
     }
 }