Merge remote branch 'origin/xorg/maint' into xorg/master
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 20 Feb 2011 18:17:51 +0000 (19:17 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 20 Feb 2011 18:17:51 +0000 (19:17 +0100)
Conflicts:
configs/mails.conf

Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
14 files changed:
bin/cron/newsletters.send.php
classes/userfilter/conditions.inc.php
classes/userfilter/orders.inc.php
configs/mails.conf
include/newsletter.inc.php
include/wiki/farmconfig.php
modules/admin.php
modules/newsletter.php
modules/profile/general.inc.php
modules/profile/page.inc.php
modules/xnetgrp.php
templates/newsletter/edit.tpl
templates/newsletter/notify_scheduled.mail.tpl [new file with mode: 0644]
upgrade/1.0.2/10_newsletter.sql

index e9e4ab5..f9fa74b 100755 (executable)
@@ -24,13 +24,17 @@ require_once './connect.db.inc.php';
 require_once 'newsletter.inc.php';
 ini_set('memory_limit', '128M');
 
-$nls = NewsLetter::getIssuesToSend();
-foreach ($nls as $nl) {
-    echo "Envoi de la lettre \"{$nl->title()}\" (Groupe {$nl->group})\n\n";
-    echo ' ' . date("H:i:s") . " -> début de l'envoi\n";
-    $emailsCount = $nl->sendToAll();
-    echo ' ' . date("H:i:s") . " -> fin de l'envoi\n\n";
-    echo $emailsCount . " emails ont été envoyés lors de cet envoi.\n\n";
+$issues = NewsLetter::getIssuesToSend();
+foreach ($issues as $issue) {
+    if ($issue->isEmpty()) {
+        echo "Lettre \"{$issue->title()}\" (Groupe {$issue->nl->group}) ignorée car vide.";
+    } else {
+        echo "Envoi de la lettre \"{$issue->title()}\" (Groupe {$issue->nl->group})\n\n";
+        echo ' ' . date("H:i:s") . " -> début de l'envoi\n";
+        $emailsCount = $issue->sendToAll();
+        echo ' ' . date("H:i:s") . " -> fin de l'envoi\n\n";
+        echo $emailsCount . " emails ont été envoyés lors de cet envoi.\n\n";
+    }
 }
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
index 7a2ded5..b782311 100644 (file)
@@ -166,6 +166,12 @@ abstract class UserFilterCondition implements PlFilterCondition
             $cond = new $class($values);
             break;
 
+          case 'school_id':
+            $values = $export->v('values', array());
+            $school_type = $export->s('school_type');
+            $cond = new UFC_SchoolId($school_type, $values);
+            break;
+
           case 'has_profile':
             $class = 'ufc_' . str_replace('_', '', $type);
             $cond = new $class();
@@ -487,6 +493,14 @@ class UFC_SchoolId extends UserFilterCondition
         }
         return XDB::format('p.' . $type . '_id IN {?}', $ids);
     }
+
+    public function export()
+    {
+        $export = $this->buildExport('school_id');
+        $export['school_type'] = $this->type;
+        $export['values'] = $this->ids;
+        return $export;
+    }
 }
 // }}}
 // {{{ class UFC_EducationSchool
index c068633..f640e00 100644 (file)
@@ -53,6 +53,7 @@ abstract class UserFilterOrders
           case 'hruid':
           case 'pid':
           case 'hrpid':
+          case 'is_admin':
             $class = 'UFO_' . str_replace('_', '', $type);
             return new $class($desc);
 
@@ -314,6 +315,23 @@ class UFO_Hrpid extends PlFilterOrder
     }
 }
 // }}}
+// {{{ class UFO_IsAdmin
+/** Sorts users, putting admins first
+ */
+class UFO_IsAdmin extends PlFilterOrder
+{
+    protected function getSortTokens(PlFilter $uf)
+    {
+        $uf->requireAccounts();
+        return 'a.is_admin';
+    }
+
+    public function export()
+    {
+        return $this->buildExport('is_admin');
+    }
+}
+// }}}
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>
index 6afd15b..c7bcabe 100644 (file)
@@ -74,3 +74,6 @@ cc="Polytechnique.org" <validation_modification@polytechnique.org>
 [xnet_notification]
 from="Polytechnique.org" <contact@polytechnique.org>
 
+[newsletter_schedule_mailing]
+from="Gestion des NLs" <support@polytechnique.org>
+to=br@staff.polytechnique.org
index 6e03646..26f648f 100644 (file)
@@ -666,6 +666,14 @@ class NLIssue
                                       WHERE  id = {?}',
                                       $this->id);
             if ($success) {
+                global $globals;
+                $mailer = new PlMailer('newsletter/notify_scheduled.mail.tpl');
+                $mailer->assign('group', $this->nl->group);
+                $mailer->assign('nl_title', $this->title_mail);
+                $mailer->assign('nl_id', $this->id());
+                $mailer->assign('base', $globals->baseurl);
+                $mailer->assign('send_before', $this->send_before);
+                $mailer->send();
                 $this->refresh();
             }
             return $success;
@@ -681,7 +689,7 @@ class NLIssue
     {
         if ($this->state == self::STATE_PENDING) {
             $success = XDB::execute('UPDATE  newsletter_issues
-                                        SET  send_before = NULL, state = \'new\'
+                                        SET  state = \'new\'
                                       WHERE  id = {?}', $this->id);
             if ($success) {
                 $this->refresh();
@@ -985,7 +993,15 @@ class NLIssue
 
     // }}}
     // {{{ Mailing
-    
+
+    /** Check whether this issue is empty
+     * An issue is empty if the email has no title (or the default one), or no articles and an empty head.
+     */
+    public function isEmpty()
+    {
+        return $this->title_mail == '' || $this->title_mail == 'to be continued' || (count($this->arts) == 0 && strlen($this->head) == 0);
+    }
+
     /** Retrieve the 'Send before' date, in a clean format.
      */
     public function getSendBeforeDate()
@@ -1079,7 +1095,7 @@ class NLIssue
 
         $ufc = new PFC_And($this->getRecipientsUFC(), new UFC_NLSubscribed($this->nl->id, $this->id), new UFC_HasEmailRedirect());
         $emailsCount = 0;
-        $uf = new UserFilter($ufc);
+        $uf = new UserFilter($ufc, array(new UFO_IsAdmin(), new UFO_Uid()));
         $limit = new PlLimit(self::BATCH_SIZE);
 
         while (true) {
index a4fef9d..243d2d8 100644 (file)
@@ -20,7 +20,7 @@ $Skin             = 'empty';
 
 @include_once("$FarmD/cookbook/e-protect.php");
 include_once($FarmD.'/scripts/xlpage-utf-8.php');
-ResolvePageName();
+$pagename = ResolvePageName($pagename);
 
 if ($action == 'rss'  || $action == 'atom' || $action == 'rdf'  || $action == 'dc') {
     $FmtPV['$MarkupExcerpt'] = '$page["text"]';
index 4cc20d9..1a103c9 100644 (file)
@@ -851,9 +851,9 @@ class AdminModule extends PLModule
                                                                         directory_name, short_name, sort_name, promo)
                                                VALUES  ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})',
                                          $pid, $infos[1], $fullName, $fullName, $directoryName, $fullName, $directoryName, $promo);
-                            XDB::execute('INSERT INTO  profile_education (pid, eduid, degreeid, entry_year, grad_year, flags)
-                                               VALUES  ({?}, {?}, {?}, {?}, {?}, {?})',
-                                         $pid, $eduSchools[Profile::EDU_X], $degreeid, $entry_year, $grad_year, 'primary');
+                            XDB::execute('INSERT INTO  profile_education (id, pid, eduid, degreeid, entry_year, grad_year, flags)
+                                               VALUES  (100, {?}, {?}, {?}, {?}, {?}, \'primary\')',
+                                         $pid, $eduSchools[Profile::EDU_X], $degreeid, $entry_year, $grad_year);
                             XDB::execute('INSERT INTO  accounts (hruid, type, is_admin, state, full_name, directory_name, display_name, sex)
                                                VALUES  ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})',
                                          $infos['hrid'], $type, 0, 'pending', $fullName, $directoryName, $infos[1], $sex);
index f827c71..6d18e7e 100644 (file)
@@ -127,7 +127,7 @@ class NewsletterModule extends PLModule
             return PL_NOT_FOUND;
         }
 
-        if($new) {
+        if ($new == 'new') {
             $id = $nl->createPending();
             pl_redirect($nl->adminPrefix() . '/edit/' . $id);
         }
@@ -173,7 +173,7 @@ class NewsletterModule extends PLModule
         );
 
         // Update the current issue
-        if($aid == 'update') {
+        if($aid == 'update' && Post::has('submit')) {
 
             // Save common fields
             $issue->title      = Post::s('title');
index 8a03a47..8453ae0 100644 (file)
@@ -149,7 +149,7 @@ class ProfileSettingSearchNames implements ProfileSetting
             $this->search_names = array();
             foreach ($value as &$sn) {
                 $sn['name'] = trim($sn['name']);
-                if (S::user()->isMe($this->owner) && ($sn['type'] == 'firstname' || $sn['type'] == 'lastname')) {
+                if (S::user()->isMe($page->owner) && ($sn['type'] == 'firstname' || $sn['type'] == 'lastname')) {
                     $sn['name'] = $this->prepare($page, $sn['type'], $sn['name'],
                                                  $initial[$sn['type']], $success_tmp);
                     $success = $success && $success_tmp;
index dd20de4..2bc4c52 100644 (file)
@@ -306,7 +306,7 @@ abstract class ProfilePage implements PlWizardPage
         $user = S::user();
         if ($owner->isActive()) {
             foreach ($changedFields as $field => $values) {
-                if (!is_null($field)) {
+                if (in_array($field, Profile::$descriptions)) {
                     XDB::execute('INSERT INTO  profile_modifications (pid, uid, field, oldText, newText, type, timestamp)
                                        VALUES  ({?}, {?}, {?}, {?}, {?}, {?}, NOW())
                       ON DUPLICATE KEY UPDATE  uid = VALUES(uid), oldText = IF(VALUES(type) != type, VALUES(oldText), oldText),
index 55d98e1..0516201 100644 (file)
@@ -500,9 +500,9 @@ class XnetGrpModule extends PLModule
             $uf = New UserFilter(New UFC_Group($globals->asso('id'), true));
             $admins = $uf->iterUsers();
             $admin = $admins->next();
-            $to = $admin->bestalias;
+            $to = $admin->bestEmail();
             while ($admin = $admins->next()) {
-                $to .= ', ' . $admin->bestalias;
+                $to .= ', ' . $admin->bestEmail();
             }
 
             $append = "\n"
index f470439..4bd93c1 100644 (file)
         {if $issue->isEditable()}
         Le {valid_date name="send_before_date" value=$issue->getSendBeforeDate() from=3 to=15} vers {html_select_time prefix="send_before_time_" time=$issue->getSendBeforeTime() display_hours=true display_minutes=false display_seconds=false display_meridian=false use_24_hours=true} heures
         {else}
-        Le {$issue->send_before|date_format:"%X vers %Hh"}
+        Le {$issue->send_before|date_format:"%d/%m/%Y vers %Hh"}
         {/if}
       </td>
     </tr>
     {/if}
     <tr class='center'>
       <td colspan='2'>
-        <input type='submit' value='Sauver' />
+        <input type='submit' name='submit' value='Sauver' />
       </td>
     </tr>
   </table>
diff --git a/templates/newsletter/notify_scheduled.mail.tpl b/templates/newsletter/notify_scheduled.mail.tpl
new file mode 100644 (file)
index 0000000..67f65c8
--- /dev/null
@@ -0,0 +1,37 @@
+{**************************************************************************}
+{*                                                                        *}
+{*  Copyright (C) 2003-2011 Polytechnique.org                             *}
+{*  http://opensource.polytechnique.org/                                  *}
+{*                                                                        *}
+{*  This program is free software; you can redistribute it and/or modify  *}
+{*  it under the terms of the GNU General Public License as published by  *}
+{*  the Free Software Foundation; either version 2 of the License, or     *}
+{*  (at your option) any later version.                                   *}
+{*                                                                        *}
+{*  This program is distributed in the hope that it will be useful,       *}
+{*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *}
+{*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *}
+{*  GNU General Public License for more details.                          *}
+{*                                                                        *}
+{*  You should have received a copy of the GNU General Public License     *}
+{*  along with this program; if not, write to the Free Software           *}
+{*  Foundation, Inc.,                                                     *}
+{*  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA               *}
+{*                                                                        *}
+{**************************************************************************}
+
+{config_load file="mails.conf" section="newsletter_schedule_mailing"}
+{if $mail_part eq 'head'}
+{from full=#from#}
+{to addr=#to#}
+{subject text="Validation de l'envoi d'une NL du groupe $group"}
+{elseif $mail_part eq 'text'}
+
+L'envoi d'une NL pour le groupe {$group}, "{$nl_title}", a été planifié pour le {$send_before}.
+
+Aperçu / édition :
+{$base}/newsletter/admin/edit/{$nl_id}
+
+{/if}
+
+{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}
index 5ffc573..a8da513 100644 (file)
@@ -42,7 +42,7 @@ CREATE TABLE newsletter_issues (
   nlid int(11) unsigned NOT NULL,
   id int(11) unsigned NOT NULL auto_increment,
   date date NOT NULL default '0000-00-00',
-  send_before date default NULL,
+  send_before datetime default NULL,
   state enum('sent','new','pending') NOT NULL default 'new',
   sufb_json text default NULL,
   title varchar(255) NOT NULL default '',