/** * Save Subscription * * @return void */ public function saveTask() { // Check for request forgeries Request::checkToken(); $id = Request::getInt('id', 0); $subscription = new Subscription($this->database); if (!$subscription->load($id)) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_SERVICES_SUBSCRIPTION_NOT_FOUND'), 'error'); return; } // get service $service = new Service($this->database); if (!$service->loadService('', $subscription->serviceid)) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_SERVICES_SERVICE_NOT_FOUND') . ' ' . $subscription->serviceid, 'error'); return; } $author = User::getInstance($subscription->uid); $subscription->notes = rtrim(stripslashes(Request::getVar('notes', ''))); $action = Request::getVar('action', ''); $message = Request::getVar('message', ''); $statusmsg = ''; $email = 0; switch ($action) { case 'refund': $received_refund = Request::getInt('received_refund', 0); $newunits = Request::getInt('newunits', 0); $pending = $subscription->pendingpayment - $received_refund; $pendingunits = $subscription->pendingunits - $newunits; $subscription->pendingpayment = $pending <= 0 ? 0 : $pending; $subscription->pendingunits = $pendingunits <= 0 ? 0 : $pendingunits; $email = 0; $statusmsg .= Lang::txt('Refund has been processed.'); break; case 'activate': $received_payment = Request::getInt('received_payment', 0); $newunits = Request::getInt('newunits', 0); $pending = $subscription->pendingpayment - $received_payment; $pendingunits = $subscription->pendingunits - $newunits; $subscription->pendingpayment = $pending <= 0 ? 0 : $pending; $subscription->pendingunits = $pendingunits <= 0 ? 0 : $pendingunits; $subscription->totalpaid = $subscription->totalpaid + $received_payment; $oldunits = $subscription->units; $months = $newunits * $service->unitsize; $newexpire = $oldunits > 0 && intval($subscription->expires) != 0 ? Date::of(strtotime($subscription->expires . "+" . $months . "months"))->format("Y-m-d") : Date::of(strtotime("+" . $months . "months"))->format("Y-m-d"); $subscription->expires = $newunits ? $newexpire : $subscription->expires; $subscription->status = 1; $subscription->units = $subscription->units + $newunits; $email = ($received_payment > 0 or $newunits > 0) ? 1 : 0; $statusmsg .= Lang::txt('COM_SERVICES_SUBSCRIPTION_ACTIVATED'); if ($newunits > 0) { $statusmsg .= ' ' . Lang::txt('for') . ' ' . $newunits . ' '; $statusmsg .= $oldunits > 0 ? Lang::txt('additional') . ' ' : ''; $statusmsg .= Lang::txt('month(s)'); } break; case 'message': $statusmsg .= Lang::txt('Your message has been sent.'); break; case 'cancelsub': $refund = 0; $unitsleft = $subscription->getRemaining('unit', $subscription, $service->maxunits, $service->unitsize); // get cost per unit (to compute required refund) $refund = $subscription->totalpaid > 0 && $unitsleft > 0 && $subscription->totalpaid - $unitsleft * $unitcost > 0 ? $unitsleft * $prevunitcost : 0; $subscription->status = 2; $subscription->pendingpayment = $refund; $subscription->pendingunits = $refund > 0 ? $unitsleft : 0; $email = 1; $statusmsg .= Lang::txt('COM_SERVICES_SUBSCRIPTION_CANCELLED'); break; } if ($action && $action != 'message' || $message) { $subscription->notes .= '------------------------------' . "\r\n"; $subscription->notes .= Lang::txt('COM_SERVICES_SUBSCRIPTION_STATUS_UPDATED') . ', ' . Date::toSql() . "\r\n"; $subscription->notes .= $statusmsg ? $statusmsg . "\r\n" : ''; $subscription->notes .= $message ? $message . "\r\n" : ''; $subscription->notes .= '------------------------------' . "\r\n"; } if (!$subscription->check()) { $this->setError($subscription->getError()); $this->editTask($subscription); return; } if (!$subscription->store()) { $this->setError($subscription->getError()); $this->editTask($subscription); return; } if ($email || $message) { // E-mail "from" info $from = array('email' => Config::get('mailfrom'), 'name' => Config::get('sitename') . ' ' . Lang::txt('COM_SERVICES_SUBSCRIPTIONS')); // start email message $subject = Lang::txt('COM_SERVICES_EMAIL_SUBJECT', $subscription->code); $emailbody = $subject . ':' . "\r\n"; $emailbody .= Lang::txt('COM_SERVICES_SUBSCRIPTION_SERVICE') . ' - ' . $service->title . "\r\n"; $emailbody .= '----------------------------------------------------------' . "\r\n"; $emailbody .= $action != 'message' && $statusmsg ? $statusmsg : ''; if ($message) { $emailbody .= "\r\n"; $emailbody .= $message; } if (!Event::trigger('xmessage.onSendMessage', array('subscriptions_message', $subject, $emailbody, $from, array($subscription->uid), $this->_option))) { \Notify::error(Lang::txt('COM_SERVICES_ERROR_FAILED_TO_MESSAGE')); } } App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_SERVICES_SUBSCRIPTION_SAVED') . ($statusmsg ? ' ' . $statusmsg : '')); }
/** * Dashboard * * @return void */ public function dashboardTask() { // Login required if (User::isGuest()) { \Notify::warning(Lang::txt('COM_JOBS_PLEASE_LOGIN_ACCESS_EMPLOYER')); $this->login(); return; } // Incoming message $this->_msg_passed = $this->_msg_passed ? $this->_msg_passed : Request::getVar('msg', ''); $uid = Request::getInt('uid', User::get('id')); if ($uid && User::get('id') != $uid && !$this->_admin) { // not authorized App::abort(403, Lang::txt('ALERTNOTAUTH')); } $uid = $uid ? $uid : User::get('id'); $admin = $this->_admin && !$this->_emp && User::get('id') == $uid ? 1 : 0; // Make sure we have special admin subscription if ($admin) { $this->_authorizeEmployer(1); } // Get the member's info $profile = new \Hubzero\User\Profile(); $profile->load($uid); // load Employer $employer = new Employer($this->database); if (!$employer->loadEmployer($uid) && !$this->_admin) { // send to subscription page App::redirect(Route::url('index.php?option=com_jobs&task=subscribe')); return; } else { if ($admin) { $employer->id = 1; } else { if (!isset($employer->id)) { App::abort(404, Lang::txt('COM_JOBS_ERROR_EMPLOYER_NOT_FOUND')); } } } // do we have a subscription already? $subscription = new Subscription($this->database); if (!$subscription->load($employer->subscriptionid) && !$this->_admin) { // send to subscription page App::redirect(Route::url('index.php?option=com_jobs&task=subscribe')); return; } $service = new Service($this->database); if (!$service->loadService('', $subscription->serviceid) && !$this->_admin) { App::abort(404, Lang::txt('COM_JOBS_ERROR_SERVICE_NOT_FOUND')); } else { // get service params like maxads $this->_getServiceParams($service); } // Get current stats for dashboard $jobstats = new JobStats($this->database); $stats = $jobstats->getStats($uid, 'employer', $admin); // Get job postings $job = new Job($this->database); $myjobs = $job->get_my_openings($uid, 0, $admin); $activejobs = $job->countMyActiveOpenings($uid, 1, $admin); // Push some styles to the template $this->css(); // Push some scripts to the template $this->js(); // Set page title $this->_buildTitle(); // Set the pathway $this->_buildPathway(); // Output HTML $this->view->title = $this->_title; $this->view->config = $this->config; $this->view->admin = $this->_admin; $this->view->masterAdmin = $this->_masterAdmin; $this->view->emp = 1; $this->view->task = $this->_task; $this->view->option = $this->_option; $this->view->updated = 0; $this->view->myjobs = $myjobs; $this->view->activejobs = $activejobs; $this->view->subscription = $subscription; $this->view->employer = $employer; $this->view->service = $service; $this->view->login = $profile->get('username'); $this->view->uid = $uid; $this->view->stats = $stats; // Set any errors if ($this->getError()) { \Notify::error($this->getError()); } $this->view->setName('dashboard')->setLayout('default')->display(); }