/** * Display module content * * @return void */ public function display() { $database = \App::get('db'); $this->moduleclass = $this->params->get('moduleclass'); $this->limit = intval($this->params->get('limit', 10)); $this->error = false; // Check for the existence of required tables that should be // installed with the com_support component $tables = $database->getTableList(); if ($tables && array_search(Config::get('dbprefix') . 'users_points', $tables) === false) { // Points table not found $this->error = true; } else { // Get the user's point summary and history $BTL = new Teller(User::get('id')); $this->summary = $BTL->summary(); $this->history = $BTL->history($this->limit); // Push the module CSS to the template $this->css(); } require $this->getLayoutPath(); }
/** * Display a form for creating a wish * * @return void */ public function addwishTask() { // Incoming $wishid = Request::getInt('wishid', 0); $listid = Request::getInt('id', 0); $refid = Request::getInt('rid', 0); $category = Request::getVar('category', ''); $wish = new Wish($wishid); if (!$listid && $refid) { if (!$category) { throw new Exception(Lang::txt('COM_WISHLIST_ERROR_WISHLIST_NOT_FOUND'), 404); } $wishlist = Wishlist::getInstance($refid, $category); if (!$wishlist->exists()) { $wishlist->set('category', $category); $wishlist->set('referenceid', $refid); $wishlist->setup(); } } else { $wishlist = Wishlist::getInstance($listid); } if (!$wishlist->exists()) { // list not found throw new Exception(Lang::txt('COM_WISHLIST_ERROR_WISHLIST_NOT_FOUND'), 404); } // Build page title $this->_list_title = ($wishlist->isPublic() or !$wishlist->isPublic() && $wishlist->access('manage')) ? $wishlist->get('title') : ''; $this->_buildTitle(); // Set the pathway $this->_taskpath = $wish->exists() ? $wish->link('edit') : 'index.php?option=' . $this->_option . '&task=add&category=' . $category . '&rid=' . $refid; $this->_taskname = $wish->exists() ? Lang::txt('COM_WISHLIST_EDITWISH') : Lang::txt('COM_WISHLIST_ADD'); $this->_buildPathway($wishlist); // Login required if (User::isGuest()) { $this->_msg = Lang::txt('COM_WISHLIST_WARNING_WISHLIST_LOGIN_TO_ADD'); $this->loginTask(); return; } // get admin priviliges if (!$wishlist->isPublic() && !$wishlist->access('manage')) { throw new Exception(Lang::txt('COM_WISHLIST_ALERTNOTAUTH'), 403); } // Get some defaults if (!$wish->exists()) { $wish->set('proposed_by', User::get('id')); $wish->set('status', 0); $wish->set('anonymous', 0); $wish->set('private', 0); $wish->set('wishlist', $wishlist->get('id')); $wish->set('category', $wishlist->get('category')); $wish->set('referenceid', $wishlist->get('referenceid')); } // do not allow points for individual wish lists $this->banking = $wishlist->get('category') == 'user' ? 0 : $this->banking; // Is banking turned on? $funds = 0; if ($this->banking) { $BTL = new Teller($this->database, User::get('id')); $balance = $BTL->summary(); $credit = $BTL->credit_summary(); $funds = $balance - $credit; $funds = $funds > 0 ? $funds : '0'; } // Output HTML $this->view->title = $this->_title; $this->view->config = $this->config; $this->view->admin = $this->_admin; $this->view->wishlist = $wishlist; $this->view->wish = $wish; // Get URL to page explaining virtual economy $aconfig = Component::params('com_answers'); $this->view->infolink = $aconfig->get('infolink', Request::base(true) . '/kb/points/'); $this->view->funds = $funds; $this->view->banking = $this->banking; if ($this->getError()) { $this->view->setError($this->getError()); } $this->view->setLayout('editwish')->display(); }
/** * Assign a point bonus to a wish * * @return void */ public function addbonusTask() { //$listid = Request::getInt('wishlist', 0); $wishid = Request::getInt('wish', 0); $amount = Request::getInt('amount', 0); // missing wish id /*if (!$wishid or !$listid) { App::abort(404, Lang::txt('COM_WISHLIST_ERROR_WISH_NOT_FOUND')); return; }*/ //$objWishlist = new Wishlist($this->database); //$objWish = new Wish($this->database); $wishlist = new Wishlist(Request::getInt('wishlist', 0)); if (!$wishlist->exists()) { throw new Exception(Lang::txt('COM_WISHLIST_ERROR_WISHLIST_NOT_FOUND'), 404); } $wish = new Wish(Request::getInt('wish', 0)); if (!$wish->exists()) { throw new Exception(Lang::txt('COM_WISHLIST_ERROR_WISH_NOT_FOUND'), 404); } // Login required if (User::isGuest()) { // Set page title if (!$wishlist->isPublic() && !$wishlist->access('manage')) { $this->_list_title = ''; } $this->_buildTitle(); // Set the pathway $this->_buildPathway($wishlist); $this->login(); return; } // check available user funds $BTL = new \Hubzero\Bank\Teller($this->database, User::get('id')); $balance = $BTL->summary(); $credit = $BTL->credit_summary(); $funds = $balance - $credit; $funds = $funds > 0 ? $funds : '0'; // missing amount if ($amount == 0) { throw new Exception(Lang::txt('COM_WISHLIST_ERROR_INVALID_AMOUNT'), 500); } if ($amount < 0) { throw new Exception(Lang::txt('COM_WISHLIST_ERROR_NEGATIVE_BONUS'), 500); } else { if ($amount > $funds) { throw new Exception(Lang::txt('COM_WISHLIST_ERROR_NO_FUNDS'), 500); } } // put the amount on hold $BTL = new Teller($this->database, User::get('id')); $BTL->hold($amount, Lang::txt('COM_WISHLIST_BANKING_HOLD') . ' #' . $wish->get('id') . ' ' . Lang::txt('COM_WISHLIST_FOR') . ' ' . $wishlist->get('title'), 'wish', $wish->get('id')); App::redirect(Route::url($wish->link())); }
/** * Create a new question * * @return void */ public function newTask($question = null) { // Login required if (User::isGuest()) { $this->setError(Lang::txt('COM_ANSWERS_PLEASE_LOGIN')); return $this->loginTask(); } if (!User::authorise('core.create', $this->_option) && !User::authorise('core.manage', $this->_option)) { App::abort(403, Lang::txt('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN')); } // Instantiate if doesn't exist if (!is_object($question)) { $question = new Question(); } // Is banking turned on? $funds = 0; if ($this->config->get('banking')) { $BTL = new Teller(User::get('id')); $funds = $BTL->summary() - $BTL->credit_summary(); $funds = $funds > 0 ? $funds : 0; } // Render view $this->view->setError($this->getErrors())->set('question', $question)->set('config', $this->config)->set('funds', $funds)->set('tag', Request::getVar('tag', ''))->setLayout('new')->display(); }
/** * Display an order * * @return void */ public function orderTask() { $this->view->store_enabled = $this->config->get('store_enabled'); // Incoming $id = Request::getInt('id', 0); // Load data $this->view->row = new Order($this->database); $this->view->row->load($id); $oi = new OrderItem($this->database); $this->view->orderitems = array(); $this->view->customer = null; $this->view->funds = 0; if ($id) { // Get order items $this->view->orderitems = $oi->getOrderItems($id); if (count($this->view->orderitems) > 0) { foreach ($this->view->orderitems as $r) { $params = new Registry($r->params); $selections = new Registry($r->selections); // Get size selection $r->sizes = $params->get('size', ''); $r->sizes = str_replace(' ', '', $r->sizes); $r->sizes = preg_split('#,#', $r->sizes); $r->selectedsize = trim($selections->get('size', '')); $r->sizeavail = in_array($r->selectedsize, $r->sizes) ? 1 : 0; // Get color selection $r->colors = $params->get('color', ''); $r->colors = str_replace(' ', '', $r->colors); $r->colors = preg_split('#,#', $r->colors); $r->selectedcolor = trim($selections->get('color', '')); } } $this->view->customer = User::getInstance($this->view->row->uid); // Check available user funds $BTL = new Teller($this->database, $this->view->row->uid); $balance = $BTL->summary(); $credit = $BTL->credit_summary(); $this->view->funds = $balance; } // Set any errors foreach ($this->getErrors() as $error) { $this->view->setError($error); } // Output the HTML $this->view->display(); }
/** * Process the order * * @return void */ public function processTask() { // Check for request forgeries Request::checkToken(); // Check authorization if (User::isGuest()) { $this->loginTask(); return; } // Set page title $this->_buildTitle(); // Set the pathway $this->_buildPathway(); // Get cart object $item = new Cart($this->database); // Calculate total $cost = $item->getCartItems(User::get('id'), 'cost'); if (!$cost) { $this->setError(Lang::txt('COM_STORE_ERR_EMPTY_ORDER')); } // Check available user funds $BTL = new Teller(User::get('id')); $balance = $BTL->summary(); $credit = $BTL->credit_summary(); $funds = $balance - $credit; $funds = $funds > 0 ? $funds : '0'; if ($cost > $funds) { $this->setError(Lang::txt('COM_STORE_MSG_NO_FUNDS')); } // Get cart items $items = $item->getCartItems(User::get('id')); // Get shipping info $this->view->posted = array_map('trim', $_POST); if (!$this->view->posted['name'] || !$this->view->posted['address'] || !$this->view->posted['country']) { $this->setError(Lang::txt('COM_STORE_ERR_BLANK_FIELDS')); } // Incoming $action = Request::getVar('action', ''); // Output HTML if (!$this->getError() && $action != 'change') { // Instantiate a new view $this->view->setLayout('finalize'); $this->view->final = true; } else { // Instantiate a new view $this->view->setLayout('checkout'); $this->view->final = false; } // Output HTML $this->view->cost = $cost; $this->view->funds = $funds; $this->view->items = $items; $this->view->infolink = $this->infolink; $this->view->xprofile = User::getInstance(); foreach ($this->getErrors() as $error) { $this->view->setError($error); } $this->view->display(); }
/** * Create a new question * * @return void */ public function newTask($question = null) { // Login required if (User::isGuest()) { $this->setError(Lang::txt('COM_ANSWERS_PLEASE_LOGIN')); $this->loginTask(); return; } if (!User::authorise('core.create', $this->_option) && !User::authorise('core.manage', $this->_option)) { throw new Exception(Lang::txt('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403); } // Instantiate a new view $this->view->config = $this->config; $this->view->task = $this->_task; // Incoming $this->view->tag = Request::getVar('tag', ''); if (is_object($question)) { $this->view->question = $question; } else { $this->view->question = new Question(0); } // Is banking turned on? $this->view->funds = 0; if ($this->config->get('banking')) { $BTL = new Teller($this->database, User::get('id')); $funds = $BTL->summary() - $BTL->credit_summary(); $this->view->funds = $funds > 0 ? $funds : 0; } // Set the page title $this->_buildTitle(); // Set the pathway $this->_buildPathway(); // Output HTML $this->view->notifications = array(); foreach ($this->getErrors() as $error) { $this->view->notifications[] = array('type' => 'error', 'message' => $error); } $this->view->setLayout('new')->display(); }