Beispiel #1
0
 function handler_picture_token(PlPage $page, $size, $token)
 {
     XDB::rawExecute('DELETE FROM  profile_photo_tokens
                            WHERE  expires <= NOW()');
     $pid = XDB::fetchOneCell('SELECT  pid
                                 FROM  profile_photo_tokens
                                WHERE  token = {?}', $token);
     if ($pid != null) {
         $res = XDB::fetchOneAssoc('SELECT  attach, attachmime, x, y, last_update
                                      FROM  profile_photos
                                     WHERE  pid = {?}', $pid);
         $photo = PlImage::fromData($res['attach'], 'image/' . $res['attachmime'], $res['x'], $res['y'], $res['last_update']);
         $photo->send();
     } else {
         return PL_NOT_FOUND;
     }
 }
Beispiel #2
0
 public function commit()
 {
     $values = array();
     $i = 0;
     foreach ($this->users as $user) {
         $values[] = XDB::format('({?}, {?}, {?}, NOW(), {?}, {?}, {?})', $user['uid'], $user['hruid'], $user['email'], rand_url_id(12), $this->user->fullName(), $this->group);
         if ($i == $this->limit) {
             XDB::rawExecute('INSERT INTO  register_pending_xnet (uid, hruid, email, date, hash, sender_name, group_name)
                                   VALUES  ' . implode(', ', $values));
             $i = 0;
             $values = array();
         } else {
             ++$i;
         }
     }
     XDB::rawExecute('INSERT INTO  register_pending_xnet (uid, hruid, email, date, hash, sender_name, group_name)
                           VALUES  ' . implode(', ', $values));
     return true;
 }
Beispiel #3
0
    preg_match($pattern, $data['private_name'], $matches);
    $has_ordinary = false;
    $count = count($matches);
    $update = array();
    $has_ordinary = update_main($data, $matches[1], $update);
    for ($i = 2; $i < $count; ++$i) {
        if (preg_match('/^\\((?:M|Mme) (.+)\\)$/', $matches[$i], $pieces)) {
            update_marital($data, $pieces[1], $update);
        } elseif (preg_match('/^\\((?:alias|autres prénoms :|autres noms :) .+\\)$/', $matches[$i], $pieces)) {
            update_private($data, $matches[$i], $data['pid'], $aliases, $perform_updates);
        } else {
            $has_ordinary = update_plain($data, $matches[$i], $update, $has_ordinary);
        }
    }
    if (count($update)) {
        $set = implode(', ', $update);
        if ($perform_updates) {
            XDB::rawExecute('UPDATE  profile_public_names
                                SET  ' . $set . '
                              WHERE  pid = ' . $data['pid']);
        } else {
            print $set . ' (for pid ' . $data['pid'] . ")\n";
        }
    }
}
if ($perform_updates) {
    print "\nUpdates done.\n";
} else {
    print "\nIf this seems correct, relaunch this script with option --perform-updates=YES.\n";
}
/* vim:set et sw=4 sts=4 ts=4: */
Beispiel #4
0
 function handler_user($page, $login = false)
 {
     global $globals;
     $page->changeTpl('admin/user.tpl');
     $page->setTitle('Administration - Compte');
     if (S::suid()) {
         $page->kill("Déjà en SUID&nbsp;!!!");
     }
     // Loads the user identity using the environment.
     if ($login) {
         $user = User::get($login);
     }
     if (empty($user)) {
         pl_redirect('admin/accounts');
     }
     $listClient = new MMList(S::user());
     $login = $user->login();
     $registered = $user->state != 'pending';
     // Form processing
     if (!empty($_POST)) {
         S::assert_xsrf_token();
         if (Post::has('uid') && Post::i('uid') != $user->id()) {
             $page->kill('Une erreur s\'est produite');
         }
     }
     // Handles specific requests (AX sync, su, ...).
     if (Post::has('log_account')) {
         pl_redirect("admin/logger?loguser={$login}&year=" . date('Y') . "&month=" . date('m'));
     }
     if (Post::has('su_account') && $registered) {
         if (!Platal::session()->startSUID($user)) {
             $page->trigError('Impossible d\'effectuer un SUID sur ' . $user->login());
         } else {
             pl_redirect("");
         }
     }
     // Handles account deletion.
     if (Post::has('account_deletion_confirmation')) {
         $uid = $user->id();
         $name = $user->fullName();
         $profile = $user->profile();
         if ($profile && Post::b('clear_profile')) {
             $user->profile()->clear();
         }
         $user->clear(true);
         $page->trigSuccess("L'utilisateur {$name} ({$uid}) a bien été désinscrit.");
         if (Post::b('erase_account')) {
             XDB::execute('DELETE FROM  accounts
                                 WHERE  uid = {?}', $uid);
             $page->trigSuccess("L'utilisateur {$name} ({$uid}) a été supprimé de la base de données");
         }
     }
     // Account Form {{{
     require_once 'emails.inc.php';
     $to_update = array();
     if (Post::has('disable_weak_access')) {
         $to_update['weak_password'] = null;
     } else {
         if (Post::has('update_account')) {
             if (!$user->hasProfile()) {
                 require_once 'name.func.inc.php';
                 $name_update = false;
                 $lastname = capitalize_name(Post::t('lastname'));
                 $firstname = capitalize_name(Post::t('firstname'));
                 if ($lastname != $user->lastname) {
                     $to_update['lastname'] = $lastname;
                     $name_update = true;
                 }
                 if (Post::s('type') != 'virtual' && $firstname != $user->firstname) {
                     $to_update['firstname'] = $firstname;
                     $name_update = true;
                 }
                 if ($name_update) {
                     if (Post::s('type') == 'virtual') {
                         $firstname = '';
                     }
                     $to_update['full_name'] = build_full_name($firstname, $lastname);
                     $to_update['directory_name'] = build_directory_name($firstname, $lastname);
                     $to_update['sort_name'] = build_sort_name($firstname, $lastname);
                 }
                 if (Post::s('display_name') != $user->displayName()) {
                     $to_update['display_name'] = Post::s('display_name');
                 }
             }
             if (Post::s('sex') != ($user->isFemale() ? 'female' : 'male')) {
                 $to_update['sex'] = Post::s('sex');
                 if ($user->hasProfile()) {
                     XDB::execute('UPDATE  profiles
                                  SET  sex = {?}
                                WHERE  pid = {?}', Post::s('sex'), $user->profile()->id());
                 }
             }
             if (!Post::blank('pwhash')) {
                 $to_update['password'] = Post::s('pwhash');
                 require_once 'googleapps.inc.php';
                 $account = new GoogleAppsAccount($user);
                 if ($account->active() && $account->sync_password) {
                     $account->set_password(Post::s('pwhash'));
                 }
             }
             if (!Post::blank('weak_password')) {
                 $to_update['weak_password'] = Post::s('weak_password');
             }
             if (Post::i('token_access', 0) != ($user->token_access ? 1 : 0)) {
                 $to_update['token'] = Post::i('token_access') ? rand_url_id(16) : null;
             }
             if (Post::i('skin') != $user->skin) {
                 $to_update['skin'] = Post::i('skin');
                 if ($to_update['skin'] == 0) {
                     $to_update['skin'] = null;
                 }
             }
             if (Post::s('state') != $user->state) {
                 $to_update['state'] = Post::s('state');
             }
             if (Post::i('is_admin', 0) != ($user->is_admin ? 1 : 0)) {
                 $to_update['is_admin'] = Post::b('is_admin');
             }
             if (Post::s('type') != $user->type) {
                 $to_update['type'] = Post::s('type');
             }
             if (Post::i('watch', 0) != ($user->watch ? 1 : 0)) {
                 $to_update['flags'] = new PlFlagset();
                 $to_update['flags']->addFlag('watch', Post::i('watch'));
             }
             if (Post::t('comment') != $user->comment) {
                 $to_update['comment'] = Post::blank('comment') ? null : Post::t('comment');
             }
             $new_email = strtolower(Post::t('email'));
             if (require_email_update($user, $new_email)) {
                 $to_update['email'] = $new_email;
                 $listClient->change_user_email($user->forlifeEmail(), $new_email);
                 update_alias_user($user->forlifeEmail(), $new_email);
             }
         }
     }
     if (!empty($to_update)) {
         $res = XDB::query('SELECT  *
                              FROM  accounts
                             WHERE  uid = {?}', $user->id());
         $oldValues = $res->fetchAllAssoc();
         $oldValues = $oldValues[0];
         $set = array();
         $diff = array();
         foreach ($to_update as $k => $value) {
             $value = XDB::format('{?}', $value);
             $set[] = $k . ' = ' . $value;
             $diff[$k] = array($oldValues[$k], trim($value, "'"));
             unset($oldValues[$k]);
         }
         XDB::rawExecute('UPDATE  accounts
                             SET  ' . implode(', ', $set) . '
                           WHERE  uid = ' . XDB::format('{?}', $user->id()));
         $page->trigSuccess('Données du compte mise à jour avec succès');
         $user = User::getWithUID($user->id());
         /* Formats the $diff and send it to the site administrators. The rules are the folowing:
          *  -formats: password, token, weak_password
          */
         foreach (array('password', 'token', 'weak_password') as $key) {
             if (isset($diff[$key])) {
                 $diff[$key] = array('old value', 'new value');
             } else {
                 $oldValues[$key] = 'old value';
             }
         }
         $mail = new PlMailer('admin/useredit.mail.tpl');
         $mail->assign('admin', S::user()->hruid);
         $mail->assign('hruid', $user->hruid);
         $mail->assign('diff', $diff);
         $mail->assign('oldValues', $oldValues);
         $mail->send();
     }
     // }}}
     // Profile form {{{
     if (Post::has('add_profile') || Post::has('del_profile') || Post::has('owner')) {
         if (Post::i('del_profile', 0) != 0) {
             XDB::execute('DELETE FROM  account_profiles
                                 WHERE  uid = {?} AND pid = {?}', $user->id(), Post::i('del_profile'));
             XDB::execute('DELETE FROM  profiles
                                 WHERE  pid = {?}', Post::i('del_profile'));
         } else {
             if (!Post::blank('new_profile')) {
                 $profile = Profile::get(Post::t('new_profile'));
                 if (!$profile) {
                     $page->trigError('Le profil ' . Post::t('new_profile') . ' n\'existe pas');
                 } else {
                     XDB::execute('INSERT IGNORE INTO  account_profiles (uid, pid)
                                           VALUES  ({?}, {?})', $user->id(), $profile->id());
                 }
             }
         }
         XDB::execute('UPDATE  account_profiles
                          SET  perms = IF(pid = {?}, CONCAT(perms, \',owner\'), REPLACE(perms, \'owner\', \'\'))
                        WHERE  uid = {?}', Post::i('owner'), $user->id());
     }
     // }}}
     // Email forwards form {{{
     $redirect = $registered ? new Redirect($user) : null;
     if (Post::has('add_fwd')) {
         $email = Post::t('email');
         if (!isvalid_email_redirection($email, $user)) {
             $page->trigError("Email non valide: {$email}");
         } else {
             $redirect->add_email($email);
             $page->trigSuccess("Ajout de {$email} effectué");
         }
     } else {
         if (!Post::blank('del_fwd')) {
             $redirect->delete_email(Post::t('del_fwd'));
         } else {
             if (!Post::blank('activate_fwd')) {
                 $redirect->modify_one_email(Post::t('activate_fwd'), true);
             } else {
                 if (!Post::blank('deactivate_fwd')) {
                     $redirect->modify_one_email(Post::t('deactivate_fwd'), false);
                 } else {
                     if (Post::has('disable_fwd')) {
                         $redirect->disable();
                     } else {
                         if (Post::has('enable_fwd')) {
                             $redirect->enable();
                         } else {
                             if (!Post::blank('clean_fwd')) {
                                 $redirect->clean_errors(Post::t('clean_fwd'));
                             }
                         }
                     }
                 }
             }
         }
     }
     // }}}
     // Email alias form {{{
     if (Post::has('add_alias')) {
         // Splits new alias in user and fqdn.
         $alias = Env::t('email');
         if (strpos($alias, '@') !== false) {
             list($alias, $domain) = explode('@', $alias);
         } else {
             $domain = $user->mainEmailDomain();
         }
         // Checks for alias' user validity.
         if (!preg_match('/[-a-z0-9\\.]+/s', $alias)) {
             $page->trigError("'{$alias}' n'est pas un alias valide");
         }
         // Eventually adds the alias to the right domain.
         if ($domain == $globals->mail->alias_dom || $domain == $globals->mail->alias_dom2) {
             $req = new AliasReq($user, $alias, 'Admin request', false);
             if ($req->commit()) {
                 $page->trigSuccess("Nouvel alias '{$alias}@{$domain}' attribué.");
             } else {
                 $page->trigError("Impossible d'ajouter l'alias '{$alias}@{$domain}', il est probablement déjà attribué.");
             }
         } elseif ($domain == $user->mainEmailDomain()) {
             XDB::execute('INSERT INTO  email_source_account (email, uid, domain, type, flags)
                                SELECT  {?}, {?}, id, \'alias\', \'\'
                                  FROM  email_virtual_domains
                                 WHERE  name = {?}', $alias, $user->id(), $domain);
             $page->trigSuccess("Nouvel alias '{$alias}' ajouté");
         } else {
             $page->trigError("Le domaine '{$domain}' n'est pas valide pour cet utilisateur.");
         }
     } else {
         if (!Post::blank('del_alias')) {
             $delete_alias = Post::t('del_alias');
             list($email, $domain) = explode('@', $delete_alias);
             XDB::execute('DELETE  s
                         FROM  email_source_account  AS s
                   INNER JOIN  email_virtual_domains AS m ON (s.domain = m.id)
                   INNER JOIN  email_virtual_domains AS d ON (d.aliasing = m.id)
                        WHERE  s.email = {?} AND s.uid = {?} AND d.name = {?} AND type != \'forlife\'', $email, $user->id(), $domain);
             XDB::execute('UPDATE  email_redirect_account AS r
                   INNER JOIN  email_virtual_domains  AS m ON (m.name = {?})
                   INNER JOIN  email_virtual_domains  AS d ON (d.aliasing = m.id)
                          SET  r.rewrite = \'\'
                        WHERE  r.uid = {?} AND r.rewrite = CONCAT({?}, \'@\', d.name)', $domain, $user->id(), $email);
             fix_bestalias($user);
             $page->trigSuccess("L'alias '{$delete_alias}' a été supprimé");
         } else {
             if (!Post::blank('best')) {
                 $best_alias = Post::t('best');
                 // First delete the bestalias flag from all this user's emails.
                 XDB::execute("UPDATE  email_source_account\n                             SET  flags = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', flags, ','), ',bestalias,', ','))\n                           WHERE  uid = {?}", $user->id());
                 // Then gives the bestalias flag to the given email.
                 list($email, $domain) = explode('@', $best_alias);
                 XDB::execute("UPDATE  email_source_account\n                             SET  flags = CONCAT_WS(',', IF(flags = '', NULL, flags), 'bestalias')\n                           WHERE  uid = {?} AND email = {?}", $user->id(), $email);
                 // As having a non-null bestalias value is critical in
                 // plat/al's code, we do an a posteriori check on the
                 // validity of the bestalias.
                 fix_bestalias($user);
             }
         }
     }
     // }}}
     // OpenId form {{{
     if (Post::has('del_openid')) {
         XDB::execute('DELETE FROM  account_auth_openid
                             WHERE  id = {?}', Post::i('del_openid'));
     }
     // }}}
     // Forum form {{{
     if (Post::has('b_edit')) {
         XDB::execute("DELETE FROM  forum_innd\n                                WHERE  uid = {?}", $user->id());
         if (Env::v('write_perm') != "" || Env::v('read_perm') != "" || Env::v('commentaire') != "") {
             XDB::execute("INSERT INTO  forum_innd\n                                      SET  ipmin = '0', ipmax = '4294967295',\n                                           write_perm = {?}, read_perm = {?},\n                                           comment = {?}, priority = '200', uid = {?}", Env::v('write_perm'), Env::v('read_perm'), Env::v('comment'), $user->id());
         }
     }
     // }}}
     $page->addJsLink('jquery.ui.xorg.js');
     // Displays last login and last host information.
     $res = XDB::query("SELECT  start, host\n                             FROM  log_sessions\n                            WHERE  uid = {?} AND suid IS NULL\n                         ORDER BY  start DESC\n                            LIMIT  1", $user->id());
     list($lastlogin, $host) = $res->fetchOneRow();
     $page->assign('lastlogin', $lastlogin);
     $page->assign('host', $host);
     // Display mailing lists
     $page->assign('mlists', $listClient->get_all_user_lists($user->forlifeEmail()));
     // Display active aliases.
     $page->assign('virtuals', $user->emailGroupAliases());
     $aliases = XDB::iterator("SELECT  CONCAT(s.email, '@', d.name) AS email, (s.type = 'forlife') AS forlife,\n                                          (s.email REGEXP '\\\\.[0-9]{2}\$') AS hundred_year,\n                                          FIND_IN_SET('bestalias', s.flags) AS bestalias, s.expire,\n                                          (s.type = 'alias_aux') AS alias\n                                    FROM  email_source_account  AS s\n                              INNER JOIN  email_virtual_domains AS d ON (s.domain = d.id)\n                                   WHERE  s.uid = {?}\n                                ORDER BY  !alias, s.email", $user->id());
     $page->assign('aliases', $aliases);
     $page->assign('account_types', XDB::iterator('SELECT * FROM account_types ORDER BY type'));
     $page->assign('skins', XDB::iterator('SELECT id, name FROM skins ORDER BY name'));
     $page->assign('profiles', XDB::iterator('SELECT  p.pid, p.hrpid, FIND_IN_SET(\'owner\', ap.perms) AS owner, p.ax_id
                                                FROM  account_profiles AS ap
                                          INNER JOIN  profiles AS p ON (ap.pid = p.pid)
                                               WHERE  ap.uid = {?}', $user->id()));
     $page->assign('openid', XDB::iterator('SELECT  id, url
                                              FROM  account_auth_openid
                                             WHERE  uid = {?}', $user->id()));
     // Displays email redirection and the general profile.
     if ($registered && $redirect) {
         $page->assign('emails', $redirect->emails);
     }
     $page->assign('user', $user);
     $page->assign('hasProfile', $user->hasProfile());
     // Displays forum bans.
     $res = XDB::query("SELECT  write_perm, read_perm, comment\n                             FROM  forum_innd\n                            WHERE  uid = {?}", $user->id());
     $bans = $res->fetchOneAssoc();
     $page->assign('bans', $bans);
 }
Beispiel #5
0
 public function save(ProfilePage $page, $field, $value)
 {
     $deletePrivate = S::user()->isMe($page->owner) || S::admin();
     XDB::execute('DELETE FROM  pj, pjt
                         USING  profile_job      AS pj
                     LEFT JOIN  profile_job_term AS pjt ON (pj.pid = pjt.pid AND pj.id = pjt.jid)
                         WHERE  pj.pid = {?}' . ($deletePrivate ? '' : ' AND pj.pub IN (\'public\', \'ax\')'), $page->pid());
     Address::deleteAddresses($page->pid(), Address::LINK_JOB, null, null, $deletePrivate);
     Phone::deletePhones($page->pid(), Phone::LINK_JOB, null, $deletePrivate);
     $previous_requests = EntrReq::get_typed_requests($page->pid(), 'entreprise');
     foreach ($previous_requests as $request) {
         $request->clean();
     }
     $terms_values = array();
     foreach ($value as $id => &$job) {
         if (($job['pub'] != 'private' || $deletePrivate) && (isset($job['name']) && $job['name'])) {
             if (isset($job['jobid']) && $job['jobid']) {
                 XDB::execute('INSERT INTO  profile_job (pid, id, description, email, entry_year,
                                                         url, pub, email_pub, jobid)
                                    VALUES  ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', $page->pid(), $id, $job['description'], $job['w_email'], $job['w_entry_year'], $job['w_url'], $job['pub'], $job['w_email_pub'], $job['jobid']);
             } else {
                 XDB::execute('INSERT INTO  profile_job (pid, id, description, email, entry_year,
                                                         url, pub, email_pub)
                                    VALUES  ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', $page->pid(), $id, $job['description'], $job['w_email'], $job['w_entry_year'], $job['w_url'], $job['pub'], $job['w_email_pub']);
                 $request = new EntrReq(S::user(), $page->profile, $id, $job['name'], $job['hq_acronym'], $job['hq_url'], $job['hq_email'], $job['hq_fixed'], $job['hq_fax'], $job['hq_address']);
                 $request->submit();
                 sleep(1);
             }
             $address = new Address(array_merge($job['w_address'], array('pid' => $page->pid(), 'id' => $id, 'type' => Address::LINK_JOB)));
             $address->save();
             Phone::savePhones($job['w_phone'], $page->pid(), Phone::LINK_JOB, $id);
             if (isset($job['terms'])) {
                 foreach ($job['terms'] as $term) {
                     $terms_values[] = XDB::format('({?}, {?}, {?}, {?})', $page->pid(), $id, $term['jtid'], "original");
                 }
             }
         }
     }
     if (count($terms_values) > 0) {
         XDB::rawExecute('INSERT INTO  profile_job_term (pid, jid, jtid, computed)
                               VALUES  ' . implode(', ', $terms_values) . '
              ON DUPLICATE KEY UPDATE  computed = VALUES(computed)');
     }
     if (S::user()->isMe($page->owner) && count($value) > 1) {
         Platal::page()->trigWarning('Attention, tu as plusieurs emplois sur ton profil. Pense à supprimer ceux qui sont obsolètes.');
     }
 }
Beispiel #6
0
 public function save(ProfilePage $page, $field, $value)
 {
     require_once 'name.func.inc.php';
     $old = XDB::fetchOneAssoc('SELECT  lastname_main, lastname_marital, lastname_ordinary,
                                        firstname_main, firstname_ordinary, pseudonym
                                  FROM  profile_public_names
                                 WHERE  pid = {?}', $page->pid());
     if ($has_diff = $this->diff($page->pid(), $old, $value['public_names'])) {
         $new_names = new NamesReq(S::user(), $page->profile, $value['public_names'], $old);
         $new_names->submit();
         Platal::page()->assign('validation', true);
         Platal::page()->trigWarning('La demande de modification des noms a bien été prise en compte.' . ' Un email sera envoyé dès que ces changements auront été effectués.');
     }
     XDB::execute('DELETE FROM  profile_private_names
                         WHERE  pid = {?}', $page->pid());
     $values = array();
     $nickname = $lastname = $firstname = 0;
     if (isset($value['private_names'])) {
         foreach ($value['private_names'] as $name) {
             $values[] = XDB::format('({?}, {?}, {?}, {?})', $page->pid(), $name['type'], ${$name}['type']++, $name['name']);
         }
     }
     if (count($values)) {
         XDB::rawExecute('INSERT INTO  profile_private_names (pid, type, id, name)
                               VALUES  ' . implode(',', $values));
     }
     if ($has_diff) {
         update_display_names($page->profile, $old, $value['private_names']);
     } else {
         update_display_names($page->profile, $value['public_names'], isset($value['private_names']) ? $value['private_names'] : null);
     }
 }
Beispiel #7
0
 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();
     }
 }
Beispiel #8
0
// Do not store backtraces.
$it = XDB::iterator('SELECT  gl.language, gc.country, gc.iso_3166_1_a2
                       FROM  geoloc_languages AS gl
                 INNER JOIN  geoloc_countries AS gc ON (gl.iso_3166_1_a2 = gc.iso_3166_1_a2)');
echo $it->total() . " pays à remplir.\n";
while ($item = $it->next()) {
    if ($item['language'] != 'fr') {
        $address = new Address(array('text' => $item['country']));
        $gmapsGeocoder = new GMapsGeocoder();
        $gmapsGeocoder->getGeocodedAddress($address, $item['language'], true);
        $country = $address->country;
    } else {
        $country = $item['country'];
    }
    $countryPlain = mb_strtoupper(replace_accent($country));
    XDB::execute('UPDATE  geoloc_languages
                     SET  country = {?}, countryPlain = {?}
                   WHERE  iso_3166_1_a2 = {?} AND language = {?}', $country, $countryPlain, $item['iso_3166_1_a2'], $item['language']);
    sleep(1);
}
$it = XDB::rawIterator('SELECT  country, iso_3166_1_a2
                          FROM  geoloc_countries');
echo $it->total() . " pays à simplifier.\n";
while ($item = $it->next()) {
    XDB::execute('UPDATE  geoloc_countries
                     SET  countryPlain = {?}
                   WHERE  iso_3166_1_a2 = {?}', mb_strtoupper(replace_accent($item['country'])), $item['iso_3166_1_a2']);
}
// Fixes geocoding errors.
XDB::rawExecute("REPLACE INTO  geoloc_languages (iso_3166_1_a2, language, country, countryPlain)\n                       VALUES  ('FM', 'en', 'Federated States of Micronesia', 'FEDERATED STATES OF MICRONESIA'),\n                               ('MH', 'en', 'Republic of the Marshall Islands', 'REPUBLIC OF THE MARSHALL ISLANDS'),\n                               ('PS', 'ar', 'دولة فلسطين', 'دولة فلسطين'),\n                               ('SB', 'en', 'Solomon Islands', 'SOLOMON ISLANDS'),\n                               ('TW', 'zh-CN', '台湾', '台湾'),\n                               ('TW', 'zh-TW', '台灣', '台灣'),\n                               ('CZ', 'cs', 'Česká Republika', 'CESKA REPUBLIKA'),\n                               ('CZ', 'sk', 'Česká Republika', 'CESKA REPUBLIKA'),\n                               ('DO', 'es', 'República Dominicana', 'REPUBLICA DOMINICANA'),\n                               ('GD', 'en', 'Grenada', 'GRENADA'),\n                               ('MD', 'ro', 'Republica Moldova', 'REPUBLICA MOLDOVA'),\n                               ('RU', 'ru', 'Россия', 'Россия'),\n                               ('SK', 'sk', 'Slovenská Republika', 'SLOVENSKA REPUBLIKA'),\n                               ('TZ', 'en', 'United Republic of Tanzania', 'UNITED REPUBLIC OF TANZANIA')");
/* vim:set et sw=4 sts=4 ts=4: */
Beispiel #9
0
 function handler_admin_member_new($page, $email = null)
 {
     global $globals;
     $page->changeTpl('xnetgrp/membres-add.tpl');
     $page->addJsLink('xnet_members.js');
     if (is_null($email)) {
         return;
     }
     S::assert_xsrf_token();
     $suggest_account_activation = false;
     // FS#703 : $_GET is urldecoded twice, hence
     // + (the data) => %2B (in the url) => + (first decoding) => ' ' (second decoding)
     // Since there can be no spaces in emails, we can fix this with :
     $email = str_replace(' ', '+', $email);
     $is_valid_email = isvalid_email($email);
     // X not registered to main site.
     if (Env::v('x') && Env::i('userid') && $is_valid_email) {
         $user = User::getSilentWithUID(Env::i('userid'));
         if (!$user) {
             $page->trigError('Utilisateur invalide.');
             return;
         }
         // User has an account but is not yet registered.
         if ($user->state == 'pending') {
             // Add email in account table.
             XDB::query('UPDATE  accounts
                            SET  email = {?}
                          WHERE  uid = {?} AND email IS NULL', $email, $user->id());
             // Add email for marketing if required.
             if (Env::v('marketing')) {
                 $market = Marketing::get($user->uid, $email);
                 if (!$market) {
                     $market = new Marketing($user->uid, $email, 'group', $globals->asso('nom'), Env::v('marketing_from'), S::v('uid'));
                     $market->add();
                 }
             }
         } elseif (Env::v('broken')) {
             // Add email for broken if required.
             $valid = new BrokenReq(S::user(), $user, $email, 'Groupe : ' . $globals->asso('nom'));
             $valid->submit();
         }
     } else {
         $user = User::getSilent($email);
         // Wrong email and no user: failure.
         if (is_null($user) && (!$is_valid_email || !User::isForeignEmailAddress($email))) {
             $page->trigError('«&nbsp;<strong>' . $email . '</strong>&nbsp;» n\'est pas une adresse email valide.');
             return;
         }
         // Deals with xnet accounts.
         if (is_null($user) || $user->type == 'xnet') {
             // User is of type xnet. There are 3 possible cases:
             //  * the email is not known yet: we create a new account and
             //      propose to send an email to the user so he can activate
             //      his account,
             //  * the email is known but the user was not contacted in order to
             //      activate yet: we propose to send an email to the user so he
             //      can activate his account,
             //  * the email is known and the user was already contacted or has
             //      an active account: nothing to be done.
             list($mbox, $domain) = explode('@', strtolower($email));
             $hruid = User::makeHrid($mbox, $domain, 'ext');
             // User might already have an account (in another group for example).
             $user = User::getSilent($hruid);
             // If the user has no account yet, creates new account: build names from email address.
             if (empty($user)) {
                 require_once 'name.func.inc.php';
                 $parts = explode('.', $mbox);
                 if (count($parts) == 1) {
                     $lastname = $display_name = capitalize_name($mbox);
                     $firstname = '';
                 } else {
                     $display_name = $firstname = capitalize_name($parts[0]);
                     $lastname = capitalize_name(implode(' ', array_slice($parts, 1)));
                 }
                 $full_name = build_full_name($firstname, $lastname);
                 $directory_name = build_directory_name($firstname, $lastname);
                 $sort_name = build_sort_name($firstname, $lastname);
                 XDB::execute('INSERT INTO  accounts (hruid, display_name, full_name, directory_name, sort_name,
                                                      firstname, lastname, email, type, state)
                                    VALUES  ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, \'xnet\', \'disabled\')', $hruid, $display_name, $full_name, $directory_name, $sort_name, $firstname, $lastname, $email);
                 $user = User::getSilent($hruid);
             }
             $suggest_account_activation = $this->suggest($user);
         }
     }
     if ($user) {
         // First check if the user used to be in this group.
         XDB::rawExecute('DELETE FROM  group_former_members
                                WHERE  remember AND DATE_SUB(NOW(), INTERVAL 1 YEAR) > unsubsciption_date');
         $former_member = XDB::fetchOneCell('SELECT  remember
                                               FROM  group_former_members
                                              WHERE  uid = {?} AND asso_id = {?}', $user->id(), $globals->asso('id'));
         if ($former_member === 1) {
             $page->trigError($user->fullName() . ' est un ancien membre du groupe qui ne souhaite pas y revenir. S\'il souhaite revenir dans le groupe, il faut qu\'il en fasse la demande sur la page d\'accueil du groupe.');
             return;
         } elseif (!is_null($former_member) && Post::i('force_continue') == 0) {
             $page->trigWarning($user->fullName() . ' est un ancien membre du groupe qui s\'est récemment désinscrit. Malgré cela, si tu penses qu\'il souhaite revenir, cliquer sur « Ajouter » l\'ajoutera bien au groupe cette fois.');
             $page->assign('force_continue', 1);
             return;
         }
         Group::subscribe($globals->asso('id'), $user->id());
         $this->removeSubscriptionRequest($user->id());
         if ($user->isActive() && $user->bestEmail()) {
             $mailer = new PlMailer('xnetgrp/forced-subscription.mail.tpl');
             $mailer->addTo($user->bestEmail());
             $mailer->assign('group', $globals->asso('nom'));
             $mailer->assign('anim', S::user()->fullname());
             $mailer->assign('diminutif', $globals->asso('diminutif'));
             $mailer->send();
         }
         // Check if the group has more than 1000 members, if so, disable the "send mail" function.
         $full_count = XDB::fetchOneCell('SELECT COUNT(*)
                                            FROM group_members
                                           WHERE asso_id = {?}', $globals->asso('id'));
         if ($full_count > 999) {
             XDB::execute("UPDATE groups\n                    SET disable_mails = 1\n                    WHERE id = {?}", $globals->asso('id'));
         }
         if ($suggest_account_activation) {
             pl_redirect('member/suggest/' . $user->login() . '/' . $email . '/' . $globals->asso('nom'));
         } else {
             pl_redirect('member/' . $user->login());
         }
     }
 }
Beispiel #10
0
XDB::rawExecute('UPDATE  fusionax_formations           AS f
              LEFT JOIN  profile_education_enum        AS pe ON (pe.name = f.Intitule_formation)
              LEFT JOIN  profile_education_degree_enum AS pd ON (pd.abbreviation = f.Intitule_diplome)
              LEFT JOIN  profile_education_field_enum  AS pf ON (pf.field = f.Descr_formation)
                    SET  f.eduid = pe.id, f.degreeid = pd.id, f.fieldid = pf.id');
XDB::rawExecute('ALTER TABLE profile_education_enum DROP INDEX name');
XDB::rawExecute('ALTER TABLE profile_education_degree_enum DROP INDEX abbreviation');
// Updates non complete educations.
XDB::rawExecute("UPDATE  profile_education             AS e\n             INNER JOIN  fusionax_formations           AS f  ON (f.pid = e.pid)\n             INNER JOIN  profile_education_degree_enum AS pd ON (e.degreeid = pd.id)\n             INNER JOIN  profile_education_degree_enum AS fd ON (f.degreeid = fd.id)\n                    SET  e.eduid = f.eduid\n                  WHERE  NOT FIND_IN_SET('primary', e.flags) AND e.eduid IS NULL AND pd.level = fd.level");
XDB::rawExecute("UPDATE  profile_education   AS e\n             INNER JOIN  fusionax_formations AS f ON (f.pid = e.pid)\n                    SET  e.degreeid = f.degreeid\n                  WHERE  NOT FIND_IN_SET('primary', e.flags) AND e.degreeid IS NULL AND e.eduid = f.eduid");
// Deletes duplicates.
XDB::rawExecute("DELETE  f\n                   FROM  fusionax_formations           AS f\n             INNER JOIN  profile_education_degree_enum AS fd ON (fd.abbreviation = f.Intitule_diplome)\n             INNER JOIN  profile_education             AS e  ON (e.pid = f.pid AND NOT FIND_IN_SET('primary', e.flags))\n             INNER JOIN  profile_education_degree_enum AS pd ON (pd.id = e.degreeid)\n                  WHERE  f.eduid = e.eduid AND fd.level = pd.level");
// Updates merge_issues table.
XDB::rawExecute("UPDATE  profile_merge_issues AS pm\n             INNER JOIN  fusionax_formations  AS f ON (f.pid = pm.pid)\n                    SET  pm.issues = IF(pm.issues, CONCAT(pm.issues, ',', 'education'), 'education')");
XDB::rawExecute("INSERT IGNORE INTO  profile_merge_issues (pid, issues)\n                             SELECT  pid, 'education'\n                               FROM  fusionax_formations");
$id = 0;
$continue = 1;
while ($continue > 0) {
    XDB::rawExecute("INSERT IGNORE INTO  profile_education (id, pid, eduid, degreeid, fieldid, program)\n                                 SELECT  {$id}, pid, eduid, degreeid, fieldid, Descr_formation\n                                   FROM  fusionax_formations");
    XDB::rawExecute("DELETE  f\n                       FROM  fusionax_formations AS f\n                 INNER JOIN  profile_education   AS pe ON (pe.pid = f.pid AND pe.id = {$id})\n                      WHERE  (pe.eduid = f.eduid OR (pe.eduid IS NULL AND f.eduid IS NULL))\n                             AND (pe.degreeid = f.degreeid OR (pe.degreeid IS NULL AND f.degreeid IS NULL))\n                             AND (pe.fieldid = f.fieldid OR (pe.fieldid IS NULL AND f.fieldid IS NULL))\n                             AND (pe.program = f.Descr_formation OR (pe.program IS NULL AND f.Descr_formation IS NULL))");
    $continue = XDB::affectedRows();
    ++$id;
}
// Updates merge_issues table (eduid and degreeid should never be empty).
XDB::rawExecute("UPDATE  profile_merge_issues AS pm\n             INNER JOIN  profile_education    AS pe ON (pe.pid = pm.pid)\n                    SET  pm.issues = CONCAT(pm.issues, ',', 'education')\n                  WHERE  NOT FIND_IN_SET('education', pm.issues) AND (pe.eduid = '' OR pe.eduid IS NULL OR pe.degreeid = '' OR pe.degreeid IS NULL)");
XDB::rawExecute("INSERT IGNORE INTO  profile_merge_issues (pid, issues)\n                             SELECT  pid, 'education'\n                               FROM  profile_education\n                              WHERE  eduid = '' OR eduid IS NULL OR degreeid = '' OR degreeid IS NULL");
XDB::rawExecute('DROP TABLE IF EXISTS fusionax_formations');
echo "Educations inclusions finished.\n";
echo "All inclusions are done.\n";
XDB::commit();
/* vim:set et sw=4 sts=4 ts=4: */