MDL-15928 prevent parsing errors when zip ext missing
[moodle.git] / portfolio / add.php
CommitLineData
67a87e7d 1<?php
2require_once(dirname(dirname(__FILE__)) . '/config.php');
a239f01e 3
4if (empty($CFG->portfolioenabled)) {
5 print_error('disabled', 'portfolio');
6}
7
67a87e7d 8require_once($CFG->libdir . '/portfoliolib.php');
9
10$exporter = null;
11if (isset($SESSION->portfolio) && isset($SESSION->portfolio->exporter)) {
12 $exporter = unserialize(serialize($SESSION->portfolio->exporter));
13 if ($exporter->instancefile) {
14 require_once($CFG->dirroot . '/' . $exporter->instancefile);
15 }
16 require_once($CFG->dirroot . '/' . $exporter->callerfile);
17 $exporter = unserialize(serialize($SESSION->portfolio->exporter));
18 $SESSION->portfolio->exporter =& $exporter;
ffcfd8a7 19 if (!$exporter->get('instance')) {
20 $instance = required_param('instance', PARAM_INT);
9eb0a772 21 if (!$instance = portfolio_instance($instance)) {
22 $exporter->raise_error('invalidinstance', 'portfolio');
23 }
67a87e7d 24 if ($broken = portfolio_instance_sanity_check($instance)) {
25 print_error(get_string($broken[$instance->get('id')], 'portfolio_' . $instance->get('plugin')));
26 }
27 $instance->set('user', $USER);
28 $exporter->set('instance', $instance);
ffcfd8a7 29 }
30 if ($cancel = optional_param('cancel', 0, PARAM_INT)) {
31 $returnurl = $exporter->get('caller')->get_return_url();
32 unset($SESSION->portfolio);
33 redirect($returnurl);
67a87e7d 34 }
35} else {
36 // we'e just posted here for the first time and have might the instance already
37 if ($instance = optional_param('instance', 0, PARAM_INT)) {
9eb0a772 38 if (!$instance = portfolio_instance($instance)) {
39 portfolio_exporter::raise_error('invalidinstance', 'portfolio');
40 }
67a87e7d 41 if ($broken = portfolio_instance_sanity_check($instance)) {
42 print_error(get_string($broken[$instance->get('id')], 'portfolio_' . $instance->get('plugin')));
43 }
44 $instance->set('user', $USER);
45 } else {
46 $instance = null;
47 }
48
49 $callbackfile = required_param('callbackfile', PARAM_PATH);
50 $callbackclass = required_param('callbackclass', PARAM_ALPHAEXT);
51
52 $callbackargs = array();
9eb0a772 53 foreach (array_keys(array_merge($_GET, $_POST)) as $key) {
67a87e7d 54 if (strpos($key, 'ca_') === 0) {
55 if (!$value = optional_param($key, false, PARAM_ALPHAEXT)) {
56 if (!$value = optional_param($key, false, PARAM_NUMBER)) {
57 $value = optional_param($key, false, PARAM_PATH);
58 }
59 }
60 $callbackargs[substr($key, 3)] = $value;
61 }
62 }
63 require_once($CFG->dirroot . $callbackfile);
64 $caller = new $callbackclass($callbackargs);
65 if (!$caller->check_permissions()) {
66 print_error('nopermissions', 'portfolio', $caller->get_return_url());
67 }
68 $caller->set('user', $USER);
69
70 // for build navigation
71 if (!$course = $caller->get('course')) {
9eb0a772 72 echo 1;
67a87e7d 73 $course = optional_param('course', 0, PARAM_INT);
74 }
75
9eb0a772 76 if (!empty($course) && is_numeric($course)) {
77 echo 2;
78 $course = $DB->get_record('course', array('id' => $course), 'id,shortname,fullname');
67a87e7d 79 // this is yuk but used in build_navigation
80 }
81
9eb0a772 82 $COURSE = $course;
83
67a87e7d 84 list($extranav, $cm) = $caller->get_navigation();
85 $extranav[] = array('type' => 'title', 'name' => get_string('exporting', 'portfolio'));
86 $navigation = build_navigation($extranav, $cm);
87
88 $exporter = new portfolio_exporter($instance, $caller, $callbackfile, $navigation);
89 $exporter->set('user', $USER);
90 $SESSION->portfolio = new StdClass;
91 $SESSION->portfolio->exporter =& $exporter;
92}
93
94
95$stage = optional_param('stage', PORTFOLIO_STAGE_CONFIG);
96$alreadystolen = false;
97// for places returning control to pass (rather than PORTFOLIO_STAGE_PACKAGE
98// which is unstable if they can't get to the constant (eg external system)
99if ($postcontrol = optional_param('postcontrol', 0, PARAM_INT)) {
100 $stage = $SESSION->portfolio->stagepresteal;
101 $exporter->instance()->post_control($stage, array_merge($_GET, $_POST));
102 $alreadystolen = true;
103}
104
105if (!$exporter->get('instance')) {
106 // we've just arrived but have no instance
107 // so retrieve everything from the request,
108 // add them as hidden fields in a new form
109 // to select the instance and post back here again
110 // for the next block to catch
111 $form = '<form action="' . $CFG->wwwroot . '/portfolio/add.php" method="post">' . "\n";
112
7c61a8f0 113 if (!$select = portfolio_instance_select(portfolio_instances(), $exporter->get('caller')->supported_formats(), get_class($exporter->get('caller')), 'instance', true)) {
67a87e7d 114 print_error('noavailableplugins', 'portfolio');
115 }
116 $form .= $select;
117 $form .= '<input type="submit" value="' . get_string('select') . '" />';
118 $form .= '</form>' . "\n";
119 $exporter->print_header();
120 print_heading(get_string('selectplugin', 'portfolio'));
121 print_simple_box_start();
122 echo $form;
123 print_simple_box_end();
124 print_footer();
125 exit;
126}
127
128$exporter->process_stage($stage, $alreadystolen);
129
130?>