From: Pierre Habouzit (MadCoder Date: Mon, 13 Dec 2004 17:54:40 +0000 (+0000) Subject: the promised refactor. obvious, isn't it ? X-Git-Tag: xorg/old~657 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=c7a9bfcfbe4e66bc4fc24195e81be9d093ec8289;p=platal.git the promised refactor. obvious, isn't it ? git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-91 --- diff --git a/htdocs/vcard.php b/htdocs/vcard.php index 121a8fc..e9bd157 100644 --- a/htdocs/vcard.php +++ b/htdocs/vcard.php @@ -22,6 +22,7 @@ require_once("xorg.inc.php"); new_nonhtml_page('vcard.tpl', AUTH_COOKIE); require_once("xorg.misc.inc.php"); +require_once("user.func.inc.php"); function format_adr($params, &$smarty) { @@ -36,60 +37,9 @@ function format_adr($params, &$smarty) $page->register_modifier('qp_enc', 'quoted_printable_encode'); $page->register_function('format_adr', 'format_adr'); -if(preg_match('/^\d*$/',$_REQUEST['x'])) { - $myquery = "SELECT prenom, nom, epouse, mobile, web, libre, promo, user_id, date, a.alias AS forlife - FROM auth_user_md5 AS u - INNER JOIN aliases AS a ON (u.user_id=a.id AND a.type='a_vie') - WHERE a.id='{$_REQUEST['x']}'"; -} else { - $myquery = "SELECT prenom, nom, epouse, mobile, web, libre, promo, user_id, date, a.alias AS forlife - 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 b ON (u.user_id=b.id AND a.type!='homonyme') - WHERE b.alias='{$_REQUEST['x']}'"; -} - -$result=$globals->db->query($myquery); -if (mysql_num_rows($result)!=1) { exit; } - -$vcard = mysql_fetch_assoc($result); -$page->assign_by_ref('vcard', $vcard); -mysql_free_result($result); - -$page->mysql_assign("SELECT alias FROM aliases WHERE id={$vcard['user_id']} AND FIND_IN_SET('bestalias',flags)",'best'); - -$adr = $globals->db->query( - "SELECT statut,adr1,adr2,adr3,cp,ville,gp.pays,gr.name,tel,fax, - FIND_IN_SET('courrier', a.statut) AS courrier - FROM adresses as a - LEFT JOIN geoloc_pays AS gp ON(a.pays = gp.a2) - LEFT JOIN geoloc_region AS gr - ON(a.pays = gr.a2 AND a.region = gr.region) - WHERE uid = {$vcard['user_id']} - ORDER BY FIND_IN_SET('active', a.statut), - NOT FIND_IN_SET('res-secondaire', a.statut)" -); -$home = Array(); -while($home[] = mysql_fetch_assoc($adr)); -array_pop($home); -mysql_free_result($adr); -$page->assign_by_ref('home', $home); - - -$adr = $globals->db->query( - "SELECT adr1,adr2,adr3,cp,ville,gp.pays,gr.name,tel,fax,poste,entreprise,f.fonction_fr as fonction - FROM entreprises as e - LEFT JOIN fonctions_def AS f ON(e.fonction = f.id) - LEFT JOIN geoloc_pays AS gp ON(e.pays = gp.a2) - LEFT JOIN geoloc_region AS gr - ON(e.pays = gr.a2 AND e.region = gr.region) - WHERE uid = {$vcard['user_id']}" -); -if(mysql_num_rows($adr)) - $work = mysql_fetch_assoc($adr); -mysql_free_result($adr); -$page->assign_by_ref('work', $work); - +$login = get_user_forlife($_REQUEST['x']); +$user = get_user_details($login); +$page->assign_by_ref('vcard', $user); header("Pragma: "); header("Cache-Control: "); diff --git a/include/user.func.inc.php b/include/user.func.inc.php index b01454e..68abbe2 100644 --- a/include/user.func.inc.php +++ b/include/user.func.inc.php @@ -164,7 +164,7 @@ function get_user_forlife($data) { // }}} // {{{ function get_user_details() -function &get_user_details($login, $from_uid) +function &get_user_details($login, $from_uid = '') { global $globals; $reqsql = "SELECT u.prenom, u.nom, u.epouse, diff --git a/templates/vcard.tpl b/templates/vcard.tpl index 2cd78e9..3dcf446 100644 --- a/templates/vcard.tpl +++ b/templates/vcard.tpl @@ -25,37 +25,39 @@ FN;ENCODING=QUOTED-PRINTABLE:{"`$vcard.prenom` `$vcard.epouse` (`$vcard.nom`)"|q FN;ENCODING=QUOTED-PRINTABLE:{"`$vcard.prenom` `$vcard.nom`"|qp_enc} {/if} N;ENCODING=QUOTED-PRINTABLE:{$vcard.nom|qp_enc};{$vcard.prenom|qp_enc};{$vcard.epouse|qp_enc};; -EMAIL;TYPE=internet:{$best[0].alias}@polytechnique.org +EMAIL;TYPE=internet:{$vcard.bestalias}@polytechnique.org +{if $vcard.bestalias neq $vcard.forlife} EMAIL;TYPE=internet:{$vcard.forlife}@polytechnique.org +{/if} {if $vcard.mobile} TEL;TYPE=cell;ENCODING=QUOTED-PRINTABLE:{$vcard.mobile|qp_enc} {/if} -{if $work} -{if $work.entreprise} -ORG;ENCODING=QUOTED-PRINTABLE:{$work.entreprise|qp_enc} +{if $vcard.adr_pro} +{if $vcard.adr_pro[0].entreprise} +ORG;ENCODING=QUOTED-PRINTABLE:{$vcard.adr_pro[0].entreprise|qp_enc} {/if} -{if $work.poste} -TITLE;ENCODING=QUOTED-PRINTABLE:{$vcard.poste|qp_enc} +{if $vcard.adr_pro[0].poste} +TITLE;ENCODING=QUOTED-PRINTABLE:{$vcard.adr_pro[0].poste|qp_enc} {/if} -{if $work.fonction} -ROLE;ENCODING=QUOTED-PRINTABLE:{$work.fonction|qp_enc} +{if $vcard.adr_pro[0].fonction} +ROLE;ENCODING=QUOTED-PRINTABLE:{$vcard.adr_pro[0].fonction|qp_enc} {/if} -{if $work.tel} -TEL;TYPE=work;ENCODING=QUOTED-PRINTABLE:{$work.tel|qp_enc} +{if $vcard.adr_pro[0].tel} +TEL;TYPE=work;ENCODING=QUOTED-PRINTABLE:{$vcard.adr_pro[0].tel|qp_enc} {/if} -{if $work.fax} -FAX;TYPE=work;ENCODING=QUOTED-PRINTABLE:{$work.fax|qp_enc} +{if $vcard.adr_pro[0].fax} +FAX;TYPE=work;ENCODING=QUOTED-PRINTABLE:{$vcard.adr_pro[0].fax|qp_enc} {/if} -ADR;TYPE=work;ENCODING=QUOTED-PRINTABLE:{format_adr adr=$work} +ADR;TYPE=work;ENCODING=QUOTED-PRINTABLE:{format_adr adr=$vcard.adr_pro[0]} {/if} -{foreach item=adr from=$home} +{foreach item=adr from=$vcard.adr} +ADR;TYPE=home{if $adr.courier},postal{/if};ENCODING=QUOTED-PRINTABLE:{format_adr adr=$adr} {if $adr.tel} TEL;TYPE=home;ENCODING=QUOTED-PRINTABLE:{$adr.tel|qp_enc} {/if} {if $adr.fax} FAX;TYPE=home;ENCODING=QUOTED-PRINTABLE:{$adr.fax|qp_enc} {/if} -ADR;TYPE=home{if $adr.courier},postal{/if};ENCODING=QUOTED-PRINTABLE:{format_adr adr=$adr} {/foreach} {if $vcard.web} URL;ENCODING=QUOTED-PRINTABLE:{$vcard.web|qp_enc}