예제 #1
0
 /**
  * Module configuration request processing
  **/
 public function _postProcess()
 {
     global $smarty;
     $errors = array();
     $method = Tools::getValue('method');
     if ($method == 'signin') {
         $djlUtil = new DejalaUtils();
         $this->dejalaConfig->mode = 'TEST';
         $this->dejalaConfig->login = Tools::getValue('login');
         $this->dejalaConfig->password = Tools::getValue('password');
         $this->dejalaConfig->country = Tools::getValue('country');
         $this->dejalaConfig->serviceURL = str_replace('.fr', '.' . $this->dejalaConfig->country, $this->dejalaConfig->serviceURL);
         $this->dejalaConfig->sandboxServiceURL = str_replace('.fr', '.' . $this->dejalaConfig->country, $this->dejalaConfig->sandboxServiceURL);
         $storeAttr = array();
         $response = $djlUtil->ping($this->dejalaConfig, 'TEST');
         if ($response['status'] == 200) {
             $this->dejalaConfig->saveConfig();
         } else {
             if ($response['status'] == 401) {
                 $errors[] = $this->l('An error occurred while authenticating your account on Dejala.com. Your credentials were not recognized.');
             } else {
                 $errors[] = $this->l('Unable to process the action.') . '(' . $response['status'] . ')';
             }
             $this->dejalaConfig->login = null;
             $this->dejalaConfig->password = null;
         }
     } elseif ($method == 'register') {
         $djlUtil = new DejalaUtils();
         $this->dejalaConfig->mode = 'TEST';
         $this->dejalaConfig->login = Tools::getValue('login');
         $this->dejalaConfig->password = Tools::getValue('password');
         $this->dejalaConfig->country = Tools::getValue('country');
         $this->dejalaConfig->serviceURL = str_replace('.fr', '.' . $this->dejalaConfig->country, $this->dejalaConfig->serviceURL);
         $this->dejalaConfig->sandboxServiceURL = str_replace('.fr', '.' . $this->dejalaConfig->country, $this->dejalaConfig->sandboxServiceURL);
         $this->dejalaConfig->storeUrl = Dejala::getHttpHost(true, true);
         $response = $djlUtil->createInstantStore($this->dejalaConfig, Tools::getValue('store_name'));
         if ($response['status'] == 201) {
             $this->dejalaConfig->saveConfig();
         } elseif ($response['status'] == 409) {
             $errors[] = $this->l('Please choose another login');
         } elseif ($response['status'] == 403) {
             $errors[] = $this->l('Dejala Server cannot be reached by your Prestashop server. This is most likely due to a limit set by your hosting provider. Please contact their technical support and ask if your server is authorized to initiate outbound HTTP connections.');
         } else {
             $errors[] = $this->l('Unable to process the action.') . '(' . $response['status'] . ')';
         }
         $this->dejalaConfig->loadConfig();
     } elseif ($method == 'location') {
         $djlUtil = new DejalaUtils();
         $response = $djlUtil->setStoreLocation($this->dejalaConfig, $_POST);
         if ($response['status'] != 200) {
             $errors[] = $this->l('An error occurred while updating location');
         }
     } elseif ($method == 'contact') {
         $djlUtil = new DejalaUtils();
         $response = $djlUtil->setStoreContacts($this->dejalaConfig, $_POST);
         if ($response['status'] != 200) {
             $errors[] = $this->l('An error occurred while updating contacts');
         }
     } elseif ($method == 'processes') {
         $djlUtil = new DejalaUtils();
         $response = $djlUtil->setStoreProcesses($this->dejalaConfig, $_POST);
         if ($response['status'] != 200) {
             $errors[] = $this->l('An error occurred while updating processes');
         }
     } elseif ($method == 'products') {
         $djlUtil = new DejalaUtils();
         $response = $djlUtil->setStoreProducts($this->dejalaConfig, $_POST);
         if ($response['status'] != 200) {
             $errors[] = $this->l('An error occurred while updating products');
         }
     } elseif ($method == 'technical_options') {
         $maxStatuses = (int) $_POST['status_max'];
         if ($maxStatuses > 30) {
             $maxStatuses = 30;
         }
         $selectedTriggers = array();
         for ($i = 0; $i < $maxStatuses; $i++) {
             $l_val = Tools::getValue('status_' . $i);
             if ($l_val) {
                 $selectedTriggers[] = $l_val;
             }
         }
         $trigerringStatuses = implode(',', $selectedTriggers);
         $this->dejalaConfig->trigerringStatuses = htmlentities($trigerringStatuses, ENT_COMPAT, 'UTF-8');
         $this->dejalaConfig->saveConfig();
         $this->dejalaConfig->loadConfig();
     } elseif ($method == 'delivery_options') {
         $djlUtil = new DejalaUtils();
         $response = $djlUtil->setStoreCalendar($this->dejalaConfig, $_POST);
         if ($response['status'] != 200) {
             $errors[] = $this->l('An error occurred while updating products');
         }
         $m_attributes['nb_days_displayed'] = htmlentities(Tools::getValue('nb_days'), ENT_COMPAT, 'UTF-8');
         $m_attributes['delivery_delay'] = htmlentities(Tools::getValue('delivery_delay'), ENT_COMPAT, 'UTF-8');
         $m_attributes['delivery_partial'] = htmlentities(Tools::getValue('delivery_partial'), ENT_COMPAT, 'UTF-8');
         $response = $djlUtil->setStoreAttributes($this->dejalaConfig, $m_attributes);
         if ($response['status'] != 200) {
             $errors[] = $this->l('An error occurred while updating products');
         }
     } elseif ($method == 'golive') {
         $djlUtil = new DejalaUtils();
         $response = $djlUtil->goLive($this->dejalaConfig, $_POST);
     } elseif ($method == 'switchMode') {
         $l_mode = Tools::getValue('mode');
         if ('PROD' == $l_mode || 'TEST' == $l_mode) {
             $this->dejalaConfig->mode = $l_mode;
             $this->dejalaConfig->saveConfig();
         }
     } elseif ($method == 'switchActive') {
         $l_active = Tools::getValue('visibility_status');
         if ($l_active == "visible" || $l_active == "invisible") {
             $this->dejalaConfig->visibility_status = $l_active;
             $this->dejalaConfig->saveConfig();
         }
         if ($l_active == "visible_limited") {
             $l_active_list = Tools::getValue('visible_users_list');
             if ($l_active_list == "") {
                 $this->dejalaConfig->visible_users_list = "";
                 $this->dejalaConfig->saveConfig();
                 $errors[] = $this->l('You must provide at least one email address to restrict Dejala\'s visibility.');
             } else {
                 $this->dejalaConfig->visibility_status = $l_active;
                 $this->dejalaConfig->visible_users_list = $l_active_list;
                 $this->dejalaConfig->saveConfig();
             }
         }
     } else {
         $errors[] = $this->l('Unable to process the action.');
     }
     return $errors;
 }
예제 #2
0
 /**
  * Module configuration request processing
  **/
 public function _postProcess()
 {
     global $smarty;
     $errors = array();
     $method = Tools::getValue('method');
     if ($method == 'signin') {
         $djlUtil = new DejalaUtils();
         $this->dejalaConfig->mode = 'TEST';
         $this->dejalaConfig->login = Tools::getValue('login');
         $this->dejalaConfig->password = Tools::getValue('password');
         $this->dejalaConfig->country = Tools::getValue('country');
         $this->dejalaConfig->serviceURL = str_replace('.fr', '.' . $this->dejalaConfig->country, $this->dejalaConfig->serviceURL);
         $this->dejalaConfig->sandboxServiceURL = str_replace('.fr', '.' . $this->dejalaConfig->country, $this->dejalaConfig->sandboxServiceURL);
         $storeAttr = array();
         $response = $djlUtil->ping($this->dejalaConfig, 'TEST');
         if (200 == $response['status']) {
             $this->dejalaConfig->saveConfig();
         } else {
             $this->dejalaConfig->login = null;
             $this->dejalaConfig->password = null;
             $errors[] = $this->l('Impossible to process the action') . '(' . $response['status'] . ')';
         }
     } else {
         if ($method == 'register') {
             $djlUtil = new DejalaUtils();
             $this->dejalaConfig->mode = 'TEST';
             $this->dejalaConfig->login = Tools::getValue('login');
             $this->dejalaConfig->password = Tools::getValue('password');
             $this->dejalaConfig->country = Tools::getValue('country');
             $this->dejalaConfig->serviceURL = str_replace('.fr', '.' . $this->dejalaConfig->country, $this->dejalaConfig->serviceURL);
             $this->dejalaConfig->sandboxServiceURL = str_replace('.fr', '.' . $this->dejalaConfig->country, $this->dejalaConfig->sandboxServiceURL);
             $response = $djlUtil->createInstantStore($this->dejalaConfig, Tools::getValue('store_name'));
             if ($response['status'] == 201) {
                 $this->dejalaConfig->saveConfig();
             } else {
                 if (409 == $response['status']) {
                     $errors[] = $this->l('Please choose another login');
                 } else {
                     $errors[] = $this->l('Impossible to process the action') . '(' . $response['status'] . ')';
                 }
                 $this->dejalaConfig->loadConfig();
             }
         } else {
             if ($method == 'location') {
                 $djlUtil = new DejalaUtils();
                 $response = $djlUtil->setStoreLocation($this->dejalaConfig, $_POST);
                 if ($response['status'] != 200) {
                     $errors[] = $this->l('An error occured while updating location');
                 }
             } else {
                 if ($method == 'contact') {
                     $djlUtil = new DejalaUtils();
                     $response = $djlUtil->setStoreContacts($this->dejalaConfig, $_POST);
                     if ($response['status'] != 200) {
                         $errors[] = $this->l('An error occured while updating contacts');
                     }
                 } else {
                     if ($method == 'processes') {
                         $djlUtil = new DejalaUtils();
                         $response = $djlUtil->setStoreProcesses($this->dejalaConfig, $_POST);
                         if ($response['status'] != 200) {
                             $errors[] = $this->l('An error occured while updating processes');
                         }
                     } else {
                         if ($method == 'products') {
                             $djlUtil = new DejalaUtils();
                             $response = $djlUtil->setStoreProducts($this->dejalaConfig, $_POST);
                             if ($response['status'] != 200) {
                                 $errors[] = $this->l('An error occured while updating products');
                             }
                         } else {
                             if ($method == 'technical_options') {
                                 $maxSatuses = $_POST['status_max'];
                                 if ($maxSatuses > 30) {
                                     $maxSatuses = 30;
                                 }
                                 $selectedTriggers = array();
                                 for ($i = 0; $i < $maxSatuses; $i++) {
                                     $l_val = Tools::getValue('status_' . $i);
                                     if ($l_val) {
                                         $selectedTriggers[] = $l_val;
                                     }
                                 }
                                 $trigerringStatuses = implode(',', $selectedTriggers);
                                 $this->dejalaConfig->trigerringStatuses = htmlentities($trigerringStatuses, ENT_COMPAT, 'UTF-8');
                                 $this->dejalaConfig->saveConfig();
                                 $this->dejalaConfig->loadConfig();
                             } else {
                                 if ($method == 'delivery_options') {
                                     $djlUtil = new DejalaUtils();
                                     $response = $djlUtil->setStoreCalendar($this->dejalaConfig, $_POST);
                                     if ($response['status'] != 200) {
                                         $errors[] = $this->l('An error occured while updating products');
                                     }
                                     $m_attributes['nb_days_displayed'] = htmlentities(Tools::getValue('nb_days'), ENT_COMPAT, 'UTF-8');
                                     $m_attributes['delivery_delay'] = htmlentities(Tools::getValue('delivery_delay'), ENT_COMPAT, 'UTF-8');
                                     $m_attributes['delivery_partial'] = htmlentities(Tools::getValue('delivery_partial'), ENT_COMPAT, 'UTF-8');
                                     $response = $djlUtil->setStoreAttributes($this->dejalaConfig, $m_attributes);
                                     if ($response['status'] != 200) {
                                         $errors[] = $this->l('An error occured while updating products');
                                     }
                                 } else {
                                     if ($method == 'golive') {
                                         $djlUtil = new DejalaUtils();
                                         $response = $djlUtil->goLive($this->dejalaConfig, $_POST);
                                     } else {
                                         if ($method == 'switchMode') {
                                             $l_mode = Tools::getValue('mode');
                                             if ('PROD' == $l_mode || 'TEST' == $l_mode) {
                                                 $this->dejalaConfig->mode = $l_mode;
                                                 $this->dejalaConfig->saveConfig();
                                             }
                                         } else {
                                             if ($method == 'switchActive') {
                                                 $l_active = intval(Tools::getValue('active_flag'));
                                                 if ($l_active == 1 || $l_active == 0) {
                                                     $this->dejalaConfig->active = $l_active;
                                                     $this->dejalaConfig->saveConfig();
                                                 }
                                             } else {
                                                 $errors[] = $this->l('Impossible to process the action');
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $errors;
 }