コード例 #1
0
ファイル: send_reports.php プロジェクト: stripthis/donate
 /**
  * undocumented function
  *
  * todo: encryption
  *
  * @return void
  * @access public
  */
 function main()
 {
     $this->out('Calculating reports ..');
     $reports = $this->Report->find('all');
     if (empty($reports)) {
         $this->out('Found 0 reports. Exiting.');
         exit(1);
     }
     $Pgp = Common::getComponent('Pgp');
     foreach ($reports as $report) {
         $this->out('Processing report "' . $report['Report']['title'] . '" ..');
         $conditions = array('ReportsUser.report_id' => $report['Report']['id']);
         $frequency = $report['Report']['frequency'];
         switch ($frequency) {
             case 'daily':
                 $date = date('Y-m-d H:i', strtotime('-1 day'));
                 break;
             case 'weekly':
                 $date = date('Y-m-d H:i', strtotime('-1 week'));
                 break;
             case 'yearly':
                 $date = date('Y-m-d H:i', strtotime('-1 year'));
                 break;
         }
         // $conditions[] = "DATE_FORMAT(ReportsUser.last_sent, '%Y-%m-%d %H:%i') = '" . $date . "'";
         $users = $this->ReportsUser->find('all', array('conditions' => $conditions, 'contain' => array('User'), 'order' => array('ReportsUser.created' => 'asc')));
         $this->out('Found ' . count($users) . ' user(s) that need a report');
         if (empty($users)) {
             continue;
         }
         $name = ucfirst($report['Report']['frequency']) . ' Report "' . $report['Report']['title'] . '"';
         foreach ($users as $user) {
             $officeId = $user['User']['office_id'];
             $query = $report['Report']['query'];
             $query = r('%condition', 'AND Gift.office_id = "' . $officeId . '"', $query);
             $results = $this->Transaction->query($query);
             $content = $this->parseTemplate($report['Report']['view'], $results);
             $attachment = $Pgp->encrypt(array('msg' => $content, 'recipient' => $user['User']['login']));
             if (!$attachment) {
                 $this->out('There was a problem encrypting the report for ' . $user['User']['login']);
             }
             $this->ReportsUser->set(array('id' => $user['ReportsUser']['id'], 'last_sent' => date('Y-m-d H:i:s')));
             $this->ReportsUser->save();
             if (!Common::isDevelopment()) {
                 $options = array('mail' => array('to' => $user['User']['login'], 'subject' => $name, 'attachments' => array($attachment)), 'vars' => compact('content'));
                 Mailer::deliver('report', $options);
                 $this->out('Sent ' . $name . ' to ' . $user['User']['login']);
             }
             $Pgp->flush();
         }
     }
 }
コード例 #2
0
ファイル: gift.php プロジェクト: stripthis/donate
 /**
  * Deliver mail receipt
  * @param string $email 
  * @param string $authKey 
  * @return void
  * @access public
  */
 function emailReceipt($email, $authKey)
 {
     $emailSettings = array('vars' => array('keyData' => $authKey), 'mail' => array('to' => $email, 'subject' => Configure::read('App.name') . ': Your Tax Receipt'), 'store' => false);
     Mailer::deliver('receipt', $emailSettings);
 }
コード例 #3
0
ファイル: admin.php プロジェクト: stripthis/donate
 /**
  * undocumented function
  *
  * @return void
  * @access public
  */
 function main()
 {
     $login = isset($this->args[0]) ? $this->args[0] : false;
     if (empty($login) || $login == Configure::read('App.emails.guestAccount')) {
         $this->out('Funny man ..');
         exit(1);
     }
     $data = $this->User->find('first', array('conditions' => compact('login')));
     if (!$data) {
         $this->out('The user ' . $login . ' does not exist yet. Please choose an office for this user:'******'Office for the new User:'******'list');
         $ids = array_keys($officeOptions);
         $names = array_values($officeOptions);
         foreach ($names as $i => $name) {
             $i++;
             $this->out($i . '. ' . $name);
         }
         $validChoice = false;
         do {
             $choice = $this->in('Please choose a number: ');
             if ($choice > count($officeOptions)) {
                 $this->out('This number is not valid, please retry.');
             } else {
                 $validChoice = true;
             }
         } while (!$validChoice);
         $data['User']['office_id'] = $ids[$choice - 1];
         $this->hr();
         $this->out('Salutation for the new user:'******'Contact']['salutation'])) {
             $title = strtoupper($this->in('[M]r oder [Mr]s'));
             switch ($title) {
                 case 'M':
                     $data['Contact']['salutation'] = 'mr';
                     break;
                 case 'Mr':
                     $data['Contact']['salutation'] = 'mrs';
                     break;
                 default:
                     $this->out('Your input is invalid. Please type in either [M] or [Mr].', true);
             }
         }
         // @todo maybe add support for title (prof., dr., prof. dr., etc.)
         $data['Contact']['email'] = $login;
         while (true) {
             $data['Contact']['fname'] = $this->in('First Name:');
             $data['Contact']['lname'] = $this->in('Last Name:');
             if ($this->validates($data, 'Contact')) {
                 break;
             }
         }
         $data['User']['name'] = $data['Contact']['fname'] . ' ' . $data['Contact']['lname'];
         $this->hr();
         $data['User']['level'] = 'admin';
         $data['User']['login'] = $login;
         $this->Contact->create($data);
         if (!$this->Contact->save()) {
             return $this->out('Sorry, an error has occurred while saving the contact data');
         }
         $contactId = $this->Contact->getLastInsertId();
         $data['User']['active'] = '1';
         $data['User']['contact_id'] = $contactId;
         $this->User->create();
     } else {
         $this->out('The user ' . $login . ' exists. Are you sure you want to reset the password for this user?');
         while (empty($confirm)) {
             $confirm = strtoupper($this->in('[Y]es or [N]o'));
             switch ($confirm) {
                 case 'Y':
                     break;
                 case 'N':
                     $this->out('O.K. The script is terminated.');
                     exit(0);
                     break;
                 default:
                     $confirm = '';
                     $this->out('Your input is invalid, please type in either [Y] or [N].', true);
             }
         }
     }
     $this->hr();
     $pwData = $this->User->generatePassword();
     $password = $pwData[0];
     $data['User']['password'] = $pwData[1];
     $data['User']['repeat_password'] = $pwData[1];
     if (!$this->User->save($data)) {
         return $this->out('Sorry, an error has occurred while saving the user data.');
     }
     $officeUrl = Configure::read('App.domain');
     $options = array('mail' => array('to' => $login, 'subject' => 'New Account for Greenpeace White Rabbit'), 'vars' => array('url' => $officeUrl, 'password' => $password));
     if (!Common::isDevelopment()) {
         Mailer::deliver('created_admin', $options);
     }
     $msg = 'The admin account for ' . $login . ' has been created/reset successfully. ';
     $msg .= 'An email has been sent to the email address.';
     $this->out($msg);
     $this->out('password is: ' . $password);
 }
コード例 #4
0
ファイル: user.php プロジェクト: stripthis/donate
 /**
  * undocumented function
  *
  * @param string $data 
  * @param string $password 
  * @return void
  * @access public
  */
 function sendNewAccountEmail($password, $data)
 {
     $options = array('mail' => array('to' => $data['User']['login'], 'subject' => __('New Account for Greenpeace White Rabbit', true)), 'vars' => array('url' => Configure::read('App.domain'), 'password' => $password));
     Mailer::deliver('created_admin', $options);
     $managers = $this->find('office_managers', array('exclude_me' => true, 'office_id' => $data[__CLASS__]['office_id']));
     foreach ($managers as $manager) {
         $options = array('mail' => array('to' => $manager[__CLASS__]['login'], 'subject' => __('New Admin created in your office for Greenpeace White Rabbit', true)), 'vars' => array('url' => Configure::read('App.domain'), 'login' => $data[__CLASS__]['login'], 'creator' => User::get()));
         Mailer::deliver('office_admin_note_for_new_user', $options);
     }
 }
コード例 #5
0
 /**
  * controller action for tellafriend feature
  *
  * @return void
  * @access public
  */
 function refer()
 {
     //render tellfriends page
     if ($this->isGet()) {
         return;
     }
     //Check whether email content is spam
     $comment = array('comment_author' => '', 'comment_author_email' => $this->data['Tellfriend']['sender'], 'comment_content' => $this->data['Tellfriend']['content'], 'comment_type' => 'tell a friend');
     $emailContentIsSpam = $this->Akismet->checkComment($comment);
     //Verify recaptcha
     $recaptchaVerified = true;
     if ($this->data['tellafriend']['useRecaptcha'] == 1) {
         $recaptchaVerified = $this->Recaptcha->valid($this->params['form']);
     }
     if ($emailContentIsSpam == 'true') {
         echo $msg = 'Message content appears to be spam.';
         exit;
     } else {
         if ($recaptchaVerified) {
             $allowedCharInEmail = array('@', ',', '.', '-', '_');
             App::import('Sanitize');
             $this->data['Tellfriend']['receiver'] = Sanitize::paranoid($this->data['Tellfriend']['receiver'], $allowedCharInEmail);
             $toEmail = explode(',', $this->data['Tellfriend']['receiver']);
             array_walk($toEmail, 'trim');
             $fromEmail = $this->data['Tellfriend']['sender'];
             $saveData = $this->data;
             $saveData['Tellfriend']['ip'] = $this->RequestHandler->getClientIP();
             if ($this->Caplimit->checkCaps($toEmail, $fromEmail) == false) {
                 return $this->render('refer_not_allowed');
             }
             if ($this->Tellfriend->saveReference($saveData, $toEmail)) {
                 $appName = Configure::read('App.name');
                 foreach ($toEmail as $email) {
                     $emailSettings = array('vars' => array('message' => $this->data['Tellfriend']['content']), 'mail' => array('to' => $email, 'subject' => 'A Friend suggested you check out ' . $appName));
                     if (Mailer::deliver('tellfriend', $emailSettings)) {
                         $this->Tellfriend->saveField('sent', 1);
                         $msg = __('Your message has been sent to your friends.', true);
                         return $this->Message->add($msg, 'ok', true, $this->referer());
                     }
                     $msg = __('Your message was not sent due to an internal problem. Please try again.', true);
                     return $this->Message->add($msg, 'ok', true, $this->referer());
                 }
             }
         } else {
             $msg = __('The characters you entered didn\'t match the word verification. Please try again.', true);
             return $this->Message->add($msg, 'ok', true, $this->referer());
         }
     }
 }