Пример #1
0
 public function getOrder()
 {
     if (!self::$order) {
         self::$order = new UFO_ProfileUpdate();
     }
     return self::$order;
 }
Пример #2
0
 function handler_broken_addr($page)
 {
     require_once 'emails.inc.php';
     $page->changeTpl('emails/broken_addr.tpl');
     if (Env::has('sort_broken')) {
         S::assert_xsrf_token();
         $list = trim(Env::v('list'));
         if ($list == '') {
             $page->trigError('La liste est vide.');
         } else {
             $valid_emails = array();
             $invalid_emails = array();
             $broken_list = explode("\n", $list);
             sort($broken_list);
             foreach ($broken_list as $orig_email) {
                 $orig_email = trim($orig_email);
                 if ($orig_email != '') {
                     $email = valide_email($orig_email);
                     if (empty($email) || $email == '@') {
                         $invalid_emails[] = trim($orig_email) . ': invalid email';
                     } elseif (!in_array($email, $valid_emails)) {
                         $nb = XDB::fetchOneCell('SELECT  COUNT(*)
                                                    FROM  email_redirect_account
                                                   WHERE  redirect = {?}', $email);
                         if ($nb > 0) {
                             $valid_emails[] = $email;
                         } else {
                             $invalid_emails[] = $orig_email . ': no such redirection';
                         }
                     }
                 }
             }
             $page->assign('valid_emails', $valid_emails);
             $page->assign('invalid_emails', $invalid_emails);
         }
     }
     if (Env::has('process_broken')) {
         S::assert_xsrf_token();
         $list = trim(Env::v('list'));
         if ($list == '') {
             $page->trigError('La liste est vide.');
         } else {
             require_once 'notifs.inc.php';
             $broken_user_list = array();
             $broken_user_email_count = array();
             $broken_user_profiles = array();
             $broken_list = explode("\n", $list);
             sort($broken_list);
             foreach ($broken_list as $email) {
                 $email = trim($email);
                 $userobj = null;
                 if ($user = mark_broken_email($email, true)) {
                     $userobj = User::getSilentWithUID($user['uid']);
                 }
                 if (is_null($userobj)) {
                     continue;
                 }
                 $profile = $userobj->profile();
                 if (is_null($profile)) {
                     continue;
                 }
                 if ($user['nb_mails'] > 0 && $user['notify']) {
                     $mail = new PlMailer('emails/broken.mail.tpl');
                     $mail->setTo($userobj);
                     $mail->assign('user', $user);
                     $mail->assign('email', $email);
                     $mail->send();
                 } else {
                     WatchProfileUpdate::register($profile, 'broken');
                 }
                 $pid = $profile->id();
                 if (!isset($broken_user_list[$pid])) {
                     $broken_user_list[$pid] = array($email);
                 } else {
                     $broken_user_list[$pid][] = $email;
                 }
                 $broken_user_email_count[$pid] = $user['nb_mails'];
                 $broken_user_profiles[$pid] = $profile;
             }
             XDB::execute('UPDATE  email_redirect_account
                              SET  broken_level = broken_level - 1
                            WHERE  flags = \'active\' AND broken_level > 1
                                   AND DATE_ADD(last, INTERVAL 1 MONTH) < CURDATE()');
             XDB::execute('UPDATE  email_redirect_account
                              SET  broken_level = 0
                            WHERE  flags = \'active\' AND broken_level = 1
                                   AND DATE_ADD(last, INTERVAL 1 YEAR) < CURDATE()');
             // Sort $broken_user_list with (promo, sortname, pid)
             $sortable_array = array();
             foreach ($broken_user_list as $pid => $mails) {
                 $profile = $broken_user_profiles[$pid];
                 $sortable_array[$pid] = array($profile->promo(), $profile->sortName(), $pid);
             }
             asort($sortable_array);
             // Output the list of users with recently broken addresses,
             // along with the count of valid redirections.
             pl_cached_content_headers('text/x-csv', null, 1, 'broken.csv');
             $csv = fopen('php://output', 'w');
             fputcsv($csv, array('nom', 'promo', 'bounces', 'nbmails', 'url', 'corps', 'job', 'networking'), ';');
             $corpsList = DirEnum::getOptions(DirEnum::CURRENTCORPS);
             foreach (array_keys($sortable_array) as $pid) {
                 $mails = $broken_user_list[$pid];
                 $profile = $broken_user_profiles[$pid];
                 $current_corps = $profile->getCorpsName();
                 $jobs = $profile->getJobs();
                 $companies = array();
                 foreach ($jobs as $job) {
                     $companies[] = $job->company->name;
                 }
                 $networkings = $profile->getNetworking(Profile::NETWORKING_ALL);
                 $networking_list = array();
                 foreach ($networkings as $networking) {
                     $networking_list[] = $networking['address'];
                 }
                 fputcsv($csv, array($profile->fullName(), $profile->promo(), join(',', $mails), $broken_user_email_count[$pid], 'https://www.polytechnique.org/marketing/broken/' . $profile->hrid(), $current_corps, implode(',', $companies), implode(',', $networking_list)), ';');
             }
             fclose($csv);
             exit;
         }
     }
 }
Пример #3
0
 public function saveData()
 {
     require_once 'notifs.inc.php';
     $changedFields = array();
     foreach ($this->settings as $field => &$setting) {
         if ($this->changed[$field]) {
             if (!is_null($setting)) {
                 $changedFields[$field] = array(preg_replace('/(\\r\\n|\\n|\\r)/', ' - ', $setting->getText($this->orig[$field])), preg_replace('/(\\r\\n|\\n|\\r)/', ' - ', $setting->getText($this->values[$field])));
             } else {
                 $changedFields[$field] = array(preg_replace('/(\\r\\n|\\n|\\r)/', ' - ', $this->orig[$field]), preg_replace('/(\\r\\n|\\n|\\r)/', ' - ', $this->values[$field]));
             }
             if (!is_null($setting)) {
                 $setting->save($this, $field, $this->values[$field]);
             }
             if (isset($this->watched[$field]) && $this->watched[$field]) {
                 WatchProfileUpdate::register($this->profile, $field);
             }
         }
     }
     $this->_saveData();
     // Update the last modification date
     XDB::execute('UPDATE  profiles
                      SET  last_change = NOW()
                    WHERE  pid = {?}', $this->pid());
     global $platal;
     S::logger()->log('profil', $platal->pl_self(2));
     /** Stores all profile modifications for active users in order to:
      *  -daily notify the user in case of third party edition,
      *  -display the modification to the secretaries for verification in
      *  case of an edition made by the user.
      */
     $owner = $this->profile->owner();
     $user = S::user();
     if ($owner->isActive()) {
         foreach ($changedFields as $field => $values) {
             if (array_key_exists($field, Profile::$descriptions)) {
                 XDB::execute('INSERT INTO  profile_modifications (pid, uid, field, oldText, newText, type, timestamp)
                                    VALUES  ({?}, {?}, {?}, {?}, {?}, {?}, NOW())
                   ON DUPLICATE KEY UPDATE  uid = VALUES(uid), oldText = IF(VALUES(type) != type, VALUES(oldText), oldText),
                                            newText = VALUES(newText), type = VALUES(type), timestamp = NOW()', $this->pid(), $user->id(), Profile::$descriptions[$field], $values[0], $values[1], $owner->id() == $user->id() ? 'self' : 'third_party');
             }
         }
     }
     return true;
 }