function prepareform($pay, $user) { // 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'; $roboturl = str_replace("https://", "http://", $globals->baseurl) . '/' . $platal->ns . "payment/paypal_return/" . $user->id() . "?comment=" . urlencode(Env::v('comment')) . '&display=' . Post::i('display'); $this->infos = array('commercant' => array('business' => $globals->money->paypal_compte, 'rm' => 2, 'return' => $roboturl, 'cn' => 'Commentaires', 'no_shipping' => 1, 'cbt' => empty($GLOBALS['IS_XNET_SITE']) ? 'Revenir sur polytechnique.org.' : 'Revenir sur polytechnique.net.')); $info_client = array('first_name' => $user->firstName(), 'last_name' => $user->lastName(), 'email' => $user->bestEmail()); if ($user->hasProfile()) { $res = XDB::query("SELECT pa.text, GROUP_CONCAT(pace2.short_name) AS city,\n GROUP_CONCAT(pace3.short_name) AS zip, GROUP_CONCAT(pace1.short_name) AS country,\n IF(pp1.display_tel != '', pp1.display_tel, pp2.display_tel) AS night_phone_b\n FROM profile_addresses AS pa\n LEFT JOIN profile_phones AS pp1 ON (pp1.pid = pa.pid AND pp1.link_type = 'address' AND pp1.link_id = pa.id)\n LEFT JOIN profile_phones AS pp2 ON (pp2.pid = pa.pid AND pp2.link_type = 'user' AND pp2.link_id = 0)\n LEFT JOIN profile_addresses_components AS pc ON (pa.pid = pc.pid AND pa.jobid = pc.jobid AND pa.groupid = pc.groupid\n AND pa.type = pc.type AND pa.id = pc.id)\n LEFT JOIN profile_addresses_components_enum AS pace1 ON (FIND_IN_SET('country', pace1.types) AND pace1.id = pc.component_id)\n LEFT JOIN profile_addresses_components_enum AS pace2 ON (FIND_IN_SET('locality', pace2.types) AND pace2.id = pc.component_id)\n LEFT JOIN profile_addresses_components_enum AS pace3 ON (FIND_IN_SET('postal_code', pace3.types) AND pace3.id = pc.component_id)\n WHERE pa.pid = {?} AND FIND_IN_SET('current', pa.flags)\n GROUP BY pa.pid, pa.jobid, pa.groupid, pa.id, pa.type\n LIMIT 1", $user->profile()->id()); if (is_array($res)) { $this->infos['client'] = array_map('replace_accent', array_merge($info_client, $res->fetchOneAssoc())); 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']); } else { $this->infos['client'] = array_map('replace_accent', $info_client); } } else { $this->infos['client'] = array_map('replace_accent', $info_client); } // We build the transaction's reference $prefix = 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); $this->infos['divers'] = array('cmd' => '_xclick'); }
function get_annuaire_infos($method, $params) { global $error_mat, $error_key, $globals; // Password verification. if (!isset($params[0]) || $params[0] != $globals->manageurs->manageurs_pass) { return false; } // If address == -1, we do not retrieve any address. if (isset($params[2]) && $params[2] == -1) { unset($params[2]); } // We check we actually have an identification number. if (!empty($params[1])) { // We only retrieve addresses when required. if (!isset($params[2])) { $res = XDB::iterRow("SELECT pp.display_tel AS cell, p.birthdate AS age\n FROM profiles AS p\n LEFT JOIN profile_phones AS pp ON (pp.pid = p.pid AND pp.link_type = 'user'\n AND pp.tel_type = 'mobile')\n WHERE p.xorg_id = {?} LIMIT 1", $params[1]); $array = $res->next(); } else { $res = XDB::iterRow("SELECT p.birthdate, pa.text, GROUP_CONCAT(pace3.short_name), GROUP_CONCAT(pace2.short_name),\n GROUP_CONCAT(pace1.short_name), p.pid, pa.id\n FROM profiles AS p\n LEFT JOIN profile_addresses AS pa ON (pa.pid = p.pid)\n LEFT JOIN profile_addresses_components AS pc ON (pa.pid = pc.pid AND pa.jobid = pc.jobid AND pa.groupid = pc.groupid\n AND pa.type = pc.type AND pa.id = pc.id)\n LEFT JOIN profile_addresses_components_enum AS pace1 ON (FIND_IN_SET(\\'country\\', pace1.types) AND pace1.id = pc.component_id)\n LEFT JOIN profile_addresses_components_enum AS pace2 ON (FIND_IN_SET(\\'locality\\', pace2.types) AND pace2.id = pc.component_id)\n LEFT JOIN profile_addresses_components_enum AS pace3 ON (FIND_IN_SET(\\'postal_code\\', pace3.types) AND pace3.id = pc.component_id)\n WHERE p.xorg_id = {?} AND NOT FIND_IN_SET('job', pa.flags)\n ORDER BY NOT FIND_IN_SET('current', pa.flags),\n FIND_IN_SET('secondary', pa.flags),\n NOT FIND_IN_SET('mail', pa.flags)\n GROUP BY pa.pid, pa.jobid, pa.groupid, pa.id, pa.type", $params[1]); // Process the addresses we got. if (list($age, $text, $adr['cp'], $adr['ville'], $adr['pays'], $pid, $adr['adrid']) = $res->next()) { list($adr['adr1'], $adr['adr2'], $adr['adr3']) = explode("\n", Geocoder::getFirstLines($text, $adr['cp'], 3)); $sql = XDB::query("SELECT display_tel\n FROM profile_phones\n WHERE pid = {?} AND link_type = 'user' AND tel_type = 'mobile'\n LIMIT 1", $pid); if ($sql->numRows() > 0) { $array['cell'] = $sql->fetchOneCell(); } else { $array['cell'] = ''; } $array['age'] = $age; $array['adresse'][] = $adr; // We limit the address number by the number of available addresses. $adresse = min((int) $params[2], $res->total()); if ($adresse != 1) { // We don't want the first address. $i = 2; while (list($age, $text, $adr['cp'], $adr['ville'], $adr['pays'], , $adr['adrid']) = $res->next()) { list($adr['adr1'], $adr['adr2'], $adr['adr3']) = explode("\n", Geocoder::getFirstLines($text, $adr['cp'], 3)); if ($adresse == $i) { // If we want this particular address. $array['adresse'][0] = $adr; //$res->free(); break; } elseif ($adresse == 0) { // If we want every address. $array['adresse'][] = $adr; } $i++; } } // We add the phone numbers. $adrid_index = array(); foreach ($array['adresse'] as $i => $a) { $adrid_index[$a['adrid']] = $i; } $restel = XDB::iterator("SELECT pp.display_tel AS tel, pp..tel_type, pp.link_id as adrid\n FROM profile_phones AS pp\n INNER JOIN profile_addresses AS pa ON (pp.link_id = pa.id AND pp.pid = pa.pid)\n WHERE pp.pid = {?} AND pp.link_type = 'address'\n AND NOT FIND_IN_SET('pro', pa.statut)", $pid); while ($tel = $restel->next()) { $array['adresse'][$adrid_index[$tel['adrid']]]['tels'][] = $tel; } foreach ($array['adresse'] as $i => $adr) { unset($lasttel); foreach ($adr['tels'] as $j => $t) { if (!isset($array['adresse'][$i]['tel']) && strpos($t['tel_type'], 'Tél') === 0) { $array['adresse'][$i]['tel'] = $t['tel']; } elseif (!isset($array['adresse'][$i]['fax']) && strpos($t['tel_type'], 'Fax') === 0) { $array['adresse'][$i]['fax'] = $t['tel']; } else { $lasttel = $t['tel']; } if (isset($array['adresse'][$i]['tel']) && isset($array['adresse'][$i]['fax'])) { break; } } if (!isset($array['adresse'][$i]['tel']) && isset($lasttel)) { $array['adresse'][$i]['tel'] = $lasttel; } elseif (!isset($array['adresse'][$i]['fax']) && isset($lasttel)) { $array['adresse'][$i]['fax'] = $lasttel; } unset($array['adresse'][$i]['adrid']); unset($array['adresse'][$i]['tels']); } } else { $array = false; } } if ($array) { // We did get a result: the identification number was rigth. // We only send the age to manageurs.com; the format is YYYY-MM-DD 0123-56-89. $year = (int) substr($array['age'], 0, 4); $month = (int) substr($array['age'], 5, 2); $day = (int) substr($array['age'], 8, 2); $age = (int) date('Y') - $year - 1; if ($month < (int) date('m') || $month == (int) date('m') && $day >= (int) date('d')) { $age += 1; } $array['age'] = $age; // We start the encryption of the data. if (manageurs_encrypt_init($params[1]) == 1) { // We did not find the key to encryptthe data. $args = array("erreur" => 3, "erreurstring" => $error_key); $reply = xmlrpc_encode_request(NULL, $args); } else { $reply = manageurs_encrypt_array($array); manageurs_encrypt_close(); } } else { // The identification number was not valid. $args = array("erreur" => 2, "erreurstring" => $erreur_mat); $reply = xmlrpc_encode_request(NULL, $args); } } else { // The identification number was not in argument. $args = array("erreur" => 1, "erreurstring" => $error_mat); $reply = xmlrpc_encode_request(NULL, $args); } return $reply; }
protected function buildEntry($pf) { global $globals; $pf = $pf['value']; $entry = new PlVCardEntry($pf->firstNames(), $pf->lastNames(), null, null, $pf->nickname); $user = $pf->owner(); // Free text $freetext = '(' . $pf->promo . ')'; if ($this->freetext) { $freetext .= "\n" . $this->freetext; } $entry->set('NOTE', $freetext); if ($pf->mobile) { $entry->addTel(null, $pf->mobile, false, true, true, false, true, true); } // Emails if (!is_null($user)) { $entry->addMail(null, $user->bestalias, true); if ($user->forlife != $user->bestalias) { $entry->addMail(null, $user->forlife); } if ($user->forlife_alternate != $user->bestalias) { $entry->addMail(null, $user->forlife_alternate); } } // Homes $adrs = $pf->iterAddresses(Profile::ADDRESS_PERSO); while ($adr = $adrs->next()) { if (!$adr->postalCode || !$adr->locality || !$adr->country) { $group = $entry->addHome($adr->text, null, null, null, null, $adr->administrativeArea, null, $adr->hasFlag('current'), $adr->hasFlag('mail'), $adr->hasFlag('mail')); } else { $group = $entry->addHome(trim(Geocoder::getFirstLines($adr->text, $adr->postalCode, 4)), null, null, $adr->postalCode, $adr->locality, $adr->administrativeArea, $adr->country, $adr->hasFlag('current'), $adr->hasFlag('mail'), $adr->hasFlag('mail')); } foreach ($adr->phones() as $phone) { if ($phone->link_type == Phone::TYPE_FIXED) { $entry->addTel($group, $phone->display, false, true, true, false, false, $adr->hasFlag('current') && empty($pf->mobile)); } else { if ($phone->link_type == Phone::TYPE_FAX) { $entry->addTel($group, $phone->display, true, false, false, false, false, false); } } } } // Pro $jobs = $pf->getJobs(); foreach ($jobs as $job) { $terms_array = array(); foreach ($job->terms as $term) { $terms_array[] = $term->full_name; } $terms = implode(', ', $terms_array); if ($job->address) { if (!$job->address->postalCode || !$job->address->locality || !$job->address->country) { $group = $entry->addWork($job->company->name, null, $job->description, $terms, $job->address->text, null, null, null, null, $job->address->administrativeArea, null); } else { $group = $entry->addWork($job->company->name, null, $job->description, $terms, trim(Geocoder::getFirstLines($job->address->text, $job->address->postalCode, 4)), null, null, $job->address->postalCode, $job->address->locality, $job->address->administrativeArea, $job->address->country); } } else { $group = $entry->addWork($job->company->name, null, $job->description, $terms, null, null, null, null, null, null, null); } if ($job->user_email) { $entry->addMail($group, $job->user_email); } foreach ($job->phones as $phone) { if ($phone->type == Phone::TYPE_MOBILE) { $entry->addTel($group, $phone->display, false, true, true, false, true); } else { if ($phone->type == Phone::TYPE_FAX) { $entry->addTel($group, $phone->display, true); } else { $entry->addTel($group, $phone->display, false, true, true); } } } } // Melix if (!is_null($user)) { $alias = $user->emailAlias(); if (!is_null($alias) && $pf->alias_pub == 'public') { $entry->addMail(null, $alias); } } // Custom fields if (!is_null($user)) { $groups = $user->groups(true, true); if (count($groups)) { $gn = DirEnum::getOptions(DirEnum::GROUPESX); $gns = array(); foreach (array_keys($groups) as $gid) { $gns[$gid] = $gn[$gid]; } $entry->set('X-GROUPS', join(', ', $gns)); } } $binets = $pf->getBinets(); if (count($binets)) { $bn = DirEnum::getOptions(DirEnum::BINETS); $bns = array(); foreach ($binets as $bid) { $bns[$bid] = $bn[$bid]; } $entry->set('X-BINETS', join(', ', $bns)); } if (!empty($pf->section)) { $entry->set('X-SECTION', $pf->section); } // Photo if ($this->photos) { $res = XDB::query("SELECT attach, attachmime\n FROM profile_photos\n WHERE pid = {?} AND pub IN ('public', {?})", $pf->id(), $this->visibility->level()); if ($res->numRows()) { list($data, $type) = $res->fetchOneRow(); $entry->setPhoto($data, strtoupper($type)); } } return $entry; }