$dom != $globals->mail->alias_dom2;
}
+ public static function isVirtualEmailAddress($email)
+ {
+ global $globals;
+ if (strpos($email, '@') === false) {
+ return false;
+ }
+
+ list($user, $dom) = explode('@', $email);
+ return $dom == $globals->mail->alias_dom
+ || $dom == $globals->mail->alias_dom2;
+ }
+
// Fetch a set of users from a list of UIDs
public static function getBulkUsersWithUIDs(array $uids)
{
}
}
+class UFC_Email implements UserFilterCondition
+{
+ private $email;
+ public function __construct($email)
+ {
+ $this->email = $email;
+ }
+
+ public function buildCondition(UserFilter &$uf)
+ {
+ if (User::isForeignEmailAddress($this->email)) {
+ $sub = $uf->addEmailRedirectFilter($this->email);
+ return XDB::format('e' . $sub . '.email IS NOT NULL OR a.email = {?}', $this->email);
+ } else {
+ if (User::isVirtualEmailAddress($this->email)) {
+ $sub = $uf->addVirtualEmailFilter($this->email);
+ } else {
+ list($user, $domain) = explode('@', $this->email);
+ $sub = $uf->addAliasFilter($user);
+ }
+ return 'al' . $sub . '.alias IS NOT NULL';
+ }
+ }
+}
/******************
private $query = null;
private $orderby = null;
- private $lastcount = 0;
+ private $lastcount = null;
public function __construct($cond = null, $sort = null)
{
public function getTotalCount()
{
if (is_null($this->lastcount)) {
+ $this->buildQuery();
return (int)XDB::fetchOneCell('SELECT COUNT(*)
' . $this->query . '
GROUP BY a.uid');
return new UserFilter(new UFC_And($min, $max));
}
+ static private function getDBSuffix($string)
+ {
+ return preg_replace('/[^a-z0-9]/i', '', $string);
+ }
+
+
+ private $option = 0;
+ private function register_optional(array &$table, $val)
+ {
+ if (is_null($val)) {
+ $sub = $this->option++;
+ $index = null;
+ } else {
+ $sub = self::getDBSuffix($val);
+ $index = $val;
+ }
+ $sub = '_' . $sub;
+ $table[$sub] = $index;
+ return $sub;
+ }
/** DISPLAY
*/
}
private $pn = array();
- private $pno = 0;
public function addNameFilter($type, $variant = null)
{
if (!is_null($variant)) {
self::assertName($ft);
if (!is_null($variant) && $variant == 'other') {
- $sub .= $this->pno++;
+ $sub .= $this->option++;
}
$this->pn[$sub] = Profile::getNameTypeId($ft);
return $sub;
private $pepe = array();
private $with_pee = false;
- private $pe_g = 0;
public function addEducationFilter($x = false, $grade = null)
{
if (!$x) {
- $index = $this->pe_g;
- $sub = $this->pe_g++;
+ $index = $this->option;
+ $sub = $this->option++;
} else {
self::assertGrade($grade);
$index = $grade;
/** GROUPS
*/
private $gpm = array();
- private $gpm_o = 0;
public function addGroupFilter($group = null)
{
if (!is_null($group)) {
$index = $sub = $group;
} else {
$index = $group;
- $sub = preg_replace('/[^a-z0-9]/i', '', $group);
+ $sub = self::getDBSuffix($group);
}
} else {
- $sub = 'group_' . $this->gpm_o++;
+ $sub = 'group_' . $this->option++;
$index = null;
}
$sub = '_' . $sub;
}
return $joins;
}
+
+ /** EMAILS
+ */
+ private $e = array();
+ public function addEmailRedirectFilter($email = null)
+ {
+ return $this->register_optional($this->e, $email);
+ }
+
+ private $ve = array();
+ public function addVirtualEmailFilter($email = null)
+ {
+ return $this->register_optional($this->ve, $email);
+ }
+
+ private $al = array();
+ public function addAliasFilter($alias = null)
+ {
+ return $this->register_optional($this->al, $alias);
+ }
+
+ private function emailJoins()
+ {
+ global $globals;
+ $joins = array();
+ foreach ($this->e as $sub=>$key) {
+ if (is_null($key)) {
+ $joins['e' . $sub] = array('left', 'emails', '$ME.uid = $UID AND $ME.flags != \'filter\'');
+ } else {
+ $joins['e' . $sub] = array('left', 'emails', XDB::format('$ME.uid = $UID AND $ME.flags != \'filter\' AND $ME.email = {?}', $key));
+ }
+ }
+ foreach ($this->ve as $sub=>$key) {
+ if (is_null($key)) {
+ $joins['v' . $sub] = array('left', 'virtual', '$ME.type = \'user\'');
+ } else {
+ $joins['v' . $sub] = array('left', 'virtual', XDB::format('$ME.type = \'user\' AND $ME.alias = {?}', $key));
+ }
+ $joins['vr' . $sub] = array('inner', 'virtual_redirect', '$ME.vid = v' . $sub . '.vid');
+ $joins['al' . $sub] = array('left', 'aliases', XDB::format('$ME.id = $UID AND (CONCAT($ME.alias, \'@\', {?}) = vr'. $sub . '.redirect
+ OR CONCAT($ME.alias, \'@\', {?}) = vr'. $sub . '.redirect)',
+ $globals->mail->domain, $globals->mail->domain2));
+ }
+ foreach ($this->al as $sub=>$key) {
+ if (is_null($key)) {
+ $joins['al' . $sub] = array('left', 'aliases', '$ME.id = $UID');
+ } else {
+ $joins['al' . $sub] = array('left', 'aliases', XDB::format('$ME.id = $UID AND $ME.alias = {?}', $key));
+ }
+ }
+ return $joins;
+ }
}
// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
}
}
- $it = XDB::iterator("SELECT IF(u.nom_usage != '', u.nom_usage, u.nom) AS nom,
- u.prenom, u.promo, u.hruid, s.ts AS date
+ $it = XDB::iterator('SELECT s.uid, a.hruid, s.ts AS date
FROM groupex.membres_sub_requests AS s
- INNER JOIN auth_user_md5 AS u ON (s.uid = u.user_id)
- WHERE asso_id = {?}
- ORDER BY nom, prenom",
- $globals->asso('id'));
-
+ INNER JOIN accounts AS a ON(s.uid = a.uid)
+ WHERE s.asso_id = {?}
+ ORDER BY s.ts', $globals->asso('id'));
$page->changeTpl('xnetgrp/subscribe-valid.tpl');
$page->assign('valid', $it);
}
$this->load('mail.inc.php');
$page->changeTpl('xnetgrp/annuaire-admin.tpl');
- $mmlist = new MMList(S::v('uid'), S::v('password'),
- $globals->asso('mail_domain'));
+ $user = S::user();
+ $mmlist = new MMList($user, $globals->asso('mail_domain'));
$lists = $mmlist->get_lists();
if (!$lists) $lists = array();
$listes = array_map(create_function('$arr', 'return $arr["list"];'), $lists);
$not_in_group_ext = array();
foreach ($subscribers as $mail) {
- $res = XDB::query(
- 'SELECT COUNT(*)
- FROM groupex.membres AS m
- LEFT JOIN auth_user_md5 AS u ON (m.uid=u.user_id AND m.uid<50000)
- LEFT JOIN aliases AS a ON (a.id=u.user_id and a.type="a_vie")
- WHERE asso_id = {?} AND
- (m.email = {?} OR CONCAT(a.alias, "@polytechnique.org") = {?})',
- $globals->asso('id'), $mail, $mail);
- if ($res->fetchOneCell() == 0) {
- if (strstr($mail, '@polytechnique.org') === false) {
+ $uf = new UserFilter(new UFC_And(new UFC_Group($globals->asso('id')),
+ new UFC_Email($mail)));
+ if ($uf->getTotalCount() == 0) {
+ if (User::isForeignEmailAddress($mail)) {
$not_in_group_ext[] = $mail;
} else {
$not_in_group_x[] = $mail;
}
} else {
if (isvalid_email($email)) {
- if (Env::v('x') && Env::has('userid') && Env::i('userid')) {
+ if (Env::v('x') && Env::i('userid')) {
$uid = Env::i('userid');
- $res = XDB::query("SELECT *
- FROM auth_user_md5
- WHERE user_id = {?} AND perms = 'pending'", $uid);
- if ($res->numRows() == 1) {
+ $user = User::getWithUID($uid);
+ if ($user && $user->state == 'pending') {
if (Env::v('market')) {
$market = Marketing::get($uid, $email);
if (!$market) {
function handler_admin_member_new_ajax(&$page)
{
header('Content-Type: text/html; charset="UTF-8"');
- $page->changeTpl('xnetgrp/membres-new-search.tpl', NO_SKIN);
- $res = null;
+ $page->changeTpl('xnetgrp/membres-new-search.tpl', NO_SKIN);
+ $users = array();
if (Env::has('login')) {
- require_once 'user.func.inc.php';
- $res = get_not_registered_user(Env::v('login'), true);
+ $user = User::getSilent(Env::t('login'));
+ if ($user && $user->state != 'pending') {
+ $users = array($user);
+ }
}
- if (is_null($res)) {
- list($nom, $prenom) = str_replace(array('-', ' ', "'"), '%', array(Env::v('nom'), Env::v('prenom')));
- $where = "perms = 'pending'";
+ if (empty($users)) {
+ list($nom, $prenom) = str_replace(array('-', ' ', "'"), '%', array(Env::t('nom'), Env::t('prenom')));
+ $cond = new UFC_And(new UFC_Not(new UFC_Registered()));
if (!empty($nom)) {
- $where .= " AND nom LIKE '%$nom%'";
+ $cond->addChild(new UFC_Name(UserFilter::LASTNAME, $nom, UFC_Name::CONTAINS));
}
if (!empty($prenom)) {
- $where .= " AND prenom LIKE '%$prenom%'";
+ $cond->addChild(new UFC_Name(UserFilter::FIRSTNAME, $prenom, UFC_Name::CONTAINS));
}
- if (preg_match('/^[0-9]{4}$/', Env::v('promo'))) {
- $where .= " AND promo = " . Env::i('promo');
- } elseif (preg_match('/^[0-9]{2}$/', Env::v('promo'))) {
- $where .= " AND MOD(promo, 100) = " . Env::i('promo');
- } elseif (Env::has('promo')) {
- return;
+ if (Env::i('promo')) {
+ $cond->addChild(new UFC_Promo('=', UserFilter::GRADE_ING, Env::i('promo')));
+ }
+ $uf = new UserFilter($cond);
+ $users = $uf->getUsers(30);
+ if ($uf->getTotalCount() > 30) {
+ $page->assign('too_many', true);
+ $users = array();
}
- $res = XDB::iterator("SELECT user_id, nom, prenom, promo
- FROM auth_user_md5
- WHERE $where");
- }
- if ($res && $res->total() < 30) {
- $page->assign("choix", $res);
}
+ $page->assign('users', $users);
}
function unsubscribe(PlUser &$user)
}
if (empty($art) && !is_null($aid)) {
- $res = XDB::query("SELECT a.*, u.nom, u.prenom, u.promo, u.hruid,
- FIND_IN_SET('public', a.flags) AS public,
+ $res = XDB::query("SELECT a.*, FIND_IN_SET('public', a.flags) AS public,
FIND_IN_SET('photo', a.flags) AS photo
FROM groupex.announces AS a
- INNER JOIN auth_user_md5 AS u USING(user_id)
WHERE asso_id = {?} AND a.id = {?}",
$globals->asso('id'), $aid);
if ($res->numRows()) {
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************/
+class UserFilterIterator implements PlIterator
+{
+ private $it;
+ private $user;
+ public function __construct(PlIterator &$it, PlUser &$user)
+ {
+ $this->it =& $it;
+ $this->user =& $user;
+ }
+
+ public function total()
+ {
+ return $this->it->total();
+ }
+
+ public function first()
+ {
+ return $this->it->first();
+ }
+
+ public function last()
+ {
+ return $this->it->last();
+ }
+
+ public function next()
+ {
+ while ($n = $this->it->next()) {
+ $uf = UserFilter::getLegacy($n['promo_min'], $n['promo_max']);
+ if ($uf->checkUser($this->user)) {
+ return $n;
+ }
+ }
+ return null;
+ }
+}
+
class XnetGrpEventFeed extends PlFeed
{
public function __construct()
$url,
'L\'actualité du groupe ' . $name,
$url . '/logo',
- 'xnetgrp/announce-rss.tpl');
+ 'xnetgrp/feed.tpl');
}
protected function fetch(PlUser &$user)
{
global $globals;
if (!is_null($user)) {
- return XDB::iterator("SELECT a.id, a.titre AS title, a.texte, a.contacts,
- a.create_date AS publication,
- CONCAT(u2.prenom, ' ', IF(u2.nom_usage != '', u2.nom_usage, u2.nom), ' (X', u2.promo, ')') AS author,
- FIND_IN_SET('photo', a.flags) AS photo,
- CONCAT({?}, '/#art', a.id) AS link
- FROM auth_user_md5 AS u
- INNER JOIN groupex.announces AS a ON ( (a.promo_min = 0 OR a.promo_min <= u.promo)
- AND (a.promo_max = 0 OR a.promo_max <= u.promo))
- INNER JOIN auth_user_md5 AS u2 ON (u2.user_id = a.user_id)
- WHERE u.user_id = {?} AND peremption >= NOW() AND a.asso_id = {?}",
- $this->link, $user->id(), $globals->asso('id'));
+ return new UserFilterIterator(
+ XDB::iterator("SELECT a.id, a.titre AS title, a.texte, a.contacts,
+ a.create_date AS publication,
+ FIND_IN_SET('photo', a.flags) AS photo,
+ CONCAT({?}, '/#art', a.id) AS link
+ FROM groupex.announces AS a
+ WHERE peremption >= NOW() AND a.asso_id = {?}",
+ $this->link, $globals->asso('id'), $user));
} else {
- return XDB::iterator("SELECT a.id, a.titre AS title, a.texte, a.create_date AS publication,
- CONCAT(u.prenom, ' ', IF(u.nom_usage != '', u.nom_usage, u.nom), ' (X', u.promo, ')') AS author,
- CONCAT({?}, '/#art', a.id) AS link,
- NULL AS photo, NULL AS contacts
- FROM groupex.announces AS a
- INNER JOIN auth_user_md5 AS u USING(user_id)
- WHERE FIND_IN_SET('public', a.flags) AND peremption >= NOW() AND a.asso_id = {?}",
+ return XDB::iterator("SELECT a.id, a.titre AS title, a.texte, a.create_date AS publication,
+ CONCAT({?}, '/#art', a.id) AS link,
+ NULL AS photo, NULL AS contacts
+ FROM groupex.announces AS a
+ WHERE FIND_IN_SET('public', a.flags) AND peremption >= NOW() AND a.asso_id = {?}",
$this->link, $globals->asso('id'));
}
}
{* *}
{**************************************************************************}
- {if !$choix}
+ {if t($too_many)}
Les critères de recherche ne sont pas assez précis.
- {elseif !$choix->total()}
+ {elseif $users|@count eq 0}
Aucun camarade non-inscrit ne correspond aux informations fournies.
- {elseif $choix->total()}
+ {else}
Camarades correspondants :
<select name="userid" onchange="document.getElementById('marketing').style.display = (this.value == 0 ? 'none' : '')">
<option value="0"></option>
- {iterate item=x from=$choix}
- <option value="{$x.user_id}" {if $choix->total() == 1}selected="selected"{/if}>{$x.prenom} {$x.nom} (X{$x.promo})</option>
- {/iterate}
+ {foreach item=user from=$users}
+ <option value="{$user->id()}" {if $users|@count == 1}selected="selected"{/if}>{profile user=$user link=false promo=true}</option>
+ {/foreach}
</select>
- <span id="marketing" {if $choix->total() != 1}style="display: none"{/if}><br />
+ <span id="marketing" {if $users|@count != 1}style="display: none"{/if}><br />
<label><input type="checkbox" name="market" checked="checked"
onchange="document.getElementById('from').style.display = (this.checked ? '' : 'none')"/>
Lui envoyer un marketing</label>
{iterate from=$valid item=user}
<tr>
<td><input type="checkbox" name="subs[{$user.hruid}]" value="1" class="select_sub" /></td>
- <td><a href="profile/{$user.hruid}" class="popup2">{$user.prenom} {$user.nom} (X{$user.promo})</a></td>
+ <td>{profile user=$user.uid promo=true}</td>
<td>{$user.date|date_format}</td>
<td><a href="{$platal->ns}subscribe/{$user.hruid}">{icon name=magnifier title="Détails"}</a></td>
</tr>