From 09824164d53588cb261dc88ca699739d164a991b Mon Sep 17 00:00:00 2001 From: x2000habouzit Date: Tue, 4 Jul 2006 19:15:00 +0000 Subject: [PATCH] migrate search module. git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@364 839d8a87-29fc-0310-9880-83ba4fa771e5 --- ChangeLog | 6 +- hooks/search.inc.php | 4 +- htdocs/advanced_search.php | 130 ----------- htdocs/search.php | 98 --------- install.d/search.files | 2 - modules/search.php | 237 +++++++++++++++++++++ templates/carnet/notifs.tpl | 2 +- templates/docs/services.tpl | 2 +- templates/geoloc/index.tpl | 2 +- templates/index.tpl | 2 +- templates/marketing/index.tpl | 2 +- .../{search.adv.form.tpl => search/adv.form.tpl} | 2 +- .../{search.adv.links.tpl => search/adv.links.tpl} | 2 +- templates/{search.tpl => search/index.tpl} | 12 +- .../quick.form.tpl} | 4 +- templates/{search.quick.tpl => search/quick.tpl} | 2 +- templates/skin/common.header.tpl | 2 +- templates/skin/common.title.header.tpl | 2 +- 18 files changed, 262 insertions(+), 251 deletions(-) delete mode 100644 htdocs/advanced_search.php delete mode 100644 htdocs/search.php create mode 100644 modules/search.php rename templates/{search.adv.form.tpl => search/adv.form.tpl} (99%) rename templates/{search.adv.links.tpl => search/adv.links.tpl} (97%) rename templates/{search.tpl => search/index.tpl} (92%) rename templates/{search.quick.form.tpl => search/quick.form.tpl} (94%) rename templates/{search.quick.tpl => search/quick.tpl} (98%) diff --git a/ChangeLog b/ChangeLog index 56dbca4..90e7d3c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,7 +7,11 @@ New: - Work hard to add nice URI's into Platal. -MC * Emails: - - Switch to the new URI scheme, into email module. -MC + - Switch to the new URI scheme. -MC + + * Search: + - Switch to the new URI scheme. -MC + ================================================================================ VERSION 0.9.10 29 Juin 2006 diff --git a/hooks/search.inc.php b/hooks/search.inc.php index 0559161..f102adb 100644 --- a/hooks/search.inc.php +++ b/hooks/search.inc.php @@ -52,8 +52,8 @@ function search_subscribe($forlife, $uid, $promo, $pass) function search_menu() { global $globals; - $globals->menu->addPrivateEntry(XOM_GROUPS, 00, 'Annuaire', 'search.php'); - $globals->menu->addPublicEntry(XOM_EXT, 00, 'Annuaire de l\'X', 'search.php'); + $globals->menu->addPrivateEntry(XOM_GROUPS, 00, 'Annuaire', 'search'); + $globals->menu->addPublicEntry(XOM_EXT, 00, 'Annuaire de l\'X', 'search'); } // }}} diff --git a/htdocs/advanced_search.php b/htdocs/advanced_search.php deleted file mode 100644 index 802a693..0000000 --- a/htdocs/advanced_search.php +++ /dev/null @@ -1,130 +0,0 @@ -assign('advanced',1); -$page->assign('public_directory',0); -$page->assign('use_map', $globals->geoloc->use_map()); -require_once("applis.func.inc.php"); -require_once("geoloc.inc.php"); - -// {{{ function form_prepare() - -function form_prepare() -{ - global $page,$globals; - $page->assign('formulaire',1); - $page->assign('choix_nats', $globals->xdb->iterator('SELECT a2 AS id,IF(nat=\'\',pays,nat) AS text FROM geoloc_pays ORDER BY text')); - $page->assign('choix_postes', $globals->xdb->iterator('SELECT id,fonction_fr FROM fonctions_def ORDER BY fonction_fr')); - $page->assign('choix_binets', $globals->xdb->iterator('SELECT id,text FROM binets_def ORDER BY text')); - $page->assign('choix_groupesx', $globals->xdb->iterator('SELECT id,text FROM groupesx_def ORDER BY text')); - $page->assign('choix_sections', $globals->xdb->iterator('SELECT id,text FROM sections ORDER BY text')); - $page->assign('choix_schools', $globals->xdb->iterator('SELECT id,text FROM applis_def ORDER BY text')); - $page->assign('choix_secteurs', $globals->xdb->iterator('SELECT id,label FROM emploi_secteur ORDER BY label')); - - if (Env::has('school')) { - $sql = 'SELECT type FROM applis_def WHERE id='.Env::getInt('school'); - } else { - $sql = 'DESCRIBE applis_def type'; - } - $res = $globals->xdb->query($sql); - $row = $res->fetchOneRow(); - if (Env::has('school')) { - $types = $row[0]; - } else { - $types = explode('(',$row[1]); - $types = str_replace("'","",substr($types[1],0,-1)); - } - $page->assign('choix_diplomas', explode(',',$types)); -} - -// }}} - -if (!Env::has('rechercher')) { - form_prepare(); -} else { - -// {{{ function get_list() - - function get_list($offset, $limit, $order) { - $fields = new SFieldGroup(true, advancedSearchFromInput()); - if ($fields->too_large()) { - form_prepare(); - new ThrowError('Recherche trop générale.'); - } - global $globals, $page; - - $page->assign('search_vars', $fields->get_url()); - - $where = $fields->get_where_statement(); - if ($where) { - $where = "WHERE $where"; - } - $sql = 'SELECT SQL_CALC_FOUND_ROWS DISTINCT - u.nom, u.prenom, - '.$globals->search->result_fields.' - c.uid AS contact, - w.ni_id AS watch - FROM auth_user_md5 AS u - LEFT JOIN auth_user_quick AS q USING(user_id) - '.$fields->get_select_statement().' - '.(Env::has('only_referent') ? ' INNER JOIN mentor AS m ON (m.uid = u.user_id)' : '').' - LEFT JOIN aliases AS a ON (u.user_id = a.id AND a.type="a_vie") - LEFT JOIN contacts AS c ON (c.uid='.Session::getInt('uid').' AND c.contact=u.user_id) - LEFT JOIN watch_nonins AS w ON (w.ni_id=u.user_id AND w.uid='.Session::getInt('uid').') - '.$globals->search->result_where_statement." - $where - ORDER BY ".($order?($order.', '):'') - .implode(',',array_filter(array($fields->get_order_statement(), 'promo DESC, NomSortKey, prenom'))).' - LIMIT '.($offset * $limit).','.$limit; - $liste = $globals->xdb->iterator($sql); - $res = $globals->xdb->query("SELECT FOUND_ROWS()"); - $nb_tot = $res->fetchOneCell(); - return Array($liste, $nb_tot); - } - -// }}} - - $search = new XOrgSearch('get_list'); - $search->setNbLines($globals->search->per_page); - - $page->assign('url_search_form', $search->make_url(Array('rechercher'=>0))); - $page->assign('with_soundex', Env::has('with_soundex')?"":($search->make_url(Array())."&with_soundex=1")); - - $nb_tot = $search->show(); - - if ($nb_tot > $globals->search->private_max) { - form_prepare(); - new ThrowError('Recherche trop générale'); - } - -} - -$page->register_modifier('display_lines', 'display_lines'); -$page->run(); - -// vim:set et sws=4 sw=4 sts=4: -?> diff --git a/htdocs/search.php b/htdocs/search.php deleted file mode 100644 index 25ac38e..0000000 --- a/htdocs/search.php +++ /dev/null @@ -1,98 +0,0 @@ -assign('xorg_title','Polytechnique.org - Annuaire'); -require_once("applis.func.inc.php"); -require_once("geoloc.inc.php"); - -$page->assign('baseurl', $globals->baseurl); - -if (Env::has('quick')) { - $page->assign('formulaire', 0); - - // {{{ get_list - function get_list($offset, $limit, $order) { - global $globals; - $qSearch = new QuickSearch('quick'); - $fields = new SFieldGroup(true, array($qSearch)); - - if ($qSearch->isempty()) { - new ThrowError('Recherche trop générale.'); - } - - $sql = 'SELECT SQL_CALC_FOUND_ROWS - UPPER(IF(u.nom!="",u.nom,u.nom_ini)) AS nom, - IF(u.prenom!="",u.prenom,u.prenom_ini) AS prenom, - '.$globals->search->result_fields.' - c.uid AS contact, - w.ni_id AS watch, - '.$qSearch->get_score_statement().' - FROM auth_user_md5 AS u - '.$fields->get_select_statement().' - LEFT JOIN auth_user_quick AS q ON (u.user_id = q.user_id) - LEFT JOIN aliases AS a ON (u.user_id = a.id AND a.type="a_vie") - LEFT JOIN contacts AS c ON (c.uid='.Session::getInt('uid').' AND c.contact=u.user_id) - LEFT JOIN watch_nonins AS w ON (w.ni_id=u.user_id AND w.uid='.Session::getInt('uid').') - '.$globals->search->result_where_statement.' - WHERE '.$fields->get_where_statement().(logged() && Env::has('nonins') ? ' AND u.perms="pending" AND u.deces=0' : '').' - GROUP BY u.user_id - ORDER BY '.($order?($order.', '):'') - .implode(',',array_filter(array($fields->get_order_statement(), 'u.promo DESC, NomSortKey, prenom'))).' - LIMIT '.$offset * $globals->search->per_page.','.$globals->search->per_page; - $list = $globals->xdb->iterator($sql); - $res = $globals->xdb->query("SELECT FOUND_ROWS()"); - $nb_tot = $res->fetchOneCell(); - return array($list, $nb_tot); - } - - // }}} - - $search = new XOrgSearch(get_list); - $search->setNbLines($globals->search->per_page); - $search->addOrder('score', 'score', false, 'pertinence', AUTH_PUBLIC, true); - - $nb_tot = $search->show(); - - if (!logged() && $nb_tot > $globals->search->public_max) { - new ThrowError('Votre recherche a généré trop de résultats pour un affichage public.'); - } elseif ($nb_tot > $globals->search->private_max) { - new ThrowError('Recherche trop générale'); - } elseif (empty($nb_tot)) { - new ThrowError('il n\'existe personne correspondant à ces critères dans la base !'); - } - -} else { - $page->assign('formulaire',1); -} - -$page->register_modifier('display_lines', 'display_lines'); -$page->run(); - -// vim:set et sws=4 sw=4 sts=4: -?> diff --git a/install.d/search.files b/install.d/search.files index 9f333ce..3f345bb 100644 --- a/install.d/search.files +++ b/install.d/search.files @@ -1,5 +1,3 @@ -htdocs/advanced_search.php -htdocs/search.php include/search.inc.php bin/cron/recherche.php templates/search.adv.form.tpl diff --git a/modules/search.php b/modules/search.php new file mode 100644 index 0000000..3400caf --- /dev/null +++ b/modules/search.php @@ -0,0 +1,237 @@ + $this->make_hook('quick', AUTH_PUBLIC), + 'search/adv' => $this->make_hook('advanced', AUTH_COOKIE), + ); + } + + function get_quick($offset, $limit, $order) + { + global $globals; + $qSearch = new QuickSearch('quick'); + $fields = new SFieldGroup(true, array($qSearch)); + + if ($qSearch->isempty()) { + new ThrowError('Recherche trop générale.'); + } + + $sql = 'SELECT SQL_CALC_FOUND_ROWS + UPPER(IF(u.nom!="",u.nom,u.nom_ini)) AS nom, + IF(u.prenom!="",u.prenom,u.prenom_ini) AS prenom, + '.$globals->search->result_fields.' + c.uid AS contact, w.ni_id AS watch, + '.$qSearch->get_score_statement().' + FROM auth_user_md5 AS u + '.$fields->get_select_statement().' + LEFT JOIN auth_user_quick AS q ON (u.user_id = q.user_id) + LEFT JOIN aliases AS a ON (u.user_id = a.id AND a.type="a_vie") + LEFT JOIN contacts AS c ON (c.uid='.Session::getInt('uid').' + AND c.contact=u.user_id) + LEFT JOIN watch_nonins AS w ON (w.ni_id=u.user_id + AND w.uid='.Session::getInt('uid').') + '.$globals->search->result_where_statement.' + WHERE '.$fields->get_where_statement() + .(logged() && Env::has('nonins') ? ' AND u.perms="pending" AND u.deces=0' : '') + .' + GROUP BY u.user_id + ORDER BY '.($order?($order.', '):'') + .implode(',',array_filter(array($fields->get_order_statement(), + 'u.promo DESC, NomSortKey, prenom'))).' + LIMIT '.$offset * $globals->search->per_page.',' + .$globals->search->per_page; + $list = $globals->xdb->iterator($sql); + $res = $globals->xdb->query("SELECT FOUND_ROWS()"); + $nb_tot = $res->fetchOneCell(); + return array($list, $nb_tot); + } + + function form_prepare() + { + global $page,$globals; + + $page->assign('formulaire',1); + $page->assign('choix_nats', + $globals->xdb->iterator('SELECT a2 AS id,IF(nat=\'\',pays,nat) AS text + FROM geoloc_pays ORDER BY text')); + $page->assign('choix_postes', + $globals->xdb->iterator('SELECT id,fonction_fr FROM fonctions_def + ORDER BY fonction_fr')); + $page->assign('choix_binets', + $globals->xdb->iterator('SELECT id,text FROM binets_def ORDER BY text')); + $page->assign('choix_groupesx', + $globals->xdb->iterator('SELECT id,text FROM groupesx_def ORDER BY text')); + $page->assign('choix_sections', + $globals->xdb->iterator('SELECT id,text FROM sections ORDER BY text')); + $page->assign('choix_schools', + $globals->xdb->iterator('SELECT id,text FROM applis_def ORDER BY text')); + $page->assign('choix_secteurs', + $globals->xdb->iterator('SELECT id,label FROM emploi_secteur ORDER BY label')); + + if (Env::has('school')) { + $sql = 'SELECT type FROM applis_def WHERE id='.Env::getInt('school'); + } else { + $sql = 'DESCRIBE applis_def type'; + } + + $res = $globals->xdb->query($sql); + $row = $res->fetchOneRow(); + if (Env::has('school')) { + $types = $row[0]; + } else { + $types = explode('(',$row[1]); + $types = str_replace("'","",substr($types[1],0,-1)); + } + $page->assign('choix_diplomas', explode(',',$types)); + } + + function get_advanced($offset, $limit, $order) + { + $fields = new SFieldGroup(true, advancedSearchFromInput()); + if ($fields->too_large()) { + $this->form_prepare(); + new ThrowError('Recherche trop générale.'); + } + global $globals, $page; + + $page->assign('search_vars', $fields->get_url()); + + $where = $fields->get_where_statement(); + if ($where) { + $where = "WHERE $where"; + } + $sql = 'SELECT SQL_CALC_FOUND_ROWS DISTINCT + u.nom, u.prenom, + '.$globals->search->result_fields.' + c.uid AS contact, + w.ni_id AS watch + FROM auth_user_md5 AS u + LEFT JOIN auth_user_quick AS q USING(user_id) + '.$fields->get_select_statement().' + '.(Env::has('only_referent') ? ' INNER JOIN mentor AS m ON (m.uid = u.user_id)' : '').' + LEFT JOIN aliases AS a ON (u.user_id = a.id AND a.type="a_vie") + LEFT JOIN contacts AS c ON (c.uid='.Session::getInt('uid').' + AND c.contact=u.user_id) + LEFT JOIN watch_nonins AS w ON (w.ni_id=u.user_id + AND w.uid='.Session::getInt('uid').') + '.$globals->search->result_where_statement." + $where + ORDER BY ".($order?($order.', '):'') + .implode(',',array_filter(array($fields->get_order_statement(), + 'promo DESC, NomSortKey, prenom'))).' + LIMIT '.($offset * $limit).','.$limit; + $liste = $globals->xdb->iterator($sql); + $res = $globals->xdb->query("SELECT FOUND_ROWS()"); + $nb_tot = $res->fetchOneCell(); + return Array($liste, $nb_tot); + } + + function handler_quick(&$page) + { + global $globals; + + require_once 'search.inc.php'; + + $page->changeTpl('search/index.tpl'); + + $page->assign('xorg_title','Polytechnique.org - Annuaire'); + require_once("applis.func.inc.php"); + require_once("geoloc.inc.php"); + + $page->assign('baseurl', $globals->baseurl); + + if (Env::has('quick')) { + $page->assign('formulaire', 0); + + $search = new XOrgSearch(array($this, 'get_quick')); + $search->setNbLines($globals->search->per_page); + $search->addOrder('score', 'score', false, 'pertinence', AUTH_PUBLIC, true); + + $nb_tot = $search->show(); + + if (!logged() && $nb_tot > $globals->search->public_max) { + new ThrowError('Votre recherche a généré trop de résultats pour un affichage public.'); + } elseif ($nb_tot > $globals->search->private_max) { + new ThrowError('Recherche trop générale'); + } elseif (empty($nb_tot)) { + new ThrowError('il n\'existe personne correspondant à ces critères dans la base !'); + } + } else { + $page->assign('formulaire',1); + } + + $page->register_modifier('display_lines', 'display_lines'); + + return PL_OK; + } + + function handler_advanced(&$page, $mode = null) + { + global $globals; + + require_once 'search.inc.php' ; + require_once 'applis.func.inc.php'; + require_once 'geoloc.inc.php'; + + + $page->changeTpl('search/index.tpl'); + + if ($mode == 'mini') { + $page->assign('simple', true); + } + + $page->assign('advanced',1); + $page->assign('public_directory',0); + $page->assign('use_map', $globals->geoloc->use_map()); + + if (!Env::has('rechercher')) { + $this->form_prepare(); + } else { + + $search = new XOrgSearch('get_list'); + $search->setNbLines($globals->search->per_page); + + $page->assign('url_search_form', $search->make_url(Array('rechercher'=>0))); + if (Env::has('with_soundex')) { + $page->assign('with_soundex', $search->make_url(Array())."&with_soundex=1"); + } + + $nb_tot = $search->show(); + + if ($nb_tot > $globals->search->private_max) { + $this->form_prepare(); + new ThrowError('Recherche trop générale'); + } + + } + + $page->register_modifier('display_lines', 'display_lines'); + + return PL_OK; + } +} + +?> diff --git a/templates/carnet/notifs.tpl b/templates/carnet/notifs.tpl index 7d954a5..878e199 100644 --- a/templates/carnet/notifs.tpl +++ b/templates/carnet/notifs.tpl @@ -99,7 +99,7 @@ Si un non-inscrit que tu surveilles s'inscrit, il sera automatiquement ajout

-Pour surveiller des membres non-inscrits, il faut passer par la recherche +Pour surveiller des membres non-inscrits, il faut passer par la recherche et cliquer sur les icones Ajouter pour les ajouter à cette liste

diff --git a/templates/docs/services.tpl b/templates/docs/services.tpl index 68b1ad2..c414d83 100644 --- a/templates/docs/services.tpl +++ b/templates/docs/services.tpl @@ -41,7 +41,7 @@ antispam.

-Le site héberge également un annuaire complet que +Le site héberge également un annuaire complet que tu peux consulter pour obtenir des renseignements sur un camarade, sur tes cocons. Il te permet aussi d'enrichir et de compléter ta fiche personnelle. Cet annuaire a une vocation professionnelle puisque diff --git a/templates/geoloc/index.tpl b/templates/geoloc/index.tpl index 00a10c4..122cace 100644 --- a/templates/geoloc/index.tpl +++ b/templates/geoloc/index.tpl @@ -74,7 +74,7 @@ function searchMapId(f)

Carte fournie gracieusement par Geodesix.

{if !$no_annu} -
+

diff --git a/templates/index.tpl b/templates/index.tpl index b7af15e..5d2d697 100644 --- a/templates/index.tpl +++ b/templates/index.tpl @@ -46,7 +46,7 @@
Dans tous les cas, vous pouvez : diff --git a/templates/marketing/index.tpl b/templates/marketing/index.tpl index 18e6004..c7ba536 100644 --- a/templates/marketing/index.tpl +++ b/templates/marketing/index.tpl @@ -32,7 +32,7 @@ - Chercher un non inscrit + Chercher un non inscrit   |   Marketing promo   |   diff --git a/templates/search.adv.form.tpl b/templates/search/adv.form.tpl similarity index 99% rename from templates/search.adv.form.tpl rename to templates/search/adv.form.tpl index 5d65c14..6da13d9 100644 --- a/templates/search.adv.form.tpl +++ b/templates/search/adv.form.tpl @@ -22,7 +22,7 @@

Recherche avancée

-

[Recherche simple]

+

[Recherche simple]

diff --git a/templates/search.adv.links.tpl b/templates/search/adv.links.tpl similarity index 97% rename from templates/search.adv.links.tpl rename to templates/search/adv.links.tpl index 6a61cd9..6abf952 100644 --- a/templates/search.adv.links.tpl +++ b/templates/search/adv.links.tpl @@ -40,7 +40,7 @@
  • Effectuer une nouvelle - recherche simple + recherche simple
  • diff --git a/templates/search.tpl b/templates/search/index.tpl similarity index 92% rename from templates/search.tpl rename to templates/search/index.tpl index 61cee13..823ca34 100644 --- a/templates/search.tpl +++ b/templates/search/index.tpl @@ -24,9 +24,9 @@ {if $formulaire==0 and !$xorg_errors|count} {if !$simple} {if !$advanced} - {include file='search.quick.form.tpl' show_js=1} + {include file=search/quick.form.tpl show_js=1} {else} - {include file=search.adv.links.tpl do_title=1 with_soundex=$with_soundex} + {include file=search/adv.links.tpl do_title=1 with_soundex=$with_soundex} {/if} {/if} @@ -86,9 +86,9 @@
    {if $smarty.capture.list|smarty:nodefaults|display_lines > 20} {if $advanced} - {include file=search.adv.links.tpl do_title=1} + {include file=search/adv.links.tpl do_title=1} {else} - {include file='search.quick.form.tpl'} + {include file=search/quick.form.tpl} {/if} {/if} @@ -98,9 +98,9 @@ {/min_auth} {else} {if $advanced} - {include file="search.adv.form.tpl"} + {include file=search/adv.form.tpl} {else} - {include file="search.quick.tpl"} + {include file=search/quick.tpl} {/if} {/if} diff --git a/templates/search.quick.form.tpl b/templates/search/quick.form.tpl similarity index 94% rename from templates/search.quick.form.tpl rename to templates/search/quick.form.tpl index 6019153..466faf4 100644 --- a/templates/search.quick.form.tpl +++ b/templates/search/quick.form.tpl @@ -22,7 +22,7 @@

    Recherche simple dans l'annuaire

    - +
    diff --git a/templates/search.quick.tpl b/templates/search/quick.tpl similarity index 98% rename from templates/search.quick.tpl rename to templates/search/quick.tpl index 8e37381..09bd0c8 100644 --- a/templates/search.quick.tpl +++ b/templates/search/quick.tpl @@ -20,7 +20,7 @@ {* *} {**************************************************************************} -{include file="search.quick.form.tpl" show_js=1} +{include file=search/quick.form.tpl show_js=1}

    Comment faire une recherche ?

    Nom, Prenom, Promo ...

    diff --git a/templates/skin/common.header.tpl b/templates/skin/common.header.tpl index 41b1f06..9f516e7 100644 --- a/templates/skin/common.header.tpl +++ b/templates/skin/common.header.tpl @@ -28,7 +28,7 @@ - + diff --git a/templates/skin/common.title.header.tpl b/templates/skin/common.title.header.tpl index 4edc86f..1ad7fda 100644 --- a/templates/skin/common.title.header.tpl +++ b/templates/skin/common.title.header.tpl @@ -30,7 +30,7 @@
    @@ -38,7 +38,7 @@ {min_auth level="cookie"} -
    Recherche avancée +
    Recherche avancée {/min_auth}
    {insert name="getNbIns"} polytechniciens sur le web - +
    -- 2.1.4