<?php
/***************************************************************************
- * Copyright (C) 2003-2010 Polytechnique.org *
+ * Copyright (C) 2003-2011 Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
// {{{ properties
public $user;
+ public $formal;
public $stamp;
public $unique;
// Validations rules: comments for administrators.
public $rules = 'Mieux vaut laisser une demande de validation à un autre administrateur que de valider une requête illégale ou que de refuser une demande légitime.';
+ // Unless differently stated, a validation must be done by a site administrator.
+ public $requireAdmin = true;
+
// }}}
// {{{ constructor
* @param $_unique: set to false if a profile can have multiple requests of this type.
* @param $_type: request's type.
*/
- public function __construct(User &$_user, $_unique, $_type)
+ 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;
*/
public function handle_formu()
{
+ if ($this->requireAdmin && !S::admin()) {
+ $this->trigError('Vous n\'avez pas les permissions nécessaires pour valider cette demande.');
+ return false;
+ }
+
if (Env::has('delete')) {
$this->clean();
$this->trigSuccess('Requête supprimée.');
$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);
public function id()
{
- return $this->user->id() . '_' . $this->type . '_' . $this->stamp;
+ return str_replace(" ", "_", $this->user->id() . '_' . $this->type . '_' . $this->stamp);
}
// }}}
* @param $_unique: set to false if a profile can have multiple requests of this type.
* @param $_type: request's type.
*/
- public function __construct(User &$_user, Profile &$_profile, $_unique, $_type)
+ public function __construct(User $_user, Profile $_profile, $_unique, $_type)
{
parent::__construct($_user, $_unique, $_type);
$this->profile = &$_profile;
{
$res = XDB::iterRow('SELECT data
FROM requests
- WHERE pid = {?} and type = {?}',
+ WHERE pid = {?} and type = {?}
+ ORDER BY stamp',
$pid, $type);
$array = array();
while (list($data) = $res->next()) {
}
// }}}
+ // {{{ 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.