From 8b10988d6ec74065073ef8ad3165f620cb2c45a7 Mon Sep 17 00:00:00 2001 From: x2001corpet Date: Tue, 13 Jun 2006 16:41:16 +0000 Subject: [PATCH] prise en compte des pub ax ou private dans la fonction get_user_detail git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@311 839d8a87-29fc-0310-9880-83ba4fa771e5 --- ChangeLog | 3 + htdocs/fiche.php | 89 +++----------------- include/user.func.inc.php | 201 ++++++++++++++++++++++++++++++++-------------- templates/fiche.tpl | 2 +- templates/profil.tpl | 4 +- 5 files changed, 159 insertions(+), 140 deletions(-) diff --git a/ChangeLog b/ChangeLog index fe6587c..139338d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,9 @@ New : * Geoloc : - Dynamic maps using geodesix plugin. -Car + * Profile : + - See fiche send to AX. -Car + * Xnet : - Use wiki from Xnet. -Car - Use wiki for group pages. -Car diff --git a/htdocs/fiche.php b/htdocs/fiche.php index c37e37b..a2f24cf 100644 --- a/htdocs/fiche.php +++ b/htdocs/fiche.php @@ -21,7 +21,13 @@ require_once("xorg.inc.php"); -new_simple_page('fiche.tpl', AUTH_PUBLIC); + +// manage the public fiche or ax fiche +$view = 'private'; +if (!logged() || Env::get('view') == 'public') $view = 'public'; +if (logged() && Env::get('view') == 'ax') $view = 'ax'; + +new_simple_page('fiche.tpl', ($view == 'public')?AUTH_PUBLIC:AUTH_COOKIE); require_once('user.func.inc.php'); if (!Env::has('user') && !Env::has('mat')) { @@ -48,7 +54,7 @@ if (Env::has('mat')) { } $new = Env::get('modif') == 'new'; -$user = get_user_details($login, Session::getInt('uid')); +$user = get_user_details($login, Session::getInt('uid'), $view); $title = $user['prenom'] . ' ' . empty($user['nom_usage']) ? $user['nom'] : $user['nom_usage']; $page->assign('xorg_title', $title); @@ -74,83 +80,12 @@ if($user['x'] < 160){ $user['x'] = 160; } -// manage the public fiche -$page->assign('logged', logged() && !Env::has('public')); -if (!logged() || Env::has('public')) { - // hide the orange status - $user['promo_sortie'] = $user['promo'] + 3; - if ($user['mobile_pub'] != 'public') $user['mobile'] = ''; - if ($user['web_pub'] != 'public') $user['web'] = ''; - if ($user['freetext_pub'] != 'public') $user['freetext'] = ''; - foreach ($user['adr'] as $i=>$adr) { - foreach ($adr['tels'] as $j=>$tel) { - if ($tel['tel_pub'] != 'public') - unset($user['adr'][$i]['tels'][$j]); - } - if (($adr['pub'] != 'public') && (count($user['adr'][$i]['tels']) == 0)) - unset($user['adr'][$i]); - elseif ($adr['pub'] != 'public') { - $user['adr'][$i]['adr1'] = ''; - $user['adr'][$i]['adr2'] = ''; - $user['adr'][$i]['adr3'] = ''; - $user['adr'][$i]['city'] = ''; - $user['adr'][$i]['postcode'] = ''; - $user['adr'][$i]['region'] = ''; - $user['adr'][$i]['regiontxt'] = ''; - $user['adr'][$i]['country'] = '00'; - $user['adr'][$i]['countrytxt'] = ''; - } - } - foreach ($user['adr_pro'] as $i=>$adr) { - if ($adr['pub'] != 'public' && $adr['tel_pub'] != 'public' && $adr['adr_pub'] != 'public' && $adr['email_pub'] != 'public') - unset($user['adr_pro'][$i]); - else { - if ($adr['adr_pub'] != 'public') { - $user['adr_pro'][$i]['adr1'] = ''; - $user['adr_pro'][$i]['adr2'] = ''; - $user['adr_pro'][$i]['adr3'] = ''; - $user['adr_pro'][$i]['city'] = ''; - $user['adr_pro'][$i]['postcode'] = ''; - $user['adr_pro'][$i]['region'] = ''; - $user['adr_pro'][$i]['country'] = '00'; - $user['adr_pro'][$i]['countrytxt'] = ''; - } - if ($adr['pub'] != 'public') { - $user['adr_pro'][$i]['entreprise'] = ''; - $user['adr_pro'][$i]['secteur'] = ''; - $user['adr_pro'][$i]['fonction'] = ''; - $user['adr_pro'][$i]['poste'] = ''; - } - if ($adr['tel_pub'] != 'public') { - $user['adr_pro'][$i]['tel'] = ''; - $user['adr_pro'][$i]['fax'] = ''; - $user['adr_pro'][$i]['mobile'] = ''; - } - if ($adr['email_pub'] != 'public') { - $user['adr_pro'][$i]['email'] = ''; - } - } - } - if ($user['medals_pub'] != 'public') { - unset($user['medals']); - } - if ($user['photo_pub'] != 'public') { - $photo = ""; - } -} -foreach($user['adr_pro'] as $i=>$pro) { - if ($pro['entreprise'] == '' && $pro['fonction'] == '' - && $pro['secteur'] == '' && $pro['poste'] == '' - && $pro['adr1'] == '' && $pro['adr2'] == '' && $pro['adr3'] == '' - && $pro['postcode'] == '' && $pro['city'] == '' && $pro['country'] == '00' - && $pro['tel'] == '' && $pro['fax'] == '' && $pro['mobile'] == '' - && $pro['email'] == '') - unset($user['adr_pro'][$i]); +$page->assign('logged', has_user_right('private', $view)); +if (!has_user_right($user['photo_pub'], $view)) { + $photo = ""; } -if (count($user['adr_pro']) == 0) unset($user['adr_pro']); -if (count($user['adr']) == 0) unset($user['adr']); -$page->assign_by_ref('x', $user); +$page->assign_by_ref('x', $user); $page->assign('photo_url', $photo); // alias virtual $res = $globals->xdb->query( diff --git a/include/user.func.inc.php b/include/user.func.inc.php index 8add780..aa38c85 100644 --- a/include/user.func.inc.php +++ b/include/user.func.inc.php @@ -1,6 +1,6 @@ xdb->query($sql, $uid); - return $res->fetchAllAssoc(); + $all_pro = $res->fetchAllAssoc(); + foreach ($all_pro as $i => $pro) { + if (!has_user_right($pro['pub'], $view)) + unset($all_pro[$i]); + else { + if (!has_user_right($pro['adr_pub'], $view)) { + $all_pro[$i]['adr1'] = ''; + $all_pro[$i]['adr2'] = ''; + $all_pro[$i]['adr3'] = ''; + $all_pro[$i]['postcode'] = ''; + $all_pro[$i]['city'] = ''; + $all_pro[$i]['countrytxt'] = ''; + $all_pro[$i]['region'] = ''; + } + if (!has_user_right($pro['tel_pub'], $view)) { + $all_pro[$i]['tel'] = ''; + $all_pro[$i]['fax'] = ''; + $all_pro[$i]['mobile'] = ''; + } + if (!has_user_right($pro['email_pub'], $view)) { + $all_pro[$i]['email'] = ''; + } + if ($all_pro[$i]['adr1'] == '' && + $all_pro[$i]['adr2'] == '' && + $all_pro[$i]['adr3'] == '' && + $all_pro[$i]['postcode'] == '' && + $all_pro[$i]['city'] == '' && + $all_pro[$i]['countrytxt'] == '' && + $all_pro[$i]['region'] == '' && + $all_pro[$i]['entreprise'] == '' && + $all_pro[$i]['fonction'] == '' && + $all_pro[$i]['secteur'] == '' && + $all_pro[$i]['poste'] == '' && + $all_pro[$i]['tel'] == '' && + $all_pro[$i]['fax'] == '' && + $all_pro[$i]['mobile'] == '' && + $all_pro[$i]['email'] == '') + unset($all_pro[$i]); + } + } + if (!count($all_pro)) return false; + return $all_pro; } // }}} +function get_user_details_adr($uid, $view = 'private') { + global $globals; + $sql = "SELECT a.adrid, a.adr1,a.adr2,a.adr3,a.postcode,a.city, + gp.pays AS countrytxt,a.region, a.regiontxt, + FIND_IN_SET('active', a.statut) AS active, a.adrid, + FIND_IN_SET('res-secondaire', a.statut) AS secondaire, + a.pub, gp.display + FROM adresses AS a + LEFT JOIN geoloc_pays AS gp ON (gp.a2=a.country) + WHERE uid= {?} 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)"; + $res = $globals->xdb->query($sql, $uid); + $all_adr = $res->fetchAllAssoc(); + $adrid_index = array(); + foreach ($all_adr as $i => $adr) { + if (!has_user_right($adr['pub'], $view)) + unset($all_adr[$i]); + else + $adrid_index[$adr['adrid']] = $i; + } + + $sql = "SELECT t.adrid, t.tel_pub, t.tel_type, t.tel, t.telid + FROM tels AS t + INNER JOIN adresses AS a ON (a.uid = t.uid) AND (a.adrid = t.adrid) + WHERE t.uid = {?} AND NOT FIND_IN_SET('pro',a.statut) + ORDER BY t.adrid, t.tel_type DESC, t.telid"; + $restel = $globals->xdb->iterator($sql, $uid); + while ($nexttel = $restel->next()) { + if (has_user_right($nexttel['tel_pub'], $view)) { + $adrid = $nexttel['adrid']; + unset($nexttel['adrid']); + if (isset($adrid_index[$adrid])) { + if (!isset($all_adr[$adrid_index[$adrid]]['tels'])) + $all_adr[$adrid_index[$adrid]]['tels'] = array($nexttel); + else + $all_adr[$adrid_index[$adrid]]['tels'][] = $nexttel; + } + } + } + return $all_adr; +} // {{{ function get_user_details() -function &get_user_details($login, $from_uid = '') +function &get_user_details($login, $from_uid = '', $view = 'private') { global $globals; $reqsql = "SELECT u.user_id, u.promo, u.promo_sortie, u.prenom, u.nom, u.nom_usage, u.date, u.cv, @@ -201,57 +294,43 @@ function &get_user_details($login, $from_uid = '') $res = $globals->xdb->query($reqsql, $from_uid, $login); $user = $res->fetchOneAssoc(); $uid = $user['user_id']; - - $user['adr_pro'] = get_user_details_pro($uid); - - $sql = "SELECT a.adrid, a.adr1,a.adr2,a.adr3,a.postcode,a.city, - gp.pays AS countrytxt,a.region, a.regiontxt, - FIND_IN_SET('active', a.statut) AS active, a.adrid, - FIND_IN_SET('res-secondaire', a.statut) AS secondaire, - a.pub, gp.display - FROM adresses AS a - LEFT JOIN geoloc_pays AS gp ON (gp.a2=a.country) - WHERE uid= {?} 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)"; - $res = $globals->xdb->query($sql, $uid); - $user['adr'] = $res->fetchAllAssoc(); - $adrid_index = array(); - foreach ($user['adr'] as $i => $adr) - $adrid_index[$adr['adrid']] = $i; + // hide orange status, cv, nickname, section + if (!has_user_right('private', $view)) { + $user['promo_sortie'] = $user['promo'] + 3; + $user['cv'] = ''; + $user['nickname'] = ''; + $user['section'] = ''; + } + // hide mobile + if (!has_user_right($user['mobile_pub'], $view)) $user['mobile'] = ''; + // hide web + if (!has_user_right($user['web_pub'], $view)) $user['web'] = ''; + // hide freetext + if (!has_user_right($user['freetext_pub'], $view)) $user['freetext'] = ''; + + $user['adr_pro'] = get_user_details_pro($uid, $view); + $user['adr'] = get_user_details_adr($uid, $view); + + if (has_user_right('private', $view)) { + $sql = "SELECT text + FROM binets_ins + LEFT JOIN binets_def ON binets_ins.binet_id = binets_def.id + WHERE user_id = {?}"; + $res = $globals->xdb->query($sql, $uid); + $user['binets'] = $res->fetchColumn(); + $user['binets_join'] = join(', ', $user['binets']); - $sql = "SELECT t.adrid, t.tel_pub, t.tel_type, t.tel - FROM tels AS t - INNER JOIN adresses AS a ON (a.uid = t.uid) AND (a.adrid = t.adrid) - WHERE t.uid = {?} AND NOT FIND_IN_SET('pro',a.statut) - ORDER BY t.adrid, t.tel_type DESC, t.telid"; - $restel = $globals->xdb->iterator($sql, $uid); - while ($nexttel = $restel->next()) { - $adrid = $nexttel['adrid']; - unset($nexttel['adrid']); - if (!isset($user['adr'][$adrid_index[$adrid]]['tels'])) - $user['adr'][$adrid_index[$adrid]]['tels'] = array($nexttel); - else - $user['adr'][$adrid_index[$adrid]]['tels'][] = $nexttel; + $res = $globals->xdb->iterRow("SELECT text, url + FROM groupesx_ins + LEFT JOIN groupesx_def ON groupesx_ins.gid = groupesx_def.id + WHERE guid = {?}", $uid); + $user['gpxs'] = Array(); + while (list($gxt, $gxu) = $res->next()) { + $user['gpxs'][] = $gxu ? "$gxt" : $gxt; + } + $user['gpxs_join'] = join(', ', $user['gpxs']); } - $sql = "SELECT text - FROM binets_ins - LEFT JOIN binets_def ON binets_ins.binet_id = binets_def.id - WHERE user_id = {?}"; - $res = $globals->xdb->query($sql, $uid); - $user['binets'] = $res->fetchColumn(); - $user['binets_join'] = join(', ', $user['binets']); - - $res = $globals->xdb->iterRow("SELECT text, url - FROM groupesx_ins - LEFT JOIN groupesx_def ON groupesx_ins.gid = groupesx_def.id - WHERE guid = {?}", $uid); - $user['gpxs'] = Array(); - while (list($gxt, $gxu) = $res->next()) { - $user['gpxs'][] = $gxu ? "$gxt" : $gxt; - } - $user['gpxs_join'] = join(', ', $user['gpxs']); - $res = $globals->xdb->iterRow("SELECT applis_def.text, applis_def.url, applis_ins.type FROM applis_ins INNER JOIN applis_def ON applis_def.id = applis_ins.aid @@ -265,14 +344,16 @@ function &get_user_details($login, $from_uid = '') } $user['applis_join'] = join(', ', $user['applis_fmt']); - $res = $globals->xdb->iterator("SELECT m.id, m.text AS medal, m.type, m.img, s.gid, g.text AS grade - FROM profile_medals_sub AS s - INNER JOIN profile_medals AS m ON ( s.mid = m.id ) - LEFT JOIN profile_medals_grades AS g ON ( s.mid = g.mid AND s.gid = g.gid ) - WHERE s.uid = {?}", $uid); - $user['medals'] = Array(); - while ($tmp = $res->next()) { - $user['medals'][] = $tmp; + if (has_user_right($user['medals_pub'], $view)) { + $res = $globals->xdb->iterator("SELECT m.id, m.text AS medal, m.type, m.img, s.gid, g.text AS grade + FROM profile_medals_sub AS s + INNER JOIN profile_medals AS m ON ( s.mid = m.id ) + LEFT JOIN profile_medals_grades AS g ON ( s.mid = g.mid AND s.gid = g.gid ) + WHERE s.uid = {?}", $uid); + $user['medals'] = Array(); + while ($tmp = $res->next()) { + $user['medals'][] = $tmp; + } } return $user; diff --git a/templates/fiche.tpl b/templates/fiche.tpl index f1b2994..fa8f3e8 100644 --- a/templates/fiche.tpl +++ b/templates/fiche.tpl @@ -32,7 +32,7 @@ function chgMainWinLoc( strPage ) { {/literal} -{if $x.forlife eq $smarty.session.forlife} +{if $logged and $x.forlife eq $smarty.session.forlife} [Modifier ma fiche] {/if} diff --git a/templates/profil.tpl b/templates/profil.tpl index 7558397..2ef8291 100644 --- a/templates/profil.tpl +++ b/templates/profil.tpl @@ -1,6 +1,6 @@ {**************************************************************************} {* *} -{* Copyright (C) 2003-2004 Polytechnique.org *} +{* Copyright (C) 2003-2006 Polytechnique.org *} {* http://opensource.polytechnique.org/ *} {* *} {* This program is free software; you can redistribute it and/or modify *} @@ -31,7 +31,7 @@

Tu peux consulter l'état actuel de ta fiche telle qu'elle apparaîtra pour un camarade, -ou telle qu'elle apparaîtra à tout le monde.

+ou telle qu'elle apparaîtra dans l'annuaire de l'AX ou à tout le monde.

-- 2.1.4