]> git.agnieray.net Git - galette.git/commitdiff
Fix mailing cancel, cleanup
authorJohan Cwiklinski <johan@x-tnd.be>
Sun, 21 Feb 2016 18:42:55 +0000 (19:42 +0100)
committerJohan Cwiklinski <johan@x-tnd.be>
Mon, 17 Oct 2016 20:39:24 +0000 (22:39 +0200)
galette/includes/dependencies.php
galette/includes/main.inc.php
galette/includes/routes/members.routes.php
galette/includes/smarty.inc.php
galette/lib/Galette/Core/GaletteMail.php
galette/lib/Galette/Filters/MembersList.php
galette/templates/default/gestion_adherents.tpl
galette/templates/default/gestion_mailings.tpl
galette/templates/default/mailing_adherents.tpl
galette/templates/default/page.tpl

index 5e3bdd0e656efb4a6e518b1b36466f2076fc3053..63602151e9a0c1b10794c514c1de82593d81f9d1 100644 (file)
@@ -73,7 +73,7 @@ $container['view'] = function ($c) {
         $c->preferences->pref_editor_enabled
     );
     $smarty->assign('pref_mail_method', $c->preferences->pref_mail_method);
-    $smarty->assign('existing_mailing', isset($c->get('session')->mailing));
+    $smarty->assign('existing_mailing', $c->get('session')->mailing !== null);
     $smarty->assign('require_tabs', null);
     $smarty->assign('require_cookie', null);
     $smarty->assign('contentcls', null);
index d49485a179a0d1760099e7b4d9d9bf414abfd343..839eb5ccb77973b3c6c8ed2991874d1d6ceca018 100644 (file)
@@ -82,18 +82,6 @@ if ($needs_update) {
     die();
 } else {
     $app = new \Slim\App(
-        /*array(
-            'view'              => new Smarty(
-                $plugins,
-                $i18n,
-                $preferences,
-                $logo,
-                $login,
-                $session
-            ),
-            'templates.path'    => GALETTE_ROOT . GALETTE_TPL_SUBDIR,
-            'mode'              => GALETTE_MODE
-        )*/
         [
             'settings' => [
                 'determineRouteBeforeAppMiddleware' => true,
@@ -158,46 +146,8 @@ $smarty = $app->getContainer()->get('view')->getSmarty();
 require_once GALETTE_ROOT . 'includes/smarty.inc.php';
 
 /**
- * Load plugins
+ * Authentication middleware
  */
-/*$plugins->setApp($app);
-$plugins->loadModules(GALETTE_PLUGINS_PATH, $i18n->getFileName());*/
-
-/*$acls = [
-    'preferences'       => 'admin',
-    'store-preferences' => 'admin',
-    'dashboard'         => 'groupmanager',
-    'sysinfos'          => 'staff',
-    'charts'            => 'staff',
-    'plugins'           => 'admin',
-    'history'           => 'staff',
-    'members'           => 'groupmanager',
-    'filter-memberslist'=> 'groupmanager',
-    'advanced-search'   => 'groupmanager',
-    'batch-memberslist' => 'groupmanager',
-    'mailing'           => 'staff',
-    'csv-memberslist'   => 'staff',
-    'groups'            => 'groupmanager',
-    'me'                => 'member',
-    'member'            => 'member',
-    'pdf-members-cards' => 'member',
-    'pdf-members-labels'=> 'groupmanager',
-    'mailings'          => 'staff',
-    'contributions'     => 'staff',
-    'transactions'      => 'staff',
-    'payments_filter'   => 'member',
-    'editmember'        => 'member',
-    'storemembers'      => 'member',
-    'impersonate'       => 'superadmin',
-    'unimpersonate'     => 'member'
-];
-
-//load user defined ACLs
-if (file_exists(GALETTE_CONFIG_PATH  . 'local_acls.inc.php')) {
-    $acls = array_merge($acls, $local_acls);
-}*/
-
-
 $authenticate = function ($request, $response, $next) use ($container) {
     $login = $container->session->login;
 
@@ -370,13 +320,10 @@ $authenticate = function ($request, $response, $next) use ($container) {
     };
 };*/
 
-//dependency injection
-$app->zdb           = $zdb;
-$app->i18n          = $i18n;
-//$app->plugins       = $plugins;
-$app->preferences   = $preferences;
-$app->login         = $login;
-
+/**
+ * Redirection middleware.
+ * Each user sill have a default homepage varying on it status (logged in or not, its credentials, etc.
+ */
 $baseRedirect = function ($request, $response, $args = []) use ($app, $container) {
     $login = $container->get('login');
     $router = $container->get('router');
@@ -399,9 +346,9 @@ $baseRedirect = function ($request, $response, $args = []) use ($app, $container
                 || $login->isAdmin()
                 || $login->isStaff()
             ) {
-               if (!isset($_COOKIE['show_galette_dashboard'])
+                if (!isset($_COOKIE['show_galette_dashboard'])
                     || $_COOKIE['show_galette_dashboard'] == 1
-               ) {
+                ) {
                     return $response
                         ->withStatus(301)
                         ->withHeader('Location', $router->pathFor('dashboard'));
index 82852ebc67ee80b8398fc3e723df988f86f846e4..3a6881f877221eadb8774e8445a46a8e0323c051 100644 (file)
@@ -1427,15 +1427,9 @@ $app->post(
             }
 
             if (isset($post['mailing'])) {
-                $options = array();
-                //FIXME
-                /*if ( $request->post() ) {
-                    $options['new'] = 'new';
-                }*/
-
                 return $response
                     ->withStatus(301)
-                    ->withHeader('Location', $this->router->pathFor('mailing', $options));
+                    ->withHeader('Location', $this->router->pathFor('mailing') . '?new=new');
             }
 
             if (isset($post['attendance_sheet'])) {
@@ -1598,56 +1592,59 @@ $app->get(
 )->setName('pdf-members-labels')->add($authenticate);
 
 //mailing
-$app->get(
+$app->map(
+    ['GET', 'POST'],
     '/mailing',
-    function () use ($app,
-        &$success_detected, &$warning_detected, &$error_detected
-    ) {
-        $request = $app->request();
+    function ($request, $response) {
+        $post = $request->getParsedBody();
+        $get = $request->getQueryParams();
+        $error_detected = [];
+        $success_detected = [];
+
         //We're done :-)
-        if ( isset($_POST['mailing_done'])
-            || isset($_POST['mailing_cancel'])
-            || isset($_GET['mailing_new'])
-            || isset($_GET['reminder'])
+        if (isset($post['mailing_done'])
+            || isset($post['mailing_cancel'])
+            || isset($get['mailing_new'])
+            || isset($get['reminder'])
         ) {
-            if ( isset($this->session->mailing) ) {
+            if ($this->session->mailing !== null) {
                 // check for temporary attachments to remove
                 $m = $this->session->mailing;
                 $m->removeAttachments(true);
             }
             $this->session->mailing = null;
-            unset($this->session->mailing);
-            if ( !isset($_GET['mailing_new']) && !isset($_GET['reminder']) ) {
-                header('location: gestion_adherents.php');
-                exit(0);
+            if (!isset($get['mailing_new']) && !isset($get['reminder'])) {
+                return $response
+                    ->withStatus(301)
+                    ->withHeader('Location', $this->router->pathFor('members'));
             }
         }
 
         $params = array();
 
-        if ( $this->preferences->pref_mail_method == Mailing::METHOD_DISABLED
+        if ($this->preferences->pref_mail_method == Mailing::METHOD_DISABLED
             && !GALETTE_MODE === 'DEMO'
         ) {
-            $hist->add(
+            $this->history->add(
                 _T("Trying to load mailing while mail is disabled in preferences.")
             );
         } else {
-            if ( isset($this->session->filter_members) ) {
+            if (isset($this->session->filter_members)) {
                 $filters =  $this->session->filter_members;
             } else {
                 $filters = new MembersList();
             }
 
-            if ( isset($this->session->mailing)
-                && !isset($_POST['mailing_cancel'])
-                && !isset($_GET['from'])
-                && !isset($_GET['reset'])
+            if ($this->session->mailing !== null
+                && !isset($post['mailing_cancel'])
+                && !isset($get['from'])
+                && !isset($get['reset'])
             ) {
                 $mailing = $this->session->mailing;
-            } else if (isset($_GET['from']) && is_numeric($_GET['from'])) {
-                $mailing = new Mailing(null, $_GET['from']);
-                MailingHistory::loadFrom((int)$_GET['from'], $mailing);
-            } else if (isset($_GET['reminder'])) {
+            } elseif (isset($get['from']) && is_numeric($get['from'])) {
+                $mailing = new Mailing(null, $get['from']);
+                MailingHistory::loadFrom((int)$get['from'], $mailing);
+            } elseif (isset($get['reminder'])) {
                 //FIXME: use a constant!
                 $filters->reinit();
                 $filters->membership_filter = Members::MEMBERSHIP_LATE;
@@ -1656,64 +1653,65 @@ $app->get(
                 $members = $m->getList(true);
                 $mailing = new Mailing(($members !== false) ? $members : null);
             } else {
-                if ( count($filters->selected) == 0
-                    && !isset($_GET['mailing_new'])
-                    && !isset($_GET['reminder'])
+                if (count($filters->selected) == 0
+                    && !isset($get['mailing_new'])
+                    && !isset($get['reminder'])
                 ) {
                     Analog::log(
-                        '[mailing_adherents.php] No member selected for mailing',
+                        '[Mailings] No member selected for mailing',
                         Analog::WARNING
                     );
 
-                    if ( isset($profiler) ) {
+                    if (isset($profiler)) {
                         $profiler->stop();
                     }
 
-                    header('location:gestion_adherents.php');
-                    die();
+                    return $response
+                        ->withStatus(301)
+                        ->withHeader('Location', $this->router->pathFor('members'));
                 }
                 $m = new Members();
                 $members = $m->getArrayList($filters->selected);
                 $mailing = new Mailing(($members !== false) ? $members : null);
             }
 
-            if ( isset($_POST['mailing_go'])
-                || isset($_POST['mailing_reset'])
-                || isset($_POST['mailing_confirm'])
-                || isset($_POST['mailing_save'])
+            if (isset($post['mailing_go'])
+                || isset($post['mailing_reset'])
+                || isset($post['mailing_confirm'])
+                || isset($post['mailing_save'])
             ) {
-                if ( trim($_POST['mailing_objet']) == '' ) {
+                if (trim($post['mailing_objet']) == '') {
                     $error_detected[] = _T("Please type an object for the message.");
                 } else {
                     $mailing->subject = $_POST['mailing_objet'];
                 }
 
-                if ( trim($_POST['mailing_corps']) == '') {
+                if (trim($post['mailing_corps']) == '') {
                     $error_detected[] = _T("Please enter a message.");
                 } else {
-                    $mailing->message = $_POST['mailing_corps'];
+                    $mailing->message = $post['mailing_corps'];
                 }
 
-                $mailing->html = ( isset($_POST['mailing_html']) ) ? true : false;
+                $mailing->html = (isset($post['mailing_html'])) ? true : false;
 
                 //handle attachments
-                if ( isset($_FILES['files']) ) {
-                    for ( $i = 0; $i < count($_FILES['files']['name']); $i++) {
-                        if ( $_FILES['files']['error'][$i] === UPLOAD_ERR_OK ) {
-                            if ( $_FILES['files']['tmp_name'][$i] !='' ) {
-                                if ( is_uploaded_file($_FILES['files']['tmp_name'][$i]) ) {
+                if (isset($_FILES['files'])) {
+                    for ($i = 0; $i < count($_FILES['files']['name']); $i++) {
+                        if ($_FILES['files']['error'][$i] === UPLOAD_ERR_OK) {
+                            if ($_FILES['files']['tmp_name'][$i] != '') {
+                                if (is_uploaded_file($_FILES['files']['tmp_name'][$i])) {
                                     $da_file = array();
-                                    foreach ( array_keys($_FILES['files']) as $key ) {
+                                    foreach (array_keys($_FILES['files']) as $key) {
                                         $da_file[$key] = $_FILES['files'][$key][$i];
                                     }
                                     $res = $mailing->store($da_file);
-                                    if ( $res < 0 ) {
+                                    if ($res < 0) {
                                         //what to do if one of attachments fail? should other be removed?
                                         $error_detected[] = $mailing->getAttachmentErrorMessage($res);
                                     }
                                 }
                             }
-                        } else if ($_FILES['files']['error'][$i] !== UPLOAD_ERR_NO_FILE) {
+                        } elseif ($_FILES['files']['error'][$i] !== UPLOAD_ERR_NO_FILE) {
                             Analog::log(
                                 $mailing->getPhpErrorMessage($_FILES['files']['error'][$i]),
                                 Analog::WARNING
@@ -1725,7 +1723,7 @@ $app->get(
                     }
                 }
 
-                if ( count($error_detected) == 0
+                if (count($error_detected) == 0
                     && !isset($_POST['mailing_reset'])
                     && !isset($_POST['mailing_save'])
                 ) {
@@ -1735,26 +1733,25 @@ $app->get(
                 }
             }
 
-            if ( isset($_POST['mailing_confirm']) && count($error_detected) == 0 ) {
-
+            if (isset($_POST['mailing_confirm']) && count($error_detected) == 0) {
                 $mailing->current_step = Mailing::STEP_SEND;
                 //ok... let's go for fun
                 $sent = $mailing->send();
-                if ( $sent == Mailing::MAIL_ERROR ) {
+                if ($sent == Mailing::MAIL_ERROR) {
                     $mailing->current_step = Mailing::STEP_START;
                     Analog::log(
-                        '[mailing_adherents.php] Message was not sent. Errors: ' .
+                        '[Mailings] Message was not sent. Errors: ' .
                         print_r($mailing->errors, true),
                         Analog::ERROR
                     );
-                    foreach ( $mailing->errors as $e ) {
+                    foreach ($mailing->errors as $e) {
                         $error_detected[] = $e;
                     }
                 } else {
                     $mlh = new MailingHistory($mailing);
                     $mlh->storeMailing(true);
                     Analog::log(
-                        '[mailing_adherents.php] Message has been sent.',
+                        '[Mailings] Message has been sent.',
                         Analog::INFO
                     );
                     $mailing->current_step = Mailing::STEP_SENT;
@@ -1762,35 +1759,33 @@ $app->get(
                     $filters->selected = null;
                     $this->session->filter_members = $filters;
                     $this->session->mailing = null;
-                    unset($this->session->mailing);
                 }
             }
 
-            if ( isset($_GET['remove_attachment']) ) {
-                $mailing->removeAttachment($_GET['remove_attachment']);
+            if (isset($get['remove_attachment'])) {
+                $mailing->removeAttachment($get['remove_attachment']);
             }
 
-            if ( $mailing->current_step !== Mailing::STEP_SENT ) {
+            if ($mailing->current_step !== Mailing::STEP_SENT) {
                 $this->session->mailing = $mailing;
             }
 
             /** TODO: replace that... */
             $this->session->labels = $mailing->unreachables;
 
-            if ( !isset($_POST['html_editor_active'])
-                || trim($_POST['html_editor_active']) == ''
+            if (!isset($post['html_editor_active'])
+                || trim($post['html_editor_active']) == ''
             ) {
-                $_POST['html_editor_active'] = $this->preferences->pref_editor_enabled;
+                $post['html_editor_active'] = $this->preferences->pref_editor_enabled;
             }
 
-            if ( isset($_POST['mailing_save']) ) {
+            if (isset($post['mailing_save'])) {
                 //user requested to save the mailing
                 $histo = new MailingHistory($mailing);
-                if ( $histo->storeMailing() !== false ) {
+                if ($histo->storeMailing() !== false) {
                     $success_detected[] = _T("Mailing has been successfully saved.");
                     $params['mailing_saved'] = true;
                     $this->session->mailing = null;
-                    unset($this->session->mailing);
                     $head_redirect = array(
                         'timeout'   => 30,
                         'url'       => 'gestion_mailings.php'
@@ -1802,18 +1797,17 @@ $app->get(
             $params = array_merge(
                 $params,
                 array(
-                    'success_detected'  => $success_detected,
-                    'warning_detected'  => $warning_detected,
-                    'error_detected'    => $error_detected,
                     'mailing'           => $mailing,
                     'attachments'       => $mailing->attachments,
                     'html_editor'       => true,
-                    'html_editor_active'=> $request->post('html_editor_active')
+                    'html_editor_active'=> $post['html_editor_active']
                 )
             );
         }
 
-        $app->render(
+        // display page
+        $this->view->render(
+            $response,
             'mailing_adherents.tpl',
             array_merge(
                 array(
@@ -1823,7 +1817,7 @@ $app->get(
                 $params
             )
         );
-
+        return $response;
     }
 )->setName('mailing')->add($authenticate);
 
index 5bd64bf86a48c9ad15b8d871f68b249eada1d3a4..dc7244b339aea65369f0f1af46b544288c83ba1a 100644 (file)
@@ -37,8 +37,6 @@
  * @since     Available since 0.63
  */
 
-use Galette\Core\Smarty;
-
 if (!defined('GALETTE_ROOT')) {
        die("Sorry. You can't access directly to this file");
 }
@@ -86,4 +84,3 @@ $smarty->registerPlugin(
     'statusLabel',
     'getStatusLabel'
 );
-
index 2126d24f0659e182cde388e1cf7f08d3f10fb727..ba5f8196b7e91fb25f995818081d7c2dd4da178f 100644 (file)
@@ -40,8 +40,6 @@ namespace Galette\Core;
 use Analog\Analog;
 
 /** @ignore */
-require_once 'class.phpmailer.php';
-require_once 'class.smtp.php';
 require_once GALETTE_ROOT . 'includes/html2text.php';
 
 /**
index f3ea081bb291cfab26c259875f62f015c7bc3fcf..5df1ed432791c71d8cc73d0bf96005bb223b086f 100644 (file)
@@ -38,7 +38,6 @@
 namespace Galette\Filters;
 
 use Analog\Analog;
-use Galette\Core\Smarty;
 use Galette\Core\Pagination;
 use Galette\Entity\Group;
 use Galette\Repository\Members;
index faffe98ef90429e074ea39c103cd12306d269778..5bea66457a0ec966080275abef187a84e1ab22f6 100644 (file)
                             buttons: {
                                 '{_T string="Resume"}': function() {
                                     $(this).dialog( "close" );
-                                    location.href = 'mailing_adherents.php';
+                                    location.href = '{path_for name="mailing"}';
                                 },
                                 '{_T string="New"}': function() {
                                     $(this).dialog( "close" );
index 56fd4462c49f6730fdecb9e6986c528befbd68a6..16e6c86040b0200598e25e0db300fc81cc80e3cf 100644 (file)
                                 title="{_T string="Display mailing '%subject' details in preview window" pattern="/%subject/" replace=$log.mailing_subject}"
                                 />
                         </a>
-                        <a href="mailing_adherents.php?from={$log.mailing_id}">
+                        <a href="{path_for name="mailing"}?from={$log.mailing_id}">
                             <img
                                 src="{base_url}/{$template_subdir}images/icon-mail.png"
                                 alt="{_T string="New mailing from %s" pattern="/%s/" replace=$log.mailing_id}"
             </tbody>
         </table>
         <div class="center">
-            <a class="button" id="btnadd" href="mailing_adherents.php?mailing_new=true">{_T string="Create new mailing"}</a>
+            <a class="button" id="btnadd" href="{path_for name="mailing"}?mailing_new=true">{_T string="Create new mailing"}</a>
         </div>
 {/block}
 
index dd0ea229428fd33d1e30fc506e4c1aceabb850d2..505b809607f883fc582aac72383c2d33f239aada 100644 (file)
@@ -6,7 +6,7 @@
             <p>{_T string="Email sent is disabled in the preferences. Ask galette admin"}</p>
         </div>
 {elseif !isset($mailing_saved)}
-        <form action="mailing_adherents.php#mail_preview" id="listform" method="post" enctype="multipart/form-data">
+        <form action="{path_for name="mailing"}#mail_preview" id="listform" method="post" enctype="multipart/form-data">
         <div class="mailing">
             <section class="mailing_infos">
                 <header class="ui-state-default ui-state-active">{_T string="Mailing informations"}</header>
                     Ok: function() {
                         var _this = $(this);
                         _this.dialog( "close" );
-                        window.location.href = 'mailing_adherents.php' + _link.attr('href');
+                        window.location.href = '{path_for name="mailing"}' + _link.attr('href');
                     },
                     {_T string="Cancel"}: function() {
                          $(this).dialog( "close" );
index 70cd8ea2655c2099429d6d926d9113d46861e4f1..835319e1570e43e39371c265ca0a42acfa701720 100644 (file)
@@ -176,8 +176,8 @@ We have to use a template file, so Smarty will do its work (like replacing varia
     <div id="content"{if $contentcls} class="{$contentcls}"{/if}>
         <h1 id="titre">
             {$page_title}
-            {if $PAGENAME neq 'mailing_adherents.php' and $existing_mailing eq true}
-                <a class="button" id="sendmail" href="{$galette_base_path}mailing_adherents.php" title="{_T string="A mailing exists in the current session. Click here if you want to resume or cancel it."}">
+            {if $cur_route neq 'mailing' and $existing_mailing eq true}
+                <a class="button" id="sendmail" href="{path_for name="mailing"}" title="{_T string="A mailing exists in the current session. Click here if you want to resume or cancel it."}">
                     {_T string="Existing mailing"}
                 </a>
             {/if}