<?php
/***************************************************************************
- * Copyright (C) 2003-2008 Polytechnique.org *
+ * Copyright (C) 2003-2010 Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
u.perms IN (\'admin\',\'user\', \'disabled\') AS inscrit,
u.perms != \'pending\' AS wasinscrit,
FIND_IN_SET(\'femme\', u.flags) AS sexe,
- a.alias AS forlife,
- ad0.text AS app0text, ad0.url AS app0url, ai0.type AS app0type,
- ad1.text AS app1text, ad1.url AS app1url, ai1.type AS app1type,
- es.label AS secteur, ef.fonction_fr AS fonction,
- IF(n.nat=\'\',n.pays,n.nat) AS nat, n.a2 AS iso3166,
+ ede0.name AS eduname0, ede0.url AS eduurl0, edd0.degree AS edudegree0,
+ edu0.grad_year AS edugrad_year0, f0.field AS edufield0, edu0.program AS eduprogram0,
+ ede1.name AS eduname1, ede1.url AS eduurl1, edd1.degree AS edudegree1,
+ edu1.grad_year AS edugrad_year1, f1.field AS edufield1, edu1.program AS eduprogram1,
+ ede2.name AS eduname2, ede2.url AS eduurl2, edd2.degree AS edudegree2,
+ edu2.grad_year AS edugrad_year2, f2.field AS edufield2, edu2.program AS eduprogram2,
+ ede3.name AS eduname3, ede3.url AS eduurl3, edd3.degree AS edudegree3,
+ edu3.grad_year AS edugrad_year3, f3.field AS edufield3, edu3.program AS eduprogram3,
+ es.name AS secteur, ef.fonction_fr AS fonction,
+ IF(n1.nat=\'\',n1.pays,n1.nat) AS nat1, n1.a2 AS iso3166_1,
+ IF(n2.nat=\'\',n2.pays,n2.nat) AS nat2, n2.a2 AS iso3166_2,
+ IF(n3.nat=\'\',n3.pays,n3.nat) AS nat3, n3.a2 AS iso3166_3,
(COUNT(em.email) > 0 OR FIND_IN_SET("googleapps", u.mail_storage) > 0) AS actif,';
// hide private information if not logged
if (S::logged())
$globals->search->result_fields .='
- q.profile_web AS web,
- q.profile_mobile AS mobile,
q.profile_freetext AS freetext,
adr.city, gp.pays AS countrytxt, gr.name AS region,
- e.entreprise,';
+ ee.name,
+ nw.address AS networking_address,
+ nwe.name AS networking_name,';
else
$globals->search->result_fields .="
- IF(q.profile_web_pub='public', q.profile_web, '') AS web,
- IF(q.profile_mobile_pub='public', q.profile_mobile, '') AS mobile,
IF(q.profile_freetext_pub='public', q.profile_freetext, '') AS freetext,
- IF(adr.pub='public', adr.city, '') AS city,
- IF(adr.pub='public', gp.pays, '') AS countrytxt,
- IF(adr.pub='public', gr.name, '') AS region,
- IF(e.pub='public', e.entreprise, '') AS entreprise,";
-@$globals->search->result_where_statement = '
- LEFT JOIN applis_ins AS ai0 ON (u.user_id = ai0.uid AND ai0.ordre = 0)
- LEFT JOIN applis_def AS ad0 ON (ad0.id = ai0.aid)
- LEFT JOIN applis_ins AS ai1 ON (u.user_id = ai1.uid AND ai1.ordre = 1)
- LEFT JOIN applis_def AS ad1 ON (ad1.id = ai1.aid)
- LEFT JOIN entreprises AS e ON (e.entrid = 0 AND e.uid = u.user_id)
- LEFT JOIN emploi_secteur AS es ON (e.secteur = es.id)
- LEFT JOIN fonctions_def AS ef ON (e.fonction = ef.id)
- LEFT JOIN geoloc_pays AS n ON (u.nationalite = n.a2)
- LEFT JOIN adresses AS adr ON (u.user_id = adr.uid AND FIND_IN_SET(\'active\',adr.statut))
- LEFT JOIN geoloc_pays AS gp ON (adr.country = gp.a2)
- LEFT JOIN geoloc_region AS gr ON (adr.country = gr.a2 AND adr.region = gr.region)
- LEFT JOIN emails AS em ON (em.uid = u.user_id AND em.flags = \'active\')';
+ IF(adr.pub='public', adr.city, '') AS city,
+ IF(adr.pub='public', gp.pays, '') AS countrytxt,
+ IF(adr.pub='public', gr.name, '') AS region,
+ IF(e.pub='public', je.name, '') AS entreprise,
+ IF(nw.pub='public', nw.address, '') AS networking_address,
+ IF(nw.pub='public', nwe.name, '') AS networking_name,";
+@$globals->search->result_where_statement = "
+ LEFT JOIN profile_education AS edu0 ON (u.user_id = edu0.pid AND edu0.id = 0)
+ LEFT JOIN profile_education_enum AS ede0 ON (ede0.id = edu0.eduid)
+ LEFT JOIN profile_education_degree_enum AS edd0 ON (edd0.id = edu0.degreeid)
+ LEFT JOIN profile_education_field_enum AS f0 ON (f0.id = edu0.fieldid)
+ LEFT JOIN profile_education AS edu1 ON (u.user_id = edu1.pid AND edu1.id = 1)
+ LEFT JOIN profile_education_enum AS ede1 ON (ede1.id = edu1.eduid)
+ LEFT JOIN profile_education_degree_enum AS edd1 ON (edd1.id = edu1.degreeid)
+ LEFT JOIN profile_education_field_enum AS f1 ON (f1.id = edu1.fieldid)
+ LEFT JOIN profile_education AS edu2 ON (u.user_id = edu2.pid AND edu2.id = 2)
+ LEFT JOIN profile_education_enum AS ede2 ON (ede2.id = edu2.eduid)
+ LEFT JOIN profile_education_degree_enum AS edd2 ON (edd2.id = edu2.degreeid)
+ LEFT JOIN profile_education_field_enum AS f2 ON (f2.id = edu2.fieldid)
+ LEFT JOIN profile_education AS edu3 ON (u.user_id = edu3.pid AND edu3.id = 3)
+ LEFT JOIN profile_education_enum AS ede3 ON (ede3.id = edu3.eduid)
+ LEFT JOIN profile_education_degree_enum AS edd3 ON (edd3.id = edu3.degreeid)
+ LEFT JOIN profile_education_field_enum AS f3 ON (f3.id = edu3.fieldid)
+ LEFT JOIN profile_job AS e ON (e.pid = u.user_id)
+ LEFT JOIN profile_job_enum AS ee ON (e.jobid = ee.id)
+ LEFT JOIN profile_job_sector_enum AS es ON (es.id = e.sectorid)
+ LEFT JOIN fonctions_def AS ef ON (e.fonction = ef.id)
+ LEFT JOIN geoloc_countries AS n1 ON (u.nationalite = n1.iso_3166_1_a2)
+ LEFT JOIN geoloc_countries AS n2 ON (u.nationalite2 = n2.iso_3166_1_a2)
+ LEFT JOIN geoloc_countries AS n3 ON (u.nationalite3 = n3.iso_3166_1_a2)
+ LEFT JOIN profile_addresses AS adr ON (u.user_id = adr.pid
+ AND FIND_IN_SET('current', adr.flags))
+ LEFT JOIN geoloc_countries AS gp ON (adr.countryId = gp.iso_3166_1_a2)
+ LEFT JOIN geoloc_administrativeareas AS gr ON (adr.countryId = gr.country
+ AND adr.administrativeAreaId = gr.id)
+ LEFT JOIN emails AS em ON (em.uid = u.user_id AND em.flags = 'active')
+ LEFT JOIN profile_networking AS nw ON (nw.pid = u.user_id)
+ LEFT JOIN profile_networking_enum AS nwe ON (nwe.network_type = nw.network_type)";
// }}}
// {{{ class ThrowError
global $globals;
$page =& Platal::page();
$page->changeTpl('search/index.tpl');
- $page->assign('pl_title','Polytechnique.org - Annuaire');
+ $page->setTitle('Polytechnique.org - Annuaire');
$page->assign('baseurl', $globals->baseurl);
$page->trigError($explain);
$page->run();
/** stores admin searches */
var $email;
var $ip;
+ /** stores phone number */
+ var $phone;
// }}}
// {{{ constructor
function isempty()
{
- return empty($this->strings) && empty($this->ranges) && empty($this->email) && empty($this->ip);
+ return empty($this->strings) && empty($this->ranges) && empty($this->email) && empty($this->ip) && empty($this->phone);
}
// }}}
$s = replace_accent(trim($this->value));
$r = $s = str_replace('*','%',$s);
- if (S::has_perms() && strpos($s, '@') !== false) {
+ if (S::admin() && strpos($s, '@') !== false) {
$this->email = $s;
- } else if (S::has_perms() && preg_match('/[0-9]+\.([0-9]+|%)\.([0-9]+|%)\.([0-9]+|%)/', $s)) {
+ } else if (S::admin() && preg_match('/[0-9]+\.([0-9]+|%)\.([0-9]+|%)\.([0-9]+|%)/', $s)) {
$this->ip = $s;
}
if ($this->email || $this->ip) {
foreach ($ranges as $r) {
if (preg_match('!^([<>]\d{4}|\d{4}(-\d{4})?)$!', $r)) $this->ranges[] = $r;
}
+
+ $t = preg_replace('!(\d{4}-\d{4}|>\d{4}|<\d{4})!', '', $s);
+ $t = preg_replace('![<>\- ]!', '', $t);
+ if (strlen($t) > 4) {
+ $this->phone = $t;
+ }
}
// }}}
if (Env::i('with_soundex') && strlen($s) > 1) {
$t = soundex_fr($s);
$where[] = "sn$i.soundex = '$t'";
+ } elseif (Env::i('exact')) {
+ $where[] = "sn$i.token = '$s'";
} else {
$t = str_replace('*', '%', $s).'%';
$t = str_replace('%%', '%', $t);
}
if (!empty($this->ip)) {
$ip = ip_to_uint($this->ip);
- $where[] = "( ls.ip = $ip OR ls.forward_ip = $ip ) AND ls.suid = 0";
+
+ // If the IP address requested for the search cannot be translated,
+ // the predicate should always be valued to false.
+ if ($ip != null) {
+ $where[] = "( ls.ip = $ip OR ls.forward_ip = $ip ) AND ls.suid = 0";
+ } else {
+ $where[] = "false";
+ }
+ }
+ if (!empty($this->phone)){
+ require_once("profil.func.inc.php");
+ $phone = format_phone_number($this->phone) . "%";
+ $where[] = 't.search_tel LIKE ' . XDB::escape($phone);
}
return join(" AND ", $where);
$join .= "LEFT JOIN emails AS ems ON (ems.uid = u.user_id)";
}
if (!empty($this->ip)) {
- $join .= "INNER JOIN logger.sessions AS ls ON (ls.uid = u.user_id)\n";
+ $join .= "INNER JOIN log_sessions AS ls ON (ls.uid = u.user_id)\n";
+ }
+ if (!empty($this->phone)) {
+ if (!S::logged()) {
+ $join .= "INNER JOIN profile_phones AS t ON (t.pid = u.user_id AND t.pub = 'public')";
+ } else {
+ $join .= "INNER JOIN profile_phones AS t ON (t.pid = u.user_id)";
+ }
}
return $join;
}
function too_large()
{
- return ($this->value=='');
+ return ($this->value == '');
}
// }}}
function compare()
{
$val = addslashes($this->value);
+ if (Env::i('exact')) return "='$val'";
return $this->exact ? "='$val'" : " LIKE '%$val%'";
}
// }}}
// {{{ class RefSFieldMultipleTable
+class PhoneSField extends RefSField
+{
+ function PhoneSField($_fieldFormName, $_fieldDbName='', $_refTable, $_refAlias, $_refCondition)
+ {
+ $this->RefSField($_fieldFormName, $_fieldDbName, $_refTable, $_refAlias, $_refCondition, true);
+ }
+
+ function get_request()
+ {
+ require_once("profil.func.inc.php");
+ $this->value = trim(Env::v($this->fieldFormName));
+ $this->value = format_phone_number($this->value);
+ }
+
+ function compare()
+ {
+ return " LIKE '" . addslashes($this->value) . "%'";
+ }
+}
+
+class IndexSField extends RefSField
+{
+ function IndexSField($_fieldFormName, $_fieldDbName='', $_refTable, $_refAlias, $_refCondition)
+ {
+ $this->RefSField($_fieldFormName, $_fieldDbName, $_refTable, $_refAlias, $_refCondition, true);
+ }
+
+ function get_request()
+ {
+ $this->value = trim(Env::v($this->fieldFormName));
+ }
+}
+
class MapSField extends RefSField
{
var $mapId;
* imposées par l'utilisateur) */
function length()
{
- $cleaned = replace_accent(strtolower($this->value));
+ $cleaned = strtolower(replace_accent($this->value));
$length = strlen(ereg_replace('[a-z0-9]', '', $cleaned));
return strlen($this->value) - $length;
}
function too_large()
{
- return ($this->length()<2);
+ return ($this->length() < 2);
}
// }}}
* @param field nom de champ de la bdd concerné par la clause */
function get_single_where_statement($field)
{
- $regexp = strtr(addslashes($this->value), '-*', '_%');
+ $val = addslashes($this->value);
+ if (Env::i('exact')) return "$field = '$val'";
+ $regexp = strtr($val, '-*', '_%');
return "$field LIKE '$regexp%'";
}
function get_single_where_statement($field)
{
- $regexp = strtr(addslashes($this->value), '-*', '_%');
+ $val = addslashes($this->value);
+ if (Env::i('exact')) return "$field = '$val'";
+ $regexp = strtr($val, '-*', '_%');
return "$field LIKE '$regexp%' OR $field LIKE '% $regexp%' OR $field LIKE '%-$regexp%'";
}
{
$this->fields = $_fields;
$this->and = $_and;
- foreach ($this->fields as $key=>&$field) {
- if (is_null($field)) {
- unset($this->fields[$key]);
+
+ $cleanFields = array();
+ foreach ($this->fields as $field) {
+ if (!is_null($field)) {
+ $cleanFields[] = $field;
}
}
+ $this->fields = $cleanFields;
}
// }}}
function too_large()
{
$b = true;
- for ($i=0 ; $b && $i<count($this->fields) ; $i++) {
+ for ($i = 0; $b && $i < count($this->fields); ++$i) {
if (!is_null($this->fields[$i])) {
$b = $b && $this->fields[$i]->too_large();
}