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