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