Ejemplo n.º 1
0
 /**
  * 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();
 }
Ejemplo n.º 2
0
 /**
  * Distribute points
  *
  * @param   integer  $qid       Question ID
  * @param   integer  $Q_owner   Question owner
  * @param   integer  $BA_owner  Account owner
  * @param   string   $type      Transaction type
  * @return  void
  */
 public function distribute_points($qid, $Q_owner, $BA_owner, $type)
 {
     if ($qid === NULL) {
         $qid = $this->qid;
     }
     $cat = 'answers';
     require_once dirname(__DIR__) . DS . 'models' . DS . 'question.php';
     $points = $this->calculate_marketvalue($qid, $type);
     $reward = Transaction::getAmount($cat, 'hold', $qid);
     $reward = $reward ? $reward : '0';
     $share = $points / 3;
     $BA_owner_share = $share + $reward;
     $A_owner_share = 0;
     // Calculate commissions for other answers
     $results = Response::all()->whereEquals('question_id', $qid)->where('state', '!=', 2)->rows();
     $n = $results->count();
     $eligible = array();
     if ($n > 1) {
         // More than one answer found
         foreach ($results as $result) {
             // Check if a regular answer has a good rating (at least 50% of positive votes)
             if ($result->get('helpful') + $result->get('nothelpful') >= 3 && $result->get('helpful') >= $result->get('nothelpful') && $result->get('state') == 0) {
                 $eligible[] = $result->get('created_by');
             }
         }
         if (count($eligible) > 0) {
             // We have eligible answers
             $A_owner_share = $share / $n;
         } else {
             // Best A owner gets remaining thrid
             $BA_owner_share += $share;
         }
     } else {
         // Best A owner gets remaining 3rd
         $BA_owner_share += $share;
     }
     // Reward asker
     $q_user = User::getInstance($Q_owner);
     if (is_object($q_user) && $q_user->get('id')) {
         $BTL_Q = new Teller($q_user->get('id'));
         //$BTL_Q->deposit($Q_owner_share, 'Commission for posting a question', $cat, $qid);
         // Separate comission and reward payment
         // Remove credit
         $credit = $BTL_Q->credit_summary();
         $adjusted = $credit - $reward;
         $BTL_Q->credit_adjustment($adjusted);
         if (intval($share) > 0) {
             $share_msg = $type == 'royalty' ? Lang::txt('Royalty payment for posting question #%s', $qid) : Lang::txt('Commission for posting question #%s', $qid);
             $BTL_Q->deposit($share, $share_msg, $cat, $qid);
         }
         // withdraw reward amount
         if ($reward) {
             $BTL_Q->withdraw($reward, Lang::txt('Reward payment for your question #%s', $qid), $cat, $qid);
         }
     }
     // Reward others
     $ba_user = User::getInstance($BA_owner);
     if (is_object($ba_user) && $ba_user->get('id')) {
         // Reward other responders
         if (count($eligible) > 0) {
             foreach ($eligible as $e) {
                 $auser = User::getInstance($e);
                 if (is_object($auser) && $auser->get('id') && is_object($ba_user) && $ba_user->get('id') && $ba_user->get('id') != $auser->get('id')) {
                     $BTL_A = new Teller($auser->get('id'));
                     if (intval($A_owner_share) > 0) {
                         $A_owner_share_msg = $type == 'royalty' ? Lang::txt('Royalty payment for answering question #%s', $qid) : Lang::txt('Answered question #%s that was recently closed', $qid);
                         $BTL_A->deposit($A_owner_share, $A_owner_share_msg, $cat, $qid);
                     }
                 }
                 // is best answer eligible for extra points?
                 if (is_object($auser) && $auser->get('id') && is_object($ba_user) && $ba_user->get('id') && $ba_user->get('id') == $auser->get('id')) {
                     $ba_extra = 1;
                 }
             }
         }
         // Reward best answer
         $BTL_BA = new Teller($ba_user->get('id'));
         if (isset($ba_extra)) {
             $BA_owner_share += $A_owner_share;
         }
         if (intval($BA_owner_share) > 0) {
             $BA_owner_share_msg = $type == 'royalty' ? Lang::txt('Royalty payment for answering question #%s', $qid) : Lang::txt('Answer for question #%s was accepted', $qid);
             $BTL_BA->deposit($BA_owner_share, $BA_owner_share_msg, $cat, $qid);
         }
     }
     // Remove hold if exists
     if ($reward) {
         $BT = Transaction::deleteRecords('answers', 'hold', $qid);
     }
 }
Ejemplo n.º 3
0
 /**
  * Calculate royalties for a contributor and distribute
  *
  * @param   object   $con   Resources Contributor
  * @param   string   $type  Point calculation type
  * @return  boolean  False if errors, true on success
  */
 public function distribute_points($con, $type = 'royalty')
 {
     if (!is_object($con)) {
         return false;
     }
     $cat = 'resource';
     $points = round($con->ranking);
     // Get qualifying users
     $user = User::getInstance($con->authorid);
     // Reward review author
     if (is_object($user) && $user->get('id')) {
         $BTL = new Teller($this->_db, $user->get('id'));
         if (intval($points) > 0) {
             $msg = $type == 'royalty' ? Lang::txt('Royalty payment for your resource contributions') : '';
             $BTL->deposit($points, $msg, $cat, 0);
         }
     }
     return true;
 }
Ejemplo n.º 4
0
 /**
  * Calculate royalties for a review and distribute
  *
  * @param   object   $review  ResourcesReview
  * @param   string   $type    Point calculation type
  * @return  boolean  False if errors, true on success
  */
 public function distribute_points($review, $type = 'royalty')
 {
     if (!is_object($review)) {
         return false;
     }
     $cat = 'review';
     $points = $this->calculate_marketvalue($review, $type);
     // Get qualifying users
     $user = User::getInstance($review->author);
     // Reward review author
     if (is_object($user)) {
         $BTL = new Teller($this->_db, $user->get('id'));
         if (intval($points) > 0) {
             $msg = $type == 'royalty' ? Lang::txt('Royalty payment for posting a review on publication #%s', $review->pid) : Lang::txt('Commission for posting a review on publication #%s', $review->pid);
             $BTL->deposit($points, $msg, $cat, $review->id);
         }
     }
     return true;
 }
Ejemplo n.º 5
0
 /**
  * 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()));
 }
Ejemplo n.º 6
0
 /**
  * Delete a question
  *
  * @return  void
  */
 public function deleteqTask()
 {
     // Login required
     if (User::isGuest()) {
         $this->setError(Lang::txt('COM_ANSWERS_PLEASE_LOGIN'));
         return $this->loginTask();
     }
     if (!User::authorise('core.delete', $this->_option) && !User::authorise('core.manage', $this->_option)) {
         App::abort(403, Lang::txt('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'));
     }
     // Incoming
     $id = Request::getInt('qid', 0);
     $ip = !User::isGuest() ? Request::ip() : '';
     $reward = 0;
     if ($this->config->get('banking')) {
         $reward = Transaction::getAmount('answers', 'hold', $id);
     }
     $question = Question::oneOrFail($id);
     $question->set('state', Question::STATE_DELETED);
     $question->set('reward', 0);
     // Store new content
     if (!$question->save()) {
         App::abort(500, $question->getError());
     }
     if ($reward && $this->config->get('banking')) {
         /*
         // Get all the answers for this question
         $responses = $question->responses()->rows();
         
         if ($responses->count())
         {
         	$users = array();
         	foreach ($responses as $r)
         	{
         		$users[] = $r->get('created_by');
         	}
         
         	// Build the "from" info
         	$from = array(
         		'email'     => Config::get('mailfrom'),
         		'name'      => Config::get('sitename') . ' ' . Lang::txt('COM_ANSWERS_ANSWERS'),
         		'multipart' => md5(date('U'))
         	);
         
         	// Build the message subject
         	$subject = Config::get('sitename') . ' ' . Lang::txt('COM_ANSWERS_ANSWERS') . ', ' . Lang::txt('COM_ANSWERS_QUESTION') . ' #' . $id . ' ' . Lang::txt('COM_ANSWERS_WAS_REMOVED');
         
         	$message = array();
         
         	// Plain text message
         	$eview = new \Hubzero\Mail\View(array(
         		'name'   => 'emails',
         		'layout' => 'removed_plaintext'
         	));
         	$eview->option   = $this->_option;
         	$eview->sitename = Config::get('sitename');
         	$eview->question = $question;
         	$eview->id       = $question->get('id');
         	$eview->boundary = $from['multipart'];
         
         	$message['plaintext'] = $eview->loadTemplate(false);
         	$message['plaintext'] = str_replace("\n", "\r\n", $message['plaintext']);
         
         	// HTML message
         	$eview->setLayout('removed_html');
         
         	$message['multipart'] = $eview->loadTemplate();
         	$message['multipart'] = str_replace("\n", "\r\n", $message['multipart']);
         
         	// Send the message
         	if (!Event::trigger('xmessage.onSendMessage', array('answers_question_deleted', $subject, $message, $from, $users, $this->_option)))
         	{
         		$this->setError(Lang::txt('COM_ANSWERS_MESSAGE_FAILED'));
         	}
         }
         */
         // Remove hold
         $transaction->deleteRecords('answers', 'hold', $id);
         // Make credit adjustment
         $teller = new Teller(User::get('id'));
         $adjusted = $teller->credit_summary() - $reward;
         $teller->credit_adjustment($adjusted);
     }
     // Log activity
     $recipients = array($question->get('created_by'));
     $recipients = $this->recipients($recipients);
     Event::trigger('system.logActivity', ['activity' => ['action' => 'deleted', 'scope' => 'question', 'scope_id' => $question->get('id'), 'description' => Lang::txt('COM_ANSWERS_ACTIVITY_QUESTION_DELETED', '<a href="' . Route::url($question->link()) . '">' . $question->get('subject') . '</a>'), 'details' => array('title' => $question->get('title'), 'url' => $question->link())], 'recipients' => $recipients]);
     // Redirect to the question
     App::redirect(Route::url('index.php?option=' . $this->_option));
 }
Ejemplo n.º 7
0
 /**
  * Saves changes to an order
  *
  * @return void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     $statusmsg = '';
     $data = array_map('trim', $_POST);
     $action = isset($data['action']) ? $data['action'] : '';
     $id = $data['id'] ? $data['id'] : 0;
     $cost = intval($data['total']);
     if ($id) {
         // initiate extended database class
         $row = new Order($this->database);
         $row->load($id);
         $row->notes = \Hubzero\Utility\Sanitize::clean($data['notes']);
         $hold = $row->total;
         $row->total = $cost;
         // get user bank account
         $xprofile = User::getInstance($row->uid);
         $BTL_Q = new Teller($this->database, $xprofile->get('id'));
         switch ($action) {
             case 'complete_order':
                 // adjust credit
                 $credit = $BTL_Q->credit_summary();
                 $adjusted = $credit - $hold;
                 $BTL_Q->credit_adjustment($adjusted);
                 // remove hold
                 $sql = "DELETE FROM `#__users_transactions` WHERE category='store' AND type='hold' AND referenceid='" . $id . "' AND uid=" . intval($row->uid);
                 $this->database->setQuery($sql);
                 if (!$this->database->query()) {
                     throw new Exception($this->database->getErrorMsg(), 500);
                 }
                 // debit account
                 if ($cost > 0) {
                     $BTL_Q->withdraw($cost, Lang::txt('COM_STORE_BANKING_PURCHASE') . ' #' . $id, 'store', $id);
                 }
                 // update order information
                 $row->status_changed = Date::toSql();
                 $row->status = 1;
                 $statusmsg = Lang::txt('COM_STORE_ORDER') . ' #' . $id . ' ' . Lang::txt('COM_STORE_HAS_BEEN') . ' ' . strtolower(Lang::txt('COM_STORE_COMPLETED')) . '.';
                 break;
             case 'cancel_order':
                 // adjust credit
                 $credit = $BTL_Q->credit_summary();
                 $adjusted = $credit - $hold;
                 $BTL_Q->credit_adjustment($adjusted);
                 // remove hold
                 $sql = "DELETE FROM `#__users_transactions` WHERE category='store' AND type='hold' AND referenceid='" . $id . "' AND uid=" . intval($row->uid);
                 $this->database->setQuery($sql);
                 if (!$this->database->query()) {
                     throw new Exception($this->database->getErrorMsg(), 500);
                 }
                 // update order information
                 $row->status_changed = Date::toSql();
                 $row->status = 2;
                 $statusmsg = Lang::txt('COM_STORE_ORDER') . ' #' . $id . ' ' . Lang::txt('COM_STORE_HAS_BEEN') . ' ' . strtolower(Lang::txt('COM_STORE_CANCELLED')) . '.';
                 break;
             case 'message':
                 $statusmsg = Lang::txt('COM_STORE_MSG_SENT') . '.';
                 break;
             default:
                 $statusmsg = Lang::txt('COM_STORE_ORDER_DETAILS_UPDATED') . '.';
                 break;
         }
         // check content
         if (!$row->check()) {
             throw new Exception($row->getError(), 500);
             return;
         }
         // store new content
         if (!$row->store()) {
             throw new Exception($row->getError(), 500);
         }
         // send email
         if ($action || $data['message']) {
             if (\Hubzero\Utility\Validate::email($row->email)) {
                 $message = new \Hubzero\Mail\Message();
                 $message->setSubject(Config::get('sitename') . ' ' . Lang::txt('COM_STORE_EMAIL_UPDATE_SHORT', $id));
                 $message->addFrom(Config::get('mailfrom'), Config::get('sitename') . ' ' . Lang::txt('COM_STORE_STORE'));
                 // Plain text email
                 $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => '_plain'));
                 $eview->option = $this->_option;
                 $eview->controller = $this->_controller;
                 $eview->orderid = $id;
                 $eview->cost = $cost;
                 $eview->row = $row;
                 $eview->action = $action;
                 $eview->message = \Hubzero\Utility\Sanitize::stripAll($data['message']);
                 $plain = $eview->loadTemplate(false);
                 $plain = str_replace("\n", "\r\n", $plain);
                 $message->addPart($plain, 'text/plain');
                 // HTML email
                 $eview->setLayout('_html');
                 $html = $eview->loadTemplate();
                 $html = str_replace("\n", "\r\n", $html);
                 $message->addPart($html, 'text/html');
                 // Send e-mail
                 $message->setTo(array($row->email));
                 $message->send();
             }
         }
     }
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), $statusmsg);
 }
Ejemplo n.º 8
0
 /**
  * Distribute points
  *
  * @return  void
  */
 public function adjustCredits()
 {
     if ($this->get('reward')) {
         // Adjust credits
         // Remove hold
         $BT = new Transaction($this->_db);
         $reward = $BT->getAmount('answers', 'hold', $this->get('id'));
         $BT->deleteRecords('answers', 'hold', $this->get('id'));
         // Make credit adjustment
         if (is_object($this->creator())) {
             $BTL = new Teller($this->_db, $this->creator('id'));
             $credit = $BTL->credit_summary();
             $adjusted = $credit - $reward;
             $BTL->credit_adjustment($adjusted);
         }
         $this->set('reward', 0);
     }
 }
Ejemplo n.º 9
0
 /**
  * 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();
 }
Ejemplo n.º 10
0
 /**
  * Distribute points
  *
  * @param   integer  $wishid  Wish ID
  * @param   string   $type    Transaction type
  * @param   number   $points  Points to distribute
  * @return  void
  */
 public function distribute_points($wishid, $type = 'grant', $points = 0)
 {
     if (!$wishid) {
         return null;
     }
     require_once dirname(__DIR__) . DS . 'models' . DS . 'wishlist.php';
     $objWish = new Tables\Wish($this->_db);
     $wish = $objWish->get_wish($wishid);
     $points = !$points ? $wish->bonus : $points;
     // Points for list owners
     if ($points > 0 && $type != 'royalty') {
         // Get the component parameters
         $wconfig = Component::params('com_wishlist');
         $admingroup = $wconfig->get('group', 'hubadmin');
         // get list owners
         $objOwner = new Tables\Owner($this->_db);
         $owners = $objOwner->get_owners($wish->wishlist, $admingroup, '', 0, $wishid);
         $owners = $owners['individuals'];
         $mainshare = $wish->assigned ? $points * 0.8 : 0;
         //80%
         $commonshare = $mainshare ? ($points - $mainshare) / count($owners) : $points / count($owners);
         // give the remaining 20%
         if ($owners && $commonshare) {
             foreach ($owners as $owner) {
                 $o = User::getInstance($owner);
                 if (!is_object($o) || !$o->get('id')) {
                     continue;
                 }
                 $BTLO = new Teller($this->_db, $owner);
                 if ($wish->assigned && $wish->assigned == $owner) {
                     //$BTLO->deposit($mainshare, Lang::txt('Bonus for fulfilling assigned wish').' #'.$wishid.' '.Lang::txt('on list').' #'.$wish->wishlist, 'wish', $wishid);
                     $mainshare += $commonshare;
                 } else {
                     $BTLO->deposit($commonshare, Lang::txt('Bonus for fulfilling wish #%s on list #%s', $wishid, $wish->wishlist), 'wish', $wishid);
                 }
             }
         } else {
             $mainshare += $commonshare;
         }
         // give main share
         if ($wish->assigned && $mainshare) {
             $o = User::getInstance($wish->assigned);
             if (is_object($o) && $o->get('id')) {
                 $BTLM = new Teller($this->_db, $wish->assigned);
                 $BTLM->deposit($mainshare, Lang::txt('Bonus for fulfilling assigned wish #%s on list #%s', $wishid, $wish->wishlist), 'wish', $wishid);
             }
         }
         // Adjust credits
         $payees = $this->getPayees($wishid);
         if ($payees) {
             foreach ($payees as $p) {
                 $o = User::getInstance($p->uid);
                 if (!is_object($o) || !$o->get('id')) {
                     continue;
                 }
                 $BTL = new Teller($this->_db, $p->uid);
                 $hold = $this->getTotalPayment($wishid, $p->uid);
                 if ($hold) {
                     $credit = $BTL->credit_summary();
                     $adjusted = $credit - $hold;
                     $BTL->credit_adjustment($adjusted);
                     // withdraw bonus amount
                     $BTL->withdraw($hold, Lang::txt('Bonus payment for granted wish #%s on list #%s', $wishid, $wish->wishlist), 'wish', $wishid);
                 }
             }
         }
         // Remove holds if exist
         if ($wish->bonus) {
             $BT = new Transaction($this->_db);
             $BT->deleteRecords('wish', 'hold', $wishid);
         }
     }
     // Points for wish author (needs to be granted by another person)
     if ($wish->ranking > 0 && $wish->proposed_by != User::get('id') && $wish->proposed_by) {
         $o = User::getInstance($wish->proposed_by);
         if (is_object($o) && $o->get('id')) {
             $BTLA = new Teller($this->_db, $wish->proposed_by);
             $BTLA->deposit($wish->ranking, Lang::txt('Your wish #%s on list #%s was granted', $wishid, $wish->wishlist), 'wish', $wishid);
         }
     }
 }
Ejemplo n.º 11
0
 /**
  * Mark an entry as opted out
  *
  * @return  mixed
  */
 public function award()
 {
     if (!$this->uid) {
         return NULL;
     }
     $opts = new Options();
     $awardPer = $opts->getAwardPerField();
     $fieldMap = array('name' => 'Fullname', 'orgtype' => 'Employment', 'organization' => 'Organization', 'countryorigin' => 'Citizenship', 'countryresident' => 'Residency', 'gender' => 'Sex', 'url' => 'URL', 'reason' => 'Reason', 'race' => 'Race', 'phone' => 'Phone', 'disability' => 'Disability');
     $alreadyComplete = 0;
     $eligible = array();
     $newAmount = 0;
     $completeSql = 'UPDATE `#__profile_completion_awards` SET edited_profile = 1';
     $optedOut = NULL;
     foreach ($this->awards as $k => $complete) {
         if ($k === 'opted_out') {
             $optedOut = $complete;
             continue;
         }
         if ($complete) {
             continue;
         }
         if ($k === 'picture') {
             self::$dbh->setQuery('SELECT picture FROM `#__xprofiles` WHERE uidNumber = ' . $this->uid);
             if (self::$dbh->loadResult()) {
                 $completeSql .= ', ' . $k . ' = 1';
                 $alreadyComplete += $awardPer;
             } else {
                 $eligible['picture'] = 1;
             }
             continue;
         }
         $regField = $fieldMap[$k];
         if ((bool) $this->profile->get($k)) {
             $completeSql .= ', ' . $k . ' = 1';
             $alreadyComplete += $awardPer;
         } else {
             $eligible[$k == 'url' ? 'web' : $k] = 1;
         }
     }
     self::$dbh->setQuery('SELECT SUM(amount) AS amount FROM `#__users_transactions` WHERE type = \'deposit\' AND category = \'registration\' AND uid = ' . $this->uid);
     $prior = self::$dbh->loadResult();
     self::$dbh->setQuery($completeSql . ' WHERE user_id = ' . $this->uid);
     self::$dbh->execute();
     if ($alreadyComplete) {
         self::$dbh->setQuery('SELECT COALESCE((SELECT balance FROM `#__users_transactions` WHERE uid = ' . $this->uid . ' AND id = (SELECT MAX(id) FROM `#__users_transactions` WHERE uid = ' . $this->uid . ')), 0)');
         $newAmount = self::$dbh->loadResult() + $alreadyComplete;
         $BTL = new Teller($this->uid);
         $BTL->deposit($alreadyComplete, 'Profile completion award', 'registration', 0);
     }
     return array('prior' => $prior, 'new' => $alreadyComplete, 'eligible' => $eligible, 'opted_out' => $optedOut);
 }
Ejemplo n.º 12
0
 /**
  * Delete a question
  *
  * @return     void
  */
 public function deleteqTask()
 {
     // Login required
     if (User::isGuest()) {
         $this->setError(Lang::txt('COM_ANSWERS_PLEASE_LOGIN'));
         $this->loginTask();
         return;
     }
     if (!User::authorise('core.delete', $this->_option) && !User::authorise('core.manage', $this->_option)) {
         throw new Exception(Lang::txt('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
     }
     // Incoming
     $id = Request::getInt('qid', 0);
     $ip = !User::isGuest() ? Request::ip() : '';
     $reward = 0;
     if ($this->config->get('banking')) {
         $BT = new Transaction($this->database);
         $reward = $BT->getAmount('answers', 'hold', $id);
     }
     $email = 0;
     $question = new Question($id);
     // Check if user is authorized to delete
     if ($question->get('created_by') != User::get('id')) {
         App::redirect(Route::url($question->link() . '&note=3'));
         return;
     }
     if ($question->get('state') == 1) {
         App::redirect(Route::url($question->link() . '&note=2'));
         return;
     }
     $question->set('state', 2);
     // Deleted by user
     $question->set('reward', 0);
     // Store new content
     if (!$question->store(false)) {
         throw new Exception($question->getError(), 500);
     }
     if ($reward && $this->config->get('banking')) {
         // Get all the answers for this question
         if ($question->comments('list', array('filterby' => 'all'))) {
             $users = array();
             foreach ($responses as $r) {
                 $users[] = $r->creator('id');
             }
             // Build the "from" info
             $from = array('email' => Config::get('mailfrom'), 'name' => Config::get('sitename') . ' ' . Lang::txt('COM_ANSWERS_ANSWERS'), 'multipart' => md5(date('U')));
             // Build the message subject
             $subject = Config::get('sitename') . ' ' . Lang::txt('COM_ANSWERS_ANSWERS') . ', ' . Lang::txt('COM_ANSWERS_QUESTION') . ' #' . $id . ' ' . Lang::txt('COM_ANSWERS_WAS_REMOVED');
             $message = array();
             // Plain text message
             $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'removed_plaintext'));
             $eview->option = $this->_option;
             $eview->sitename = Config::get('sitename');
             $eview->question = $question;
             $eview->id = $question->get('id');
             $eview->boundary = $from['multipart'];
             $message['plaintext'] = $eview->loadTemplate(false);
             $message['plaintext'] = str_replace("\n", "\r\n", $message['plaintext']);
             // HTML message
             $eview->setLayout('removed_html');
             $message['multipart'] = $eview->loadTemplate();
             $message['multipart'] = str_replace("\n", "\r\n", $message['multipart']);
             // Send the message
             if (!Event::trigger('xmessage.onSendMessage', array('answers_question_deleted', $subject, $message, $from, $users, $this->_option))) {
                 $this->setError(Lang::txt('COM_ANSWERS_MESSAGE_FAILED'));
             }
         }
         // Remove hold
         $BT->deleteRecords('answers', 'hold', $id);
         // Make credit adjustment
         $BTL_Q = new Teller($this->database, User::get('id'));
         $adjusted = $BTL_Q->credit_summary() - $reward;
         $BTL_Q->credit_adjustment($adjusted);
     }
     // Redirect to the question
     App::redirect(Route::url('index.php?option=' . $this->_option));
 }