コード例 #1
0
ファイル: mailjet.php プロジェクト: ac3gam3r/Maxokraft
 public function postProcess()
 {
     $modif = false;
     // Res is here to test page the time to wait the functional application
     if (($res = Tools::getValue('mj_check_hosting')) && !$this->isAccountSet()) {
         $this->page_name = $res ? 'SETUP_STEP_1' : 'SETUP_STEP_0';
     } else {
         if (Tools::isSubmit('MJ_set_connect')) {
             $this->checkAuthentication();
         } else {
             if (Tools::isSubmit('MJ_set_login')) {
                 $this->checkAuthentication();
             } else {
                 if ($events_list = Tools::getValue('events')) {
                     $mj_event = new MailJetEvents();
                     foreach ($events_list as $key => $id_mf_events) {
                         $mj_event->id = $id_mf_events;
                         if ($mj_event->delete()) {
                             unset($events_list[$key]);
                         }
                     }
                     $this->context->smarty->assign('MJ_events_form_success', $events_list);
                 }
             }
         }
     }
     // All emails sending by Mailjet ?
     if (Tools::isSubmit('MJ_set_allemails')) {
         $triggers = ($triggers = Tools::jsonDecode(Configuration::get('MJ_TRIGGERS'), true)) ? $triggers : $this->triggers;
         Configuration::updateValue('MJ_TRIGGERS', Tools::jsonEncode($triggers));
         if (Tools::getValue('MJ_allemails_active')) {
             $this->activateAllEmailMailjet();
             $triggers['active'] = 1;
         } else {
             Configuration::updateValue('PS_MAIL_METHOD', 1);
             /*
              * deactivate triggers if Mailjet emails are disabled
              */
             $triggers['active'] = 0;
         }
         Configuration::updateValue('MJ_ALLEMAILS', Tools::getValue('MJ_allemails_active'));
         $this->context->smarty->assign(array('MJ_allemails_active' => Configuration::get('MJ_ALLEMAILS'), 'AllMailsActiveMessage' => Tools::getValue('MJ_allemails_active') ? 1 : 2));
     }
     // Campaign
     if (Tools::isSubmit('MJ_submitCampaign')) {
         $this->page_name = 'NEWSLETTER';
     }
     if (Tools::isSubmit('MJ_submitCampaign2')) {
         $this->page_name = 'CAMPAIGN3';
     }
     // Activation root file Creation
     if (Tools::isSubmit('submitCreateRootFile')) {
         $api = MailjetTemplate::getApi();
         $domains = $api->getTrustDomains();
         foreach ($domains->domains as $domain) {
             if ($domain->domain == Configuration::get('PS_SHOP_DOMAIN') || $domain->domain == Configuration::get('PS_SHOP_DOMAIN_SSL')) {
                 $fp = fopen(_PS_ROOT_DIR_ . $domain->file_name, 'w');
                 fclose($fp);
             }
         }
     }
     // Account settings : details
     if (Tools::isSubmit('MJ_set_account_details')) {
         $api = MailjetTemplate::getApi();
         $api->updateUser(Tools::getValue('MJ_account_address_city'), Tools::getValue('MJ_account_address_country'), Tools::getValue('MJ_account_address_postal_code'), Tools::getValue('MJ_account_address_street'), Tools::getValue('MJ_account_company_name'), null, Tools::getValue('MJ_account_firstname'), Tools::getValue('MJ_account_lastname'), null);
         /* $locale = NULL */
         $modif = true;
     }
     // Account settings : tracking
     if (Tools::isSubmit('MJ_set_account_tracking')) {
         $api = MailjetTemplate::getApi();
         if (Tools::getValue('MJ_account_tracking_clicks') == '1') {
             $tracking_clicks = true;
         } else {
             $tracking_clicks = false;
         }
         if (Tools::getValue('MJ_account_tracking_openers') == '1') {
             $tracking_openers = true;
         } else {
             $tracking_openers = false;
         }
         $api->updateTracking($tracking_clicks, $tracking_openers);
         $modif = true;
     }
     // Account settings : senders
     if (Tools::isSubmit('MJ_set_account_senders')) {
         $api = MailjetTemplate::getApi();
         $address = Tools::getValue('MJ_account_senders_new');
         $api->createSender($address);
         $modif = true;
     }
     // Triggers
     if (Tools::isSubmit('MJ_set_triggers')) {
         $this->triggers['active'] = Tools::getValue('MJ_triggers_active');
         for ($sel = 1; $sel <= 9; $sel++) {
             $this->triggers['trigger'][$sel]['active'] = Tools::getValue('MJ_triggers_trigger_' . $sel . '_active');
             if ($sel != 5 && $sel != 6) {
                 $this->triggers['trigger'][$sel]['period'] = (double) Tools::getValue('MJ_triggers_trigger_' . $sel . '_period');
                 $this->triggers['trigger'][$sel]['periodType'] = (int) Tools::getValue('MJ_triggers_trigger_' . $sel . '_periodType');
             } else {
                 $this->triggers['trigger'][$sel]['discount'] = (double) Tools::getValue('MJ_triggers_trigger_' . $sel . '_discount');
                 $this->triggers['trigger'][$sel]['discountType'] = (int) Tools::getValue('MJ_triggers_trigger_' . $sel . '_discountType');
             }
             $languages = Language::getLanguages();
             foreach ($languages as $l) {
                 $this->triggers['trigger'][$sel]['subject'][$l['id_lang']] = Tools::getValue('MJ_triggers_trigger_' . $sel . '_subject_' . $l['id_lang']);
                 $this->triggers['trigger'][$sel]['mail'][$l['id_lang']] = Tools::getValue('MJ_triggers_trigger_' . $sel . '_mail_' . $l['id_lang']);
             }
         }
         $this->updateTriggers();
         $modif = true;
     }
     if (Tools::isSubmit('MJ_triggers_import_submit')) {
         if (isset($_FILES['MJ_triggers_import_file']['tmp_name']) && !empty($_FILES['MJ_triggers_import_file']['tmp_name'])) {
             $file = new SplFileObject($_FILES['MJ_triggers_import_file']['tmp_name']);
             while (!$file->eof()) {
                 $triggers .= $file->fgets();
             }
             Configuration::updateValue('MJ_TRIGGERS', $triggers);
             $modif = true;
         }
     }
     if (Tools::isSubmit('MJ_triggers_export_submit')) {
         $triggers = ($triggers = Configuration::get('MJ_TRIGGERS')) ? $triggers : Tools::jsonEncode($this->triggers);
         header("Content-Type: plain/text");
         header("Content-Disposition: Attachment; filename=Mailjet_Trigger_Templates.txt");
         header("Pragma: no-cache");
         echo "{$triggers}";
         die;
     }
     if ($modif) {
         $link = new Link();
         Tools::redirectAdmin($link->getAdminLink('AdminModules') . '&configure=mailjet&module_name=mailjet&MJ_request_page=' . Tools::getValue('MJ_request_page') . '&conf=4');
     }
 }