Exemple #1
0
 /**
  * Saves an entry
  *
  * @return  void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.create', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     User::setState('com_forum.edit.section.data', null);
     // Incoming
     $fields = Request::getVar('fields', array(), 'post');
     $fields = array_map('trim', $fields);
     // Initiate extended database class
     $section = Section::oneOrNew($fields['id'])->set($fields);
     // Bind the rules.
     $data = Request::getVar('jform', array(), 'post');
     if (isset($data['rules']) && is_array($data['rules'])) {
         $model = new AdminSection();
         $form = $model->getForm($data, false);
         $validData = $model->validate($form, $data);
         $section->assetRules = new \JAccessRules($validData['rules']);
     }
     if (!$section->save()) {
         Notify::error($section->getError());
         return $this->editTask($section);
     }
     Notify::success(Lang::txt('COM_FORUM_SECTION_SAVED'));
     if ($this->getTask() == 'apply') {
         return $this->editTask($section);
     }
     // Redirect
     $this->cancelTask();
 }
Exemple #2
0
 /**
  * Displays a question response for editing
  *
  * @param   object  $category
  * @return  void
  */
 public function editTask($category = null)
 {
     Request::setVar('hidemainmenu', 1);
     if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.create', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     // Incoming
     $section = Section::oneOrNew(Request::getInt('section_id', 0));
     if (!is_object($category)) {
         $id = Request::getVar('id', array(0));
         if (is_array($id)) {
             $id = !empty($id) ? intval($id[0]) : 0;
         }
         $category = Category::oneOrNew($id);
     }
     if ($category->isNew()) {
         $category->set('created_by', User::get('id'));
         $category->set('section_id', $section->get('id'));
         $category->set('scope', $section->get('scope'));
         $category->set('scope_id', $section->get('scope_id'));
     }
     $data = Section::all()->ordered()->rows();
     $sections = array();
     foreach ($data as $s) {
         $ky = $s->scope . ' (' . $s->scope_id . ')';
         if ($s->scope == 'site') {
             $ky = '[ site ]';
         }
         if (!isset($sections[$ky])) {
             $sections[$ky] = array();
         }
         $sections[$ky][] = $s;
         asort($sections[$ky]);
     }
     User::setState('com_forum.edit.category.data', array('id' => $category->get('id'), 'asset_id' => $category->get('asset_id')));
     $m = new AdminCategory();
     // Output the HTML
     $this->view->set('row', $category)->set('section', $section)->set('sections', $sections)->set('form', $m->getForm())->setLayout('edit')->display();
 }
Exemple #3
0
 /**
  * Saves a section and redirects to main page afterward
  *
  * @return  void
  */
 public function saveTask()
 {
     // Is the user logged in?
     if (User::isGuest()) {
         App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode(Route::url('index.php?option=' . $this->_option, false, true))), Lang::txt('COM_FORUM_LOGIN_NOTICE'), 'warning');
     }
     $this->_authorize('section');
     // Permissions check
     if (!$this->config->get('access-create-section') && !$this->config->get('access-edit-section')) {
         App::redirect(Route::url('index.php?option=' . $this->_option), Lang::txt('COM_FORUM_NOT_AUTHORIZED'), 'error');
     }
     // Check for request forgeries
     Request::checkToken();
     // Incoming posted data
     $fields = Request::getVar('fields', array(), 'post');
     $fields = array_map('trim', $fields);
     // Instantiate a new table row and bind the incoming data
     $section = Section::oneOrNew($fields['id'])->set($fields);
     // Check for alias duplicates
     if (!$section->isUnique()) {
         App::redirect(Route::url('index.php?option=' . $this->_option), Lang::txt('COM_FORUM_ERROR_SECTION_ALREADY_EXISTS'), 'error');
     }
     // Store new content
     if (!$section->save()) {
         Notify::error($section->getError());
     }
     // Log activity
     Event::trigger('system.logActivity', ['activity' => ['action' => $fields['id'] ? 'updated' : 'created', 'scope' => 'forum.section', 'scope_id' => $section->get('id'), 'description' => Lang::txt('COM_FORUM_ACTIVITY_SECTION_' . ($fields['id'] ? 'UPDATED' : 'CREATED'), '<a href="' . Route::url('index.php?option=' . $this->_option) . '">' . $section->get('title') . '</a>'), 'details' => array('title' => $section->get('title'), 'url' => Route::url('index.php?option=' . $this->_option))], 'recipients' => array(['forum.site', 1], ['forum.section', $section->get('id')], ['user', $section->get('created_by')])]);
     // Set the redirect
     App::redirect(Route::url('index.php?option=' . $this->_option));
 }
Exemple #4
0
 /**
  * Displays a question response for editing
  *
  * @param   mixed  $post
  * @return  void
  */
 public function editTask($post = null)
 {
     Request::setVar('hidemainmenu', 1);
     if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.create', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     // Incoming
     $parent = Request::getInt('parent', 0);
     if (!is_object($post)) {
         $id = Request::getVar('id', array(0));
         if (is_array($id)) {
             $id = intval($id[0]);
         }
         $post = Post::oneOrNew($id);
     }
     if ($post->isNew()) {
         $post->set('parent', $parent);
         $post->set('created_by', User::get('id'));
     }
     if ($post->get('parent')) {
         $threads = Post::all()->whereEquals('category_id', $post->get('category_id'))->whereEquals('parent', 0)->ordered()->rows();
     }
     // Get the category
     $category = Category::oneOrNew($post->get('category_id'));
     $categories = array();
     foreach (Category::all()->rows() as $c) {
         if (!isset($categories[$c->section_id])) {
             $categories[$c->section_id] = array();
         }
         $categories[$c->section_id][] = $c;
         asort($categories[$c->section_id]);
     }
     // Get the section
     $section = Section::oneOrNew($category->get('section_id'));
     // Get the sections for this group
     $sections = array();
     foreach (Section::all()->rows() as $s) {
         $ky = $s->scope . ' (' . $s->scope_id . ')';
         if ($s->scope == 'site') {
             $ky = '[ site ]';
         }
         if (!isset($sections[$ky])) {
             $sections[$ky] = array();
         }
         $s->categories = isset($categories[$s->id]) ? $categories[$s->id] : array();
         $sections[$ky][] = $s;
         asort($sections[$ky]);
     }
     User::setState('com_forum.edit.thread.data', array('id' => $post->get('id'), 'asset_id' => $post->get('asset_id')));
     $m = new AdminThread();
     $form = $m->getForm();
     // Get tags on this article
     $this->view->set('row', $post)->set('sections', $sections)->set('categories', $categories)->set('form', $form)->setLayout('edit')->display();
 }
 /**
  * Saves a section and redirects to main page afterward
  *
  * @return  void
  */
 public function savesection()
 {
     if (!$this->course->access('manage', 'offering')) {
         return $this->panel();
     }
     // Incoming posted data
     $fields = Request::getVar('fields', array(), 'post');
     $fields = array_map('trim', $fields);
     // Instantiate a new table row and bind the incoming data
     $section = Section::oneOrNew($fields['id'])->set($fields);
     // Check for alias duplicates
     if (!$section->isUnique()) {
         App::redirect(Route::url($this->base . '&unit=manage'), Lang::txt('COM_FORUM_ERROR_SECTION_ALREADY_EXISTS'), 'error');
     }
     // Store new content
     if (!$section->save()) {
         Notify::error($section->getError());
     }
     // Log activity
     Event::trigger('system.logActivity', ['activity' => ['action' => $fields['id'] ? 'updated' : 'created', 'scope' => 'forum.section', 'scope_id' => $section->get('id'), 'description' => Lang::txt('PLG_COURSES_FORUM_ACTIVITY_SECTION_' . ($fields['id'] ? 'UPDATED' : 'CREATED'), '<a href="' . Route::url($this->base) . '">' . $section->get('title') . '</a>'), 'details' => array('title' => $section->get('title'), 'url' => Route::url($this->base))], 'recipients' => array(['course', $this->offering->get('id')], ['forum.' . $this->forum->get('scope'), $this->forum->get('scope_id')], ['forum.section', $section->get('id')], ['user', $section->get('created_by')])]);
     // Set the redirect
     App::redirect(Route::url($this->base . '&unit=manage'));
 }
Exemple #6
0
 /**
  * Saves a section and redirects to main page afterward
  *
  * @return  void
  */
 public function savesection()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming posted data
     $fields = Request::getVar('fields', array(), 'post');
     $fields = array_map('trim', $fields);
     $fields['state'] = 1;
     // Instantiate a new table row and bind the incoming data
     $section = \Components\Forum\Models\Section::oneOrNew($fields['id'])->set($fields);
     if (in_array($section->get('alias'), array('new', 'settings', 'savesettings'))) {
         App::redirect(Route::url($this->base), Lang::txt('PLG_GROUPS_FORUM_SECTION_TITLE_RESERVED', $section->get('alias')), 'error');
     }
     // Check for alias duplicates
     if (!$section->isUnique()) {
         App::redirect(Route::url($this->base), Lang::txt('PLG_GROUPS_FORUM_ERROR_SECTION_ALREADY_EXISTS'), 'error');
     }
     // Store new content
     if (!$section->save()) {
         Notify::error($section->getError());
     } else {
         // Log activity
         Event::trigger('system.logActivity', ['activity' => ['action' => $fields['id'] ? 'updated' : 'created', 'scope' => 'forum.section', 'scope_id' => $section->get('id'), 'description' => Lang::txt('PLG_GROUPS_FORUM_ACTIVITY_SECTION_' . ($fields['id'] ? 'UPDATED' : 'CREATED'), '<a href="' . Route::url($this->base) . '">' . $section->get('title') . '</a>'), 'details' => array('title' => $section->get('title'), 'url' => Route::url($this->base))], 'recipients' => array(['group', $this->group->get('gidNumber')], ['forum.' . $this->forum->get('scope'), $this->forum->get('scope_id')], ['forum.section', $section->get('id')], ['user', $section->get('created_by')])]);
     }
     // Set the redirect
     App::redirect(Route::url($this->base));
 }