Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/licenselib.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 
00029 defined('MOODLE_INTERNAL') || die();
00030 
00031 class license_manager {
00042     static public function add($license) {
00043         global $DB;
00044         if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
00045             // record exists
00046             if ($record->version < $license->version) {
00047                 // update license record
00048                 $license->enabled = $record->enabled;
00049                 $license->id = $record->id;
00050                 $DB->update_record('license', $license);
00051             }
00052         } else {
00053             $DB->insert_record('license', $license);
00054         }
00055         return true;
00056     }
00057 
00063     static public function get_licenses($param = null) {
00064         global $DB;
00065         if (empty($param) || !is_array($param)) {
00066             $param = array();
00067         }
00068         // get licenses by conditions
00069         if ($records = $DB->get_records('license', $param)) {
00070             return $records;
00071         } else {
00072             return array();
00073         }
00074     }
00075 
00081     static public function get_license_by_shortname($name) {
00082         global $DB;
00083         if ($record = $DB->get_record('license', array('shortname'=>$name))) {
00084             return $record;
00085         } else {
00086             return null;
00087         }
00088     }
00089 
00095     static public function enable($license) {
00096         global $DB;
00097         if ($license = self::get_license_by_shortname($license)) {
00098             $license->enabled = 1;
00099             $DB->update_record('license', $license);
00100         }
00101         self::set_active_licenses();
00102         return true;
00103     }
00104 
00110     static public function disable($license) {
00111         global $DB, $CFG;
00112         // Site default license cannot be disabled!
00113         if ($license == $CFG->sitedefaultlicense) {
00114             print_error('error');
00115         }
00116         if ($license = self::get_license_by_shortname($license)) {
00117             $license->enabled = 0;
00118             $DB->update_record('license', $license);
00119         }
00120         self::set_active_licenses();
00121         return true;
00122     }
00123 
00127     static private function set_active_licenses() {
00128         // set to global $CFG
00129         $licenses = self::get_licenses(array('enabled'=>1));
00130         $result = array();
00131         foreach ($licenses as $l) {
00132             $result[] = $l->shortname;
00133         }
00134         set_config('licenses', implode(',', $result));
00135     }
00136 
00140     static public function install_licenses() {
00141         $active_licenses = array();
00142 
00143         $license = new stdClass();
00144 
00145         $license->shortname = 'unknown';
00146         $license->fullname = 'Unknown license';
00147         $license->source = '';
00148         $license->enabled = 1;
00149         $license->version = '2010033100';
00150         $active_licenses[] = $license->shortname;
00151         self::add($license);
00152 
00153         $license->shortname = 'allrightsreserved';
00154         $license->fullname = 'All rights reserved';
00155         $license->source = 'http://en.wikipedia.org/wiki/All_rights_reserved';
00156         $license->enabled = 1;
00157         $license->version = '2010033100';
00158         $active_licenses[] = $license->shortname;
00159         self::add($license);
00160 
00161         $license->shortname = 'public';
00162         $license->fullname = 'Public Domain';
00163         $license->source = 'http://creativecommons.org/licenses/publicdomain/';
00164         $license->enabled = 1;
00165         $license->version = '2010033100';
00166         $active_licenses[] = $license->shortname;
00167         self::add($license);
00168 
00169         $license->shortname = 'cc';
00170         $license->fullname = 'Creative Commons';
00171         $license->source = 'http://creativecommons.org/licenses/by/3.0/';
00172         $license->enabled = 1;
00173         $license->version = '2010033100';
00174         $active_licenses[] = $license->shortname;
00175         self::add($license);
00176 
00177         $license->shortname = 'cc-nd';
00178         $license->fullname = 'Creative Commons - NoDerivs';
00179         $license->source = 'http://creativecommons.org/licenses/by-nd/3.0/';
00180         $license->enabled = 1;
00181         $license->version = '2010033100';
00182         $active_licenses[] = $license->shortname;
00183         self::add($license);
00184 
00185         $license->shortname = 'cc-nc-nd';
00186         $license->fullname = 'Creative Commons - No Commercial NoDerivs';
00187         $license->source = 'http://creativecommons.org/licenses/by-nc-nd/3.0/';
00188         $license->enabled = 1;
00189         $license->version = '2010033100';
00190         $active_licenses[] = $license->shortname;
00191         self::add($license);
00192 
00193         $license->shortname = 'cc-nc';
00194         $license->fullname = 'Creative Commons - No Commercial';
00195         $license->source = 'http://creativecommons.org/licenses/by-nd/3.0/';
00196         $license->enabled = 1;
00197         $license->version = '2010033100';
00198         $active_licenses[] = $license->shortname;
00199         self::add($license);
00200 
00201         $license->shortname = 'cc-nc-sa';
00202         $license->fullname = 'Creative Commons - No Commercial ShareAlike';
00203         $license->source = 'http://creativecommons.org/licenses/by-nc-sa/3.0/';
00204         $license->enabled = 1;
00205         $license->version = '2010033100';
00206         $active_licenses[] = $license->shortname;
00207         self::add($license);
00208 
00209         $license->shortname = 'cc-sa';
00210         $license->fullname = 'Creative Commons - ShareAlike';
00211         $license->source = 'http://creativecommons.org/licenses/by-sa/3.0/';
00212         $license->enabled = 1;
00213         $license->version = '2010033100';
00214         $active_licenses[] = $license->shortname;
00215         self::add($license);
00216 
00217         set_config('licenses', implode(',', $active_licenses));
00218     }
00219 }
 All Data Structures Namespaces Files Functions Variables Enumerations