/** * 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(); }
/** * 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'); }
/** * 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; }
/** * Display a form for adding a question * * @param object $row * @return string */ private function _new($row = null) { // Login required if (User::isGuest()) { $rtrn = Request::getVar('REQUEST_URI', Route::url('index.php?option=' . $this->option . '&id=' . $this->model->resource->id . '&active=' . $this->_name, false, true), 'server'); App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($rtrn)), Lang::txt('PLG_RESOURCES_QUESTIONS_LOGIN_TO_ASK_QUESTION'), 'warning'); return; } Lang::load('com_answers', PATH_ROOT) || Lang::load('com_answers', PATH_CORE . DS . 'com_answers' . DS . 'site'); $view = $this->view('new', 'question'); $view->option = $this->option; $view->resource = $this->model->resource; if (is_object($row)) { $view->row = $row; } else { $view->row = new \Components\Answers\Models\Question(0); } $view->tag = $this->filters['tag']; // Are we banking? $upconfig = Component::params('com_members'); $view->banking = $upconfig->get('bankAccounts'); $view->funds = 0; if ($view->banking) { $BTL = new \Hubzero\Bank\Teller($this->database, User::get('id')); $funds = $BTL->summary() - $BTL->credit_summary(); $view->funds = $funds > 0 ? $funds : 0; } foreach ($this->getErrors() as $error) { $view->setError($error); } return $view->loadTemplate(); }
/** * 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(); }
/** * Display a form for adding a question * * @param object $row * @return string */ private function _new($row = null) { // Login required if (User::isGuest()) { App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($_SERVER['REQUEST_URI'])), Lang::txt('PLG_PUBLICATIONS_QUESTIONS_LOGIN_TO_ASK_QUESTION'), 'warning'); return; } $view = $this->view('new', 'question'); $view->option = $this->option; $view->publication = $this->publication; if (!is_object($row)) { $row = new \Components\Answers\Models\Question(); } $view->row = $row; $view->tag = $this->filters['tag']; // Are we banking? $upconfig = Component::params('com_members'); $view->banking = $upconfig->get('bankAccounts'); $view->funds = 0; if ($view->banking) { $BTL = new \Hubzero\Bank\Teller($this->database, User::get('id')); $funds = $BTL->summary() - $BTL->credit_summary(); $view->funds = $funds > 0 ? $funds : 0; } foreach ($this->getErrors() as $error) { $view->setError($error); } return $view->loadTemplate(); }
/** * 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; }
/** * Display a form for adding a question * * @param object $row * @return string */ private function _new($row = null) { // Login required if (User::isGuest()) { $rtrn = Request::getVar('REQUEST_URI', Route::url('index.php?option=' . $this->option . '&id=' . $this->publication->id . '&active=' . $this->_name, false, true), 'server'); App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($rtrn)), Lang::txt('PLG_PUBLICATIONS_QUESTIONS_LOGIN_TO_ASK_QUESTION'), 'warning'); return; } if (!is_object($row)) { $row = new \Components\Answers\Models\Question(); } // Are we banking? $banking = Component::params('com_members')->get('bankAccounts'); $funds = 0; if ($banking) { $BTL = new \Hubzero\Bank\Teller(User::get('id')); $funds = $BTL->summary() - $BTL->credit_summary(); $funds = $funds > 0 ? $funds : 0; } $view = $this->view('new', 'question')->set('option', $this->option)->set('publication', $this->publication)->set('row', $row)->set('tag', $this->filters['tag'])->set('banking', $banking)->set('funds', $funds); foreach ($this->getErrors() as $error) { $view->setError($error); } return $view->loadTemplate(); }