d7eb99bf66ee46c885cbda2bf43eef3c63b7e6e5
[moodle.git] / admin / tool / installaddon / index.php
1 <?php
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/>.
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  */
26 require(dirname(__FILE__) . '/../../../config.php');
27 require_once($CFG->libdir.'/adminlib.php');
29 admin_externalpage_setup('tool_installaddon_index');
31 if (!empty($CFG->disableonclickaddoninstall)) {
32     notice(get_string('featuredisabled', 'tool_installaddon'));
33 }
35 $installer = tool_installaddon_installer::instance();
37 $output = $PAGE->get_renderer('tool_installaddon');
38 $output->set_installer_instance($installer);
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);
45 $form = $installer->get_installfromzip_form();
47 if ($form->is_cancelled()) {
48     redirect($PAGE->url);
50 } else if ($data = $form->get_data()) {
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);
55     if (empty($data->plugintype)) {
56         $versiondir = make_temp_directory('tool_installaddon/'.$jobid.'/version');
57         $detected = $installer->detect_plugin_component($sourcedir.'/'.$zipfilename, $versiondir);
58         list($detectedtype, $detectedname) = core_component::normalize_component($detected);
59         if ($detectedtype and $detectedname and $detectedtype !== 'core') {
60             $data->plugintype = $detectedtype;
61         } else {
62             $form->require_explicit_plugintype();
63         }
64     }
65     // Redirect to the validation page.
66     if (!empty($data->plugintype)) {
67         $nexturl = new moodle_url('/admin/tool/installaddon/validate.php', array(
68             'sesskey' => sesskey(),
69             'jobid' => $jobid,
70             'zip' => $zipfilename,
71             'type' => $data->plugintype,
72             'rootdir' => $data->rootdir));
73         redirect($nexturl);
74     }
75 }
77 // Output starts here.
78 echo $output->index_page();