From 5ec2bee0e1b26c92cb5cd93e5d1073a103f8a3ed Mon Sep 17 00:00:00 2001 From: x2000bedo Date: Mon, 16 Aug 2004 22:27:47 +0000 Subject: [PATCH] =?utf8?q?Fin=20de=20la=20recherche=20avanc=E9e.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Il faudra bien tester à la fin de la migration ! --- htdocs/advanced_search.php | 37 +++++++++++++++------ htdocs/search.php | 2 +- include/search.classes.inc.php | 65 ++++++++++++++++++++++++++++++++++--- templates/search.form.tpl | 8 ++--- templates/search.result.private.tpl | 2 +- 5 files changed, 94 insertions(+), 20 deletions(-) diff --git a/htdocs/advanced_search.php b/htdocs/advanced_search.php index 47a7fec..21f268a 100644 --- a/htdocs/advanced_search.php +++ b/htdocs/advanced_search.php @@ -1,7 +1,7 @@ assign('advanced',1); $page->assign('public_directory',0); require_once("applis.func.inc.php"); @@ -14,17 +14,34 @@ if (array_key_exists('rechercher', $_REQUEST)) { $firstnameField = new StringSField('firstname',array('u.prenom'),''); $promo1Field = new PromoSField('promo1','egal1',array('u.promo'),''); $promo2Field = new PromoSField('promo2','egal2',array('u.promo'),''); - $fields = new SFieldGroup(true,array($nameField,$firstnameField,$promo1Field,$promo2Field)); + + $townField = new RefSField('ville',array('av.ville'),'adresses','av','u.user_id=av.uid',false); + $countryField = new RefSField('pays',array('ap.pays'),'adresses','ap','u.user_id=ap.uid'); + $regionField = new RefSField('region',array('ar.region'),'adresses','ar','u.user_id=ar.uid'); + + $entrepriseField = new RefSField('enteprise',array('ee.entreprise'),'entreprises','ee','u.user_id=ee.uid'); + $posteField = new RefSField('poste',array('ep.fonction'),'entreprises','ep','u.user_id=ep.uid'); + $secteurField = new RefSField('secteur',array('es.secteur'),'entreprises','es','u.user_id=es.uid'); + $cvField = new StringSField('cv',array('u.cv'),''); + + $nationaliteField = new RefSField('nationalite',array('u.nationalite'),'','',''); + $binetField = new RefSField('binet',array('b.binet_id'),'binets_ins','b','u.user_id=b.user_id'); + $groupexField = new RefSField('groupex',array('g.gid'),'groupesx_ins','g','u.user_id=g.guid'); + $sectionField = new RefSField('section',array('u.section'),'','',''); + $schoolField = new RefSField('school',array('as.aid'),'applis_ins','as','u.user_id=as.uid'); + $diplomaField = new RefSField('diploma',array('ad.type'),'applis_ins','ad','u.user_id=ad.uid'); + + $fields = new SFieldGroup(true,array($nameField,$firstnameField,$promo1Field,$promo2Field, + $townField,$countryField,$regionField, + $entrepriseField,$posteField,$secteurField,$cvField, + $nationaliteField,$binetField,$groupexField,$sectionField,$schoolField,$diplomaField)); - if ($nameField->length()<2 && $firstnameField->length()<2 && - ($public_directory || !$promo1Field->is_a_single_promo())) - { - new ThrowError('Recherche trop générale.'); - } $offset = new NumericSField('offset'); - + + $where = $fields->get_where_statement(); $sql = 'SELECT SQL_CALC_FOUND_ROWS u.matricule,i.matricule_ax, + 1 AS inscrit, u.nom, u.epouse, u.prenom, @@ -35,14 +52,14 @@ if (array_key_exists('rechercher', $_REQUEST)) { ad0.text AS app0text, ad0.url AS app0url, ai0.type AS app0type, ad1.text AS app1text, ad1.url AS app1url, ai1.type AS app1type, c.uid AS contact - FROM auth_user_md5 AS u + FROM auth_user_md5 AS u '.$fields->get_select_statement().' INNER JOIN identification AS i ON (i.matricule=u.matricule) LEFT JOIN contacts AS c ON (c.uid='.((array_key_exists('uid',$_SESSION))?$_SESSION['uid']:0).' AND c.contact=u.user_id) LEFT JOIN applis_ins AS ai0 ON (u.user_id = ai0.uid AND ai0.ordre = 0) LEFT JOIN applis_def AS ad0 ON (ad0.id = ai0.aid) LEFT JOIN applis_ins AS ai1 ON (u.user_id = ai1.uid AND ai1.ordre = 1) LEFT JOIN applis_def AS ad1 ON (ad1.id = ai1.aid) - WHERE '.$fields->get_where_statement().' + '.(($where!='')?('WHERE '.$where):'').' ORDER BY '.implode(',',array_filter(array($fields->get_order_statement(),'promo DESC,nom,prenom'))).' LIMIT '.$offset->value.','.$globals->search_results_per_page; diff --git a/htdocs/search.php b/htdocs/search.php index c58740e..ffb4c4f 100644 --- a/htdocs/search.php +++ b/htdocs/search.php @@ -6,7 +6,7 @@ $public_directory = ((isset($_REQUEST['public_directory']) && $_REQUEST['public_ if ($public_directory) new_skinned_page('search.tpl', AUTH_PUBLIC); else - new_skinned_page('search.tpl', AUTH_COOKIE); + new_skinned_page('search.tpl', AUTH_COOKIE,true); $page->assign('advanced',0); $page->assign('public_directory',$public_directory); require_once("applis.func.inc.php"); diff --git a/include/search.classes.inc.php b/include/search.classes.inc.php index e4086b6..c177ced 100644 --- a/include/search.classes.inc.php +++ b/include/search.classes.inc.php @@ -51,9 +51,10 @@ class SField { * à chacun d'entre eux une clause spécifique * la clause totale et la disjonction de ces clauses spécifiques */ function get_where_statement() { - return ($this->value!='')? - '('.implode(' OR ',array_map(array($this,'get_single_where_statement'),$this->fieldDbName)).')' - :false; + if ($this->value=='') + return false; + $res = implode(' OR ',array_filter(array_map(array($this,'get_single_where_statement'),$this->fieldDbName))); + return ($res!='')?('('.$res.')'):''; } /** récupérer la clause correspondant au champ dans la clause ORDER BY de la requête @@ -62,6 +63,10 @@ class SField { return false; } + function get_select_statement() { + return false; + } + /** récupérer le bout d'URL correspondant aux paramètres permettant d'imiter une requête d'un * utilisateur assignant la valeur $this->value à ce champ */ function get_url() { @@ -92,6 +97,49 @@ class NumericSField extends SField { } } +class RefSField extends SField { + var $refTable; + var $refAlias; + var $refCondition; + var $exact=true; + + function RefSField($_fieldFormName,$_fieldDbName='',$_refTable,$_refAlias,$_refCondition,$_exact=true) { + $this->fieldFormName = $_fieldFormName; + $this->fieldDbName = $_fieldDbName; + $this->refTable = $_refTable; + $this->refAlias = $_refAlias; + $this->refCondition = $_refCondition; + $this->exact = $_exact; + $this->get_request(); + } + + function get_request() { + parent::get_request(); + if ($this->value=='00' || $this->value=='0') + $this->value=''; + } + + function compare() { + if ($this->exact) + return "='".$this->value."'"; + else + return "LIKE '%".$this->value."%'"; + } + + function get_single_where_statement($field) { + if ($this->refTable=='') + return $field.$this->compare(); + return false; + } + + function get_select_statement() { + if ($this->value=='' || $this->refTable=='') + return false; + return 'INNER JOIN '.$this->refTable.' AS '.$this->refAlias. + ' ON('.$this->refCondition.' AND '.$this->fieldDbName[0].$this->compare().")"; + } +} + /** classe de champ texte (nom par exemple) */ class StringSField extends SField { @@ -202,6 +250,10 @@ class SFieldGroup { $this->and = $_and; } + function field_get_select($f) { + return $f->get_select_statement(); + } + /** récupérer la clause WHERE d'un objet champ de recherche */ function field_get_where($f) { return $f->get_where_statement(); @@ -217,11 +269,16 @@ class SFieldGroup { return $f->get_url(); } + function get_select_statement() { + return implode(' ',array_filter(array_map(array($this,'field_get_select'),$this->fields))); + } + /** récupérer la clause WHERE du groupe de champs = conjonction (ET) ou disjonction (OU) de * clauses des champs élémentaires */ function get_where_statement() { $joinText=($this->and)?' AND ':' OR '; - return '('.implode($joinText,array_filter(array_map(array($this,'field_get_where'),$this->fields))).')'; + $res = implode($joinText,array_filter(array_map(array($this,'field_get_where'),$this->fields))); + return ($res!='')?('('.$res.')'):''; } /** récupérer la clause ORDER BY du groupe de champs = conjonction (ET) ou disjonction (OU) de diff --git a/templates/search.form.tpl b/templates/search.form.tpl index 3c53162..125c67e 100644 --- a/templates/search.form.tpl +++ b/templates/search.form.tpl @@ -92,7 +92,7 @@ Poste - + {section name=secteur loop=$choix_secteurs} + {section name=diploma loop=$choix_diplomas}