require_once('validations.inc.php');
- $trombi_x = '/home/web/trombino/photos'.S::v('promo')
- .'/'.S::v('forlife').'.jpg';
-
+ $trombi_x = '/home/web/trombino/photos' . S::v('promo') . '/' . S::user()->login() . '.jpg';
if (Env::has('upload')) {
S::assert_xsrf_token();
function handler_profile(&$page, $x = null)
{
+ // TODO/note for upcoming developers:
+ // We currently maintain both $user and $login; $user is the old way of
+ // obtaining information, and eventually everything will be loaded
+ // through $login. That is the reason why in the template $user is named
+ // $x, and $login $user (sorry for the confusion).
+
+ // Determines which user to display the profile of, and retrieves basic
+ // information on this user.
if (is_null($x)) {
return PL_NOT_FOUND;
}
- global $globals;
- require_once 'user.func.inc.php';
-
- $page->changeTpl('profile/profile.tpl', SIMPLE);
-
- $view = 'private';
- if (!S::logged() || Env::v('view') == 'public') $view = 'public';
- if (S::logged() && Env::v('view') == 'ax') $view = 'ax';
-
$login = S::logged() ? User::get($x) : User::getSilent($x);
if (!$login) {
return PL_NOT_FOUND;
}
+ // Now that we know this is the profile of an existing user, we can
+ // switch to the appropriate template.
+ $page->changeTpl('profile/profile.tpl', SIMPLE);
+ require_once 'user.func.inc.php';
+
+ // Determines the access level at which the profile will be displayed.
+ if (!S::logged() || Env::v('view') == 'public') {
+ $view = 'public';
+ } else if (S::logged() && Env::v('view') == 'ax') {
+ $view = 'ax';
+ } else {
+ $view = 'private';
+ }
+
+ // Determines is the user is registered, and fetches the user infos in
+ // the appropriate way.
$res = XDB::query("SELECT perms IN ('admin','user','disabled')
FROM auth_user_md5
WHERE user_id = {?}", $login->id());
- if (!$res->fetchOneCell()) {
- $user = get_not_registered_user($x, true);
- if ($user->total() != 1) {
- return PL_NOT_FOUND;
- }
- $user = $user->next();
+ if ($res->fetchOneCell()) {
+ $new = Env::v('modif') == 'new';
+ $user = get_user_details($login->login(), S::v('uid'), $view);
+ } else {
+ $new = false;
+ $user = array();
if (S::logged()) {
- pl_redirect('marketing/public/' . $user['user_id']);
+ pl_redirect('marketing/public/' . $login->login());
}
- $user['forlife'] = $x;
- } else {
- $new = Env::v('modif') == 'new';
- $user = get_user_details($login->login(), S::v('uid'), $view);
}
+ // Profile view are logged.
if (S::logged()) {
S::logger()->log('view_profile', $login->login());
}
- $title = $user['prenom'] . ' ' . ( empty($user['nom_usage']) ? $user['nom'] : $user['nom_usage'] );
- $page->setTitle($title);
+ // Sets the title of the html page.
+ $page->setTitle($login->fullName());
- // photo
-
- $photo = 'photo/'.$user['forlife'].($new ? '/req' : '');
+ // Prepares the display of the user's mugshot.
+ $photo = 'photo/' . $login->login() . ($new ? '/req' : '');
+ if (!isset($user['photo_pub']) || !has_user_right($user['photo_pub'], $view)) {
+ $photo = "";
+ }
+ $page->assign('photo_url', $photo);
if (!isset($user['y']) and !isset($user['x'])) {
list($user['x'], $user['y']) = getimagesize("images/none.png");
$user['x'] = 160;
}
- $page->assign('logged', has_user_right('private', $view));
- if (!has_user_right($user['photo_pub'], $view)) {
- $photo = "";
- }
-
- $page->assign_by_ref('x', $user);
- $page->assign('photo_url', $photo);
- // alias virtual
+ // Determines and displays the virtual alias.
+ global $globals;
$res = XDB::query(
- "SELECT alias
- FROM virtual
- INNER JOIN virtual_redirect USING(vid)
- INNER JOIN auth_user_quick ON ( user_id = {?} AND emails_alias_pub = 'public' )
- WHERE ( redirect={?} OR redirect={?} )
- AND alias LIKE '%@{$globals->mail->alias_dom}'",
- $user['user_id'],
- $user['forlife'].'@'.$globals->mail->domain,
- $user['forlife'].'@'.$globals->mail->domain2);
+ "SELECT alias
+ FROM virtual
+ INNER JOIN virtual_redirect USING (vid)
+ INNER JOIN auth_user_quick ON (user_id = {?} AND emails_alias_pub = 'public')
+ WHERE (redirect={?} OR redirect={?})
+ AND alias LIKE '%@{$globals->mail->alias_dom}'",
+ $login->id(),
+ $login->forlifeEmail(),
+ // TODO(vzanotti): get ride of all @m4x.org addresses in the
+ // virtual redirect base, and remove this über-ugly hack.
+ $login->login() . '@' . $globals->mail->domain2);
$page->assign('virtualalias', $res->fetchOneCell());
+
+ // Adds miscellaneous properties to the display.
+ // Adds the global user property array to the display.
+ $page->assign_by_ref('x', $user);
+ $page->assign_by_ref('user', $login);
+ $page->assign('logged', has_user_right('private', $view));
$page->assign('view', $view);
$page->addJsLink('close_on_esc.js');
- header('Last-Modified: ' . date('r', strtotime($user['date'])));
+ if (isset($user['date'])) {
+ header('Last-Modified: ' . date('r', strtotime($user['date'])));
+ }
}
function handler_ax(&$page, $user = null)
$vcard->do_page($page);
}
- function handler_admin_trombino(&$page, $uid = null, $action = null) {
+ function handler_admin_trombino(&$page, $login = null, $action = null) {
$page->changeTpl('profile/admin_trombino.tpl');
$page->setTitle('Administration - Trombino');
- $page->assign('uid', $uid);
- $q = XDB::query(
- "SELECT a.alias,promo
- FROM auth_user_md5 AS u
- INNER JOIN aliases AS a ON ( u.user_id = a.id AND type='a_vie' )
- WHERE user_id = {?}", $uid);
- list($forlife, $promo) = $q->fetchOneRow();
+ if (!$login || !($user = User::get($login))) {
+ return PL_NOT_FOUND;
+ } else {
+ $page->assign_by_ref('user', $user);
+ }
switch ($action) {
case "original":
header("Content-type: image/jpeg");
- readfile("/home/web/trombino/photos".$promo."/".$forlife.".jpg");
+ readfile("/home/web/trombino/photos" . $user->promo() . "/" . $user->login() . ".jpg");
exit;
break;
unlink($_FILES['userfile']['tmp_name']);
XDB::execute(
"REPLACE INTO photo SET uid={?}, attachmime = {?}, attach={?}, x={?}, y={?}",
- $uid, $mimetype, $data, $x, $y);
+ $user->id(), $mimetype, $data, $x, $y);
break;
case "delete":
S::assert_xsrf_token();
- XDB::execute('DELETE FROM photo WHERE uid = {?}', $uid);
+ XDB::execute('DELETE FROM photo WHERE uid = {?}', $user->id());
break;
}
-
- $page->assign('forlife', $forlife);
}
function handler_admin_binets(&$page, $action = 'list', $id = null) {
$page->setTitle('Administration - Binets');
<div id="fiche">
<div id="photo" class="part">
- {if $photo_url}<img alt="Photo de {$x.forlife}" src="{$photo_url}" width="{$x.x}"/>{/if}
+ {if $photo_url}<img alt="Photo de {$user->login()}" src="{$photo_url}" width="{$x.x}"/>{/if}
{if $logged && ( $x.section|smarty:nodefaults || $x.binets_join|smarty:nodefaults || $x.gpxs_join|smarty:nodefaults)}
<h2>À l'X...</h2>
{if $x.section}<div><em class="intitule">Section : </em><span>{$x.section}</span></div>{/if}
</div>
<div id="fiche_identite" class="part">
<div class="civilite">
- {if $x.sexe}•{/if}
- {$x.prenom} {if $x.nom_usage eq ""}{$x.nom}{else}{$x.nom_usage} ({$x.nom}){/if}
+ {if $user->isFemale()}•{/if}
+ {$user->fullName()}{if $x.nom_usage neq ""} ({$x.nom}){/if}
{if $logged}
{if $x.nickname} (alias {$x.nickname}){/if}
{/if}
{if $x.web} <a href="{$x.web}">{icon name="world_go" title="Site Web"}</a>{/if}
{if $logged}
- {if !$x.dcd}<a href="vcard/{$x.forlife}.vcf">{*
+ {if !$x.dcd}<a href="vcard/{$user->login()}.vcf">{*
*}{icon name=vcard title="Afficher la carte de visite"}</a>{/if}
{if !$x.is_contact}
- <a href="javascript:chgMainWinLoc('carnet/contacts?action=ajouter&user={$x.forlife}&token={xsrf_token}')">
+ <a href="javascript:chgMainWinLoc('carnet/contacts?action=ajouter&user={$user->login()}&token={xsrf_token}')">
{icon name=add title="Ajouter à mes contacts"}</a>
{else}
- <a href="javascript:chgMainWinLoc('carnet/contacts?action=retirer&user={$x.forlife}&token={xsrf_token}')">
+ <a href="javascript:chgMainWinLoc('carnet/contacts?action=retirer&user={$user->login()}&token={xsrf_token}')">
{icon name=cross title="Retirer de mes contacts"}</a>
{/if}
{if hasPerm('admin')}
- <a href="javascript:chgMainWinLoc('admin/user/{$x.forlife}')">
+ <a href="javascript:chgMainWinLoc('admin/user/{$user->login()}')">
{icon name=wrench title="administrer user"}</a>
{/if}
- {if $x.forlife eq $smarty.session.forlife}
+ {if $user->login() eq $smarty.session.hruid}
<a href="javascript:chgMainWinLoc('profile/edit')">{icon name="user_edit" title="Modifier ma fiche"}</a>
{/if}
{/if}
{if $logged}
<div class='email'>
{if $x.dcd}
- Décédé{if $x.sexe}e{/if} le {$x.deces|date_format}
+ Décédé{if $user->isFemale()}e{/if} le {$x.deces|date_format}
{elseif !$x.actif}
Ce{if $c.sexe}tte{/if} camarade n'a plus d'adresse de redirection valide,<br />
- <a href="marketing/broken/{$x.forlife}" class="popup">clique ici si tu connais son adresse email !</a>
+ <a href="marketing/broken/{$user->login()}" class="popup">clique ici si tu connais son adresse email !</a>
{elseif !$x.inscrit}
Cette personne n'est pas inscrite à Polytechnique.org,<br />
- <a href="marketing/public/{$x.hruid}" class="popup">clique ici si tu connais son adresse email !</a>
+ <a href="marketing/public/{$user->login()}" class="popup">clique ici si tu connais son adresse email !</a>
{else}
{if $virtualalias}
<a href="mailto:{$virtualalias}">{$virtualalias}</a><br />
{/if}
- <a href="mailto:{$x.bestalias}@{#globals.mail.domain#}">{$x.bestalias}@{#globals.mail.domain#}</a>
- {if $x.bestalias neq $x.forlife}<br />
- <a href="mailto:{$x.forlife}@{#globals.mail.domain#}">{$x.forlife}@{#globals.mail.domain#}</a>
+ <a href="mailto:{$user->bestEmail()}">{$user->bestEmail()}</a>
+ {if $user->bestEmail() neq $user->forlifeEmail()}<br />
+ <a href="mailto:{$user->forlifeEmail()}">{$user->forlifeEmail()}</a>
{/if}
{/if}
</div>
{if $x.iso3166}
<img src='images/flags/{$x.iso3166}.gif' alt='{$x.nationalite}' height='11' title='{$x.nationalite}' />
{/if}
- X {$x.promo}
- {if ($x.promo_sortie-3 > $x.promo)}
+ X {$user->promo()}
+ {if $x.promo_sortie && ($x.promo_sortie-3 > $x.promo)}
- X {math equation="a-b" a=$x.promo_sortie b=3}
{/if}
{if $x.applis_join}
- Formation : {$x.applis_join|smarty:nodefaults}
{/if}
{if $logged && $x.is_referent}
- [<a href="referent/{$x.forlife}" class='popup2'>Ma fiche référent</a>]
+ [<a href="referent/{$user->login()}" class='popup2'>Ma fiche référent</a>]
{/if}
</div>
</div>
<div class="part">
<small>
Cette fiche est publique et visible par tout internaute,<br />
- vous pouvez aussi voir <a href="profile/private/{$x.forlife}?display=light">celle réservée aux X</a>.
+ vous pouvez aussi voir <a href="profile/private/{$user->login()}?display=light">celle réservée aux X</a>.
</small>
</div>
{elseif $view eq 'ax'}