Example #1
0
 /**
  * Saves changes to a group or saves a new entry if creating
  *
  * @return void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $g = Request::getVar('group', array(), 'post', 'none', 2);
     $g = $this->_multiArrayMap('trim', $g);
     // Instantiate a Group object
     $group = new Group();
     // Is this a new entry or updating?
     $isNew = false;
     if (!$g['gidNumber']) {
         $isNew = true;
         // Set the task - if anything fails and we re-enter edit mode
         // we need to know if we were creating new or editing existing
         $this->_task = 'new';
         $before = new Group();
     } else {
         $this->_task = 'edit';
         // Load the group
         $group->read($g['gidNumber']);
         $before = clone $group;
     }
     $task = $this->_task == 'edit' ? 'edit' : 'create';
     if (!$this->authorize($task, $group)) {
         return;
     }
     // Check for any missing info
     if (!$g['cn']) {
         $this->setError(Lang::txt('COM_GROUPS_ERROR_MISSING_INFORMATION') . ': ' . Lang::txt('COM_GROUPS_ID'));
     }
     if (!$g['description']) {
         $this->setError(Lang::txt('COM_GROUPS_ERROR_MISSING_INFORMATION') . ': ' . Lang::txt('COM_GROUPS_TITLE'));
     }
     // Push back into edit mode if any errors
     if ($this->getError()) {
         $this->view->setLayout('edit');
         $this->view->group = $group;
         // Set any errors
         if ($this->getError()) {
             $this->view->setError($this->getError());
         }
         // Output the HTML
         $this->view->display();
         return;
     }
     $g['cn'] = strtolower($g['cn']);
     // Ensure the data passed is valid
     if (!$this->_validCn($g['cn'], true)) {
         $this->setError(Lang::txt('COM_GROUPS_ERROR_INVALID_ID'));
     }
     //only check if cn exists if we are creating or have changed the cn
     if ($this->_task == 'new' || $group->get('cn') != $g['cn']) {
         if (Group::exists($g['cn'], true)) {
             $this->setError(Lang::txt('COM_GROUPS_ERROR_GROUP_ALREADY_EXIST'));
         }
     }
     // Push back into edit mode if any errors
     if ($this->getError()) {
         $this->view->setLayout('edit');
         $this->view->group = $group;
         // Set any errors
         if ($this->getError()) {
             $this->view->setError($this->getError());
         }
         // Output the HTML
         $this->view->display();
         return;
     }
     // group params
     $gparams = new Registry($group->get('params'));
     $gparams->merge(new Registry($g['params']));
     // set membership control param
     $membership_control = isset($g['params']['membership_control']) ? 1 : 0;
     $gparams->set('membership_control', $membership_control);
     $params = $gparams->toString();
     // Set the group changes and save
     $group->set('cn', $g['cn']);
     $group->set('type', $g['type']);
     if ($isNew) {
         $group->create();
         $group->set('published', 1);
         $group->set('approved', 1);
         $group->set('created', Date::toSql());
         $group->set('created_by', User::get('id'));
         $group->add('managers', array(User::get('id')));
         $group->add('members', array(User::get('id')));
     }
     $group->set('description', $g['description']);
     $group->set('discoverability', $g['discoverability']);
     $group->set('join_policy', $g['join_policy']);
     $group->set('public_desc', $g['public_desc']);
     $group->set('private_desc', $g['private_desc']);
     $group->set('restrict_msg', $g['restrict_msg']);
     $group->set('logo', $g['logo']);
     $group->set('plugins', $g['plugins']);
     $group->set('discussion_email_autosubscribe', $g['discussion_email_autosubscribe']);
     $group->set('params', $params);
     $group->update();
     // create home page
     if ($isNew) {
         // create page
         $page = new Page(array('gidNumber' => $group->get('gidNumber'), 'parent' => 0, 'lft' => 1, 'rgt' => 2, 'depth' => 0, 'alias' => 'overview', 'title' => 'Overview', 'state' => 1, 'privacy' => 'default', 'home' => 1));
         $page->store(false);
         // create page version
         $version = new Page\Version(array('pageid' => $page->get('id'), 'version' => 1, 'content' => "<!-- {FORMAT:HTML} -->\n<p>[[Group.DefaultHomePage()]]</p>", 'created' => Date::of('now')->toSql(), 'created_by' => User::get('id'), 'approved' => 1));
         $version->store(false);
     }
     // Get plugins
     Event::trigger('groups.onGroupAfterSave', array($before, $group));
     // log edit
     Log::log(array('gidNumber' => $group->get('gidNumber'), 'action' => 'group_edited', 'comments' => 'edited by administrator'));
     // handle special groups
     if ($group->isSuperGroup()) {
         $this->_handleSuperGroup($group);
         // git lab stuff
         $this->_handSuperGroupGitlab($group);
     }
     // Output messsage and redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_GROUPS_SAVED'));
 }
 /**
  * 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);
 }
Example #3
0
 /**
  * Save a citation
  *
  * @return	void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     $citation = array_map('trim', Request::getVar('citation', array(), 'post'));
     $exclude = Request::getVar('exclude', '', 'post');
     $rollover = Request::getInt("rollover", 0);
     $this->tags = Request::getVar('tags', '');
     $this->badges = Request::getVar('badges', '');
     $this->sponsors = Request::getVar('sponsors', array(), 'post');
     // toggle the affiliation
     if (!isset($citation['affiliated']) || $citation['affiliated'] == NULL) {
         $citation['affiliated'] = 0;
     }
     // toggle fundeby
     if (!isset($citation['fundedby']) || $citation['fundedby'] == NULL) {
         $citation['fundedby'] = 0;
     }
     // Bind incoming data to object
     $row = new Citation($this->database);
     if (!$row->bind($citation)) {
         $this->row = $row;
         $this->setError($row->getError());
         $this->editTask();
         return;
     }
     //set params
     $cparams = new Registry($this->_getParams($row->id));
     $cparams->set('exclude', $exclude);
     $cparams->set('rollover', $rollover);
     $row->params = $cparams->toString();
     // New entry so set the created date
     if (!$row->id) {
         $row->created = \Date::toSql();
     }
     // Check content for missing required data
     if (!$row->check()) {
         $this->row = $row;
         $this->setError($row->getError());
         $this->editTask();
         return;
     }
     // Store new content
     if (!$row->store()) {
         $this->row = $row;
         $this->setError($row->getError());
         $this->editTask();
         return;
     }
     // Incoming associations
     $arr = Request::getVar('assocs', array(), 'post');
     $ignored = array();
     foreach ($arr as $a) {
         $a = array_map('trim', $a);
         // Initiate extended database class
         $assoc = new Association($this->database);
         //check to see if we should delete
         if (isset($a['id']) && $a['tbl'] == '' && $a['oid'] == '') {
             // Delete the row
             if (!$assoc->delete($a['id'])) {
                 throw new Exception($assoc->getError(), 500);
             }
         } else {
             if ($a['tbl'] != '' || $a['oid'] != '') {
                 $a['cid'] = $row->id;
                 // bind the data
                 if (!$assoc->bind($a)) {
                     throw new Exception($assoc->getError(), 500);
                 }
                 // Check content
                 if (!$assoc->check()) {
                     throw new Exception($assoc->getError(), 500);
                 }
                 // Store new content
                 if (!$assoc->store()) {
                     throw new Exception($assoc->getError(), 500);
                 }
             }
         }
     }
     //save sponsors on citation
     if ($this->sponsors) {
         $cs = new Sponsor($this->database);
         $cs->addSponsors($row->id, $this->sponsors);
     }
     //add tags & badges
     $ct = new Tags($row->id);
     $ct->setTags($this->tags, User::get('id'), 0, 1, '');
     $ct->setTags($this->badges, User::get('id'), 0, 1, 'badge');
     // Redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('CITATION_SAVED'));
 }
Example #4
0
 /**
  * Method to filter the form data.
  *
  * @param   array   $data   An array of field values to filter.
  * @param   string  $group  The dot-separated form group path on which to filter the fields.
  * @return  mixed   Array or false.
  */
 public function filter($data, $group = null)
 {
     // Make sure there is a valid Form XML document.
     if (!$this->xml instanceof SimpleXMLElement) {
         return false;
     }
     // Initialise variables.
     $input = new Registry($data);
     $output = new Registry();
     // Get the fields for which to filter the data.
     $fields = $this->findFieldsByGroup($group);
     if (!$fields) {
         // PANIC!
         return false;
     }
     // Filter the fields.
     foreach ($fields as $field) {
         // Initialise variables.
         $name = (string) $field['name'];
         // Get the field groups for the element.
         $attrs = $field->xpath('ancestor::fields[@name]/@name');
         $groups = array_map('strval', $attrs ? $attrs : array());
         $group = implode('.', $groups);
         // Get the field value from the data input.
         if ($group) {
             // Filter the value if it exists.
             if ($input->exists($group . '.' . $name)) {
                 $output->set($group . '.' . $name, $this->filterField($field, $input->get($group . '.' . $name, (string) $field['default'])));
             }
         } else {
             // Filter the value if it exists.
             if ($input->exists($name)) {
                 $output->set($name, $this->filterField($field, $input->get($name, (string) $field['default'])));
             }
         }
     }
     return $output->toArray();
 }
Example #5
0
 /**
  * Save campaign task
  *
  * @return 	void
  */
 public function saveTask($apply = false)
 {
     //get post
     $newsletter = Request::getVar("newsletter", array(), 'post', 'ARRAY', JREQUEST_ALLOWHTML);
     //make sure we have valid alias
     if ($newsletter['alias']) {
         $newsletter['alias'] = str_replace(" ", "", strtolower($newsletter['alias']));
     } else {
         $newsletter['alias'] = str_replace(" ", "", strtolower($newsletter['name']));
     }
     //get unique newsletter name
     $newsletterId = isset($newsletter['id']) ? $newsletter['id'] : null;
     $newsletter['alias'] = $this->_getUniqueNewsletterAlias($newsletter['alias'], $newsletterId);
     //instantiate campaign object
     $newsletterNewsletter = new Letter($this->database);
     //do we need to set the created and created_by
     if (!isset($newsletter['id'])) {
         //update the modified info
         $newsletter['created'] = Date::toSql();
         $newsletter['created_by'] = User::get('id');
     } else {
         $newsletterNewsletter->load($newsletter['id']);
     }
     //did we have params
     if (isset($newsletter['params'])) {
         //load previous params
         $params = new Registry($newsletterNewsletter->params);
         //set from name
         if (isset($newsletter['params']['from_name'])) {
             $params->set('from_name', $newsletter['params']['from_name']);
         }
         //set from address
         if (isset($newsletter['params']['from_address'])) {
             $params->set('from_address', $newsletter['params']['from_address']);
         }
         //set reply-to name
         if (isset($newsletter['params']['replyto_name'])) {
             $params->set('replyto_name', $newsletter['params']['replyto_name']);
         }
         //set reply-to address
         if (isset($newsletter['params']['replyto_address'])) {
             $params->set('replyto_address', $newsletter['params']['replyto_address']);
         }
         //newsletter params to string
         $newsletter['params'] = $params->toString();
     }
     //update the modified info
     $newsletter['modified'] = Date::toSql();
     $newsletter['modified_by'] = User::get('id');
     // if no plain text was entered lets take the html content
     if (isset($newsletter['plain_content'])) {
         if ($newsletter['plain_content'] == '') {
             $newsletter['plain_content'] = strip_tags($newsletter['html_content']);
             $newsletter['plain_content'] = preg_replace('/(?:(?:\\r\\n|\\r|\\n)\\s*){2}\\n/', '', $newsletter['plain_content']);
         }
         // remove html from plain content
         $newsletter['plain_content'] = strip_tags($newsletter['plain_content']);
     }
     //save campaign
     if (!$newsletterNewsletter->save($newsletter)) {
         $this->newsletter = new stdClass();
         $this->newsletter->id = $newsletterNewsletter->id;
         $this->newsletter->alias = $newsletterNewsletter->alias;
         $this->newsletter->name = $newsletterNewsletter->name;
         $this->newsletter->issue = $newsletterNewsletter->issue;
         $this->newsletter->type = $newsletterNewsletter->type;
         $this->newsletter->template = $newsletterNewsletter->template;
         $this->newsletter->published = $newsletterNewsletter->published;
         $this->newsletter->sent = $newsletterNewsletter->sent;
         $this->newsletter->html_content = $newsletterNewsletter->html_content;
         $this->newsletter->plain_content = $newsletterNewsletter->plain_content;
         $this->newsletter->tracking = $newsletterNewsletter->tracking;
         $this->newsletter->created = $newsletterNewsletter->created;
         $this->newsletter->created_by = $newsletterNewsletter->created_by;
         $this->newsletter->modified = $newsletterNewsletter->modified;
         $this->newsletter->modified_by = $newsletterNewsletter->modified_by;
         $this->newsletter->params = $newsletterNewsletter->params;
         // set the id so we can pick up the stories
         Request::setVar('id', array($this->newsletter->id));
         $this->setError($newsletterNewsletter->getError());
         $this->editTask();
         return;
     } else {
         // set success message
         Notify::success(Lang::txt('COM_NEWSLETTER_SAVED_SUCCESS'));
         // redirect back to campaigns list
         App::redirect(Route::url('index.php?option=com_newsletter&controller=newsletter', false));
         // if we just created campaign go back to edit form so we can add content
         if (!isset($newsletter['id']) || $apply) {
             App::redirect(Route::url('index.php?option=com_newsletter&controller=newsletter&task=edit&id=' . $newsletterNewsletter->id, false));
         }
     }
 }
Example #6
0
 /**
  * For version 2.5.x only
  * Check if com_config parameters are blank. If so, populate with com_content text filters.
  *
  * @return  mixed  boolean true if params are updated, null otherwise
  */
 public function fixDefaultTextFilters()
 {
     $table = \JTable::getInstance('Extension');
     $table->load($table->find(array('name' => 'com_config')));
     // Check for empty $config and non-empty content filters
     if (!$table->params) {
         // Get filters from com_content and store if you find them
         $contentParams = Component::params('com_content');
         if ($contentParams->get('filters')) {
             $newParams = new Registry();
             $newParams->set('filters', $contentParams->get('filters'));
             $table->params = (string) $newParams;
             $table->store();
             return true;
         }
     }
 }