Example #1
0
 private function getUF($admin = false, $extra_cond = null, $sort = null)
 {
     $cond = new PFC_And(new UFC_Group($this->id, $admin), new PFC_Not(new UFC_Dead()));
     if (!is_null($extra_cond)) {
         $cond->addChild($extra_cond);
     }
     if ($this->cat == self::CAT_PROMOTIONS) {
         $cond->addChild(new UFC_Registered());
     }
     return new UserFilter($cond, $sort);
 }
Example #2
0
 function handler_index($page, $action = '', $subaction = '')
 {
     global $globals;
     if (!$this->isDeltaTenEnabled(S::user(), Profile::DELTATEN_YOUNG)) {
         $page->killError("Ta promotion ne participe pas à l'opération N N-10.");
     }
     if ($this->isDeltaTenEnabled(S::user(), Profile::DELTATEN_OLD)) {
         $profile = S::user()->profile();
         if ($profile->getDeltatenMessage()) {
             $page->trigSuccess("Tu participes bien à l'opération N N-10 en tant qu'ancien.");
         } else {
             $page->trigWarning("Tu ne participes pas encore à l'opération N N-10 en tant qu'ancien.");
         }
     }
     $page->setTitle("Opération N N-10");
     $page->assign('deltaten_promo_old', S::user()->profile()->yearpromo() - 10);
     $wp = new PlWikiPage('Docs.Deltaten');
     $wp->buildCache();
     require_once 'ufbuilder.inc.php';
     $ufb = new UFB_DeltaTenSearch();
     $page->addJsLink('search.js');
     if (!$ufb->isEmpty()) {
         require_once 'userset.inc.php';
         $ufc = $ufb->getUFC();
         if (!$ufc instanceof PFC_And) {
             $ufc = new PFC_And($ufc);
         }
         $ufc->addChild(new UFC_DeltaTen());
         $ufc->addChild(new UFC_Promo('=', UserFilter::GRADE_ING, S::user()->profile()->yearpromo() - 10));
         $set = new ProfileSet($ufc);
         $set->addMod('minifiche', 'Opération N N-10');
         $set->apply('deltaten/search', $page, $action, $subaction);
         $nb_tot = $set->count();
         if ($nb_tot > $globals->search->private_max) {
             $page->assign('formulaire', 1);
             $page->trigError('Recherche trop générale.');
             $page->assign('plset_count', 0);
         } else {
             if ($nb_tot == 0) {
                 $page->assign('formulaire', 1);
                 $page->trigError("Il n'existe personne correspondant à ces critères dans la base.");
             }
         }
     }
     $page->changeTpl('deltaten/index.tpl');
 }
Example #3
0
 public function __construct(UserFilterBuilder $ufb, PlFilterCondition $cond = null)
 {
     if (is_null($cond)) {
         $conds = new PFC_And();
     } else {
         if ($cond instanceof PFC_And) {
             $conds = $cond;
         } else {
             $conds = new PFC_And($cond);
         }
     }
     if (!$ufb->isValid()) {
         $this->valid = false;
         return;
     }
     $ufc = $ufb->getUFC();
     $conds->addChild($ufc);
     $orders = $ufb->getOrders();
     parent::__construct($conds, $orders);
 }
Example #4
0
 function handler_batch($page)
 {
     $page->changeTpl('carnet/batch.tpl');
     $errors = false;
     $incomplete = array();
     if (Post::has('add')) {
         S::assert_xsrf_token();
         require_once 'userset.inc.php';
         require_once 'emails.inc.php';
         require_once 'marketing.inc.php';
         $list = explode("\n", Post::v('list'));
         $origin = Post::v('origin');
         foreach ($list as $item) {
             if ($item = trim($item)) {
                 $elements = preg_split("/\\s/", $item);
                 $email = array_pop($elements);
                 if (!isvalid_email($email)) {
                     $page->trigError('Email invalide : ' . $email);
                     $incomplete[] = $item;
                     $errors = true;
                     continue;
                 }
                 $user = User::getSilent($email);
                 if (is_null($user)) {
                     $details = implode(' ', $elements);
                     $promo = trim(array_pop($elements));
                     $cond = new PFC_And();
                     if (preg_match('/^[MDX]\\d{4}$/', $promo)) {
                         $cond->addChild(new UFC_Promo('=', UserFilter::DISPLAY, $promo));
                     } else {
                         $cond->addChild(new UFC_NameTokens($promo));
                     }
                     foreach ($elements as $element) {
                         $cond->addChild(new UFC_NameTokens($element));
                     }
                     $uf = new UserFilter($cond);
                     $count = $uf->getTotalCount();
                     if ($count == 0) {
                         $page->trigError('Les informations : « ' . $item . ' » ne correspondent à aucun camarade.');
                         $incomplete[] = $item;
                         $errors = true;
                         continue;
                     } elseif ($count > 1) {
                         $page->trigError('Les informations : « ' . $item . ' » sont ambigues et correspondent à plusieurs camarades.');
                         $incomplete[] = $item;
                         $errors = true;
                         continue;
                     } else {
                         $user = $uf->getUser();
                     }
                 }
                 if ($user->state == 'active') {
                     $this->addRegistered($page, $user->profile());
                 } else {
                     if (!User::isForeignEmailAddress($email)) {
                         $page->trigError('Email pas encore attribué : ' . $email);
                         $incomplete[] = $item;
                         $errors = true;
                     } else {
                         $this->addNonRegistered($page, $user);
                         if (!Marketing::get($user->id(), $email, true)) {
                             check_email($email, "Une adresse surveillée est proposée au marketing par " . S::user()->login());
                             $market = new Marketing($user->id(), $email, 'default', null, $origin, S::v('uid'), null);
                             $market->add();
                         }
                     }
                 }
             }
         }
     }
     $page->assign('errors', $errors);
     $page->assign('incomplete', $incomplete);
 }
Example #5
0
 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();
     }
 }
Example #6
0
 /** Get the count of subscribers to the NL.
  * @return Number of subscribers.
  */
 public function subscriberCount($lost = null, $sex = null, $grade = null, $first_promo = null, $last_promo = null)
 {
     $cond = new PFC_And(new UFC_NLSubscribed($this->id));
     if (!is_null($sex)) {
         $cond->addChild(new UFC_Sex($sex));
     }
     if (!is_null($grade)) {
         $cond->addChild(new UFC_Promo('>=', $grade, $first_promo));
         $cond->addChild(new UFC_Promo('<=', $grade, $last_promo));
     }
     if (!($lost === null)) {
         if ($lost === true) {
             $cond->addChild(new PFC_Not(new UFC_HasEmailRedirect()));
         } else {
             $cond->addChild(new UFC_HasEmailRedirect());
         }
     }
     $uf = new UserFilter($cond);
     return $uf->getTotalCount();
 }
Example #7
0
 /** Compute the conditions to use for the current request.
  * @return A PlFilterCondition instance (actually a PFC_And)
  */
 protected function getCond()
 {
     $cond = new PFC_And();
     foreach ($this->criteria as $criterion => $value) {
         switch ($criterion) {
             // ENUM fields
             case WSRequestCriteria::SCHOOL:
                 // Useless criterion: we don't need to check on origin school
                 if (WSRequestCriteria::$choices_enum[$criterion][$value]) {
                     $cond->addChild(new PFC_True());
                 } else {
                     $cond->addChild(new PFC_False());
                 }
                 break;
             case WSRequestCriteria::DIPLOMA:
                 $diploma = WSRequestCriteria::$choices_enum[$criterion][$value];
                 $id_X = XDB::fetchOneCell('SELECT  id
                                          FROM  profile_education_enum
                                         WHERE  abbreviation = {?}', 'X');
                 $cond->addChildren(array(new UFC_EducationSchool($id_X), new UFC_EducationDegree($diploma)));
                 break;
                 // TEXT fields
             // TEXT fields
             case WSRequestCriteria::FIRSTNAME:
             case WSRequestCriteria::LASTNAME:
                 $cond->addChild(new UFC_NameTokens($value, UFC_NameTokens::FLAG_PUBLIC, false, false, $criterion));
                 break;
             case WSRequestCriteria::PROMOTION:
                 $cond->addChild(new PFC_Or(new UFC_Promo(UserFilter::OP_EQUALS, UserFilter::GRADE_ING, $value), new UFC_Promo(UserFilter::OP_EQUALS, UserFilter::GRADE_MST, $value), new UFC_Promo(UserFilter::OP_EQUALS, UserFilter::GRADE_PHD, $value)));
                 break;
             case WSRequestCriteria::ALT_DIPLOMA:
                 $cond->addChild(new UFC_EducationDegree(DirEnum::getIds(DirEnum::EDUDEGREES, $value)));
                 break;
             case WSRequestCriteria::DIPLOMA_FIELD:
                 $cond->addChild(new UFC_EducationField(DirEnum::getIds(DirEnum::EDUFIELDS, $value)));
                 break;
             case WSRequestCriteria::CITY:
                 $cond->addChild(new UFC_AddressField($value, UFC_AddressField::FIELD_LOCALITY, UFC_Address::TYPE_HOME, UFC_Address::FLAG_CURRENT));
                 break;
             case WSRequestCriteria::COUNTRY:
                 $cond->addChild(new UFC_AddressField($value, UFC_AddressField::FIELD_COUNTRY, UFC_Address::TYPE_HOME, UFC_Address::FLAG_CURRENT));
                 break;
             case WSRequestCriteria::ZIPCODE:
                 $cond->addChild(new UFC_AddressField($value, UFC_AddressField::FIELD_ZIPCODE, UFC_Address::TYPE_HOME, UFC_Address::FLAG_CURRENT));
                 break;
             case WSRequestCriteria::JOB_ANY_COUNTRY:
                 $cond->addChild(new UFC_AddressField($value, UFC_AddressField::FIELD_COUNTRY, UFC_Address::TYPE_PRO, UFC_Address::FLAG_ANY));
                 break;
             case WSRequestCriteria::JOB_CURRENT_CITY:
                 $cond->addChild(new UFC_AddressField($value, UFC_AddressField::FIELD_LOCALITY, UFC_Address::TYPE_PRO, UFC_Address::FLAG_ANY));
                 break;
             case WSRequestCriteria::JOB_ANY_COMPANY:
             case WSRequestCriteria::JOB_CURRENT_COMPANY:
                 $cond->addChild(new UFC_Job_Company(UFC_Job_Company::JOBNAME, $value));
                 break;
             case WSRequestCriteria::JOB_ANY_SECTOR:
             case WSRequestCriteria::JOB_CURRENT_SECTOR:
             case WSRequestCriteria::JOB_CURRENT_TITLE:
                 $cond->addChild(new UFC_Job_Terms(DirEnum::getIds(DirEnum::JOBTERMS, $value)));
                 break;
                 // LIST fields
             // LIST fields
             case WSRequestCriteria::HOBBIES:
                 $subcond = new PFC_Or();
                 foreach ($value as $val) {
                     $subcond->addChild(new UFC_Comment($value));
                 }
                 $cond->addChild($subcond);
                 break;
             case WSRequestCriteria::JOB_COMPETENCIES:
             case WSRequestCriteria::JOB_RESUME:
             case WSRequestCriteria::PROFESSIONAL_PROJECT:
                 $subcond = new PFC_Or();
                 foreach ($value as $val) {
                     $subcond->addChild(new UFC_Job_Description($value, UserFilter::JOB_USERDEFINED));
                 }
                 $cond->addChild($subcond);
                 break;
             case WSRequestCriteria::NOT_UID:
                 $cond->addChild(new PFC_Not(new UFC_PartnerSharingID($this->partner->id, $value)));
                 break;
             default:
                 break;
         }
     }
     return $cond;
 }
Example #8
0
 function handler_admin_member_new_ajax($page)
 {
     pl_content_headers("text/html");
     $page->changeTpl('xnetgrp/membres-new-search.tpl', NO_SKIN);
     $users = array();
     $same_email = false;
     if (Env::has('login')) {
         $user = User::getSilent(Env::t('login'));
         if ($user && $user->state != 'pending') {
             $users = array($user->id() => $user);
             $same_email = true;
         }
     }
     if (empty($users)) {
         list($lastname, $firstname) = str_replace(array('-', ' ', "'"), '%', array(Env::t('nom'), Env::t('prenom')));
         $cond = new PFC_And();
         if (!empty($lastname)) {
             $cond->addChild(new UFC_NameTokens($lastname, array(), false, false, Profile::LASTNAME));
         }
         if (!empty($firstname)) {
             $cond->addChild(new UFC_NameTokens($firstname, array(), false, false, Profile::FIRSTNAME));
         }
         if (Env::t('promo')) {
             $cond->addChild(new UFC_Promo('=', UserFilter::DISPLAY, Env::t('promo')));
         }
         $uf = new UserFilter($cond);
         $users = $uf->getUsers(new PlLimit(30));
         if ($uf->getTotalCount() > 30) {
             $page->assign('too_many', true);
             $users = array();
         }
     }
     $page->assign('users', $users);
     $page->assign('same_email', $same_email);
 }
Example #9
0
// Do not store backtraces
$opts = getopt('f:p:');
if (empty($opts['f']) || empty($opts['p'])) {
    print "File name missing (-f=file_name) or promotion missing (-p=file_name).\n";
    exit;
}
$file = $opts['f'];
$handle = fopen($file, 'r');
$promo_year = $opts['p'];
$already = array();
$new = array();
$ambiguous = array();
while ($line = trim(fgets($handle))) {
    $data = explode(';', $line);
    $cond = new PFC_And(new UFC_NameTokens(split_name_for_search($data[0]), array(), false, false, Profile::LASTNAME));
    $cond->addChild(new UFC_NameTokens(split_name_for_search($data[1]), array(), false, false, Profile::FIRSTNAME));
    $uf = new UserFilter($cond);
    $profiles = $uf->getProfiles();
    switch (count($profiles)) {
        case 0:
            $new[] = $line;
            break;
        case 1:
            foreach ($profiles as $profile) {
                $already[] = $profile->hrid();
            }
            break;
        default:
            $hrids = array();
            foreach ($profiles as $profile) {
                $hrids[] = $profile->hrid();
Example #10
0
 protected function buildUFC(UserFilterBuilder $ufb)
 {
     $r = $s = $this->val;
     /** Admin: Email, IP
      */
     if (S::admin() && strpos($s, '@') !== false) {
         return new UFC_Email($s);
     } else {
         if (S::admin() && preg_match('/[0-9]+\\.([0-9]+|%)\\.([0-9]+|%)\\.([0-9]+|%)/', $s)) {
             return new UFC_Ip($s);
         }
     }
     $conds = new PFC_And();
     /** Name
      */
     $s = preg_replace('!\\d+!', ' ', $s);
     $strings = preg_split("![^a-z%]+!i", $s, -1, PREG_SPLIT_NO_EMPTY);
     foreach ($strings as $key => $string) {
         if (strlen($string) < 2) {
             unset($strings[$key]);
         }
     }
     if (count($strings) > 5) {
         Platal::page()->trigWarning("Tu as indiqué trop d'éléments dans ta recherche, seuls les 5 premiers seront pris en compte");
         $strings = array_slice($strings, 0, 5);
     }
     if (count($strings)) {
         if (S::user() != null && S::user()->checkPerms('directory_private')) {
             $flags = array();
         } else {
             $flags = array('public');
         }
         $exact = $ufb->b('exact');
         $conds->addChild(new UFC_NameTokens($strings, $flags, $ufb->b('with_soundex'), $exact));
         $ufb->addOrder(new UFO_Score());
     }
     /** Promo ranges
      */
     $s = preg_replace('! *- *!', '-', $r);
     $s = preg_replace('!([<>]) *!', ' \\1', $s);
     $s = preg_replace('![^0-9xmd\\-><]!i', ' ', $s);
     $s = preg_replace('![<>\\-] !', '', $s);
     $ranges = preg_split('! +!', strtolower($s), -1, PREG_SPLIT_NO_EMPTY);
     $grades = array('' => UserFilter::GRADE_ING, 'x' => UserFilter::GRADE_ING, 'm' => UserFilter::GRADE_MST, 'd' => UserFilter::GRADE_PHD);
     foreach ($ranges as $r) {
         if (preg_match('!^([xmd]?)(\\d{4})$!', $r, $matches)) {
             $conds->addChild(new UFC_Promo('=', $grades[$matches[1]], $matches[2]));
         } elseif (preg_match('!^([xmd]?)(\\d{4})-\\1(\\d{4})$!', $r, $matches)) {
             $p1 = min(intval($matches[2]), intval($matches[3]));
             $p2 = max(intval($matches[2]), intval($matches[3]));
             $conds->addChild(new PFC_And(new UFC_Promo('>=', $grades[$matches[1]], $p1), new UFC_Promo('<=', $grades[$matches[1]], $p2)));
         } elseif (preg_match('!^<([xmd]?)(\\d{4})!', $r, $matches)) {
             $conds->addChild(new UFC_Promo('<=', $grades[$matches[1]], $matches[2]));
         } elseif (preg_match('!^>([xmd]?)(\\d{4})!', $r, $matches)) {
             $conds->addChild(new UFC_Promo('>=', $grades[$matches[1]], $matches[2]));
         }
     }
     /** Phone number
      */
     $t = preg_replace('!([xmd]?\\d{4}-|>|<|)[xmd]?\\d{4}!i', '', $s);
     $t = preg_replace('![<>\\- ]!', '', $t);
     if (strlen($t) > 4) {
         $conds->addChild(new UFC_Phone($t));
     }
     return $conds;
 }