| 1 | <?php |
| 2 | /*************************************************************************** |
| 3 | * Copyright (C) 2003-2006 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 | require_once("xorg.inc.php"); |
| 23 | require_once('search.inc.php'); |
| 24 | if (Env::get('display')!='mini') |
| 25 | new_skinned_page('search.tpl', AUTH_COOKIE); |
| 26 | else |
| 27 | new_simple_page('search.tpl', AUTH_COOKIE); |
| 28 | $page->assign('advanced',1); |
| 29 | $page->assign('public_directory',0); |
| 30 | require_once("applis.func.inc.php"); |
| 31 | require_once("geoloc.inc.php"); |
| 32 | |
| 33 | // {{{ function form_prepare() |
| 34 | |
| 35 | function form_prepare() |
| 36 | { |
| 37 | global $page,$globals; |
| 38 | $page->assign('formulaire',1); |
| 39 | $page->assign('choix_nats', $globals->xdb->iterator('SELECT a2 AS id,IF(nat=\'\',pays,nat) AS text FROM geoloc_pays ORDER BY text')); |
| 40 | $page->assign('choix_postes', $globals->xdb->iterator('SELECT id,fonction_fr FROM fonctions_def ORDER BY fonction_fr')); |
| 41 | $page->assign('choix_binets', $globals->xdb->iterator('SELECT id,text FROM binets_def ORDER BY text')); |
| 42 | $page->assign('choix_groupesx', $globals->xdb->iterator('SELECT id,text FROM groupesx_def ORDER BY text')); |
| 43 | $page->assign('choix_sections', $globals->xdb->iterator('SELECT id,text FROM sections ORDER BY text')); |
| 44 | $page->assign('choix_schools', $globals->xdb->iterator('SELECT id,text FROM applis_def ORDER BY text')); |
| 45 | $page->assign('choix_secteurs', $globals->xdb->iterator('SELECT id,label FROM emploi_secteur ORDER BY label')); |
| 46 | |
| 47 | if (Env::has('school')) { |
| 48 | $sql = 'SELECT type FROM applis_def WHERE id='.Env::getInt('school'); |
| 49 | } else { |
| 50 | $sql = 'DESCRIBE applis_def type'; |
| 51 | } |
| 52 | $res = $globals->xdb->query($sql); |
| 53 | $row = $res->fetchOneRow(); |
| 54 | if (Env::has('school')) { |
| 55 | $types = $row[0]; |
| 56 | } else { |
| 57 | $types = explode('(',$row[1]); |
| 58 | $types = str_replace("'","",substr($types[1],0,-1)); |
| 59 | } |
| 60 | $page->assign('choix_diplomas', explode(',',$types)); |
| 61 | } |
| 62 | |
| 63 | // }}} |
| 64 | |
| 65 | if (!Env::has('rechercher')) { |
| 66 | form_prepare(); |
| 67 | } else { |
| 68 | |
| 69 | // {{{ function get_list() |
| 70 | |
| 71 | function get_list($offset, $limit, $order) { |
| 72 | $fields = new SFieldGroup(true, advancedSearchFromInput()); |
| 73 | if ($fields->too_large()) { |
| 74 | form_prepare(); |
| 75 | new ThrowError('Recherche trop générale.'); |
| 76 | } |
| 77 | global $globals, $page; |
| 78 | |
| 79 | $page->assign('search_vars', $fields->get_url()); |
| 80 | |
| 81 | $where = $fields->get_where_statement(); |
| 82 | if ($where) { |
| 83 | $where = "WHERE $where"; |
| 84 | } |
| 85 | $sql = 'SELECT SQL_CALC_FOUND_ROWS DISTINCT |
| 86 | u.nom, u.prenom, |
| 87 | '.$globals->search->result_fields.' |
| 88 | c.uid AS contact, |
| 89 | w.ni_id AS watch |
| 90 | FROM auth_user_md5 AS u |
| 91 | LEFT JOIN auth_user_quick AS q USING(user_id) |
| 92 | '.$fields->get_select_statement().' |
| 93 | '.(Env::has('only_referent') ? ' INNER JOIN mentor AS m ON (m.uid = u.user_id)' : '').' |
| 94 | LEFT JOIN aliases AS a ON (u.user_id = a.id AND a.type="a_vie") |
| 95 | LEFT JOIN contacts AS c ON (c.uid='.Session::getInt('uid').' AND c.contact=u.user_id) |
| 96 | LEFT JOIN watch_nonins AS w ON (w.ni_id=u.user_id AND w.uid='.Session::getInt('uid').') |
| 97 | '.$globals->search->result_where_statement." |
| 98 | $where |
| 99 | ORDER BY ".($order?($order.', '):'') |
| 100 | .implode(',',array_filter(array($fields->get_order_statement(), 'promo DESC, NomSortKey, prenom'))).' |
| 101 | LIMIT '.($offset * $limit).','.$limit; |
| 102 | $liste = $globals->xdb->iterator($sql); |
| 103 | $res = $globals->xdb->query("SELECT FOUND_ROWS()"); |
| 104 | $nb_tot = $res->fetchOneCell(); |
| 105 | return Array($liste, $nb_tot); |
| 106 | } |
| 107 | |
| 108 | // }}} |
| 109 | |
| 110 | $search = new XOrgSearch('get_list'); |
| 111 | $search->setNbLines($globals->search->per_page); |
| 112 | |
| 113 | $page->assign('url_search_form', $search->make_url(Array('rechercher'=>0))); |
| 114 | $page->assign('with_soundex', Env::has('with_soundex')?"":($search->make_url(Array())."&with_soundex=1")); |
| 115 | |
| 116 | $nb_tot = $search->show(); |
| 117 | |
| 118 | if ($nb_tot > $globals->search->private_max) { |
| 119 | form_prepare(); |
| 120 | new ThrowError('Recherche trop générale'); |
| 121 | } |
| 122 | |
| 123 | } |
| 124 | |
| 125 | $page->assign('use_map', $globals->geoloc->use_map()); |
| 126 | |
| 127 | $page->register_modifier('display_lines', 'display_lines'); |
| 128 | $page->run(); |
| 129 | |
| 130 | // vim:set et sws=4 sw=4 sts=4: |
| 131 | ?> |