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); }
public function save(ProfilePage $page, $field, $value) { XDB::execute("DELETE FROM profile_binets\n WHERE pid = {?}", $page->pid()); if (!count($value)) { return; } $insert = array(); foreach ($value as $id => $text) { $insert[] = XDB::format('({?}, {?})', $page->pid(), $id); } XDB::execute("INSERT INTO profile_binets (pid, binet_id)\n VALUES " . implode(',', $insert)); }
public static function getComponentId(array $component) { $where = ''; foreach ($component['types'] as $type) { $where .= XDB::format(' AND FIND_IN_SET({?}, types)', $type); } $id = XDB::fetchOneCell('SELECT id FROM profile_addresses_components_enum WHERE short_name = {?} AND long_name = {?}' . $where, $component['short_name'], $component['long_name']); if (is_null($id)) { XDB::execute('INSERT INTO profile_addresses_components_enum (short_name, long_name, types) VALUES ({?}, {?}, {?})', $component['short_name'], $component['long_name'], implode(',', $component['types'])); $id = XDB::insertId(); } return $id; }
public function commit() { $values = array(); $i = 0; foreach ($this->users as $user) { $values[] = XDB::format('({?}, {?}, {?}, NOW(), {?}, {?}, {?})', $user['uid'], $user['hruid'], $user['email'], rand_url_id(12), $this->user->fullName(), $this->group); if ($i == $this->limit) { XDB::rawExecute('INSERT INTO register_pending_xnet (uid, hruid, email, date, hash, sender_name, group_name) VALUES ' . implode(', ', $values)); $i = 0; $values = array(); } else { ++$i; } } XDB::rawExecute('INSERT INTO register_pending_xnet (uid, hruid, email, date, hash, sender_name, group_name) VALUES ' . implode(', ', $values)); return true; }
public static function get($id, $can_be_shortname = true) { if (!$id) { return null; } if (!$can_be_shortname) { $where = XDB::format('a.id = {?}', $id); } else { $where = XDB::format('a.diminutif = {?}', $id); } $res = XDB::query('SELECT a.*, d.nom AS domnom, FIND_IN_SET(\'wiki_desc\', a.flags) AS wiki_desc, FIND_IN_SET(\'notif_unsub\', a.flags) AS notif_unsub, FIND_IN_SET(\'notify_all\', a.flags) AS notify_all, (nls.id IS NOT NULL) AS has_nl, ad.text AS address, p.display_tel AS phone, f.display_tel AS fax FROM groups AS a LEFT JOIN group_dom AS d ON d.id = a.dom LEFT JOIN newsletters AS nls ON (nls.group_id = a.id) LEFT JOIN profile_phones AS p ON (p.link_type = \'group\' AND p.link_id = a.id AND p.tel_id = 0) LEFT JOIN profile_phones AS f ON (f.link_type = \'group\' AND f.link_id = a.id AND f.tel_id = 1) LEFT JOIN profile_addresses AS ad ON (ad.type = \'group\' AND ad.groupid = a.id) WHERE ' . $where); if ($res->numRows() != 1) { if ($can_be_shortname && (is_int($id) || ctype_digit($id))) { return Group::get($id, false); } return null; } $data = $res->fetchOneAssoc(); $positions = XDB::fetchAllAssoc('SELECT position, uid FROM group_members WHERE asso_id = {?} AND position IS NOT NULL ORDER BY position', $data['id']); return new Group(array_merge($data, array('positions' => $positions))); }
function handler_trusted($page, $action = 'list', $id = null) { $page->setTitle('Sites tiers de confiance'); $page->assign('title', 'Mes sites tiers de confiance pour OpenId'); $table_editor = new PLTableEditor('openid/trusted', 'account_auth_openid', 'id'); $table_editor->set_where_clause(XDB::format('uid = {?}', S::user()->id())); $table_editor->vars['uid']['display_list'] = false; $table_editor->vars['uid']['display_item'] = false; $table_editor->describe('url', 'site tiers', true); $page->assign('deleteonly', true); $table_editor->apply($page, $action, $id); }
public function getAutoComplete($text, $subid = null) { $text = str_replace(array('%', '_'), '', $text); if (is_null($this->ac_where) || $this->ac_where == '') { $where = ''; } else { $where = $this->ac_where . ' AND '; } if ($subid != null && array_key_exists($subid, $this->suboptions)) { $where .= XDB::format($this->optfield . ' = {?} AND ', $subid); } $tests = $this->mkTests($this->valfield, $text); if (!is_null($this->valfield2)) { $tests = array_merge($tests, $this->mkTests($this->valfield2, $text)); } $where .= '(' . implode(' OR ', $tests) . ')'; return XDB::fetchAllAssoc('SELECT ' . $this->valfield . ' AS field' . ($this->ac_distinct ? ', COUNT(DISTINCT ' . $this->ac_unique . ') AS nb' : '') . ($this->ac_withid ? ', ' . $this->idfield . ' AS id' : '') . ' FROM ' . $this->from . ' ' . $this->ac_join . ' WHERE ' . $where . ' GROUP BY ' . $this->valfield . ' ORDER BY ' . ($this->ac_distinct ? 'nb DESC' : $this->valfield) . ' LIMIT ' . self::AUTOCOMPLETE_LIMIT); }
protected function getSortTokens(PlFilter $uf) { $toks = $uf->getNameTokens(); $scores = array(); // If there weren't any sort tokens, we shouldn't sort by score, sort by NULL instead if (count($toks) == 0) { return 'NULL'; } foreach ($toks as $sub => $token) { $scores[] = XDB::format('SUM(' . $sub . '.score + IF (' . $sub . '.token = {?}, 5, 0) )', $token); } return implode(' + ', $scores); }
public function buildCondition(PlFilter $f) { $sub = $f->addGroupFilter(); return XDB::format($sub . '.gid IN {?}', $this->gids); }
public function save(ProfilePage $page, $field, $value) { require_once 'name.func.inc.php'; $old = XDB::fetchOneAssoc('SELECT lastname_main, lastname_marital, lastname_ordinary, firstname_main, firstname_ordinary, pseudonym FROM profile_public_names WHERE pid = {?}', $page->pid()); if ($has_diff = $this->diff($page->pid(), $old, $value['public_names'])) { $new_names = new NamesReq(S::user(), $page->profile, $value['public_names'], $old); $new_names->submit(); Platal::page()->assign('validation', true); Platal::page()->trigWarning('La demande de modification des noms a bien été prise en compte.' . ' Un email sera envoyé dès que ces changements auront été effectués.'); } XDB::execute('DELETE FROM profile_private_names WHERE pid = {?}', $page->pid()); $values = array(); $nickname = $lastname = $firstname = 0; if (isset($value['private_names'])) { foreach ($value['private_names'] as $name) { $values[] = XDB::format('({?}, {?}, {?}, {?})', $page->pid(), $name['type'], ${$name}['type']++, $name['name']); } } if (count($values)) { XDB::rawExecute('INSERT INTO profile_private_names (pid, type, id, name) VALUES ' . implode(',', $values)); } if ($has_diff) { update_display_names($page->profile, $old, $value['private_names']); } else { update_display_names($page->profile, $value['public_names'], isset($value['private_names']) ? $value['private_names'] : null); } }
protected static function loadMainFieldsFromUIDs(array $uids, $respect_order = true) { if (empty($uids)) { return PlIteratorUtils::emptyIterator(); } global $globals; $joins = ''; $fields = array(); if ($globals->asso('id')) { $joins .= XDB::format("LEFT JOIN group_members AS gpm ON (gpm.uid = a.uid AND gpm.asso_id = {?})\n", $globals->asso('id')); $fields[] = 'gpm.perms AS group_perms'; $fields[] = 'gpm.comm AS group_comm'; $fields[] = 'gpm.position AS group_position'; } if (count($fields) > 0) { $fields = ', ' . implode(', ', $fields); } else { $fields = ''; } if ($respect_order) { $order = 'ORDER BY ' . XDB::formatCustomOrder('a.uid', $uids); } else { $order = ''; } $uids = array_map(array('XDB', 'escape'), $uids); return XDB::iterator('SELECT a.uid, a.hruid, a.registration_date, h.uid IS NOT NULL AS homonym, a.firstname, a.lastname, IF(ef.email IS NULL, NULL, CONCAT(ef.email, \'@\', mf.name)) AS forlife, IF(ef.email IS NULL, NULL, CONCAT(ef.email, \'@\', df.name)) AS forlife_alternate, IF(eb.email IS NULL, NULL, CONCAT(eb.email, \'@\', mb.name)) AS bestalias, (er.redirect IS NULL AND a.state = \'active\' AND FIND_IN_SET(\'mail\', at.perms)) AS lost, a.email, a.full_name, a.directory_name, a.display_name, a.sort_name, a.sex = \'female\' AS gender, IF(a.state = \'active\', CONCAT(at.perms, \',\', IF(a.user_perms IS NULL, \'\', a.user_perms)), \'\') AS perms, a.user_perms, a.email_format, a.is_admin, a.state, a.type, at.description AS type_description, a.skin, FIND_IN_SET(\'watch\', a.flags) AS watch, a.comment, a.weak_password IS NOT NULL AS weak_access, g.g_account_name IS NOT NULL AS googleapps, a.token IS NOT NULL AS token_access, a.token, a.last_version, s.start AS lastlogin, s.host, fp.last_seen AS banana_last ' . $fields . ' FROM accounts AS a INNER JOIN account_types AS at ON (at.type = a.type) LEFT JOIN email_source_account AS ef ON (ef.uid = a.uid AND ef.type = \'forlife\') LEFT JOIN email_virtual_domains AS mf ON (ef.domain = mf.id) LEFT JOIN email_virtual_domains AS df ON (df.aliasing = mf.id AND df.name LIKE CONCAT(\'%\', {?}) AND df.name NOT LIKE \'alumni.%\') LEFT JOIN email_source_account AS eb ON (eb.uid = a.uid AND FIND_IN_SET(\'bestalias\',eb.flags)) LEFT JOIN email_virtual_domains AS mb ON (a.best_domain = mb.id) LEFT JOIN email_redirect_account AS er ON (er.uid = a.uid AND er.flags = \'active\' AND er.broken_level < 3 AND er.type != \'imap\' AND er.type != \'homonym\') LEFT JOIN homonyms_list AS h ON (h.uid = a.uid) LEFT JOIN gapps_accounts AS g ON (a.uid = g.l_userid AND g.g_status = \'active\') LEFT JOIN log_last_sessions AS ls ON (ls.uid = a.uid) LEFT JOIN log_sessions AS s ON (s.id = ls.id) LEFT JOIN forum_profiles AS fp ON (fp.uid = a.uid) ' . $joins . ' WHERE a.uid IN (' . implode(', ', $uids) . ') GROUP BY a.uid ' . $order, $globals->mail->domain2, $globals->mail->domain2); }
public static function rebuildSearchTokens($pids, $transaction = true) { require_once 'name.func.inc.php'; if (!is_array($pids)) { $pids = array($pids); } $keys = XDB::iterator("(SELECT pid, name, type, IF(type = 'nickname', 2, 1) AS score, '' AS public\n FROM profile_private_names\n WHERE pid IN {?})\n UNION\n (SELECT pid, lastname_main, 'lastname' AS type, 10 AS score, 'public' AS public\n FROM profile_public_names\n WHERE lastname_main != '' AND pid IN {?})\n UNION\n (SELECT pid, lastname_marital, 'lastname' AS type, 10 AS score, 'public' AS public\n FROM profile_public_names\n WHERE lastname_marital != '' AND pid IN {?})\n UNION\n (SELECT pid, lastname_ordinary, 'lastname' AS type, 10 AS score, 'public' AS public\n FROM profile_public_names\n WHERE lastname_ordinary != '' AND pid IN {?})\n UNION\n (SELECT pid, firstname_main, 'firstname' AS type, 10 AS score, 'public' AS public\n FROM profile_public_names\n WHERE firstname_main != '' AND pid IN {?})\n UNION\n (SELECT pid, firstname_ordinary, 'firstname' AS type, 10 AS score, 'public' AS public\n FROM profile_public_names\n WHERE firstname_ordinary != '' AND pid IN {?})\n UNION\n (SELECT pid, pseudonym, 'nickname' AS type, 10 AS score, 'public' AS public\n FROM profile_public_names\n WHERE pseudonym != '' AND pid IN {?})", $pids, $pids, $pids, $pids, $pids, $pids, $pids); $names = array(); while ($key = $keys->next()) { if ($key['name'] == '') { continue; } $pid = $key['pid']; $toks = split_name_for_search($key['name']); $toks = array_reverse($toks); /* Split the score between the tokens to avoid the user to be over-rated. * Let says my user name is "Machin-Truc Bidule" and I also have a user named * 'Machin Truc'. Distributing the score force "Machin Truc" to be displayed * before "Machin-Truc" for both "Machin Truc" and "Machin" searches. */ $eltScore = ceil((double) $key['score'] / (double) count($toks)); $token = ''; foreach ($toks as $tok) { $token = $tok . $token; $names["{$pid}-{$token}"] = XDB::format('({?}, {?}, {?}, {?}, {?}, {?})', $token, $pid, soundex_fr($token), $eltScore, $key['public'], $key['type']); } } if ($transaction) { XDB::startTransaction(); } XDB::execute('DELETE FROM search_name WHERE pid IN {?}', $pids); if (count($names) > 0) { XDB::rawExecute('INSERT INTO search_name (token, pid, soundex, score, flags, general_type) VALUES ' . implode(', ', $names)); } if ($transaction) { XDB::commit(); } }
/** Save the global properties of this NL issue (title&co). */ public function save() { $errors = array(); // Fill the list of fields to update $fields = array('title' => $this->title, 'mail_title' => $this->title_mail, 'head' => $this->head, 'signature' => $this->signature); if (!empty($this->reply_to) && !isvalid_email($this->reply_to)) { $errors[] = self::ERROR_INVALID_REPLY_TO; } else { $fields['reply_to'] = $this->reply_to; } if ($this->isEditable()) { $fields['date'] = $this->date; if (!preg_match('/^[-a-z0-9]+$/i', $this->shortname) || is_numeric($this->shortname)) { $errors[] = self::ERROR_INVALID_SHORTNAME; } else { $fields['short_name'] = $this->shortname; } if ($this->sufb->isValid() || $this->sufb->isEmpty()) { $fields['sufb_json'] = json_encode($this->sufb->export()->dict()); // If sufb_json is too long to be store, we do not store a truncated json and notify the user. // The limit is LONGTEXT's one, ie 2^32 = 4294967296. if (strlen($fields['sufb_json']) > 4294967295) { $errors[] = self::ERROR_TOO_LONG_UFC; } } else { $errors[] = self::ERROR_INVALID_UFC; } if ($this->nl->automaticMailingEnabled()) { $fields['send_before'] = $this->send_before ? $this->send_before : null; } } if (count($errors)) { return $errors; } $field_sets = array(); foreach ($fields as $key => $value) { $field_sets[] = XDB::format($key . ' = {?}', $value); } XDB::execute('UPDATE newsletter_issues SET ' . implode(', ', $field_sets) . ' WHERE id={?}', $this->id); if (XDB::affectedRows()) { $this->refresh(); } else { $errors[] = self::ERROR_SQL_SAVE; } return $errors; }
public function layoutMinimodules(array $layout) { $cols = array_keys(FrankizMiniModule::emptyLayout()); $sql = array(); foreach ($cols as $col) { if (isset($layout[$col])) { foreach ($layout[$col] as $row => $name) { $sql[] = XDB::format('({?}, {?}, {?}, {?})', S::user()->id(), $name, $col, $row); } } } XDB::execute('INSERT INTO users_minimodules (uid, name, col, row) VALUES ' . implode(', ', $sql) . ' ON DUPLICATE KEY UPDATE col = VALUES(col), row = VALUES(row)'); if (!(XDB::affectedRows() > 0)) { return false; } $this->select(UserSelect::minimodules()); return true; }
public function __construct(array $pids, array $link_types, array $link_ids, $visibility) { $where = array(); if (count($pids) != 0) { $where[] = XDB::format('(pid IN {?})', $pids); } if (count($link_types) != 0) { $where[] = XDB::format('(link_type IN {?})', $link_types); } if (count($link_ids) != 0) { $where[] = XDB::format('(link_id IN {?})', $link_ids); } if ($visibility == null || !$visibility instanceof Visibility) { $visibility = Visibility::defaultForRead(); } $where[] = 'pve.best_display_level+0 <= pub+0'; $sql = 'SELECT search_tel AS search, display_tel AS display, comment, link_id, tel_type AS type, link_type, tel_id AS id, pid, pub FROM profile_phones LEFT JOIN profile_visibility_enum AS pve ON (pve.access_level = {?}) WHERE ' . implode(' AND ', $where) . ' ORDER BY pid, link_id, tel_id'; $this->dbiter = XDB::iterator($sql, $visibility->level()); }
public function buildCondition(PlFilter $f) { $sub = $f->addActivityInstanceFilter(); return XDB::format($sub . '.id IN {?}', $this->aids); }
public function buildCondition(PlFilter $uf) { $sub = $uf->addRoomFilter(); if ($this->exact) { return XDB::format("{$sub}.rid IN {?}", $this->rooms); } else { if (count($this->rooms) == 0) { return false; } else { if (count($this->rooms) == 1) { return $sub . '.rid ' . XDB::formatWildcards(XDB::WILDCARD_CONTAINS, $this->rooms[0]); } else { foreach ($this->rooms as $room) { $temp[] = $sub . '.rid ' . XDB::formatWildcards(XDB::WILDCARD_CONTAINS, $room); } return '(' . implode(') ' . 'OR' . ' (', $temp) . ')'; } } } }
public function save(ProfilePage $page, $field, $value) { $deletePrivate = S::user()->isMe($page->owner) || S::admin(); XDB::execute('DELETE FROM pj, pjt USING profile_job AS pj LEFT JOIN profile_job_term AS pjt ON (pj.pid = pjt.pid AND pj.id = pjt.jid) WHERE pj.pid = {?}' . ($deletePrivate ? '' : ' AND pj.pub IN (\'public\', \'ax\')'), $page->pid()); Address::deleteAddresses($page->pid(), Address::LINK_JOB, null, null, $deletePrivate); Phone::deletePhones($page->pid(), Phone::LINK_JOB, null, $deletePrivate); $previous_requests = EntrReq::get_typed_requests($page->pid(), 'entreprise'); foreach ($previous_requests as $request) { $request->clean(); } $terms_values = array(); foreach ($value as $id => &$job) { if (($job['pub'] != 'private' || $deletePrivate) && (isset($job['name']) && $job['name'])) { if (isset($job['jobid']) && $job['jobid']) { XDB::execute('INSERT INTO profile_job (pid, id, description, email, entry_year, url, pub, email_pub, jobid) VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', $page->pid(), $id, $job['description'], $job['w_email'], $job['w_entry_year'], $job['w_url'], $job['pub'], $job['w_email_pub'], $job['jobid']); } else { XDB::execute('INSERT INTO profile_job (pid, id, description, email, entry_year, url, pub, email_pub) VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', $page->pid(), $id, $job['description'], $job['w_email'], $job['w_entry_year'], $job['w_url'], $job['pub'], $job['w_email_pub']); $request = new EntrReq(S::user(), $page->profile, $id, $job['name'], $job['hq_acronym'], $job['hq_url'], $job['hq_email'], $job['hq_fixed'], $job['hq_fax'], $job['hq_address']); $request->submit(); sleep(1); } $address = new Address(array_merge($job['w_address'], array('pid' => $page->pid(), 'id' => $id, 'type' => Address::LINK_JOB))); $address->save(); Phone::savePhones($job['w_phone'], $page->pid(), Phone::LINK_JOB, $id); if (isset($job['terms'])) { foreach ($job['terms'] as $term) { $terms_values[] = XDB::format('({?}, {?}, {?}, {?})', $page->pid(), $id, $term['jtid'], "original"); } } } } if (count($terms_values) > 0) { XDB::rawExecute('INSERT INTO profile_job_term (pid, jid, jtid, computed) VALUES ' . implode(', ', $terms_values) . ' ON DUPLICATE KEY UPDATE computed = VALUES(computed)'); } if (S::user()->isMe($page->owner) && count($value) > 1) { Platal::page()->trigWarning('Attention, tu as plusieurs emplois sur ton profil. Pense à supprimer ceux qui sont obsolètes.'); } }
public function buildCondition(PlFilter $f) { $u = $f->addUserFilter(); return XDB::format("{$u}.uid IN {?}", $this->uids); }
public function __construct(array $pids, array $types, array $jobids, $visibility, $_where) { $where = array(); if (!is_null($_where)) { $where[] = $_where; } if (count($pids) != 0) { $where[] = XDB::format('(pa.pid IN {?})', $pids); } if (count($types) != 0) { $where[] = XDB::format('(pa.type IN {?})', $types); } if (count($jobids) != 0) { $where[] = XDB::format('(pa.jobid IN {?})', $jobids); } if ($visibility == null || !$visibility instanceof Visibility) { $visibility = Visibility::defaultForRead(); } $where[] = 'pve.best_display_level+0 <= pa.pub+0'; $sql = 'SELECT pa.pid, pa.jobid, pa.groupid, pa.type, pa.id, pa.flags, pa.text, pa.postalText, pa.pub, pa.comment, pa.types, pa.formatted_address, pa.location_type, pa.partial_match, pa.latitude, pa.longitude, pa.southwest_latitude, pa.southwest_longitude, pa.northeast_latitude, pa.northeast_longitude, pa.geocoding_date, pa.geocoding_calls, GROUP_CONCAT(DISTINCT pc.component_id SEPARATOR \',\') AS componentsIds, GROUP_CONCAT(pace1.long_name) AS postalCode, GROUP_CONCAT(pace2.long_name) AS locality, GROUP_CONCAT(pace3.long_name) AS administrativeArea, GROUP_CONCAT(pace4.long_name) AS country FROM profile_addresses AS pa LEFT JOIN profile_addresses_components AS pc ON (pa.pid = pc.pid AND pa.jobid = pc.jobid AND pa.groupid = pc.groupid AND pa.type = pc.type AND pa.id = pc.id) LEFT JOIN profile_addresses_components_enum AS pace1 ON (FIND_IN_SET(\'postal_code\', pace1.types) AND pace1.id = pc.component_id) LEFT JOIN profile_addresses_components_enum AS pace2 ON (FIND_IN_SET(\'locality\', pace2.types) AND pace2.id = pc.component_id) LEFT JOIN profile_addresses_components_enum AS pace3 ON (FIND_IN_SET(\'administrative_area_level_1\', pace3.types) AND pace3.id = pc.component_id) LEFT JOIN profile_addresses_components_enum AS pace4 ON (FIND_IN_SET(\'country\', pace4.types) AND pace4.id = pc.component_id) LEFT JOIN profile_visibility_enum AS pve ON (pve.access_level = {?}) WHERE ' . implode(' AND ', $where) . ' GROUP BY pa.pid, pa.jobid, pa.groupid, pa.type, pa.id ORDER BY pa.pid, pa.jobid, pa.id'; $this->dbiter = XDB::iterator($sql, $visibility->level()); $this->visibility = $visibility; }
/** Check that the profile match the given rule. */ public function checkProfile(Profile $profile) { $this->requireProfiles(); $this->buildQuery(); $count = (int) XDB::rawFetchOneCell('SELECT COUNT(*) ' . $this->query . XDB::format(' AND p.pid = {?}', $profile->id())); return $count == 1; }
/** Return an iterator over the validation concerning the given type * and the given user. * * @param type The type of the validations to fetch, null mean "any type" * @param applyTo A User or a Profile object the validation applies to. */ public static function iterate($type = null, $applyTo = null) { function toValidation($elt) { list($result, $stamp) = $elt; $result = Validate::unserialize($result); $result->stamp = $stamp; return $result; } $where = array(); if ($type) { $where[] = XDB::format('type = {?}', $type); } if ($applyTo) { if ($applyTo instanceof User) { $where[] = XDB::format('uid = {?}', $applyTo->id()); } else { if ($applyTo instanceof Profile) { $where[] = XDB::format('pid = {?}', $applyTo->id()); } } } if (!empty($where)) { $where = 'WHERE ' . implode('AND', $where); } else { $where = ''; } $it = XDB::iterRow('SELECT data, DATE_FORMAT(stamp, "%Y%m%d%H%i%s") FROM requests ' . $where . ' ORDER BY stamp'); return PlIteratorUtils::map($it, 'toValidation'); }
private function delPromo(PlPage $page, $promo) { $promos = $this->getPromo($page, $promo); if (!$promos || count($promos) == 0) { return; } $to_delete = array(); foreach ($promos as $promo) { $to_delete[] = XDB::format('{?}', $promo); } XDB::execute('DELETE FROM watch_promo WHERE ' . XDB::format('uid = {?}', S::i('uid')) . ' AND promo IN (' . implode(', ', $to_delete) . ')'); S::user()->invalidWatchCache(); Platal::session()->updateNbNotifs(); }
public function buildCondition(PlFilter $f) { $c = $f->addCasteFilter(); $cu = $f->addUserFilter(); return XDB::format("{$c}.rights = {?} OR ({$c}.rights = {?} AND {$cu}.uid IN {?})", (string) Rights::everybody(), (string) Rights::restricted(), $this->uids); }
function get_event_participants(&$evt, $item_id, array $tri = array(), $limit = null, $offset = 0) { global $globals; $eid = $evt['eid']; $money = $evt['money'] && function_exists('may_update') && may_update(); $pay_id = $evt['paiement_id']; $append = $item_id ? XDB::format(' AND ep.item_id = {?}', $item_id) : ''; $query = XDB::fetchAllAssoc('uid', 'SELECT ep.uid, SUM(ep.paid) AS paid, SUM(ep.nb) AS nb, FIND_IN_SET(\'notify_payment\', ep.flags) AS notify_payment FROM group_event_participants AS ep WHERE ep.eid = {?} AND nb > 0 ' . $append . ' GROUP BY ep.uid', $eid); $uf = new UserFilter(new PFC_True(), $tri); $users = User::getBulkUsersWithUIDs($uf->filter(array_keys($query), new PlLimit($limit, $offset))); $tab = array(); foreach ($users as $user) { $uid = $user->id(); $tab[$uid] = $query[$uid]; $tab[$uid]['user'] = $user; } if ($item_id) { return $tab; } $evt['adminpaid'] = 0; $evt['telepaid'] = 0; $evt['topay'] = 0; $evt['paid'] = 0; foreach ($tab as $uid => &$u) { $u['adminpaid'] = (double) $u['paid']; $u['montant'] = 0; if ($money && $pay_id) { $montant = XDB::fetchOneCell('SELECT SUM(amount) FROM payment_transactions AS t WHERE status = "confirmed" AND ref = {?} AND uid = {?}', $pay_id, $uid); $u['paid'] += $montant; } $u['telepayment'] = $u['paid'] - $u['adminpaid']; $res_ = XDB::iterator('SELECT ep.nb, ep.item_id, ei.montant FROM group_event_participants AS ep INNER JOIN group_event_items AS ei ON (ei.eid = ep.eid AND ei.item_id = ep.item_id) WHERE ep.eid = {?} AND ep.uid = {?}', $eid, $uid); while ($i = $res_->next()) { $u[$i['item_id']] = $i['nb']; $u['montant'] += $i['montant'] * $i['nb']; } $evt['telepaid'] += $u['telepayment']; $evt['adminpaid'] += $u['adminpaid']; $evt['paid'] += $u['paid']; $evt['topay'] += $u['montant']; } return $tab; }
public function buildCondition(PlFilter $f) { $c = $f->addCasteFilter(); $cu = $f->addUserFilter(); return XDB::format("{$c}.rights = {?} AND {$cu}.uid IN {?}", (string) $this->rights, $this->uids); }
protected function getIDList($ids = null, PlLimit $limit) { $schema = $this->schema(); $as = $schema['as']; $id = $schema['id']; $this->buildQuery(); $lim = $limit->getSql(); $cond = ''; if (!is_null($ids)) { $cond = XDB::format(" AND {$as}.{$id} IN {?}", $ids); } $fetched = XDB::fetchColumn("SELECT SQL_CALC_FOUND_ROWS {$as}.{$id}\n {$this->query}\n {$cond}\n GROUP BY {$as}.{$id}\n {$this->orderby}\n {$lim}"); $this->lastcount = (int) XDB::fetchOneCell('SELECT FOUND_ROWS()'); return $fetched; }
function handler_add_secondary_edu($page) { $page->changeTpl('admin/add_secondary_edu.tpl'); if (!(Post::has('verify') || Post::has('add'))) { return; } elseif (!Post::has('people')) { $page->trigWarning("Aucune information n'a été fournie."); return; } require_once 'name.func.inc.php'; $lines = explode("\n", Post::t('people')); $separator = Post::t('separator'); $degree = Post::v('degree'); $promotion = Post::i('promotion'); $schoolsList = array_flip(DirEnum::getOptions(DirEnum::EDUSCHOOLS)); $degreesList = array_flip(DirEnum::getOptions(DirEnum::EDUDEGREES)); $edu_id = $schoolsList[Profile::EDU_X]; $degree_id = $degreesList[$degree]; $res = array('incomplete' => array(), 'empty' => array(), 'multiple' => array(), 'already' => array(), 'new' => array()); $old_pids = array(); $new_pids = array(); foreach ($lines as $line) { $line = trim($line); $line_array = explode($separator, $line); array_walk($line_array, 'trim'); if (count($line_array) != 3) { $page->trigError("La ligne « {$line} » est incomplète."); $res['incomplete'][] = $line; continue; } $cond = new PFC_And(new UFC_NameTokens(split_name_for_search($line_array[0]), array(), false, false, Profile::LASTNAME)); $cond->addChild(new UFC_NameTokens(split_name_for_search($line_array[1]), array(), false, false, Profile::FIRSTNAME)); $cond->addChild(new UFC_Promo('=', UserFilter::DISPLAY, $line_array[2])); $uf = new UserFilter($cond); $pid = $uf->getPIDs(); $count = count($pid); if ($count == 0) { $page->trigError("La ligne « {$line} » ne correspond à aucun profil existant."); $res['empty'][] = $line; continue; } elseif ($count > 1) { $page->trigError("La ligne « {$line} » correspond à plusieurs profils existant."); $res['multiple'][] = $line; continue; } else { $count = XDB::fetchOneCell('SELECT COUNT(*) AS count FROM profile_education WHERE pid = {?} AND eduid = {?} AND degreeid = {?}', $pid, $edu_id, $degree_id); if ($count == 1) { $res['already'][] = $line; $old_pids[] = $pid[0]; } else { $res['new'][] = $line; $new_pids[] = $pid[0]; } } } $display = array(); foreach ($res as $type => $res_type) { if (count($res_type) > 0) { $display = array_merge($display, array('--------------------' . $type . ':'), $res_type); } } $page->assign('people', implode("\n", $display)); $page->assign('promotion', $promotion); $page->assign('degree', $degree); if (Post::has('add')) { $entry_year = $promotion - Profile::educationDuration($degree); if (Post::b('force_addition')) { $pids = array_unique(array_merge($old_pids, $new_pids)); } else { $pids = array_unique($new_pids); // Updates years. if (count($old_pids)) { XDB::execute('UPDATE profile_education SET entry_year = {?}, grad_year = {?}, promo_year = {?} WHERE pid IN {?} AND eduid = {?} AND degreeid = {?}', $entry_year, $promotion, $promotion, $old_pids, $edu_id, $degree_id); } } // Precomputes values common to all users. $select = XDB::format('MAX(id) + 1, pid, {?}, {?}, {?}, {?}, {?}, \'secondary\'', $edu_id, $degree_id, $entry_year, $promotion, $promotion); XDB::startTransaction(); foreach ($pids as $pid) { XDB::execute('INSERT INTO profile_education (id, pid, eduid, degreeid, entry_year, grad_year, promo_year, flags) SELECT ' . $select . ' FROM profile_education WHERE pid = {?} GROUP BY pid', $pid); } XDB::commit(); } }
function update_plain($data, $string, &$update, $has_ordinary) { $string = substr($string, 1, strlen($string) - 2); if ($string == $data['lastname_main']) { return true; } if ($string != $data['pseudonym']) { if ($has_ordinary) { $update[] = XDB::format('pseudonym = {?}', $string); } else { $update[] = XDB::format('lastname_main = {?}', $string); } return true; } return false; }
* Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ /** * This script saves database information into outputed SQL lines */ require_once dirname(__FILE__) . '/connect.db.inc.php'; // DELETE confidential data echo XDB::format('UPDATE account SET password={?};', '') . PHP_EOL; echo 'DELETE FROM remote;' . PHP_EOL; echo 'DELETE FROM remote_groups;' . PHP_EOL; // Get this data from bdd $iter = XDB::iterRow('SELECT hruid, password FROM account WHERE password != {?}', ''); while (list($hruid, $password) = $iter->next()) { echo XDB::format('UPDATE account SET password = {?} WHERE hruid = {?};', $password, $hruid) . PHP_EOL; } // Save dev's remote sites $remote_cols = array('site', 'privkey', 'label', 'rights'); $remotes = Remote::selectAll(RemoteSelect::groups()); foreach ($remotes as $r) { $query = XDB::format('INSERT INTO remote SET remid = {?}', $r->id()); foreach ($remote_cols as $c) { $query .= XDB::format(', ' . $c . ' = {?}', $r->{$c}()); } echo $query . ';' . PHP_EOL; foreach ($r->groups() as $g) { echo XDB::format('INSERT INTO remote_groups SET remid = {?}, gid = {?};', $r->id(), $g->id()) . PHP_EOL; } }