private function fetchJobs(ProfilePage $page) { // Build the jobs tree $jobs = XDB::fetchAllAssoc('SELECT j.id, j.jobid, je.name, j.description, j.email AS w_email, j.email_pub AS w_email_pub, j.url AS w_url, j.pub, j.entry_year AS w_entry_year FROM profile_job AS j LEFT JOIN profile_job_enum AS je ON (j.jobid = je.id) WHERE j.pid = {?} ORDER BY j.id', $page->pid()); if (empty($jobs)) { return array($this->emptyJob()); } $compagnies = array(); $backtrack = array(); foreach ($jobs as $key => $job) { $compagnies[] = $job['jobid']; $backtrack[$job['id']] = $key; } $it = Address::iterate(array($page->pid()), array(Address::LINK_JOB), array(), Visibility::get(Visibility::VIEW_ADMIN)); while ($address = $it->next()) { $jobs[$address->id]['w_address'] = $address->toFormArray(); } $it = Phone::iterate(array($page->pid()), array(Phone::LINK_JOB), array(), Visibility::get(Visibility::VIEW_ADMIN)); while ($phone = $it->next()) { $jobs[$phone->link_id]['w_phone'][$phone->id] = $phone->toFormArray(); } $res = XDB::iterator("SELECT e.jtid, e.full_name, j.jid\n FROM profile_job_term_enum AS e\n INNER JOIN profile_job_term AS j USING(jtid)\n WHERE pid = {?}\n ORDER BY j.jid", $page->pid()); while ($term = $res->next()) { // $jid is the ID of the job among this user's jobs $jid = $term['jid']; if (!isset($backtrack[$jid])) { continue; } $job =& $jobs[$backtrack[$jid]]; if (!isset($job['terms'])) { $job['terms'] = array(); } $job['terms'][] = $term; } $phone = new Phone(); $address = new Address(); foreach ($jobs as $id => &$job) { if (!isset($job['w_phone'])) { $job['w_phone'] = array(0 => $phone->toFormArray()); } if (!isset($job['w_address'])) { $job['w_address'] = $address->toFormArray(); } $job['w_email_new'] = ''; if (!isset($job['w_email_pub'])) { $job['w_email_pub'] = 'private'; } } return $jobs; }
/** The constructor, creates a new entry in the sessions table * * @param $uid the id of the logged user * @param $suid the id of the administrator who has just su'd to the user * @return VOID */ public function __construct($uid, $suid = 0) { // write the session entry $this->uid = $uid; $this->session = $this->writeSession($uid, $suid); // retrieve available actions $this->actions = XDB::fetchAllAssoc('text', 'SELECT id, text FROM log_actions'); }
public function __construct(User $user, array $uids, $group, $dim) { parent::__construct($user, false, 'bulkaccounts'); $this->group = $group; $this->dim = $dim; $this->users = XDB::fetchAllAssoc('SELECT uid, hruid, email FROM accounts WHERE uid IN {?}', $uids); }
public function __construct(User $user, $hruid, $email, $group, $dim) { parent::__construct($user, false, 'account'); $this->hruid = $hruid; $this->email = $email; $this->group = $group; $this->dim = $dim; $this->uid = XDB::fetchOneCell('SELECT uid FROM accounts WHERE hruid = {?}', $hruid); $this->groups = XDB::fetchAllAssoc('SELECT g.nom, g.diminutif FROM groups AS g INNER JOIN group_members AS m ON (g.id = m.asso_id) WHERE m.uid = {?} ORDER BY g.nom', $this->uid); }
public function value(ProfilePage $page, $field, $value, &$success) { $success = true; if (is_null($value) || !S::user()->isMyProfile($profile) && $page->values['medals_pub'] == 'private' && !S::user()->checkPerms(User::PERM_DIRECTORY_PRIVATE)) { // Fetch already attributed medals $value = XDB::fetchAllAssoc("SELECT m.mid AS id, m.gid AS grade, 1 AS valid, FIND_IN_SET('has_levels', e.flags) AS has_levels, m.level\n FROM profile_medals AS m\n INNER JOIN profile_medal_enum AS e ON (m.mid = e.id)\n WHERE m.pid = {?}", $page->pid()); // Fetch not yet validated medals $medals = ProfileValidate::get_typed_requests($page->pid(), 'medal'); foreach ($medals as &$medal) { $value[] = array('id' => $medal->mid, 'grade' => $medal->gid, 'level' => $medal->level, 'has_levels' => $medal->has_levels, 'valid' => '0'); } } elseif (!is_array($value)) { $value = array(); } usort($value, 'self::compareMedals'); return $value; }
function handler_marketing($page) { $page->changeTpl('marketing/index.tpl'); $page->setTitle('Marketing'); $alive = array('all' => new ProfileFilter(new PFC_Not(new UFC_Dead())), 'women' => new ProfileFilter(new PFC_And(new UFC_Sex(User::GENDER_FEMALE), new PFC_Not(new UFC_Dead()))), 'x' => new ProfileFilter(new PFC_And(new PFC_Not(new UFC_Dead()), new UFC_AccountType('x'))), '72' => new ProfileFilter(new PFC_And(new UFC_Promo('>=', UserFilter::GRADE_ING, 1972), new PFC_Not(new UFC_Dead()))), 'master' => new ProfileFilter(new PFC_And(new PFC_Not(new UFC_Dead()), new UFC_AccountType('master'))), 'phd' => new ProfileFilter(new PFC_And(new PFC_Not(new UFC_Dead()), new UFC_AccountType('phd')))); $registered = array('all' => new ProfileFilter(new PFC_And(new UFC_Registered(true), new PFC_Not(new UFC_Dead()))), 'women' => new ProfileFilter(new PFC_And(new UFC_Registered(true), new UFC_Sex(User::GENDER_FEMALE), new PFC_Not(new UFC_Dead()))), 'x' => new ProfileFilter(new PFC_And(new UFC_Registered(true), new PFC_Not(new UFC_Dead()), new UFC_AccountType('x'))), '72' => new ProfileFilter(new PFC_And(new UFC_Registered(true), new UFC_Promo('>=', UserFilter::GRADE_ING, 1972), new PFC_Not(new UFC_Dead()))), 'master' => new ProfileFilter(new PFC_And(new UFC_Registered(true), new PFC_Not(new UFC_Dead()), new UFC_AccountType('master'))), 'phd' => new ProfileFilter(new PFC_And(new UFC_Registered(true), new PFC_Not(new UFC_Dead()), new UFC_AccountType('phd')))); $statistics = array('all' => array('description' => "Étudiants et anciens de l'X"), 'women' => array('description' => "Étudiantes et anciennes de l'X"), 'x' => array('description' => 'X'), '72' => array('description' => 'X vivants depuis la promo 1972'), 'master' => array('description' => "Masters de l'X"), 'phd' => array('description' => "Docteurs de l'X")); foreach ($statistics as $key => &$data) { $data['alive'] = $alive[$key]->getTotalCount(); $data['registered'] = $registered[$key]->getTotalCount(); $data['rate'] = round($data['registered'] / $data['alive'] * 100, 2); } $registeredWeek = new ProfileFilter(new PFC_And(new UFC_Registered(true, '>=', strtotime('1 week ago')), new PFC_Not(new UFC_Dead()))); $registrationPending = XDB::fetchOneCell('SELECT COUNT(*) FROM register_pending'); $registrations = array('week' => $registeredWeek->getTotalCount(), 'pending' => $registrationPending); $ok = XDB::fetchOneCell('SELECT COUNT(*) FROM register_mstats WHERE success != \'0000-00-00\''); $okWeek = XDB::fetchOneCell('SELECT COUNT(*) FROM register_mstats WHERE success >= {?}', strtotime('1 week ago')); $res = XDB::fetchAllAssoc('SELECT type, COUNT(*) as count FROM register_marketing GROUP BY type'); $no = array(); foreach ($res as $value) { $no[$value['type']] = $value['count']; } $no['week'] = XDB::fetchOneCell('SELECT COUNT(*) FROM register_marketing WHERE last >= {?}', strtotime('1 week ago')); $marketings = array('ok' => $ok, 'okWeek' => $okWeek, 'noPerso' => isset($no['user']) ? $no['user'] : 0, 'noXorg' => isset($no['staff']) ? $no['staff'] : 0, 'noAX' => isset($no['ax']) ? $no['ax'] : 0, 'noWeek' => $no['week']); $page->assign('statistics', $statistics); $page->assign('registrations', $registrations); $page->assign('marketings', $marketings); }
private function _getActions() { $actions = XDB::fetchAllAssoc('id', 'SELECT id, description FROM log_actions'); $actions[0] = '----'; ksort($actions); return $actions; }
* This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ require_once 'connect.db.inc.php'; require_once 'plmailer.php'; $limit = 60; $users = XDB::fetchAllAssoc('SELECT a.uid, a.hruid, r.hash, r.group_name, r.sender_name, r.email FROM register_pending_xnet AS r INNER JOIN accounts AS a ON (r.uid = a.uid) WHERE a.state = \'disabled\' ORDER BY r.date, a.uid'); $mailer = new PlMailer('xnet/account.mail.tpl'); $mailer->addCc('*****@*****.**'); $i = 0; foreach ($users as $user) { $mailer->setTo($user['email']); $mailer->assign('hash', $user['hash']); $mailer->assign('email', $user['email']); $mailer->assign('group', $user['group_name']); $mailer->assign('sender_name', $user['sender_name']); $mailer->assign('again', false); $mailer->assign('baseurl', Platal::globals()->baseurl); $mailer->send(); XDB::execute('UPDATE accounts
echo "Nouvelles adresses en panne detectees :\n"; foreach ($res as $assoc) { echo '* ' . $assoc['redirect'] . ' pour ' . $assoc['hruid'] . "\n"; } echo "\n\n"; Xdb::execute("UPDATE email_redirect_account\n SET flags = 'broken'\n WHERE broken_level = 3"); } Xdb::execute('UPDATE email_redirect_account SET broken_level = {?} WHERE broken_level > {?}', $panne_level, $panne_level); } /* * Retrieve the users with no active redirection, but still one working * inactive redirection. */ if ($opt_verbose) { $res = XDB::fetchAllAssoc("SELECT a.hruid, r2.redirect\n FROM accounts AS a\n LEFT JOIN email_redirect_account AS r1 ON (a.uid = r1.uid AND r1.flags = 'active')\n INNER JOIN email_redirect_account AS r2 ON (a.uid = r2.uid AND r2.flags = 'inactive'\n AND r2.type != 'imap' AND r2.type != 'homonym')\n WHERE r1.uid IS NULL\n GROUP BY a.uid"); if ($res) { echo "Camarades n'ayant plus d'adresses actives, mais ayant une adresse inactive :\n"; foreach ($res as $user) { echo '* ' . $user['redirect'] . ' pour ' . $user['hruid'] . "\n"; } } echo "\n"; } /* * Updates imap settings for users with no active redirection. Their emails * must go to imap and bounce. */ XDB::execute("UPDATE email_redirect_account AS r\n LEFT JOIN email_redirect_account AS a ON (r.uid = a.uid AND a.flags = 'active' AND a.type != 'imap')\n SET r.action = 'imap_and_bounce'\n WHERE r.type = 'imap' AND a.redirect IS NULL"); // vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
public function value(ProfilePage $page, $field, $value, &$success) { $success = true; if (is_null($value)) { $value = XDB::fetchAllAssoc('SELECT type, text, pub FROM profile_hobby WHERE pid = {?}', $page->pid()); } if (!is_array($value)) { return array(); } foreach ($value as $i => &$hobby) { $hobby['text'] = trim($hobby['text']); if (!$hobby['text'] || !in_array($hobby['type'], self::$type)) { unset($value[$i]); } else { if (!isset($hobby['pub'])) { $hobby['pub'] = 'private'; } $s = true; $hobby['pub'] = $this->pub->value($page, 'pub', $hobby['pub'], $s); $success = $success && $s; } } return $value; }
public function articleSearch($search, $field, $user) { $search = XDB::formatWildcards(XDB::WILDCARD_CONTAINS, $search); if ($field == self::SEARCH_ALL) { $where = '(a.title ' . $search . ' OR a.body ' . $search . ' OR a.append ' . $search . ')'; } else { $where = 'a.' . $field . $search; } $list = XDB::fetchAllAssoc('SELECT i.short_name, a.aid, i.id, a.title FROM newsletter_art AS a INNER JOIN newsletter_issues AS i ON (a.id = i.id) WHERE i.nlid = {?} AND i.state = \'sent\' AND ' . $where . ' GROUP BY a.id, a.aid ORDER BY i.date DESC, a.aid', $this->id); $articles = array(); foreach ($list as $item) { $issue = new NLIssue($item['id'], $this, false); if ($issue->checkUser($user)) { $articles[] = $item; } } return $articles; }
/** * Page for url "profile/jobterms" (function also used for "referent/autocomplete" @see * handler_ref_autocomplete). Displays an "autocomplete" page (plain text with values * separated by "|" chars) for jobterms to add in profile. * @param $page the Platal page * @param $type set to 'mentor' to display the number of mentors for each term and order * by descending number of mentors. * * @param Env::v('q') the text that has been typed and to complete automatically */ function handler_jobterms($page, $type = 'nomentor') { pl_content_headers("text/plain"); $q = Env::v('term') . '%'; $tokens = JobTerms::tokenize($q); if (count($tokens) == 0) { exit; } sort($tokens); $q_normalized = implode(' ', $tokens); // Try to look in cached results. $cached = false; $cache = XDB::query('SELECT result FROM search_autocomplete WHERE name = {?} AND query = {?} AND generated > NOW() - INTERVAL 1 DAY', $type, $q_normalized); if ($cache->numRows() > 0) { $cached = true; $data = explode("\n", $cache->fetchOneCell()); $list = array(); foreach ($data as $line) { if ($line != '') { $aux = explode("\t", $line); if ($type == 'mentor') { $item = array('field' => $aux[0], 'nb' => $aux[1], 'id' => $aux[2]); $item['value'] = SearchModule::format_autocomplete($item); } else { $item = array('value' => $aux[0], 'id' => $aux[1]); } array_push($list, $item); } } } else { $joins = JobTerms::token_join_query($tokens, 'e'); if ($type == 'mentor') { $count = ', COUNT(DISTINCT pid) AS nb'; $countjoin = ' INNER JOIN profile_job_term_relation AS r ON(r.jtid_1 = e.jtid) INNER JOIN profile_mentor_term AS m ON(r.jtid_2 = m.jtid)'; $countorder = 'nb DESC, '; } else { $count = $countjoin = $countorder = ''; } $list = XDB::fetchAllAssoc('SELECT e.jtid AS id, e.full_name AS field' . $count . ' FROM profile_job_term_enum AS e ' . $joins . $countjoin . ' GROUP BY e.jtid ORDER BY ' . $countorder . 'field LIMIT ' . DirEnumeration::AUTOCOMPLETE_LIMIT); $to_cache = ''; if ($type == 'mentor') { foreach ($list as &$item) { $to_cache .= $item['field'] . "\t" . $item['nb'] . "\t" . $item['id'] . "\n"; $item['value'] = SearchModule::format_autocomplete($item); } } else { foreach ($list as &$item) { $to_cache .= $item['field'] . "\t" . $item['id'] . "\n"; $item['value'] = $item['field']; } } } if (count($list) == DirEnumeration::AUTOCOMPLETE_LIMIT && $type == 'nomentor') { $list[] = array('value' => '… parcourir les résultats dans un arbre …', 'field' => '', 'id' => -1); } if (!$cached) { XDB::query('INSERT INTO search_autocomplete (name, query, result, generated) VALUES ({?}, {?}, {?}, NOW()) ON DUPLICATE KEY UPDATE result = VALUES(result), generated = VALUES(generated)', $type, $q_normalized, $to_cache); } echo json_encode($list); exit; }
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 toCSV($sep = ',', $enc = '"', $asep = '|') { $nbq = count($this->questions); //require_once dirname(__FILE__) . '/../../classes/varstream.php'; VarStream::init(); global $csv_output; $csv_output = ''; $csv = fopen('var://csv_output', 'w'); $line = $this->isMode(self::MODE_XIDENT) ? array('id', 'Nom', 'Prenom', 'Promo') : array('id'); $qids = array(); for ($qid = 0; $qid < $nbq; $qid++) { $qids[$qid] = count($line); // stores the first id of a question (in case of questions with subquestions) array_splice($line, count($line), 0, $this->questions[$qid]->getCSVColumns()); // the first line contains the questions } $nbf = count($line); $users = array(); if ($this->isMode(self::MODE_XIDENT)) { // if the mode is non anonymous $users = User::getBulkUsersWithUIDs(XDB::fetchAllAssoc('vid', 'SELECT v.id AS vid, v.uid FROM survey_votes AS v WHERE v.survey_id = {?} ORDER BY vid ASC', $this->id)); } $sql = 'SELECT v.id AS vid, a.question_id AS qid, a.answer AS answer FROM survey_votes AS v INNER JOIN survey_answers AS a ON a.vote_id=v.id WHERE v.survey_id={?} ORDER BY vid ASC, qid ASC, answer ASC'; $res = XDB::iterator($sql, $this->id); // retrieves all answers from database $vid = -1; $vid_ = 0; while (($cur = $res->next()) != null) { if ($vid != $cur['vid']) { // if the vote id changes, then starts a new line fputcsv($csv, $line, $sep, $enc); // stores the former line into $csv_output $vid = $cur['vid']; $line = array_fill(0, $nbf, ''); // creates an array full of empty string $line[0] = $vid_; // the first field is a 'clean' vote id (not the one stored in database) if ($this->isMode(self::MODE_XIDENT)) { // if the mode is non anonymous if (array_key_exists($vid, $users)) { // and if the user data can be found $line[1] = $users[$vid]->lastName(); // adds the user data (in the first fields of the line) $line[2] = $users[$vid]->firstName(); $line[3] = $users[$vid]->promo(); } } $vid_++; } $ans = $this->questions[$cur['qid']]->formatAnswer($cur['answer']); // formats the current answer if (!is_null($ans)) { if (is_array($ans)) { $fid = $qids[$cur['qid']] + $ans['id']; // computes the field id $a = $ans['answer']; } else { $fid = $qids[$cur['qid']]; $a = $ans; } if ($line[$fid] != '') { // if this field already contains something $line[$fid] .= $asep; // then adds a separator before adding the new answer } $line[$fid] .= $a; // adds the current answer to the correct field } } fputcsv($csv, $line, $sep, $enc); // stores the last line into $csv_output return $csv_output; }
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))); }
public function getAutoComplete($text, $sub_id = null) { $tokens = JobTerms::tokenize($text . '%'); if (count($tokens) == 0) { return array(); } $token_join = JobTerms::token_join_query($tokens, 'e'); return XDB::fetchAllAssoc('SELECT e.jtid AS id, e.full_name AS field, COUNT(DISTINCT p.pid) AS nb FROM profile_job_term_enum AS e INNER JOIN profile_job_term_relation AS r ON (r.jtid_1 = e.jtid) INNER JOIN profile_job_term AS p ON (r.jtid_2 = p.jtid) ' . $token_join . ' GROUP BY e.jtid ORDER BY nb DESC, field LIMIT ' . self::AUTOCOMPLETE_LIMIT); }
function handler_awaiting_active($page) { global $globals; $page->changeTpl('xnetgrp/awaiting_active.tpl'); XDB::execute('DELETE FROM register_pending_xnet WHERE DATE_SUB(NOW(), INTERVAL 1 MONTH) > date'); $uids = XDB::fetchColumn('SELECT g.uid FROM group_members AS g INNER JOIN accounts AS a ON (a.uid = g.uid) INNER JOIN register_pending_xnet AS p ON (p.uid = g.uid) WHERE a.uid = g.uid AND g.asso_id = {?} AND a.type = \'xnet\' AND a.state = \'pending\'', $globals->asso('id')); if (Post::has('again')) { S::assert_xsrf_token(); $uids_to_again = array_intersect(array_keys(Post::v('again')), $uids); foreach ($uids_to_again as $uid) { $this->again($uid); } $page->trigSuccess('Relances effectuées avec succès.'); } if ($uids) { $registration_date = XDB::fetchAllAssoc('uid', 'SELECT uid, date FROM register_pending_xnet WHERE uid IN {?}', $uids); $last_date = XDB::fetchAllAssoc('uid', 'SELECT uid, last_date FROM register_pending_xnet WHERE uid IN {?}', $uids); $users = User::getBulkUsersWithUIDs($uids); $page->assign('users', $users); $page->assign('registration_date', $registration_date); $page->assign('last_date', $last_date); } }
function handler_payment_csv($page, $pid = null) { if (is_null($pid)) { pl_redirect('payment'); } if (substr($pid, -4) == '.vcf') { $pid = substr($pid, 0, strlen($pid) - 4); } $res = XDB::fetchAllAssoc('SELECT uid, IF(ts_confirmed = \'0000-00-00\', 0, ts_confirmed) AS date, comment, amount FROM payment_transactions WHERE ref = {?} ORDER BY ts_confirmed', $pid); if (is_null($res)) { pl_redirect('payment'); } $users = User::getBulkUsersWithUIDs($res, 'uid', 'user'); $sum = 0; pl_cached_content_headers('text/x-csv', 'iso-8859-1', 1); $csv = fopen('php://output', 'w'); fputcsv($csv, array('Date', 'Nom', utf8_decode('Prénom'), 'Sexe', 'Promotion', 'Email', 'Commentaire', 'Montant'), ';'); foreach ($users as $item) { $user = $item['user']; $sum += $item['amount']; fputcsv($csv, array(format_datetime($item['date'], '%d/%m/%y'), utf8_decode($user->lastName()), utf8_decode($user->firstName()), $user->isFemale() ? 'F' : 'M', $user->promo(), $user->ForlifeEmail(), utf8_decode($item['comment']), strtr($item['amount'], '.', ',') . ' EUR'), ';'); } fputcsv($csv, array(date('d/m/y'), 'Total', '', '', '', '', '', strtr($sum, '.', ',') . ' EUR'), ';'); fclose($csv); exit; }
function handler_admin($page, $eid = null, $item_id = null) { global $globals; $this->load('xnetevents.inc.php'); $evt = get_event_detail($eid, $item_id); if (!$evt) { return PL_NOT_FOUND; } $page->changeTpl('xnetevents/admin.tpl'); if (!$evt['show_participants'] && !may_update()) { return PL_FORBIDDEN; } if (may_update() && Post::v('adm')) { S::assert_xsrf_token(); $member = User::getSilent(Post::v('mail')); if (!$member) { $page->trigError("Membre introuvable"); } // change the price paid by a participant if (Env::v('adm') == 'prix' && $member) { $amount = strtr(Env::v('montant'), ',', '.'); XDB::execute("UPDATE group_event_participants\n SET paid = paid + {?}\n WHERE uid = {?} AND eid = {?} AND nb > 0\n ORDER BY item_id ASC\n LIMIT 1", $amount, $member->uid, $evt['eid']); subscribe_lists_event($member->uid, $evt['short_name'], 1, $amount); } // change the number of personns coming with a participant if (Env::v('adm') == 'nbs' && $member) { $res = XDB::query("SELECT SUM(paid)\n FROM group_event_participants\n WHERE uid = {?} AND eid = {?}", $member->uid, $evt['eid']); $paid = $res->fetchOneCell(); // Ensure we have an integer if ($paid == null) { $paid = 0; } $nbs = Post::v('nb', array()); $paid_inserted = false; foreach ($nbs as $id => $nb) { $nb = max(intval($nb), 0); if (!$paid_inserted && $nb > 0) { $item_paid = $paid; $paid_inserted = true; } else { $item_paid = 0; } XDB::execute('INSERT INTO group_event_participants (eid, uid, item_id, nb, flags, paid) VALUES ({?}, {?}, {?}, {?}, {?}, {?}) ON DUPLICATE KEY UPDATE nb = VALUES(nb), flags = VALUES(flags), paid = VALUES(paid)', $evt['eid'], $member->uid, $id, $nb, '', $item_paid); } $res = XDB::query('SELECT COUNT(uid) AS cnt, SUM(nb) AS nb FROM group_event_participants WHERE uid = {?} AND eid = {?} GROUP BY uid', $member->uid, $evt['eid']); $u = $res->fetchOneAssoc(); if ($paid == 0 && Post::v('cancel')) { XDB::execute("DELETE FROM group_event_participants\n WHERE uid = {?} AND eid = {?}", $member->uid, $evt['eid']); $u = 0; subscribe_lists_event($member->uid, $evt['short_name'], -1, $paid); } else { $u = $u['cnt'] ? $u['nb'] : null; subscribe_lists_event($member->uid, $evt['short_name'], $u > 0 ? 1 : 0, $paid); } } $evt = get_event_detail($eid, $item_id); } $page->assign_by_ref('evt', $evt); $page->assign('tout', is_null($item_id)); if (count($evt['moments'])) { $page->assign('moments', $evt['moments']); } if ($evt['paiement_id']) { $infos = User::getBulkUsersWithUIDs(XDB::fetchAllAssoc('SELECT t.uid, t.amount FROM payment_transactions AS t LEFT JOIN group_event_participants AS ep ON(ep.uid = t.uid AND ep.eid = {?}) WHERE t.status = "confirmed" AND t.ref = {?} AND ep.uid IS NULL', $evt['eid'], $evt['paiement_id']), 'uid', 'user'); $page->assign('oublis', count($infos)); $page->assign('oubliinscription', $infos); } $absents = User::getBulkUsersFromDB('SELECT p.uid FROM group_event_participants AS p LEFT JOIN group_event_participants AS p2 ON (p2.uid = p.uid AND p2.eid = p.eid AND p2.nb != 0) WHERE p.eid = {?} AND p2.eid IS NULL GROUP BY p.uid', $evt['eid']); $ofs = Env::i('offset'); $part = get_event_participants($evt, $item_id, UserFilter::sortByName(), NB_PER_PAGE, $ofs * NB_PER_PAGE); $nbp = ceil($evt['user_count'] / NB_PER_PAGE); if ($nbp > 1) { $links = array(); if ($ofs) { $links['précédent'] = $ofs - 1; } for ($i = 1; $i <= $nbp; $i++) { $links[(string) $i] = $i - 1; } if ($ofs < $nbp - 1) { $links['suivant'] = $ofs + 1; } $page->assign('links', $links); } $page->assign('absents', $absents); $page->assign('participants', $part); }
function handler_issues($page, $action = '') { static $issueList = array('name' => 'noms', 'phone' => 'téléphones', 'education' => 'formations', 'address' => 'adresses', 'job' => 'emplois'); static $typeList = array('name' => 'general', 'phone' => 'general', 'education' => 'general', 'address' => 'adresses', 'job' => 'emploi'); if (!array_key_exists($action, $issueList)) { pl_redirect('fusionax'); } else { $total = XDB::fetchOneCell('SELECT COUNT(*) FROM profile_merge_issues WHERE FIND_IN_SET({?}, issues)', $action); if ($total == 0) { pl_redirect('fusionax'); } $issues = XDB::fetchAllAssoc('SELECT p.hrpid, pd.directory_name, pd.promo FROM profile_merge_issues AS pm INNER JOIN profiles AS p ON (pm.pid = p.pid) INNER JOIN profile_display AS pd ON (pd.pid = p.pid) WHERE FIND_IN_SET({?}, pm.issues) ORDER BY pd.directory_name LIMIT 100', $action); $page->changeTpl('fusionax/other_issues.tpl'); $page->assign('issues', $issues); $page->assign('issue', $issueList[$action]); $page->assign('type', $typeList[$action]); $page->assign('total', $total); } }
public function __construct(User $user) { if (!$user) { return; } $this->user =& $user; $res = XDB::fetchOneAssoc('SELECT COUNT(DISTINCT(action)) AS action_count, COUNT(redirect) AS redirect_count, action FROM email_redirect_account WHERE uid = {?} AND (type = \'smtp\' OR type = \'googleapps\') AND flags = \'active\' GROUP BY uid', $user->id()); if ($res['redirect_count'] == 0) { return; } $this->single_redirection = $res['redirect_count'] == 1; $this->redirections = XDB::fetchAllAssoc('SELECT IF(type = \'googleapps\', type, redirect) AS redirect, type, action FROM email_redirect_account WHERE uid = {?} AND (type = \'smtp\' OR type = \'googleapps\') ORDER BY type, redirect', $user->id()); foreach ($this->redirections as &$redirection) { $redirection['filter'] = array_search($redirection['action'], self::$states); } if ($res['action_count'] == 1) { $this->state = array_search($res['action'], self::$states); $this->single_state = true; } else { $this->single_state = $this->state = false; } }
public function groups($institutions = false, $onlyPublic = false) { if (is_null($this->groups)) { $this->groups = XDB::fetchAllAssoc('asso_id', 'SELECT gm.asso_id, gm.perms, gm.comm, g.diminutif, g.nom, g.site, g.cat, g.pub FROM group_members AS gm INNER JOIN groups AS g ON (g.id = gm.asso_id) WHERE uid = {?}', $this->id()); } if (!$institutions && !$onlyPublic) { return $this->groups; } else { $result = array(); foreach ($this->groups as $id => $data) { if ($institutions) { if ($data['cat'] != Group::CAT_GROUPESX && $data['cat'] != Group::CAT_INSTITUTIONS) { continue; } } if ($onlyPublic) { if ($data['pub'] != 'public') { continue; } } $result[$id] = $data; } return $result; } }
function update_display_names(Profile $profile, array $public_names, array $private_names = null) { if (is_null($private_names)) { $private_names = XDB::fetchAllAssoc('SELECT type, name FROM profile_private_names WHERE pid = {?} ORDER BY type, id', $profile->id()); } $display_names = build_display_names($public_names, $private_names, $profile->isFemale()); XDB::execute('UPDATE profile_display SET public_name = {?}, private_name = {?}, directory_name = {?}, short_name = {?}, sort_name = {?} WHERE pid = {?}', $display_names['public_name'], $display_names['private_name'], $display_names['directory_name'], $display_names['short_name'], $display_names['sort_name'], $profile->id()); Profile::rebuildSearchTokens($profile->id(), false); if ($profile->owner()) { update_account_from_profile($profile->owner()->id()); } }
protected function action_saveSubs($groups) { global $globals; $uid = $this->user->id(); Banana::$profile['subscribe'] = array(); XDB::execute('DELETE FROM forum_subs WHERE uid = {?}', $this->user->id()); if (!count($groups)) { return true; } $fids = XDB::fetchAllAssoc('name', 'SELECT fid, name FROM forums'); $diff = array_diff($groups, array_keys($fids)); foreach ($diff as $g) { XDB::execute('INSERT INTO forums (name) VALUES ({?})', $g); $fids[$g] = XDB::insertId(); } foreach ($groups as $g) { XDB::execute('INSERT INTO forum_subs (fid, uid) VALUES ({?}, {?})', $fids[$g], $uid); Banana::$profile['subscribe'][] = $g; } }
public static function getPIDsFromUIDs($uids, $respect_order = true) { if ($respect_order) { $order = 'ORDER BY ' . XDB::formatCustomOrder('uid', $uids); } else { $order = ''; } return XDB::fetchAllAssoc('uid', 'SELECT ap.uid, ap.pid FROM account_profiles AS ap WHERE FIND_IN_SET(\'owner\', ap.perms) AND ap.uid IN ' . XDB::formatArray($uids) . ' ' . $order); }
require_once 'connect.db.inc.php'; require_once 'name.func.inc.php'; $globals->debug = 0; // Do not store backtraces. $options = getopt('', array('perform-updates::')); if (isset($options['perform-updates']) && $options['perform-updates'] == 'YES') { $perform_updates = true; } else { $perform_updates = false; } $other_data = XDB::rawFetchOneCell("SELECT COUNT(*)\n FROM profile_name AS pn\n INNER JOIN profile_name_enum AS pne ON (pn.typeid = pne.id)\n WHERE pne.type = 'name_other' OR pne.type = 'firstname_other'"); if ($other_data) { print "Update this script to take 'name_other' and 'firstname_other' into account."; exit; } else { $aliases = XDB::fetchAllAssoc('pid', "SELECT pid, name\n FROM profile_private_names\n WHERE type = 'nickname'"); } // This contains a firstname and a lastname, both can be either main or ordinary. function update_main($data, $string, &$update) { $matches = explode(' ', $string); $count = count($matches); $i = 0; for (; $i < $count + 1; ++$i) { $firstname = implode(' ', array_slice($matches, 0, $i + 1)); $lastname = implode(' ', array_slice($matches, $i + 1)); if ($firstname == $data['firstname_main'] || $firstname == $data['firstname_ordinary']) { if ($lastname == $data['lastname_ordinary']) { return true; } if ($lastname != $data['lastname_main'] && $lastname != $data['lastname_ordinary']) {
#!/usr/bin/php5 <?php require_once 'connect.db.inc.php'; $globals->debug = 0; // Do not store backtraces. $domains = array('x' => 'polytechnique.org', 'master' => 'master.polytechnique.org', 'phd' => 'doc.polytechnique.org'); $domains_ids = XDB::fetchAllAssoc('name', 'SELECT name, id FROM email_virtual_domains WHERE name IN {?}', $domains); foreach ($domains as $type => $domain) { XDB::execute('UPDATE accounts SET best_domain = {?} WHERE type = {?}', $domains_ids[$domain], $type); } /* vim:set et sw=4 sts=4 ts=4: */