function preDispatch()
 {
     $this->getDi()->auth->requireLogin(ROOT_URL . '/member');
     $this->user = $this->getDi()->user;
     $this->view->assign('user', $this->user);
     $this->user_id = $this->user->pk();
 }
Example #2
0
 function logDownload(User $user, File $file, $ip = '')
 {
     $begin_date = $this->getDi()->dateTime;
     $begin_date->modify('-' . self::TOLERANCE . ' seconds');
     $begin_date = $begin_date->format('Y-m-d H:i:s');
     $count = $this->countBy(array('user_id' => $user->pk(), 'file_id' => $file->pk(), 'dattm' => '>' . $begin_date));
     if (!$count) {
         $this->insert(array('user_id' => $user->pk(), 'file_id' => $file->pk(), 'dattm' => $this->getDi()->sqlDateTime, 'remote_addr' => $ip));
     }
 }
Example #3
0
 public function changeEmail(User $user, $oldEmail, $newEmail)
 {
     $list_ids = $this->getDi()->newsletterUserSubscriptionTable->getSubscribedIds($user->pk());
     $lists = array();
     foreach ($this->getDi()->newsletterListTable->loadIds($list_ids) as $list) {
         if ($list->plugin_id != $this->getId()) {
             continue;
         }
         $lists[] = $list->plugin_list_id;
     }
     if (empty($lists)) {
         return;
     }
     require_once 'lib/csrest_subscribers.php';
     $customFields = $this->getCustomFields($user);
     foreach ($lists as $listId) {
         $wrap = new CS_REST_Subscribers($listId, array('api_key' => $this->getConfig('api_key')));
         $result = $wrap->update($oldEmail, array('EmailAddress' => $newEmail, 'Name' => $user->getName(), 'Resubscribe' => true));
         if (!empty($customFields)) {
             $result['CustomFields'] = $customFields;
         }
         if (!$result->was_successful()) {
             $this->debugLog("Cannot update email user {$oldEmail}/{$newEmail} by reason: {$result->http_status_code}");
         }
     }
 }
 public function payoutAction()
 {
     $query = new Am_Query($this->getDi()->affPayoutDetailTable);
     $query->leftJoin('?_aff_payout', 'p', 'p.payout_id=t.payout_id');
     $query->addField('p.*')->addWhere('aff_id=?', $this->user->pk());
     $this->view->payouts = $query->selectAllRecords();
     $this->view->display('aff/payout.phtml');
 }
 function match(Invoice $invoice, InvoiceItem $item, User $aff, $paymentNumber = 0, $tier = 0, $paymentDate = 'now')
 {
     switch ($this->type) {
         case self::TYPE_GLOBAL_1:
             return $tier == 0;
         case self::TYPE_GLOBAL_2:
             return $tier == 1;
     }
     if ($tier != 0) {
         return false;
     }
     // no custom rules for 2-tier
     // check conditions
     foreach ($this->getConditions() as $conditionType => $vars) {
         switch ($conditionType) {
             case self::COND_AFF_SALES_COUNT:
             case self::COND_AFF_SALES_AMOUNT:
                 if (empty($vars['count']) || empty($vars['days'])) {
                     return false;
                 }
                 $e = sqlDate($paymentDate);
                 $b = sqlDate($e . '-' . $vars['days'] . ' days');
                 $stats = $this->getDi()->affCommissionTable->getAffStats($aff->pk(), $b, $e);
                 $key = $conditionType == self::COND_AFF_SALES_AMOUNT ? 'amount' : 'count';
                 if ($stats[$key] < $vars['count']) {
                     return false;
                 }
                 break;
             case self::COND_AFF_GROUP_ID:
                 if (!array_intersect($aff->getGroups(), (array) $vars)) {
                     return false;
                 }
                 break;
             case self::COND_PRODUCT_ID:
                 if ($item->item_type != 'product' || !in_array($item->item_id, (array) $vars)) {
                     return false;
                 }
                 break;
             case self::COND_PRODUCT_CATEGORY_ID:
                 if ($item->item_type != 'product') {
                     return false;
                 }
                 $pr = $item->tryLoadProduct();
                 if (!$pr) {
                     return false;
                 }
                 if (!array_intersect($pr->getCategories(), (array) $vars)) {
                     return false;
                 }
                 break;
             default:
                 return false;
         }
     }
     return true;
 }
Example #6
0
 protected function getCurrentListsId(User $user)
 {
     $list_ids = $this->getDi()->newsletterUserSubscriptionTable->getSubscribedIds($user->pk());
     $lists = array();
     foreach ($this->getDi()->newsletterListTable->loadIds($list_ids) as $list) {
         if ($list->plugin_id != $this->getId()) {
             continue;
         }
         $lists[] = $list->plugin_list_id;
     }
     return $lists;
 }
Example #7
0
 function changeEmail(User $user, $oldEmail, $newEmail)
 {
     $lists = $this->getDi()->newsletterUserSubscriptionTable->getSubscribedIds($user->pk());
     $campaigns = array();
     foreach ($lists as $v) {
         $list = $this->getDi()->newsletterListTable->load($v);
         $campaigns[] = $list->plugin_list_id;
     }
     $user->email = $oldEmail;
     $this->changeSubscription($user, array(), $campaigns);
     $user->email = $newEmail;
     $this->changeSubscription($user, $campaigns, array());
 }
Example #8
0
 public function onIpCountExceeded(User $user)
 {
     if ($user->is_locked < 0) {
         return;
     }
     // auto-lock disabled
     if ($this->getDi()->store->get('on-ip-count-exceeded-' . $user->pk())) {
         return;
     }
     //action already done
     $this->getDi()->store->set('on-ip-count-exceeded-' . $user->pk(), 1, '+20 minutes');
     if (in_array('email-admin', $this->getDi()->config->get('max_ip_actions', array()))) {
         $et = Am_Mail_Template::load('max_ip_actions_admin');
         if (!$et) {
             throw new Am_Exception_Configuration("No e-mail template found for [max_ip_actions_admin]");
         }
         $et->setMaxipcount($this->getDi()->config->get('max_ip_count', 0))->setMaxipperiod($this->getDi()->config->get('max_ip_period', 0))->setUser($user);
         if (in_array('disable-user', $this->getDi()->config->get('max_ip_actions', array()))) {
             $et->setUserlocked(___('Customer account has been automatically locked.'));
         }
         $et->sendAdmin();
     }
     if (in_array('email-user', $this->getDi()->config->get('max_ip_actions', array()))) {
         $et = Am_Mail_Template::load('max_ip_actions_user');
         if (!$et) {
             throw new Am_Exception_Configuration("No e-mail template found for [max_ip_actions_user]");
         }
         $et->setMaxipcount($this->getDi()->config->get('max_ip_count', 0))->setMaxipperiod($this->getDi()->config->get('max_ip_period', 0))->setUser($user);
         if (in_array('disable-user', $this->getDi()->config->get('max_ip_actions', array()))) {
             $et->setUserlocked(___('Your account has been automatically locked.'));
         }
         $et->send($user->email);
     }
     if (in_array('disable-user', $this->getDi()->config->get('max_ip_actions', array()))) {
         // disable customer
         $user->lock();
     }
 }
Example #9
0
 function am3goAction()
 {
     $this->aff = $this->findAm3Aff();
     $event = new Am_Event(Am_Event::GET_AFF_REDIRECT_LINK, array('aff' => $this->aff));
     $event->setReturn($this->findAm3Url());
     $this->getDi()->hook->call($event);
     $this->link = $event->getReturn();
     /// log click
     if ($this->aff) {
         $aff_click_id = $this->getDi()->affClickTable->log($this->aff, $this->banner, null, $this->getModule()->findKeywordId($this->aff->pk()));
         $this->getModule()->setCookie($this->aff, $this->banner ? $this->banner : null, $aff_click_id);
     }
     $this->_redirect($this->link ? $this->link : '/', array('prependBase' => false));
 }
Example #10
0
 public function changeEmail(User $user, $oldEmail, $newEmail)
 {
     $ef = $this->getConfig('email_field', 'email');
     $list_ids = $this->getDi()->newsletterUserSubscriptionTable->getSubscribedIds($user->pk());
     $lists = array();
     foreach ($this->getDi()->newsletterListTable->loadIds($list_ids) as $list) {
         if ($list->plugin_id != $this->getId()) {
             continue;
         }
         $lists[] = $list->plugin_list_id;
     }
     $user->set($ef, $oldEmail)->toggleFrozen(true);
     $this->changeSubscription($user, array(), $lists);
     // subscribe again
     $user->set($ef, $newEmail)->toggleFrozen(false);
     $this->changeSubscription($user, $lists, array());
 }
 function checkSubscriptions(User $user)
 {
     if (!empty($user->unsubscribed)) {
         $this->_db->query("UPDATE {$this->_table} SET is_active = 0 WHERE user_id=?d", $user->pk());
         return;
     }
     // array of NewsletterList user has access at all
     $ids = array();
     foreach ($this->getDi()->newsletterListTable->getAllowed($user) as $list) {
         $ids[$list->pk()] = array('l' => $list);
     }
     foreach ($this->findByUserId($user->pk()) as $r) {
         $ids[$r->list_id]['s'] = $r;
     }
     ////
     foreach ($ids as $list_id => $record) {
         /* @var $availableList NewsletterList */
         $availableList = @$record['l'];
         /* @var $existingSub NewsletterUserSubscription */
         $existingSub = @$record['s'];
         if ($existingSub) {
             if (!$availableList) {
                 // if not available now, de-activate
                 $existingSub->disable();
                 continue;
             } elseif ($existingSub->isUnsubscribed()) {
                 // if user unsubscribed previously, make sure it disabled
                 $existingSub->disable();
                 continue;
             } else {
                 // status = user or status = auto
                 // if user was subscribed before, enable it
                 $r->enable();
             }
         } elseif ($user->data()->get(Bootstrap_Newsletter::NEWSLETTER_SIGNUP_DATA) == 1) {
             $this->add($user->pk(), $availableList->pk(), NewsletterUserSubscription::TYPE_USER);
         } elseif (($data = $user->data()->get(Bootstrap_Newsletter::NEWSLETTER_SIGNUP_DATA)) && !empty($data[$availableList->pk()])) {
             $this->add($user->pk(), $availableList->pk(), NewsletterUserSubscription::TYPE_USER);
         } elseif ($availableList && $availableList->auto_subscribe) {
             // no existing list - create if 'auto'
             $this->add($user->pk(), $availableList->pk(), NewsletterUserSubscription::TYPE_AUTO);
         }
     }
 }
    public function doChangePass(User $user, $code)
    {
        $form = $this->createForm();
        $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array(self::SECURITY_VAR => $code, 'login' => $user->login)));
        if ($form->isSubmitted() && $form->validate()) {
            $user->setPass($this->getParam('pass0'));
            $user->save();
            // Password has been reset. Delete all other sessions besides of current one. (Logout other' users)
            $this->getDi()->db->query('DELETE FROM ?_session where user_id=? and id<>?', $user->pk(), session_id());
            $this->getDi()->store->delete(self::STORE_PREFIX . $code);
            $msg = ___('Your password has been changed successfully. ' . 'You can %slogin to your account%s with new password.', sprintf('<a href="%s">', $this->escape(REL_ROOT_URL . '/login')), '</a>');
            $this->view->title = ___('Change Password');
            $this->view->content = <<<CUT
   <div class="am-info">{$msg}</div>
CUT;
            $this->view->display('layout.phtml');
        } else {
            $this->view->form = $form;
            $this->view->display('changepass.phtml');
        }
    }
Example #13
0
 function calculateJaclGroups(User $user)
 {
     $levels = array();
     if ($user && $user->pk()) {
         foreach ($this->getIntegrationTable()->getAllowedResources($user, $this->getId()) as $integration) {
             $vars = unserialize($integration->vars);
             $levels[] = $vars['jacl_groups'];
         }
     }
     return array_filter(array_unique($levels));
 }
Example #14
0
 function calculateNetworkGroups(User $user = null)
 {
     $groups = array();
     if ($user && $user->pk()) {
         foreach ($this->getIntegrationTable()->getAllowedResources($user, $this->getNetworkPlugin()->getId()) as $integration) {
             $vars = unserialize($integration->vars);
             if ($vars['gr']) {
                 $groups[@$vars['blog_id']][] = $vars['gr'];
             }
         }
     }
     return $groups;
 }
    function init()
    {
        /* General Settings */
        $fieldSet = $this->addElement('fieldset', 'general', array('id' => 'general', 'label' => ___('General')));
        $loginGroup = $fieldSet->addGroup('', array('id' => 'login'))->setLabel(___('Username'));
        $login = $loginGroup->addElement('text', 'login', array('size' => 20));
        $login->addRule('required');
        $loginGroup->addRule('callback2', '-error-', array($this, 'checkUniqLogin'));
        $comment = $fieldSet->addTextarea("comment", array('style' => "width:90%", 'id' => 'comment'), array('label' => ___('Comment')));
        if ($this->record && $this->record->pk()) {
            $url = Am_Controller::escape(Am_Controller::makeUrl('admin-users', 'login-as', null, array('id' => $this->record->pk())));
            $loginGroup->addStatic('_login_as')->setContent("&nbsp;<a href='{$url}' target='_blank'>" . ___("login as user") . "</a>");
        }
        $pass = $fieldSet->addElement('password', '_pass', array('size' => 20, 'autocomplete' => 'off'))->setLabel(___('New Password'));
        //$pass0 = $gr->addElement('password', '_pass0', array('size' => 20));
        //$pass0->addRule('eq', 'Password confirmation must be equal to Password', $pass);
        if ($this->getAttribute('_a_') == 'insert') {
            $pass->addRule('required');
        }
        $nameField = $fieldSet->addGroup('', array('id' => 'name'), array('label' => ___('Name')));
        $nameField->addElement('text', 'name_f', array('size' => 20));
        $nameField->addElement('text', 'name_l', array('size' => 20));
        $gr = $fieldSet->addGroup()->setLabel(___('E-Mail Address'));
        $gr->addElement('text', 'email', array('size' => 40))->addRule('required');
        $gr->addRule('callback2', '-error-', array($this, 'checkUniqEmail'));
        $fieldSet->addElement('text', 'phone', array('size' => 20))->setLabel(___('Phone Number'));
        if ($this->record && $this->record->isLoaded()) {
            $resendText = Am_Controller::escape(___("Resend Signup E-Mail"));
            $sending = Am_Controller::escape(___('sending'));
            $sent = Am_Controller::escape(___('sent successfully'));
            $id = $this->record->pk();
            $gr->addElement('static')->setContent(<<<CUT
<input type='button' value='{$resendText}' id='resend-signup-email' />
<script type='text/javascript'>
\$(function(){
\$("#resend-signup-email").click(function(){
    var btn = this;
    var txt = btn.value;
    btn.value += '...({$sending})...';
    \$.post(window.rootUrl + '/admin-users/resend-signup-email', {id: {$id}}, function(){
        btn.value = txt + '...({$sent})';
        setTimeout(function(){ btn.value = txt; }, 600);
    });
});
});
</script>
CUT
);
        }
        $isLocked = $fieldSet->addElement('advradio', 'is_locked', array('id' => 'is_locked'))->loadOptions(array('' => 'No', '1' => '<font color=red><b>' . ___("Yes, locked") . '</b></font>', '-1' => '<i>' . ___("Disable auto-locking for this customer") . '</i>'))->setLabel(___('Is Locked'));
        if (Am_Di::getInstance()->config->get('manually_approve')) {
            $fieldSet->addElement('advcheckbox', 'is_approved', array('id' => 'is_approved'))->setLabel(___('Is Approved'));
        }
        $fieldSet->addElement('advradio', 'unsubscribed', array('id' => 'unsubscribed'))->setLabel(___("Is Unsubscribed?\nif enabled, this will\nunsubscribe the customer from:\n* messages that you send from aMember Cp, \n* autoresponder messages,\n* subscription expiration notices"))->loadOptions(array('' => ___('No'), '1' => ___('Yes, do not e-mail this customer for any reasons')));
        if ($this->record->isLoaded()) {
            $fieldSet->addStatic('_signup_info', null, array('label' => ___('Signup Info')))->setContent(sprintf("<div>%s</div>", $this->record->added . ' / ' . $this->record->remote_addr));
        }
        if (Am_Di::getInstance()->config->get('use_user_groups')) {
            $group = $this->addGroup('', array('id' => 'user_groups'))->setLabel(___('User Groups'));
            $groups = $group->addSelect('_groups', array('multiple' => 'multiple', 'class' => 'magicselect'));
            $groups->loadOptions(Am_Di::getInstance()->userGroupTable->getSelectOptions());
            $group->addHtml()->setHtml(sprintf('<a href="%s" target="_blank">%s<a/>', Am_Controller::escape(REL_ROOT_URL . '/admin-user-groups'), ___("Edit Groups")));
        }
        /* Address Info */
        $this->insertAddressFields();
        $this->insertAdditionalFields();
        $event = new Am_Event_UserForm(Am_Event_UserForm::INIT, $this, $this->record, array());
        $event->run();
    }
Example #16
0
 function calculateLevels(User $user = null, $addDefault = false)
 {
     throw new Am_Exception('Deprecated!');
     // we have got no user so search does not make sense, return default group if configured
     $levels = array();
     if ($user && $user->pk()) {
         foreach ($this->getIntegrationTable()->getAllowedResources($user, $this->getId()) as $integration) {
             $vars = unserialize($integration->vars);
             $levels[] = $vars['level'];
         }
     }
     if (!$levels) {
         return $this->getConfig('default_wplevel', 0);
     } else {
         return max($levels);
     }
 }
Example #17
0
 /**
  * Calculate available limits, enable and disable users
  * @param User $user 
  */
 function checkAndUpdate(User $user)
 {
     $counts = $this->calculateCounts($user->pk());
     $this->workoutLimits($user->pk(), $counts);
     if (!count($counts)) {
         $counts = null;
     }
     $user->data()->set('subusers_count', $counts)->update();
 }
Example #18
0
 function getNotificationsByTargetProduct(User $user)
 {
     return $this->getDi()->db->selectCol("SELECT notification_id \n            FROM  ?_notification n\n            WHERE n.notification_id in (\n                SELECT DISTINCT r.notification_id \n                FROM ?_notification_access r \n                LEFT JOIN ?_access_cache c \n                ON \n                    c.user_id=? \n                    AND (((c.fn = r.fn) AND (c.id = r.id)) OR (r.fn='product_category_id' AND r.id=-1)) \n                    AND ((c.status='active' AND r.start_days IS NULL AND r.stop_days IS NULL) \n                         OR\n                         (c.status='active' AND c.days BETWEEN IFNULL(r.start_days,0) AND IFNULL(r.stop_days, 90000)) \n                         OR\n                         (c.days >= IFNULL(r.start_days,0) AND r.stop_days = -1)) \n                WHERE c.user_id IS NOT NULL)\n            AND  (n.begin IS NULL OR n.begin<=?) AND (n.expire IS NULL OR n.expire>=?) AND is_disabled=0\n           ", $user->pk(), sqlDate('now'), sqlDate('now'));
 }
Example #19
0
 protected function delGrs(User $user, $listId, $groupId)
 {
     $params = array("apiMailingListId" => $listId, "apiRecipientIds" => (array) $user->data()->get(self::USER_DATA_SWM_LISTS . $listId), "apiGroupIds" => (array) $groupId);
     $result = $this->getClient()->call('api_Recipients.api_removeRecipientsFromGroups', $params, '', '', false, true);
     $this->debugLog("removeRecipientsFromGroups - request: " . json_encode($params));
     if ($this->getClient()->fault) {
         $this->errorLog("removeRecipientsFromGroups - " . $result['faultstring']);
         return false;
     }
     $this->debugLog("User #{$user->pk()}/{$user->login} was deleted from group#{$groupId} at list #{$listId}");
 }
Example #20
0
 function setCookie(User $aff, $banner, $aff_click_id = null)
 {
     $tm = $this->getDi()->time + $this->getDi()->config->get('aff.cookie_lifetime', 30) * 3600 * 24;
     $val = $aff->pk();
     $val .= '-' . ($banner ? $banner->pk() : "0");
     if ($aff_click_id) {
         $val .= '-' . $this->encodeClickId($aff_click_id);
     }
     Am_Controller::setCookie(self::COOKIE_NAME, $val, $tm, '/', $_SERVER['HTTP_HOST']);
 }
Example #21
0
 function _valuesToForm(array &$values, User $record)
 {
     if ($record->isLoaded()) {
         $values['_groups'] = $this->getDi()->subusersSubscriptionTable->getForUser($record->pk());
     } else {
         $values['_groups'] = array();
     }
 }
 protected function merge(User $target, User $source)
 {
     //module should throw Exception in case of merge is not possible
     $event = new Am_Event(Am_Event::USER_BEFORE_MERGE, array('target' => $target, 'source' => $source));
     $this->getDi()->hook->call(Am_Event::USER_BEFORE_MERGE, $event);
     $this->getDi()->db->query('UPDATE ?_access SET user_id=? WHERE user_id=?', $target->pk(), $source->pk());
     $this->getDi()->db->query('UPDATE ?_access_log SET user_id=? WHERE user_id=?', $target->pk(), $source->pk());
     $this->getDi()->db->query('UPDATE ?_invoice SET user_id=? WHERE user_id=?', $target->pk(), $source->pk());
     $this->getDi()->db->query('UPDATE ?_invoice_log SET user_id=? WHERE user_id=?', $target->pk(), $source->pk());
     $this->getDi()->db->query('UPDATE ?_invoice_payment SET user_id=? WHERE user_id=?', $target->pk(), $source->pk());
     $this->getDi()->db->query('UPDATE ?_invoice_refund SET user_id=? WHERE user_id=?', $target->pk(), $source->pk());
     //        $this->getDi()->db->query('UPDATE ?_admin_log SET record_id=? WHERE record_id=?
     //            AND tablename=?',
     //            $target->pk(), $source->pk(), 'user');
     $this->getDi()->db->query('UPDATE ?_coupon_batch SET user_id=? WHERE user_id=?', $target->pk(), $source->pk());
     $this->getDi()->db->query('UPDATE ?_file_download SET user_id=? WHERE user_id=?', $target->pk(), $source->pk());
     $this->getDi()->db->query('UPDATE ?_upload SET user_id=? WHERE user_id=?', $target->pk(), $source->pk());
     $event = new Am_Event(Am_Event::USER_MERGE, array('target' => $target, 'source' => $source));
     $this->getDi()->hook->call(Am_Event::USER_MERGE, $event);
     $source->delete();
     $target->save();
     $target->checkSubscriptions(true);
 }
Example #23
0
 public function __construct(Am_Paysystem_Abstract $plugin, User $user, $token)
 {
     $this->plugin = $plugin;
     $this->user = $user;
     $this->request = new Am_HttpRequest(Am_Paysystem_Omise::API_ENDPOINT . 'customers', Am_HttpRequest::METHOD_POST);
     $this->request->addPostParameter(array('email' => $user->email, 'description' => sprintf('%s (#%d)', $user->getName(), $user->pk()), 'card' => $token));
     $this->request->setAuth($this->getPlugin()->getConfig('skey'));
 }
Example #24
0
 /**
  * Return plugin groups that must be set according to 
  * aMember user subscriptions and aMember configuration
  * @param User $user if null, defaul group returned
  * @return array of int third-party group ids, or int for single-group, or true/false for GROUP_NONE
  */
 function calculateGroups(User $user = null, $addDefault = false)
 {
     // we have got no user so search does not make sense, return default group if configured
     $groups = array();
     if ($user && $user->pk()) {
         foreach ($this->getIntegrationTable()->getAllowedResources($user, $this->getId()) as $integration) {
             $vars = unserialize($integration->vars);
             $groups[] = $vars;
         }
         if ($this->groupMode == self::GROUP_NONE) {
             return (bool) $groups;
         }
     } else {
         if ($this->groupMode == self::GROUP_NONE) {
             return false;
         }
     }
     $groups = $this->chooseGroups($groups, $user);
     if ($addDefault && !$groups) {
         $ret = $this->getConfig('default_group', null);
         if ($this->groupMode == self::GROUP_MULTI && !is_array($ret)) {
             $ret = array($ret);
         }
         return $ret;
     } else {
         return $groups;
     }
 }
 function userHasAccess(User $user, $id, $type)
 {
     $q = $this->_getBaseQuery("c.user_id=" . intval($user->pk()));
     $q->addWhere("resource_type=?", $type);
     $q->addWhere("resource_id=?", $id);
     return (bool) $q->selectPageRecords(0, 1);
 }
 function match(Invoice $invoice, InvoiceItem $item, User $aff, $paymentNumber = 0, $tier = 0, $paymentDate = 'now')
 {
     if ($this->type == self::TYPE_GLOBAL) {
         return $tier == $this->tier;
     }
     if ($tier != 0) {
         return false;
     }
     // no custom rules for 2-tier
     // check conditions
     foreach ($this->getConditions() as $conditionType => $vars) {
         switch ($conditionType) {
             case self::COND_AFF_SALES_COUNT:
             case self::COND_AFF_ITEMS_COUNT:
             case self::COND_AFF_SALES_AMOUNT:
                 if (empty($vars['count']) || empty($vars['days'])) {
                     return false;
                 }
                 $e = sqlDate($paymentDate);
                 $b = sqlDate($e . '-' . $vars['days'] . ' days');
                 $stats = $this->getDi()->affCommissionTable->getAffStats($aff->pk(), $b, $e);
                 switch ($conditionType) {
                     case self::COND_AFF_ITEMS_COUNT:
                         $key = 'items_count';
                         break;
                     case self::COND_AFF_SALES_COUNT:
                         $key = 'count';
                         break;
                     default:
                         $key = 'amount';
                 }
                 if ($stats[$key] < $vars['count']) {
                     return false;
                 }
                 break;
             case self::COND_AFF_GROUP_ID:
                 if (!array_intersect($aff->getGroups(), (array) $vars)) {
                     return false;
                 }
                 break;
             case self::COND_PRODUCT_ID:
                 if ($item->item_type != 'product' || !in_array($item->item_id, (array) $vars)) {
                     return false;
                 }
                 break;
             case self::COND_PRODUCT_CATEGORY_ID:
                 if ($item->item_type != 'product') {
                     return false;
                 }
                 $pr = $item->tryLoadProduct();
                 if (!$pr) {
                     return false;
                 }
                 if (!array_intersect($pr->getCategories(), (array) $vars)) {
                     return false;
                 }
                 break;
             case self::COND_COUPON:
                 $coupon = $invoice->getCoupon();
                 switch ($vars['type']) {
                     case 'any':
                         $coupon_cond_match = (bool) $coupon;
                         break;
                     case 'coupon':
                         $coupon_cond_match = $coupon && $vars['code'] == $coupon->code;
                         break;
                     case 'batch':
                         $coupon_cond_match = $coupon && $vars['batch_id'] == $coupon->batch_id;
                         break;
                 }
                 if ($vars['used'] ? !$coupon_cond_match : $coupon_cond_match) {
                     return false;
                 }
                 break;
             case self::COND_PAYSYS_ID:
                 if (!in_array($invoice->paysys_id, (array) $vars)) {
                     return false;
                 }
                 break;
             default:
                 return false;
         }
     }
     return true;
 }
 protected function createCcRecord(User $user)
 {
     $cc = $this->getDi()->ccRecordTable->createRecord();
     $cc->user_id = $user->pk();
     $cc->cc_number = rand(0, 100) > 20 ? '4111111111111111' : '4111111111119999';
     $cc->cc_expire = date('my', time() + 3600 * 24 * 366);
     $cc->cc_name_f = $user->name_f;
     $cc->cc_name_l = $user->name_l;
     $cc->cc_country = $user->country;
     $cc->cc_street = $user->street;
     $cc->cc_city = $user->city;
     $cc->cc_state = $user->state;
     $cc->cc_zip = $user->zip;
     return $cc;
 }
Example #28
0
 function log(User $aff, AffBanner $banner = null, $referrer = null, $keyword_id = null)
 {
     $this->_db->query("INSERT INTO ?_aff_click\n            SET\n                aff_id=?d,\n                time=?,\n                banner_id=?d,\n                remote_addr=?,\n                referer=?,\n                keyword_id = ?\n            ", $aff->pk(), $this->getDi()->sqlDateTime, $banner ? $banner->pk() : null, $_SERVER['REMOTE_ADDR'], $referrer ? $referrer : $_SERVER['HTTP_REFERER'], $keyword_id);
     return $this->_db->selectCell("SELECT LAST_INSERT_ID()");
 }
Example #29
0
 function getNotificationsForUser(User $user)
 {
     $product_ids = $user->getActiveProductIds();
     array_push($product_ids, '-1');
     //to avoide SQL error
     $category_ids = array();
     array_push($category_ids, '-1');
     //to avoide SQL error
     $category_product = $this->getDi()->productCategoryTable->getCategoryProducts();
     foreach ($category_product as $category_id => $list) {
         if (array_intersect($product_ids, $list)) {
             array_push($category_ids, $category_id);
         }
     }
     $user_group_ids = $user->getGroups();
     array_push($user_group_ids, '-1');
     //to avoide SQL error
     return $this->selectObjects("SELECT * FROM ?_notification WHERE\n            notification_id IN (\n                SELECT notification_id FROM ?_notification_access WHERE\n                    ((fn=? AND id =  ?) OR\n                    (fn=? AND id IN (?a)) OR\n                    (fn=? AND id IN (?a)) OR\n                    (fn=?)) OR\n                    (fn=? AND id IN (?a))\n            )\n            AND\n                (begin IS NULL OR begin<=?) AND\n                (expire IS NULL OR expire>=?) AND\n                is_disabled=0\n            ORDER BY sort_order", 'user_id', $user->pk(), 'product_id', $product_ids, 'product_category_id', $category_ids, 'free', 'user_group_id', $user_group_ids, sqlDate('now'), sqlDate('now'));
 }