<?php
require("auto.prepend.inc.php");
require("search.classes.inc.php");
-$perpage = 10;
// choix entre partie publique (annuaire_public est vrai) et partie privée de l'annuaire.
$public_directory = ((isset($_REQUEST['public_directory']) && $_REQUEST['public_directory']==1));
if ($public_directory)
$firstnameField = new StringSField('firstname',array('u.prenom','i.prenom'),'i.prenom');
$promoField = new PromoSField('promo','egal',array('u.promo','i.promo'),'i.promo');
$fields = new SFieldGroup(true,array($nameField,$firstnameField,$promoField));
+ if ($nameField->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,
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);
<?php
+class ThrowError {
+ function ThrowError($explain) {
+ global $page;
+ $page->assign('error','Erreur : '.$explain);
+ $page->run();
+ }
+}
+
class SField {
var $fieldFormName;
var $fieldDbName;
(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)).')'
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.<br>');
+ new ThrowError('Un champ numérique contient des caractères alphanumériques.<br>');
}
}
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.<br>');
}
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) {
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.<br>');
+ new ThrowError('La promotion est une année à quatre chiffres.<br>');
}
function is_a_single_promo() {
--- /dev/null
+<div class="rubrique">
+ Recherche
+</div>
+{if $error}
+ <p class="error">
+ {$error}
+ </p>
+{/if}
+<div class="center">
+ <form action="{$smarty.server.PHP_SELF}" method="post">
+ <input type="hidden" name="public_directory" value="{$public_directory}">
+ <table class="tinybicol" cellpadding="3" summary="Recherche">
+ <tr>
+ <td>Nom</td>
+ <td><input type="text" name="name" size="50" maxlength="50" /></td>
+ </tr>
+ <tr>
+ <td>Prénom</td>
+ <td><input type="text" name="firstname" size="50" maxlength="50" /></td>
+ </tr>
+ <tr>
+ <td>Promotion</td>
+ <td>
+ <select name="egal">
+ <option value="=" selected> = </option>
+ <option value=">" > > </option>
+ <option value="<" > < </option>
+ </select>
+ <input type="text" name="promo" size="4" maxlength="4" />
+ </td>
+ </tr>
+ <tr>
+ <td colspan="2" class="center"><input type="submit" name="rechercher" value="Ok" /></td>
+ </tr>
+ </table>
+ </form>
+</div>
--- /dev/null
+<td>
+ {if $result.inscrit==1}
+ <a href="javascript:x()" onclick="popWin('x.php?x={$result.username}')">
+ <img src="images/loupe.gif" border=0 ALT="Afficher les détails">
+ </a>
+ <a href="vcard.php/{$result.username}.vcf?x={$result.username}">
+ <img src="images/vcard.png" border=0 ALT="Afficher la carte de visite">
+ </a>
+ <a href="mescontacts.php?action={if $result.contact!=""}retirer{else}ajouter{/if}&user={$result.username}&mode=normal">
+ <img src="images/{if $result.contact!=""}retirer{else}ajouter{/if}.gif" border=0 ALT="{if $result.contact!=""}Retirer de{else}Ajouter parmi{/if} mes contacts">
+ </a>
+ {else}
+ {if $result.decede != 1}
+ <a href="marketing.php?num={$result.matricule*2-100}" target="_blank">
+ clique ici si tu connais son adresse email !
+ </a>
+ {/if}
+ {/if}
+ {if $is_admin==1}
+ <a href="http://www.polytechniciens.com/index.php?page=AX_FICHE_ANCIEN&anc_id={$result.matricule_ax}" target="_blank">
+ AX
+ </a>
+ {/if}
+</td>
--- /dev/null
+<td>
+ <strong>{$result.nom} {$result.prenom}</strong>
+ {if $result.epouse neq ""}
+ <div>({$result.epouse} {$result.prenom})</div>
+ {/if}
+ {if $result.decede == 1}
+ <div>(décédé)</div>
+ {/if}
+</td>
+<td>
+ (X {$result.promo})
+</td>
{dynamic}
-{if $formulaire==0}
+{if $formulaire==0 and !$error}
<div class="rubrique">
Résultats
</div>
+ <div class="right">
+ <a href="{$smarty.server.PHP_SELF}?public_directory={$public_directory}">Nouvelle recherche</a>
+ </div>
<p class="smaller">
{if $nb_resultats_total==0}Aucune{else}{$nb_resultats_total}{/if} réponse{if $nb_resultats_total>1}s{/if}.
</p>
<table class="bicol">
{section name=resultat loop=$resultats}
<tr class="{cycle values="pair,impair"}">
- <td>
- <strong>{$resultats[resultat].nom} {$resultats[resultat].prenom}</strong>
- {if $resultats[resultat].epouse neq ""}
- <div>({$resultats[resultat].epouse} {$resultats[resultat].prenom})</div>
- {/if}
- {if $resultats[resultat].decede == 1}
- <div>(décédé)</div>
- {/if}
- </td>
- <td>
- (X {$resultats[resultat].promo})
- {if $resultats[resultat].inscrit==1}
- <a href="javascript:x()" onclick="popWin('x.php?x={$resultats[resultat].username}')">
- <img src="images/loupe.gif" border=0 ALT="Afficher les détails"></a>
- <a href="vcard.php/{$resultats[resultat].username}.vcf?x={$resultats[resultat].username}">
- <img src="images/vcard.png" border=0 ALT="Afficher la carte de visite"></a>
- <a href="mescontacts.php?action={if $resultats[resultat].contact!=""}retirer{else}ajouter{/if}&user={$resultats[resultat].username}&mode=normal">
- <img src="images/{if $resultats[resultat].contact!=""}retirer{else}ajouter{/if}.gif" border=0 ALT="{if $resultats[resultat].contact!=""}Retirer de{else}Ajouter parmi{/if} mes contacts"></a>
- {/if}
- </td>
+ {include file="search.result.public.tpl" result=$resultats[resultat]}
+ {if $public_directory!=1}
+ {include file="search.result.private.tpl" result=$resultats[resultat]}
+ {/if}
</tr>
{/section}
</table>
{if $perpage<$nb_resultats_total}
+ <p>
{if $offset!=0}
- <a href="{$smarty.server.PHP_SELF}?public_directory={$public_directory}&rechercher=1&{$url_args}&offset=0">Précédent</a>
+ <a href="{$smarty.server.PHP_SELF}?public_directory={$public_directory}&rechercher=1&{$url_args}&offset={$offset-$perpage}">
+ Précédent
+ </a>
+
{/if}
+ {section name=offset loop=$offsets}
+ {if $offset!=$smarty.section.offset.index*$perpage}
+ <a href="{$smarty.server.PHP_SELF}?public_directory={$public_directory}&rechercher=1&{$url_args}&offset={$smarty.section.offset.index*$perpage}">
+ {$smarty.section.offset.index+1}
+ </a>
+ {else}
+ <strong>{$smarty.section.offset.index+1}</strong>
+ {/if}
+
+ {/section}
{if $offset<$nb_resultats_total-$perpage}
- <a
- href="{$smarty.server.PHP_SELF}?public_directory={$public_directory}&rechercher=1&{$url_args}&offset={$offset+$perpage}">Suivant</a>
+ <a href="{$smarty.server.PHP_SELF}?public_directory={$public_directory}&rechercher=1&{$url_args}&offset={$offset+$perpage}">
+ Suivant
+ </a>
+
{/if}
+ </p>
{/if}
{else}
- <div class="rubrique">
- Recherche
- </div>
- <div class="center">
- <form action="{$smarty.server.PHP_SELF}" method="post">
- <input type="hidden" name="public_directory" value="{$public_directory}">
- <table class="tinybicol" cellpadding="3" summary="Recherche">
- <tr>
- <td>Nom</td>
- <td><input type="text" name="name" size="50" maxlength="50" /></td>
- </tr>
- <tr>
- <td>Prénom</td>
- <td><input type="text" name="firstname" size="50" maxlength="50" /></td>
- </tr>
- <tr>
- <td>Promotion</td>
- <td>
- <select name="egal">
- <option value="=" selected> = </option>
- <option value=">" > > </option>
- <option value="<" > < </option>
- </select>
- <input type="text" name="promo" size="4" maxlength="4" />
- </td>
- </tr>
- <tr>
- <td colspan="2" class="center"><input type="submit" name="rechercher" value="Ok" /></td>
- </tr>
- </table>
- </form>
- </div>
+ {include file="search.form.tpl"}
{/if}
{/dynamic}