<?php
require("auto.prepend.inc.php");
require("search.classes.inc.php");
-new_skinned_page('search.tpl', AUTH_COOKIE);
+new_skinned_page('search.tpl', AUTH_COOKIE,true);
$page->assign('advanced',1);
$page->assign('public_directory',0);
require_once("applis.func.inc.php");
$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,
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;
* à 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
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() {
}
}
+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 {
$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();
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
<td>Poste</td>
<td>
<select name="poste">
- <option value=""></option>
+ <option value="0"></option>
{section name=poste loop=$choix_postes}
<option value="{$choix_postes[poste].id}" {if $smarty.request.poste eq $choix_postes[poste].id}selected{/if}>
{$choix_postes[poste].fonction_fr}
<td>Secteur</td>
<td>
<select name="secteur">
- <option value=""></option>
+ <option value="0"></option>
{section name=secteur loop=$choix_secteurs}
<option value="{$choix_secteurs[secteur].id}" {if $smarty.request.secteur eq $choix_secteurs[secteur].id}selected{/if}>
{$choix_secteurs[secteur].label}
<td>Formation</td>
<td>
<select name="school" onChange="javascript:document.recherche.submit();">
- <option value=""></option>
+ <option value="0"></option>
{section name=school loop=$choix_schools}
<option value="{$choix_schools[school].id}" {if $smarty.request.school eq $choix_schools[school].id}selected{/if}>
{$choix_schools[school].text}
<td></td>
<td>
<select name="diploma">
- <option value=""></option>
+ <option value="0"></option>
{section name=diploma loop=$choix_diplomas}
<option value="{$choix_diplomas[diploma]}" {if $smarty.request.diploma eq $choix_diplomas[diploma]}selected{/if}>
{$choix_diplomas[diploma]}