From 66756018a500e8f65338f3128b090e9146e4adaa Mon Sep 17 00:00:00 2001 From: x2000habouzit Date: Tue, 31 Aug 2004 19:48:46 +0000 Subject: [PATCH] lots of simplifications. NOTE : registering a smarty plugin is not very efficient. it should be used only in case of sharing the plugin. else, use foreach !!! --- htdocs/mescontacts_ldif.php | 4 +- htdocs/referent.php | 8 +- htdocs/vcard.php | 3 +- include/profil/assign_skill.inc.php | 64 +--------- include/profil/get_skill.inc.php | 4 +- include/tabs.inc.php | 84 ++++++------- include/valid_ml.inc.php | 186 ----------------------------- include/validations.inc.php | 5 +- templates/profil/skill.tpl | 227 +++++++++++++++++------------------- 9 files changed, 165 insertions(+), 420 deletions(-) delete mode 100644 include/valid_ml.inc.php diff --git a/htdocs/mescontacts_ldif.php b/htdocs/mescontacts_ldif.php index 52ea298..dbb1ae6 100644 --- a/htdocs/mescontacts_ldif.php +++ b/htdocs/mescontacts_ldif.php @@ -18,7 +18,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: mescontacts_ldif.php,v 1.7 2004-08-31 10:03:28 x2000habouzit Exp $ + $Id: mescontacts_ldif.php,v 1.8 2004-08-31 19:48:46 x2000habouzit Exp $ ***************************************************************************/ require("auto.prepend.inc.php"); @@ -74,7 +74,7 @@ $req = $globals->db->query( LEFT JOIN geoloc_region AS gr ON (a.pays = gr.a2 AND a.region = gr.region) WHERE c.uid = {$_SESSION['uid']} ORDER BY c.contact"); -echo mysql_error(); + while($line = mysql_fetch_assoc($req)) $contacts[$line['id']]['home'] = ensure_adr($line); mysql_free_result($req); diff --git a/htdocs/referent.php b/htdocs/referent.php index 1839587..9a0bc63 100644 --- a/htdocs/referent.php +++ b/htdocs/referent.php @@ -18,7 +18,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: referent.php,v 1.5 2004-08-31 13:59:42 x2000habouzit Exp $ + $Id: referent.php,v 1.6 2004-08-31 19:48:46 x2000habouzit Exp $ ***************************************************************************/ @@ -120,9 +120,9 @@ if(isset($_REQUEST['Chercher'])){ $sql = "SELECT $champ_select $clause_from $clause_where GROUP BY uid ORDER BY RAND({$_SESSION['uid']})"; - //echo "requete : ".htmlentities($sql)."
"; + $res = $globals->db->query($sql); - // echo mysql_error()."
"; + if(mysql_num_rows($res) == 0){ $page->assign('recherche_trop_large',true); mysql_free_result($res); @@ -134,7 +134,7 @@ if(isset($_REQUEST['Chercher'])){ else{ $page_courante = 1; } - //echo "nombre de pages : $nb_pages
"; + $current_uid = 0; $nb_resultats = 0; $page->assign('resultats',true); diff --git a/htdocs/vcard.php b/htdocs/vcard.php index c3a46be..72613c3 100644 --- a/htdocs/vcard.php +++ b/htdocs/vcard.php @@ -18,7 +18,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: vcard.php,v 1.7 2004-08-31 10:03:29 x2000habouzit Exp $ + $Id: vcard.php,v 1.8 2004-08-31 19:48:46 x2000habouzit Exp $ ***************************************************************************/ require("auto.prepend.inc.php"); @@ -83,7 +83,6 @@ $myquery = WHERE username='{$_REQUEST['x']}'"; $result=$globals->db->query($myquery); if (mysql_num_rows($result)!=1) { - echo 'erreur'; exit; } $vcard = mysql_fetch_assoc($result); diff --git a/include/profil/assign_skill.inc.php b/include/profil/assign_skill.inc.php index 2360951..d16c37b 100644 --- a/include/profil/assign_skill.inc.php +++ b/include/profil/assign_skill.inc.php @@ -18,67 +18,9 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: assign_skill.inc.php,v 1.1 2004-08-31 15:12:37 x2000habouzit Exp $ + $Id: assign_skill.inc.php,v 1.2 2004-08-31 19:48:46 x2000habouzit Exp $ ***************************************************************************/ - -function select_comppros_name($cproname){ - global $comppros_def, $comppros_title; - reset($comppros_def); - echo ""; - foreach( $comppros_def as $cid => $cname){ - if($comppros_title[$cid] == 1){ - //c'est un titre de categorie - echo ""; - } - else{ - echo ""; - } - } -} -function _select_comppros_name($params){ - select_comppros_name($params['competence']); -} -$page->register_function('select_competence', '_select_comppros_name'); - -function select_langue_name($lgname){ - global $langues_def; - reset($langues_def); - echo ""; - foreach( $langues_def as $lid => $lname){ - echo ""; - } -} -function _select_langue_name($params){ - select_langue_name($params['langue']); -} -$page->register_function('select_langue', '_select_langue_name'); - -function select_langue_level($llevel){ - global $langues_levels; - reset($langues_levels); - echo ""; - foreach( $langues_levels as $level => $levelname){ - echo ""; - } -} -function _select_langue_level($params){ - select_langue_level($params['level']); -} -$page->register_function('select_langue_level', '_select_langue_level'); - -function select_comppros_level(){ - global $comppros_levels; - reset($comppros_levels); - foreach( $comppros_levels as $level => $levelname){ - echo ""; - } -} -function _select_cppro_level($params){ - select_comppros_level($params['level']); -} -$page->register_function('select_competence_level', '_select_cppro_level'); - $page->assign('nb_lg_max', $nb_lg_max); $page->assign('nb_cpro_max', $nb_cpro_max); $page->assign('nb_lg', $nb_lg); @@ -89,9 +31,9 @@ $page->assign('nb_cpro', $nb_cpro); $page->assign_by_ref('cpro_id', $cpro_id); $page->assign_by_ref('cpro_name', $cpro_name); $page->assign_by_ref('cpro_level', $cpro_level); -$page->assign_by_ref('langues_level',$langues_level); +$page->assign_by_ref('langues_levels',$langues_levels); $page->assign_by_ref('langues_def',$langues_def); -$page->assign_by_ref('comppros_level',$comppros_level); +$page->assign_by_ref('comppros_levels',$comppros_levels); $page->assign_by_ref('comppros_def',$comppros_def); $page->assign_by_ref('comppros_title',$comppros_title); diff --git a/include/profil/get_skill.inc.php b/include/profil/get_skill.inc.php index 0a8802c..cec60ab 100644 --- a/include/profil/get_skill.inc.php +++ b/include/profil/get_skill.inc.php @@ -18,7 +18,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: get_skill.inc.php,v 1.1 2004-08-31 15:12:37 x2000habouzit Exp $ + $Id: get_skill.inc.php,v 1.2 2004-08-31 19:48:46 x2000habouzit Exp $ ***************************************************************************/ @@ -74,7 +74,6 @@ $langues_levels = Array( ); $res = $globals->db->query("SELECT id, langue_fr FROM langues_def"); -//echo mysql_error(); while(list($tmp_lid, $tmp_lg_fr) = mysql_fetch_row($res)){ $langues_def[$tmp_lid] = $tmp_lg_fr; @@ -87,7 +86,6 @@ $comppros_levels = Array( ); $res = $globals->db->query("SELECT id, text_fr, FIND_IN_SET('titre',flags) FROM competences_def"); -//echo mysql_error(); while(list($tmp_id, $tmp_text_fr, $tmp_title) = mysql_fetch_row($res)){ $comppros_def[$tmp_id] = $tmp_text_fr; diff --git a/include/tabs.inc.php b/include/tabs.inc.php index 6aedaee..c460b95 100644 --- a/include/tabs.inc.php +++ b/include/tabs.inc.php @@ -18,77 +18,77 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: tabs.inc.php,v 1.4 2004-08-31 11:16:48 x2000habouzit Exp $ + $Id: tabs.inc.php,v 1.5 2004-08-31 19:48:46 x2000habouzit Exp $ ***************************************************************************/ $tabname_array = Array( - "general" => "Informations
générales", - "adresses" => "Adresses
personnelles", - "poly" => "Informations
polytechniciennes", - "emploi" => "Informations
professionnelles", - "skill" => "Compétences
diverses", - "mentor" => "Mentoring" - ); - + "general" => "Informations
générales", + "adresses" => "Adresses
personnelles", + "poly" => "Informations
polytechniciennes", + "emploi" => "Informations
professionnelles", + "skill" => "Compétences
diverses", + "mentor" => "Mentoring" +); + $opened_tab = 'general'; $page->assign("onglets",$tabname_array); $page->assign("onglet_last",'mentor'); function get_last_tab(){ - end($GLOBALS['tabname_array']); - return key($GLOBALS['tabname_array']); + end($GLOBALS['tabname_array']); + return key($GLOBALS['tabname_array']); } function get_next_tab($tabname){ - global $tabname_array; - reset($tabname_array); - $marker = false; - while(list($current_tab,$current_tab_desc) = each($tabname_array)){ - if($current_tab == $tabname){ - $res = key($tabname_array);// each() sets key to the next element - if($res != NULL)// if it was the last call of each(), key == NULL => we return the first key - return $res; - else{ - reset($tabname_array); - return key($tabname_array); - } - } - } - // We should not arrive to this point, but at least, we return the first key - reset($tabname_array); - return key($tabname_array); + global $tabname_array; + reset($tabname_array); + $marker = false; + while(list($current_tab,$current_tab_desc) = each($tabname_array)){ + if($current_tab == $tabname){ + $res = key($tabname_array);// each() sets key to the next element + if($res != NULL)// if it was the last call of each(), key == NULL => we return the first key + return $res; + else{ + reset($tabname_array); + return key($tabname_array); + } + } + } + // We should not arrive to this point, but at least, we return the first key + reset($tabname_array); + return key($tabname_array); } function draw_all_tabs(){ - global $tabname_array, $new_tab; - reset($tabname_array); + global $tabname_array, $new_tab; + reset($tabname_array); ?> + global $tabname_array; + if($is_opened){?>
  • + else{ ?>
  • - "> + ">
  • diff --git a/include/valid_ml.inc.php b/include/valid_ml.inc.php deleted file mode 100644 index 2d91a90..0000000 --- a/include/valid_ml.inc.php +++ /dev/null @@ -1,186 +0,0 @@ -Validate($_uid, false, 'ml', $_stamp); - $this->alias = $_alias; - $this->topic = $_topic; - $this->publique = $_publique; - $this->libre = $_libre; - $this->archive = $_archive; - $this->freeins = $_freeins; - $this->comment = $_comment; - $this->moderos = $_moderos; - $this->membres = $_membres; - - $sql = $globals->db->query("SELECT username,prenom,nom FROM auth_user_md5 WHERE user_id=".$this->uid); - list($this->username,$this->prenom,$this->nom) = mysql_fetch_row($sql); - mysql_free_result($sql); - } - - function get_unique_request($uid) { - return false; // ben oui, c pas un objet unique !!! - } - - function formu() { - global $globals; - $sql = $globals->db->query("SELECT username FROM auth_user_md5" - ." WHERE user_id IN ({$this->moderos})" - ." ORDER BY nom, prenom"); - $tab = array(); - while(list($username) = mysql_fetch_row($sql)) $tab[] = $username; - $this->moderos_txt = implode(', ', $tab); - mysql_free_result($sql); - - $sql = $globals->db->query("SELECT username FROM auth_user_md5" - ." WHERE user_id IN ({$this->membres})" - ." ORDER BY nom, prenom"); - $tab = array(); - while(list($username) = mysql_fetch_row($sql)) $tab[] = $username; - $this->membres_txt = implode(', ', $tab); - mysql_free_result($sql); - return 'include/form.valid.ml.tpl'; - } - - function handle_formu () { - global $no_update_bd; - if($no_update_bd) return false; - - if(empty($_REQUEST['submit']) || ($_REQUEST['submit']!="Accepter" - && $_REQUEST['submit']!="Refuser")) - return false; - - $this->alias = $_REQUEST['alias']; - $this->topic = $_REQUEST['topic']; - $this->publique = isset($_REQUEST['publique']) && $_REQUEST['publique']; - $this->libre = isset($_REQUEST['libre']) && $_REQUEST['libre']; - $this->archive = isset($_REQUEST['archive']) && $_REQUEST['archive']; - $this->freeins = isset($_REQUEST['freeins']) && $_REQUEST['freeins']; - - $this->clean(); - $this->submit(); - - require_once("tpl.mailer.inc.php"); - - $mymail = new TplMailer(); - $mymail->assign('username',$this->username); - $mymail->assign('alias',$this->alias); - $mymail->assign('motif',stripslashes($_REQUEST['motif'])); - - if($_REQUEST['submit']=="Accepter") { - $mymail->assign('answer', 'yes'); - if(!$this->commit()) { - return "

    Aucun mail envoyé, erreur !

    \n"; - } - } else { - $mymail->assign('answer', 'no'); - $this->clean(); - } - - $mymail->send(); - return "Mail envoyé"; - } - - function commit () { - global $no_update_bd, $globals; - if($no_update_bd) return false; - - $type = new DiogenesFlagset(); - if ($this->libre) $type->addflag('libre'); - if ($this->publique) $type->addflag('publique'); - if ($this->archive) $type->addflag('archive'); - if ($this->freeins) $type->addflag('freeins'); - - $globals->db->query("INSERT INTO listes_def SET type='".$type->value."', topic='{$this->topic}'"); - echo "

    Liste {$this->alias} créée

    \n"; - - if(!mysql_errno()) { - $id = mysql_insert_id(); - if ($this->archive) - $globals->db->query("replace into listes_ins set idl=$id, idu=0"); - $globals->db->query("INSERT INTO aliases (alias,type,id) VALUES". - "('{$this->alias}','liste',$id)". - ",('owner-{$this->alias}','liste-owner',$id)". - ",('sm-{$this->alias}','liste-sans-moderation',$id)". - ",('{$this->alias}-request','liste-request',$id)"); - - if (!mysql_errno()) { - echo "

    Liste {$this->alias} ajoutée aux alias

    \n"; - if (isset($this->moderos)) { - $tokens = explode(',',$this->moderos); - $values = array(); - foreach ($tokens as $tok) { - $values[] = "($id,$tok)"; - } - $values = implode(',', $values); - $globals->db->query("INSERT INTO listes_mod (idl, idu) VALUES $values"); - } - - // ajout des membres si précisés - if (isset($this->membres)) { - $tokens = explode(',',$this->membres); - $values = array(); - foreach ($tokens as $tok) { - $values[] = "($id,$tok)"; - } - $values = implode(',', $values); - $globals->db->query("INSERT INTO listes_ins (idl, idu) VALUES $values"); - } - - $this->clean(); - return true; - } else { // alias déjà existant ? - $globals->db->query("DELETE FROM aliases WHERE id='$id'"); - $globals->db->query("DELETE FROM listes_ins WHERE id='$id'"); - $globals->db->query("DELETE FROM listes_def WHERE id='$id'"); - echo "

    Nom déjà utilisé (owner-{$this->alias} ou {$this->alias}-request)

    \n"; - return false; - } // if mysql_errno == 0 pour insert dans aliases - } else { - echo "

    Nom déjà utilisé

    \n"; - return false; - } // if mysql_errno == 0 pour insert dans liste_def - - return true; - } -} - -?> diff --git a/include/validations.inc.php b/include/validations.inc.php index ae38336..2cfd88d 100644 --- a/include/validations.inc.php +++ b/include/validations.inc.php @@ -18,11 +18,11 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: validations.inc.php,v 1.11 2004-08-31 11:16:48 x2000habouzit Exp $ + $Id: validations.inc.php,v 1.12 2004-08-31 19:48:46 x2000habouzit Exp $ ***************************************************************************/ /* vim: set expandtab shiftwidth=4 tabstop=4 softtabstop=4 textwidth=100: - * $Id: validations.inc.php,v 1.11 2004-08-31 11:16:48 x2000habouzit Exp $ + * $Id: validations.inc.php,v 1.12 2004-08-31 19:48:46 x2000habouzit Exp $ * */ @@ -181,7 +181,6 @@ class Validate { require("valid_aliases.inc.php"); require("valid_epouses.inc.php"); require("valid_photos.inc.php"); -require("valid_ml.inc.php"); require("valid_sondages.inc.php"); require("valid_emploi.inc.php"); require("valid_evts.inc.php"); diff --git a/templates/profil/skill.tpl b/templates/profil/skill.tpl index 9f5bc54..5389b54 100644 --- a/templates/profil/skill.tpl +++ b/templates/profil/skill.tpl @@ -17,7 +17,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: skill.tpl,v 1.5 2004-08-31 11:25:42 x2000habouzit Exp $ + $Id: skill.tpl,v 1.6 2004-08-31 19:48:47 x2000habouzit Exp $ ***************************************************************************} @@ -97,125 +97,118 @@   - {section name=comp loop=$nb_cpro+1 start=1} - {assign var='i' value=$smarty.section.comp.index} - {if $i%2} - - {else} - - {/if} - - {$cpro_name.$i} - - -   {$cpro_level.$i} - - - retirer - - - {/section} - {if $nb_cpro < $nb_cpro_max} - {if $i%2} - - {else} - - {/if} - - - - - - - - ajouter - - - {/if} - - - + {foreach from=$cpro_name key=i item=name} + + + {$name} + + +   {$cpro_level.$i} + + + retirer + + + {/foreach} + {if $nb_cpro < $nb_cpro_max} + + + + + + + + + ajouter + + + {/if} + + -
    - - - - - - - - - - - - - {section name=lg loop=$nb_lg+1 start=1} - {assign var='i' value=$smarty.section.lg.index} - {if $i%2} - - {else} - - {/if} - - + + + + + + + {foreach from=$langue_name item=name key=i} + + + + + + {/foreach} + {if $nb_lg < $nb_lg_max} + + + + + + {/if} +
    - Compétences linguistiques - - - -
    - - - - - -
    - - - ne peut être ni public ni transmis à l'AX -
    -
    - Langue - - Niveau - - Quel niveau ? -
    - {$langue_name.$i} - -   {if $langue_level.$i == 0}-{else}{$langue_level.$i}{/if} +
    + + + + + +
    + Compétences linguistiques + + + +
    + + + - - {/section} - {if $nb_lg < $nb_lg_max} - {if $i%2} - - {else} - - {/if} - - - - - {/if} -
    + - retirer + + ne peut être ni public ni transmis à l'AX
    - - - - - ajouter -
    - +
    +
    + Langue + + Niveau + + Quel niveau ? +
    + {$name} + +   {if $langue_level.$i == 0}-{else}{$langue_level.$i}{/if} + + retirer +
    + + + + + ajouter +
    +
    {* vim:set et sw=2 sts=2 sws=2: *} -- 2.1.4