From 420b03aaaee78c5389513e1394682fa35baff2b2 Mon Sep 17 00:00:00 2001 From: "Pierre Habouzit (MadCoder" Date: Mon, 13 Dec 2004 00:00:25 +0000 Subject: [PATCH] refactor fiche.php is not the biggest page of the site anymore git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-74 --- htdocs/fiche.php | 308 ++++++++++++++++++++-------------------------------- templates/fiche.tpl | 62 ++++++----- 2 files changed, 150 insertions(+), 220 deletions(-) diff --git a/htdocs/fiche.php b/htdocs/fiche.php index 53b0e64..f91b87b 100644 --- a/htdocs/fiche.php +++ b/htdocs/fiche.php @@ -24,234 +24,156 @@ require_once("xorg.inc.php"); new_simple_page('fiche.tpl',AUTH_COOKIE); require_once('applis.func.inc.php'); +require_once('user.func.inc.php'); //$isnetscape = !empty($_SESSION['skin_compatible']); -if (!isset($_REQUEST['user']) && !isset($_REQUEST['mat'])) - exit; +if (!isset($_REQUEST['user']) && !isset($_REQUEST['mat'])) { + $page->kill("cette page n'existe pas"); +} + +if (isset($_REQUEST['user'])) { + $login = get_user_forlife($_REQUEST['user']); + if ($login === false) { + $page->kill(""); + } +} -if (isset($_REQUEST["modif"]) && $_REQUEST["modif"]=="new") { - $new = true; -} else { - $new = false; +if (isset($_REQUEST['mat'])) { + $res = $globals->db->query("SELECT alias + FROM aliases AS a + INNER JOIN auth_user_md5 AS u ON (a.id=u.user_id AND a.type='a_vie') + WHERE matricule='{$_REQUEST['mat']}'"); + if (!(list($login) = mysql_fetch_row($res))) { + $page->kill("cette page n'existe pas"); + } + mysql_free_result($res); } -if (isset($_REQUEST['user'])) - $where_clause = "INNER JOIN aliases AS a1 ON (a1.id=u.user_id AND a1.alias = '{$_REQUEST['user']}' AND a.type!='homonyne')"; -else - $where_clause = " WHERE u.matricule = '{$_REQUEST['mat']}'"; +$new = (isset($_REQUEST["modif"]) && $_REQUEST["modif"]=="new"); -$reqsql = "SELECT u.prenom, u.nom, u.epouse, IF(gp.nat='',gp.pays,gp.nat) AS text, gp.a2, - u.user_id, a.alias, a2.alias, u.matricule, u.perms IN ('admin','user'), - FIND_IN_SET('femme', u.flags) AS sexe, u.deces != 0 as dcd, u.deces, - u.date, u.cv, sections.text, u.mobile, u.web, - u.libre, u.promo, c.uid IS NOT NULL, p.x, p.y +$reqsql = "SELECT u.prenom, u.nom, u.epouse, + IF(gp.nat='',gp.pays,gp.nat) AS nationalite, gp.a2 AS iso3166, + u.user_id, a.alias AS forlife, a2.alias AS bestalias, + u.matricule, u.perms IN ('admin','user') AS inscrit, + FIND_IN_SET('femme', u.flags) AS sexe, u.deces != 0 AS dcd, u.deces, + u.date, u.cv, sections.text AS section, u.mobile, u.web, + u.libre, u.promo, c.uid IS NOT NULL AS is_contact, p.x, p.y, + + m.expertise != '' AS is_referent + FROM auth_user_md5 AS u INNER JOIN aliases AS a ON (u.user_id=a.id AND a.type='a_vie') INNER JOIN aliases AS a2 ON (u.user_id=a2.id AND FIND_IN_SET('bestalias',a2.flags)) LEFT JOIN contacts AS c ON (c.uid = {$_SESSION['uid']} and c.contact = u.user_id) LEFT JOIN geoloc_pays AS gp ON (gp.a2 = u.nationalite) - INNER JOIN sections ON(sections.id = u.section) - LEFT JOIN photo AS p ON(p.uid = u.user_id) ".$where_clause; + INNER JOIN sections ON (sections.id = u.section) + LEFT JOIN photo AS p ON (p.uid = u.user_id) + LEFT JOIN mentor AS m ON (m.uid = u.user_id) + WHERE a.alias = '$login'"; $result = $globals->db->query($reqsql); +$user = mysql_fetch_assoc($result); +mysql_free_result($result); -if (mysql_num_rows($result)!=1) - exit; - -if (list($prenom, $nom, $epouse, $nationalite, $iso3166, - $user_id, $forlife, $bestalias, $matricule, $inscrit, - $sexe, $dcd, $deces, $date, - $cv, $section, - $mobile, $web, $libre, $promo, - $is_contact, $size_x, $size_y) = mysql_fetch_row($result)) { - -$page->assign('user_id', $user_id); -$page->assign('prenom', $prenom); -$page->assign('nom', $nom); -$page->assign('promo', $promo); -$page->assign('cv', $cv); -$page->assign('forlife', $forlife); -$page->assign('bestalias', $bestalias); -$page->assign('epouse', $epouse); -$page->assign('nationalite', $nationalite); -$page->assign('iso3166', $iso3166); -$page->assign('user_id', $user_id); -$page->assign('matricule', $matricule); -$page->assign('inscrit', $inscrit); -$page->assign('sexe', $sexe); -$page->assign('dcd', $dcd); -$page->assign('deces', $deces); -$page->assign('date', $date); -$page->assign('section', $section); -$page->assign('mobile', $mobile); -$page->assign('web', $web); -$page->assign('libre', $libre); - -if (empty($epouse)) - $page->assign('xorg_title', "$prenom $nom"); -else - $page->assign('xorg_title', "$prenom $epouse"); - - -// reformatage is_contact -$is_contact = (bool) $is_contact; -$page->assign('is_contact', $is_contact); +$title = $user['prenom'] . ' ' . empty($user['epouse']) ? $user['nom'] : $user['epouse']; +$page->assign('xorg_title', $title); // photo -$photo="getphoto.php?x=".$forlife.(SID == '' ? '' : '&'.SID).($new ? '&modif=new' : ''); -if(!isset($size_y) and !isset($size_x)) list($size_x, $size_y) = getimagesize("images/none.png"); -if(!isset($size_y) or $size_y < 1) $size_y=1; -if(!isset($size_x) or $size_x < 1) $size_x=1; -if($size_x > 240){ - $size_y = (integer)($size_y*240/$size_x); - $size_x = 240; +$photo="getphoto.php?x=".$user['forlife'].($new ? '&modif=new' : ''); + +if(!isset($user['y']) and !isset($user['x'])) { + list($user['x'], $user['y']) = getimagesize("images/none.png"); } -if($size_y > 300){ - $size_x = (integer)($size_x*300/$size_y); - $size_y = 300; +if(!isset($user['y']) or $user['y'] < 1) $user['y']=1; +if(!isset($user['x']) or $user['x'] < 1) $user['x']=1; +if($user['x'] > 240){ + $user['y'] = (integer)($user['y']*240/$user['x']); + $user['x'] = 240; } -if($size_x < 160){ - $size_y = (integer)($size_y*160/$size_x); - $size_x = 160; +if($user['y'] > 300){ + $user['x'] = (integer)($user['x']*300/$user['y']); + $user['y'] = 300; } -$page->assign('photo_url', $photo); -$page->assign('size_x', $size_x); -$page->assign('size_y', $size_y); - - -mysql_free_result($result); - -//check si le gars est un referent : -$reqsql = "SELECT 1 FROM mentor WHERE uid = '$user_id' AND expertise <> ''"; -$result = $globals->db->query($reqsql); -if (list($is_referent) = mysql_fetch_row($result)){ - mysql_free_result($result); +if($user['x'] < 160){ + $user['y'] = (integer)($user['y']*160/$user['x']); + $user['x'] = 160; } -$page->assign('is_referent', $is_referent); +$page->assign('photo_url', $photo); +$page->assign_by_ref('x', $user); //recuperation des infos professionnelles -$reqsql = - "SELECT e.entreprise, s.label as secteur , ss.label as sous_secteur , f.fonction_fr as fonction, - e.poste, e.adr1, e.adr2, e.adr3, e.cp, e.ville, - gp.pays, gr.name, e.tel, e.fax - FROM entreprises AS e - LEFT JOIN emploi_secteur AS s ON(e.secteur = s.id) - LEFT JOIN emploi_ss_secteur AS ss ON(e.ss_secteur = ss.id AND e.secteur = ss.secteur) - LEFT JOIN fonctions_def AS f ON(e.fonction = f.id) - LEFT JOIN geoloc_pays AS gp ON (gp.a2 = e.pays) - LEFT JOIN geoloc_region AS gr ON (gr.a2 = e.pays and gr.region = e.region) - WHERE e.uid = $user_id - ORDER BY e.entrid - "; - -$result = $globals->db->query($reqsql); - -$i = 0; -while(list($adr_pro[$i]['entreprise'], $adr_pro[$i]['secteur'], $adr_pro[$i]['ss_secteur'], - $adr_pro[$i]['fonction'], $adr_pro[$i]['poste'], - $adr_pro[$i]['adr1'], $adr_pro[$i]['adr2'], $adr_pro[$i]['adr3'], - $adr_pro[$i]['cp'], $adr_pro[$i]['ville'], - $adr_pro[$i]['pays'], $adr_pro[$i]['region'], - $adr_pro[$i]['tel'], $adr_pro[$i]['fax']) = mysql_fetch_row($result)){ - if(!empty($adr_pro[$i]['entreprise']) || !empty($adr_pro[$i]['secteur']) || - !empty($adr_pro[$i]['fonction']) || !empty($adr_pro[$i]['poste']) || - !empty($adr_pro[$i]['adr1']) || !empty($adr_pro[$i]['adr2']) || !empty($adr_pro[$i]['adr3']) || - !empty($adr_pro[$i]['cp']) || !empty($adr_pro[$i]['ville']) || - !empty($adr_pro[$i]['pays']) || !empty($adr_pro[$i]['tel']) || !empty($adr_pro[$i]['fax']) - ){ - $i++; - } -} -unset($adr_pro[$i]); -$nb_infos_pro = $i; -$page->assign('nb_infos_pro', $nb_infos_pro); -$page->assign_by_ref('adr_pro', $adr_pro); -mysql_free_result($result); +$sql = "SELECT e.entreprise, s.label as secteur , ss.label as sous_secteur , f.fonction_fr as fonction, + e.poste, e.adr1, e.adr2, e.adr3, e.cp, e.ville, + gp.pays, gr.name, e.tel, e.fax + FROM entreprises AS e + LEFT JOIN emploi_secteur AS s ON(e.secteur = s.id) + LEFT JOIN emploi_ss_secteur AS ss ON(e.ss_secteur = ss.id AND e.secteur = ss.secteur) + LEFT JOIN fonctions_def AS f ON(e.fonction = f.id) + LEFT JOIN geoloc_pays AS gp ON (gp.a2 = e.pays) + LEFT JOIN geoloc_region AS gr ON (gr.a2 = e.pays and gr.region = e.region) + WHERE e.uid = {$user['user_id']} + ORDER BY e.entrid"; +$page->mysql_assign($sql, 'adr_pro'); //recuperation des adresses -$reqsql = - "SELECT a.adr1,a.adr2,a.adr3,a.cp,a.ville, - gp.pays,gr.name AS region,a.tel,a.fax, - FIND_IN_SET('active', a.statut), - FIND_IN_SET('res-secondaire', a.statut) - FROM adresses AS a - LEFT JOIN geoloc_pays AS gp ON (gp.a2=a.pays) - LEFT JOIN geoloc_region AS gr ON (gr.a2=a.pays and gr.region=a.region) - WHERE uid=$user_id AND NOT FIND_IN_SET('pro',a.statut) - ORDER BY NOT FIND_IN_SET('active',a.statut), FIND_IN_SET('temporaire',a.statut), FIND_IN_SET('res-secondaire',a.statut)"; - -$result = $globals->db->query($reqsql); - -$nbadr=mysql_num_rows($result); - -for ($i=0;$row = mysql_fetch_row($result);$i++) { - - list( $adr[$i]['adr1'], $adr[$i]['adr2'], $adr[$i]['adr3'], - $adr[$i]['cp'], $adr[$i]['ville'], - $adr[$i]['pays'], $adr[$i]['region'], - $adr[$i]['tel'], $adr[$i]['fax'], - $adr[$i]['active'], $adr[$i]['secondaire']) = $row; - - if ($adr[$i]['active']) - $adr[$i]['title'] = "Mon adresse actuelle :"; - elseif ($adr[$i]['secondaire']) - $adr[$i]['title'] = "Adresse secondaire :"; - else - $adr[$i]['title'] = "Adresse principale :"; - -} -$page->assign_by_ref('adr', $adr); -mysql_free_result($result); - +$sql = "SELECT a.adr1,a.adr2,a.adr3,a.cp,a.ville, + gp.pays,gr.name AS region,a.tel,a.fax, + FIND_IN_SET('active', a.statut) AS active, + FIND_IN_SET('res-secondaire', a.statut) AS secondaire + FROM adresses AS a + LEFT JOIN geoloc_pays AS gp ON (gp.a2=a.pays) + LEFT JOIN geoloc_region AS gr ON (gr.a2=a.pays and gr.region=a.region) + WHERE uid={$user['user_id']} AND NOT FIND_IN_SET('pro',a.statut) + ORDER BY NOT FIND_IN_SET('active',a.statut), FIND_IN_SET('temporaire',a.statut), FIND_IN_SET('res-secondaire',a.statut)"; +$page->mysql_assign($sql, 'adr'); // reformatage binets -$result = $globals->db->query("SELECT text - FROM binets_ins - LEFT JOIN binets_def - ON binets_ins.binet_id = binets_def.id - WHERE user_id = '$user_id'"); -if (list($binets) = mysql_fetch_row($result)){ - while (list($binet) = mysql_fetch_row($result)) - $binets .= ", $binet"; - } -} -mysql_free_result($result); +$sql = "SELECT text + FROM binets_ins + LEFT JOIN binets_def ON binets_ins.binet_id = binets_def.id + WHERE user_id = {$user['user_id']}"; +$res = $globals->db->query($sql); +if (list($binets) = mysql_fetch_row($res)){ + while (list($binet) = mysql_fetch_row($res)) { + $binets .= ", $binet"; + } +} +mysql_free_result($res); $page->assign('binets', $binets); // reformatage Groupes X -$result = $globals->db->query("SELECT text, url - FROM groupesx_ins - LEFT JOIN groupesx_def ON groupesx_ins.gid = groupesx_def.id - WHERE guid = '$user_id'"); -$gxs = ""; -while (list($gxt,$gxu) = mysql_fetch_row($result)) { - if ($gxs) $gxs .= ", "; - if ($gxu) $gxs .= ""; - $gxs .= $gxt; - if ($gxu) $gxs .= ""; +$res = $globals->db->query("SELECT text, url + FROM groupesx_ins + LEFT JOIN groupesx_def ON groupesx_ins.gid = groupesx_def.id + WHERE guid = '{$user['user_id']}'"); +$gxs = Array(); +while (list($gxt,$gxu) = mysql_fetch_row($res)) { + if ($gxu) { + $gxs[] = "$gxt"; + } else { + $gxs[] = $gxt; + } } -mysql_free_result($result); -$page->assign('groupes', $gxs); +mysql_free_result($res); +$page->assign('groupes', join(', ', $gxs)); // reformatage appli -$result = $globals->db->query("SELECT applis_def.text, applis_def.url, applis_ins.type - FROM applis_ins - INNER JOIN applis_def ON applis_def.id = applis_ins.aid - WHERE uid='$user_id' - ORDER by ordre"); -if (list($rapp_txt, $rapp_url, $rapp_type) = mysql_fetch_row($result)) { - $applis = applis_fmt($rapp_type, $rapp_txt, $rapp_url); - while (list($rapp_txt, $rapp_url, $rapp_type) = mysql_fetch_row($result)) { - $applis .=", "; - $applis .= applis_fmt($rapp_type, $rapp_txt, $rapp_url); - } -} else { - $applis = ''; +$res = $globals->db->query("SELECT applis_def.text, applis_def.url, applis_ins.type + FROM applis_ins + INNER JOIN applis_def ON applis_def.id = applis_ins.aid + WHERE uid='{$user['user_id']}' + ORDER BY ordre"); +if (list($rapp_txt, $rapp_url, $rapp_type) = mysql_fetch_row($res)) { + $applis = applis_fmt($rapp_type, $rapp_txt, $rapp_url); + while (list($rapp_txt, $rapp_url, $rapp_type) = mysql_fetch_row($res)) { + $applis .=", "; + $applis .= applis_fmt($rapp_type, $rapp_txt, $rapp_url); + } + $page->assign('applis', $applis); } -mysql_free_result($result); -$page->assign('applis', $applis); +mysql_free_result($res); $page->run(); diff --git a/templates/fiche.tpl b/templates/fiche.tpl index 5ad5025..0539360 100644 --- a/templates/fiche.tpl +++ b/templates/fiche.tpl @@ -31,65 +31,65 @@ function chgMainWinLoc( strPage ) {
- {if $sexe}•{/if} - {$prenom} {if $epouse eq ""}{$nom}{else}{$epouse} ({$nom}){/if}  - + {if $x.sexe}•{/if} + {$x.prenom} {if $x.epouse eq ""}{$x.nom}{else}{$x.epouse} ({$x.nom}){/if}  + Afficher la carte de visite - {if !$is_contact} - + {if !$x.is_contact} + Ajouter à mes contacts {else} - + Retirer de mes contacts {/if} {perms level=admin} - + admin {/perms}
Fiche mise à jour
- le {$date|date_format:"%d %b. %Y"} + le {$x.date|date_format:"%d %b. %Y"}
- {if $mobile}Mobile : {$mobile}
{/if} + {if $x.mobile}Mobile : {$x.mobile}
{/if}
- {if $iso3166} - {$nationalite}  + {if $x.iso3166} + {$x.nationalite}  {/if} - X {$promo}{if $applis} - Formation : {$applis|smarty:nodefaults}{/if} - {if $is_referent} - [Ma fiche référent] + X {$x.promo}{if $applis} - Formation : {$applis|smarty:nodefaults}{/if} + {if $x.is_referent} + [Ma fiche référent] {/if}
- Photo de {$forlife} - {if $section}Section : {$section}
{/if} + Photo de {$x.forlife} + {if $x.section}Section : {$x.section}
{/if} {if $binets}Binet(s) : {$binets}
{/if} {if $groupes}Groupe(s) X : {$groupes|smarty:nodefaults}
{/if} - {if $web}Site Web : {$web}{/if} - {if $libre}
Commentaires :
{$libre|nl2br}{/if} + {if $x.web}Site Web : {$x.web}{/if} + {if $x.libre}
Commentaires :
{$x.libre|nl2br}{/if} {if $adr|@count > 0} @@ -98,7 +98,15 @@ function chgMainWinLoc( strPage ) {

Contact :

{foreach from=$adr item="address" key="i"}
-
{$address.title}
+
+ {if $address.active} + Mon adresse actuelle : + {elseif $address.secondaire} + Adresse secondaire : + {else} + Adresse principale : + {/if} +
{if $address.adr1 || $address.pays || $address.ville}
{if $address.adr1}{$address.adr1}
{/if} @@ -189,11 +197,11 @@ function chgMainWinLoc( strPage ) { {/if} - {if $cv} + {if $x.cv}

Curriculum Vitae :

- {$cv|nl2br} + {$x.cv|nl2br} {/if} -- 2.1.4