From 6fdd8fa76f7c164365b8890bc465bb26c623013e Mon Sep 17 00:00:00 2001 From: mjollnir_ Date: Mon, 4 Aug 2008 16:07:37 +0000 Subject: [PATCH] MDL-14591 portfolio: small fixes and improvements. --- lib/portfoliolib.php | 31 ++++++++++++++++++++++- portfolio/add.php | 59 ++++++++++++++++++++++++-------------------- 2 files changed, 62 insertions(+), 28 deletions(-) diff --git a/lib/portfoliolib.php b/lib/portfoliolib.php index b65596f34a..771af1d565 100644 --- a/lib/portfoliolib.php +++ b/lib/portfoliolib.php @@ -148,6 +148,12 @@ function portfolio_add_button($callbackclass, $callbackargs, $callbackfile=null, return; } + if (!empty($SESSION->portfoliointernal)) { + // something somewhere has detected a risk of this being called during inside the preparation + // eg forum_print_attachments + return; + } + if (empty($callbackfile)) { $backtrace = debug_backtrace(); if (!array_key_exists(0, $backtrace) || !array_key_exists('file', $backtrace[0]) || !is_readable($backtrace[0]['file'])) { @@ -2010,7 +2016,7 @@ final class portfolio_exporter { * error handler - decides whether we're running interactively or not * and behaves accordingly */ - public static function raise_error($string, $module, $continue=null) { + public static function raise_error($string, $module='moodle', $continue=null) { if (defined('FULLME') && FULLME == 'cron') { debugging(get_string($string, $module)); return false; @@ -2021,6 +2027,29 @@ final class portfolio_exporter { } } +class portfolio_instance_select extends moodleform { + + private $caller; + + function definition() { + $this->caller = $this->_customdata['caller']; + $options = portfolio_instance_select( + portfolio_instances(), + $this->caller->supported_formats(), + get_class($this->caller), + 'instance', + true, + true + ); + if (empty($options)) { + portfolio_exporter::raise_error('noavailableplugins', 'portfolio'); + } + $mform =& $this->_form; + $mform->addElement('select', 'instance', get_string('selectplugin', 'portfolio'), $options); + $this->add_action_buttons(true, get_string('next')); + } +} + /** * event handler for the portfolio_send event */ diff --git a/portfolio/add.php b/portfolio/add.php index 6aba09dbea..91026ae1a3 100644 --- a/portfolio/add.php +++ b/portfolio/add.php @@ -6,7 +6,7 @@ if (empty($CFG->portfolioenabled)) { } require_once($CFG->libdir . '/portfoliolib.php'); - +require_once($CFG->libdir . '/formslib.php'); $exporter = null; if (isset($SESSION->portfolio) && isset($SESSION->portfolio->exporter)) { $exporter = unserialize(serialize($SESSION->portfolio->exporter)); @@ -16,22 +16,23 @@ if (isset($SESSION->portfolio) && isset($SESSION->portfolio->exporter)) { require_once($CFG->dirroot . '/' . $exporter->callerfile); $exporter = unserialize(serialize($SESSION->portfolio->exporter)); $SESSION->portfolio->exporter =& $exporter; - if (!$exporter->get('instance')) { - $instance = required_param('instance', PARAM_INT); - if (!$instance = portfolio_instance($instance)) { - $exporter->raise_error('invalidinstance', 'portfolio'); - } - if ($broken = portfolio_instance_sanity_check($instance)) { - print_error(get_string($broken[$instance->get('id')], 'portfolio_' . $instance->get('plugin'))); - } - $instance->set('user', $USER); - $exporter->set('instance', $instance); - } - if ($cancel = optional_param('cancel', 0, PARAM_INT)) { + if ($cancel = optional_param('cancel', 0, PARAM_RAW)) { $returnurl = $exporter->get('caller')->get_return_url(); unset($SESSION->portfolio); redirect($returnurl); } + if (!$exporter->get('instance')) { + if ($instance = optional_param('instance', '', PARAM_INT)) { + if (!$instance = portfolio_instance($instance)) { + $exporter->raise_error('invalidinstance', 'portfolio'); + } + if ($broken = portfolio_instance_sanity_check($instance)) { + print_error(get_string($broken[$instance->get('id')], 'portfolio_' . $instance->get('plugin'))); + } + $instance->set('user', $USER); + $exporter->set('instance', $instance); + } + } } else { // we'e just posted here for the first time and have might the instance already if ($instance = optional_param('instance', 0, PARAM_INT)) { @@ -108,21 +109,25 @@ if (!$exporter->get('instance')) { // add them as hidden fields in a new form // to select the instance and post back here again // for the next block to catch - $form = '
' . "\n"; - - if (!$select = portfolio_instance_select(portfolio_instances(), $exporter->get('caller')->supported_formats(), get_class($exporter->get('caller')), 'instance', true)) { - print_error('noavailableplugins', 'portfolio'); + $mform = new portfolio_instance_select('', array('caller' => $exporter->get('caller'))); + if ($mform->is_cancelled()) { + $returnurl = $caller->get_return_url(); + unset($SESSION->portfolio); + redirect($returnurl); + exit; + } else if ($fromform = $mform->get_data()){ + redirect($CFG->wwwroot . '/portfolio/add.php?instance=' . $fromform->instance); + exit; + } + else { + $exporter->print_header(); + print_heading(get_string('selectplugin', 'portfolio')); + print_simple_box_start(); + $mform->display(); + print_simple_box_end(); + print_footer(); + exit; } - $form .= $select; - $form .= ''; - $form .= '
' . "\n"; - $exporter->print_header(); - print_heading(get_string('selectplugin', 'portfolio')); - print_simple_box_start(); - echo $form; - print_simple_box_end(); - print_footer(); - exit; } $exporter->process_stage($stage, $alreadystolen); -- 2.39.5