public function handle() { // Get user ID for the cart require_once dirname(dirname(dirname(__DIR__))) . DS . 'models' . DS . 'Cart.php'; $userId = \Components\Cart\Models\Cart::getCartUser($this->crtId); // Get number of points to add if (!empty($this->item['meta']['addPoints']) && is_numeric($this->item['meta']['addPoints'])) { // Update points account $BTL = new \Hubzero\Bank\Teller($userId); $BTL->deposit($this->item['meta']['addPoints'], 'PRO Membership Bonus', 'PRO', $this->item['info']->sId); } }
public function handle() { // Get user ID for the cart require_once JPATH_BASE . DS . 'components' . DS . 'com_cart' . DS . 'models' . DS . 'Cart.php'; $userId = CartModelCart::getCartUser($this->crtId); // Get number of points to add if (!empty($this->item['meta']['addPoints']) && is_numeric($this->item['meta']['addPoints'])) { // Update points account $db = App::get('db'); $BTL = new \Hubzero\Bank\Teller($db, $userId); $BTL->deposit($this->item['meta']['addPoints'], 'PRO Membership Bonus', 'PRO', $this->item['info']->sId); } }
/** * Delete a record * * @param boolean $isSpam * @return void */ public function removeTask($isSpam = false) { // Check for request forgeries Request::checkToken(); // Incoming $id = Request::getInt('id', 0); $parentid = Request::getInt('parentid', 0); // Ensure we have an ID to work with if (!$id) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false)); return; } $email = 1; // Turn off/on $gratitude = 1; // Turn off/on $message = ''; // Load the report $report = new ReportAbuse($this->database); $report->load($id); $report->reviewed = Date::toSql(); $report->reviewed_by = User::get('id'); $report->note = Request::getVar('note', ''); // Get the reported item $results = Event::trigger('support.getReportedItem', array($report->referenceid, $report->category, $parentid)); // Check the results returned for a reported item $reported = null; if ($results) { foreach ($results as $result) { if ($result) { $reported = $result[0]; } } } // Remove the reported item and any other related processes that need be performed $results = Event::trigger('support.deleteReportedItem', array($report->referenceid, $parentid, $report->category, $message)); if ($results) { foreach ($results as $result) { if ($result) { $message .= $result; } } } if ($isSpam) { $results = Event::trigger('antispam.onAntispamTrain', array($reported->text, $isSpam)); } // Mark abuse report as deleted $report->state = 2; if (!$report->store()) { throw new Exception($report->getError(), 500); } // Notify item owner if ($email) { $user = User::getInstance($reported->author); // Email "from" info $from = array('name' => Config::get('sitename') . ' ' . Lang::txt('COM_SUPPORT'), 'email' => Config::get('mailfrom'), 'multipart' => md5(date('U'))); // Email subject $subject = Lang::txt('COM_SUPPORT_REPORT_ABUSE_EMAIL_SUBJECT', Config::get('sitename')); // Plain text $eview = new View(array('base_path' => PATH_CORE . DS . 'components' . DS . 'com_support' . DS . 'site', 'name' => 'emails', 'layout' => 'abuse_plain')); $eview->option = $this->_option; $eview->controller = $this->_controller; $eview->reported = $reported; $eview->report = $report; $eview->author = $user; $plain = $eview->loadTemplate(false); $plain = str_replace("\n", "\r\n", $plain); // HTML $eview->setLayout('abuse_html'); $html = $eview->loadTemplate(); $html = str_replace("\n", "\r\n", $html); // Build message $message = new Message(); $message->setSubject($subject)->addFrom($from['email'], $from['name'])->addTo($user->get('email'), $user->get('name'))->addHeader('X-Component', 'com_support')->addHeader('X-Component-Object', 'abuse_item_removal'); $message->addPart($plain, 'text/plain'); $message->addPart($html, 'text/html'); // Send the email if (Utilities::checkValidEmail($user->get('email'))) { $message->send(); } } // Check the HUB configuration to see if banking is turned on $upconfig = Component::params('com_members'); $banking = $upconfig->get('bankAccounts'); // Give some points to whoever reported abuse if ($banking && $gratitude) { $BC = \Hubzero\Bank\Config::values(); $ar = $BC->get('abusereport'); // How many points? if ($ar) { $ruser = User::getInstance($report->created_by); if (is_object($ruser) && $ruser->get('id')) { $BTL = new \Hubzero\Bank\Teller($ruser->get('id')); $BTL->deposit($ar, Lang::txt('COM_SUPPORT_ACKNOWLEDGMENT_FOR_VALID_REPORT'), 'abusereport', $id); } } } // Redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_SUPPORT_REPORT_ITEM_TAKEN_DOWN')); }
/** * Display module contents * * @return void */ public function display() { if (User::isGuest()) { return; } $dbg = isset($_GET['dbg']); $uid = (int) User::get('id'); $dbh = \App::get('db'); require_once Component::path('com_members') . '/tables/incremental/awards.php'; require_once Component::path('com_members') . '/tables/incremental/groups.php'; require_once Component::path('com_members') . '/tables/incremental/options.php'; $opts = new ModIncrementalRegistrationOptions(); if (!$opts->isEnabled($uid)) { return; } $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['REDIRECT_REQUEST_URI']; if (preg_match('%(?:members|invoke|session|privacy)%', $uri)) { return; } // looks like an error page, don't show if (\JDocument::getInstance('error')->getTitle()) { return; } if (isset($_POST['incremental-registration']) && isset($_POST['submit']) && $_POST['submit'] === 'opt-out') { $awards = new ModIncrementalRegistrationAwards($uid); $awards->optOut(); return; } $groups = new ModIncrementalRegistrationGroups(); $hasCurl = file_exists(__DIR__ . '/assets/img/bigcurl.png'); if (($row = $groups->getActiveColumns($uid)) || $hasCurl) { if (!isset($_SESSION['return']) && !preg_match('/[.]/', $uri)) { $_SESSION['return'] = $uri; } $this->css(); $this->js(); if ($row) { $dbh->setQuery('SELECT popover_text, award_per FROM `#__incremental_registration_options` ORDER BY added DESC LIMIT 1'); list($introText, $awardPer) = $dbh->loadRow(); if ($_SERVER['REQUEST_METHOD'] == 'GET') { require $this->getLayoutPath('popover'); } elseif (isset($_POST['incremental-registration']) && $_POST['incremental-registration'] == 'update') { $errors = array(); $orgtype = null; $organization = null; $reason = null; $mailPreferenceOption = -1; if (isset($_POST['mailPreferenceOption'])) { $mailPreferenceOption = (int) $_POST['mailPreferenceOption']; } if (isset($_POST['orgtype']) && trim($_POST['orgtype'])) { $orgtype = trim($_POST['orgtype']); } if (isset($_POST['org-other']) && trim($_POST['org-other'])) { $organization = trim($_POST['org-other']); } elseif (isset($_POST['org']) && trim($_POST['org'])) { $organization = trim($_POST['org']); } if (isset($_POST['reason-other']) && trim($_POST['reason-other'])) { $reason = trim($_POST['reason-other']); } elseif (isset($_POST['reason']) && trim($_POST['reason'])) { $reason = trim($_POST['reason']); } if (isset($_POST['name'])) { if (!isset($POST['name']['first']) || !isset($_POST['name']['last'])) { $errors['name'] = true; } $name = preg_replace('/\\s+/', ' ', trim(implode(' ', array($name['first'], $name['middle'], $name['last'])))); } if (isset($row['gender'])) { if (!isset($_POST['gender']) || $_POST['gender'] != 'male' && $_POST['gender'] != 'female' && $_POST['gender'] != 'refused') { $errors['gender'] = true; } else { $gender = $_POST['gender']; } } if (isset($_POST['url'])) { if (!trim($_POST['url'])) { $errors['url'] = true; } $url = trim($_POST['url']); } if (isset($_POST['phone'])) { if (!trim($_POST['phone'])) { $errors['phone'] = true; } $phone = trim($_POST['phone']); } if (isset($row['race'])) { if (empty($_POST['race']) || !is_array($_POST['race'])) { $errors['race'] = true; } else { $race = array_map('trim', $_POST['race']); } } if (isset($row['countryorigin'])) { if (isset($_POST['countryorigin_us']) && $_POST['countryorigin_us'] == 'yes') { $countryorigin = 'us'; } elseif (!isset($_POST['countryorigin']) || !preg_match('/[A-Za-z]{2}/', $_POST['countryorigin'])) { $errors['countryorigin'] = true; } else { $countryorigin = $_POST['countryorigin']; } // race does not apply to non-us if (isset($countryorigin) && strtolower($countryorigin) != 'us' && isset($errors['race'])) { unset($errors['race']); } } if (isset($row['countryresident'])) { if (isset($_POST['countryresident_us']) && $_POST['countryresident_us'] == 'yes') { $countryresident = 'us'; } elseif (!isset($_POST['countryresident']) || !preg_match('/[A-Za-z]{2}/', $_POST['countryresident'])) { $errors['countryresident'] = true; } else { $countryresident = $_POST['countryresident']; } } if (isset($row['disability'])) { if (!isset($_POST['disability']) || $_POST['disability'] == 'yes' && ((!isset($_POST['specificDisability']) || !$_POST['specificDisability']) && (!isset($_POST['otherDisability']) || !trim($_POST['otherDisability'])))) { $errors['disability'] = true; } } if (isset($row['orgtype']) && !$orgtype) { $errors['orgtype'] = true; } if (isset($row['organization']) && !$organization) { $errors['organization'] = true; } if (isset($row['reason']) && !$reason) { $errors['reason'] = true; } if (isset($row['mailPreferenceOption']) && $mailPreferenceOption == -1) { $errors['mailPreferenceOption'] = true; } if (isset($row['location']) && !$location) { if (isset($_POST['location'])) { $location = trim($_POST['location']); } else { $errors['location'] = true; } } if ($errors) { require $this->getLayoutPath('popover'); } else { $dbh->setQuery('SELECT ' . implode(', ', array_keys($row)) . ' FROM #__profile_completion_awards WHERE user_id = ' . $uid); $award = 0; $awarded = $dbh->loadAssoc(); if (!empty($awarded)) { foreach ($awarded as $v) { if (!$v) { $award += $awardPer; } } } $dbh->setQuery('SELECT COALESCE((SELECT balance FROM `#__users_transactions` WHERE uid = ' . $uid . ' AND id = (SELECT MAX(id) FROM `#__users_transactions` WHERE uid = ' . $uid . ')), 0)'); $new_amount = $dbh->loadResult() + $award; if ($award) { $BTL = new \Hubzero\Bank\Teller($dbh, $uid); $BTL->deposit($award, Lang::txt('MOD_INCREMENTAL_REGISTRATION_PROFILE_COMPLETION_AWARD'), 'registration', 0); } $xp_update = 'UPDATE `#__xprofiles` SET '; $aw_update = 'UPDATE `#__profile_completion_awards` SET edited_profile = 1, '; $first = true; foreach (array_keys($row) as $k) { if ($k == 'race') { if (isset($race)) { $dbh->setQuery('DELETE FROM `#__xprofiles_race` WHERE uidNumber = ' . $uid); $dbh->execute(); foreach ($race as $r) { $dbh->setQuery('INSERT INTO `#__xprofiles_race` (uidNumber, race) VALUES (' . $uid . ', ' . $dbh->quote($r) . ')'); $dbh->execute(); } if (isset($_POST['racenativetribe'])) { $dbh->setQuery('UPDATE `#__xprofiles` SET nativeTribe = ' . $dbh->quote($_POST['racenativetribe']) . ' WHERE uidNumber = ' . $uid); $dbh->execute(); } } continue; } if ($k == 'disability') { $disabilities = array(); switch ($_POST['disability']) { case 'yes': $disabilities = isset($_POST['specificDisability']) && is_array($_POST['specificDisability']) ? $_POST['specificDisability'] : array(); if ($other = isset($_POST['otherDisability']) ? trim($_POST['otherDisability']) : NULL) { $disabilities[] = $other; } break; case 'no': $disabilities[] = 'none'; break; case 'refused': $disabilities[] = 'refused'; break; } foreach ($disabilities as $disability) { $dbh->setQuery('INSERT INTO `#__xprofiles_disability` (uidNumber, disability) VALUES (' . $uid . ', ' . $dbh->quote($disability) . ')'); $dbh->execute(); } continue; } if ($k == 'location') { $dbh->setQuery('INSERT INTO `#__xprofiles_address` (uidNumber, addressPostal) VALUES(' . $uid . ', ' . $dbh->quote($location) . ')'); $dbh->execute(); continue; } if ($k == 'name') { $dbh->setQuery('UPDATE `#__xprofiles` SET givenName = ' . $dbh->quote($_POST['name']['first']) . ', middleName = ' . $dbh->quote($_POST['name']['middle']) . ', surname = ' . $dbh->quote($_POST['name']['last']) . ' WHERE uidNumber = ' . $uid); $dbh->execute(); } if ($k == 'countryorigin' || $k == 'countryresident') { ${$k} = strtoupper(${$k}); } if (isset($row[$k])) { $xp_update .= ($first ? '' : ', ') . $k . ' = ' . $dbh->quote(${$k}); $aw_update .= ($first ? '' : ', ') . $k . ' = 1'; $first = false; } } if (!$first) { $dbh->setQuery($xp_update . ' WHERE uidNumber = ' . $uid); $dbh->execute(); $dbh->setQuery($aw_update . ' WHERE user_id = ' . $uid); $dbh->execute(); } require $this->getLayoutPath('thanks'); return; } } } else { if (!preg_match('%^/members/' . $uid . '/profile%', $uri) && $hasCurl) { require $this->getLayoutPath('curl'); } } } }
/** * Process a batch of records * * @return void */ public function process_batchTask() { // Check for request forgeries Request::checkToken(); $duplicate = 0; $log = Request::getVar('log', array()); $log = array_map('trim', $log); $log['category'] = $log['category'] ? $log['category'] : 'general'; $log['action'] = $log['action'] ? $log['action'] : 'batch'; $data = Request::getVar('transaction', array()); $data = array_map('trim', $data); $when = Date::toSql(); // make sure this function was not already run $MH = new MarketHistory($this->database); $duplicate = $MH->getRecord($ref, $action, $category, '', $data['description']); if ($data['amount'] && $data['description'] && $data['users']) { if (!$duplicate) { // run only once // get array of affected users $users = str_replace(' ', ',', $data['users']); $users = explode(',', $users); $users = array_unique($users); // get rid of duplicates foreach ($users as $user) { $validuser = \Hubzero\User\Profile::getInstance($user); if ($user && $validuser) { $BTL = new \Hubzero\Bank\Teller($this->database, $user); switch ($data['type']) { case 'withdraw': $BTL->withdraw($data['amount'], $data['description'], $log['category'], $log['ref']); break; case 'deposit': $BTL->deposit($data['amount'], $data['description'], $log['category'], $log['ref']); break; } } } // Save log $MH = new MarketHistory($this->database); $data['itemid'] = $log['ref']; $data['date'] = Date::toSql(); $data['market_value'] = $data['amount']; $data['category'] = $log['category']; $data['action'] = $log['action']; $data['log'] = $data['description']; if (!$MH->bind($data)) { $err = $MH->getError(); } if (!$MH->store()) { $err = $MH->getError(); } Notify::success(Lang::txt('Batch transaction was processed successfully.')); } else { Notify::warning(Lang::txt('This batch transaction was already processed earlier. Use a different identifier if you need to run it again.')); } } else { Notify::error(Lang::txt('Could not process. Some required fields are missing.')); } // show output if run manually App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=batch', false)); }
/** * Mark an entry as opted out * * @return mixed */ public function award() { if (!$this->uid) { return NULL; } $opts = new ModIncrementalRegistrationOptions(); $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 \Hubzero\Bank\Teller(self::$dbh, $this->uid); $BTL->deposit($alreadyComplete, 'Profile completion award', 'registration', 0); } return array('prior' => $prior, 'new' => $alreadyComplete, 'eligible' => $eligible, 'opted_out' => $optedOut); }