Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/course/publish/index.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 /*
00018  * @package    course
00019  * @subpackage publish
00020  * @author     Jerome Mouneyrac <jerome@mouneyrac.com>
00021  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
00022  * @copyright  (C) 1999 onwards Martin Dougiamas  http://dougiamas.com
00023  *
00024  * The user selects if he wants to publish the course on Moodle.org hub or
00025  * on a specific hub. The site must be registered on a hub to be able to
00026  * publish a course on it.
00027 */
00028 
00029 require('../../config.php');
00030 require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php');
00031 require_once($CFG->dirroot . '/course/publish/lib.php');
00032 
00033 $id = required_param('id', PARAM_INT);
00034 $hubname = optional_param('hubname', 0, PARAM_TEXT);
00035 $huburl = optional_param('huburl', 0, PARAM_URL);
00036 
00037 $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
00038 
00039 require_login($course);
00040 $context = get_context_instance(CONTEXT_COURSE, $course->id);
00041 $shortname = format_string($course->shortname, true, array('context' => $context));
00042 
00043 $PAGE->set_url('/course/publish/index.php', array('id' => $course->id));
00044 $PAGE->set_pagelayout('course');
00045 $PAGE->set_title(get_string('course') . ': ' . $course->fullname);
00046 $PAGE->set_heading($course->fullname);
00047 
00048 //check that the PHP xmlrpc extension is enabled
00049 if (!extension_loaded('xmlrpc')) {
00050     $notificationerror = $OUTPUT->doc_link('admin/environment/php_extension/xmlrpc', '');
00051     $notificationerror .= get_string('xmlrpcdisabledpublish', 'hub');
00052     echo $OUTPUT->header();
00053     echo $OUTPUT->heading(get_string('publishcourse', 'hub', $shortname), 3, 'main');
00054     echo $OUTPUT->notification($notificationerror);
00055     echo $OUTPUT->footer();
00056     die();
00057 }
00058 
00059 if (has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE, $id))) {
00060 
00061     $publicationmanager = new course_publish_manager();
00062     $confirmmessage = '';
00063 
00064     //update the courses status
00065     $updatestatusid = optional_param('updatestatusid', false, PARAM_INT);
00066     if (!empty($updatestatusid) and confirm_sesskey()) {
00067         //get the communication token from the publication
00068         $hub = $publicationmanager->get_registeredhub_by_publication($updatestatusid);
00069         if (empty($hub)) {
00070             $confirmmessage = $OUTPUT->notification(get_string('nocheckstatusfromunreghub', 'hub'));
00071         } else {
00072             //get all site courses registered on this hub
00073             $function = 'hub_get_courses';
00074             $params = array('search' => '', 'downloadable' => 1,
00075                 'enrollable' => 1, 'options' => array( 'allsitecourses' => 1));
00076             $serverurl = $hub->huburl."/local/hub/webservice/webservices.php";
00077             require_once($CFG->dirroot."/webservice/xmlrpc/lib.php");
00078             $xmlrpcclient = new webservice_xmlrpc_client($serverurl, $hub->token);
00079             $result = $xmlrpcclient->call($function, $params);
00080             $sitecourses = $result['courses'];
00081 
00082             //update status for all these course
00083             foreach ($sitecourses as $sitecourse) {
00084                 //get the publication from the hub course id
00085                 $publication = $publicationmanager->get_publication($sitecourse['id'], $hub->huburl);
00086                 if (!empty($publication)) {
00087                     $publication->status = $sitecourse['privacy'];
00088                     $publication->timechecked = time();
00089                     $publicationmanager->update_publication($publication);
00090                 } else {
00091                     $msgparams = new stdClass();
00092                     $msgparams->id = $sitecourse['id'];
00093                     $msgparams->hubname = html_writer::tag('a', $hub->hubname, array('href' => $hub->huburl));
00094                     $confirmmessage .= $OUTPUT->notification(
00095                             get_string('detectednotexistingpublication', 'hub', $msgparams));
00096                 }
00097             }
00098         }
00099     }
00100 
00101     //if the site os registered on no hub display an error page
00102     $registrationmanager = new registration_manager();
00103     $registeredhubs = $registrationmanager->get_registered_on_hubs();
00104     if (empty($registeredhubs)) {
00105         echo $OUTPUT->header();
00106         echo $OUTPUT->heading(get_string('publishon', 'hub'), 3, 'main');
00107         echo $OUTPUT->box(get_string('notregisteredonhub', 'hub'));
00108         echo $OUTPUT->footer();
00109         die();
00110     }
00111 
00112     $renderer = $PAGE->get_renderer('core', 'publish');
00113   
00115     $cancel = optional_param('cancel', 0, PARAM_BOOL);
00116     if (!empty($cancel) and confirm_sesskey()) {
00117         $confirm = optional_param('confirm', 0, PARAM_BOOL);      
00118         $hubcourseid = optional_param('hubcourseid', 0, PARAM_INT);
00119         $publicationid = optional_param('publicationid', 0, PARAM_INT);
00120         $timepublished = optional_param('timepublished', 0, PARAM_INT);
00121         $publication->courseshortname = $course->shortname;
00122         $publication->courseid = $course->id;
00123         $publication->hubname = $hubname;
00124         $publication->huburl = $huburl;
00125         $publication->hubcourseid = $hubcourseid;
00126         $publication->timepublished = $timepublished;
00127         if (empty($publication->hubname)) {
00128              $publication->hubname = $huburl;
00129         }
00130         $publication->id = $publicationid;
00131         if($confirm) {
00132             //unpublish the publication by web service
00133             $registeredhub = $registrationmanager->get_registeredhub($huburl);
00134             $function = 'hub_unregister_courses';
00135             $params = array('courseids' => array( $publication->hubcourseid));
00136             $serverurl = $huburl."/local/hub/webservice/webservices.php";
00137             require_once($CFG->dirroot."/webservice/xmlrpc/lib.php");
00138             $xmlrpcclient = new webservice_xmlrpc_client($serverurl, $registeredhub->token);
00139             $result = $xmlrpcclient->call($function, $params);
00140 
00141             //delete the publication from the database
00142             $publicationmanager->delete_publication($publicationid);
00143 
00144             //display confirmation message
00145             $confirmmessage = $OUTPUT->notification(get_string('courseunpublished', 'hub', $publication), 'notifysuccess');
00146 
00147         } else {
00148             //display confirmation page for unpublishing
00149 
00150             echo $OUTPUT->header();
00151             echo $OUTPUT->heading(get_string('unpublishcourse', 'hub', $shortname), 3, 'main');
00152             echo $renderer->confirmunpublishing($publication);
00153             echo $OUTPUT->footer();
00154             die();
00155         }
00156     }
00157 
00158     //check if a course was published
00159     if (optional_param('published', 0, PARAM_TEXT)) {
00160         $confirmmessage = $OUTPUT->notification(get_string('coursepublished', 'hub',
00161                 empty($hubname)?$huburl:$hubname), 'notifysuccess');
00162     }
00163 
00164  
00166     echo $OUTPUT->header();
00167     echo $confirmmessage;
00168 
00169     echo $OUTPUT->heading(get_string('publishcourse', 'hub', $shortname), 3, 'main');
00170     echo $renderer->publicationselector($course->id);
00171 
00172     $publications = $publicationmanager->get_course_publications($course->id);
00173     if (!empty($publications)) {
00174         echo $OUTPUT->heading(get_string('publishedon', 'hub'), 3, 'main');
00175         echo $renderer->registeredonhublisting($course->id, $publications);
00176     }
00177 
00178     echo $OUTPUT->footer();
00179 
00180 }
 All Data Structures Namespaces Files Functions Variables Enumerations