Merge branch 'platal-1.0.0'
[platal.git] / templates / search / adv.form.tpl
1 {**************************************************************************}
2 {*                                                                        *}
3 {*  Copyright (C) 2003-2010 Polytechnique.org                             *}
4 {*  http://opensource.polytechnique.org/                                  *}
5 {*                                                                        *}
6 {*  This program is free software; you can redistribute it and/or modify  *}
7 {*  it under the terms of the GNU General Public License as published by  *}
8 {*  the Free Software Foundation; either version 2 of the License, or     *}
9 {*  (at your option) any later version.                                   *}
10 {*                                                                        *}
11 {*  This program is distributed in the hope that it will be useful,       *}
12 {*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *}
13 {*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *}
14 {*  GNU General Public License for more details.                          *}
15 {*                                                                        *}
16 {*  You should have received a copy of the GNU General Public License     *}
17 {*  along with this program; if not, write to the Free Software           *}
18 {*  Foundation, Inc.,                                                     *}
19 {*  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA               *}
20 {*                                                                        *}
21 {**************************************************************************}
22
23 <h1>Recherche dans l'annuaire</h1>
24
25 {javascript name=jquery.form}
26
27 <script type="text/javascript">// <!--
28   var baseurl = platal_baseurl + "search/";
29   {literal}
30   String.prototype.htmlEntities = function () {
31     return this.replace(/&/g,'&amp;').replace(new RegExp('<','g'),'&lt;').replace(/>/g,'&gt;');
32   };
33   // display an autocomplete row : blabla (nb of found matches)
34   function make_format_autocomplete(block) {
35     return function(row) {
36         regexp = new RegExp('(' + RegExp.escape(block.value) + ')', 'i');
37
38         name = row[0].htmlEntities().replace(regexp, '<strong>$1<\/strong>');
39
40         if (row[1] === "-1") {
41           return '&hellip;';
42         }
43
44         if (row[1] === "-2") {
45           return '<em>aucun camarade trouvé pour '+row[0].htmlEntities()+'<\/em>';
46         }
47
48         camarades = (row[1] > 1) ? "camarades" : "camarade";
49
50         return name + '<em>&nbsp;&nbsp;-&nbsp;&nbsp;' + row[1].htmlEntities() + '&nbsp;' + camarades + '<\/em>';
51       };
52   }
53
54   // when changing country, open up region choice
55   function changeCountry(a2) {
56     $(".autocompleteTarget[name='country']").attr('value',a2);
57
58     if (a2) {
59       $(".autocomplete[name='countryTxt']").addClass('hidden_valid');
60
61       $("[name='region']").parent().load(baseurl + 'list/region/', { country:a2 }, function() {
62           if ($("select[name='region']").children("option").size() > 1) {
63             $("select[name='region']").attr('value', '{/literal}{$smarty.request.region}{literal}');
64
65             $("tr#region_ln").show();
66           } else {
67             $("select[name='region']").attr('value', '');
68
69             $("tr#region_ln").hide();
70           }
71         });
72     } else {
73       $(".autocomplete[name='countryTxt']").removeClass('hidden_valid');
74
75       $("select[name='region']").attr('value', '');
76
77       $("tr#region_ln").hide();
78     }
79   }
80
81   // when changing school, open diploma choice
82   function changeSchool(schoolId) {
83     $(".autocompleteTarget[name='school']").attr('value',schoolId);
84
85     if (schoolId) {
86       $(".autocomplete[name='schoolTxt']").addClass('hidden_valid');
87     } else {
88       $(".autocomplete[name='schoolTxt']").removeClass('hidden_valid');
89     }
90
91     $("[name='diploma']").parent().load(baseurl + 'list/diploma/', { school:schoolId }, function() {
92         $("select[name='diploma']").attr('value', '{/literal}{$smarty.request.diploma}{literal}');
93       });
94   }
95
96   // when choosing a job term in tree, hide tree and set job term field
97   function searchForJobTerm(treeid, jtid, full_name) {
98     $(".term_tree").remove();
99     $("input[name='jobtermTxt']").val(full_name).addClass("hidden_valid").show();
100     $("input[name='jobterm']").val(jtid);
101   }
102
103   function cancel_autocomplete(field, realfield) {
104     $(".autocomplete[name='"+field+"']").removeClass('hidden_valid').val('').focus();
105     if (typeof(realfield) != "undefined") {
106       $(".autocompleteTarget[name='"+realfield+"']").val('');
107     }
108     return;
109   }
110
111   // when choosing autocomplete from list, must validate
112   function select_autocomplete(name) {
113       nameRealField = name.replace(/Txt$/, '');
114
115       // nothing to do if field is not a text field for a list
116       if (nameRealField == name)
117         return null;
118
119       // if changing country, might want to open region choice
120       if (nameRealField == 'country')
121         return function(i) {
122             if (i.extra[0] < 0) {
123               cancel_autocomplete('countryTxt', 'country');
124               i.extra[1] = '';
125             }
126             changeCountry(i.extra[1]);
127           }
128
129       if (nameRealField == 'school')
130         return function(i) {
131             if (i.extra[0] < 0) {
132               cancel_autocomplete('schoolTxt', 'school');
133               i.extra[1] = '';
134             }
135             changeSchool(i.extra[1]);
136           }
137
138       // change field in list and display text field as valid
139       return function(i) {
140         nameRealField = this.field.replace(/Txt$/, '');
141
142         if (i.extra[0] < 0) {
143           cancel_autocomplete(this.field, nameRealField);
144           return;
145         }
146
147         $(".autocompleteTarget[name='"+nameRealField+"']").attr('value',i.extra[1]);
148
149         $(".autocomplete[name='"+this.field+"']").addClass('hidden_valid');
150       }
151     }
152
153   $(document).ready(function() {
154       $(".autocompleteTarget").hide();
155       $(".autocomplete").show().each(function() {
156         targeted = $("../.autocompleteTarget",this)[0];
157
158         if (targeted && targeted.value) {
159           me = $(this);
160
161           $.get(baseurl + 'list/'+ targeted.name +'/'+targeted.value, {},function(textValue) {
162             me.attr('value', textValue);
163             me.addClass('hidden_valid');
164           });
165         }
166
167         $(this).autocomplete(baseurl + "autocomplete/"+this.name,{
168           selectOnly:1,
169           formatItem:make_format_autocomplete(this),
170           field:this.name,
171           onItemSelect:select_autocomplete(this.name),
172           matchSubset:0,
173           width:$(this).width()});
174         });
175
176       $(".autocomplete").change(function() { $(this).removeClass('hidden_valid'); });
177
178       $(".autocomplete[name='countryTxt']").change(function() { changeCountry(''); });
179
180       changeCountry({/literal}'{$smarty.request.country}'{literal});
181
182       $(".autocomplete[name='schoolTxt']").change(function() { changeSchool(''); });
183
184       changeSchool({/literal}'{$smarty.request.school}'{literal});
185
186       $(".autocompleteToSelect").each(function() {
187           var fieldName = $(this).attr('href');
188
189           $(this).attr('href', baseurl + 'list/'+fieldName).click(function() {
190               var oldval = $("input.autocompleteTarget[name='"+fieldName+"']")[0].value;
191
192               $(".autocompleteTarget[name='"+fieldName+"']").parent().load(baseurl + 'list/'+fieldName,{},
193                 function(selectBox) {
194                   $(".autocompleteTarget[name='"+fieldName+"']").remove();
195                   $(".autocomplete[name='"+fieldName+"Txt']").remove();
196                   $("select[name='"+fieldName+"']").attr('value', oldval);
197                 });
198
199               return false;
200             });
201         }).parent().find('.autocomplete').change(function() {
202           // If we change the value in the type="text" field, then the value in the 'integer id' field must not be used,
203           // to ensure that, we unset it
204           $(this).parent().find('.autocompleteTarget').val('');
205         });
206     });
207 /** Regexps to wipe out from search queries */
208 var default_form_values = [ /&woman=0(&|$)/, /&subscriber=0(&|$)/, /&alive=0(&|$)/, /&egal[12]=[^&]*&promo[12]=(&|$)/g, /&[^&=]+=(&|$)/g ];
209 /** Uses javascript to clean form from all empty fields */
210 function cleanForm(f) {
211   var query = $(f).formSerialize();
212   var old_query;
213   for (var i in default_form_values) {
214     var reg = default_form_values[i];
215     if (typeof(reg) != "undefined") {
216       do {
217         old_query = query;
218         query = query.replace(reg, '$1');
219       } while (old_query != query);
220     }
221   }
222   query = query.replace(/^&*(.*)&*$/, '$1');
223   if (query == "rechercher=Chercher") {
224     alert("Aucun critère n'a été spécifié");
225     return false;
226   }
227   document.location = f.action + '?' + query;
228   return false;
229 }
230 -->
231 {/literal}</script>
232 <p class="center">[<a href="search">Revenir à la recherche simple</a>]</p>
233 <form id="recherche" action="search/adv" method="get" onsubmit="return cleanForm(this)">
234   <table class="bicol" cellpadding="3" summary="Recherche">
235     <tr>
236       <th colspan="2">
237         Recherche avancée
238       </th>
239     </tr>
240     <tr>
241       <td>Nom, prénom, surnom...</td>
242       <td>
243         <input type="hidden" name="rechercher" value="Chercher"/>
244         <input type="submit" style="display:none"/>
245         <input type="text" name="name" size="32" value="{$smarty.request.name}" />
246       </td>
247     </tr>
248     <tr>
249       <td>Promotion</td>
250       <td>
251         <select name="egal1">
252           <option value="=" {if $smarty.request.egal1 eq "="}selected="selected"{/if}>&nbsp;=&nbsp;</option>
253           <option value="&gt;=" {if $smarty.request.egal1 eq "&gt;="}selected="selected"{/if}>&nbsp;&gt;=&nbsp;</option>
254           <option value="&lt;=" {if $smarty.request.egal1 eq "&lt;="}selected="selected"{/if}>&nbsp;&lt;=&nbsp;</option>
255         </select>
256         <input type="text" name="promo1" size="4" maxlength="4" value="{$smarty.request.promo1}" />
257         &nbsp;et&nbsp;
258         <select name="egal2">
259           <option value="=" {if $smarty.request.egal2 eq "="}selected="selected"{/if}>&nbsp;=&nbsp;</option>
260           <option value="&gt;=" {if $smarty.request.egal2 eq "&gt;="}selected="selected"{/if}>&nbsp;&gt;=&nbsp;</option>
261           <option value="&lt;=" {if $smarty.request.egal2 neq "&gt;=" && $smarty.request.egal2 neq "="}selected="selected"{/if}>&nbsp;&lt;=&nbsp;</option>
262         </select>
263         <input type="text" name="promo2" size="4" maxlength="4" value="{$smarty.request.promo2}" />
264       </td>
265     </tr>
266     <tr>
267       <td>Sexe</td>
268       <td>
269         <table>
270           <tr>
271             <td style="width:100px">
272               <input type="radio" name="woman" value="0" {if !$smarty.request.woman}checked="checked"{/if} id="woman0"/><label for="woman0">indifférent</label>
273             </td>
274             <td style="width:100px">
275               <input type="radio" name="woman" value="1" {if $smarty.request.woman eq 1}checked="checked"{/if} id="woman1"/><label for="woman1">homme</label>
276             </td>
277             <td style="width:100px">
278               <input type="radio" name="woman" value="2" {if $smarty.request.woman eq 2}checked="checked"{/if} id="woman2"/><label for="woman2">femme</label>
279             </td>
280           </tr>
281         </table>
282       </td>
283     </tr>
284     <tr>
285       <td>Sur Polytechnique.org</td>
286       <td>
287         <table>
288           <tr>
289             <td style="width:100px">
290               <input type="radio" name="subscriber" value="0" {if !$smarty.request.subscriber}checked="checked"{/if} id="subscriber0"/><label for="subscriber0">indifférent</label>
291             </td>
292             <td style="width:100px">
293               <input type="radio" name="subscriber" value="1" {if $smarty.request.subscriber eq 1}checked="checked"{/if} id="subscriber1"/><label for="subscriber1">inscrit</label>
294             </td>
295             <td style="width:100px">
296               <input type="radio" name="subscriber" value="2" {if $smarty.request.subscriber eq 2}checked="checked"{/if} id="subscriber2"/><label for="subscriber2">non inscrit</label>
297             </td>
298           </tr>
299         </table>
300       </td>
301     </tr>
302     <tr>
303       <td>En vie</td>
304       <td>
305         <table>
306           <tr>
307             <td style="width:100px">
308               <input type="radio" name="alive" value="0" {if !$smarty.request.alive}checked="checked"{/if} id="alive0"/><label for="alive0">indifférent</label>
309             </td>
310             <td style="width:100px">
311               <input type="radio" name="alive" value="1" {if $smarty.request.alive eq 1}checked="checked"{/if} id="alive1"/><label for="alive1">vivant</label>
312             </td>
313             <td style="width:100px">
314               <input type="radio" name="alive" value="2" {if $smarty.request.alive eq 2}checked="checked"{/if} id="alive2"/><label for="alive2">décédé</label>
315             </td>
316           </tr>
317         </table>
318       </td>
319     </tr>
320     <tr>
321       <td colspan="2">
322         <input type="checkbox" name="with_soundex" value="1" {if $smarty.request.with_soundex}checked="checked"{/if} id="sdxn" />
323         <label for="sdxn">Étendre par proximité sonore (uniquement sur nom et prénom).</label>
324       </td>
325     </tr>
326     <tr>
327       <th colspan="2">Géographie</th>
328     </tr>
329     <tr>
330       <td>Ville ou code postal</td>
331       <td><input type="text" class="autocomplete" name="city" size="32" value="{$smarty.request.city}" /></td>
332     </tr>
333     <tr>
334       <td>Pays</td>
335       <td>
336         <input name="countryTxt" type="text" class="autocomplete" style="display:none" size="32"
337                value="{$smarty.request.countryTxt}"/>
338         <input name="country" class="autocompleteTarget" type="hidden" value="{$smarty.request.country}"/>
339         <a href="country" class="autocompleteToSelect">{icon name="table" title="Tous les pays"}</a>
340       </td>
341     </tr>
342     <tr id="region_ln">
343       <td>Région ou département</td>
344       <td>
345         <input name="region" type="hidden" size="32" value="{$smarty.request.region}"/>
346       </td>
347     </tr>
348     <tr>
349       <td colspan="2">
350         <label for="only_current">
351           <input name="only_current" id="only_current" type="checkbox"{if $smarty.request.only_current} checked="checked"{/if}/>
352           Chercher uniquement les adresses où les camarades sont actuellement.
353         </label>
354       </td>
355     </tr>
356     <tr>
357       <th colspan="2">Activité</th>
358     </tr>
359     <tr>
360       <td>Entreprise</td>
361       <td><input type="text" class="autocomplete" name="entreprise" size="32" value="{$smarty.request.entreprise}" /></td>
362     </tr>
363     <tr>
364       <td>Description</td>
365       <td><input type="text" class="autocomplete" name="description" size="32" value="{$smarty.request.description}" /></td>
366     </tr>
367     <tr>
368       <td>Mots-clefs</td>
369       <td>
370         <input name="jobtermTxt" type="text" class="autocomplete{if $smarty.request.jobterm} hidden_valid{/if}" style="display:none" size="32"
371                value="{$smarty.request.jobtermTxt}"/>
372         <input name="jobterm" class="autocompleteTarget" type="hidden" value="{$smarty.request.jobterm}"/>
373         <a href="jobterm" class="autocompleteToSelect">{icon name="table" title="Tous les mots-clefs"}</a>
374       </td>
375     </tr>
376     <tr>
377       <td>CV contient</td>
378       <td><input type="text" name="cv" size="32" value="{$smarty.request.cv}" /></td>
379     </tr>
380     <tr>
381       <td colspan="2">
382         <input type='checkbox' name='only_referent' {if $smarty.request.only_referent}checked='checked'{/if} id="only_referent"/>
383         <label for="only_referent">Chercher uniquement parmi les camarades se proposant comme référents.</label>
384       </td>
385     </tr>
386     <tr>
387       <th colspan="2">Divers</th>
388     </tr>
389     <tr>
390       <td>Nationalité</td>
391       <td>
392         <input name="nationaliteTxt" type="text" class="autocomplete" style="display:none" size="32"
393                value="{$smarty.request.nationaliteTxt}"/>
394         <input name="nationalite" class="autocompleteTarget" type="hidden" value="{$smarty.request.nationalite}"/>
395         <a href="nationalite" class="autocompleteToSelect">{icon name="table" title="Toutes les nationalités"}</a>
396       </td>
397     </tr>
398     <tr>
399       <td>Binet</td>
400       <td>
401         <input name="binetTxt" type="text" class="autocomplete" style="display:none" size="32"
402                value="{$smarty.request.binetTxt}"/>
403         <input name="binet" class="autocompleteTarget" type="hidden" value="{$smarty.request.binet}"/>
404         <a href="binet" class="autocompleteToSelect">{icon name="table" title="Tous les binets"}</a>
405       </td>
406     </tr>
407     <tr>
408       <td>Groupe X</td>
409       <td>
410         <input name="groupexTxt" type="text" class="autocomplete" style="display:none" size="32"
411                value="{$smarty.request.groupexTxt}"/>
412         <input name="groupex" class="autocompleteTarget" type="hidden" value="{$smarty.request.groupex}"/>
413         <a href="groupex" class="autocompleteToSelect">{icon name="table" title="Tous les groupes X"}</a>
414       </td>
415     </tr>
416     <tr>
417       <td>Section</td>
418       <td>
419         <input name="sectionTxt" type="text" class="autocomplete" style="display:none" size="32"
420                value="{$smarty.request.sectionTxt}"/>
421         <input name="section" class="autocompleteTarget" type="hidden" value="{$smarty.request.section}"/>
422         <a href="section" class="autocompleteToSelect">{icon name="table" title="Toutes les sections"}</a>
423       </td>
424     </tr>
425     <tr>
426       <td>Formation</td>
427       <td>
428         <input name="schoolTxt" type="text" class="autocomplete" style="display:none" size="32"
429                value="{$smarty.request.schoolTxt}"/>
430         <input name="school" class="autocompleteTarget" type="hidden" value="{$smarty.request.school}"/>
431         <a href="school" class="autocompleteToSelect">{icon name="table" title="Toutes les formations"}</a>
432       </td>
433     </tr>
434     <tr>
435       <td>Diplôme</td>
436       <td>
437         <input name="diploma" size="32" value="{$smarty.request.diploma}"/>
438       </td>
439     </tr>
440     <tr>
441       <td>Commentaire contient</td>
442       <td><input type="text" name="free" size="32" value="{$smarty.request.free}" /></td>
443     </tr>
444     <tr>
445       <td>Numéro de téléphone</td>
446       <td><input type="text" name="phone_number" size="32" value="{$smarty.request.phone_number}"/></td>
447     </tr>
448     <tr>
449       <td style="vertical-align: middle">
450         <span>Networking et sites webs</span>
451       </td>
452       <td>
453         <table>
454           <tr>
455             <td style="padding-left: 0px;">
456               <input type="text" name="networking_address" size="32" value="{$smarty.request.networking_address}" />
457             </td>
458             <td>
459               <input type="text" name="networking_typeTxt" class="autocomplete" size="10" value="{$smarty.request.networking_typeTxt}" />
460               <input name="networking_type" class="autocompleteTarget" type="hidden" value="{$smarty.request.networking_type}"/>
461               <a href="networking_type" class="autocompleteToSelect">{icon name="table" title="Tous les types d'adresse"}</a>
462             </td>
463           </tr>
464         </table>
465       </td>
466     </tr>
467         {if $smarty.session.auth ge AUTH_COOKIE}
468     <tr>
469       <td colspan="2">
470           <input type='checkbox' name='order' value='date_mod' {if $smarty.request.order eq "date_mod"}checked='checked'{/if} id="order"/>
471           <label for="order">Mettre les fiches modifiées récemment en premier.</label>
472       </td>
473     </tr>
474     <tr>
475       <td colspan="2">
476            <input type='checkbox' name='exact' id="exact" {if $smarty.request.exact}checked='checked'{/if} value='1'/>
477            <label for="exact">Faire une recherche exacte.</label>
478       </td>
479     </tr>
480         {/if}
481     <tr><td colspan="2"></td></tr>
482     <tr>
483       <td colspan="2" style="text-align: center">
484           <input type="submit" value="Chercher" />
485       </td>
486     </tr>
487   </table>
488 </form>
489 <p>
490   <small><strong>N.B.&nbsp;:</strong> le caractère joker * peut remplacer une ou plusieurs lettres dans les recherches.</small>
491 </p>
492
493 {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}