Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/blocks/community/communitycourse.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00018 /*
00019  * @package    blocks
00020  * @subpackage community
00021  * @author     Jerome Mouneyrac <jerome@mouneyrac.com>
00022  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
00023  * @copyright  (C) 1999 onwards Martin Dougiamas  http://dougiamas.com
00024  *
00025  * This page display the community course search form.
00026  * It also handles adding a course to the community block.
00027  * It also handles downloading a course template.
00028  */
00029 
00030 require('../../config.php');
00031 require_once($CFG->dirroot . '/blocks/community/locallib.php');
00032 require_once($CFG->dirroot . '/blocks/community/forms.php');
00033 require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php');
00034 
00035 require_login();
00036 $courseid = required_param('courseid', PARAM_INT); //if no courseid is given
00037 $parentcourse = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
00038 
00039 $context = get_context_instance(CONTEXT_COURSE, $courseid);
00040 $PAGE->set_course($parentcourse);
00041 $PAGE->set_url('/blocks/community/communitycourse.php');
00042 $PAGE->set_heading($SITE->fullname);
00043 $PAGE->set_pagelayout('course');
00044 $PAGE->set_title(get_string('searchcourse', 'block_community'));
00045 $PAGE->navbar->add(get_string('searchcourse', 'block_community'));
00046 
00047 $search = optional_param('search', null, PARAM_TEXT);
00048 
00049 //if no capability to search course, display an error message
00050 $usercansearch = has_capability('moodle/community:add', $context);
00051 $usercandownload = has_capability('moodle/community:download', $context);
00052 if (empty($usercansearch)) {
00053     $notificationerror = get_string('cannotsearchcommunity', 'hub');
00054 } else if (!extension_loaded('xmlrpc')) {
00055     $notificationerror = $OUTPUT->doc_link('admin/environment/php_extension/xmlrpc', '');
00056     $notificationerror .= get_string('xmlrpcdisabledcommunity', 'hub');
00057 }
00058 if (!empty($notificationerror)) {
00059     echo $OUTPUT->header();
00060     echo $OUTPUT->heading(get_string('searchcommunitycourse', 'block_community'), 3, 'main');
00061     echo $OUTPUT->notification($notificationerror);
00062     echo $OUTPUT->footer();
00063     die();
00064 }
00065 
00066 $communitymanager = new block_community_manager();
00067 $renderer = $PAGE->get_renderer('block_community');
00068 
00070 $add = optional_param('add', -1, PARAM_INTEGER);
00071 $confirm = optional_param('confirmed', false, PARAM_INTEGER);
00072 if ($add != -1 and $confirm and confirm_sesskey()) {
00073     $course = new stdClass();
00074     $course->name = optional_param('coursefullname', '', PARAM_TEXT);
00075     $course->description = optional_param('coursedescription', '', PARAM_TEXT);
00076     $course->url = optional_param('courseurl', '', PARAM_URL);
00077     $course->imageurl = optional_param('courseimageurl', '', PARAM_URL);
00078     $communitymanager->block_community_add_course($course, $USER->id);
00079     echo $OUTPUT->header();
00080     echo $renderer->save_link_success(
00081             new moodle_url('/course/view.php', array('id' => $courseid)));
00082     echo $OUTPUT->footer();
00083     die();
00084 }
00085 
00087 $cancelrestore = optional_param('cancelrestore', false, PARAM_INT);
00088 if ($usercandownload and $cancelrestore and confirm_sesskey()) {
00089     $filename = optional_param('filename', '', PARAM_ALPHANUMEXT);
00090     //delete temp file
00091     unlink($CFG->tempdir . '/backup/' . $filename . ".mbz");
00092 }
00093 
00095 $huburl = optional_param('huburl', false, PARAM_URL);
00096 $download = optional_param('download', -1, PARAM_INTEGER);
00097 $downloadcourseid = optional_param('downloadcourseid', '', PARAM_INTEGER);
00098 $coursefullname = optional_param('coursefullname', '', PARAM_ALPHANUMEXT);
00099 $backupsize = optional_param('backupsize', 0, PARAM_INT);
00100 if ($usercandownload and $download != -1 and !empty($downloadcourseid) and confirm_sesskey()) {
00101     $course = new stdClass();
00102     $course->fullname = $coursefullname;
00103     $course->id = $downloadcourseid;
00104     $course->huburl = $huburl;
00105 
00106     //OUTPUT: display restore choice page
00107     echo $OUTPUT->header();
00108     echo $OUTPUT->heading(get_string('downloadingcourse', 'block_community'), 3, 'main');
00109     $sizeinfo = new stdClass();
00110     $sizeinfo->total = number_format($backupsize / 1000000, 2);
00111     echo html_writer::tag('div', get_string('downloadingsize', 'block_community', $sizeinfo),
00112             array('class' => 'textinfo'));
00113     if (ob_get_level()) {
00114         ob_flush();
00115     }
00116     flush();
00117     $filenames = $communitymanager->block_community_download_course_backup($course);
00118     echo html_writer::tag('div', get_string('downloaded', 'block_community'),
00119             array('class' => 'textinfo'));
00120     echo $OUTPUT->notification(get_string('downloadconfirmed', 'block_community',
00121                     '/downloaded_backup/' . $filenames['privatefile']), 'notifysuccess');
00122     echo $renderer->restore_confirmation_box($filenames['tmpfile'], $context);
00123     echo $OUTPUT->footer();
00124     die();
00125 }
00126 
00128 $remove = optional_param('remove', '', PARAM_INTEGER);
00129 $communityid = optional_param('communityid', '', PARAM_INTEGER);
00130 if ($remove != -1 and !empty($communityid) and confirm_sesskey()) {
00131     $communitymanager->block_community_remove_course($communityid, $USER->id); 
00132     echo $OUTPUT->header();
00133     echo $renderer->remove_success(new moodle_url(get_referer(false)));
00134     echo $OUTPUT->footer();
00135     die();
00136 }
00137 
00138 //Get form default/current values
00139 $fromformdata['coverage'] = optional_param('coverage', 'all', PARAM_TEXT);
00140 $fromformdata['licence'] = optional_param('licence', 'all', PARAM_ALPHANUMEXT);
00141 $fromformdata['subject'] = optional_param('subject', 'all', PARAM_ALPHANUMEXT);
00142 $fromformdata['audience'] = optional_param('audience', 'all', PARAM_ALPHANUMEXT);
00143 $fromformdata['language'] = optional_param('language', current_language(), PARAM_ALPHANUMEXT);
00144 $fromformdata['educationallevel'] = optional_param('educationallevel', 'all', PARAM_ALPHANUMEXT);
00145 $fromformdata['downloadable'] = optional_param('downloadable', 0, PARAM_ALPHANUM);
00146 $fromformdata['orderby'] = optional_param('orderby', 'newest', PARAM_ALPHA);
00147 $fromformdata['huburl'] = optional_param('huburl', HUB_MOODLEORGHUBURL, PARAM_URL);
00148 $fromformdata['search'] = $search;
00149 $fromformdata['courseid'] = $courseid;
00150 $hubselectorform = new community_hub_search_form('', $fromformdata);
00151 $hubselectorform->set_data($fromformdata);
00152 
00153 //Retrieve courses by web service
00154 $courses = null;
00155 if (optional_param('executesearch', 0, PARAM_INTEGER) and confirm_sesskey()) {
00156     $downloadable = optional_param('downloadable', false, PARAM_INTEGER);
00157 
00158     $options = new stdClass();
00159     if (!empty($fromformdata['coverage'])) {
00160         $options->coverage = $fromformdata['coverage'];
00161     }
00162     if ($fromformdata['licence'] != 'all') {
00163         $options->licenceshortname = $fromformdata['licence'];
00164     }
00165     if ($fromformdata['subject'] != 'all') {
00166         $options->subject = $fromformdata['subject'];
00167     }
00168     if ($fromformdata['audience'] != 'all') {
00169         $options->audience = $fromformdata['audience'];
00170     }
00171     if ($fromformdata['educationallevel'] != 'all') {
00172         $options->educationallevel = $fromformdata['educationallevel'];
00173     }
00174     if ($fromformdata['language'] != 'all') {
00175         $options->language = $fromformdata['language'];
00176     }
00177 
00178     $options->orderby = $fromformdata['orderby'];
00179 
00180     //the range of course requested
00181     $options->givememore = optional_param('givememore', 0, PARAM_INTEGER);
00182 
00183     //check if the selected hub is from the registered list (in this case we use the private token)
00184     $token = 'publichub';
00185     $registrationmanager = new registration_manager();
00186     $registeredhubs = $registrationmanager->get_registered_on_hubs();
00187     foreach ($registeredhubs as $registeredhub) {
00188         if ($huburl == $registeredhub->huburl) {
00189             $token = $registeredhub->token;
00190         }
00191     }
00192 
00193     $function = 'hub_get_courses';
00194     $params = array('search' => $search, 'downloadable' => $downloadable,
00195         'enrollable' => !$downloadable, 'options' => $options);
00196     $serverurl = $huburl . "/local/hub/webservice/webservices.php";
00197     require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php");
00198     $xmlrpcclient = new webservice_xmlrpc_client($serverurl, $token);
00199     try {
00200         $result = $xmlrpcclient->call($function, $params);
00201         $courses = $result['courses'];
00202         $coursetotal = $result['coursetotal'];
00203     } catch (Exception $e) {
00204         $errormessage = $OUTPUT->notification(
00205                         get_string('errorcourselisting', 'block_community', $e->getMessage()));
00206     }
00207 }
00208 
00209 // OUTPUT
00210 echo $OUTPUT->header();
00211 echo $OUTPUT->heading(get_string('searchcommunitycourse', 'block_community'), 3, 'main');
00212 $hubselectorform->display();
00213 if (!empty($errormessage)) {
00214     echo $errormessage;
00215 }
00216 
00217 //load javascript
00218 $commentedcourseids = array(); //result courses with comments only
00219 $courseids = array(); //all result courses
00220 $courseimagenumbers = array(); //number of screenshots of all courses (must be exact same order than $courseids)
00221 if (!empty($courses)) {
00222     foreach ($courses as $course) {
00223         if (!empty($course['comments'])) {
00224             $commentedcourseids[] = $course['id'];
00225         }
00226         $courseids[] = $course['id'];
00227         $courseimagenumbers[] = $course['screenshots'];
00228     }
00229 }
00230 $PAGE->requires->yui_module('moodle-block_community-comments', 'M.blocks_community.init_comments',
00231         array(array('commentids' => $commentedcourseids)));
00232 $PAGE->requires->yui_module('moodle-block_community-imagegallery', 'M.blocks_community.init_imagegallery',
00233         array(array('imageids' => $courseids, 'imagenumbers' => $courseimagenumbers,
00234                 'huburl' => $huburl)));
00235 
00236 echo highlight($search, $renderer->course_list($courses, $huburl, $courseid));
00237 
00238 //display givememore/Next link if more course can be displayed
00239 if (!empty($courses)) {
00240     if (($options->givememore + count($courses)) < $coursetotal) {
00241         $fromformdata['givememore'] = count($courses) + $options->givememore;
00242         $fromformdata['executesearch'] = true;
00243         $fromformdata['sesskey'] = sesskey();
00244         echo $renderer->next_button($fromformdata);
00245     }
00246 }
00247 
00248 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations