From: x2000bedo Date: Thu, 5 Aug 2004 00:36:24 +0000 (+0000) Subject: Nouvelles améliorations X-Git-Tag: xorg/old~1775 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=9c02c09e06ad8be28dcd89a5cd8aedc56d5eea1e;p=platal.git Nouvelles améliorations - Navigation sur plusieurs pages de recherches - Mise en évidence des requêtes trop générales - Gestion des erreurs de requêtes - Gestion des requêtes en annuaire public ou privé - Ajout des liens AX et marketing Attention ! Ajout de deux nouveaux paramètres dans config.xorg.inc.php : /* limitations recherche */ $globals->public_max_search_results = 25; $globals->search_results_per_page = 10; Reste pas mal d'esthétique et extension au soundex puis formulaire séparé pour la recherche avancée. A propos d'esthétique, où on modifie la CSS pour y ajouter de nouvelles classes ? --- diff --git a/htdocs/search.php b/htdocs/search.php index 60b0f0e..9bd51ae 100644 --- a/htdocs/search.php +++ b/htdocs/search.php @@ -1,7 +1,6 @@ length()<2 && $firstnameField->length()<2 && + ($public_directory || !$promoField->is_a_single_promo())) + new ThrowError('Recherche trop générale.'); $offset = new NumericSField('offset'); - $sql = 'SELECT SQL_CALC_FOUND_ROWS + $sql = 'SELECT SQL_CALC_FOUND_ROWS + i.matricule_ax,i.matricule, u.nom!="" AS inscrit, IF(u.nom!="",u.nom,i.nom) AS nom, u.epouse, @@ -27,15 +30,23 @@ if (array_key_exists('rechercher', $_REQUEST)) { c.uid AS contact FROM identification AS i LEFT JOIN auth_user_md5 AS u ON (i.matricule=u.matricule) - LEFT JOIN contacts AS c ON (c.uid = '.$_SESSION['uid'].' AND c.contact=u.user_id) + LEFT JOIN contacts AS c ON (c.uid='. + ((array_key_exists('uid',$_SESSION))?$_SESSION['uid']:0). + ' AND c.contact=u.user_id) WHERE '.$fields->get_where_statement().' ORDER BY '.implode(',',array_filter(array($fields->get_order_statement(), 'promo DESC,nom,prenom'))).' - LIMIT '.$offset->value.','.$perpage; + LIMIT '.$offset->value.','.$globals->search_results_per_page; $page->mysql_assign($sql, 'resultats', 'nb_resultats','nb_resultats_total'); + if ($public_directory && + $page->get_template_vars('nb_resultats_total')>$globals->public_max_search_results) + new ThrowError('Votre recherche a généré trop de résultats pour un affichage public.'); + $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('offset',$offset->value); - $page->assign('perpage',$perpage); + $page->assign('perpage',$globals->search_results_per_page); + $page->assign('is_admin',has_perms()); } else $page->assign('formulaire',1); diff --git a/include/search.classes.inc.php b/include/search.classes.inc.php index 05165b2..2cb9154 100644 --- a/include/search.classes.inc.php +++ b/include/search.classes.inc.php @@ -1,4 +1,12 @@ assign('error','Erreur : '.$explain); + $page->run(); + } +} + class SField { var $fieldFormName; var $fieldDbName; @@ -17,12 +25,6 @@ class SField { (isset($_REQUEST[$this->fieldFormName]))?trim(stripslashes($_REQUEST[$this->fieldFormName])):''; } - function error($explain) { - global $page; - $page->assign('error',$explain); - $page->run(); - } - function get_where_statement() { return ($this->value!='')? '('.implode(' OR ',array_map(array($this,'get_single_where_statement'),$this->fieldDbName)).')' @@ -52,7 +54,7 @@ class NumericSField extends SField { if ($this->value=='') $this->value = 0; if (!preg_match("/^[0-9]+$/", $this->value)) - $this->error('Un champ numérique contient des caractères alphanumériques.
'); + new ThrowError('Un champ numérique contient des caractères alphanumériques.
'); } } @@ -60,13 +62,14 @@ class StringSField extends SField { function get_request() { parent::get_request(); if (preg_match(":[][<>{}~/§_`|%$^=+]|\*\*:", $this->value)) - $this->error('Un champ contient un caractère interdit rendant la recherche' + new ThrowError('Un champ contient un caractère interdit rendant la recherche' .' impossible.
'); } function length() { + global $lc_accent,$uc_accent; return - length($this->value)-length(ereg_replace('[a-z]'.$CARACTERES_ACCENTUES,'',strtolower($this->value))); + strlen($this->value)-strlen(ereg_replace('[a-z'.$lc_accent.$uc_accent.']','',strtolower($this->value))); } function get_single_where_statement($field) { @@ -96,7 +99,7 @@ class PromoSField extends SField { function get_request() { parent::get_request(); if (!(empty($this->value) or preg_match("/^[0-9]{4}$/", $this->value))) - $this->error('La promotion est une année à quatre chiffres.
'); + new ThrowError('La promotion est une année à quatre chiffres.
'); } function is_a_single_promo() { diff --git a/templates/search.form.tpl b/templates/search.form.tpl new file mode 100644 index 0000000..fd59724 --- /dev/null +++ b/templates/search.form.tpl @@ -0,0 +1,37 @@ +
+ Recherche +
+{if $error} +

+ {$error} +

+{/if} +
+
+ + + + + + + + + + + + + + + + + +
Nom
Prénom
Promotion + + +
+
+
diff --git a/templates/search.result.private.tpl b/templates/search.result.private.tpl new file mode 100644 index 0000000..558ee01 --- /dev/null +++ b/templates/search.result.private.tpl @@ -0,0 +1,24 @@ + + {if $result.inscrit==1} + + Afficher les détails + + + Afficher la carte de visite + + + {if $result.contact!= + + {else} + {if $result.decede != 1} + + clique ici si tu connais son adresse email ! + + {/if} + {/if} + {if $is_admin==1} + + AX + + {/if} + diff --git a/templates/search.result.public.tpl b/templates/search.result.public.tpl new file mode 100644 index 0000000..4c5bf87 --- /dev/null +++ b/templates/search.result.public.tpl @@ -0,0 +1,12 @@ + + {$result.nom} {$result.prenom} + {if $result.epouse neq ""} +
({$result.epouse} {$result.prenom})
+ {/if} + {if $result.decede == 1} +
(décédé)
+ {/if} + + + (X {$result.promo}) + diff --git a/templates/search.tpl b/templates/search.tpl index 7e82678..f92a06c 100644 --- a/templates/search.tpl +++ b/templates/search.tpl @@ -1,78 +1,51 @@ {dynamic} -{if $formulaire==0} +{if $formulaire==0 and !$error}
Résultats
+
+ Nouvelle recherche +

{if $nb_resultats_total==0}Aucune{else}{$nb_resultats_total}{/if} réponse{if $nb_resultats_total>1}s{/if}.

{section name=resultat loop=$resultats} - - + {include file="search.result.public.tpl" result=$resultats[resultat]} + {if $public_directory!=1} + {include file="search.result.private.tpl" result=$resultats[resultat]} + {/if} {/section}
- {$resultats[resultat].nom} {$resultats[resultat].prenom} - {if $resultats[resultat].epouse neq ""} -
({$resultats[resultat].epouse} {$resultats[resultat].prenom})
- {/if} - {if $resultats[resultat].decede == 1} -
(décédé)
- {/if} -
- (X {$resultats[resultat].promo}) - {if $resultats[resultat].inscrit==1} - - Afficher les détails - - Afficher la carte de visite - - {if $resultats[resultat].contact!= - {/if} -
{if $perpage<$nb_resultats_total} +

{if $offset!=0} - Précédent + + Précédent + +   {/if} + {section name=offset loop=$offsets} + {if $offset!=$smarty.section.offset.index*$perpage} + + {$smarty.section.offset.index+1} + + {else} + {$smarty.section.offset.index+1} + {/if} +   + {/section} {if $offset<$nb_resultats_total-$perpage} - Suivant + + Suivant + +   {/if} +

{/if} {else} -
- Recherche -
-
-
- - - - - - - - - - - - - - - - - -
Nom
Prénom
Promotion - - -
-
-
+ {include file="search.form.tpl"} {/if} {/dynamic}