v7‰PNG  IHDR Ÿ f Õ†C1 sRGB ®Îé gAMA ± üa pHYs à ÃÇo¨d GIDATx^íÜL”÷ð÷Yçªö("Bh_ò«®¸¢§q5kÖ*:þ0A­ºšÖ¥]VkJ¢M»¶f¸±8\k2íll£1]q®ÙÔ‚ÆT db.xml000064400000001165152101606220005651 0ustar00
library/CustomUserAccount.php000064400000004250152101606220012343 0ustar00_amount = $amount; } function getProductId() { return $this->account_id; } function getType() { return 'custom-account'; } function getTitle() { return sprintf('(%s) %s', $this->number, $this->title); } function getDescription() { return $this->description; } function getFirstPrice() { return $this->_amount; } function getFirstPeriod() { return Am_Period::MAX_SQL_DATE; } function getRebillTimes() { return 0; } function getSecondPrice() { return null; } function getSecondPeriod() { return null; } function getCurrencyCode() { return (string) Am_Currency::getDefault(); } function getTaxGroup() { return 0; } function getIsTangible() { return false; } function getIsCountable() { return false; } function getQty() { return 1; } function getIsVariableQty() { return false; } function getBillingPlanId() { return null; } function getBillingPlanData() { return array(); } public function getOptions() { return $this->_options; } public function setOptions(array $options) { $this->_options = (array) $options; } function calculateStartDate($paymentDate, Invoice $invoice) { return $paymentDate; } function findItem(array $existingInvoiceItems) { return null; } function addQty($requestedQty, $itemQty) { return 1; } } class CustomUserAccountTable extends Am_Table { protected $_key = 'account_id'; protected $_table = '?_custom_user_account'; protected $_recordClass = 'CustomUserAccount'; function getOptions($user_id) { return $this->_db->selectCol("SELECT account_id as ARRAY_KEY, CONCAT('(', number, ') ', title) FROM ?_custom_user_account WHERE user_id=?", $user_id); } }library/Am/Report/Account.php000064400000007573152101606220012134 0ustar00title = ___('Transaction Report'); $this->setQuantity(new Am_Report_Quant_Exact(1)); } public function _initConfigForm(Am_Form $form) { parent::_initConfigForm($form); $form->addSelect('interval', null, array('options' => $this->getDi()->interval->getOptions())) ->setLabel(___('Period')) ->setValue(array(Am_Interval::PERIOD_TODAY)); } public function runQuery() { $vars = $this->form->getValue(); list($start, $stop) = $this->getDi()->interval->getStartStop($vars['interval']); $point_fld = self::POINT_FLD; $this->stmt = $this->getDi()->db->queryResultOnly( "SELECT dattm, amount, CONCAT(u.name_f, ' ', u.name_l) AS name, CONCAT(t.receipt_id, '/', t.invoice_public_id) AS transaction, GROUP_CONCAT(item_title SEPARATOR ', ') AS items, GROUP_CONCAT(DISTINCT cua.number SEPARATOR ', ') AS accounts, SUBSTR(details, LOCATE('', details) + 16, LOCATE('', details) - LOCATE('', details) - 16) AS CardholderName, invoice_payment_id AS $point_fld FROM ?_invoice_payment t LEFT JOIN ?_user u ON u.user_id=t.user_id LEFT JOIN ?_invoice_item ii ON t.invoice_id = ii.invoice_id LEFT JOIN ?_custom_user_account cua ON ii.item_type='custom-account' AND ii.item_id = cua.account_id LEFT JOIN ?_invoice_log il ON t.invoice_id = il.invoice_id WHERE dattm BETWEEN ? AND ? GROUP BY $point_fld", $start, $stop); } public function getLines() { return array( new Am_Report_Line('dattm', ___('Transaction Date'), null, 'amDatetime'), new Am_Report_Line('name', ___('Name on Account')), new Am_Report_Line('CardholderName', ___('Cardholder Name')), new Am_Report_Line('accounts', ___('Account Number')), new Am_Report_Line('transaction', ___('Transaction/Invoice #')), new Am_Report_Line('amount', ___('Transaction Amount'), null, array('Am_Currency', 'render')), new Am_Report_Line('items', ___('Invoice Items')), ); } public function getOutput(Am_Report_Result $result) { return array( new Am_Report_TableNoTotal($result) ); } public function getReport(Am_Report_Result $result = null) { return parent::getReport(new Am_Report_Result_NoPropagation); } } class Am_Report_Result_NoPropagation extends Am_Report_Result { protected function populatePoints($start, $values) { //nop } } class Am_Report_TableNoTotal extends Am_Report_Output { protected $title = "Table"; public function render() { $out = "
\n"; $out .= "\n"; $out .= "\n"; foreach ($this->result->getLines() as $line) $out .= "\n"; $out .= "\n"; $totals = array(); foreach ($this->result->getPoints() as $point) { if (!$point->hasValues()) continue; $out .= ""; $i = 0; foreach ($this->result->getLines() as $line) { $out .= sprintf("", Am_Controller::escape($line->formatValue($point->getValue($line->getKey())))); @$lines[$i] = $line; } $out .= "\n"; } $out .= "
" . Am_Controller::escape($line->getLabel()) . "
%s
\n"; $out .= "
"; return $out; } }library/SetupForms.php000064400000001257152101606220011030 0ustar00setTitle(___('Accounts')); } function initElements() { $this->addMagicSelect('custom-account.paysys_id') ->loadOptions($this->getOptions()) ->setLabel(___("Available Payment Systems\n" . "keep empty to use all public")); } function getOptions() { $options = array(); foreach (Am_Di::getInstance()->paysystemList->getAllPublic() as $ps) { $options[$ps->getId()] = $ps->getId(); } return $options; } }email-templates.xml000064400000001073152101606220010345 0ustar00 custom-account.balance_updated en text Account Updated [%account.number%] Dear %user.name_f% %user.name_l%, Your account %account.number% (%account.title%) has been updated by administrator. New balance of your account is %account.balance|currency% -- Best Regards, %site_title% %root_url% Bootstrap.php000064400000010376152101606220007234 0ustar00addReturn(___('Account: Can manage user Accounts'), self::ADMIN_PERM_ID); } function onInitFinished(Am_Event $e) { $this->getDi()->invoiceItemTable->registerItemLoader('custom-account', 'customUserAccountTable'); $router = Zend_Controller_Front::getInstance()->getRouter(); $router->addRoute('custom-account-pay', new Zend_Controller_Router_Route( 'bill/pay', array( 'module' => 'custom-account', 'controller' => 'pay', 'action' => 'index' ) )); $this->getDi()->blocks->add(new Am_Block('member/main/left', ___('Accounts'), 'accounts', $this, array($this, 'renderBlock'))); } function onLoadReports() { require_once 'Am/Report/Account.php'; } function onUserMerge(Am_Event $event) { $target = $event->getTarget(); $source = $event->getSource(); $this->getDi()->db->query('UPDATE ?_custom_user_account SET user_id=? WHERE user_id=?', $target->pk(), $source->pk()); } function onUserAfterDelete(Am_Event_UserAfterDelete $event) { $this->getDi()->db->query("DELETE FROM ?_custom_user_account WHERE user_id=?", $event->getUser()->user_id); } function renderBlock(Am_View $v) { $user = $this->getDi()->user; $accounts = $this->getDi()->customUserAccountTable->findByUserId($user->pk()); if (!$accounts) return 'You have not accounts yet'; $out = ''; foreach ($accounts as $a) { $out .= sprintf('

  • ', $a->number, $a->title, Am_Currency::render($a->balance), $a->description); } return sprintf('', $out); } function onAdminMenu(Am_Event $e) { $page = $e->getMenu()->findOneBy('id', 'users'); $page->addPage(array( 'label' => ___('Update Accounts'), 'controller' => 'admin-account', 'action' => 'index', 'module' => 'custom-account', 'id' => 'custom-account', 'resource' => self::ADMIN_PERM_ID )); $page->addPage(array( 'label' => ___('Upload Account Files'), 'controller' => 'admin-account', 'action' => 'upload', 'module' => 'custom-account', 'id' => 'custom-account-upload', 'resource' => self::ADMIN_PERM_ID )); } function onUserTabs(Am_Event_UserTabs $e) { $e->getTabs()->addPage(array( 'id' => 'account', 'module' => 'custom-account', 'controller' => 'admin-user', 'action' => 'index', 'params' => array( 'user_id' => $e->getUserId() ), 'label' => ___('Accounts'), 'order' => 1000, 'resource' => self::ADMIN_PERM_ID, )); } function onUserMenu(Am_Event $e) { $user = $e->getUser(); if ($this->getDi()->db->selectCell("SELECT COUNT(*) FROM ?_custom_user_account WHERE user_id=?", $user->pk())) { $e->getMenu()->addPage(array( 'id' => 'account', 'label' => ___('Pay Your Bill'), 'controller' => 'pay', 'action' => 'index', 'module' => 'custom-account', 'route' => 'custom-account-pay', 'order' => 3, )); } } function onSetupEmailTemplateTypes(Am_Event $event) { $event->addReturn(array( 'id' => 'custom-account.balance_updated', 'title' => 'Account Updated', 'mailPeriodic' => Am_Mail::REGULAR, 'vars' => array('user', 'account.number' => 'Account Number', 'account.title' => 'Account Title', 'account.balance' => 'Account Balance', ), ), 'custom-account.balance_updated'); } }module.xml000064400000000304152101606220006543 0ustar00 custom-account Account Handle Payments to User Accounts @@VERSION@@ controllers/PayController.php000064400000012127152101606220012416 0ustar00getDi()->auth->requireLogin(REL_ROOT_URL . '/custom-balance/pay'); } function indexAction() { $form = $this->createForm(); $errors = array(); if ($form->isSubmitted() && $form->validate()) { $vars = $form->getValue(); $invoice = $this->getDi()->invoiceRecord; foreach ($vars['account_id'] as $id) { $account = $this->getDi()->customUserAccountTable->load($id); if ($account->user_id != $this->getDi()->user->user_id) throw new Am_Exception_AccessDenied; if (!$vars['amount'][$id]) { $errors[] = ___('Please specify amount for account %s', $account->number); } $account->setAmount($vars['amount'][$id]); $invoice->add($account); } if (!$invoice->getItems()) { $errors[] = ___('You need to choose at least one account to pay for'); } if ($errors) { $form->setError(implode(', ', $errors)); goto form; } $invoice->calculate(); $invoice->setPaysystem($vars['paysys_id']); $invoice->setUser($this->getDi()->user); $err = $invoice->validate(); if ($err) throw new Am_Exception_InputError($err[0]); $invoice->save(); $payProcess = new Am_Paysystem_PayProcessMediator($this, $invoice); $result = $payProcess->process(); throw new Am_Exception_InternalError( sprintf('Error occurred while trying proccess invoice [%s]', filterId($invoice->public_id))); } form: $this->view->title = ___('Pay Your Bill'); $this->view->content = (string) $form; $this->view->display('member/layout.phtml'); } function createForm() { $aOptions = array(); $dAmount = array(); foreach ($this->getDi()->customUserAccountTable->findByUserId($this->getDi()->auth->getUserId()) as $a) { $aOptions[$a->pk()] = $this->renderAccount($a); $dAmount[$a->pk()] = $a->balance; } $form = new Am_Form('pay'); $account = $form->addGroup() ->setLabel(___('Account')); $account->setSeparator('
    '); foreach ($aOptions as $k => $v) { $gr = $account->addGroup(); if (count($aOptions) == 1) { $gr->addHidden("account_id[$k]", array('value' => $k)); $gr->addStatic() ->setContent($v); } else { $gr->addCheckbox("account_id[$k]", array('value' => $k, 'class' => 'account'), array('content' => $v)); } $gr->addText("amount[$k]", array('size' => 10, 'style' => 'clear:both; display:block', 'placeholder' => ___('Amount to Pay'))) ->setId('amount-' . $k); } $form->addScript() ->setScript(<<getPsOptions(); if (count($psOptions) > 1) { $paysys = $form->addAdvRadio('paysys_id') ->setLabel(___('Payment System')) ->loadOptions($psOptions); $paysys->addRule('required', ___('Please choose a payment system')); } else { $form->addHidden('paysys_id') ->setValue(key($psOptions)); } $form->addSaveButton('Pay'); $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('amount' => $dAmount))); return $form; } protected function renderAccount($a) { return sprintf('
    ', $a->number, $a->title, Am_Currency::render($a->balance), $a->description); } protected function getPsOptions() { $paysystems = array(); if (!$this->getModule()->getConfig('paysys_id', array())) { $paysystems = $this->getDi()->paysystemList->getAllPublic(); } else { foreach ($this->getModule()->getConfig('paysys_id') as $ps_id) { try { $ps = $this->getDi()->paysystemList->get($ps_id); } catch (Exception $e) { $this->getDi()->errorLogTable->logException($e); continue; } $paysystems[] = $ps; } } $options = array(); foreach ($paysystems as $ps) { $options[$ps->getId()] = $this->renderPaysys($ps); } return $options; } protected function renderPaysys(Am_Paysystem_Description $p) { return sprintf('%s %s', $p->getTitle(), $p->getDescription()); } }controllers/AdminAccountController.php000064400000012625152101606220014235 0ustar00hasPermission(Bootstrap_CustomAccount::ADMIN_PERM_ID); } function indexAction() { $form = new Am_Form_Admin('custom-account'); $accounts = array(); foreach ($this->getDi()->customUserAccountTable->findBy() as $a) { $user = $this->getDi()->userTable->load($a->user_id, false); if (!$user) continue; $accounts[$a->pk()] = $a; $form->addText(sprintf('account[%d]', $a->pk()), array('class' => 'el-wide row-wide', 'placeholder' => ___('Do not change'))) ->setLabel($this->renderAccount($a, $user)); } $gr = $form->addGroup(); $gr->setSeparator(' '); $gr->addAdvCheckbox('notify_user'); $gr->addElement('email_link', 'custom-account.balance_updated'); $gr->setLabel(___('Notify User about Account Update')); $form->addSaveButton('Update Accounts'); $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('notify_user' => 1))); if ($form->isSubmitted() && $form->validate()) { $v = $form->getValue(); foreach ($v['account'] as $id => $val) { if (!$val) continue; $accounts[$id]->balance = $val; $accounts[$id]->save(); if ($v['notify_user']) { $user = $this->getDi()->userTable->load($accounts[$id]->user_id); $et = Am_Mail_Template::load('custom-account.balance_updated', $user->lang); $et->setUser($user); $et->setAccount($accounts[$id]); $et->send($user); } } Am_Controller::redirectLocation(REL_ROOT_URL . '/custom-account/admin-account'); } $this->view->title = 'Account Update'; $this->view->content = (string) $form; $this->view->display('admin/layout.phtml'); } function uploadAction() { $upload = new Am_Upload($this->getDi()); $upload->setPrefix(Am_Plugin_PersonalContent::UPLOAD_PREFIX); $form = new Am_Form_Admin('custom-account-upload'); $form->setAttribute('enctype', 'multipart/form-data'); $form->addElement('file', 'file[]', array('multiple' => 1)) ->setLabel(___("Files\n" . 'in the following format [number]_mm-dd-yy')); $gr = $form->addGroup(); $gr->setSeparator(' '); $gr->addAdvCheckbox('notify_user'); $gr->addElement('email_link', 'misc.personal-content.notify_user'); $gr->setLabel(___('Notify User about new file upload')); $form->addSaveButton('Upload'); $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('notify_user' => 1))); if ($form->isSubmitted() && $form->validate() && $upload->processSubmit('file') && $files = $upload->getUploads()) { $v = $form->getValue(); $results = array(); $notify = array(); foreach ($files as $file) { $result = array( 'filename' => $file->name, 'user' => null, 'account' => null ); if (preg_match('/^([^_]*)_/', $file->name, $m)) { if ($a = $this->getDi()->customUserAccountTable->findFirstByNumber($m[1])) { if ($user = $this->getDi()->userTable->load($a->user_id, false)) { $pc = $user->data()->getBlob('personal_content'); $pc = $pc ? unserialize($pc) : array(); $pc[] = $file->pk(); $user->data()->setBlob('personal_content', serialize($pc)); $user->save(); $result['user'] = $user; $result['account'] = $a; if (!$user->unsubscribed) { $notify[$user->pk()]['user'] = $user; $notify[$user->pk()]['files'][] = $file->name; } } } } $results[] = $result; } if ($v['notify_user']) { foreach ($notify as $n) { $user = $n['user']; $files = implode(', ', $n['files']); $et = Am_Mail_Template::load('misc.personal-content.notify_user', $user->lang); $et->setUser($user); $et->setFiles($files); $et->send($user); } } $this->view->results = $results; $this->view->display('admin/custom-account/upload-report.phtml'); return; } $this->view->title = 'Upload Files'; $this->view->content = (string) $form; $this->view->display('admin/layout.phtml'); } protected function renderAccount($a, $user) { return sprintf(' | ', $a->number, $this->escape($user->getName()), Am_Currency::render($a->balance)); } }controllers/AdminUserController.php000064400000004652152101606220013560 0ustar00hasPermission(Bootstrap_CustomAccount::ADMIN_PERM_ID); } function preDispatch() { $this->getDi()->navigationUserTabs->setActive('account'); $this->setActiveMenu('users-browse'); $this->user_id = $this->getRequest()->getParam('user_id'); if (!$this->user_id) { throw new Am_Exception_InputError('user_id is not found in request'); } parent::preDispatch(); } function createGrid() { $ds = new Am_Query($this->getDi()->customUserAccountTable); $ds->addWhere('user_id=?', $this->user_id); $grid = new Am_Grid_Editable('_acc', ___('Accounts'), $ds, $this->getRequest(), $this->view); $grid->setPermissionId(Bootstrap_CustomAccount::ADMIN_PERM_ID); $grid->setForm(array($this, 'createForm')); $grid->addField('number', ___('Number')); $grid->addField('title', ___('Title')); $grid->addField('balance', ___('Balance')) ->setFormatFunction(array('Am_Currency', 'render')); $grid->addCallback(Am_Grid_Editable::CB_BEFORE_INSERT, array($this, 'beforeInsert')); return $grid; } function createForm() { $form = new Am_Form_Admin('account'); $form->addText('title', array('class' => 'el-wide')) ->setLabel(___('Title')) ->addRule('required'); $form->addText('description', array('class' => 'el-wide')) ->setLabel(___('Description')); $n = $form->addText('number') ->setLabel(___('Number')); $n->addRule('required'); $n->addRule('callback', ___('Such Account Number already exists'), array($this, 'checkAccountNumber')); $form->addText('balance') ->setLabel(___('Balance')); return $form; } function checkAccountNumber($number) { $r = $this->grid->getRecord(); $cnt = $this->getDi()->db->selectCell('SELECT COUNT(*) FROM ?_custom_user_account WHERE number=? {AND account_id<>?}', $number, $r->isLoaded() ? $r->pk() : DBSIMPLE_SKIP); return !(bool)$cnt; } function beforeInsert($vars, $record, $grid) { $record->user_id = $this->user_id; } }views/public/img/icons/custom-account-upload.png000064400000001154152101606220015776 0ustar00PNG  IHDRagAMA7tEXtSoftwareAdobe ImageReadyqe<IDAT=]Uе;C`DD Ve h*B"6VV"c vba"NB ޙ{~jo|x&,K*o=]߻_v<}tu.R[Ҝ9Xsy|o~ |u_Bk6Yf7bQڴ^Й<T::֊Ǧ7Uݕuwٞ ,6}4'kٞF%*T⏿NHZ'}&NGۯ_鋾ﴌ*UD:tHُZkƦ/F%8A#хJpFQ$Q5:H0' QEDDK$e]t4IJDUS*!BxKOƈ5Hup9Q pҫj'ɬ4nx93W3j7˜oO$*yHI$H=m?!|nmIENDB`views/public/img/icons/custom-account.png000064400000001312152101606220014510 0ustar00PNG  IHDRagAMA7tEXtSoftwareAdobe ImageReadyqe<\IDAT8˥KSQU/"/HAL͕bkbmiIbk֦Ӷvcnwwv݊4 s=9(eSM57=@`Ճ\CY4yQo%(nVEdsڑ5lEXN2o;F!~m#o T祹  j0w EXd2ORd- ~mcW"}ˆ{-p8FNpK"@7cc)g- %>ǥ(gId^C.D:XuEphe{ib1D X4&euQ!qAT"RӨޛ/gHdS v0ʂOg6apωFKޠN0Bd{gFdr I@_9Z:s7վG8L   1 ݥ˱>u8 ѐ՛Ln:Uf( aPz')p!Ԩ$'fF$lE k\+5ݸuLkެ83k=!;L[IENDB`views/admin/query-content/index.php000044400000003674152101606220013431 0ustar000kb<");};?>
    '); } } } ?> setLayout('admin/layout.phtml'); ?>
    login) ?> number) ?>