public function Prepare($page) { parent::Prepare($page); $res = XDB::iterRow("SELECT sub, domain\n FROM register_subs\n WHERE uid = {?} AND type = 'list'\n ORDER BY domain", S::i('uid')); $lists = array(); while (list($sub, $domain) = $res->next()) { $mlist = new MailingList($sub, $domain); list($details, ) = $mlist->getMembers(); $lists["{$sub}@{$domain}"] = $details; } $page->assign_by_ref('lists', $lists); }
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; }
protected function handler_images(Collection $frankizimages, $size) { $_frankizimages = array(); foreach ($frankizimages as $frankizimage) { $_frankizimages[$frankizimage->id()] = array(); } $iter = XDB::iterRow("SELECT iid, size, x, y, data\n FROM images_sizes\n WHERE size IN {?} AND iid IN {?}", $fields, $frankizimages->ids()); while ($datas = $iter->next()) { $_frankizimages[$datas['iid']][$datas['size']] = new Image($datas); } foreach ($frankizimages as $frankizimage) { $frankizimage->fillFromArray(array('images' => $_frankizimages[$frankizimage->id()])); } }
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; }
public function value(ProfilePage $page, $field, $value, &$success) { if (is_null($value)) { $value = array(); $res = XDB::iterRow("SELECT g.id, g.text\n FROM profile_binet_enum AS g\n INNER JOIN profile_binets AS i ON (i.binet_id = g.id)\n WHERE i.pid = {?}", $page->pid()); while (list($gid, $text) = $res->next()) { $value[intval($gid)] = $text; } } if (!is_array($value)) { $value = array(); } ksort($value); $success = true; return $value; }
protected function handler_item(Collection $validates, $fields) { $items = array(); foreach ($validates as $validate) { $items[$validate->id()] = array(); } $iter = XDB::iterRow("SELECT id, item\n FROM validate\n WHERE id IN {?}", $validates->ids()); while (list($id, $item) = $iter->next()) { $items[$id] = unserialize($item); } $selects = array(); $collections = array(); foreach ($items as $item) { foreach ($item->objects() as $field => $select) { $hash = $select->hash(); $selects[$hash] = $select; if (empty($collections[$hash])) { $collections[$hash] = new Collection($select->className()); } if ($item->{$field}() != false) { $item->{$field}($collections[$hash]->addget($item->{$field}())); } } foreach ($item->collections() as $field => $select) { $hash = $select->hash(); $selects[$hash] = $select; if (empty($collections[$hash])) { $collections[$hash] = new Collection($select->className()); } if ($item->{$field}() != false) { $temp = new Collection($select->className()); foreach ($item->{$field}() as $f) { $temp->add($collections[$hash]->addget($f)); } $item->{$field}($temp); } } } foreach ($collections as $hash => $collection) { $collection->select($selects[$hash]); } foreach ($validates as $validate) { $validate->fillFromArray(array('item' => $items[$validate->id()])); } }
/** affiche un Array javascript contenant les diplômes de chaque formation */ function education_degree() { $html = ''; $res = XDB::iterRow("SELECT eduid, degreeid\n FROM profile_education_degree\n ORDER BY eduid"); $edu_degree = $res->next(); for ($eduid = 1; $edu_degree; ++$eduid) { $html .= '['; if ($edu_degree['0'] == $eduid) { $html .= $edu_degree['1']; $edu_degree = $res->next(); while ($edu_degree['0'] == $eduid) { $html .= ',' . $edu_degree['1']; $edu_degree = $res->next(); } } $html .= ']'; if ($edu_degree) { $html .= ",\n"; } } return $html; }
protected function handler_promos(Collection $formations, $fields) { $_formations = array(); foreach ($formations as $f) { $_formations[$f->id()] = array(); } $iter = XDB::iterRow('SELECT formation_id AS id, GROUP_CONCAT(DISTINCT promo ORDER BY promo SEPARATOR ",") AS p FROM studies WHERE formation_id IN {?} GROUP BY formation_id', $formations->ids()); while (list($id, $promos) = $iter->next()) { $promos = explode(',', $promos); foreach ($promos as &$p) { $p = (int) $p; } sort($promos); $_formations[$id] = $promos; } foreach ($formations as $f) { $f->fillFromArray(array('promos' => $_formations[$f->id()])); } }
function check($sql, $comment = '') { $it = XDB::iterRow($sql); if ($err = XDB::error()) { echo $err; } if ($it->total() > 0) { echo "Erreur pour la vérification : {$comment}\n{$sql}\n\n"; echo "|"; while ($col = $it->nextField()) { echo "\t" . $col->name . "\t|"; } echo "\n"; while ($arr = $it->next()) { echo "|"; foreach ($arr as $val) { echo "\t{$val}\t|"; } echo "\n"; } echo "\n"; } }
<?php /*************************************************************************** * Copyright (C) 2004-2012 Binet Réseau * * http://br.binets.fr/ * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * 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 dirname(__FILE__) . '/../connect.db.inc.php'; $iter = XDB::iterRow('SELECT uid, pa FROM temp'); while (list($uid, $paname) = $iter->next()) { $pa = Group::from($paname); $u = new User($uid); $pa->select(GroupSelect::castes()); $pa->caste(Rights::member())->addUser($u); echo "."; } echo 'Over'; // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
public function selectRights(Collection $users) { $rights = array(); if ($users->count() > 0) { $iter = XDB::iterRow('SELECT cu.uid, c.rights FROM castes AS c INNER JOIN castes_users AS cu ON (cu.cid = c.cid AND (cu.visibility IN {?} OR cu.uid = {?})) INNER JOIN groups AS g ON g.gid = c.`group` WHERE g.gid = {?} AND cu.uid IN {?}', S::user()->visibleGids(), S::user()->id(), $this->id(), $users->ids()); while (list($uid, $right) = $iter->next()) { if (empty($rights[$uid])) { $rights[$uid] = array(); } $rights[$uid][] = new Rights($right); } } return $rights; }
function list_all_my_groups($params) { if (!S::logged()) { return; } $res = XDB::iterRow('SELECT a.nom, a.diminutif FROM groups AS a INNER JOIN group_members AS m ON m.asso_id = a.id WHERE m.uid = {?}', S::i('uid')); $links = '<a href="exit">déconnexion</a>'; $html = '<div>Mes groupes (' . $links . ') :</div>'; while (list($nom, $mini) = $res->next()) { $html .= "<span class='gp'>• <a href='login/{$mini}'>{$nom}</a></span>"; } return $html; }
} elseif ($age > 7) { $head = "[Armageddon imminent] "; } elseif ($age > 5) { $head = "[Guerre nucléaire] "; } elseif ($age > 3) { $head = "[ET Téléphone maison] "; } elseif ($age > 1) { $head = "[Réveil !] "; } elseif (!empty($nbveryold)) { $head = "[Urgent] "; } if (empty($nb)) { exit; } $plural = $nb == 1 ? '' : 's'; $mymail = new PlMailer(); $mymail->setFrom('validation@' . $globals->mail->domain); $mymail->addTo('validation@' . $globals->mail->domain); $mymail->setSubject($head . "Il y a {$nb} validation{$plural} non effectuée{$plural}"); $message = "Il y a {$nb} validation{$plural} à effectuer\n" . (empty($nbold) ? '' : "dont {$nbold} depuis le dernier mail !!!\n") . (empty($nbveryold) ? '' : "et dont *{$nbveryold}* " . ($nbveryold == 1 ? 'est' : 'sont') . ' en retard de plus de 6h !!!') . "\n" . "https://www.polytechnique.org/admin/validate\n\n" . "Par catégorie :\n"; $res = XDB::iterRow('SELECT type, count(*) FROM requests GROUP BY type ORDER BY type'); while (list($type, $nb) = $res->next()) { $message .= "- {$type} : {$nb}\n"; } $message = wordwrap($message, 78); $mymail->setTxtBody($message); $mymail->send(); // vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
public function commit() { global $globals; $email = $this->m_user->bestEmail(); XDB::execute('UPDATE email_redirect_account SET flags = \'active\', broken_level = 2 WHERE uid = {?} AND redirect = {?}', $this->m_user->id(), $this->m_email); if (XDB::affectedRows() > 0) { $this->m_reactive = true; $mailer = new PlMailer(); $mailer->setFrom('"Association Polytechnique.org" <register@' . $globals->mail->domain . '>'); $mailer->addTo($email); $mailer->setSubject("Mise à jour de ton adresse {$email}"); $mailer->setTxtBody(wordwrap("Cher Camarade,\n\n" . "Ton adresse {$email} étant en panne et ayant été informés que ta redirection {$this->m_email}, jusqu'à présent inactive, " . "est fonctionnelle, nous venons de réactiver cette adresse.\n\n" . "N'hésite pas à aller gérer toi-même tes redirections en te rendant à la page :\n" . "https://www.polytechnique.org/emails/redirect\n" . "Si tu as perdu ton mot de passe d'accès au site, tu peux également effectuer la procédure de récupération à l'adresse :\n" . "https://www.polytechnique.org/recovery\n\n" . "-- \nTrès Cordialement,\nL'Équipe de Polytechnique.org\n")); $mailer->send(); return true; } if ($this->m_user->email) { $subject = "Ton adresse {$email} semble ne plus fonctionner"; $reason = "Nous avons été informés que ton adresse {$email} ne fonctionne plus correctement par un camarade"; } else { $res = XDB::iterRow('SELECT redirect FROM email_redirect_account WHERE uid = {?} AND flags = \'broken\'', $this->m_user->id()); $redirect = array(); while (list($red) = $res->next()) { list(, $redirect[]) = explode('@', $red); } $subject = "Ton adresse {$email} ne fonctionne plus"; $reason = "Ton adresse {$email} ne fonctionne plus"; if (!count($redirect)) { $reason .= '.'; } elseif (count($redirect) == 1) { $reason .= ' car sa redirection vers ' . $redirect[0] . ' est hors-service depuis plusieurs mois.'; } else { $reason .= ' car ses redirections vers ' . implode(', ', $redirect) . ' sont hors-services depuis plusieurs mois.'; } } $body = ($this->m_user->isFemale() ? 'Chère ' : 'Cher ') . $this->m_user->displayName() . ",\n\n" . $reason . "\n\n" . "L'adresse {$this->m_email} nous a été communiquée, veux-tu que cette adresse devienne ta nouvelle " . "adresse de redirection ? Si oui, envoie nous des informations qui " . "nous permettront de nous assurer de ton identité (par exemple ta date de naissance et ta promotion).\n\n" . "-- \nTrès Cordialement,\nL'Équipe de Polytechnique.org\n"; $body = wordwrap($body, 78); $mailer = new PlMailer(); $mailer->setFrom('"Association Polytechnique.org" <register@' . $globals->mail->domain . '>'); $mailer->addTo($this->m_email); $mailer->setSubject($subject); $mailer->setTxtBody($body); return $mailer->send(); }
function handler_duplicated($page, $action = 'list', $email = null) { $page->changeTpl('emails/duplicated.tpl'); $states = array('pending' => 'En attente...', 'safe' => 'Pas d\'inquiétude', 'unsafe' => 'Recherches en cours', 'dangerous' => 'Usurpations par cette adresse'); $page->assign('states', $states); if (Post::has('action')) { S::assert_xsrf_token(); } switch (Post::v('action')) { case 'create': if (trim(Post::v('emailN')) != '') { Xdb::execute('INSERT IGNORE INTO email_watch (email, state, detection, last, uid, description) VALUES ({?}, {?}, CURDATE(), NOW(), {?}, {?})', trim(Post::v('emailN')), Post::v('stateN'), S::i('uid'), Post::v('descriptionN')); } break; case 'edit': Xdb::execute('UPDATE email_watch SET state = {?}, last = NOW(), uid = {?}, description = {?} WHERE email = {?}', Post::v('stateN'), S::i('uid'), Post::v('descriptionN'), Post::v('emailN')); break; default: if ($action == 'delete' && !is_null($email)) { Xdb::execute('DELETE FROM email_watch WHERE email = {?}', $email); } } if ($action != 'create' && $action != 'edit') { $action = 'list'; } $page->assign('action', $action); if ($action == 'list') { $it = XDB::iterRow('SELECT w.email, w.detection, w.state, s.email AS forlife FROM email_watch AS w INNER JOIN email_redirect_account AS r ON (w.email = r.redirect) INNER JOIN email_source_account AS s ON (s.uid = r.uid AND s.type = \'forlife\') ORDER BY w.state, w.email, s.email'); $table = array(); $props = array(); while (list($email, $date, $state, $forlife) = $it->next()) { if (count($props) == 0 || $props['mail'] != $email) { if (count($props) > 0) { $table[] = $props; } $props = array('mail' => $email, 'detection' => $date, 'state' => $state, 'users' => array($forlife)); } else { $props['users'][] = $forlife; } } if (count($props) > 0) { $table[] = $props; } $page->assign('table', $table); } elseif ($action == 'edit') { $it = XDB::iterRow('SELECT w.detection, w.state, w.last, w.description, a.hruid AS edit, s.email AS forlife FROM email_watch AS w INNER JOIN email_redirect_account AS r ON (w.email = r.redirect) INNER JOIN email_source_account AS s ON (s.uid = r.uid AND s.type = \'forlife\') LEFT JOIN accounts AS a ON (w.uid = a.uid) WHERE w.email = {?} ORDER BY s.email', $email); $props = array(); while (list($detection, $state, $last, $description, $edit, $forlife) = $it->next()) { if (count($props) == 0) { $props = array('mail' => $email, 'detection' => $detection, 'state' => $state, 'last' => $last, 'description' => $description, 'edit' => $edit, 'users' => array($forlife)); } else { $props['users'][] = $forlife; } } $page->assign('doublon', $props); } }
/** * Select a GID which identifies the visibility of a caste-user assocation */ protected function handler_cuvisibility(Collection $users, $fields) { $_users = array(); foreach ($users as $u) { $_users[$u->id()] = array(); } $viscoll = new Collection('Group'); $iter = XDB::iterRow('SELECT uid, cid, visibility FROM castes_users WHERE uid IN {?}', $users->ids()); while (list($uid, $cid, $vis) = $iter->next()) { $_users[$uid][$cid] = $vis; if ($vis != 0) { $viscoll->add($vis); } } $viscoll->select(GroupSelect::base()); foreach ($users as $u) { $cuarray = array_map(function ($gid) use($viscoll) { return $gid == 0 ? null : $viscoll->get($gid); }, $_users[$u->id()]); $u->fillFromArray(array('cuvisibility' => $cuarray)); } }
public static function retrieveList($type, $tpl = true) { switch ($type) { case 'c': case 'current': $where = 'end > NOW()'; break; case 'o': case 'old': $where = 'end <= NOW()'; break; default: return null; } $sql = 'SELECT id, title, end, mode FROM surveys WHERE ' . $where . ' ORDER BY end DESC;'; if ($tpl) { return XDB::iterator($sql); } else { return XDB::iterRow($sql); } }
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; }
#!/usr/bin/php5 <?php global $globals; require_once 'connect.db.inc.php'; // Fetches the list of existing xnetevents aliases. $events = XDB::iterRow("SELECT e.eid, e.asso_id, e.short_name, al.vid, pl.vid\n FROM groupex.evenements AS e\n LEFT JOIN virtual AS al ON (al.type = 'evt' AND al.alias = CONCAT(short_name, {?}))\n LEFT JOIN virtual AS pl ON (pl.type = 'evt' AND pl.alias = CONCAT(short_name, {?}))\n WHERE al.vid IS NOT NULL AND pl.vid IS NOT NULL\n ORDER BY e.eid", '-absents@' . $globals->xnet->evts_domain, '-participants@' . $globals->xnet->evts_domain); // Fixes the alias recipients for each list. while (list($eid, $asso_id, $shortname, $absent_vid, $participant_vid) = $events->next()) { $recipient_count = array(); foreach (array($absent_vid, $participant_vid) as $vid) { $res = XDB::query("SELECT COUNT(*) FROM virtual_redirect WHERE vid = {?}", $vid); $recipient_count[$vid] = $res->fetchOneCell(); } // Updates the alias for participants. XDB::execute("DELETE FROM virtual_redirect WHERE vid = {?}", $participant_vid); XDB::execute("INSERT INTO virtual_redirect (\n SELECT {?} AS vid, IF(u.nom IS NULL, m.email, CONCAT(a.alias, {?})) AS redirect\n FROM groupex.evenements_participants AS ep\n LEFT JOIN groupex.membres AS m ON (ep.uid = m.uid)\n LEFT JOIN auth_user_md5 AS u ON (u.user_id = ep.uid)\n LEFT JOIN aliases AS a ON (a.id = ep.uid AND a.type = 'a_vie')\n WHERE ep.eid = {?} AND ep.nb > 0\n GROUP BY ep.uid)", $participant_vid, '@' . $globals->mail->domain, $eid); // Updates the alias for absents. XDB::execute("DELETE FROM virtual_redirect WHERE vid = {?}", $absent_vid); XDB::execute("INSERT INTO virtual_redirect (\n SELECT {?} AS vid, IF(u.nom IS NULL, m.email, CONCAT(a.alias, {?})) AS redirect\n FROM groupex.membres AS m\n LEFT JOIN groupex.evenements_participants AS ep ON (ep.uid = m.uid AND ep.eid = {?})\n LEFT JOIN auth_user_md5 AS u ON (u.user_id = m.uid)\n LEFT JOIN aliases AS a ON (a.id = m.uid AND a.type = 'a_vie')\n WHERE m.asso_id = {?} AND ep.uid IS NULL\n GROUP BY m.uid)", $absent_vid, "@" . $globals->mail->domain, $eid, $asso_id); // Lists alias recipient count changes. $new_recipient_count = array(); foreach (array($absent_vid, $participant_vid) as $vid) { $res = XDB::query("SELECT COUNT(*) FROM virtual_redirect WHERE vid = {?}", $vid); $new_recipient_count[$vid] = $res->fetchOneCell(); } if ($new_recipient_count[$absent_vid] != $recipient_count[$absent_vid] || $new_recipient_count[$participant_vid] != $recipient_count[$participant_vid]) { printf(" Fixed aliases for event %d (%s): absent list %d -> %d, participant list %d -> %d\n", $eid, $shortname, $recipient_count[$absent_vid], $new_recipient_count[$absent_vid], $recipient_count[$participant_vid], $new_recipient_count[$participant_vid]); } }
public static function isPending($uid) { $res = XDB::iterRow('SELECT data FROM requests WHERE type = \'account\' ORDER BY stamp'); while (list($data) = $res->next()) { $request = Validate::unserialize($data); if ($request->uid == $uid) { return true; } } return false; }
/** * Select an FlagSet from the database into a field * * @param Collection $metas The objects to select * @param string $field An FlagSet field */ protected function helper_flagset(Collection $metas, $field) { $_metas = array(); foreach ($metas as $meta) { $_metas[$meta->id()] = new PlFlagSet(); } // Query database according to the schema $id = $this->schema->id(); list($table, $column) = $this->schema->flagsetType($field); $iter = XDB::iterRow("SELECT {$id}, {$column}\n FROM {$table}\n WHERE {$id} IN {?}", $metas->ids()); // Put database result in a id => array(l_col) fashion while (list($id, $value) = $iter->next()) { $_metas[$id]->addFlag($value); } // Fill metas foreach ($metas as $meta) { $meta->fillFromArray(array($field => $_metas[$meta->id()])); } }
* along with this program; if not, write to the Free Software * * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ /** * Check that for every profile, the best postal address which is used to * send mail is the right one according to a rule in Address::updateAxMail(). * * To fix something which has been reported by this script, you only need to * run "Address::updateBestMail($pid)" with $pid being the Profile ID */ require '../connect.db.inc.php'; require_once '../../classes/address.php'; $admin_visibility = Visibility::get(Visibility::VIEW_ADMIN); // Enumerate every profile $pids = XDB::iterRow("SELECT pid from profiles"); while ($row = $pids->next()) { $pid = $row[0]; // Find the address which would be selected as "AX mail" // But don't update anything $best_mail = Address::updateBestMail($pid, true); if (is_null($best_mail)) { continue; } // Just continue if the returned address is already selected $flags = new PlFlagSet($best_mail['flags']); if ($flags->hasFlag('dn_best_mail')) { continue; } // The current profile is buggy. // Let's fetch more data to print detailed information
/** Same as get_typed_request() but return an array of objects. */ public static function get_all_typed_requests($type) { $res = XDB::iterRow('SELECT data FROM requests WHERE type = {?} ORDER BY stamp', $type); $array = array(); while (list($data) = $res->next()) { $array[] = Validate::unserialize($data); } return $array; }
XDB::execute('INSERT INTO ips SET ip = {?}, rid = {?}, comment = {?}', $ip, $rid, $comment); echo "... Inserted.\n"; } } else { unset($ips2roomUnkown[$ip]); if ($ips2room[$ip]['r'] != $rid) { echo "IP " . $ip . " is associated with room " . $ips2room[$ip]['r'] . " (" . $ips2room[$ip]['c'] . ") instead of " . $rid . " (" . $comment . ")\n"; if ($execute_real) { XDB::execute('UPDATE ips SET rid = {?}, comment = {?} WHERE ip = {?}', $rid, $comment, $ip); echo "... Changed.\n"; } } } } // Get all rooms $iter = XDB::iterRow('SELECT rid FROM rooms'); $matches = array(); while (list($rid) = $iter->next()) { if (preg_match('/^X(09|10|11|12)([1-4]0)([0-9][0-9])$/', $rid, $matches)) { array_shift($matches); list($moon, $floor, $number) = $matches; $ip3 = $halfmoons[$moon] + (intval($floor[0]) - 1); $ip4 = intval($number); associate_room_ip($rid, '129.104.' . $ip3 . '.' . $ip4, 'principale'); associate_room_ip($rid, '129.104.' . $ip3 . '.' . (100 + $ip4), 'secondaire'); } elseif (preg_match('/^X17([12]0)([0-9][0-9])$/', $rid, $matches)) { array_shift($matches); list($floor, $number) = $matches; list($ip3, $ip4) = $pem[$floor]; $ip4 += intval($number); associate_room_ip($rid, '129.104.' . $ip3 . '.' . $ip4, 'principale');
function handler_deaths($page, $promo = 0, $validate = false) { $page->changeTpl('admin/deces_promo.tpl'); $page->setTitle('Administration - Deces'); if (!$promo) { $promo = Env::t('promo', 'X1923'); } $page->assign('promo', $promo); if (!$promo) { return; } if ($validate) { S::assert_xsrf_token(); $res = XDB::iterRow('SELECT p.pid, pd.directory_name, p.deathdate FROM profiles AS p INNER JOIN profile_display AS pd ON (p.pid = pd.pid) WHERE pd.promo = {?}', $promo); while (list($pid, $name, $death) = $res->next()) { $val = Env::v('death_' . $pid); if ($val == $death) { continue; } if (empty($val)) { $val = null; } XDB::execute('UPDATE profiles SET deathdate = {?}, deathdate_rec = NOW() WHERE pid = {?}', $val, $pid); $page->trigSuccess('Édition du décès de ' . $name . ' (' . ($val ? $val : 'ressuscité') . ').'); if ($val && ($death == '0000-00-00' || empty($death))) { $profile = Profile::get($pid); $profile->clear(); $profile->owner()->clear(false); } } } $res = XDB::iterator('SELECT p.pid, pd.directory_name, p.deathdate FROM profiles AS p INNER JOIN profile_display AS pd ON (p.pid = pd.pid) WHERE pd.promo = {?} ORDER BY pd.sort_name', $promo); $page->assign('profileList', $res); }
protected function fetchArticles($force = false) { if (count($this->arts) && !$force) { return; } // Load the articles $res = XDB::iterRow('SELECT a.title, a.body, a.append, a.aid, a.cid, a.pos FROM newsletter_art AS a INNER JOIN newsletter_issues AS ni USING(id) LEFT JOIN newsletter_cat AS c ON (a.cid = c.cid) WHERE a.id = {?} ORDER BY c.pos, a.pos', $this->id); while (list($title, $body, $append, $aid, $cid, $pos) = $res->next()) { $this->arts[$cid][$aid] = new NLArticle($title, $body, $append, $aid, $cid, $pos); } }
#!/usr/bin/php5 <?php require_once 'connect.db.inc.php'; // Fetches the list of unregistered users. $users = XDB::iterRow("SELECT user_id, prenom, nom, promo\n FROM auth_user_md5\n WHERE hruid IS NULL"); // Creates missing human readable uids. while (list($user_id, $prenom, $nom, $promo) = $users->next()) { $forlife = make_forlife($prenom, $nom, $promo); $hruid = XDB::query('SELECT * FROM auth_user_md5 WHERE hruid = {?} AND user_id != {?}', $forlife, $user_id); if ($hruid->numRows() > 0) { echo "WARNING: Duplicate forlife for user {$user_id} and forlife '{$forlife}'. Please check manually the entry.\n"; } else { XDB::execute('UPDATE auth_user_md5 SET hruid = {?} WHERE user_id = {?}', $forlife, $user_id); } }
* 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 * ***************************************************************************/ /** * 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;
$uf_kes = new UserFilter(new UFC_Group(Group::from('kes'), Rights::admin())); $c->userfilter($uf_kes); } } } // Update promotions $iter = XDB::iterRow('SELECT promo FROM studies GROUP BY promo ORDER BY promo'); while (list($promo) = $iter->next()) { $f = new UserFilter(new UFC_Promo($promo, '=')); $g = update_group('promo_' . $promo, $promo, Group::NS_PROMO, $f); create_promo_image($g, $promo); } // Update promotions by formation $iter = XDB::iterRow('SELECT s.promo, s.formation_id, f.abbrev, f.label FROM studies AS s LEFT JOIN formations AS f ON (f.formation_id = s.formation_id) WHERE s.formation_id > 0 GROUP BY s.promo, s.formation_id ORDER BY s.promo, s.formation_id ASC'); while (list($promo, $formation_id, $abbrev, $label) = $iter->next()) { $f = new UserFilter(new UFC_Promo($promo, '=', $formation_id)); $g = update_group('promo_' . $abbrev . $promo, $promo . ' ' . $label, Group::NS_PROMO, $f); create_promo_image($g, $promo); } // Update on_platal, specifying the number of years a school remains on the platal $onplatal_numyears = array('x' => 2, 'poly' => 0, 'master' => 0, 'doc' => 0, 'pei' => 0, 'iogs' => 0, 'fkz' => 0, 'stcyr' => 0, 'ensta' => 2); $formations->select(FormationSelect::on_platal()); $formations->select(FormationSelect::promos()); $filters = array(); foreach ($formations as $f) { if (!isset($onplatal_numyears[$f->abbrev()])) { echo 'Warning: no numyears for ' . $f->label() . "\n";
protected function handler_questions(Collection $surveys, array $fields) { $_surveys = array(); foreach ($surveys as $s) { $_surveys[$s->id()] = new Collection('SurveyQuestion'); $_surveys[$s->id()]->order('rank', false); } $iter = XDB::iterRow("SELECT qid, survey, type\n FROM surveys_questions\n WHERE survey IN {?}", $surveys->ids()); $questions = new Collection('SurveyQuestion'); while (list($qid, $sid, $type) = $iter->next()) { $className = 'SurveyQuestion' . $type; $question = new $className($qid); $questions->add($question); $_surveys[$sid]->add($question); } foreach ($surveys as $s) { $s->fillFromArray(array('questions' => $_surveys[$s->id()])); } if (!empty($questions) && !empty($this->subs['questions'])) { $questions->select($this->subs['questions']); } }