if (array_key_exists('rechercher', $_REQUEST)) {
$page->assign('formulaire',0);
- $nameField = new StringSField('name',array('u.nom','u.epouse'),'');
- $firstnameField = new StringSField('firstname',array('u.prenom'),'');
+ $with_soundex = ((isset($_REQUEST['with_soundex']) && $_REQUEST['with_soundex']==1));
+
+ if ($with_soundex) {
+ $nameField = new RefWithSoundexSField('name',array('rn.nom1_soundex','rn.nom2_soundex','rn.nom3_soundex'),'recherche_soundex','rn','u.matricule = rn.matricule');
+ $firstnameField = new RefWithSoundexSField('firstname',array('rp.prenom1_soundex','rp.prenom2_soundex'),'recherche_soundex','rp','u.matricule = rp.matricule');
+ } else {
+ $nameField = new StringSField('name',array('u.nom','u.epouse'),'');
+ $firstnameField = new StringSField('firstname',array('u.prenom'),'');
+ }
$promo1Field = new PromoSField('promo1','egal1',array('u.promo'),'');
$promo2Field = new PromoSField('promo2','egal2',array('u.promo'),'');
$nbpages = ($page->get_template_vars('nb_resultats_total')-1)/$globals->search_results_per_page;
$page->assign('offsets',range(0,$nbpages));
$page->assign('url_args',$fields->get_url());
- $page->assign('with_soundex',0);
+ $page->assign('with_soundex',$with_soundex);
$page->assign('offset',$offset->value);
$page->assign('perpage',$globals->search_results_per_page);
$page->assign('is_admin',has_perms());
return " LIKE '%".$this->value."%'";
}
+ function get_single_match_statement($field) {
+ return $field.$this->compare();
+ }
+
function get_single_where_statement($field) {
if ($this->refTable=='')
- return $field.$this->compare();
+ return $this->get_single_match_statement($field);
return false;
}
function get_select_statement() {
if ($this->value=='' || $this->refTable=='')
return false;
+ $res = implode(' OR ',array_filter(array_map(array($this,'get_single_match_statement'),$this->fieldDbName)));
return 'INNER JOIN '.$this->refTable.' AS '.$this->refAlias.
- ' ON('.$this->refCondition.' AND '.$this->fieldDbName[0].$this->compare().")";
+ ' ON('.$this->refCondition.' AND '.'('.$res.')'.")";
+ }
+}
+
+class RefWithSoundexSField extends RefSField {
+ function get_request() {
+ parent::get_request();
+ if ($this->value!='')
+ $this->value=soundex_fr($this->value);
}
}