Ejemplo n.º 1
0
 /**
  * Display module contents
  *
  * @return  void
  */
 public function display()
 {
     if (!App::isAdmin()) {
         return;
     }
     $return = self::getReturnURI();
     $freturn = base64_encode('index.php?' . Request::getQueryString());
     $returnQueryString = !empty($return) ? "&return={$return}" : '';
     $authenticators = [];
     $plugins = \Plugin::byType('authentication');
     foreach ($plugins as $p) {
         $pparams = new Registry($p->params);
         // Make sure it supports admin login
         if (!$pparams->get('admin_login', false)) {
             continue;
         }
         // If it's the default hubzero plugin, don't include it in the list (we'll include it separately)
         if ($p->name == 'hubzero') {
             $site_display = $pparams->get('display_name', \Config::get('sitename'));
             $basic = true;
         } else {
             $display = $pparams->get('display_name', ucfirst($p->name));
             $authenticators[$p->name] = array('name' => $p->name, 'display' => $display);
         }
     }
     require $this->getLayoutPath($this->params->get('layout', 'default'));
 }
Ejemplo n.º 2
0
 /**
  * Get current progress
  *
  * At this point, this method only takes into account what students have viewed.
  * This makes sense on a PDF download, for example, but not on a quiz.  This
  * should be expanded to account for views on simpler asset types, and more complex
  * criteria on assets where it can be tracked (ex: videos, where we can track an
  * entire view, or an exam, where we know when they've actually finished it).
  *
  * @param      int $member_id
  * @return     array $progress
  */
 public function progress($member_id = null)
 {
     static $instances;
     $key = !is_null($member_id) ? serialize($member_id) : 'all';
     if (isset($instances[$key])) {
         return $instances[$key];
     }
     $offeringParams = new Registry($this->course->offering()->get('params'));
     $sectionParams = new Registry($this->course->offering()->section()->get('params'));
     $progress_calculation = $this->course->config()->get('progress_calculation', 'all');
     $progress_calculation = $offeringParams->get('progress_calculation', false) ? $offeringParams->get('progress_calculation') : $progress_calculation;
     $progress_calculation = $sectionParams->get('progress_calculation', false) ? $sectionParams->get('progress_calculation') : $progress_calculation;
     $filters = array('section_id' => $this->course->offering()->section()->get('id'), 'member_id' => $member_id);
     $dbo = \App::get('db');
     switch ($progress_calculation) {
         // Support legacy label of 'forms', as well as new, more accurate label of 'graded'
         case 'forms':
         case 'graded':
             // Get count of graded items taken
             $filters = array('member_id' => $member_id, 'scope' => 'asset', 'graded' => true);
             $grades = $this->_grades($filters);
             $views = array();
             foreach ($grades as $g) {
                 if (!is_null($g->score) || !is_null($g->override)) {
                     $views[] = (object) array('member_id' => $g->member_id, 'grade_weight' => $g->grade_weight, 'unit_id' => $g->unit_id, 'asset_id' => $g->scope_id);
                 }
             }
             break;
         case 'manual':
             $filters['progress_calculation'] = true;
             // Get the asset views
             $assetViews = new Tables\AssetViews($dbo);
             $views = $assetViews->find($filters);
             break;
         case 'videos':
             // Add another filter
             $filters['asset_type'] = 'video';
             // Get the asset views
             $assetViews = new Tables\AssetViews($dbo);
             $views = $assetViews->find($filters);
             break;
         case 'all':
         default:
             // Get the asset views
             $assetViews = new Tables\AssetViews($dbo);
             $views = $assetViews->find($filters);
             break;
     }
     $progress = array();
     // Restructure array
     foreach ($views as $v) {
         $progress[$v->member_id][$v->unit_id][$v->asset_id] = 1;
     }
     $counts = array();
     // Calculate unit completion percentage for each student
     // Note: this is not their score, but rather, simply how many items within the unit they have viewed/completed
     foreach ($progress as $member_id => $m) {
         foreach ($m as $unit_id => $unit) {
             if (!isset($counts[$unit_id])) {
                 // Get the assets
                 $asset = new Tables\Asset($dbo);
                 $filters = array('w' => array('course_id' => $this->course->get('id'), 'unit_id' => $unit_id, 'state' => 1, 'asset_scope' => 'asset_group'));
                 switch ($progress_calculation) {
                     // Support legacy label of 'forms', as well as new, more accurate label of 'graded'
                     case 'forms':
                     case 'graded':
                         $filters['w']['graded'] = true;
                         break;
                     case 'manual':
                         $filters['w']['section_id'] = $this->course->offering()->section()->get('id');
                         $filters['w']['progress_calculation'] = true;
                         break;
                     case 'videos':
                         $filters['w']['asset_type'] = 'video';
                         break;
                 }
                 $counts[$unit_id] = $asset->count($filters);
                 $counts[$unit_id] = $counts[$unit_id] ? $counts[$unit_id] : 1;
                 // Enforce 1. Can't divide by zero.
             }
             $progress[$member_id][$unit_id]['percentage_complete'] = round(array_sum($unit) / $counts[$unit_id] * 100, 2);
         }
     }
     $instances[$key] = $progress;
     return $progress;
 }
Ejemplo n.º 3
0
 /**
  * Saves an asset group
  *
  * @apiMethod POST
  * @apiUri    /courses/assetgroup/save
  * @apiParameter {
  * 		"name":        "id",
  * 		"description": "Asset group ID to edit",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "title",
  * 		"description": "Asset group title",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     "New asset group"
  * }
  * @apiParameter {
  * 		"name":        "state",
  * 		"description": "State of asset group",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "description",
  * 		"description": "Short description",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "unit_id",
  * 		"description": "ID of parent unit",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "parent",
  * 		"description": "ID of parent asset group",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "params",
  * 		"description": "Parameters related to the asset group",
  * 		"type":        "array",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @return    void
  */
 public function saveTask()
 {
     // Require authentication and authorization
     $this->authorizeOrFail();
     // Check for an incoming 'id'
     $id = Request::getInt('id', null);
     // Create an asset group instance
     $assetGroup = new Assetgroup($id);
     // Check to make sure we have an asset group object
     if (!is_object($assetGroup)) {
         App::abort(500, 'Failed to create an asset group object');
     }
     // We'll always save the title again, even if it's just to the same thing
     $title = $assetGroup->get('title');
     $title = !empty($title) ? $title : 'New asset group';
     // Set our variables
     $assetGroup->set('title', Request::getString('title', $title));
     $assetGroup->set('alias', strtolower(str_replace(' ', '', $assetGroup->get('title'))));
     // Save the asset group
     if (!$assetGroup->get('title')) {
         App::abort(400, 'No title provided');
     }
     $state = Request::getInt('state', null);
     if (!is_null($state)) {
         $assetGroup->set('state', $state);
     }
     $assetGroup->set('description', Request::getVar('description', $assetGroup->get('description')));
     // When creating a new asset group
     if (!$id) {
         $assetGroup->set('unit_id', Request::getInt('unit_id', 0));
         $assetGroup->set('parent', Request::getInt('parent', 0));
         $assetGroup->set('created', Date::toSql());
         $assetGroup->set('created_by', App::get('authn')['user_id']);
     }
     if (($params = Request::getVar('params', false, 'post')) || !$id) {
         $p = new Registry('');
         $db = App::get('db');
         $query = $db->getQuery(true);
         $query->select('folder AS type, element AS name, params')->from('#__extensions')->where('enabled >= 1')->where('type =' . $db->quote('plugin'))->where('state >= 0')->where('folder =' . $db->quote('courses'))->order('ordering');
         if ($plugins = $db->setQuery($query)->loadObjectList()) {
             foreach ($plugins as $plugin) {
                 $default = new Registry($plugin->params);
                 foreach ($default->toArray() as $k => $v) {
                     if (substr($k, 0, strlen('default_')) == 'default_') {
                         $p->set(substr($k, strlen('default_')), $default->get($k, $v));
                     }
                 }
             }
         }
         if ($params) {
             $p->parse($params);
         }
         $assetGroup->set('params', $p->toString());
     }
     // Save the asset group
     if (!$assetGroup->store()) {
         App::abort(500, 'Asset group save failed');
     }
     // Return message
     $this->send(['assetgroup_id' => $assetGroup->get('id'), 'assetgroup_title' => $assetGroup->get('title'), 'assetgroup_state' => (int) $assetGroup->get('state'), 'assetgroup_style' => 'display:none', 'course_id' => $this->course_id, 'offering_alias' => $this->offering_alias], $id ? 200 : 201);
 }
Ejemplo n.º 4
0
 /**
  * Add membership request for user
  *
  * @return  array
  */
 public function dorequestTask()
 {
     // Check if they're logged in
     if (User::isGuest()) {
         $this->loginTask(Lang::txt('COM_GROUPS_INVITE_MUST_BE_LOGGED_IN_TO_REQUEST'));
         return;
     }
     Request::checkToken();
     //check to make sure we have  cname
     if (!$this->cn) {
         $this->_errorHandler(400, Lang::txt('COM_GROUPS_ERROR_NO_ID'));
     }
     // Load the group page
     $this->view->group = Group::getInstance($this->cn);
     // Ensure we found the group info
     if (!$this->view->group || !$this->view->group->get('gidNumber')) {
         $this->_errorHandler(404, Lang::txt('COM_GROUPS_ERROR_NOT_FOUND'));
     }
     // Get the group params
     $gparams = new Registry($this->view->group->get('params'));
     // If membership is managed in seperate place disallow action
     if ($gparams->get('membership_control', 1) == 0) {
         $this->setNotification(Lang::txt('COM_GROUPS_MEMBERSHIP_MANAGED_ELSEWHERE'), 'error');
         App::redirect(Route::url('index.php?option=com_groups&cn=' . $this->view->group->get('cn')));
         return;
     }
     //make sure group has restricted policy
     if ($this->view->group->get('join_policy') != 1) {
         return;
     }
     //add user to applicants
     $this->view->group->add('applicants', array(User::get('id')));
     $this->view->group->update();
     // Instantiate the reason object and bind the incoming data
     $row = new Reason($this->database);
     $row->uidNumber = User::get('id');
     $row->gidNumber = $this->view->group->get('gidNumber');
     $row->reason = Request::getVar('reason', Lang::txt('GROUPS_NO_REASON_GIVEN'), 'post');
     $row->reason = \Hubzero\Utility\Sanitize::stripAll($row->reason);
     $row->date = Date::toSql();
     // Check and store the reason
     if (!$row->check()) {
         return App::abort(500, $row->getError());
     }
     if (!$row->store()) {
         return App::abort(500, $row->getError());
     }
     // Log the membership request
     Log::log(array('gidNumber' => $this->view->group->get('gidNumber'), 'action' => 'membership_requested', 'comments' => array(User::get('id'))));
     // Log activity
     $url = Route::url('index.php?option=' . $this->_option . '&cn=' . $this->view->group->get('cn'));
     $recipients = array(['group', $this->view->group->get('gidNumber')], ['user', User::get('id')]);
     foreach ($this->view->group->get('managers') as $recipient) {
         $recipients[] = ['user', $recipient];
     }
     Event::trigger('system.logActivity', ['activity' => ['action' => 'requested', 'scope' => 'group', 'scope_id' => $this->view->group->get('gidNumber'), 'description' => Lang::txt('COM_GROUPS_ACTIVITY_GROUP_USER_REQUESTED', '<a href="' . $url . '">' . $this->view->group->get('description') . '</a>'), 'details' => array('title' => $this->view->group->get('description'), 'url' => $url, 'cn' => $this->view->group->get('cn'), 'gidNumber' => $this->view->group->get('gidNumber'))], 'recipients' => $recipients]);
     // E-mail subject
     $subject = Lang::txt('COM_GROUPS_JOIN_REQUEST_EMAIL_SUBJECT', $this->view->group->get('cn'));
     // Build the e-mail message
     $eview = new \Hubzero\Component\View(array('name' => 'emails', 'layout' => 'request'));
     $eview->option = $this->_option;
     $eview->sitename = Config::get('sitename');
     $eview->user = User::getInstance();
     $eview->group = $this->view->group;
     $eview->row = $row;
     $html = $eview->loadTemplate();
     $html = str_replace("\n", "\r\n", $html);
     // Get the system administrator e-mail
     $emailadmin = Config::get('mailfrom');
     // Build the "from" portion of the e-mail
     $from = array();
     $from['name'] = Config::get('sitename') . ' ' . Lang::txt(strtoupper($this->_name));
     $from['email'] = Config::get('mailfrom');
     // build array of managers
     $managers = array();
     foreach ($this->view->group->get('managers') as $m) {
         $profile = User::getInstance($m);
         if ($profile) {
             $managers[$profile->get('email')] = $profile->get('name');
         }
     }
     // create new message
     $message = new \Hubzero\Mail\Message();
     // build message object and send
     $message->setSubject($subject)->addFrom($from['email'], $from['name'])->setTo($managers)->addHeader('X-Mailer', 'PHP/' . phpversion())->addHeader('X-Component', 'com_groups')->addHeader('X-Component-Object', 'group_membership_requested')->addPart($html, 'text/plain')->send();
     //tell the user they just did good
     $this->setNotification(Lang::txt('COM_GROUPS_INVITE_REQUEST_FORWARDED'), 'passed');
     // Push through to the groups listing
     App::redirect($url);
 }
Ejemplo n.º 5
0
 /**
  * Method to validate form data.
  *
  * Validation warnings will be pushed into Form::errors and should be
  * retrieved with Form::getErrors() when validate returns boolean false.
  *
  * @param   array   $data   An array of field values to validate.
  * @param   string  $group  The optional dot-separated form group path on which to filter the fields to be validated.
  * @return  mixed   True on sucess.
  */
 public function validate($data, $group = null)
 {
     // Make sure there is a valid Form XML document.
     if (!$this->xml instanceof SimpleXMLElement) {
         return false;
     }
     // Initialise variables.
     $return = true;
     // Create an input registry object from the data to validate.
     $input = new Registry($data);
     // Get the fields for which to validate the data.
     $fields = $this->findFieldsByGroup($group);
     if (!$fields) {
         // PANIC!
         return false;
     }
     // Validate the fields.
     foreach ($fields as $field) {
         // Initialise variables.
         $value = null;
         $name = (string) $field['name'];
         // Get the group names as strings for ancestor fields elements.
         $attrs = $field->xpath('ancestor::fields[@name]/@name');
         $groups = array_map('strval', $attrs ? $attrs : array());
         $group = implode('.', $groups);
         // Get the value from the input data.
         if ($group) {
             $value = $input->get($group . '.' . $name);
         } else {
             $value = $input->get($name);
         }
         // Validate the field.
         $valid = $this->validateField($field, $group, $value, $input);
         // Check for an error.
         if ($valid instanceof Exception) {
             if ($valid instanceof MissingData || $valid instanceof InvalidData) {
                 $this->errors[$name] = $valid;
                 $return = false;
             } else {
                 throw new Exception($valid->getMessage());
                 return false;
             }
         }
     }
     return $return;
 }
Ejemplo n.º 6
0
 /**
  * Display an offering asset
  *
  * @return     void
  */
 public function assetTask()
 {
     $sparams = new Registry($this->course->offering()->section()->get('params'));
     $section_id = $this->course->offering()->section()->get('id');
     $asset = new Models\Asset(Request::getInt('asset_id', null));
     $asset->set('section_id', $section_id);
     // First, check if current user has access to course
     if (!$this->course->offering()->access('view')) {
         // Is a preview available?
         $preview = $sparams->get('preview', 0);
         // If no preview is available or if type  is form (i.e. you can never preview forms)
         if (!$preview || $asset->get('type') == 'form') {
             // Check if they're logged in
             if (User::isGuest()) {
                 $this->loginTask(Lang::txt('COM_COURSES_ENROLLMENT_REQUIRED_FOR_ASSET'));
                 return;
             } else {
                 // Redirect back to the course outline
                 App::redirect(Route::url($this->course->offering()->link()), Lang::txt('COM_COURSES_ENROLLMENT_REQUIRED_FOR_ASSET'), 'warning');
                 return;
             }
         } elseif ($preview == 2) {
             $units = $asset->units();
             if ($units && count($units) > 0) {
                 foreach ($units as $unit) {
                     if ($unit->get('ordering') > 1) {
                         // Check if they're logged in
                         if (User::isGuest()) {
                             $this->loginTask(Lang::txt('COM_COURSES_ENROLLMENT_REQUIRED_FOR_ASSET'));
                             return;
                         } else {
                             // Redirect back to the course outline
                             App::redirect(Route::url($this->course->offering()->link()), Lang::txt('COM_COURSES_ENROLLMENT_REQUIRED_FOR_ASSET'), 'warning');
                             return;
                         }
                     }
                 }
             }
         }
     }
     // If not a manager and either the offering or section is unpublished...
     if (!$this->course->offering()->access('manage') && (!$this->course->offering()->isPublished() || !$this->course->offering()->section()->isPublished())) {
         return App::abort(403, Lang::txt('COM_COURSES_ERROR_ASSET_UNAVAILABLE'));
     }
     if (!$this->course->offering()->access('manage') && !$asset->isAvailable()) {
         // Allow expired forms to pass through (i.e. so students can see their results)
         if (!$asset->get('type') == 'form' || !$asset->ended()) {
             // Redirect back to the course outline
             App::redirect(Route::url($this->course->offering()->link()), Lang::txt('COM_COURSES_ERROR_ASSET_UNAVAILABLE'), 'warning');
             return;
         }
     }
     // Check prerequisites
     $member = $this->course->offering()->section()->member(User::get('id'));
     if (is_null($member->get('section_id'))) {
         $member->set('section_id', $section_id);
     }
     $prerequisites = $member->prerequisites($this->course->offering()->gradebook());
     if (!$this->course->offering()->access('manage') && !$prerequisites->hasMet('asset', $asset->get('id'))) {
         $prereqs = $prerequisites->get('asset', $asset->get('id'));
         $requirements = array();
         foreach ($prereqs as $pre) {
             $reqAsset = new Models\Asset($pre['scope_id']);
             $requirements[] = $reqAsset->get('title');
         }
         $requirements = implode(', ', $requirements);
         // Redirect back to the course outline
         App::redirect(Route::url($this->course->offering()->link()), Lang::txt('COM_COURSES_ERROR_ASSET_HAS_PREREQ', $requirements), 'warning');
         return;
     }
     // If requesting a file from a wiki type asset, then serve that up directly
     if ($asset->get('subtype') == 'wiki' && Request::getVar('file', false)) {
         echo $asset->download($this->course);
     }
     echo $asset->render($this->course);
 }
Ejemplo n.º 7
0
 /**
  *  Show confirm delete view
  *
  * @return  void
  */
 public function deleteTask()
 {
     // set the neeced layout
     $this->view->setLayout('delete');
     // Check if they're logged in
     if (User::isGuest()) {
         $this->loginTask(Lang::txt('COM_GROUPS_DELETE_MUST_BE_LOGGED_IN'));
         return;
     }
     //check to make sure we have  cname
     if (!$this->cn) {
         $this->_errorHandler(400, Lang::txt('COM_GROUPS_ERROR_NO_ID'));
     }
     // Load the group page
     $this->view->group = Group::getInstance($this->cn);
     // Ensure we found the group info
     if (!$this->view->group || !$this->view->group->get('gidNumber')) {
         $this->_errorHandler(404, Lang::txt('COM_GROUPS_ERROR_NOT_FOUND'));
     }
     // Check authorization
     if ($this->_authorize() != 'manager') {
         $this->_errorHandler(403, Lang::txt('COM_GROUPS_ERROR_NOT_AUTH'));
     }
     // Get the group params
     $gparams = new Registry($this->view->group->get('params'));
     // If membership is managed in seperate place disallow action
     if ($gparams->get('membership_control', 1) == 0) {
         $this->setNotification(Lang::txt('COM_GROUPS_MEMBERSHIP_MANAGED_ELSEWHERE'), 'error');
         App::redirect(Route::url('index.php?option=com_groups&cn=' . $this->view->group->get('cn')));
         return;
     }
     //start log
     $this->view->log = Lang::txt('COM_GROUPS_DELETE_MEMBER_LOG', count($this->view->group->get('members')));
     // Trigger the functions that delete associated content
     // Should return logs of what was deleted
     $logs = Event::trigger('groups.onGroupDeleteCount', array($this->view->group));
     if (count($logs) > 0) {
         $this->view->log .= '<br />' . implode('<br />', $logs);
     }
     // build the title
     $this->_buildTitle();
     // build pathway
     $this->_buildPathway();
     // get view notifications
     $this->view->notifications = $this->getNotifications() ? $this->getNotifications() : array();
     //set some vars for view
     $this->view->title = Lang::txt('COM_GROUPS_DELETE_GROUP') . ': ' . $this->view->group->get('description');
     $this->view->msg = Request::getVar('msg', '');
     //display view
     $this->view->display();
 }
Ejemplo n.º 8
0
 /**
  * Send Newsletter
  *
  * @param   $newsletter
  * @param   $newsletterHtmlContent
  * @param   $newsletterPlainContent
  * @param   $newsletterContacts
  * @param   $newsletterMailinglist
  * @param   $sendingTest
  * @return  object
  */
 private function _send($newsletter, $newsletterHtmlContent, $newsletterPlainContent, $newsletterContacts, $newsletterMailinglist, $sendingTest = false)
 {
     //set default mail from and reply-to names and addresses
     $defaultMailFromName = Config::get("sitename") . ' Newsletter';
     $defaultMailFromAddress = 'contact@' . $_SERVER['HTTP_HOST'];
     $defaultMailReplytoName = Config::get("sitename") . ' Newsletter - Do Not Reply';
     $defaultMailReplytoAddress = 'do-not-reply@' . $_SERVER['HTTP_HOST'];
     //get the config mail from and reply-to names and addresses
     $mailFromName = $this->config->get('newsletter_from_name', $defaultMailFromName);
     $mailFromAddress = $this->config->get('newsletter_from_address', $defaultMailFromAddress);
     $mailReplytoName = $this->config->get('newsletter_replyto_name', $defaultMailReplytoName);
     $mailReplytoAddress = $this->config->get('newsletter_replyto_address', $defaultMailReplytoAddress);
     //parse newsletter specific emails
     $params = new Registry($newsletter->params);
     $mailFromName = $params->get('from_name', $mailFromName);
     $mailFromAddress = $params->get('from_address', $mailFromAddress);
     $mailReplytoName = $params->get('replyto_name', $mailReplytoName);
     $mailReplytoAddress = $params->get('replyto_address', $mailReplytoAddress);
     //set final mail from and reply-to
     $mailFrom = '"' . $mailFromName . '" <' . $mailFromAddress . '>';
     $mailReplyTo = '"' . $mailReplytoName . '" <' . $mailReplytoAddress . '>';
     //set subject and body
     $mailSubject = $newsletter->name ? $newsletter->name : 'Your ' . Config::get("sitename") . '.org Newsletter';
     $mailHtmlBody = $newsletterHtmlContent;
     $mailPlainBody = $newsletterPlainContent;
     //set mail headers
     //$mailHeaders  = "MIME-Version: 1.0" . "\r\n";
     //$mailHeaders .= "Content-type: text/html; charset=\"UTF-8\"" . "\r\n";
     $mailHeaders = "From: {$mailFrom}" . "\r\n";
     $mailHeaders .= "Reply-To: {$mailReplyTo}" . "\r\n";
     //set mail priority
     $mailHeaders .= "X-Priority: 3" . "\r\n";
     //$mailHeaders .= "X-MSMail-Priority: Normal" . "\r\n";
     //$mailHeaders .= "Importance: Normal\n";
     //set extra headers
     $mailHeaders .= "X-Mailer: PHP/" . phpversion() . "\r\n";
     $mailHeaders .= "X-Component: " . $this->_option . "\r\n";
     $mailHeaders .= "X-Component-Object: Campaign Mailing" . "\r\n";
     $mailHeaders .= "X-Component-ObjectId: {{CAMPAIGN_MAILING_ID}}" . "\r\n";
     //$mailHeaders .= "List-Unsubscribe: <mailto:{{UNSUBSCRIBE_MAILTO_LINK}}>, <{{UNSUBSCRIBE_LINK}}>";
     //set mail args
     $mailArgs = '';
     //$mailArgs = '-f hubmail-bounces@' . $_SERVER['HTTP_HOST'];
     //are we sending test mailing
     if ($sendingTest) {
         foreach ($newsletterContacts as $contact) {
             // get tracking & unsubscribe token
             $recipient = new stdClass();
             $recipient->email = $contact;
             $recipient->mailingid = $newsletterMailinglist ? $newsletterMailinglist : -1;
             $emailToken = \Components\Newsletter\Helpers\Helper::generateMailingToken($recipient);
             // create unsubscribe link
             $unsubscribeMailtoLink = '';
             $unsubscribeLink = 'https://' . $_SERVER['SERVER_NAME'] . '/newsletter/unsubscribe?e=' . urlencode($contact) . '&t=' . $emailToken;
             // add unsubscribe link - placeholder & in header (must do after adding tracking!!)
             $mailHtmlBody = str_replace("{{UNSUBSCRIBE_LINK}}", $unsubscribeLink, $mailHtmlBody);
             $mailPlainBody = str_replace("{{UNSUBSCRIBE_LINK}}", $unsubscribeLink, $mailPlainBody);
             // create new message
             $message = new \Hubzero\Mail\Message();
             foreach (explode("\r\n", $mailHeaders) as $header) {
                 $parts = array_map("trim", explode(':', $header));
                 switch ($parts[0]) {
                     case 'From':
                         if (preg_match("/\\\"([^\"]*)\\\"\\s<([^>]*)>/ux", $parts[1], $matches)) {
                             $message->setFrom(array($matches[2] => $matches[1]));
                         }
                         break;
                     case 'Reply-To':
                         if (preg_match("/\\\"([^\"]*)\\\"\\s<([^>]*)>/ux", $parts[1], $matches)) {
                             $message->setReplyTo(array($matches[2] => $matches[1]));
                         }
                         break;
                     case 'Importance':
                     case 'X-Priority':
                     case 'X-MSMail-Priority':
                         $priority = isset($parts[1]) && in_array($parts[1], array(1, 2, 3, 4, 5)) ? $parts[1] : 3;
                         $message->setPriority($priority);
                         break;
                     default:
                         if (isset($parts[1])) {
                             $message->addHeader($parts[0], $parts[1]);
                         }
                 }
             }
             // build message object and send
             $message->setSubject('[SENDING TEST] - ' . $mailSubject)->setTo($contact)->addPart($mailHtmlBody, 'text/html')->addPart($mailPlainBody, 'text/plain')->send();
         }
         return true;
     }
     //get the scheduling
     $scheduler = Request::getInt('scheduler', 1);
     if ($scheduler == '1') {
         $scheduledDate = Date::toSql();
     } else {
         $schedulerDate = Request::getVar('scheduler_date', '');
         $schedulerHour = Request::getVar('scheduler_date_hour', '00');
         $schedulerMinute = Request::getVar('scheduler_date_minute', '00');
         $schedulerMeridian = Request::getVar('scheduler_date_meridian', 'AM');
         //make sure we have at least the date or we use now
         if (!$schedulerDate) {
             $scheduledDate = Date::toSql();
         }
         //break apart parts of date
         $schedulerDateParts = explode('/', $schedulerDate);
         //make sure its in 24 time
         if ($schedulerMeridian == 'pm') {
             $schedulerHour += 12;
         }
         //build scheduled time
         $scheduledTime = $schedulerDateParts[2] . '-' . $schedulerDateParts[0] . '-' . $schedulerDateParts[1];
         $scheduledTime .= ' ' . $schedulerHour . ':' . $schedulerMinute . ':00';
         $scheduledDate = Date::of(strtotime($scheduledTime))->toSql();
     }
     //create mailing object
     $mailing = new stdClass();
     $mailing->nid = $newsletter->id;
     $mailing->lid = $newsletterMailinglist;
     $mailing->subject = $mailSubject;
     $mailing->html_body = $mailHtmlBody;
     $mailing->plain_body = $mailPlainBody;
     $mailing->headers = $mailHeaders;
     $mailing->args = $mailArgs;
     $mailing->tracking = $newsletter->tracking;
     $mailing->date = $scheduledDate;
     //save mailing object
     $newsletterMailing = new Mailing($this->database);
     if (!$newsletterMailing->save($mailing)) {
         $this->setError(Lang::txt('COM_NEWSLETTER_NEWSLETTER_SEND_FAIL'));
         $this->sendNewsletterTask();
         return;
     }
     // create recipients
     $this->_sendTo($newsletterMailing, $newsletterContacts);
     return $newsletterMailing;
 }
Ejemplo n.º 9
0
 /**
  * Display module content
  *
  * @return  void
  */
 public function display()
 {
     // [!] Legacy compatibility for older view overrides
     $params = $this->params;
     $module = $this->module;
     // Make sure we're using a secure connection
     if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') {
         \App::redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
         die('insecure connection and redirection failed');
     }
     // Get and add the js and extra css to the page
     $this->css('login.css', 'com_users');
     $this->css('providers.css', 'com_users');
     $this->js('login', 'com_users');
     $this->css('uniform.css', 'system');
     $this->js('jquery.uniform', 'system');
     $this->js('jquery.hoverIntent', 'system');
     $type = self::getType();
     $return = Request::getVar('return', null);
     $freturn = base64_encode($_SERVER['REQUEST_URI']);
     // If we have a return set with an authenticator in it, we're linking an existing account
     // Parse the return to retrive the authenticator, and remove it from the list below
     $auth = '';
     if ($areturn = Request::getVar('return', null)) {
         $areturn = base64_decode($areturn);
         $query = parse_url($areturn);
         if (is_array($query) && isset($query['query'])) {
             $query = $query['query'];
             $query = explode('&', $query);
             $auth = '';
             foreach ($query as $q) {
                 $n = explode('=', $q);
                 if ($n[0] == 'authenticator') {
                     $auth = $n[1];
                 }
             }
         }
     }
     // Figure out whether or not any of our third party auth plugins are turned on
     // Don't include the 'hubzero' plugin, or the $auth plugin as described above
     $multiAuth = false;
     $plugins = Plugin::byType('authentication');
     $authenticators = array();
     foreach ($plugins as $p) {
         if ($p->name != 'hubzero' && $p->name != $auth) {
             $pparams = new Registry($p->params);
             $display = $pparams->get('display_name', ucfirst($p->name));
             $authenticators[] = array('name' => $p->name, 'display' => $display);
             $multiAuth = true;
         } else {
             if ($p->name == 'hubzero') {
                 $pparams = new Registry($p->params);
                 $remember_me_default = $pparams->get('remember_me_default', 0);
             }
         }
     }
     Plugin::import('authentication');
     // Set the return if we have it...
     $returnQueryString = $return ? "&return={$return}" : '';
     require $this->getLayoutPath();
 }
Ejemplo n.º 10
0
 /**
  * Display an order
  *
  * @return     void
  */
 public function orderTask()
 {
     $this->view->store_enabled = $this->config->get('store_enabled');
     // Incoming
     $id = Request::getInt('id', 0);
     // Load data
     $this->view->row = new Order($this->database);
     $this->view->row->load($id);
     $oi = new OrderItem($this->database);
     $this->view->orderitems = array();
     $this->view->customer = null;
     $this->view->funds = 0;
     if ($id) {
         // Get order items
         $this->view->orderitems = $oi->getOrderItems($id);
         if (count($this->view->orderitems) > 0) {
             foreach ($this->view->orderitems as $r) {
                 $params = new Registry($r->params);
                 $selections = new Registry($r->selections);
                 // Get size selection
                 $r->sizes = $params->get('size', '');
                 $r->sizes = str_replace(' ', '', $r->sizes);
                 $r->sizes = preg_split('#,#', $r->sizes);
                 $r->selectedsize = trim($selections->get('size', ''));
                 $r->sizeavail = in_array($r->selectedsize, $r->sizes) ? 1 : 0;
                 // Get color selection
                 $r->colors = $params->get('color', '');
                 $r->colors = str_replace(' ', '', $r->colors);
                 $r->colors = preg_split('#,#', $r->colors);
                 $r->selectedcolor = trim($selections->get('color', ''));
             }
         }
         $this->view->customer = User::getInstance($this->view->row->uid);
         // Check available user funds
         $BTL = new Teller($this->database, $this->view->row->uid);
         $balance = $BTL->summary();
         $credit = $BTL->credit_summary();
         $this->view->funds = $balance;
     }
     // Set any errors
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     // Output the HTML
     $this->view->display();
 }
Ejemplo n.º 11
0
 /**
  * Display a list of all citations, with filtering&search options.
  *
  * @return		 string HTML
  */
 private function _browse()
 {
     // Instantiate a new citations object
     $obj = $this->_filterHandler(Request::getVar('filters', array()), $this->group->get('gidNumber'));
     $count = clone $obj['citations'];
     $count = $count->count();
     $isManager = $this->authorized == 'manager' ? true : false;
     $config = new \Hubzero\Config\Registry($this->group->get('params'));
     $display = $config->get('display');
     $total = \Components\Citations\Models\Citation::all()->where('scope', '=', self::PLUGIN_SCOPE)->where('scope_id', '=', $this->group->get('gidNumber'))->where('published', '=', \Components\Citations\Models\Citation::STATE_PUBLISHED)->count();
     // for first-time use
     if ($count == 0 && $isManager && !isset($display)) {
         // have a group manager set the settings
         App::redirect(Route::url('index.php?option=com_groups&cn=' . $this->group->cn . '&active=citations&action=settings'), Lang::txt('Please select your settings for this group.'), 'warning');
     } elseif ((int) $count == 0 && $isManager && isset($display) && $total <= 0) {
         $view = $this->view('intro', 'browse');
         $view->group = $this->group;
         $view->isManager = $this->authorized == 'manager' ? true : false;
     } else {
         // initialize the view
         $view = $this->view('default', 'browse');
         // push objects to the view
         $view->group = $this->group;
         $view->option = $this->option;
         $view->task = $this->_name;
         $view->database = $this->database;
         $view->title = Lang::txt(strtoupper($this->_name));
         $view->isManager = $this->authorized == 'manager' ? true : false;
         $view->config = $config;
     }
     // get applied filters
     $view->filters = $obj['filters'];
     // only display published citations to non-managers.
     if ($view->isManager) {
         // get filtered citations
         $view->citations = $obj['citations']->paginated()->rows();
     } else {
         $view->citations = $obj['citations']->where('published', '=', \Components\Citations\Models\Citation::STATE_PUBLISHED)->paginated()->rows();
     }
     // get the earliest year we have citations for
     $view->earliest_year = 2001;
     // Contribution filter
     $view->filterlist = array('all' => Lang::txt('PLG_GROUPS_CITATIONS_ALL'), 'member' => Lang::txt('PLG_GROUPS_CITATIONS_MEMBERCONTRIB'));
     // set default values for required filters for this view.
     $view->filters['search'] = isset($view->filters['search']) ? $view->filters['search'] : "";
     $view->filters['type'] = isset($view->filters['type']) ? $view->filters['type'] : "";
     $view->filters['tag'] = isset($view->filters['tag']) ? $view->filters['tag'] : "";
     $view->filters['author'] = isset($view->filters['author']) ? $view->filters['author'] : "";
     $view->filters['publishedin'] = isset($view->filters['publishedin']) ? $view->filters['publishedin'] : "";
     $view->filters['year_start'] = isset($view->filters['year_start']) ? $view->filters['year_start'] : "";
     $view->filters['year_end'] = isset($view->filters['year_end']) ? $view->filters['year_end'] : "";
     $view->filters['startuploaddate'] = isset($view->filters['startuploaddate']) ? $view->filters['startuploaddate'] : "";
     $view->filters['enduploaddate'] = isset($view->filters['enduploaddate']) ? $view->filters['enduploaddate'] : "";
     $view->filters['sort'] = isset($view->filters['sort']) ? $view->filters['sort'] : "";
     $view->filters['filter'] = isset($view->filters['filter']) ? $view->filters['filter'] : "";
     // Sort Filter
     $view->sorts = array('year DESC' => Lang::txt('PLG_GROUPS_CITATIONS_YEAR'), 'created DESC' => Lang::txt('PLG_GROUPS_CITATIONS_NEWEST'), 'title ASC' => Lang::txt('PLG_GROUPS_CITATIONS_TITLE'), 'author ASC' => Lang::txt('PLG_GROUPS_CITATIONS_AUTHOR'), 'journal ASC' => Lang::txt('PLG_GROUPS_CITATIONS_JOURNAL'));
     // Handling ids of the the boxes checked for download
     $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
     $session = App::get('session');
     // If it's new search remove all user citation checkmarks
     if (isset($_POST['filter'])) {
         $view->filters['idlist'] = "";
         $session->set('idlist', $view->filters['idlist']);
     } else {
         $view->filters['idlist'] = Request::getVar('idlist', $session->get('idlist'));
         $session->set('idlist', $view->filters['idlist']);
     }
     // Reset the filter if the user came from a different section
     if (strpos($referer, "/citations/browse") == false) {
         $view->filters['idlist'] = "";
         $session->set('idlist', $view->filters['idlist']);
     }
     // get the preferred labeling scheme
     $view->label = "both";
     if ($view->label == "none") {
         $view->citations_label_class = "no-label";
     } elseif ($view->label == "number") {
         $view->citations_label_class = "number-label";
     } elseif ($view->label == "type") {
         $view->citations_label_class = "type-label";
     } elseif ($view->label == "both") {
         $view->citations_label_class = "both-label";
     } else {
         $view->citations_label_class = "both-label";
     }
     // enable coins support
     $view->coins = 1;
     // types
     $ct = \Components\Citations\Models\Type::all();
     $view->types = $ct;
     // OpenURL
     $openURL = $this->_handleOpenURL();
     $view->openurl['link'] = $openURL['link'];
     $view->openurl['text'] = $openURL['text'];
     $view->openurl['icon'] = $openURL['icon'];
     // Output HTML
     foreach ($this->getErrors() as $error) {
         $view->setError($error);
     }
     return $view->loadTemplate();
 }
Ejemplo n.º 12
0
 /**
  * Fix Joomla version in #__extensions table if wrong (doesn't equal JVersion short version)
  *
  * @return   mixed  string update version if success, false if fail
  */
 public function fixUpdateVersion()
 {
     $table = \JTable::getInstance('Extension');
     $table->load('700');
     $cache = new Registry($table->manifest_cache);
     $updateVersion = $cache->get('version');
     $cmsVersion = new \JVersion();
     if ($updateVersion == $cmsVersion->getShortVersion()) {
         return $updateVersion;
     } else {
         $cache->set('version', $cmsVersion->getShortVersion());
         $table->manifest_cache = $cache->toString();
         if ($table->store()) {
             return $cmsVersion->getShortVersion();
         } else {
             return false;
         }
     }
 }