コード例 #1
0
ファイル: admin.php プロジェクト: Ekleog/platal
 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();
     }
 }
コード例 #2
0
ファイル: promo_update_help.php プロジェクト: Ekleog/platal
// 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();
コード例 #3
0
ファイル: profile.php プロジェクト: Ekleog/platal
 public static function rebuildSearchTokens($pids, $transaction = true)
 {
     require_once 'name.func.inc.php';
     if (!is_array($pids)) {
         $pids = array($pids);
     }
     $keys = XDB::iterator("(SELECT  pid, name, type, IF(type = 'nickname', 2, 1) AS score, '' AS public\n                                  FROM  profile_private_names\n                                 WHERE  pid IN {?})\n                                UNION\n                               (SELECT  pid, lastname_main, 'lastname' AS type, 10 AS score, 'public' AS public\n                                  FROM  profile_public_names\n                                 WHERE  lastname_main != '' AND pid IN {?})\n                                UNION\n                               (SELECT  pid, lastname_marital, 'lastname' AS type, 10 AS score, 'public' AS public\n                                  FROM  profile_public_names\n                                 WHERE  lastname_marital != '' AND pid IN {?})\n                                UNION\n                               (SELECT  pid, lastname_ordinary, 'lastname' AS type, 10 AS score, 'public' AS public\n                                  FROM  profile_public_names\n                                 WHERE  lastname_ordinary != '' AND pid IN {?})\n                                UNION\n                               (SELECT  pid, firstname_main, 'firstname' AS type, 10 AS score, 'public' AS public\n                                  FROM  profile_public_names\n                                 WHERE  firstname_main != '' AND pid IN {?})\n                                UNION\n                               (SELECT  pid, firstname_ordinary, 'firstname' AS type, 10 AS score, 'public' AS public\n                                  FROM  profile_public_names\n                                 WHERE  firstname_ordinary != '' AND pid IN {?})\n                                UNION\n                               (SELECT  pid, pseudonym, 'nickname' AS type, 10 AS score, 'public' AS public\n                                  FROM  profile_public_names\n                                 WHERE  pseudonym != '' AND pid IN {?})", $pids, $pids, $pids, $pids, $pids, $pids, $pids);
     $names = array();
     while ($key = $keys->next()) {
         if ($key['name'] == '') {
             continue;
         }
         $pid = $key['pid'];
         $toks = split_name_for_search($key['name']);
         $toks = array_reverse($toks);
         /* Split the score between the tokens to avoid the user to be over-rated.
          * Let says my user name is "Machin-Truc Bidule" and I also have a user named
          * 'Machin Truc'. Distributing the score force "Machin Truc" to be displayed
          * before "Machin-Truc" for both "Machin Truc" and "Machin" searches.
          */
         $eltScore = ceil((double) $key['score'] / (double) count($toks));
         $token = '';
         foreach ($toks as $tok) {
             $token = $tok . $token;
             $names["{$pid}-{$token}"] = XDB::format('({?}, {?}, {?}, {?}, {?}, {?})', $token, $pid, soundex_fr($token), $eltScore, $key['public'], $key['type']);
         }
     }
     if ($transaction) {
         XDB::startTransaction();
     }
     XDB::execute('DELETE FROM  search_name
                         WHERE  pid IN {?}', $pids);
     if (count($names) > 0) {
         XDB::rawExecute('INSERT INTO  search_name (token, pid, soundex, score, flags, general_type)
                               VALUES  ' . implode(', ', $names));
     }
     if ($transaction) {
         XDB::commit();
     }
 }
コード例 #4
0
ファイル: ufbuilder.inc.php プロジェクト: Ekleog/platal
 protected function check(UserFilterBuilder $ufb)
 {
     if (!parent::check($ufb)) {
         return false;
     }
     require_once 'name.func.inc.php';
     $this->val = split_name_for_search($this->val);
     if (count($this->val) == 0) {
         $this->empty = true;
     }
     $this->type = $ufb->v($this->envfieldtype);
     if (!in_array($this->type, array('', 'lastname', 'firstname', 'nickname'))) {
         return $this->raise("Le critère {$this->type} n'est pas valide pour le champ %s");
     }
     return true;
 }