From: x2000habouzit Date: Tue, 31 Aug 2004 16:04:11 +0000 (+0000) Subject: mentor code is now at least 5 times faster, and 2 times smaller X-Git-Tag: xorg/old~1654 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=ac4dea9641423dfe58099faccc4c309fc401d07b;p=platal.git mentor code is now at least 5 times faster, and 2 times smaller works --- diff --git a/htdocs/profil.php b/htdocs/profil.php index fe2504f..ba44514 100644 --- a/htdocs/profil.php +++ b/htdocs/profil.php @@ -18,7 +18,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: profil.php,v 1.7 2004-08-31 15:03:33 x2000habouzit Exp $ + $Id: profil.php,v 1.8 2004-08-31 16:04:11 x2000habouzit Exp $ ***************************************************************************/ require("auto.prepend.inc.php"); @@ -72,7 +72,7 @@ if (isset($_REQUEST['modifier']) || isset($_REQUEST['suivant'])) { require_once("profil/get_{$opened_tab}.inc.php"); require_once("profil/verif_{$opened_tab}.inc.php"); - if(isset($verif_errs)) { + if(!empty($errs)) { require_once("profil/assign_{$opened_tab}.inc.php"); $page->assign("errs", $errs); $page->assign('onglet',$opened_tab); diff --git a/include/geoloc.inc.php b/include/geoloc.inc.php index f9926a4..032b841 100644 --- a/include/geoloc.inc.php +++ b/include/geoloc.inc.php @@ -18,7 +18,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: geoloc.inc.php,v 1.4 2004-08-31 13:59:43 x2000habouzit Exp $ + $Id: geoloc.inc.php,v 1.5 2004-08-31 16:04:11 x2000habouzit Exp $ ***************************************************************************/ @@ -27,11 +27,12 @@ * @return echo */ function geoloc_pays($current) { - $sql = "SELECT a2,pays FROM geoloc_pays ORDER BY pays"; + global $globals; + $sql = "SELECT a2,pays FROM geoloc_pays ORDER BY pays"; - $result = $globals->db->query($sql); - while (list($my_id,$my_pays) = mysql_fetch_row($result)) - printf("\n",$my_id,($current==$my_id?"selected='selected'":""),$my_pays); + $result = $globals->db->query($sql); + while (list($my_id,$my_pays) = mysql_fetch_row($result)) + printf("\n",$my_id,($current==$my_id?"selected='selected'":""),$my_pays); } function _geoloc_pays_smarty($params){ if(!isset($params['pays'])) @@ -46,12 +47,13 @@ $page->register_function('geoloc_pays', '_geoloc_pays_smarty'); * @return echo */ function geoloc_region($pays,$current) { - $sql = "SELECT region,name FROM geoloc_region where a2='".$pays."' ORDER BY name"; - $result = $globals->db->query($sql); + global $globals; + $sql = "SELECT region,name FROM geoloc_region where a2='".$pays."' ORDER BY name"; + $result = $globals->db->query($sql); - echo ""; - while (list($regid,$regname) = mysql_fetch_row($result)) - printf("\n",$regid,($current==$regid?"selected='selected'":""),$regname); + echo ""; + while (list($regid,$regname) = mysql_fetch_row($result)) + printf("\n",$regid,($current==$regid?"selected='selected'":""),$regname); } function _geoloc_region_smarty($params){ if(!isset($params['pays'])) diff --git a/include/profil/assign_mentor.inc.php b/include/profil/assign_mentor.inc.php new file mode 100644 index 0000000..03985b4 --- /dev/null +++ b/include/profil/assign_mentor.inc.php @@ -0,0 +1,35 @@ +assign('mentor_secteur_id_new', $mentor_secteur_id_new); +$page->assign('can_add_pays', $nb_mentor_pays < $max_mentor_pays); +$page->assign('can_add_secteurs', $nb_mentor_secteurs < $max_mentor_secteurs); +$page->assign('mentor_expertise', $mentor_expertise); +$page->assign('mentor_pid', $mentor_pid); +$page->assign('mentor_pays', $mentor_pays); +$page->assign('mentor_sid', $mentor_sid); +$page->assign('mentor_secteur', $mentor_secteur); +$page->assign('mentor_ssid', $mentor_ssid); +$page->assign('mentor_ss_secteur', $mentor_ss_secteur); + +?> diff --git a/include/profil/get_mentor.inc.php b/include/profil/get_mentor.inc.php new file mode 100644 index 0000000..248253d --- /dev/null +++ b/include/profil/get_mentor.inc.php @@ -0,0 +1,108 @@ +db->query("SELECT expertise FROM mentor WHERE uid = {$_SESSION['uid']}"); + +if(mysql_num_rows($res) > 0) { + list($mentor_expertise) = mysql_fetch_row($res); +} else { + $mentor_expertise = ''; +} +$mentor_expertise_bd = $mentor_expertise; + +//suppression eventuelle d'un pays +if(isset($_POST['mentor_pays_op']) && ($_POST['mentor_pays_op'] == 'retirer')) { + if(isset($_POST['mentor_pays_id'])) { + $id_supprimee = $_POST['mentor_pays_id']; + $globals->db->query("DELETE FROM mentor_pays WHERE uid = {$_SESSION['uid']} AND pid = '$id_supprimee' LIMIT 1"); + } +} + +//recuperation des pays +$res = $globals->db->query("SELECT m.pid, p.pays + FROM mentor_pays AS m + LEFT JOIN geoloc_pays AS p ON(m.pid = p.a2) WHERE m.uid = {$_SESSION['uid']} LIMIT $max_mentor_pays"); +$nb_mentor_pays = mysql_num_rows($res); +$mentor_pid = $mentor_pays = Array(); +for($i = 1; $i <= $nb_mentor_pays ; $i++) list($mentor_pid[$i], $mentor_pays[$i]) = mysql_fetch_row($res); + +//ajout eventuel d'un pays +if(isset($_POST['mentor_pays_op']) && ($_POST['mentor_pays_op'] == 'ajouter') && ($nb_mentor_pays < $max_mentor_pays)) { + if(isset($_POST['mentor_pays_id']) && ($_POST['mentor_pays_id'] != '00')) { + $id_ajoutee = $_POST['mentor_pays_id']; + $globals->db->query("INSERT INTO mentor_pays(uid, pid) VALUES('{$_SESSION['uid']}', '$id_ajoutee')"); + $nb_mentor_pays++; + $mentor_pid[$nb_mentor_pays] = $id_ajoutee; + $mentor_pays[$nb_mentor_pays] = stripslashes($_POST['mentor_pays_name']); + } +} + + + +//suppression d'un secteur / ss-secteur +if(isset($_POST['mentor_secteur_op']) && ($_POST['mentor_secteur_op'] == 'retirer')) { + if(isset($_POST['mentor_secteur_id'])) { + $id_supprimee = $_POST['mentor_secteur_id']; + $globals->db->query("DELETE FROM mentor_secteurs WHERE uid = {$_SESSION['uid']} AND secteur = '$id_supprimee' LIMIT 1"); + } +} + +//recuperation des secteurs +$res = $globals->db->query("SELECT m.secteur, s.label, m.ss_secteur, ss.label + FROM mentor_secteurs AS m + LEFT JOIN emploi_secteur AS s ON(m.secteur = s.id) + LEFT JOIN emploi_ss_secteur AS ss ON(s.id = ss.secteur AND m.ss_secteur = ss.id) + WHERE m.uid = {$_SESSION['uid']} + LIMIT $max_mentor_pays"); +$nb_mentor_secteurs = mysql_num_rows($res); +$mentor_sid = $mentor_secteur = $mentor_ssid = $mentor_ss_secteur = Array(); +for($i = 1; $i <= $nb_mentor_secteurs ; $i++) + list($mentor_sid[$i], $mentor_secteur[$i], $mentor_ssid[$i], $mentor_ss_secteur[$i]) = mysql_fetch_row($res); + +//ajout d'un secteur +$mentor_secteur_id_new = ''; +if(isset($_POST['mentor_secteur_op']) && ($_POST['mentor_secteur_op'] == 'ajouter') && ($nb_mentor_secteurs < $max_mentor_secteurs)) { + if(isset($_POST['mentor_secteur_id']) && ($_POST['mentor_secteur_id'] != '')) + { + $sid_ajoutee = $_POST['mentor_secteur_id']; + if(isset($_POST['mentor_ss_secteur_id'])) + $ssid_ajoutee = $_POST['mentor_ss_secteur_id']; + $globals->db->query("INSERT INTO mentor_secteurs (uid, secteur, ss_secteur) + VALUES('{$_SESSION['uid']}', '$sid_ajoutee',".( ($ssid_ajoutee == '')?'NULL':"'$ssid_ajoutee'" ).")"); + $nb_mentor_secteurs++; + $mentor_sid[$nb_mentor_secteurs] = $sid_ajoutee; + $mentor_secteur[$nb_mentor_secteurs] = stripslashes($_POST['mentor_secteur_name']); + $mentor_ssid[$nb_mentor_secteurs] = $ssid_ajoutee; + $mentor_ss_secteur[$nb_mentor_secteurs] = stripslashes($_POST['mentor_ss_secteur_name']); + } +} elseif(isset($_POST['mentor_secteur_id_new'])){ + $mentor_secteur_id_new = $_POST['mentor_secteur_id_new']; +} +?> diff --git a/include/profil/profil_mentor.inc.php b/include/profil/profil_mentor.inc.php deleted file mode 100644 index e00712d..0000000 --- a/include/profil/profil_mentor.inc.php +++ /dev/null @@ -1,136 +0,0 @@ -'; else echo ''; -?> - - - - -    - - - retirer - - -'; else echo ''; -?> - - - - - - - ajouter - - - -register_function('print_pays','_print_pays_smarty'); - - -$max_mentor_pays = 10; -$max_mentor_secteurs = 10; - -$page->assign('max_mentor_pays', $max_mentor_pays); -$page->assign('max_mentor_secteurs', $max_mentor_secteurs); - -//suppression eventuelle d'un pays -if(isset($_POST['mentor_pays_op']) && ($_POST['mentor_pays_op'] == 'retirer')) -{ - if(isset($_POST['mentor_pays_id'])) - { - $id_supprimee = $_POST['mentor_pays_id']; - $globals->db->query("DELETE FROM mentor_pays WHERE uid = {$_SESSION['uid']} AND pid = '$id_supprimee' LIMIT 1"); - } -} - -//suppression d'un secteur / ss-secteur -if(isset($_POST['mentor_secteur_op']) && ($_POST['mentor_secteur_op'] == 'retirer')) -{ - if(isset($_POST['mentor_secteur_id'])) - { - $id_supprimee = $_POST['mentor_secteur_id']; - $globals->db->query("DELETE FROM mentor_secteurs WHERE uid = {$_SESSION['uid']} AND secteur = '$id_supprimee' LIMIT 1"); - } -} - -//recuperation de l'expertise -$res = $globals->db->query("SELECT expertise FROM mentor WHERE uid = {$_SESSION['uid']}"); - -if(mysql_num_rows($res) > 0){ - list($mentor_expertise) = mysql_fetch_row($res); -} -else{ - $mentor_expertise = ''; -} -$mentor_expertise_bd = $mentor_expertise; - -$page->assign_by_ref('mentor_expertise', $mentor_expertise); -//recuperation des pays -$res = $globals->db->query("SELECT m.pid, p.pays - FROM mentor_pays AS m - LEFT JOIN geoloc_pays AS p ON(m.pid = p.a2) WHERE m.uid = {$_SESSION['uid']} LIMIT $max_mentor_pays"); - -$nb_mentor_pays = mysql_num_rows($res); -if($nb_mentor_pays > 0){ - for($i = 1; $i <= $nb_mentor_pays ; $i++) - list($mentor_pid[$i], $mentor_pays[$i]) = mysql_fetch_row($res); -} -$page->assign_by_ref('mentor_pid', $mentor_pid); -$page->assign_by_ref('mentor_pays', $mentor_pays); -$page->assign_by_ref('nb_mentor_pays', $nb_mentor_pays); - -//recuperation des secteurs -$res = $globals->db->query("SELECT m.secteur, s.label, m.ss_secteur, ss.label - FROM mentor_secteurs AS m - LEFT JOIN emploi_secteur AS s ON(m.secteur = s.id) - LEFT JOIN emploi_ss_secteur AS ss ON(s.id = ss.secteur AND m.ss_secteur = ss.id) - WHERE m.uid = {$_SESSION['uid']} - LIMIT $max_mentor_pays"); -$nb_mentor_secteurs = mysql_num_rows($res); -if($nb_mentor_secteurs > 0){ - for($i = 1; $i <= $nb_mentor_secteurs ; $i++) - list($mentor_sid[$i], $mentor_secteur[$i], - $mentor_ssid[$i], $mentor_ss_secteur[$i]) = mysql_fetch_row($res); -} -$page->assign_by_ref('mentor_sid', $mentor_sid); -$page->assign_by_ref('mentor_secteur', $mentor_secteur); -$page->assign_by_ref('mentor_ssid', $mentor_ssid); -$page->assign_by_ref('mentor_ss_secteur', $mentor_ss_secteur); -$page->assign_by_ref('nb_mentor_secteurs', $nb_mentor_secteurs); - -?> diff --git a/include/profil/update_mentor.inc.php b/include/profil/update_mentor.inc.php index 2f43311..48de5cf 100644 --- a/include/profil/update_mentor.inc.php +++ b/include/profil/update_mentor.inc.php @@ -18,14 +18,13 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: update_mentor.inc.php,v 1.3 2004-08-31 13:59:43 x2000habouzit Exp $ + $Id: update_mentor.inc.php,v 1.4 2004-08-31 16:04:11 x2000habouzit Exp $ ***************************************************************************/ //mise a jour d'expertise si nécessaire -if($mentor_expertise != $mentor_expertise_bd) -{ - $globals->db->query("REPLACE INTO mentor(uid, expertise) VALUES('{$_SESSION['uid']}', '".put_in_db($mentor_expertise)."')"); +if($mentor_expertise != $mentor_expertise_bd) { + $globals->db->query("REPLACE INTO mentor(uid, expertise) VALUES('{$_SESSION['uid']}', '".put_in_db($mentor_expertise)."')"); } diff --git a/include/profil/verif_general.inc.php b/include/profil/verif_general.inc.php index 9f04e92..e94aa7e 100644 --- a/include/profil/verif_general.inc.php +++ b/include/profil/verif_general.inc.php @@ -18,13 +18,12 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: verif_general.inc.php,v 1.4 2004-08-31 15:03:33 x2000habouzit Exp $ + $Id: verif_general.inc.php,v 1.5 2004-08-31 16:04:11 x2000habouzit Exp $ ***************************************************************************/ // validité du mobile if (strlen(strtok($mobile,"<>{}@&#~\/:;?,!§*_`[]|%$^=")) < strlen($mobile)) { - $verif_errs = true; $errs[] = "Le champ 'Téléphone mobile' contient un caractère interdit."; } diff --git a/include/profil/verif_mentor.inc.php b/include/profil/verif_mentor.inc.php index 3ebed5c..4a3f1d1 100644 --- a/include/profil/verif_mentor.inc.php +++ b/include/profil/verif_mentor.inc.php @@ -18,60 +18,16 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: verif_mentor.inc.php,v 1.4 2004-08-31 13:59:43 x2000habouzit Exp $ + $Id: verif_mentor.inc.php,v 1.5 2004-08-31 16:04:11 x2000habouzit Exp $ ***************************************************************************/ -//ajout eventuel d'un pays -if(isset($_POST['mentor_pays_op']) && ($_POST['mentor_pays_op'] == 'ajouter') && ($nb_mentor_pays < $max_mentor_pays)) -{ - if(isset($_POST['mentor_pays_id']) && ($_POST['mentor_pays_id'] != '00')) - { - $id_ajoutee = $_POST['mentor_pays_id']; - $globals->db->query("INSERT INTO mentor_pays(uid, pid) - VALUES('{$_SESSION['uid']}', '$id_ajoutee')"); - if(mysql_affected_rows() == 1){ - $nb_mentor_pays++; - $mentor_pid[$nb_mentor_pays] = $id_ajoutee; - $mentor_pays[$nb_mentor_pays] = stripslashes($_POST['mentor_pays_name']); - } - } -} - -//ajout d'un secteur -if(isset($_POST['mentor_secteur_op']) && ($_POST['mentor_secteur_op'] == 'ajouter') && ($nb_mentor_secteurs < $max_mentor_secteurs)) -{ - if(isset($_POST['mentor_secteur_id']) && ($_POST['mentor_secteur_id'] != '')) - { - $sid_ajoutee = $_POST['mentor_secteur_id']; - if(isset($_POST['mentor_ss_secteur_id'])) - $ssid_ajoutee = $_POST['mentor_ss_secteur_id']; - $globals->db->query("INSERT INTO mentor_secteurs(uid, secteur, ss_secteur) - VALUES('{$_SESSION['uid']}', '$sid_ajoutee', - ".( ($ssid_ajoutee == '')?'NULL':"'$ssid_ajoutee'" ).")"); - if(mysql_affected_rows() == 1){ - $nb_mentor_secteurs++; - $mentor_sid[$nb_mentor_secteurs] = $sid_ajoutee; - $mentor_secteur[$nb_mentor_secteurs] = stripslashes($_POST['mentor_secteur_name']); - $mentor_ssid[$nb_mentor_secteurs] = $ssid_ajoutee; - $mentor_ss_secteur[$nb_mentor_secteurs] = stripslashes($_POST['mentor_ss_secteur_name']); - } - } -} //au cas ou le submit du formulaire vient d'un changement du nouveau secteur -else if(isset($_POST['mentor_secteur_id_new'])){ - $mentor_secteur_id_new = $_POST['mentor_secteur_id_new']; -} -else{ - $mentor_secteur_id_new = ''; -} -$page->assign_by_ref('mentor_secteur_id_new', $mentor_secteur_id_new); - if(isset($_POST['mentor_expertise'])){ $mentor_expertise = stripslashes($_POST['mentor_expertise']); if(!empty($mentor_expertise)){ if (strlen(strtok($mentor_expertise,"<>{}~§`|%$^")) < strlen($mentor_expertise)){//TODO: affiner la liste - $str_error = $str_error."L'expertise contient un caractère interdit.
"; + $errs[] = "L'expertise contient un caractère interdit."; } } } diff --git a/include/secteur.emploi.inc.php b/include/secteur.emploi.inc.php index b134902..9b68671 100644 --- a/include/secteur.emploi.inc.php +++ b/include/secteur.emploi.inc.php @@ -18,32 +18,34 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: secteur.emploi.inc.php,v 1.4 2004-08-31 13:59:43 x2000habouzit Exp $ + $Id: secteur.emploi.inc.php,v 1.5 2004-08-31 16:04:11 x2000habouzit Exp $ ***************************************************************************/ function select_secteur($secteur){ - if($secteur == '') $secteur = -1; - echo "\n"; - $res = $globals->db->query("SELECT id, label FROM emploi_secteur"); - while(list($tmp_id, $tmp_label) = mysql_fetch_row($res)){ - echo "\n"; - } - mysql_free_result($res); + global $globals; + if($secteur == '') $secteur = -1; + echo "\n"; + $res = $globals->db->query("SELECT id, label FROM emploi_secteur"); + while(list($tmp_id, $tmp_label) = mysql_fetch_row($res)){ + echo "\n"; + } + mysql_free_result($res); } function select_ss_secteur($secteur,$ss_secteur){ - if($secteur != ''){ - echo "\n"; - $res = $globals->db->query("SELECT id, label FROM emploi_ss_secteur WHERE secteur = '$secteur'"); - while(list($tmp_id, $tmp_label) = mysql_fetch_row($res)){ - echo "\n"; - } - mysql_free_result($res); - } - else{ - echo "\n"; + global $globals; + if($secteur != ''){ + echo "\n"; + $res = $globals->db->query("SELECT id, label FROM emploi_ss_secteur WHERE secteur = '$secteur'"); + while(list($tmp_id, $tmp_label) = mysql_fetch_row($res)){ + echo "\n"; } + mysql_free_result($res); + } + else{ + echo "\n"; + } } //fonctions pour smarty diff --git a/templates/profil/mentor.tpl b/templates/profil/mentor.tpl index 62b21e6..d6bad53 100644 --- a/templates/profil/mentor.tpl +++ b/templates/profil/mentor.tpl @@ -17,13 +17,13 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: mentor.tpl,v 1.7 2004-08-31 11:25:42 x2000habouzit Exp $ + $Id: mentor.tpl,v 1.8 2004-08-31 16:04:11 x2000habouzit Exp $ ***************************************************************************} {literal}