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