// 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"; continue; } $numyears = $onplatal_numyears[$f->abbrev()]; $promos = $f->promos(); $onplatal_promos = new PlFlagSet(); sort($promos); while ($numyears > 0) { $promo = array_pop($promos); if (is_null($promo)) { break; }
public static function birthday() { return new UserSelect(array('hruid', 'original', 'photo', 'gender', 'firstname', 'lastname', 'nickname', 'studies'), array('studies' => FormationSelect::base())); }
// Get webmaster caste $ufc_web = new UFC_Group(Group::from('webmasters'), Rights::member()); // Get kes admins $ufc_kes = new UFC_Group(Group::from('kes'), Rights::admin()); // Shalom-CCX-AMEP $shccxamep_groups = new Collection(); $shccxamep_groups->add(Group::from('shalom')); $shccxamep_groups->add(Group::from('ccx')); $shccxamep_groups->add(Group::from('amep')); $ufc_shalom_ccx_amep = new UFC_Group($shccxamep_groups, Rights::admin()); unset($shccxamep_groups); // licenses members = on_platal and X $ufc_licenses = new PFC_And(array(new UFC_Group(Group::from('formation_x'), Rights::restricted()), new UFC_Group(Group::from('on_platal'), Rights::restricted()))); // Get formations $formations = array(); foreach (Formation::selectAll(FormationSelect::base()) as $form) { $formations[$form->abbrev()] = intval($form->id()); } // Test wether the userfilter which is in the database is the expected one function test_userfilters($grouptext, $rights, $db_caste, $expected_condition = null) { $castetext = $rights . " userfilter (caste " . $db_caste->id() . ")"; $db_userfilter = $db_caste->userfilter(); if (is_null($expected_condition)) { if ($db_userfilter) { echo "Info: group " . $grouptext . " has unexpected " . $castetext . " " . json_encode($db_userfilter->export()) . "\n"; } } else { $expected_userfilter = new UserFilter($expected_condition); $expected_json = json_encode($expected_userfilter->export()); if (!$db_userfilter) {
function handler_mail($page) { $subject = Env::t('subject', ''); $body = Env::t('mail_body', ''); $no_wiki = Env::has('no_wiki'); // Retrieve the years on_platal of each formation $formations = Formation::selectAll(FormationSelect::on_platal()); if (Env::has('send')) { try { $required_fields = array('subject' => 'Il faut donner un sujet à ton mail', 'mail_body' => 'Tu ne veux pas envoyer de mail vide à tous. Si ?'); foreach ($required_fields as $field => $msg) { if (Env::v($field, '') == '') { throw new Exception($msg); } } if (Env::t('origin_mail_proposal') == 'false') { $origin = false; } else { $origin = new Group(Env::i('origin_mail_proposal')); } if ($origin !== false && !S::user()->hasRights($origin, Rights::admin())) { throw new Exception("Invalid credentials for origin Group"); } if (Env::t('type_mail_proposal') == 'group') { // Mail to a group list($temp, $target_group) = self::target_picker_to_caste_group('mail'); $target = new Collection('Caste'); $target->add($temp); $target_group->select(GroupSelect::validate()); $nv = new MailValidate(array('writer' => S::user(), 'type_mail' => Env::t('type_mail_proposal'), 'origin' => $origin, 'targets' => $target, 'subject' => $subject, 'body' => $body, 'nowiki' => $no_wiki, 'formation' => $target_group)); $el = new Validate(array('item' => $nv, 'group' => $target_group, 'writer' => S::user(), 'type' => 'mail')); $el->insert(); } elseif (Env::t('type_mail_proposal') == 'promo') { // Target group is a Collection of formation groups, which validate requests $target_group = new Collection('Group'); // Group promos by formation $promos = unflatten(Env::v('promos')); $promosByFormation = array(); foreach ($promos as $formation_promo) { $formation_promo = trim($formation_promo); if (!$formation_promo) { continue; } if (!preg_match('/^([0-9]+)_([0-9]+)$/', $formation_promo, $matches)) { throw new Exception("Oops, mauvais format de destinataire."); } $formid = (int) $matches[1]; $promo = (int) $matches[2]; if (isset($promosByFormation[$formid])) { $promosByFormation[$formid][] = $promo; } else { $promosByFormation[$formid] = array($promo); } } if (empty($promosByFormation)) { throw new Exception("Il faut indiquer au moins un destinataire."); } foreach ($promosByFormation as $formid => $promos) { // Now, $promos are the list of promos of formation $formid $form = $formations->get($formid); // Study group are the people the mail is sent to, array of CasteFilterCondition $cfc_study_groups = array(); foreach ($promos as $promo) { if (!$form->hasPlatalYear($promo)) { throw new Exception("Mauvaise promo " . $promo . " pour " . $form->label() . "."); } $cfc_study_groups[] = new CFC_Group($form->getGroupForPromo($promo), Rights::restricted()); } $target = new CasteFilter(new PFC_Or($cfc_study_groups)); $target = $target->get(); $target->select(CasteSelect::validate()); // $target_group is the group which validates this email $target_group = $form->getGroup(); $target_group->select(GroupSelect::validate()); $nv = new MailValidate(array('writer' => S::user(), 'type_mail' => Env::t('type_mail_proposal'), 'origin' => $origin, 'targets' => $target, 'subject' => $subject, 'body' => $body, 'nowiki' => $no_wiki, 'formation' => $target_group)); $el = new Validate(array('item' => $nv, 'group' => $target_group, 'writer' => S::user(), 'type' => 'mail')); $el->insert(); } } $page->assign('envoye', true); } catch (Exception $e) { $page->trigError($e->getMessage()); } } $page->assign('subject', $subject); $page->assign('body', $body); $page->assign('nowiki', $no_wiki); $page->assign('formations', $formations); $page->assign('title', 'Envoi des mails'); $page->addCssLink('validate.css'); $page->changeTpl('validate/prop.mail.tpl'); }