Commit | Line | Data |
---|---|---|
0056f2a3 DM |
1 | <?php |
2 | ||
3 | // This file is part of Moodle - http://moodle.org/ | |
4 | // | |
5 | // Moodle is free software: you can redistribute it and/or modify | |
6 | // it under the terms of the GNU General Public License as published by | |
7 | // the Free Software Foundation, either version 3 of the License, or | |
8 | // (at your option) any later version. | |
9 | // | |
10 | // Moodle is distributed in the hope that it will be useful, | |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | // GNU General Public License for more details. | |
14 | // | |
15 | // You should have received a copy of the GNU General Public License | |
16 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
18 | /** | |
19 | * The main screen of the tool. | |
20 | * | |
21 | * @package tool_installaddon | |
22 | * @copyright 2013 David Mudrak <david@moodle.com> | |
23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
24 | */ | |
25 | ||
26 | require(dirname(__FILE__) . '/../../../config.php'); | |
27 | require_once($CFG->libdir.'/adminlib.php'); | |
0056f2a3 DM |
28 | |
29 | admin_externalpage_setup('tool_installaddon_index'); | |
30 | ||
31 | if (!empty($CFG->disableonclickaddoninstall)) { | |
32 | notice(get_string('featuredisabled', 'tool_installaddon')); | |
33 | } | |
34 | ||
35 | $installer = tool_installaddon_installer::instance(); | |
36 | ||
af96f120 DM |
37 | $output = $PAGE->get_renderer('tool_installaddon'); |
38 | $output->set_installer_instance($installer); | |
39 | ||
40 | // Handle the eventual request for installing from remote repository. | |
41 | $remoterequest = optional_param('installaddonrequest', null, PARAM_RAW); | |
42 | $confirmed = optional_param('confirm', false, PARAM_BOOL); | |
43 | $installer->handle_remote_request($output, $remoterequest, $confirmed); | |
44 | ||
0056f2a3 DM |
45 | $form = $installer->get_installfromzip_form(); |
46 | ||
47 | if ($form->is_cancelled()) { | |
48 | redirect($PAGE->url); | |
49 | ||
50 | } else if ($data = $form->get_data()) { | |
585b64a6 DM |
51 | // Save the ZIP file into a temporary location. |
52 | $jobid = md5(rand().uniqid('', true)); | |
53 | $sourcedir = make_temp_directory('tool_installaddon/'.$jobid.'/source'); | |
54 | $zipfilename = $installer->save_installfromzip_file($form, $sourcedir); | |
c192a330 DM |
55 | if (empty($data->plugintype)) { |
56 | $versiondir = make_temp_directory('tool_installaddon/'.$jobid.'/version'); | |
57 | $detected = $installer->detect_plugin_component($sourcedir.'/'.$zipfilename, $versiondir); | |
ef86599e | 58 | if (empty($detected)) { |
c192a330 | 59 | $form->require_explicit_plugintype(); |
ef86599e DM |
60 | } else { |
61 | list($detectedtype, $detectedname) = core_component::normalize_component($detected); | |
62 | if ($detectedtype and $detectedname and $detectedtype !== 'core') { | |
63 | $data->plugintype = $detectedtype; | |
64 | } else { | |
65 | $form->require_explicit_plugintype(); | |
66 | } | |
c192a330 DM |
67 | } |
68 | } | |
585b64a6 | 69 | // Redirect to the validation page. |
c192a330 DM |
70 | if (!empty($data->plugintype)) { |
71 | $nexturl = new moodle_url('/admin/tool/installaddon/validate.php', array( | |
72 | 'sesskey' => sesskey(), | |
73 | 'jobid' => $jobid, | |
74 | 'zip' => $zipfilename, | |
75 | 'type' => $data->plugintype, | |
76 | 'rootdir' => $data->rootdir)); | |
77 | redirect($nexturl); | |
78 | } | |
0056f2a3 DM |
79 | } |
80 | ||
af96f120 | 81 | // Output starts here. |
0056f2a3 | 82 | echo $output->index_page(); |