Moving to GitHub.
[platal.git] / include / validations.inc.php
index 7c87d4c..9bcde80 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2011 Polytechnique.org                              *
+ *  Copyright (C) 2003-2014 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -31,6 +31,7 @@ abstract class Validate
     // {{{ properties
 
     public $user;
+    public $formal;
 
     public $stamp;
     public $unique;
@@ -56,6 +57,7 @@ abstract class Validate
     public function __construct(User $_user, $_unique, $_type)
     {
         $this->user   = &$_user;
+        $this->formal = !$this->user->hasProfile();
         $this->stamp  = date('YmdHis');
         $this->unique = $_unique;
         $this->type   = $_type;
@@ -221,8 +223,13 @@ abstract class Validate
         $mailer->addTo("\"{$this->user->fullName()}\" <{$this->user->bestEmail()}>");
         $mailer->addCc("validation+{$this->type}@{$globals->mail->domain}");
 
-        $body = ($this->user->isFemale() ? "Chère camarade,\n\n" : "Cher camarade,\n\n")
-              . $this->_mail_body($isok)
+        // If the user has no profile, we should be more formal as if she has one.
+        if ($this->formal) {
+            $body = ($this->user->isFemale() ? 'Bonjour Madame' : 'Bonjour Monsieur');
+        } else {
+            $body = ($this->user->isFemale() ? 'Chère camarade' : 'Cher camarade');
+        }
+        $body .= ",\n\n" . $this->_mail_body($isok)
               . (Env::has('comm') ? "\n\n" . Env::v('comm') : '')
               . "\n\nCordialement,\n-- \nL'équipe de Polytechnique.org\n"
               . $this->_mail_ps($isok);
@@ -383,7 +390,7 @@ abstract class Validate
 
     public function id()
     {
-        return $this->user->id() . '_' . $this->type . '_' . $this->stamp;
+        return str_replace(" ", "_", $this->user->id() . '_' . $this->type . '_' . $this->stamp);
     }
 
     // }}}
@@ -433,6 +440,8 @@ abstract class Validate
         }
         if (!empty($where)) {
             $where = 'WHERE ' . implode('AND', $where);
+        } else {
+            $where = '';
         }
         $it = XDB::iterRow('SELECT  data, DATE_FORMAT(stamp, "%Y%m%d%H%i%s")
                               FROM  requests
@@ -617,6 +626,25 @@ abstract class ProfileValidate extends Validate
     }
 
     // }}}
+    // {{{ function get_all_typed_requests()
+
+    /** Same as get_typed_request() but return an array of objects.
+     */
+    static public function get_all_typed_requests($type)
+    {
+        $res = XDB::iterRow('SELECT  data
+                               FROM  requests
+                              WHERE  type = {?}
+                           ORDER BY  stamp',
+                            $type);
+        $array = array();
+        while (list($data) = $res->next()) {
+            $array[] = Validate::unserialize($data);
+        }
+        return $array;
+    }
+
+    // }}}
     // {{{ function get_typed_requests_count()
 
     /** Same as get_typed_requests() but returns the count of available requests.
@@ -645,5 +673,5 @@ foreach (glob(dirname(__FILE__) . '/validations/*.inc.php') as $file) {
     require_once $file;
 }
 
-/* vim: set expandtab shiftwidth=4 tabstop=4 softtabstop=4 foldmethod=marker enc=utf-8: */
+/* vim:set expandtab shiftwidth=4 tabstop=4 softtabstop=4 foldmethod=marker fenc=utf-8: */
 ?>