public function delete_by_variable($pluginid, $variable) { if (!$pluginid || !$variable) { return; } XDB::delete($this->_table, XDB::field('pluginid', $pluginid) . ' AND ' . XDB::field('variable', $variable)); }
public static function IsCandidate(User $user, $candidate) { $profile = $user->profile(); if (!$profile) { return false; } // We only test if the user is in her promotion group for it is too // expensive to check if she is in the corresponding ML as well. $res = XDB::query('SELECT COUNT(*) FROM group_members WHERE uid = {?} AND asso_id = (SELECT id FROM groups WHERE diminutif = {?})', $user->id(), $user->profile()->yearPromo()); $mlCount = $res->fetchOneCell(); if ($mlCount) { Reminder::MarkCandidateAsAccepted($user->id(), $candidate); } if ($mlCount == 0) { $mlist = MailingList::promo($user->profile()->yearPromo()); try { $mlist->getMembersLimit(0, 0); } catch (Exception $e) { return false; } } return false; }
public function run() { global $platal, $globals; $nom = S::v('prenom') . ' ' . S::v('nom'); $mail = $this->user->bestEmail(); $sig = $nom . ' (' . S::v('promo') . ')'; Banana::$msgedit_headers['X-Org-Mail'] = $this->user->forlifeEmail(); // Tree color $req = XDB::query('SELECT tree_unread, tree_read FROM forum_profiles WHERE uid= {?}', $this->user->id()); if (!(list($unread, $read) = $req->fetchOneRow())) { $unread = 'o'; $read = 'dg'; } Banana::$tree_unread = $unread; Banana::$tree_read = $read; // Build user profile Banana::$profile['headers']['From'] = "{$nom} <{$mail}>"; Banana::$profile['headers']['Organization'] = make_Organization(); Banana::$profile['signature'] = $sig; // Page design Banana::$page->killPage('forums'); Banana::$page->killPage('subscribe'); // Run Banana return parent::run(); }
public function commit() { if ($this->user->hasProfile()) { XDB::execute('UPDATE profiles SET alias_pub = {?} WHERE pid = {?}', $this->public, $this->user->profile()->id()); } if ($this->old) { $success = XDB::execute('UPDATE email_source_account SET email = {?} WHERE uid = {?} AND type = \'alias_aux\'', $this->alias, $this->user->id()); } else { $success = XDB::execute('INSERT INTO email_source_account (email, uid, domain, type, flags) SELECT {?}, {?}, id, \'alias_aux\', \'\' FROM email_virtual_domains WHERE name = {?}', $this->alias, $this->user->id(), Platal::globals()->mail->alias_dom); } if ($success) { // Update the local User object, to pick up the new bestalias. require_once 'emails.inc.php'; fix_bestalias($this->user); $this->user = User::getSilentWithUID($this->user->id()); } return $success; }
public function fetch_all_by_searchc($condition, $orderby, $start = 0, $ppp = 0) { if (is_array($condition)) { $where = " AND " . implode($condition, ' AND '); } return XDB::fetch_all("SELECT * FROM %t WHERE 1 %i ORDER BY %i LIMIT %d, %d", array($this->_table, $where, $orderby, $start, $ppp)); }
public function commit() { $sql = 'INSERT INTO surveys SET questions = {?}, title = {?}, description = {?}, uid = {?}, end = {?},mode = {?}, promos = {?}'; return XDB::execute($sql, serialize($this->questions), $this->title, $this->description, $this->user->id(), $this->end, $this->mode, $this->promos); }
function query($sql) { XDB::execute($sql); if (XDB::errno() != 0) { echo "error in \"{$sql}\":\n", XDB::error(), "\n"; } }
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'); }
public static function assign_json_to_map(PlPage $page, $pids = null) { if (!is_null($pids)) { $where = XDB::format(' AND pa.pid IN {?}', $pids); } else { $where = ''; } if (!S::logged() || !S::user()->checkPerms('directory_ax')) { $where .= " AND pa.pub = 'public'"; $name_publicity = 'public'; } else { if (!S::user()->checkPerms('directory_private')) { $where .= " AND pa.pub = 'ax'"; $name_publicity = 'public'; } else { $name_publicity = 'private'; } } $data = XDB::rawFetchAllAssoc('SELECT pa.latitude, pa.longitude, GROUP_CONCAT(DISTINCT p.hrpid SEPARATOR \',\') AS hrpid, GROUP_CONCAT(pd.promo SEPARATOR \',\') AS promo, GROUP_CONCAT(DISTINCT pd.' . $name_publicity . '_name, \' (\', pd.promo, \')\' SEPARATOR \', \') AS name, GROUP_CONCAT(DISTINCT pa.pid SEPARATOR \',\') AS pid FROM profile_addresses AS pa INNER JOIN profiles AS p ON (pa.pid = p.pid) INNER JOIN profile_display AS pd ON (pd.pid = pa.pid) WHERE pa.type = \'home\' AND p.deathdate IS NULL AND pa.latitude IS NOT NULL AND pa.longitude IS NOT NULL' . $where . ' GROUP BY pa.latitude, pa.longitude'); $page->jsonAssign('data', $data); }
function do_update_by_block($values) { // Update display_tel by block // Because there is no mysql update syntax for multiple updates in one query // we use a multiple insert syntax which will fail because the key already exist // and then update the display_tel XDB::execute("INSERT INTO profile_phones (pid, link_type, link_id, tel_id ,tel_type,\n search_tel, display_tel, pub, comment)\n VALUES " . $values . "\n ON DUPLICATE KEY UPDATE display_tel = VALUES(display_tel)"); }
public function fetch_all_username_by_uid($uid) { $user = ''; if ($uid) { $user = XDB::result_first('SELECT username FROM %t WHERE uid=%s', array($this->_table, $uid)); } return $user; }
public function run() { $today = date('d'); $month = date('m'); $res = XDB::query("\n SELECT name\n FROM days\n WHERE day={$today} AND month={$month}\n "); $fetes = $res->fetchColumn(0); $this->assign("fetes", $fetes); }
public function delete_by_tid($tids) { $tids = dintval($tids, true); if ($tids) { return XDB::delete($this->_table, XDB::field('tid', $tids)); } return 0; }
/** * Purges session events without a valid session. */ function purgeOrphanedEvents() { $begin = time(); XDB::execute("DELETE e\n FROM log_events AS e\n LEFT JOIN log_sessions AS s ON (s.id = e.session)\n WHERE s.id IS NULL"); $affectedRows = XDB::affectedRows(); $duration = time() - $begin; echo "Orphaned events: removed {$affectedRows} events in {$duration} seconds.\n"; }
public function run() { $res = XDB::query('SELECT todo_id, sent, checked, tobedone FROM todo WHERE uid = {?} ORDER BY sent DESC', S::user()->id()); $array_todo = $res->fetchAllAssoc(); $this->assign('list', $array_todo); }
function get_address_text($adr) { $t = ''; if (isset($adr['adr1']) && $adr['adr1']) { $t .= $adr['adr1']; } if (isset($adr['adr2']) && $adr['adr2']) { $t .= "\n" . $adr['adr2']; } if (isset($adr['adr3']) && $adr['adr3']) { $t .= "\n" . $adr['adr3']; } $l = ''; if (isset($adr['display']) && $adr['display']) { $keys = explode(' ', $adr['display']); foreach ($keys as $key) { if (isset($adr[$key])) { $l .= ' ' . $adr[$key]; } else { $l .= ' ' . $key; } } if ($l) { substr($l, 1); } } elseif ($adr['country'] == 'US' || $adr['country'] == 'CA' || $adr['country'] == 'GB') { if ($adr['city']) { $l .= $adr['city'] . ",\n"; } if ($adr['region']) { $l .= $adr['region'] . ' '; } if ($adr['postcode']) { $l .= $adr['postcode']; } } else { if (isset($adr['postcode']) && $adr['postcode']) { $l .= $adr['postcode'] . ' '; } if (isset($adr['city']) && $adr['city']) { $l .= $adr['city']; } } if ($l) { $t .= "\n" . trim($l); } if ($adr['country'] != '00' && (!$adr['countrytxt'] || $adr['countrytxt'] == strtoupper($adr['countrytxt']))) { $res = XDB::query('SELECT countryFR FROM geoloc_countries WHERE iso_3166_1_a2 = {?}', $adr['country']); $adr['countrytxt'] = $res->fetchOneCell(); } if (isset($adr['countrytxt']) && $adr['countrytxt']) { $t .= "\n" . $adr['countrytxt']; } return trim($t); }
public static function IsCandidate(User $user, $candidate) { $res = XDB::query("SELECT COUNT(*) AS lists\n FROM register_subs\n WHERE uid = {?} AND type = 'list'", $user->id()); $mlCount = $res->fetchOneCell(); if (!$mlCount) { Reminder::MarkCandidateAsAccepted($user->id(), $candidate); } return $mlCount > 0; }
protected function fetch(PlUser $user) { global $globals; if (!is_null($user)) { return new UserFilterIterator(XDB::iterator("SELECT id, titre AS title, texte, contacts,\n create_date AS publication,\n FIND_IN_SET('photo', flags) AS photo,\n CONCAT({?}, '/#art', id) AS link\n FROM group_announces\n WHERE expiration >= NOW() AND asso_id = {?}", $this->link, $globals->asso('id'), $user)); } else { return XDB::iterator("SELECT id, titre AS title, texte, create_date AS publication,\n CONCAT({?}, '/#art', id) AS link,\n NULL AS photo, NULL AS contacts\n FROM group_announces\n WHERE FIND_IN_SET('public', flags) AND expiration >= NOW() AND asso_id = {?}", $this->link, $globals->asso('id')); } }
public function formu() { $res = XDB::query('SELECT IF(MAX(m.last)>p.relance, MAX(m.last), p.relance) FROM accounts AS a LEFT JOIN register_pending AS p ON p.uid = a.uid LEFT JOIN register_marketing AS m ON m.uid = a.uid WHERE a.uid = {?}', $this->m_user->id()); $this->m_relance = $res->fetchOneCell(); return 'include/form.valid.mark.tpl'; }
function handler_ajax_todo_clear($page) { S::assert_xsrf_token(); XDB::execute('DELETE FROM todo WHERE uid = {?} AND checked = 1', S::user()->id()); if (XDB::affectedRows() != 1) { $page->jsonAssign('error', "Impossible de nettoyer la liste des tâches"); } return PL_JSON; }
function check_email($email, $message) { $res = XDB::fetchOneCell('SELECT COUNT(*) FROM email_watch WHERE state != \'safe\' AND email = {?}', $email); if ($res) { send_warning_mail($message); return true; } return false; }
public function update_all($data) { if (is_array($data)) { $update = array(); foreach ($data as $key => $val) { $update[] = "`" . $key . "` = '" . $val . "'"; } $setwhere = implode($update, ', '); XDB::query("UPDATE " . XDB::table($this->_table) . " SET " . $setwhere); } }
function checkCount($sql, $comment = '') { $count = XDB::rawFetchOneCell($sql); if ($err = XDB::error()) { echo $err; } if ($count > 0) { echo "Erreur pour la vérification : {$comment}\n{$sql}\n\n"; echo "|\tTotal\t|\n|\t{$count}\t|\n\n"; } }
public static function countNonGeocoded($pid) { $count = XDB::fetchOneCell('SELECT COUNT(*) FROM profile_addresses AS pa WHERE pid = {?} AND type = \'home\' AND NOT EXISTS (SELECT * FROM profile_addresses_components AS pc WHERE pa.pid = pc.pid AND pa.jobid = pc.jobid AND pa.groupid = pc.groupid AND pa.type = pc.type AND pa.id = pc.id)', $pid); return $count; }
public function check_moderator_for_uid($fid, $uid, $accessmasks = 0) { if (!intval($fid) || !intval($uid)) { return false; } if ($accessmasks) { $accessadd1 = ', a.allowview, a.allowpost, a.allowreply, a.allowgetattach, a.allowgetimage, a.allowpostattach'; $accessadd2 = "LEFT JOIN " . XDB::table('forum_access') . " a ON a." . XDB::field('uid', $uid) . " AND a." . XDB::field('fid', $fid); } return XDB::fetch_first("SELECT ff.postperm, m.uid AS istargetmod {$accessadd1}\n\t\t\t\tFROM " . XDB::table($this->_table) . " ff\n\t\t\t\t{$accessadd2}\n\t\t\t\tLEFT JOIN " . XDB::table('forum_moderator') . " m ON m.fid=%d AND m.uid=%d\n\t\t\t\tWHERE ff.fid=%d", array($fid, $uid, $fid)); }
function smarty_function_select_domains($params, &$smarty) { $userdomain = User::getDomainFromCookie(); $res = XDB::iterRow("SELECT f.domain\n FROM formations AS f\n LEFT JOIN studies AS s ON s.formation_id = f.formation_id\n GROUP BY f.domain\n ORDER BY COUNT(f.domain) DESC"); $sel = ' selected="selected"'; $html = ""; while (list($domain) = $res->next()) { $isSelected = $userdomain == $domain ? $sel : ""; $html .= '<option value="' . $domain . '"' . $isSelected . '>' . $domain . '</option>' . "\n"; } return $html; }
public static function fetchById($id) { $res = XDB::fetchOneAssoc('SELECT id, shortname, name, url, has_directory, has_bulkmail, default_sharing_level, api_uid FROM profile_partnersharing_enum WHERE id = {?}', $id); if ($res == null) { return null; } else { return new PartnerSharing($res); } }
private static function ListMergeIssues(Profile $profile) { if (Platal::globals()->merge->state != 'done') { return null; } $flags = XDB::fetchOneCell('SELECT issues FROM profile_merge_issues WHERE pid = {?}', $profile->id()); if (!$flags) { return null; } return new PlFlagSet($flags); }
public function clear() { require_once libfile('function/forum'); $delaids = array(); $query = XDB::query("SELECT aid, attachment, thumb FROM %t WHERE %i", array($this->_table, XDB::field('dateline', TIMESTAMP - 86400))); while ($attach = XDB::fetch($query)) { dunlink($attach); $delaids[] = $attach['aid']; } if ($delaids) { XDB::query("DELETE FROM %t WHERE %i", array('forum_attachment', XDB::field('aid', $delaids)), false, true); XDB::query("DELETE FROM %t WHERE %i", array($this->_table, XDB::field('dateline', TIMESTAMP - 86400)), false, true); } }
function select_nat($valeur, $pad = false) { $res = XDB::iterRow("SELECT iso_3166_1_a2 AS id, nationality AS text\n FROM geoloc_countries\n WHERE nationality IS NOT NULL\n ORDER BY nationality"); $sel = ' selected="selected"'; // on ajoute une entree vide si $pad est vrai $html = ""; if ($pad) { $html .= sprintf("<option value=\"\"%s> </option>\n", $valeur ? $sel : ""); } while (list($my_id, $my_text) = $res->next()) { $html .= sprintf("<option value=\"%s\"%s>%s</option>\n", $my_id, $valeur == $my_id ? $sel : "", $my_text ? $my_text : " "); } return $html; }