Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/ajax/ajaxlib.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 
00039 function user_preference_allow_ajax_update($name, $paramtype) {
00040     global $USER, $PAGE;
00041 
00042     // Make sure that the required JavaScript libraries are loaded.
00043     $PAGE->requires->yui2_lib('connection');
00044 
00045     // Record in the session that this user_preference is allowed to updated remotely.
00046     $USER->ajax_updatable_user_prefs[$name] = $paramtype;
00047 }
00048 
00054 function ajaxenabled(array $browsers = null) {
00055     global $CFG, $USER;
00056 
00057     if (!empty($browsers)) {
00058         $valid = false;
00059         foreach ($browsers as $brand => $version) {
00060             if (check_browser_version($brand, $version)) {
00061                 $valid = true;
00062             }
00063         }
00064 
00065         if (!$valid) {
00066             return false;
00067         }
00068     }
00069 
00070     $ie = check_browser_version('MSIE', 6.0);
00071     $ff = check_browser_version('Gecko', 20051106);
00072     $op = check_browser_version('Opera', 9.0);
00073     $sa = check_browser_version('Safari', 412);
00074     $ch = check_browser_version('Chrome', 6);
00075 
00076     if (!$ie && !$ff && !$op && !$sa && !$ch) {
00078         // Gecko build 20051107 is what is in Firefox 1.5.
00079         // We still have issues with AJAX in other browsers.
00080         return false;
00081     }
00082 
00083     if (!empty($CFG->enableajax) && (!empty($USER->ajax) || !isloggedin())) {
00084         return true;
00085     } else {
00086         return false;
00087     }
00088 }
00089 
00090 
00091 
00092 // ==============================================================================
00093 // TODO: replace this with something more up-to-date with our coding standards
00094 
00099 class jsportal {
00100 
00101     var $currentblocksection = null;
00102     var $blocks = array();
00103 
00104 
00108     function block_add($id, $hidden=false){
00109         $hidden_binary = 0;
00110 
00111         if ($hidden) {
00112             $hidden_binary = 1;
00113         }
00114         $this->blocks[count($this->blocks)] = array($this->currentblocksection, $id, $hidden_binary);
00115     }
00116 
00117 
00121     function print_javascript($courseid, $return=false) {
00122         global $CFG, $USER, $OUTPUT, $COURSE, $DB;
00123 
00124         $blocksoutput = $output = '';
00125         for ($i=0; $i<count($this->blocks); $i++) {
00126             $blocksoutput .= "['".$this->blocks[$i][0]."',
00127                              '".$this->blocks[$i][1]."',
00128                              '".$this->blocks[$i][2]."']";
00129 
00130             if ($i != (count($this->blocks) - 1)) {
00131                 $blocksoutput .= ',';
00132             }
00133         }
00134         $output .= "<script type=\"text/javascript\">\n";
00135         $output .= "    main.portal.id = ".$courseid.";\n";
00136         $output .= "    main.portal.blocks = new Array(".$blocksoutput.");\n";
00137         $output .= "    main.portal.strings['courseformat']='".$COURSE->format."';\n";
00138         $output .= "    main.portal.strings['wwwroot']='".$CFG->wwwroot."';\n";
00139         $output .= "    main.portal.strings['marker']='".addslashes_js(get_string('markthistopic', '', '_var_'))."';\n";
00140         $output .= "    main.portal.strings['marked']='".addslashes_js(get_string('markedthistopic', '', '_var_'))."';\n";
00141         $output .= "    main.portal.numsections = ".$COURSE->numsections.";\n";
00142         $output .= "    main.portal.lastsection = ".$DB->get_field_sql("SELECT MAX(section) FROM {course_sections} WHERE course = ?", array($courseid)).";\n"; // needed for orphaned activities in unavailable sections
00143         $output .= "    main.portal.strings['hide']='".addslashes_js(get_string('hide'))."';\n";
00144         $output .= "    main.portal.strings['hidesection']='".addslashes_js(get_string('hidesection', '', '_var_'))."';\n";
00145         $output .= "    main.portal.strings['show']='".addslashes_js(get_string('show'))."';\n";
00146         $output .= "    main.portal.strings['delete']='".addslashes_js(get_string('delete'))."';\n";
00147         $output .= "    main.portal.strings['move']='".addslashes_js(get_string('move'))."';\n";
00148         $output .= "    main.portal.strings['movesection']='".addslashes_js(get_string('movesection', '', '_var_'))."';\n";
00149         $output .= "    main.portal.strings['moveleft']='".addslashes_js(get_string('moveleft'))."';\n";
00150         $output .= "    main.portal.strings['moveright']='".addslashes_js(get_string('moveright'))."';\n";
00151         $output .= "    main.portal.strings['update']='".addslashes_js(get_string('update'))."';\n";
00152         $output .= "    main.portal.strings['groupsnone']='".addslashes_js(get_string('clicktochangeinbrackets', 'moodle', get_string('groupsnone')))."';\n";
00153         $output .= "    main.portal.strings['groupsseparate']='".addslashes_js(get_string('clicktochangeinbrackets', 'moodle', get_string('groupsseparate')))."';\n";
00154         $output .= "    main.portal.strings['groupsvisible']='".addslashes_js(get_string('clicktochangeinbrackets', 'moodle', get_string('groupsvisible')))."';\n";
00155         $output .= "    main.portal.strings['deletecheck']='".addslashes_js(get_string('deletecheckfull','','_var_'))."';\n";
00156         $output .= "    main.portal.strings['resource']='".addslashes_js(get_string('resource'))."';\n";
00157         $output .= "    main.portal.strings['activity']='".addslashes_js(get_string('activity'))."';\n";
00158         $output .= "    main.portal.strings['sesskey']='".sesskey()."';\n";
00159         foreach (array_keys(get_plugin_list('mod')) as $modtype) {
00160             $output .= "    main.portal.strings['modtype_".$modtype."']='".addslashes_js(get_string('pluginname', 'mod_'.$modtype))."';\n";
00161         }
00162         $output .= "    main.portal.icons['spacerimg']='".$OUTPUT->pix_url('spacer')."';\n";
00163         $output .= "    main.portal.icons['marker']='".$OUTPUT->pix_url('i/marker')."';\n";
00164         $output .= "    main.portal.icons['ihide']='".$OUTPUT->pix_url('i/hide')."';\n";
00165         $output .= "    main.portal.icons['move_2d']='".$OUTPUT->pix_url('i/move_2d')."';\n";
00166         $output .= "    main.portal.icons['show']='".$OUTPUT->pix_url('t/show')."';\n";
00167         $output .= "    main.portal.icons['hide']='".$OUTPUT->pix_url('t/hide')."';\n";
00168         $output .= "    main.portal.icons['delete']='".$OUTPUT->pix_url('t/delete')."';\n";
00169         $output .= "    main.portal.icons['groupn']='".$OUTPUT->pix_url('t/groupn')."';\n";
00170         $output .= "    main.portal.icons['groups']='".$OUTPUT->pix_url('t/groups')."';\n";
00171         $output .= "    main.portal.icons['groupv']='".$OUTPUT->pix_url('t/groupv')."';\n";
00172         if (right_to_left()) {
00173             $output .= "    main.portal.icons['backwards']='".$OUTPUT->pix_url('t/right')."';\n";
00174             $output .= "    main.portal.icons['forwards']='".$OUTPUT->pix_url('t/left')."';\n";
00175         } else {
00176             $output .= "    main.portal.icons['backwards']='".$OUTPUT->pix_url('t/left')."';\n";
00177             $output .= "    main.portal.icons['forwards']='".$OUTPUT->pix_url('t/right')."';\n";
00178         }
00179 
00180         $output .= "    onloadobj.load();\n";
00181         $output .= "    main.process_blocks();\n";
00182         $output .= "</script>";
00183         if ($return) {
00184             return $output;
00185         } else {
00186             echo $output;
00187         }
00188     }
00189 
00190 }
 All Data Structures Namespaces Files Functions Variables Enumerations