function onAuthCheckUser(Am_Event $event)
 {
     /* @var $user User */
     $user = $event->getUser();
     $recs = $this->getDi()->loginSessionTable->findBy(array('user_id' => $user->pk(), 'session_id' => '<>' . Zend_Session::getId(), 'modified' => '>' . sqlTime(sprintf('-%d minutes', $this->getConfig('timeout', 5))), 'need_logout' => 0));
     if ($recs) {
         switch ($this->getConfig('action', self::ACTION_LOGIN_REJECT)) {
             case self::ACTION_LOGIN_REJECT:
                 $event->setReturn(new Am_Auth_Result(-100, $this->getConfig('error', 'There is already exits active login session for your account.
                         Simultaneous login from different computers is not allowed.')));
                 $event->stop();
                 break;
             case self::ACTION_LOGOUT_OTHER:
                 foreach ($recs as $rec) {
                     $rec->updateQuick('need_logout', 1);
                 }
                 break;
             case self::ACTION_NOTHING:
                 break;
         }
         if ($this->getConfig('notify_admin') && !$this->getDi()->store->get('single-login-session-detected-' . $user->pk())) {
             $this->getDi()->store->set('single-login-session-detected-' . $user->pk(), 1, '+20 minutes');
             if ($et = Am_Mail_Template::load('misc.single-login-session.notify_admin')) {
                 $et->setUser($user);
                 $et->sendAdmin();
             }
         }
     }
 }
Example #2
0
 public function onAdminWarnings(\Am_Event $event)
 {
     if (!$this->_api_loaded) {
         $event->setReturn(array(___('Facebook SDK was  not loaded. Got an error: %s', $this->_api_error)));
     } else {
         parent::onAdminWarnings($event);
     }
 }
Example #3
0
 /**
  * 
  * Set Invoice ID wich will be displayed in pdf invoice
  */
 protected function setDisplayInvoiceId()
 {
     $e = new Am_Event(Am_Event::SET_DISPLAY_INVOICE_REFUND_ID, array('record' => $this));
     $e->setReturn($this->getInvoice()->public_id . '/' . $this->receipt_id);
     $this->getDi()->hook->call($e);
     $this->display_invoice_id = $e->getReturn();
     $this->updateSelectedFields('display_invoice_id');
 }
Example #4
0
 function indexAction()
 {
     $this->form = new Am_Form_Profile();
     $this->form->addCsrf();
     if ($c = $this->getFiltered('c')) {
         $record = $this->getDi()->savedFormTable->findFirstBy(array('code' => $c, 'type' => SavedForm::T_PROFILE));
     } else {
         $record = $this->getDi()->savedFormTable->getDefault(SavedForm::D_PROFILE);
     }
     $event = new Am_Event(Am_Event::LOAD_PROFILE_FORM, array('request' => $this->_request, 'user' => $this->getDi()->auth->getUser()));
     $event->setReturn($record);
     $this->getDi()->hook->call($event);
     $record = $event->getReturn();
     if (!$record) {
         throw new Am_Exception_Configuration("No profile form configured");
     }
     if ($record->meta_title) {
         $this->view->meta_title = $record->meta_title;
     }
     if ($record->meta_keywords) {
         $this->view->headMeta()->setName('keywords', $record->meta_keywords);
     }
     if ($record->meta_description) {
         $this->view->headMeta()->setName('description', $record->meta_description);
     }
     $this->form->initFromSavedForm($record);
     $this->form->setUser($this->user);
     $u = $this->user->toArray();
     unset($u['pass']);
     $dataSources = array(new HTML_QuickForm2_DataSource_Array($u));
     if ($this->form->isSubmitted()) {
         array_unshift($dataSources, $this->_request);
     }
     $this->form->setDataSources($dataSources);
     if ($this->form->isSubmitted() && $this->form->validate()) {
         $oldUser = clone $this->user;
         $oldUser->toggleFrozen(true);
         $vars = $this->form->getValue();
         unset($vars['user_id']);
         if (!empty($vars['pass'])) {
             $this->user->setPass($vars['pass']);
         }
         unset($vars['pass']);
         $ve = $this->handleEmail($record, $vars) ? 1 : 0;
         $u = $this->user->setForUpdate($vars);
         $this->emailChangesToAdmin();
         $u->update();
         $this->getDi()->hook->call(Am_Event::PROFILE_USER_UPDATED, array('vars' => $vars, 'oldUser' => $oldUser, 'user' => $u, 'form' => $this->form));
         $this->getDi()->auth->setUser($u, '');
         $msg = $ve ? ___('Verification email has been sent to your address.
                 E-mail will be changed in your account after confirmation') : ___('Your profile has been updated successfully');
         return $this->redirectLocation($this->getFullUrl() . '?a=saved&_msg=' . urlencode($msg));
     }
     $this->view->title = $record->title;
     $this->view->form = $this->form;
     $this->view->display('member/profile.phtml');
 }
Example #5
0
 function onLoadProfileForm(Am_Event $event)
 {
     if (!$this->getDi()->config->get('subusers_different_profile_form')) {
         return;
     }
     /* @var $user User */
     $user = $event->getUser();
     if ($user->subusers_parent_id && !$event->getRequest()->getParam('c')) {
         $event->setReturn($this->getDi()->savedFormTable->findFirstByType(self::SAVED_FORM_TYPE));
     }
 }
Example #6
0
 static function getAvailableOptions()
 {
     $ret = array();
     foreach (get_declared_classes() as $className) {
         if (strpos($className, __CLASS__ . '_') === 0) {
             $o = new $className();
             $ret[$o->getId()] = $o->getTitle();
         }
     }
     $event = new Am_Event(Bootstrap_Aff::AFF_GET_PAYOUT_OPTIONS);
     $event->setReturn($ret);
     Am_Di::getInstance()->hook->call($event);
     return $event->getReturn();
 }
Example #7
0
 function loadForm()
 {
     if ($c = $this->getFiltered('c')) {
         if ($c == 'cart') {
             if ($this->_request->getParam('amember_redirect_url')) {
                 $this->getSession()->redirectUrl = $this->_request->getParam('amember_redirect_url');
             }
             if ($this->getDi()->auth->getUser() != null) {
                 $url = $this->getSession()->redirectUrl;
                 $this->getSession()->redirectUrl = '';
                 $this->_redirect('cart/' . urldecode($url));
             } else {
                 $this->record = $this->getDi()->savedFormTable->getByType(SavedForm::T_CART);
             }
         } else {
             $this->record = $this->getDi()->savedFormTable->findFirstBy(array('code' => $c, 'type' => SavedForm::T_SIGNUP));
         }
     } else {
         $this->record = $this->getDi()->savedFormTable->getDefault($this->getDi()->auth->getUserId() ? SavedForm::D_MEMBER : SavedForm::D_SIGNUP);
     }
     // call a hook to allow load another form
     $event = new Am_Event(Am_Event::LOAD_SIGNUP_FORM, array('request' => $this->_request, 'user' => $this->getDi()->auth->getUser()));
     $event->setReturn($this->record);
     $this->getDi()->hook->call($event);
     $this->record = $event->getReturn();
     if (!$this->record) {
         $this->getDi()->errorLogTable->log("Wrong signup form code - the form does not exists. Redirect Customer to default form. Referrer: " . $this->getRequest()->getHeader('REFERER'));
         $this->redirect('/signup', array('code' => 302));
     }
     /* @var $this->record SavedForm */
     if (!$this->record->isSignup()) {
         throw new Am_Exception_InputError("Wrong signup form loaded [{$this->record}->saved_form_id] - it is not a signup form!");
     }
     if ($this->record->meta_title) {
         $this->view->meta_title = $this->record->meta_title;
     }
     if ($this->record->meta_keywords) {
         $this->view->headMeta()->setName('keywords', $this->record->meta_keywords);
     }
     if ($this->record->meta_description) {
         $this->view->headMeta()->setName('description', $this->record->meta_description);
     }
     $this->view->code = $this->record->code;
 }
Example #8
0
 /**
  * Return array - key => value of available options for template with given $id
  * @param type $id
  * @return array
  */
 public function getTagsOptions($id)
 {
     $record = @$this[$id];
     $ret = array('%site_title%' => 'Site Title', '%root_url%' => 'aMember Root URL', '%admin_email%' => 'Admin E-Mail Address');
     if (!$record || empty($record['vars'])) {
         return $ret;
     }
     foreach ($record['vars'] as $k => $v) {
         if (is_int($k)) {
             // tag set
             $ret = array_merge($ret, $this->tagSets[$v]);
         } else {
             // single variable
             $ret['%' . $k . '%'] = $v;
         }
     }
     $event = new Am_Event(Am_Event::EMAIL_TEMPLATE_TAG_OPTIONS, array('templateName' => $id));
     $event->setReturn($ret);
     Am_Di::getInstance()->hook->call($event);
     $ret = $event->getReturn();
     return $ret;
 }
Example #9
0
 public function getOkUrl()
 {
     $event = new Am_Event(Am_Event::AUTH_GET_OK_REDIRECT, array('user' => $this->getDi()->user));
     $event->setReturn($this->getConfiguredRedirect());
     $this->getDi()->hook->call($event);
     return get_first($this->redirect_url, $event->getReturn());
 }
Example #10
0
 /** @return array of Am_Form_Brick */
 function getBricks()
 {
     $ret = array();
     foreach ($this->getFields() as $brickConfig) {
         if (strpos($brickConfig['id'], 'PageSeparator') === 0) {
             continue;
         }
         $b = Am_Form_Brick::createFromRecord($brickConfig);
         if (!$b) {
             continue;
         }
         $ret[] = $b;
     }
     $event = new Am_Event(Am_Event::SAVED_FORM_GET_BRICKS, array('type' => $this->type, 'code' => $this->code, 'savedForm' => $this));
     $event->setReturn($ret);
     $this->getDi()->hook->call($event);
     $ret = $event->getReturn();
     foreach ($ret as $brick) {
         $brick->init();
     }
     return $ret;
 }
Example #11
0
 public function getPaysystems()
 {
     $psList = Am_Di::getInstance()->paysystemList->getAllPublic();
     $_psList = array();
     foreach ($psList as $k => $ps) {
         $_psList[$ps->getId()] = $ps;
     }
     $psEnabled = $this->getConfig('paysystems', array_keys($_psList));
     $event = new Am_Event(Am_Event::SIGNUP_FORM_GET_PAYSYSTEMS);
     $event->setReturn($psEnabled);
     Am_Di::getInstance()->hook->call($event);
     $psEnabled = $event->getReturn();
     //we want same order of paysystems as in $psEnabled
     $ret = array();
     foreach ($psEnabled as $psId) {
         if (isset($_psList[$psId])) {
             $ret[] = $_psList[$psId];
         }
     }
     return $ret;
 }
Example #12
0
 /**  run additional checks on authenticated user */
 public function checkUser($user, $ip)
 {
     /* @var $user User */
     if (!$user->isLocked()) {
         // now log access and check for account sharing
         $accessLog = $this->getDi()->accessLogTable;
         $accessLog->logOnce($user->user_id, $ip);
         if ($user->is_locked >= 0 && $accessLog->isIpCountExceeded($user->user_id, $ip)) {
             $this->onIpCountExceeded($user);
             $this->setUser(null, $ip);
             return new Am_Auth_Result(Am_Auth_Result::LOCKED);
         }
     } else {
         // if locked
         $this->setUser(null, $ip);
         return new Am_Auth_Result(Am_Auth_Result::LOCKED);
     }
     if (!$user->isApproved()) {
         return new Am_Auth_Result(Am_Auth_Result::NOT_APPROVED);
     }
     $event = new Am_Event(Am_Event::AUTH_CHECK_USER, array('user' => $user));
     $event->setReturn(null);
     $this->getDi()->hook->call($event);
     return $event->getReturn();
 }
Example #13
0
 /**
  * @return array of instantiated Am_Billing_Calc_* objects
  */
 function getCalculators()
 {
     $ret = array(new Am_Billing_Calc_Zero(), new Am_Billing_Calc_Coupon(), new Am_Billing_Calc_Tax(), new Am_Billing_Calc_Shipping(), new Am_Billing_Calc_Total());
     $event = new Am_Event(Am_Event::INVOICE_GET_CALCULATORS);
     $event->setReturn($ret);
     $this->getDi()->hook->call($event);
     return $event->getReturn();
 }
Example #14
0
 public function onEmailTemplateTagSets(Am_Event $event)
 {
     $tagSets = $event->getReturn();
     $tagSets['user']['%user.aff_link%'] = ___('User Affiliate Link');
     $tagSets['affiliate'] = array('%affiliate.name_f%' => 'Affiliate First Name', '%affiliate.name_l%' => 'Affiliate Last Name', '%affiliate.login%' => 'Affiliate Username', '%affiliate.email%' => 'Affiliate E-Mail', '%affiliate.user_id%' => 'Affiliate Internal ID#', '%affiliate.street%' => 'Affiliate Street', '%affiliate.street2%' => 'Affiliate Street (Second Line)', '%affiliate.city%' => 'Affiliate City', '%affiliate.state%' => 'Affiliate State', '%affiliate.zip%' => 'Affiliate ZIP', '%affiliate.country%' => 'Affiliate Country');
     foreach ($this->getDi()->userTable->customFields()->getAll() as $field) {
         if (@$field->sql && @$field->from_config) {
             $tagSets['affiliate']['%affiliate.' . $field->name . '%'] = 'Affiliate ' . $field->title;
         }
     }
     $tagSets['affiliate']['%affiliate.aff_link%'] = ___('Affiliate Affiliate Link');
     $event->setReturn($tagSets);
 }
 /**
  * Process invoice and insert necessary commissions for it
  *
  * External code should guarantee that this method with $payment = null will be called
  * only once for each user for First user invoice
  */
 public function processPayment(Invoice $invoice, InvoicePayment $payment = null)
 {
     $aff_id = $invoice->aff_id;
     /* @var $coupon Coupon */
     try {
         if (!$aff_id && ($coupon = $invoice->getCoupon())) {
             // try to find affiliate by coupon
             $aff_id = $coupon->aff_id ? $coupon->aff_id : $coupon->getBatch()->aff_id;
         }
     } catch (Am_Exception_Db_NotFound $e) {
         //coupon not found
     }
     if (empty($aff_id)) {
         $aff_id = $invoice->getUser()->aff_id;
     }
     if ($aff_id && empty($invoice->aff_id)) {
         // set aff_id to invoice for quick access next time
         $invoice->updateQuick('aff_id', $aff_id);
     }
     // run event to get plugins chance choose another affiliate
     $event = new Am_Event(Bootstrap_Aff::AFF_FIND_AFFILIATE, array('invoice' => $invoice, 'payment' => $payment));
     $event->setReturn($aff_id);
     $this->getDi()->hook->call($event);
     $aff_id = $event->getReturn();
     if (empty($aff_id)) {
         return;
     }
     // no affiliate id registered
     if ($aff_id == $invoice->getUser()->pk()) {
         return;
     }
     //strange situation
     // load affiliate and continue
     $aff = $this->getDi()->userTable->load($aff_id, false);
     if (!$aff || !$aff->is_affiliate) {
         return;
     }
     // affiliate not found
     $user = $invoice->getUser();
     if (!$user->aff_id) {
         $user->aff_id = $aff->pk();
         $user->aff_added = sqlTime('now');
         $user->data()->set('aff-source', 'invoice-' . $invoice->pk());
         $user->save();
     }
     // try to load other tier affiliate
     $aff_tier = $aff;
     $aff_tiers = array();
     $aff_tiers_exists = array($aff->pk());
     for ($tier = 1; $tier <= $this->getMaxTier(); $tier++) {
         if (!$aff_tier->aff_id || $aff_tier->pk() == $invoice->getUser()->pk()) {
             break;
         }
         $aff_tier = $this->getDi()->userTable->load($aff_tier->aff_id, false);
         if (!$aff_tier || !$aff_tier->is_affiliate || $aff_tier->pk() == $invoice->getUser()->pk() || in_array($aff_tier->pk(), $aff_tiers_exists)) {
             //already in chain
             break;
         }
         $aff_tiers[$tier] = $aff_tier;
         $aff_tiers_exists[] = $aff_tier->pk();
     }
     $isFirst = !$payment || $payment->isFirst();
     //to define price field
     $paymentNumber = is_null($payment) ? 0 : $invoice->getPaymentsCount();
     if (!$payment) {
         $tax = 0;
     } else {
         $tax = $this->getDi()->config->get('aff.commission_include_tax', false) ? 0 : doubleval($payment->tax);
     }
     $amount = $payment ? $payment->amount - $tax : 0;
     $date = $payment ? $payment->dattm : 'now';
     // now calculate commissions
     $items = is_null($payment) ? array_slice($invoice->getItems(), 0, 1) : $invoice->getItems();
     foreach ($items as $item) {
         //we do not calculate commission for free items in invoice
         $prefix = $isFirst ? 'first' : 'second';
         if (!is_null($payment) && !(double) $item->get("{$prefix}_total")) {
             continue;
         }
         $comm = $this->getDi()->affCommissionRecord;
         $comm->date = sqlDate($date);
         $comm->record_type = AffCommission::COMMISSION;
         $comm->invoice_id = $invoice->invoice_id;
         $comm->invoice_item_id = $item->invoice_item_id;
         $comm->invoice_payment_id = $payment ? $payment->pk() : null;
         $comm->receipt_id = $payment ? $payment->receipt_id : null;
         $comm->product_id = $item->item_id;
         $comm->is_first = $paymentNumber <= 1;
         $comm->_setPayment($payment);
         $comm->_setInvoice($invoice);
         $comm_tier = clone $comm;
         $rules = array();
         $topay_this = $topay = $this->calculate($invoice, $item, $aff, $paymentNumber, 0, $amount, $date, $rules);
         if ($topay > 0) {
             $comm->aff_id = $aff->pk();
             $comm->amount = $topay;
             $comm->tier = 0;
             $comm->_setAff($aff);
             $comm->insert();
             $comm->setCommissionRules(array_map(create_function('$el', 'return $el->pk();'), $rules));
         }
         foreach ($aff_tiers as $tier => $aff_tier) {
             $rules = array();
             $topay_this = $this->calculate($invoice, $item, $aff_tier, $paymentNumber, $tier, $topay_this, $date, $rules);
             if ($topay_this > 0) {
                 $comm_this = clone $comm_tier;
                 $comm_this->aff_id = $aff_tier->pk();
                 $comm_this->amount = $topay_this;
                 $comm_this->tier = $tier;
                 $comm_this->_setAff($aff_tier);
                 $comm_this->insert();
                 $comm_this->setCommissionRules(array_map(create_function('$el', 'return $el->pk();'), $rules));
             }
         }
     }
 }
Example #16
0
 /**
  * Expand types constant to list of resource types
  *
  * @param string|array|null|enum(ResourceAccess::USER_VISIBLE_TYPES, ResourceAccess::USER_VISIBLE_PAGES) $types
  * @return array|null
  * @see Am_Event::GET_RESOURCE_TYPES
  */
 protected function getResourceTypes($types)
 {
     if (is_null($types) || is_array($types) || !in_array($types, array(ResourceAccess::USER_VISIBLE_TYPES, ResourceAccess::USER_VISIBLE_PAGES))) {
         return $types;
     }
     if (isset($this->_types[$types])) {
         return $this->_types[$types];
     }
     $res = array();
     if ($types === ResourceAccess::USER_VISIBLE_TYPES) {
         $res = array(ResourceAccess::FOLDER, ResourceAccess::FILE, ResourceAccess::PAGE, ResourceAccess::LINK, ResourceAccess::VIDEO);
     } elseif ($types === ResourceAccess::USER_VISIBLE_PAGES) {
         $res = array(ResourceAccess::FOLDER, ResourceAccess::PAGE, ResourceAccess::LINK);
     }
     $event = new Am_Event(Am_Event::GET_RESOURCE_TYPES, array('type' => $types));
     $event->setReturn($res);
     $this->getDi()->hook->call($event);
     $res = $event->getReturn();
     $this->_types[$types] = $res;
     return $res;
 }
Example #17
0
File: Tax.php Project: grlf/eyedock
 function setSequentialNumber(Am_Event $e, $prefix, $default)
 {
     $numbers = $this->getDi()->store->getBlob('invoice_sequential_numbers');
     if (empty($numbers)) {
         $numbers = array();
     } else {
         $numbers = @unserialize($numbers);
     }
     if (empty($numbers[$prefix])) {
         $numbers[$prefix] = $default;
     } else {
         $numbers[$prefix]++;
     }
     $this->getDi()->store->setBlob('invoice_sequential_numbers', serialize($numbers));
     $e->setReturn($prefix . $numbers[$prefix]);
 }
Example #18
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 #19
0
 public function render()
 {
     $invoice = $this->invoice;
     $payment = $this->payment;
     $user = $invoice->getUser();
     $pdf = $this->createPdfTemplate();
     $event = new Am_Event(Am_Event::PDF_INVOICE_BEFORE_RENDER, array('amPdfInvoice' => $this, 'pdf' => $pdf, 'invoice' => $invoice, 'payment' => $payment, 'user' => $user));
     $event->setReturn(false);
     $this->getDi()->hook->call($event);
     // If event processing already rendered the Pdf.
     if ($event->getReturn() === true) {
         return $pdf->render();
     }
     $width_num = 30;
     $width_qty = 40;
     $width_price = 80;
     $width_total = 120;
     $padd = 20;
     $left = $padd;
     $right = $this->getPaperWidth() - $padd;
     $fontH = $this->getFontRegular();
     $fontHB = $this->getFontBold();
     $styleBold = array('font' => array('face' => $fontHB, 'size' => 10));
     $page = new Am_Pdf_Page_Decorator($pdf->pages[0]);
     $page->setFont($fontH, 10);
     $pointer = $this->getPointer();
     $pointerL = $pointerR = $pointer;
     $leftCol = new stdClass();
     $leftCol->invoiceNumber = ___('Corrective Invoice Number: ') . $payment->getDisplayInvoiceId();
     $leftCol->recInvoiceNumber = ___('Rectifies Invoice Number: ') . $this->getOrigPayment()->getDisplayInvoiceId();
     $leftCol->date = ___('Date: ') . amDate($payment->dattm);
     if ($user->tax_id) {
         $leftCol->taxId = ___('EU VAT ID: ') . $user->tax_id;
     }
     $this->getDi()->hook->call(Am_Event::PDF_INVOICE_COL_LEFT, array('col' => $leftCol, 'invoice' => $invoice, 'payment' => $payment, 'user' => $user));
     foreach ($leftCol as $line) {
         $page->drawText($line, $left, $pointerL);
         $page->nl($pointerL);
     }
     $rightCol = new stdClass();
     $rightCol->name = $invoice->getName();
     $rightCol->email = $invoice->getEmail();
     $rightCol->address = implode(', ', array_filter(array($invoice->getStreet(), $invoice->getCity())));
     $rightCol->country = implode(', ', array_filter(array($this->getState($invoice), $invoice->getZip(), $this->getCountry($invoice))));
     $this->getDi()->hook->call(Am_Event::PDF_INVOICE_COL_RIGHT, array('col' => $rightCol, 'invoice' => $invoice, 'payment' => $payment, 'user' => $user));
     foreach ($rightCol as $line) {
         $page->drawText($line, $right, $pointerR, 'UTF-8', Am_Pdf_Page_Decorator::ALIGN_RIGHT);
         $page->nl($pointerR);
     }
     $pointer = min($pointerR, $pointerL);
     $p = new stdClass();
     $p->value =& $pointer;
     $this->getDi()->hook->call(Am_Event::PDF_INVOICE_BEFORE_TABLE, array('page' => $page, 'pointer' => $p, 'invoice' => $invoice, 'payment' => $payment, 'user' => $user));
     $table = new Am_Pdf_Table();
     $table->setMargin($padd, $padd, $padd, $padd);
     $table->setStyleForRow(1, array('shape' => array('type' => Zend_Pdf_Page::SHAPE_DRAW_STROKE, 'color' => new Zend_Pdf_Color_Html("#cccccc")), 'font' => array('face' => $fontHB, 'size' => 10)));
     $table->setStyleForColumn(1, array('align' => 'right', 'width' => $width_num));
     $table->setStyleForColumn(3, array('align' => 'right', 'width' => $width_qty));
     $table->setStyleForColumn(4, array('align' => 'right', 'width' => $width_price));
     $table->setStyleForColumn(5, array('align' => 'right', 'width' => $width_total));
     $table->addRow(array(___('#'), ___('Subscription/Product Title'), ___('Qty'), ___('Unit Price'), ___('Total Price')));
     $num = 0;
     foreach ($invoice->getItems() as $p) {
         /* @var $p InvoiceItem */
         $table->addRow(array(++$num . '.', $p->item_title, $p->qty, $invoice->getCurrency($this->isFirstPayment() ? $p->first_price : $p->second_price), $invoice->getCurrency($this->isFirstPayment() ? $p->getFirstSubtotal() : $p->getSecondSubtotal())));
     }
     $pointer = $page->drawTable($table, 0, $pointer);
     $table = new Am_Pdf_Table();
     $table->setMargin($padd, $padd, $padd, $padd);
     $table->setStyleForColumn(2, array('align' => 'right', 'width' => $width_total));
     $subtotal = $this->isFirstPayment() ? $invoice->first_subtotal : $invoice->second_subtotal;
     $total = $this->isFirstPayment() ? $invoice->first_total : $invoice->second_total;
     if ($subtotal != $total) {
         $table->addRow(array(___('Subtotal'), $invoice->getCurrency($subtotal)))->addStyle($styleBold);
     }
     if ($this->isFirstPayment() && $invoice->first_discount > 0 || !$this->isFirstPayment() && $invoice->second_discount > 0) {
         $table->addRow(array(___('Coupon Discount'), $invoice->getCurrency($this->isFirstPayment() ? $invoice->first_discount : $invoice->second_discount)));
     }
     $table->addRow(array(___('Total'), $invoice->getCurrency($total)))->addStyle($styleBold);
     $table->addRow(array(___('Taxable Income'), "-" . $invoice->getCurrency($this->getOrigPayment()->amount - $this->getOrigPayment()->tax)))->addStyle($styleBold);
     if ($this->getOrigPayment()->tax > 0) {
         $table->addRow(array(___('Tax') . " " . $invoice->tax_rate . "%", "-" . $invoice->getCurrency($this->getOrigPayment()->tax)))->addStyle($styleBold);
     }
     $table->addRow(array(___('Amount Paid'), $invoice->getCurrency(sprintf("%.2f", $this->getOrigPayment()->amount - $this->payment->amount))))->addStyle(array('font' => array('face' => $fontHB, 'size' => 10)));
     $x = $this->getPaperWidth() - ($width_qty + $width_price + $width_total) - 2 * $padd;
     $pointer = $page->drawTable($table, $x, $pointer);
     $page->nl($pointer);
     $page->nl($pointer);
     if (!$this->getDi()->config->get('invoice_do_not_include_terms')) {
         $termsText = new Am_TermsText($invoice);
         $page->drawTextWithFixedWidth(___('Subscription Terms') . ': ' . $termsText, $left, $pointer, $this->getPaperWidth() - 2 * $padd);
         $page->nl($pointer);
     }
     $p = new stdClass();
     $p->value =& $pointer;
     $this->getDi()->hook->call(Am_Event::PDF_INVOICE_AFTER_TABLE, array('page' => $page, 'pointer' => $p, 'invoice' => $invoice, 'payment' => $payment, 'user' => $user));
     if (!$this->getDi()->config->get('invoice_custom_template') || !$this->getDi()->uploadTable->load($this->getDi()->config->get('invoice_custom_template'))) {
         if ($ifn = $this->getDi()->config->get('invoice_footer_note')) {
             $tmpl = new Am_SimpleTemplate();
             $tmpl->assignStdVars();
             $tmpl->assign('user', $user);
             $tmpl->assign('invoice', $invoice);
             $ifn = $tmpl->render($ifn);
             $page->nl($pointer);
             $page->drawTextWithFixedWidth($ifn, $left, $pointer, $this->getPaperWidth() - 2 * $padd);
         }
     }
     return $pdf->render();
 }
 public function initFilter(Am_Grid_ReadOnly $grid)
 {
     parent::initFilter($grid);
     $query = $grid->getDataSource();
     $query->setPrefix('_u_search');
     /* @var $query Am_Query_User */
     if ($id = $grid->getCompleteRequest()->getInt('_search_del')) {
         $query->deleteSaved($id);
         Am_Controller::redirectLocation(REL_ROOT_URL . '/admin-users');
         exit;
     } elseif ($id = $grid->getRequest()->getInt('search_load')) {
         $query->load($id);
     } elseif (is_string($this->vars['filter']) && $this->vars['filter']) {
         $cond = new Am_Query_User_Condition_Filter();
         $cond->setFromRequest(array('filter' => array('val' => $this->vars['filter'])));
         $event = new Am_Event(Am_Event::ADMIN_USERS_FILTER_INIT, array('query' => $query, 'filter' => $this->vars['filter']));
         $event->setReturn($cond);
         Am_Di::getInstance()->hook->call($event);
         $query->add($event->getReturn());
     } else {
         $query->setFromRequest($grid->getCompleteRequest());
     }
 }
Example #21
0
 function getStrongPasswordRegex()
 {
     $regexp = '/^(?=.*[0-9].*[0-9])(?=.*[-!@#$%^&*().,=+`~].*[-!@#$%^&*().,=+`~])(?=.*[A-Z].*[A-Z])/';
     $event = new Am_Event(Am_Event::GET_STRONG_PASSWORD_REGEX);
     $event->setReturn($regexp);
     $this->getDi()->hook->call($event);
     return $event->getReturn();
 }
Example #22
0
 function indexAction()
 {
     $products_cancel = array();
     $recurringInvoices = $this->getDi()->invoiceTable->selectObjects("SELECT * FROM ?_invoice i\n            WHERE  status=? AND user_id=?", Invoice::RECURRING_ACTIVE, $this->user_id);
     foreach ($recurringInvoices as $invoice) {
         $cancelUrl = null;
         try {
             $ps = $this->getDi()->plugins_payment->loadGet($invoice->paysys_id, false);
             if ($ps) {
                 $cancelUrl = $ps->getUserCancelUrl($invoice);
             }
         } catch (Exception $e) {
         }
         if ($cancelUrl) {
             /* @var $invoice Invoice */
             foreach ($invoice->getItems() as $item) {
                 if ($item->item_type == 'product') {
                     $products_cancel[$item->item_id] = $cancelUrl;
                 }
             }
         }
     }
     $products_upgrade = array();
     $activeInvoices = $this->getDi()->invoiceTable->selectObjects("SELECT * FROM ?_invoice i\n            WHERE  status IN (?a) AND user_id=?\n            ORDER BY tm_started DESC", array(Invoice::RECURRING_ACTIVE, Invoice::PAID, Invoice::RECURRING_CANCELLED), $this->user_id);
     foreach ($activeInvoices as $invoice) {
         foreach ($invoice->getItems() as $item) {
             if ($product = $item->tryLoadProduct()) {
                 if ($upgrades = $this->getDi()->productUpgradeTable->findUpgrades($invoice, $item)) {
                     $item->_upgrades = $upgrades;
                     $products_upgrade[$product->pk()] = $item;
                 }
             }
         }
     }
     $this->view->assign('member_products', $this->getDi()->user->getActiveProducts());
     $this->view->assign('member_future_products', $this->getDi()->user->getFutureProducts());
     $member_links = array(ROOT_URL . '/logout' => ___('Logout'), ROOT_URL . '/profile' => ___('Change Password/Edit Profile'));
     $event = new Am_Event(Am_Event::GET_MEMBER_LINKS, array('user' => $this->user));
     $event->setReturn($member_links);
     $this->view->assign('member_links', $this->getDi()->hook->call($event)->getReturn());
     $left_member_links = $this->getDi()->hook->call(Am_Event::GET_LEFT_MEMBER_LINKS, array('user' => $this->user))->getReturn();
     $this->view->assign('left_member_links', $left_member_links);
     $resources = $this->getDi()->resourceAccessTable->getAllowedResources($this->getDi()->user, ResourceAccess::USER_VISIBLE_TYPES);
     $this->view->assign('resources', $resources);
     foreach ($resources as $k => $r) {
         if (!$r->renderLink()) {
             unset($resources[$k]);
         }
     }
     if (!$resources && !$left_member_links) {
         $this->getDi()->blocks->remove('member-main-resources');
     }
     $this->view->assign('products_expire', $this->getDi()->user->getActiveProductsExpiration());
     $this->view->assign('products_rebill', $this->getDi()->user->getActiveProductsRebill());
     $this->view->assign('products_begin', $this->getDi()->user->getFutureProductsBeginning());
     $this->view->assign('products_cancel', $products_cancel);
     $this->view->assign('products_upgrade', $products_upgrade);
     $this->view->display('member/main.phtml');
 }