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