Example #1
0
    /**
     * undocumented function
     *
     * @return void
     * @access public
     */
    function beforeValidate()
    {
        if (isset($this->data[__CLASS__]['default']) && $this->data[__CLASS__]['default']) {
            $Session = Common::getComponent('Session');
            $conditions = array('default' => '1', 'office_id' => $Session->read('Office.id'));
            if (!empty($this->data[__CLASS__]['id'])) {
                $conditions['id <>'] = $this->data[__CLASS__]['id'];
            }
            $defaultAppeal = $this->find('first', array('conditions' => $conditions, 'fields' => array('id', 'name')));
            if (!empty($defaultAppeal)) {
                $msg = sprintf(__('Sorry, there can only be one default appeal at the same time. 
							The current default appeal is: "%s".', true), $defaultAppeal[__CLASS__]['name']);
                $this->invalidate('default', $msg);
                return false;
            }
        }
        $published = isset($this->data[__CLASS__]['published']) && $this->data[__CLASS__]['published'];
        $templateId = false;
        if (isset($this->data[__CLASS__]['template_id'])) {
            $templateId = $this->data[__CLASS__]['template_id'];
        } elseif (isset($this->data[__CLASS__]['id'])) {
            $templateId = $this->lookup(array('id' => $this->data[__CLASS__]['id']), 'template_id', false);
        }
        $publishedTemplate = $this->Template->lookup(array('id' => $templateId), 'published', false);
        if ($published && !$publishedTemplate) {
            $msg = __('You cannot set the status to "published" if there is no published template assigned.', true);
            $this->invalidate('published', $msg);
        }
    }
Example #2
0
 /**
  * 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();
         }
     }
 }
Example #3
0
 /**
  * undocumented function
  *
  * @param string 
  * @param string 
  * @return void
  * @access public
  */
 function find($type, $query = array())
 {
     $args = func_get_args();
     switch ($type) {
         case 'list_for_office':
             $Session = Common::getComponent('Session');
             $gatewaysOffices = $this->GatewaysOffice->find('all', array('conditions' => array('GatewaysOffice.office_id' => $Session->read('Office.id')), 'contain' => array('Gateway(id, name)'), 'order' => array('Gateway.name' => 'asc')));
             return Set::combine($gatewaysOffices, '/Gateway/id', '/Gateway/name');
         case 'processing_options':
             return ClassRegistry::init('GatewayProcessing')->find('options');
     }
     return call_user_func_array(array('parent', 'find'), $args);
 }
Example #4
0
 /**
  * This function logs an activity of a given $activityType together with an array of $data related to it
  *
  * @param mixed $activityTypeId Either the numeric foreign key value for the activity_type or a string to look it up / create
  * @param array $data An array of data that will be serialized for later reference
  * @param $repeatWithin Either false or a timestamp in the past / array of conditions for this to qualify as a repeated activity
  * @return boolean True on success
  * @access public
  */
 function get($navGroup = null)
 {
     $Session = Common::getComponent('Session');
     $navigations = array('Guests' => array(), 'Admin' => array(__('Home', true) => array('/admin/home', '#/^\\/admin(\\/statistics|\\/home).*$/iU'), __('Appeals', true) => array('/admin/appeals/index', '#/^\\/admin\\/appeals.*$/iU'), __('Templates', true) => array('/admin/templates', '#/^\\/admin\\/templates.*$/iU'), __('Gifts', true) => array('/admin/gifts/index/all', '#/\\/admin(\\/gifts|\\/exports\\/gifts).*/iU'), __('Transactions', true) => array('/admin/transactions/index/all', '#/\\/admin\\/transactions.*/iU'), __('Supporters', true) => array('/admin/supporters', '#/\\/admin\\/supporters.*/iU'), __('Office Config', true) => array('/admin/offices/edit', '#/\\/admin\\/offices(\\/edit|\\/view).*/iU', '#/\\/admin\\/(offices|users).*/iU', 'role' => 'office_manager'), __('Help', true) => array('/admin/help', '#/\\/admin\\/help.*/iU')), 'appeal_sub' => array(__('All', true) => array('/admin/appeals/index', '#/^\\/admin\\/appeals\\/index.*$/iU')), 'template_sub' => array(__('All', true) => array('/admin/appeals/index', '#/^\\/admin\\/templates.*$/iU')), 'gift_sub' => array(__('All', true) => array('/admin/gifts/index/all', '#/^\\/admin\\/gifts\\/index\\/all.*$/iU'), __('Onetime', true) => array('/admin/gifts/index/onetime', '#/^\\/admin\\/gifts\\/index\\/onetime.*$/iU'), __('Recurring', true) => array('/admin/gifts/index/recurring', '#/^\\/admin\\/gifts\\/index\\/recurring.*$/iU'), __('Favorites', true) => array('/admin/gifts/index/favorites', '#/^\\/admin\\/gifts\\/index\\/favorites.*$/iU'), __('Archived', true) => array('/admin/gifts/index/archived', '#/^\\/admin\\/gifts\\/index\\/archived.*$/iU'), __('Statistics', true) => array('/admin/gifts/stats', '#/^\\/admin\\/gifts\\/stats.*$/iU')), 'transaction_sub' => array(__('All', true) => array('/admin/transactions/index/all', '#/^\\/admin\\/transactions\\/index\\/all.*$/iU'), __('Favorites', true) => array('/admin/transactions/index/favorites', '#/^\\/admin\\/gifts\\/transactions\\/index\\/favorites.*$/iU'), __('Archived', true) => array('/admin/transactions/index/archived', '#/^\\/admin\\/gifts\\/transactions\\/index\\/archived.*$/iU')), 'user_sub' => array(__('All', true) => array('/admin/users/index/all', '#/^\\/admin\\/users\\/index\\/all.*$/iU'), __('My Office Colleagues', true) => array('/admin/users/index/colleagues', '#/^\\/admin\\/users\\/index\\/colleagues.*$/iU')), 'supporter_sub' => array(__('All', true) => array('/admin/supporters', '#/^\\/admin\\/supporters$/iU'), __('One-off', true) => array('/admin/supporters/index/oneoff', '#/^\\/admin\\/supporters\\/index\\/oneoff.*$/iU'), __('Recurring', true) => array('/admin/supporters/index/recurring', '#/^\\/admin\\/supporters\\/index\\/recurring.*$/iU'), __('Favorites', true) => array('/admin/supporters/index/favorites', '#/^\\/admin\\/supporters\\/favorites.*$/iU'), __('Signups', true) => array('/admin/supporters/index/signups', '#/^\\/admin\\/supporters\\/signups.*$/iU')), 'user_preferences' => array(__('Preferences', true) => array('/admin/users/preferences', '#/^\\/admin\\/users\\/preferences.*$/iU'), __('Edit Password', true) => array('/admin/users/edit_password', '#/^\\/admin\\/users\\/edit_password.*$/iU'), __('Public Key', true) => array('/admin/users/public_key', '#/^\\/admin\\/users\\/public_key.*$/iU'), __('Email Reports', true) => array('/admin/users/email_reports', '#/^\\/admin\\/users\\/email_reports.*$/iU', 'condition' => User::allowed('Users', 'admin_email_reports'))), 'admin_auth_sub' => array(__('Login', true) => array('/admin/auth/login', '#/^\\/admin\\/(auth\\/|)login.*$/iU'), __('Lost Password', true) => array('/admin/users/forgot_pw', '#/^\\/admin\\/users\\/forgot_pw.*$/iU')), 'admin_config_sub' => array(__('Config', true) => array('/admin/offices/edit/', '#/\\/admin\\/offices(\\/edit|\\/view)\\/.*/iU', 'role' => array('office_manager')), __('Team &amp; Permissions', true) => array('/admin/users', '#/\\/admin\\/users\\/(index\\/[^unactivated]|view).*/iU', 'role' => array('office_manager')), __('Unactivated Users', true) => array('/admin/users/index/unactivated', '#/\\/admin\\/users\\/index\\/unactivated.*/iU', 'role' => array('office_manager'))), 'admin_help_sub' => array(__('Getting started', true) => array('/admin/help', '#/\\/admin\\/help(\\/start)/'), __('Faq', true) => array('/admin/help/faq', '#/\\/admin\\/help\\/faq\\/.*/iU')), 'admin_root_admin_sub' => array(__('Dashboard', true) => array('/admin/dashboards', '#/\\/admin\\/dashboards.*/iU'), __('Offices', true) => array('/admin/offices', '#/\\/admin\\/offices.*/iU', 'role' => 'root'), __('Users', true) => array('/admin/users', '#/\\/admin\\/users.*/iU', 'role' => 'root'), __('Roles', true) => array('/admin/roles', '#/\\/admin\\/roles.*/iU', 'role' => 'root'), __('Activity Log', true) => array('/admin/logs', '#/\\/admin\\/logs.*/iU', 'role' => 'root'), __('Smileys', true) => array('/admin/smileys', '#/\\/admin\\/smileys.*/iU', 'role' => 'root')));
     if (!empty($navGroup) && isset($navigations[$navGroup])) {
         return $navigations[$navGroup];
     }
     $navigation = $navigations['Guests'];
     if (class_exists('User') && !User::is('guest')) {
         $navigation = $navigations['Admin'];
     }
     return $navigation;
 }
Example #5
0
 static function deliver($template, $options = array())
 {
     $options = Set::merge(array('vars' => array(), 'mail' => array('to' => array(), 'from' => Configure::read('App.emails.noReply'), 'charset' => 'utf8', 'sendAs' => 'text', 'subject' => '', 'template' => $template, 'layout' => 'email', 'attachments' => array()), 'store' => false), $options);
     if (!empty($options['mail']['subject'])) {
         $options['mail']['subject'] = strip_tags($options['mail']['subject']);
     }
     $delivery = Configure::read('App.emailDeliveryMethod');
     if (!empty($delivery) && !isset($options['mail']['delivery'])) {
         $options['mail']['delivery'] = $delivery;
     }
     if (isset($options['mail']['delivery']) && $options['mail']['delivery'] == 'smtp') {
         $options['mail']['smtpOptions'] = Configure::read('App.smtpOptions');
     }
     if (Common::isDevelopment()) {
         $options['mail']['delivery'] = 'debug';
     }
     App::import('Core', 'Controller');
     $Email = Common::getComponent('Email');
     Common::setProperties($Email, $options['mail']);
     if (!isset($Email->Controller)) {
         App::import('Core', 'Router');
         $Email->Controller = new AppController();
     }
     $Email->Controller->set($options['vars']);
     if ($options['store']) {
         $hash = sha1(json_encode($options));
         $folder = substr($hash, 0, 2);
         $file = substr($hash, 2) . '.html';
         $url = '/emails/' . $folder . '/' . $file;
         $path = APP . 'webroot' . $url;
         if (!is_dir(dirname($path))) {
             @mkdir(dirname($path));
         }
         $url = Router::url($url, true);
         $Email->Controller->set('emailUrl', $url);
         $View = new View($Email->Controller, false);
         $View->layout = $Email->layout;
         $View->layoutPath = 'email' . DS . 'html';
         $html = $View->element('email' . DS . 'html' . DS . $options['mail']['template'], array('content' => null), true);
         $html = $View->renderLayout($html);
         file_put_contents($path, $html);
     }
     if (!isset($Email->Controller->Session)) {
         $Email->Controller->Session = Common::getComponent('Session');
     }
     $result = $Email->send();
     if (Common::isDevelopment() && Configure::read('App.email_debug')) {
         Common::debugEmail();
     }
     return $result;
 }
Example #6
0
 /**
  * undocumented function
  *
  * @param string 
  * @param string 
  * @return void
  * @access public
  */
 function find($type, $query = array())
 {
     $args = func_get_args();
     switch ($type) {
         case 'options':
             $conditions = array();
             if (!isset($query['all'])) {
                 $Session = Common::getComponent('Session');
                 $langs = $this->LanguagesOffice->find('all', array('conditions' => array('office_id' => $Session->read('Office.id')), 'fields' => array('language_id')));
                 if (!empty($langs)) {
                     $conditions['id'] = Set::extract('/LanguagesOffice/language_id', $langs);
                 }
             }
             return $this->find('list', array('conditions' => $conditions, 'fields' => array('code', 'name'), 'order' => array('name' => 'asc')));
     }
     return call_user_func_array(array('parent', 'find'), $args);
 }
Example #7
0
 /**
  * undocumented function
  *
  * @param string $model 
  * @param string $field 
  * @param string $default 
  * @param string $data 
  * @return void
  * @access public
  */
 function value($model, $field, $default, $data)
 {
     $result = $default;
     $this->Cookie = Common::getComponent('Cookie');
     $cookieValue = $this->Cookie->read($model . '.' . $field);
     if (!empty($cookieValue)) {
         $result = $cookieValue;
     }
     $this->Session = Common::getComponent('Session');
     $sessValue = $this->Session->read($model . '.' . $field);
     if (!empty($sessValue)) {
         $result = $sessValue;
     }
     if (isset($data[$model][$field])) {
         $result = $data[$model][$field];
     }
     return $result;
 }
Example #8
0
 /**
  * undocumented function
  *
  * @param string $file 
  * @param string $template 
  * @return void
  * @access public
  */
 function parseFile($file, $template, $save = false, $importId = false)
 {
     $Session = Common::getComponent('Session');
     $Transaction = ClassRegistry::init('Transaction');
     $officeId = $Session->read('Office.id');
     $formats = array('friends' => array('delim' => '|', 'fields' => array('parent_order_id', 'parent_currency', 'parent_amount', 'order_id', 'currency', 'amount')));
     if (!array_key_exists($template, $formats)) {
         return false;
     }
     $format = $formats[$template];
     App::import('Vendor', 'csv_parser');
     $csv =& new csv_bv($file, ',', '"', '\\');
     $csv->SkipEmptyRows(false);
     $csv->TrimFields(TRUE);
     $num = 0;
     $result = array('valid' => 0, 'invalid_missing_parent' => 0);
     while ($row = $csv->NextLine()) {
         $num++;
         $values = explode($format['delim'], $row[0]);
         $data = array();
         foreach ($format['fields'] as $i => $field) {
             $data[$field] = $values[$i];
             if ($field == 'parent_order_id') {
                 $parent = $this->Transaction->find('first', array('conditions' => array('order_id' => $values[$i]), 'fields' => array('id', 'gift_id', 'gateway_id')));
                 if (empty($parent)) {
                     $result['invalid_missing_parent']++;
                     continue 2;
                 }
                 $data['parent_id'] = $parent['Transaction']['id'];
                 $data['gift_id'] = $parent['Transaction']['gift_id'];
                 $data['gateway_id'] = $parent['Transaction']['gateway_id'];
             }
         }
         if ($save) {
             $data['import_id'] = $importId;
             $this->Transaction->create($data);
             $this->Transaction->save();
         }
         $result['valid']++;
     }
     return $result;
 }
 /**
  * undocumented function
  *
  * @return void
  * @access public
  */
 function init()
 {
     $config = Configure::read('Logging');
     $RequestHandler = Common::getComponent('RequestHandler');
     $ip = $RequestHandler->getClientIP();
     $userData = User::get();
     foreach ($config['models'] as $model) {
         $Model = ClassRegistry::init($model);
         $attached = $Model->Behaviors->_attached;
         foreach ($attached as $behavior) {
             $Model->Behaviors->detach($behavior);
         }
         $Model->Behaviors->attach('Logging.Logable');
         foreach ($attached as $behavior) {
             $Model->Behaviors->attach($behavior);
         }
         $Model->setUserData($userData);
         $Model->setUserIp($ip);
     }
 }
Example #10
0
 /**
  * undocumented function
  *
  * @param string $templateId 
  * @param string $step 
  * @return void
  * @access public
  */
 function trackHit($templateId, $appealId, $step)
 {
     $conditions = array('template_id' => $templateId, 'is_thanks' => '1');
     if ($step != 'thanks') {
         unset($conditions['is_thanks']);
         $conditions['num'] = $step;
     }
     $step = $this->TemplateStep->find('first', array('conditions' => $conditions, 'fields' => array('id')));
     $stepId = $step['TemplateStep']['id'];
     $isPageview = false;
     $RequestHandler = Common::getComponent('RequestHandler');
     $ip = $RequestHandler->getClientIp();
     $date = date('Y-m-d H:i:s', strtotime('-1 hours'));
     $visit = $this->find('first', array('conditions' => array('template_step_id' => $stepId, 'foreign_id' => $appealId, 'ip' => $ip, "DATE_FORMAT(" . __CLASS__ . ".created, '%Y-%m-%d %H:%i:%s') >= '" . $date . "'"), 'fields' => array('id', 'pageviews')));
     if (!empty($visit)) {
         $this->set(array('id' => $visit[__CLASS__]['id'], 'pageviews' => $visit[__CLASS__]['pageviews'] + 1));
     } else {
         $this->create(array('template_step_id' => $stepId, 'foreign_id' => $appealId, 'ip' => $ip, 'pageviews' => '1'));
     }
     return $this->save();
 }
Example #11
0
 /**
  * undocumented function
  *
  * @return void
  * @access public
  */
 function debugEmail()
 {
     $Session = Common::getComponent('Session');
     prd($Session->read('Message.email'));
 }
Example #12
0
 /**
  * Writes all current sess messages to the session.
  *
  * @return void
  * @access public
  */
 function writeToSession()
 {
     $Session = Common::getComponent('Session');
     $result = $Session->write($this->sessKey, $this->sessMessages);
     return $result;
 }
Example #13
0
 /**
  * Set the user as current
  * @param array $user
  * @param bool $updateSession
  * @param bool $generateAuthCookie
  */
 static function setActive($user = null, $find = true)
 {
     $_this = Common::getModel('User');
     //@TODO only fetch if $user is incomplete compared to find conditions
     if ($find) {
         if ($user != 'guest' && isset($user['User']['id']) && Common::isUuid($user['User']['id'])) {
             $user = $_this->find('first', $_this->getFindOptions('userActivation', $user));
         }
         if ($user == 'guest' || is_null($user) || empty($user)) {
             $user = $_this->find('first', $_this->getFindOptions('guestActivation'));
         }
     }
     if (isset($user['User']['password'])) {
         unset($user['User']['password']);
         // just to make sure
     }
     Configure::write('User', $user);
     $Session = Common::getComponent('Session');
     $Session->write('User', $user);
     return $user;
 }
Example #14
0
 /**
  * undocumented function
  *
  * @return void
  * @access public
  */
 static function ip()
 {
     $RequestHandler = Common::getComponent('RequestHandler');
     return $RequestHandler->getClientIP();
 }
Example #15
0
<?php

App::import('Model', 'Favorites.Favorite');
$Session = Common::getComponent('Session');
$officeId = $Session->read('Office.id');
$config = array('Favorites' => array('subject' => 'starred item', 'verb' => 'star', 'adjective' => 'starred', 'models' => array('Gift' => 'name', 'Transaction' => 'serial', 'Contact' => 'name', 'Comment' => 'increment'), 'loadConditions' => array('or' => array('Gift.office_id' => $officeId, 'Gift.id IS NULL')), 'urls' => array('/\\/admin\\/.*$/')));
Example #16
0
 /**
  * undocumented function
  *
  * @return void
  * @access public
  */
 function officeId()
 {
     $result = false;
     $isGuest = User::is('guest');
     $Session = Common::getComponent('Session');
     if ($Session->check('Office.id') && !$isGuest) {
         $result = $Session->read('Office.id');
     }
     if ($Session->check('gift_process_office_id') && $isGuest) {
         $result = $Session->read('gift_process_office_id');
     }
     return $result;
 }
Example #17
0
 /**
  * undocumented function
  *
  * @param string $id 
  * @return void
  * @access public
  */
 function reload($id)
 {
     $Session = Common::getComponent('Session');
     if ($id == $Session->read('Office.id')) {
         $this->activate($id);
     }
 }
Example #18
0
 /**
  * undocumented function
  *
  * @param string $id 
  * @return void
  * @access public
  */
 function isFavorited($id)
 {
     $Session = Common::getComponent('Session');
     return in_array($id, $Session->read('favorites'));
 }