[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle 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 // Moodle 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 * @package course 19 * @subpackage publish 20 * @author Jerome Mouneyrac <jerome@mouneyrac.com> 21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL 22 * @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com 23 * 24 * The user selects if he wants to publish the course on Moodle.org hub or 25 * on a specific hub. The site must be registered on a hub to be able to 26 * publish a course on it. 27 */ 28 29 require('../../config.php'); 30 require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php'); 31 require_once($CFG->dirroot . '/course/publish/lib.php'); 32 33 $id = required_param('id', PARAM_INT); 34 $hubname = optional_param('hubname', 0, PARAM_TEXT); 35 $huburl = optional_param('huburl', 0, PARAM_URL); 36 37 $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST); 38 39 require_login($course); 40 $context = context_course::instance($course->id); 41 $shortname = format_string($course->shortname, true, array('context' => $context)); 42 43 $PAGE->set_url('/course/publish/index.php', array('id' => $course->id)); 44 $PAGE->set_pagelayout('incourse'); 45 $PAGE->set_title(get_string('course') . ': ' . $course->fullname); 46 $PAGE->set_heading($course->fullname); 47 48 //check that the PHP xmlrpc extension is enabled 49 if (!extension_loaded('xmlrpc')) { 50 $notificationerror = $OUTPUT->doc_link('admin/environment/php_extension/xmlrpc', ''); 51 $notificationerror .= get_string('xmlrpcdisabledpublish', 'hub'); 52 echo $OUTPUT->header(); 53 echo $OUTPUT->heading(get_string('publishcourse', 'hub', $shortname), 3, 'main'); 54 echo $OUTPUT->notification($notificationerror); 55 echo $OUTPUT->footer(); 56 die(); 57 } 58 59 if (has_capability('moodle/course:publish', context_course::instance($id))) { 60 61 $publicationmanager = new course_publish_manager(); 62 $confirmmessage = ''; 63 64 //update the courses status 65 $updatestatusid = optional_param('updatestatusid', false, PARAM_INT); 66 if (!empty($updatestatusid) and confirm_sesskey()) { 67 //get the communication token from the publication 68 $hub = $publicationmanager->get_registeredhub_by_publication($updatestatusid); 69 if (empty($hub)) { 70 $confirmmessage = $OUTPUT->notification(get_string('nocheckstatusfromunreghub', 'hub')); 71 } else { 72 //get all site courses registered on this hub 73 $function = 'hub_get_courses'; 74 $params = array('search' => '', 'downloadable' => 1, 75 'enrollable' => 1, 'options' => array( 'allsitecourses' => 1)); 76 $serverurl = $hub->huburl."/local/hub/webservice/webservices.php"; 77 require_once($CFG->dirroot."/webservice/xmlrpc/lib.php"); 78 $xmlrpcclient = new webservice_xmlrpc_client($serverurl, $hub->token); 79 $result = $xmlrpcclient->call($function, $params); 80 $sitecourses = $result['courses']; 81 82 //update status for all these course 83 foreach ($sitecourses as $sitecourse) { 84 //get the publication from the hub course id 85 $publication = $publicationmanager->get_publication($sitecourse['id'], $hub->huburl); 86 if (!empty($publication)) { 87 $publication->status = $sitecourse['privacy']; 88 $publication->timechecked = time(); 89 $publicationmanager->update_publication($publication); 90 } else { 91 $msgparams = new stdClass(); 92 $msgparams->id = $sitecourse['id']; 93 $msgparams->hubname = html_writer::tag('a', $hub->hubname, array('href' => $hub->huburl)); 94 $confirmmessage .= $OUTPUT->notification( 95 get_string('detectednotexistingpublication', 'hub', $msgparams)); 96 } 97 } 98 } 99 } 100 101 //if the site os registered on no hub display an error page 102 $registrationmanager = new registration_manager(); 103 $registeredhubs = $registrationmanager->get_registered_on_hubs(); 104 if (empty($registeredhubs)) { 105 echo $OUTPUT->header(); 106 echo $OUTPUT->heading(get_string('publishon', 'hub'), 3, 'main'); 107 echo $OUTPUT->box(get_string('notregisteredonhub', 'hub')); 108 echo $OUTPUT->footer(); 109 die(); 110 } 111 112 $renderer = $PAGE->get_renderer('core', 'publish'); 113 114 /// UNPUBLISH 115 $cancel = optional_param('cancel', 0, PARAM_BOOL); 116 if (!empty($cancel) and confirm_sesskey()) { 117 $confirm = optional_param('confirm', 0, PARAM_BOOL); 118 $hubcourseid = optional_param('hubcourseid', 0, PARAM_INT); 119 $publicationid = optional_param('publicationid', 0, PARAM_INT); 120 $timepublished = optional_param('timepublished', 0, PARAM_INT); 121 $publication = new stdClass(); 122 $publication->courseshortname = $course->shortname; 123 $publication->courseid = $course->id; 124 $publication->hubname = $hubname; 125 $publication->huburl = $huburl; 126 $publication->hubcourseid = $hubcourseid; 127 $publication->timepublished = $timepublished; 128 if (empty($publication->hubname)) { 129 $publication->hubname = $huburl; 130 } 131 $publication->id = $publicationid; 132 if($confirm) { 133 //unpublish the publication by web service 134 $registeredhub = $registrationmanager->get_registeredhub($huburl); 135 $function = 'hub_unregister_courses'; 136 $params = array('courseids' => array( $publication->hubcourseid)); 137 $serverurl = $huburl."/local/hub/webservice/webservices.php"; 138 require_once($CFG->dirroot."/webservice/xmlrpc/lib.php"); 139 $xmlrpcclient = new webservice_xmlrpc_client($serverurl, $registeredhub->token); 140 $result = $xmlrpcclient->call($function, $params); 141 142 //delete the publication from the database 143 $publicationmanager->delete_publication($publicationid); 144 145 //display confirmation message 146 $confirmmessage = $OUTPUT->notification(get_string('courseunpublished', 'hub', $publication), 'notifysuccess'); 147 148 } else { 149 //display confirmation page for unpublishing 150 151 echo $OUTPUT->header(); 152 echo $OUTPUT->heading(get_string('unpublishcourse', 'hub', $shortname), 3, 'main'); 153 echo $renderer->confirmunpublishing($publication); 154 echo $OUTPUT->footer(); 155 die(); 156 } 157 } 158 159 //check if a course was published 160 if (optional_param('published', 0, PARAM_TEXT)) { 161 $confirmmessage = $OUTPUT->notification(get_string('coursepublished', 'hub', 162 empty($hubname)?$huburl:$hubname), 'notifysuccess'); 163 } 164 165 166 /// OUTPUT 167 echo $OUTPUT->header(); 168 echo $confirmmessage; 169 170 echo $OUTPUT->heading(get_string('publishcourse', 'hub', $shortname), 3, 'main'); 171 echo $renderer->publicationselector($course->id); 172 173 $publications = $publicationmanager->get_course_publications($course->id); 174 if (!empty($publications)) { 175 echo $OUTPUT->heading(get_string('publishedon', 'hub'), 3, 'main'); 176 echo $renderer->registeredonhublisting($course->id, $publications); 177 } 178 179 echo $OUTPUT->footer(); 180 181 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |