Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// This program is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * Get repository properties and generate app properties - put them to configuration
19
 *
20
 * @package mod_edusharing
21
 * @copyright metaVentis GmbH — http://metaventis.com
22
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 * @todo Implement as moustache template
24
 */
25
 
26
use mod_edusharing\EduSharingService;
27
use mod_edusharing\EduSharingUserException;
28
use mod_edusharing\MetaDataFrontend;
29
use mod_edusharing\MetadataLogic;
30
use mod_edusharing\PluginRegistrationFrontend;
31
use mod_edusharing\UtilityFunctions;
32
 
33
require_once(dirname(__FILE__) . '/../../config.php');
34
 
35
global $CFG;
36
require_once($CFG->dirroot . '/mod/edusharing/eduSharingAutoloader.php');
37
 
38
try {
39
    require_login();
40
} catch (Exception $exception) {
41
    echo $exception->getMessage();
42
    unset($exception);
43
    exit();
44
}
45
 
46
echo '<html>
47
<head>
48
    <title>edu-sharing metadata import</title>
49
    <link rel="stylesheet" href="import_metadata_style.css" />
50
</head>
51
<body>
52
<div class="h5p-header">
53
    <h1>Import metadata from an edu-sharing repository</h1>
54
</div>
55
<div class="wrap">';
56
if (!is_siteadmin()) {
57
    echo '<h3>Access denied!</h3>';
58
    echo '<p>Please login with your admin account in moodle.</p>';
59
    exit();
60
}
61
 
62
 
63
if (isset($_POST['repoReg'])) {
64
    if (!empty($_POST['appId'])) {
65
        set_config('application_appid', $_POST['appId'], 'edusharing');
66
    }
67
    if (!empty($_POST['host_aliases'])) {
68
        set_config('application_host_aliases', $_POST['host_aliases'], 'edusharing');
69
    }
70
    echo PluginRegistrationFrontend::register_plugin($_POST['repoUrl'], $_POST['repoAdmin'], $_POST['repoPwd']);
71
    exit();
72
}
73
 
74
$filename = '';
75
try {
76
    $metadataurl = optional_param('mdataurl', '', PARAM_NOTAGS);
77
} catch (Exception $exception) {
78
    // This exception is stupid.
79
    unset($exception);
80
}
81
 
82
if (!empty($metadataurl)) {
83
    try {
84
        $utils = new UtilityFunctions();
85
        $appid = $utils->get_config_entry('application_appid');
86
        if (empty($appid)) {
87
            $utils->set_config_entry('application_appid', uniqid('moodle_'));
88
        }
89
        $service = new MetadataLogic(new EduSharingService());
90
        $service->import_metadata($metadataurl);
91
        echo '<h3 class="edu_success">Import successful.</h3>';
92
    } catch (EduSharingUserException $edusharinguserexception) {
93
        echo $edusharinguserexception->get_html_message();
94
    } catch (Exception $exception) {
95
        echo '<p style="background: #FF8170">Unexpected error - please try again later<br></p>';
96
    }
97
    if ($service->reloadform) {
98
        echo MetaDataFrontend::get_meta_data_form();
99
    }
100
    $repoform = MetaDataFrontend::get_repo_form();
101
    if ($repoform !== null) {
102
        echo $repoform;
103
    }
104
    exit();
105
}
106
 
107
echo MetaDataFrontend::get_meta_data_form();
108
$repoform = MetaDataFrontend::get_repo_form();
109
if ($repoform !== null) {
110
    echo $repoform;
111
}
112
 
113
echo '</div></body></html>';
114
exit();