$page->assign('photo_incitation', $res->fetchOneCell() == 0);
// Geo-location onebox.
- require_once 'geoloc.inc.php';
- $res = localize_addresses(S::user()->id());
- $page->assign('geoloc_incitation', count($res));
+ require_once "geocoding.inc.php";
+ $page->assign('geoloc_incitation', Geocoder::countNonGeocoded(S::user()->id()));
// Direct link to the RSS feed, when available.
- if (S::rssActivated()) {
+ if (S::hasAuthToken()) {
$page->setRssLink('Polytechnique.org :: News',
- '/rss/'.S::v('hruid') .'/'.S::v('core_rss_hash').'/rss.xml');
+ '/rss/'.S::v('hruid') .'/'.S::v('token').'/rss.xml');
}
// Hide the read event, and reload the page to get to the next event.
$this->val_number = $val;
}
- // }}}
- // {{{ function form()
-
function prepareform(&$pay)
{
- // toute la doc sur :
- // https://www.paypal.com/fr_FR/pdf/integration_guide.pdf
- // attention : le renvoi automatique ne fonctionne que si
- // on oblige les gens à créer un compte paypal
- // nous ne l'utilisons pas ; il faut donc que l'utilisateur
- // revienne sur le site
+ // Documentation:
+ // https://www.paypal.com/developer
+ // Warning: the automatic return only works if we force the
+ // users to create a paypal account. We do not use it; thus
+ // the user must come back on the site.
global $globals, $platal;
- $this->urlform = 'https://'.$globals->money->paypal_site.'/cgi-bin/webscr';
+ $this->urlform = 'https://' . $globals->money->paypal_site . '/cgi-bin/webscr';
- $req = XDB::query("SELECT IF(nom_usage!='', nom_usage, nom) AS nom
- FROM auth_user_md5
- WHERE user_id = {?}", S::v('uid'));
- $name = $req->fetchOneCell();
+ $user = S::user();
+ $name = $user->lastName();
$roboturl = str_replace("https://","http://",$globals->baseurl)
- . '/' . $platal->ns . "payment/paypal_return/".S::v('uid')."?comment=".urlencode(Env::v('comment'));
+ . '/' . $platal->ns . "payment/paypal_return/" . S::v('uid')
+ . "?comment=" . urlencode(Env::v('comment'));
- $this->infos = Array();
+ $this->infos = array();
- $this->infos['commercant'] = Array(
+ $this->infos['commercant'] = array(
'business' => $globals->money->paypal_compte,
- 'rm' => 2,
+ 'rm' => 2,
'return' => $roboturl,
- 'cn' => 'Commentaires',
+ 'cn' => 'Commentaires',
'no_shipping' => 1,
'cbt' => empty($GLOBALS['IS_XNET_SITE']) ?
- 'Revenir sur polytechnique.org' :
- 'Revenir sur polytechnique.net');
+ 'Revenir sur polytechnique.org.' :
+ 'Revenir sur polytechnique.net.'
+ );
- $info_client = Array(
+ $info_client = array(
'first_name' => S::v('prenom'),
'last_name' => $name,
- 'email' => S::user()->bestEmail());
+ 'email' => S::user()->bestEmail()
+ );
+ // XXX: waiting for port of adresses.
$res = XDB::query(
- "SELECT a.adr1 AS address1, a.adr2 AS address2,
- a.city, a.postcode AS zip, a.country,
- IF(t1.display_tel != '', t1.display_tel, t2.display_tel) AS night_phone_b
- FROM auth_user_quick AS q
- LEFT JOIN adresses AS a ON (q.user_id = a.uid AND FIND_IN_SET('active', a.statut))
- LEFT JOIN profile_phones AS t1 ON (t1.uid = a.uid AND t1.link_type = 'address' AND t1.link_id = a.adrid)
- LEFT JOIN profile_phones AS t2 ON (t2.uid = a.uid AND t2.link_type = 'user' AND t2.link_id = 0)
- WHERE q.user_id = {?}
- LIMIT 1", S::v('uid'));
+ "SELECT a.text, l.name AS city, a.postalCode AS zip, a.countryiId AS country,
+ IF(t1.display_tel != '', t1.display_tel, t2.display_tel) AS night_phone_b
+ FROM auth_user_quick AS q
+ LEFT JOIN profile_addresses AS a ON (q.user_id = a.pid AND FIND_IN_SET('current', a.flags))
+ LEFT JOIN profile_phones AS t1 ON (t1.uid = a.uid AND t1.link_type = 'address'
+ AND t1.link_id = a.adrid)
+ LEFT JOIN profile_phones AS t2 ON (t2.uid = a.uid AND t2.link_type = 'user'
+ AND t2.link_id = 0)
+ LEFT JOIN geoloc_localities AS l ON (l.id = a.localityId)
+ WHERE q.user_id = {?}
+ LIMIT 1",
+ S::v('uid'));
$this->infos['client'] = array_map('replace_accent', array_merge($info_client, $res->fetchOneAssoc()));
-
- // on constuit la reference de la transaction
- $prefix = ($pay->flags->hasflag('unique')) ? str_pad("",15,"0") : rand_url_id();
- $fullref = substr("$prefix-xorg-{$pay->id}",-15);
-
- $this->infos['commande'] = Array(
- 'item_name' => replace_accent($pay->text),
- 'amount' => $this->val_number,
+ list($this->infos['client']['address1'], $this->infos['client']['address2']) =
+ explode("\n", Geocoder::getFirstLines($this->infos['client']['text'],
+ $this->infos['client']['zip'], 2));
+ unset($this->infos['client']['text']);
+
+ // We build the transaction's reference
+ $prefix = ($pay->flags->hasflag('unique')) ? str_pad("", 15, "0") : rand_url_id();
+ $fullref = substr("$prefix-xorg-{$pay->id}", -15);
+
+ $this->infos['commande'] = array(
+ 'item_name' => replace_accent($pay->text),
+ 'amount' => $this->val_number,
'currency_code' => 'EUR',
- 'custom' => $fullref);
+ 'custom' => $fullref
+ );
- $this->infos['divers'] = Array('cmd' => '_xclick');
+ $this->infos['divers'] = array('cmd' => '_xclick');
}
-
- // }}}
}
$api = 'PayPal';
return $value;
}
- private function saveTel($addrid, $telid, array &$tel)
- {
- XDB::execute("INSERT INTO profile_phones (uid, link_type, link_id, tel_id, tel_type,
- search_tel, display_tel, pub)
- VALUES ({?}, 'address', {?}, {?}, {?},
- {?}, {?}, {?})",
- S::i('uid'), $addrid, $telid, $tel['type'],
- format_phone_number($tel['tel']), $tel['tel'], $tel['pub']);
- }
-
- private function saveAddress($addrid, array &$address)
+ private function saveAddress($pid, $adrid, array &$address)
{
+ require_once "geocoding.inc.php";
+
$flags = new PlFlagSet();
- $flags->addFlag('res-secondaire', $address['secondaire']);
- $flags->addFlag('courrier', $address['mail']);
- $flags->addFlag('temporaire', $address['temporary']);
- $flags->addFlag('active', $address['current']);
- $flags->addFlag('coord-checked', $address['checked']);
- XDB::execute("INSERT INTO adresses (adr1, adr2, adr3,
- postcode, city, cityid,
- country, region, regiontxt,
- pub, datemaj, statut,
- uid, adrid, glat, glng, comment)
- VALUES ({?}, {?}, {?},
- {?}, {?}, {?},
- {?}, {?}, {?},
- {?}, FROM_UNIXTIME({?}), {?},
- {?}, {?}, {?}, {?}, {?})",
- $address['adr1'], $address['adr2'], $address['adr3'],
- $address['postcode'], $address['city'], $address['cityid'],
- $address['country'], $address['region'], $address['regiontxt'],
- $address['pub'], $address['datemaj'], $flags,
- $pid, $adrid, $address['precise_lat'], $address['precise_lon'], $address['comment']);
- if ($address['current']) {
- $flags->addFlag('current');
- }
- if ($address['temporary']) {
- $flags->addFlag('temporary');
- }
- if ($address['secondary']) {
- $flags->addFlag('secondary');
- }
- if ($address['mail']) {
- $flags->addFlag('mail');
- }
- if ($address['cedex'] =
++ $flags->addFlag('current', $address['current']);
++ $flags->addFlag('temporary', $address['temporary']);
++ $flags->addFlag('secondary', $address['secondary']);
++ $flags->addFlag('mail', $address['mail']);
++ $flags->addFlag('cedex', $address['cedex'] =
+ (strpos(strtoupper(preg_replace(array("/[0-9,\"'#~:;_\- ]/", "/\r\n/"),
- array("", "\n"), $address['text'])), 'CEDEX')) !== false) {
- $flags->addFlag('cedex');
- }
++ array("", "\n"), $address['text'])), 'CEDEX')) !== false);
+ Geocoder::getAreaId($address, "administrativeArea");
+ Geocoder::getAreaId($address, "subAdministrativeArea");
+ Geocoder::getAreaId($address, "locality");
+ XDB::execute("INSERT INTO profile_addresses (pid, type, id, flags, accuracy,
+ text, postalText, postalCode, localityId,
+ subAdministrativeAreaId, administrativeAreaId,
+ countryId, latitude, longitude, updateTime, pub, comment,
+ north, south, east, west)
+ VALUES ({?}, 'home', {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?},
+ {?}, {?}, FROM_UNIXTIME({?}), {?}, {?}, {?}, {?}, {?}, {?})",
- S::i('uid'), $addrid, $flags, $address['accuracy'],
++ $pid, $addrid, $flags, $address['accuracy'],
+ $address['text'], $address['postalText'], $address['postalCode'], $address['localityId'],
+ $address['subAdministrativeAreaId'], $address['administrativeAreaId'],
+ $address['countryId'], $address['latitude'], $address['longitude'],
+ $address['updateTime'], $address['pub'], $address['comment'],
+ $address['north'], $address['south'], $address['east'], $address['west']);
}
public function save(ProfilePage &$page, $field, $value)
{
- XDB::execute("DELETE FROM adresses
- WHERE uid = {?}",
+ XDB::execute("DELETE FROM profile_addresses
+ WHERE pid = {?} AND type = 'home'",
- S::i('uid'));
+ $page->pid());
XDB::execute("DELETE FROM profile_phones
WHERE uid = {?} AND link_type = 'address'",
- S::i('uid'));
+ $page->pid());
- foreach ($value as $adrid=>&$address) {
- $this->saveAddress($page->pid(), $adrid, $address);
- $profiletel = new ProfilePhones('address', $adrid);
+ foreach ($value as $addrid => &$address) {
- $this->saveAddress($addrid, $address);
++ $this->saveAddress($page->pid(), $addrid, $address);
+ $profiletel = new ProfilePhones('address', $addrid);
- $profiletel->saveTels('tel', $address['tel']);
+ $profiletel->saveTels($page->pid(), 'tel', $address['tel']);
}
}
}
protected function _fetchData()
{
- // Build the addresses tree
- $res = XDB::query("SELECT a.adrid AS id, a.adr1, a.adr2, a.adr3,
- UNIX_TIMESTAMP(a.datemaj) AS datemaj,
- a.postcode, a.city, a.cityid, a.region, a.regiontxt,
- a.pub, a.country, gp.pays AS countrytxt, gp.display,
- FIND_IN_SET('coord-checked', a.statut) AS checked,
- FIND_IN_SET('res-secondaire', a.statut) AS secondaire,
- FIND_IN_SET('courrier', a.statut) AS mail,
- FIND_IN_SET('temporaire', a.statut) AS temporary,
- FIND_IN_SET('active', a.statut) AS current,
- a.glat AS precise_lat, a.glng AS precise_lon,
- a.comment
- FROM adresses AS a
- INNER JOIN geoloc_pays AS gp ON(gp.a2 = a.country)
- WHERE uid = {?} AND NOT FIND_IN_SET('pro', statut)
- ORDER BY adrid",
+ $res = XDB::query("SELECT type, id, accuracy, text, postalText,
+ postalCode, localityId, subAdministrativeAreaId, administrativeAreaId,
+ countryId, latitude, longitude, pub, comment, updateTime,
+ north, south, east, west,
+ FIND_IN_SET('current', flags) AS current,
+ FIND_IN_SET('temporary', flags) AS temporary,
+ FIND_IN_SET('secondary', flags) AS secondary,
+ FIND_IN_SET('mail', flags) AS mail,
+ FIND_IN_SET('cedex', flags) AS cedex
+ FROM profile_addresses
+ WHERE pid = {?} AND type = 'home'
+ ORDER BY id",
- S::i('uid'));
+ $this->pid());
if ($res->numRows() == 0) {
$this->values['addresses'] = array();
} else {
FROM profile_job AS j
LEFT JOIN profile_job_enum AS je ON (j.jobid = je.id)
LEFT JOIN entreprises AS e ON (j.uid = e.uid AND j.id = e.entrid)
- LEFT JOIN geoloc_pays AS gp ON (gp.a2 = e.country)
+ LEFT JOIN geoloc_countries AS gc ON (gc.iso_3166_1_a2 = e.country)
LEFT JOIN profile_job_subsubsector_enum AS s ON (s.id = j.subsubsectorid)
WHERE j.uid = {?}
- ORDER BY entrid", S::i('uid'));
+ ORDER BY entrid", $this->pid());
$this->values['jobs'] = array();
while (list($id, $name, $function, $secteur, $ss_secteur, $sss_secteur, $description,
$w_adr1, $w_adr2, $w_adr3, $w_postcode, $w_city, $w_cityid,
$success = true;
if (is_null($value)) {
$value = array();
- $res = XDB::iterRow("SELECT m.country, p.pays
+ $res = XDB::iterRow("SELECT m.country, gc.countryFR
FROM profile_mentor_country AS m
- INNER JOIN geoloc_pays AS p ON (m.country = p.a2)
+ INNER JOIN geoloc_countries AS gc ON (m.country = gc.iso_3166_1_a2)
WHERE m.uid = {?}",
- S::i('uid'));
+ $page->pid());
while (list($id, $name) = $res->next()) {
$value[$id] = $name;
}
switch ($type) {
case 'binetTxt':
- $db = '`binets_def` INNER JOIN
- `binets_ins` ON(`binets_def`.`id` = `binets_ins`.`binet_id`)';
- $field = '`binets_def`.`text`';
+ $db = 'binets_def INNER JOIN
+ binets_ins ON(binets_def.id = binets_ins.binet_id)';
+ $field = 'binets_def.text';
if (strlen($q) > 2)
$beginwith = false;
- $realid = '`binets_def`.`id`';
+ $realid = 'binets_def.id';
break;
case 'networking_typeTxt':
- $db = '`profile_networking_enum` INNER JOIN
- `profile_networking` ON(`profile_networking`.`network_type` = `profile_networking_enum`.`network_type`)';
- $field = '`profile_networking_enum`.`name`';
+ $db = 'profile_networking_enum INNER JOIN
+ profile_networking ON(profile_networking.network_type = profile_networking_enum.network_type)';
+ $field = 'profile_networking_enum.name';
$unique = 'uid';
- $realid = '`profile_networking_enum`.`network_type`';
+ $realid = 'profile_networking_enum.network_type';
break;
case 'city':
- $db = 'geoloc_city INNER JOIN
- adresses ON(geoloc_city.id = adresses.cityid)';
- $unique='uid';
- $field='geoloc_city.name';
+ $db = 'geoloc_localities INNER JOIN
+ profile_addresses ON (geoloc_localities.id = profile_addresses.localityId)';
+ $unique = 'uid';
+ $field ='geoloc_localities.name';
break;
case 'countryTxt':
- $db = 'geoloc_pays INNER JOIN
- adresses ON(geoloc_pays.a2 = adresses.country)';
- $unique = 'uid';
- $field = 'geoloc_pays.pays';
- $field2 = 'geoloc_pays.country';
- $realid = 'geoloc_pays.a2';
+ $db = 'geoloc_countries INNER JOIN
+ profile_addresses ON (geoloc_countries.iso_3166_1_a2 = profile_addresses.countryId)';
+ $unique = 'pid';
+ $field = 'geoloc_countries.countryFR';
+ $realid = 'geoloc_countries.iso_3166_1_a2';
break;
case 'entreprise':
$db = 'profile_job_enum INNER JOIN
$unique = 'm.uid';
break;
case 'nationaliteTxt':
- $db = 'geoloc_pays AS acgp
- INNER JOIN profiles AS acp ON (acgp.a2 IN (acp.nationality1, acp.nationality2, acp.nationality3))';
- $field = 'IF(acgp.nat = \'\', acgp.pays, acgp.nat)';
- $realid = 'acgp.a2';
+ $db = 'geoloc_countries INNER JOIN
- auth_user_md5 ON (geoloc_countries.a2 = auth_user_md5.nationalite
- OR geoloc_countries.a2 = auth_user_md5.nationalite2
- OR geoloc_countries.a2 = auth_user_md5.nationalite3)';
++ profile ON (geoloc_countries.a2 IN (profile.nationality1, profile.nationality2, profile.nationality3))';
+ $field = 'geoloc_countries.nationalityFR';
+ $realid = 'geoloc_countries.iso_3166_1_a2';
break;
case 'description':
$db = 'profile_job';
switch ($type) {
case 'binet':
- $db = '`binets_def`';
+ $db = 'binets_def';
break;
case 'networking_type':
- $db = '`profile_networking_enum`';
- $field = '`name`';
- $id = '`network_type`';
+ $db = 'profile_networking_enum';
+ $field = 'name';
+ $id = 'network_type';
break;
case 'country':
- $db = 'geoloc_pays';
- $field = 'pays';
- $id = 'a2';
+ $db = 'geoloc_countries';
+ $field = 'countryFR';
+ $id = 'iso_3166_1_a2';
$page->assign('onchange', 'changeCountry(this.value)');
break;
case 'fonction':
$field = 'nom';
break;
case 'nationalite':
- $db = 'geoloc_pays AS acgp INNER JOIN
+ $db = 'geoloc_countries INNER JOIN
- auth_user_md5 ON (geoloc_countries.iso_3166_1_a2 = auth_user_md5.nationalite
- OR geoloc_countries.iso_3166_1_a2 = auth_user_md5.nationalite2
- OR geoloc_countries.iso_3166_1_a2 = auth_user_md5.nationalite3)';
+ profiles AS acp ON (acgp.a2 IN (acp.nationality1, acp.nationality2, acp.nationality3))';
- $field = 'IF(acgp.nat=\'\', acgp.pays, acgp.nat)';
- $id = 'acgp.a2';
+ $field = 'nationalityFR';
+ $id = 'iso_3166_1_a2';
break;
case 'region':
- $db = 'geoloc_region';
+ $db = 'geoloc_administrativeareas';
$field = 'name';
- $id = 'region';
+ $id = 'id';
if (isset($_REQUEST['country'])) {
- $where .= ' WHERE a2 = "'.$_REQUEST['country'].'"';
+ $where .= ' WHERE country = "' . $_REQUEST['country'] . '"';
}
break;
case 'school':
</a>
{/if}
<ul style="padding-top:0px;padding-bottom:0px">
- <li><a href="http://www.polytechnique.net/{$asso.diminutif}/annuaire">annuaire</a></li>
- <li><a href="http://www.polytechnique.net/{$asso.diminutif}/trombi">trombino</a></li>
- {if $asso.lists}
- <li><a href="http://www.polytechnique.net/{$asso.diminutif}/lists">listes de diffusion</a></li>
+ <li><a href="http://www.polytechnique.net/{$asso->diminutif}/annuaire">annuaire</a></li>
+ <li><a href="http://www.polytechnique.net/{$asso->diminutif}/trombi">trombino</a></li>
- <li><a href="http://www.polytechnique.net/{$asso->diminutif}/geoloc">carte</a></li>
+ {if $asso->lists}
+ <li><a href="http://www.polytechnique.net/{$asso->diminutif}/lists">listes de diffusion</a></li>
{/if}
- {if $asso.events}
- <li><a href="http://www.polytechnique.net/{$asso.diminutif}/events">{$asso.events} événement{if $asso.events > 1}s{/if}</a></li>
+ {if $asso->events}
+ <li><a href="http://www.polytechnique.net/{$asso->diminutif}/events">{$asso->events} événement{if $asso->events > 1}s{/if}</a></li>
{/if}
- {if !$asso.lists}
+ {if !$asso->lists}
<li style="display:block"> </li>
{/if}
- {if !$asso.events}
+ {if !$asso->events}
<li style="display:block"> </li>
{/if}
</ul>