Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/repository/repository_callback.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 require_once(dirname(dirname(__FILE__)).'/config.php');
00030 require_once(dirname(dirname(__FILE__)).'/lib/filelib.php');
00031 require_once(dirname(__FILE__).'/lib.php');
00032 
00033 require_login();
00034 
00036 $repo_id   = required_param('repo_id', PARAM_INT); // Repository ID
00037 
00039 header('Cache-Control: no-cache, must-revalidate');
00040 header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
00041 
00043 set_time_limit(0);
00044 
00046 $sql = 'SELECT i.name, i.typeid, r.type, i.contextid FROM {repository} r, {repository_instances} i '.
00047        'WHERE i.id=? AND i.typeid=r.id';
00048 
00049 $repository = $DB->get_record_sql($sql, array($repo_id), '*', MUST_EXIST);
00050 
00051 $type = $repository->type;
00052 
00053 if (file_exists($CFG->dirroot.'/repository/'.$type.'/lib.php')) {
00054     require_once($CFG->dirroot.'/repository/'.$type.'/lib.php');
00055     $classname = 'repository_' . $type;
00056     $repo = new $classname($repo_id, $repository->contextid, array('type'=>$type));
00057 } else {
00058     print_error('invalidplugin', 'repository', $type);
00059 }
00060 
00061 // post callback
00062 $repo->callback();
00063 // call opener window to refresh repository
00064 // the callback url should be something like this:
00065 // http://xx.moodle.com/repository/repository_callback.php?repo_id=1&sid=xxx
00066 // sid is the attached auth token from external source
00067 // If Moodle is working on HTTPS mode, then we are not allowed to access
00068 // parent window, in this case, we need to alert user to refresh the repository
00069 // manually.
00070 $strhttpsbug = get_string('cannotaccessparentwin', 'repository');
00071 $strrefreshnonjs = get_string('refreshnonjsfilepicker', 'repository');
00072 $js =<<<EOD
00073 <html>
00074 <head>
00075     <script type="text/javascript">
00076     if(window.opener){
00077         window.opener.M.core_filepicker.active_filepicker.list();
00078         window.close();
00079     } else {
00080         alert("{$strhttpsbug }");
00081     }
00082     </script>
00083 </head>
00084 <body>
00085     <noscript>
00086     {$strrefreshnonjs}
00087     </noscript>
00088 </body>
00089 </html>
00090 EOD;
00091 
00092 die($js);
 All Data Structures Namespaces Files Functions Variables Enumerations