public function deleteAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         try {
             if (empty($datas['value_id'])) {
                 throw new Exception($this->_('An error occurred while deleting the option'));
             }
             // Récupère les données de l'application pour cette option
             $option_value = new Application_Model_Option_Value();
             $option_value->find($datas['value_id']);
             $app_id = $this->getApplication()->getId();
             if (!$option_value->getId() or $option_value->getAppId() != $app_id) {
                 throw new Exception($this->_('An error occurred while deleting the option'));
             }
             $html = array('success' => 1, 'value_id' => $datas['value_id'], 'path' => $option_value->getPath(null, array(), "mobile"), 'was_folder' => false, 'was_category' => false, 'was_feature' => false);
             // Option folder
             if (isset($datas['category_id'])) {
                 $option_value->setFolderId(null)->setFolderCategoryId(null)->setFolderCategoryPosition(null)->save();
                 $html['was_category'] = true;
                 $html['category'] = array('id' => $datas['category_id']);
             } else {
                 // Récupère l'option
                 $option = new Application_Model_Option();
                 $option->find($option_value->getOptionId());
                 $html['was_feature'] = true;
                 $html['use_user_account'] = $this->getApplication()->usesUserAccount();
                 if ($option_value->getCode() == "folder") {
                     $html['was_folder'] = true;
                 }
                 // Supprime l'option de l'application
                 $option_value->delete();
                 if ($option->onlyOnce()) {
                     $html['page'] = array('id' => $option->getId(), 'name' => $option->getName(), 'icon_url' => $option->getIconUrl(), 'category_id' => $option->getCategoryId());
                 }
                 // Renvoi le nouveau code HTML
                 //                    $this->getLayout()->setBaseRender('content', 'application/customization/page/list.phtml', 'admin_view_default');
             }
         } catch (Exception $e) {
             $html = array('message' => $this->_('An error occurred while deleting the option'), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->_sendHtml($html);
     }
 }
 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 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 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));
     }
 }
 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;
     }
 }