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); } }
/** * Edit Subscription * * @return void */ public function editTask($row = null) { Request::setVar('hidemainmenu', 1); if (!is_object($row)) { $id = Request::getInt('id', 0); $row = new Subscription($this->database); $this->view->subscription = $row->getSubscription($id); } $this->view->subscription = $row; if (!$this->view->subscription) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_SERVICES_SUBSCRIPTION_NOT_FOUND')); return; } $this->view->customer = User::getInstance($this->view->subscription->uid); // check available user funds $BTL = new \Hubzero\Bank\Teller($this->database, $this->view->subscription->uid); $balance = $BTL->summary(); $credit = $BTL->credit_summary(); $funds = $balance; $this->view->funds = $funds > 0 ? $funds : '0'; // Set any errors foreach ($this->getErrors() as $error) { $this->view->setError($error); } // Output the HTML $this->view->setLayout('edit')->display(); }
/** * Event call to return data for a specific member * * @param object $user User * @param object $member Profile * @param string $option Component name * @param string $areas Plugins to return data * @return array Return array of html */ public function onMembers($user, $member, $option, $areas) { $returnhtml = true; $returnmeta = true; // Check if our area is in the array of areas we want to return results for if (is_array($areas)) { if (!array_intersect($areas, $this->onMembersAreas($user, $member)) && !array_intersect($areas, array_keys($this->onMembersAreas($user, $member)))) { $returnhtml = false; } } $arr = array('html' => '', 'metadata' => ''); $database = App::get('db'); $tables = $database->getTableList(); $table = $database->getPrefix() . 'users_points'; if (!in_array($table, $tables)) { $arr['html'] = '<p class="error">' . Lang::txt('PLG_MEMBERS_POINTS_ERROR_MISSING_TABLE') . '</p>'; return $arr; } $BTL = new \Hubzero\Bank\Teller($member->get('id')); // Build the final HTML if ($returnhtml) { $view = $this->view('default', 'history'); $view->sum = $BTL->summary(); $view->credit = $BTL->credit_summary(); $funds = $view->sum - $view->credit; $view->funds = $funds > 0 ? $funds : 0; $view->hist = $BTL->history(0); if ($this->getError()) { $view->setError($this->getError()); } $arr['html'] = $view->loadTemplate(); } // Build the HTML meant for the "about" tab's metadata overview if ($returnmeta) { $arr['metadata'] = array(); $points = $BTL->summary(); $prefix = $user->get('id') == $member->get('id') ? 'I have' : $member->get('name') . ' has'; $title = $prefix . ' ' . $points . ' points.'; $arr['metadata']['count'] = $points; } return $arr; }
/** * Retrieves a row from the database * * @param string $refid ID of the database table row * @param string $category Element type (determines table to look in) * @param string $parent If the element has a parent element * @return array */ public function transferItem($from_type, $from_id, $to_type, $rid = 0, $deactivate = 1) { $upconfig = Component::params('com_members'); $this->banking = $upconfig->get('bankAccounts'); $database = App::get('db'); if ($from_type == NULL or $from_id == NULL or $to_type == NULL) { $this->setError(Lang::txt('PLG_SUPPORT_TRANSFER_ERROR_MISSING_INFO')); return false; } if ($from_type == $to_type) { $this->setError(Lang::txt('PLG_SUPPORT_TRANSFER_ERROR_CATEGORIES_MUST_BE_DIFFERENT')); return false; } // collectors $author = ''; $subject = ''; $body = ''; $tags = ''; $owner = ''; // name of group owning the item $anonymous = 0; // get needed scripts include_once PATH_CORE . DS . 'components' . DS . 'com_support' . DS . 'models' . DS . 'ticket.php'; include_once PATH_CORE . DS . 'components' . DS . 'com_answers' . DS . 'models' . DS . 'question.php'; include_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'models' . DS . 'wishlist.php'; $wconfig = Component::params('com_wishlist'); $admingroup = $wconfig->get('group') ? $wconfig->get('group') : 'hubadmin'; // Get needed scripts & initial data switch ($from_type) { // Transfer from a Support Ticket case 'ticket': $row = new \Components\Support\Models\Ticket($from_id); if ($row->exists()) { $author = $row->get('login'); $subject = $row->content('raw', 200); // max 200 characters $body = $row->get('summary'); $owner = $row->get('group'); // If we are de-activating original item if ($deactivate) { $row->set('status', 2); $row->set('resolved', 'transfered'); } $tags = $row->tags('string'); } else { $this->setError(Lang::txt('PLG_SUPPORT_TRANSFER_ERROR_ITEM_NOT_FOUND')); return false; } break; // Transfer from a Question // Transfer from a Question case 'question': $row = new \Components\Answers\Models\Question($from_id); if ($row->exists()) { $author = $row->get('created_by'); $subject = $row->subject('raw', 200); // max 200 characters $body = $row->get('question'); $anonymous = $row->get('anonymous'); // If we are de-activating original item if ($deactivate) { $row->set('state', 2); $row->set('reward', 0); } $tags = $row->tags('string'); } else { $this->setError(Lang::txt('PLG_SUPPORT_TRANSFER_ERROR_ITEM_NOT_FOUND')); return false; } break; // Transfer from a Wish // Transfer from a Wish case 'wish': $row = new \Components\Wishlist\Tables\Wish($database); $row->load($from_id); if ($row->id) { $author = $row->proposed_by; $subject = \Hubzero\Utility\String::truncate($row->subject, 200); // max 200 characters $body = $row->about; $anonymous = $row->anonymous; // If we are de-activating original item if ($deactivate) { $row->status = 2; $row->ranking = 0; // also delete all previous votes for this wish $objR = new \Components\Wishlist\Tables\Rank($database); $objR->remove_vote($from_id); } // get owner $objG = new \Components\Wishlist\Tables\OwnerGroup($database); $nativegroups = $objG->get_owner_groups($row->wishlist, $admingroup, '', 1); $owner = count($nativegroups) > 0 && $nativegroups[0] != $admingroup ? $nativegroups[0] : ''; // tool group $objWishlist = new \Components\Wishlist\Tables\Wishlist($database); $wishlist = $objWishlist->get_wishlist($row->wishlist); if (isset($wishlist->resource) && isset($wishlist->resource->alias)) { $tags = $wishlist->resource->type == 7 ? 'tool:' : 'resource:'; $tags .= $wishlist->resource->alias ? $wishlist->resource->alias : $wishlist->referenceid; } } else { $this->setError(Lang::txt('PLG_SUPPORT_TRANSFER_ERROR_ITEM_NOT_FOUND')); return false; } break; } // if no author can be found, use current administrator $author = User::getInstance($author); if (!is_object($author)) { $author = User::getInstance(User::get('id')); } $today = Date::toSql(); // Where do we transfer? switch ($to_type) { // Transfer to a Support Ticket case 'ticket': $newrow = new \Components\Support\Models\Ticket(); $newrow->set('open', 1); $newrow->set('status', 0); $newrow->set('created', $today); $newrow->set('login', $author->get('username')); $newrow->set('severity', 'normal'); $newrow->set('summary', $subject); $newrow->set('report', $body ? $body : $subject); $newrow->set('section', 1); $newrow->set('type', 0); $newrow->set('instances', 1); $newrow->set('email', $author->get('email')); $newrow->set('name', $author->get('name')); // do we have an owner group? $newrow->set('group', $owner ? $owner : ''); break; case 'question': $newrow = new \Components\Answers\Models\Question(); $newrow->set('subject', $subject); $newrow->set('question', $body); $newrow->set('created', $today); $newrow->set('created_by', $author->get('id')); $newrow->set('state', 0); $newrow->set('anonymous', $anonymous); break; case 'wish': $newrow = new \Components\Wishlist\Models\Wish(); $newrow->set('subject', $subject); $newrow->set('about', $body); $newrow->set('proposed', $today); $newrow->set('proposed_by', $author->get('id')); $newrow->set('status', 0); $newrow->set('anonymous', $anonymous); // which wishlist? $objWishlist = new \Components\Wishlist\Tables\Wishlist($database); $mainlist = $objWishlist->get_wishlistID(1, 'general'); $listid = 0; if (!$rid && $owner) { $rid = $this->getResourceIdFromGroup($owner); } if ($rid) { $listid = $objWishlist->get_wishlistID($rid); } $newrow->set('wishlist', $listid ? $listid : $mainlist); break; } // Save new information if (!$newrow->store()) { $this->setError($newrow->getError()); return; } else { // Checkin ticket //$newrow->checkin(); // Extras if ($newrow->exists()) { switch ($to_type) { case 'ticket': // Tag new ticket if ($tags) { $newrow->tag($tags, User::get('id'), 0); } break; case 'question': // Tag new question if ($tags) { $newrow->tag($tags, User::get('id'), 0); } break; } } } // If we are de-activating original item if ($deactivate) { // overwrite old entry if (!$row->store()) { $this->setError($row->getError()); exit; } // Clean up rewards if banking if ($this->banking) { switch ($from_type) { case 'ticket': // no banking yet break; case 'question': $reward = \Hubzero\Bank\Transaction::getAmount('answers', 'hold', $from_id, $author->get('id')); // Remove hold if ($reward) { \Hubzero\Bank\Transaction::deleteRecords('answers', 'hold', $from_id); // Make credit adjustment $BTL_Q = new \Hubzero\Bank\Teller($author->get('id')); $credit = $BTL_Q->credit_summary(); $adjusted = $credit - $reward; $BTL_Q->credit_adjustment($adjusted); } break; case 'wish': include_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'helpers' . DS . 'economy.php'; $WE = new \Components\Wishlist\Helpers\Economy($database); $WE->cleanupBonus($from_id); break; } } } return $newrow->get('id'); }
/** * 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)); }
/** * Save a question and redirect to the main listing when done * * @return void */ private function _save() { // Login required if (User::isGuest()) { return $this->_browse(); } // Check for request forgeries Request::checkToken(); Lang::load('com_answers'); // Incoming $tags = Request::getVar('tags', ''); $funds = Request::getInt('funds', 0); $reward = Request::getInt('reward', 0); // If offering a reward, do some checks if ($reward) { // Is it an actual number? if (!is_numeric($reward)) { App::abort(500, Lang::txt('COM_ANSWERS_REWARD_MUST_BE_NUMERIC')); return; } // Are they offering more than they can afford? if ($reward > $funds) { App::abort(500, Lang::txt('COM_ANSWERS_INSUFFICIENT_FUNDS')); return; } } // Initiate class and bind posted items to database fields $fields = Request::getVar('question', array(), 'post', 'none', 2); $row = new \Components\Answers\Models\Question($fields['id']); if (!$row->bind($fields)) { $this->setError($row->getError()); return $this->_new($row); } if ($reward && $this->banking) { $row->set('reward', 1); } // Ensure the user added a tag /* if (!$tags) { $this->setError(Lang::txt('COM_ANSWERS_QUESTION_MUST_HAVE_TAG')); return $this->_new($row); } */ // Store new content if (!$row->store(true)) { $row->set('tags', $tags); $this->setError($row->getError()); return $this->_new($row); } // Hold the reward for this question if we're banking if ($reward && $this->banking) { $BTL = new \Hubzero\Bank\Teller($this->database, User::get('id')); $BTL->hold($reward, Lang::txt('COM_ANSWERS_HOLD_REWARD_FOR_BEST_ANSWER'), 'answers', $row->get('id')); } // Add the tags $row->tag($tags); // Add the tag to link to the resource $tag = $this->model->isTool() ? 'tool:' . $this->model->resource->alias : 'resource:' . $this->model->resource->id; $row->addTag($tag, User::get('id'), $this->model->isTool() ? 0 : 1); // Get users who need to be notified on every question $config = Component::params('com_answers'); $apu = $config->get('notify_users', ''); $apu = explode(',', $apu); $apu = array_map('trim', $apu); $receivers = array(); // Get tool contributors if question is about a tool if ($tags) { $tags = explode(',', $tags); if (count($tags) > 0) { require_once PATH_CORE . DS . 'components' . DS . 'com_tools' . DS . 'tables' . DS . 'author.php'; require_once PATH_CORE . DS . 'components' . DS . 'com_tools' . DS . 'tables' . DS . 'version.php'; $TA = new \Components\Tools\Tables\Author($this->database); $objV = new \Components\Tools\Tables\Version($this->database); if ($this->model->isTool()) { $toolname = $this->model->resource->alias; $rev = $objV->getCurrentVersionProperty($toolname, 'revision'); $authors = $TA->getToolAuthors('', 0, $toolname, $rev); if (count($authors) > 0) { foreach ($authors as $author) { $receivers[] = $author->uidNumber; } } } } } if (!empty($apu)) { foreach ($apu as $u) { $user = User::getInstance($u); if ($user) { $receivers[] = $user->get('id'); } } } $receivers = array_unique($receivers); // Send the message if (!empty($receivers)) { // Send a message about the new question to authorized users (specified admins or related content authors) $from = array('email' => Config::get('mailfrom'), 'name' => Config::get('sitename') . ' ' . Lang::txt('COM_ANSWERS_ANSWERS'), 'multipart' => md5(date('U'))); // Build the message subject $subject = Lang::txt('COM_ANSWERS_ANSWERS') . ', ' . Lang::txt('new question about content you author or manage'); // Build the message $eview = new \Hubzero\Mail\View(array('base_path' => PATH_CORE . DS . 'components' . DS . 'com_answers' . DS . 'site', 'name' => 'emails', 'layout' => 'question_plaintext')); $eview->option = 'com_answers'; $eview->sitename = Config::get('sitename'); $eview->question = $row; $eview->id = $row->get('id', 0); $eview->boundary = $from['multipart']; $message['plaintext'] = $eview->loadTemplate(false); $message['plaintext'] = str_replace("\n", "\r\n", $message['plaintext']); // HTML message $eview->setLayout('question_html'); $message['multipart'] = $eview->loadTemplate(); $message['multipart'] = str_replace("\n", "\r\n", $message['multipart']); if (!Event::trigger('xmessage.onSendMessage', array('new_question_admin', $subject, $message, $from, $receivers, 'com_answers'))) { $this->setError(Lang::txt('COM_ANSWERS_MESSAGE_FAILED')); } } // Redirect to the question App::redirect(Route::url('index.php?option=' . $this->option . '&id=' . $this->model->resource->id . '&active=' . $this->_name)); }
/** * Subscription form * * @return void */ public function subscribeTask() { // Login required if (User::isGuest()) { \Notify::warning(Lang::txt('COM_JOBS_PLEASE_LOGIN_ACCESS_EMPLOYER')); $this->login(); return; } // are we viewing other person's subscription? (admins only) $uid = Request::getInt('uid', 0); if ($uid && User::get('id') != $uid && !$this->_admin) { // not authorized App::abort(403, Lang::txt('COM_JOBS_ALERTNOTAUTH')); } $uid = $uid ? $uid : User::get('id'); // Set page title $this->_buildTitle(); // Set the pathway $this->_buildPathway(); // Push some styles to the template $this->css(); // Push some scripts to the template $this->js(); // Get the member's info $profile = new \Hubzero\User\Profile(); $profile->load($uid); // load Employer $employer = new Employer($this->database); if (!$employer->loadEmployer($uid)) { $employer = new Employer($this->database); $employer->uid = $uid; $employer->subscriptionid = 0; $employer->companyName = $profile->get('organization'); $employer->companyLocation = $profile->get('countryresident'); $employer->companyWebsite = $profile->get('url'); } // do we have an active subscription already? $subscription = new Subscription($this->database); if (!$subscription->loadSubscription($employer->subscriptionid, '', '', $status = array(0, 1))) { $subscription = new Subscription($this->database); $subscription->uid = $uid; $subscription->serviceid = 0; } // get subscription options $objS = new Service($this->database); $specialgroup = $this->config->get('specialgroup', ''); if ($specialgroup) { $sgroup = \Hubzero\User\Group::getInstance($specialgroup); if (!$sgroup) { $specialgroup = ''; } } $services = $objS->getServices('jobs', 1, 1, 'ordering', 'ASC', $specialgroup); if (!$services) { // setup with default info $this->_setupServices(); } // check available user funds (if paying with points) $BTL = new \Hubzero\Bank\Teller($this->database, $subscription->uid); $balance = $BTL->summary(); $credit = $BTL->credit_summary(); $funds = $balance; $funds = $funds > 0 ? $funds : '0'; // Output HTML $this->view->title = $this->_title; $this->view->config = $this->config; $this->view->subscription = $subscription; $this->view->employer = $employer; $this->view->services = $services; $this->view->funds = $funds; $this->view->uid = $uid; $this->view->emp = $this->_emp; $this->view->admin = $this->_admin; $this->view->task = $this->_task; $this->view->option = $this->_option; // Set any errors if ($this->getError()) { \Notify::error($this->getError()); } $this->view->setName('subscribe')->setLayout('default')->display(); }
/** * Save a question and redirect to the main listing when done * * @return void */ private function _save() { // Login required if (User::isGuest()) { return $this->_browse(); } // Check for request forgeries Request::checkToken(); // Incoming $tags = Request::getVar('tags', ''); $funds = Request::getInt('funds', 0); $reward = Request::getInt('reward', 0); // If offering a reward, do some checks if ($reward) { // Is it an actual number? if (!is_numeric($reward)) { App::abort(500, Lang::txt('COM_ANSWERS_REWARD_MUST_BE_NUMERIC')); return; } // Are they offering more than they can afford? if ($reward > $funds) { App::abort(500, Lang::txt('COM_ANSWERS_INSUFFICIENT_FUNDS')); return; } } // Initiate class and bind posted items to database fields $fields = Request::getVar('question', array(), 'post', 'none', 2); $row = \Components\Answers\Models\Question::oneOrNew($fields['id'])->set($fields); if ($reward && $this->banking) { $row->set('reward', 1); } // Store new content if (!$row->save()) { $this->setError($row->getError()); return $this->_new($row); } // Hold the reward for this question if we're banking if ($reward && $this->banking) { $BTL = new \Hubzero\Bank\Teller($this->database, User::get('id')); $BTL->hold($reward, Lang::txt('COM_ANSWERS_HOLD_REWARD_FOR_BEST_ANSWER'), 'answers', $row->get('id')); } // Add the tags $row->tag($tags); // Add the tag to link to the publication $identifier = $this->publication->get('alias') ? $this->publication->get('alias') : $this->publication->get('id'); $tag = $this->publication->isTool() ? 'tool' . $identifier : 'publication' . $identifier; $row->addTag($tag, User::get('id'), $this->publication->isTool() ? 0 : 1); // Redirect to the question App::redirect(Route::url($this->publication->link() . '&active=questions')); }
/** * Removes an item reported as abusive * * @param integer $referenceid ID of the database table row * @param integer $parentid If the element has a parent element * @param string $category Element type (determines table to look in) * @param string $message Message to user to append to * @return string */ public function deleteReportedItem($referenceid, $parentid, $category, $message) { if (!$this->_canHandle($category)) { return null; } $database = App::get('db'); switch ($category) { case 'answer': $database->setQuery("UPDATE `#__answers_responses` SET state='2' WHERE id=" . $referenceid); if (!$database->query()) { $this->setError($database->getErrorMsg()); return false; } $message .= Lang::txt('PLG_SUPPORT_ANSWERS_NOTIFY_ANSWER_REMOVED', $parentid); break; case 'question': $upconfig = Component::params('com_members'); $banking = $upconfig->get('bankAccounts'); $reward = 0; if ($banking) { $reward = $this->getReward($parentid); } $responders = array(); // Get all the answers for this question $database->setQuery("SELECT r.id, r.created_by FROM `#__answers_responses` AS r WHERE r.question_id=" . $referenceid); $answers = $database->loadObjectList(); if ($answers) { foreach ($answers as $answer) { // Delete response $database->setQuery("UPDATE `#__answers_responses` SET state='2' WHERE id=" . $answer->id); if (!$database->query()) { $this->setError($database->getErrorMsg()); return false; } // Collect responders names $responders[] = $answer->created_by; } } $database->setQuery("UPDATE `#__answers_questions` SET state='2', reward='0' WHERE id=" . $referenceid); if (!$database->query()) { $this->setError($database->getErrorMsg()); return false; } if ($banking && $reward) { // Send email to people who answered question with reward if ($responders) { foreach ($responders as $r) { $zuser = User::getInstance($r); if (is_object($zuser)) { if (\Components\Support\Helpers\Utilities::checkValidEmail($zuser->get('email')) && $email) { $admin_email = Config::get('mailfrom'); $sub = Lang::txt('PLG_SUPPORT_ANSWERS_SUBJECT', Config::get('sitename'), $referenceid); $from = Lang::txt('PLG_SUPPORT_ANSWERS_TITLE', Config::get('sitename')); $hub = array('email' => $admin_email, 'name' => $from); $mes = Lang::txt('PLG_SUPPORT_ANSWERS_BODY') . "\r\n"; $mes .= '----------------------------' . "\r\n\r\n"; $mes .= Lang::txt('PLG_SUPPORT_ANSWERS_QUESTION', $referenceid) . "\r\n"; \Components\Support\Helpers\Utilities::sendEmail($hub, $zuser->get('email'), $sub, $mes); } } } } // get id of asker $database->setQuery("SELECT created_by FROM `#__answers_questions` WHERE id=" . $parentid); $asker = $database->loadResult(); if ($asker) { $quser = User::getInstance($asker); if (is_object($quser)) { $asker_id = $quser->get('id'); } if (isset($asker_id)) { // Remove hold $sql = "DELETE FROM `#__users_transactions` WHERE category='answers' AND type='hold' AND referenceid=" . $parentid . " AND uid='" . $asker_id . "'"; $database->setQuery($sql); if (!$database->query()) { $this->setError($database->getErrorMsg()); return false; } // Make credit adjustment $BTL_Q = new \Hubzero\Bank\Teller($database, $asker_id); $credit = $BTL_Q->credit_summary(); $adjusted = $credit - $reward; $BTL_Q->credit_adjustment($adjusted); } } } $message .= Lang::txt('PLG_SUPPORT_ANSWERS_NOTIFY_QUESTION_REMOVED', $parentid); break; case 'answercomment': $comment = new \Hubzero\Item\Comment($database); $comment->load($referenceid); $comment->state = 2; if (!$comment->store()) { $this->setError($comment->getError()); return false; } $message .= Lang::txt('PLG_SUPPORT_ANSWERS_NOTIFY_COMMENT_REMOVED', $parentid); break; } return $message; }
/** * 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); }