[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/user/ -> portfolio.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * This file is part of the User section Moodle
  19   *
  20   * @copyright 1999 Martin Dougiamas  http://dougiamas.com
  21   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22   * @package core_user
  23   */
  24  
  25  require_once(__DIR__ . '/../config.php');
  26  
  27  if (empty($CFG->enableportfolios)) {
  28      print_error('disabled', 'portfolio');
  29  }
  30  
  31  require_once($CFG->libdir . '/portfoliolib.php');
  32  require_once($CFG->libdir . '/portfolio/forms.php');
  33  
  34  $config   = optional_param('config', 0, PARAM_INT);
  35  $hide     = optional_param('hide', 0, PARAM_INT);
  36  $courseid = optional_param('courseid', SITEID, PARAM_INT);
  37  
  38  $url = new moodle_url('/user/portfolio.php', array('courseid' => $courseid));
  39  
  40  if ($config !== 0) {
  41      $url->param('config', $config);
  42  }
  43  if (! $course = $DB->get_record("course", array("id" => $courseid))) {
  44      print_error('invalidcourseid');
  45  }
  46  
  47  $user = $USER;
  48  $fullname = fullname($user);
  49  $strportfolios = get_string('portfolios', 'portfolio');
  50  $configstr = get_string('manageyourportfolios', 'portfolio');
  51  $namestr = get_string('name');
  52  $pluginstr = get_string('plugin', 'portfolio');
  53  $baseurl = $CFG->wwwroot . '/user/portfolio.php';
  54  $introstr = get_string('intro', 'portfolio');
  55  $showhide = get_string('showhide', 'portfolio');
  56  
  57  $display = true; // Set this to false in the conditions to stop processing.
  58  
  59  require_login($course, false);
  60  
  61  $PAGE->set_url($url);
  62  $PAGE->set_context(context_user::instance($user->id));
  63  $PAGE->set_title($configstr);
  64  $PAGE->set_heading($fullname);
  65  $PAGE->set_pagelayout('admin');
  66  
  67  echo $OUTPUT->header();
  68  $showroles = 1;
  69  
  70  if (!empty($config)) {
  71      navigation_node::override_active_url(new moodle_url('/user/portfolio.php', array('courseid' => $courseid)));
  72      $instance = portfolio_instance($config);
  73      $mform = new portfolio_user_form('', array('instance' => $instance, 'userid' => $user->id));
  74      if ($mform->is_cancelled()) {
  75          redirect($baseurl);
  76          exit;
  77      } else if ($fromform = $mform->get_data()) {
  78          if (!confirm_sesskey()) {
  79              print_error('confirmsesskeybad', '', $baseurl);
  80          }
  81          // This branch is where you process validated data.
  82          $instance->set_user_config($fromform, $USER->id);
  83          core_plugin_manager::reset_caches();
  84          redirect($baseurl, get_string('instancesaved', 'portfolio'), 3);
  85  
  86          exit;
  87      } else {
  88          echo $OUTPUT->heading(get_string('configplugin', 'portfolio'));
  89          echo $OUTPUT->box_start();
  90          $mform->display();
  91          echo $OUTPUT->box_end();
  92          $display = false;
  93      }
  94  
  95  } else if (!empty($hide)) {
  96      $instance = portfolio_instance($hide);
  97      $instance->set_user_config(array('visible' => !$instance->get_user_config('visible', $USER->id)), $USER->id);
  98      core_plugin_manager::reset_caches();
  99  }
 100  
 101  if ($display) {
 102      echo $OUTPUT->heading($configstr);
 103      echo $OUTPUT->box_start();
 104  
 105      echo html_writer::tag('p', $introstr);
 106  
 107      if (!$instances = portfolio_instances(true, false)) {
 108          print_error('noinstances', 'portfolio', $CFG->wwwroot . '/user/view.php');
 109      }
 110  
 111      $table = new html_table();
 112      $table->head = array($namestr, $pluginstr, $showhide);
 113      $table->data = array();
 114  
 115      foreach ($instances as $i) {
 116          $visible = $i->get_user_config('visible', $USER->id);
 117          $table->data[] = array($i->get('name'), $i->get('plugin'),
 118              ($i->has_user_config()
 119                  ? '<a href="' . $baseurl . '?config=' . $i->get('id') . '"><img src="' . $OUTPUT->pix_url('t/edit') . '" alt="' . get_string('configure') . '" /></a>' : '') .
 120                     ' <a href="' . $baseurl . '?hide=' . $i->get('id') . '"><img src="' . $OUTPUT->pix_url('t/' . (($visible) ? 'hide' : 'show')) . '" alt="' . get_string($visible ? 'hide' : 'show') . '" /></a><br />'
 121          );
 122      }
 123  
 124      echo html_writer::table($table);
 125      echo $OUTPUT->box_end();
 126  }
 127  echo $OUTPUT->footer();


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1