PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/mod/studynotes/view.php

https://github.com/galitush2005/RTL-BIDI-Hebrew-Moodle-Plugins
PHP | 395 lines | 303 code | 77 blank | 15 comment | 94 complexity | 4aeb3cf6e5f73e43bbc3e55b25d7dea5 MD5 | raw file
  1. <?php
  2. // $Id: view.php,v 1.21 2009/08/10 19:26:21 fabiangebert Exp $
  3. /**
  4. * This page prints a particular instance of studynotes
  5. *
  6. * @author
  7. * @version $Id: view.php,v 1.21 2009/08/10 19:26:21 fabiangebert Exp $
  8. * @package studynotes
  9. **/
  10. require_once ("../../config.php"); //this is not the Mediabird config
  11. require_once ("lib.php");
  12. require_once ($CFG->dirroot.DIRECTORY_SEPARATOR."mod".DIRECTORY_SEPARATOR."studynotes".DIRECTORY_SEPARATOR."ext".DIRECTORY_SEPARATOR."moodle_auth.php");
  13. require_once ($CFG->dirroot.DIRECTORY_SEPARATOR."mod".DIRECTORY_SEPARATOR."studynotes".DIRECTORY_SEPARATOR."ext".DIRECTORY_SEPARATOR."config_default.php");
  14. require_once ($CFG->dirroot.DIRECTORY_SEPARATOR."mod".DIRECTORY_SEPARATOR."studynotes".DIRECTORY_SEPARATOR."ext".DIRECTORY_SEPARATOR."config.php");
  15. require_once ($CFG->dirroot.DIRECTORY_SEPARATOR."mod".DIRECTORY_SEPARATOR."studynotes".DIRECTORY_SEPARATOR."server".DIRECTORY_SEPARATOR."utility.php");
  16. require_once ($CFG->dirroot.DIRECTORY_SEPARATOR."mod".DIRECTORY_SEPARATOR."studynotes".DIRECTORY_SEPARATOR."ext".DIRECTORY_SEPARATOR."db_moodle.php");
  17. require_once ($CFG->dirroot.DIRECTORY_SEPARATOR."mod".DIRECTORY_SEPARATOR."studynotes".DIRECTORY_SEPARATOR."server".DIRECTORY_SEPARATOR."helper.php");
  18. function studynotes_handle_session($action, $auth) {
  19. global $CFG, $cm;
  20. require_once ($CFG->dirroot.DIRECTORY_SEPARATOR."mod".DIRECTORY_SEPARATOR."studynotes".DIRECTORY_SEPARATOR."server".DIRECTORY_SEPARATOR."data_handling.php");
  21. require_once ($CFG->dirroot.DIRECTORY_SEPARATOR."mod".DIRECTORY_SEPARATOR."studynotes".DIRECTORY_SEPARATOR."server".DIRECTORY_SEPARATOR."filterlib".DIRECTORY_SEPARATOR."HTMLPurifier.standalone.php");
  22. require_once ($CFG->dirroot.DIRECTORY_SEPARATOR."mod".DIRECTORY_SEPARATOR."studynotes".DIRECTORY_SEPARATOR."server".DIRECTORY_SEPARATOR."equationsupport".DIRECTORY_SEPARATOR."LaTeXrender.php");
  23. require_once ($CFG->dirroot.DIRECTORY_SEPARATOR."mod".DIRECTORY_SEPARATOR."studynotes".DIRECTORY_SEPARATOR."server".DIRECTORY_SEPARATOR."session_handler.php");
  24. $data = ($action == "upload"?$_POST:$_POST['data']);
  25. $ignoreQuotes = true;
  26. foreach ($_POST['data'] as $key=>$value) {
  27. if (!get_magic_quotes_gpc()) {
  28. $data[$key] = stripslashes($value);
  29. }
  30. }
  31. if ($action == "upload") {
  32. $topic = $data['topic'];
  33. $hasAccess = MediabirdUtility::checkAccess($topic, $auth->userId);
  34. if ($hasAccess) {
  35. $userQuota = MediabirdUtility::getUserQuota($auth->userId);
  36. $quotaLeft = MediabirdUtility::quotaLeft($auth->userId, $userQuota);
  37. //determine folder path
  38. $folder = MediabirdConfig::$uploads_folder.$auth->userId.DIRECTORY_SEPARATOR;
  39. $prefix = MediabirdConfig::$uploads_folder;
  40. $key = "file";
  41. $name = $_FILES[$key]['name'];
  42. $_FILES[$key]['name'] = MediabirdUtility::getFreeFilename($folder);
  43. $info = MediabirdUtility::storeUpload($key, $folder, $quotaLeft, $prefix);
  44. if ( isset ($info['filename']) && strlen($info['filename']) > 0) {
  45. if($id = MediabirdUtility::recordFile($info['filename'],0,$auth->userId,$topic)) {
  46. $info['filename'] = 'view.php?action=download&id='.$cm->id.'&did='.$id;
  47. }
  48. else {
  49. $info['filename'] = null;
  50. $info['error'] = "database error";
  51. }
  52. }
  53. else {
  54. $info['filename'] = null;
  55. }
  56. }
  57. else {
  58. $info['filename'] = null;
  59. $info['error'] = "invalidtopic";
  60. }
  61. echo MediabirdUtility::generateUploadHtml($info['filename'], $info['error']);
  62. exit ();
  63. }
  64. if ($action == "download") {
  65. $id = $_GET['did'];
  66. if ( isset ($id)) {
  67. if ($upload_info = get_record("studynotes_uploads", "id", $id)) {
  68. $topicId = $upload_info->topic_id;
  69. $hasAccess = MediabirdUtility::checkAccess($topicId, $auth->userId);
  70. if ($hasAccess) {
  71. MediabirdUtility::readUpload($upload_info->filename, $upload_info->type);
  72. }
  73. }
  74. }
  75. exit ();
  76. }
  77. $handler = new MediabirdSessionHandler();
  78. $reply = $handler->process($action, $auth, $data);
  79. if ( isset ($reply->filename) && isset($reply->success) && isset($reply->topic)) {
  80. if($id = MediabirdUtility::recordFile($reply->filename,0,$auth->userId,$reply->topic)) {
  81. $reply->filename = 'view.php?action=download&id='.$cm->id.'&did='.$id;
  82. }
  83. else {
  84. $reply->success = false;
  85. $reply->error = "database error";
  86. }
  87. }
  88. header("Cache-Control: no-store, no-cache, max-age=0, must-revalidate;");
  89. header("Pragma: no-cache;");
  90. header('Content-Type: application/json;');
  91. return json_encode($reply);
  92. }
  93. $id = optional_param('id', 0, PARAM_INT); // Course Module ID, or
  94. $a = optional_param('a', 0, PARAM_INT); // studynotes ID
  95. if ($id) {
  96. if (!$cm = get_record("course_modules", "id", $id)) {
  97. error("Course Module ID was incorrect");
  98. }
  99. if (!$course = get_record("course", "id", $cm->course)) {
  100. error("Course is misconfigured");
  101. }
  102. if (!$studynotes = get_record("studynotes", "id", $cm->instance)) {
  103. error("Course module is incorrect");
  104. }
  105. }
  106. else {
  107. if (!$studynotes = get_record("studynotes", "id", $a)) {
  108. error("Course module is incorrect");
  109. }
  110. if (!$course = get_record("course", "id", $studynotes->course)) {
  111. error("Course is misconfigured");
  112. }
  113. if (!$cm = get_coursemodule_from_instance("studynotes", $studynotes->id, $course->id)) {
  114. error("Course Module ID was incorrect");
  115. }
  116. }
  117. require_login($course->id);
  118. if (isguestuser() || !isloggedin()) {
  119. error(get_string('login_required', 'studynotes'));
  120. return;
  121. }
  122. if(empty($_COOKIE)) {
  123. error(get_string('cookies_required', 'studynotes'));
  124. return;
  125. }
  126. if(!version_compare(PHP_VERSION,'5.2.0','>=')) {
  127. error(get_string('wrong_php_version', 'studynotes'));
  128. return;
  129. }
  130. $moodleid = $USER->id;
  131. $email = $USER->email;
  132. $fullname = $USER->firstname.' '.$USER->lastname;
  133. if (strlen(trim($fullname)) == 0) {
  134. $fullname = $USER->username;
  135. }
  136. $mediabirdDb = new MediabirdDboMoodle();
  137. $helper = new MediabirdHtmlHelper();
  138. unset ($action);
  139. if ( isset ($_POST["data"]) && isset ($_POST["data"]["action"])) {
  140. $action = $_POST["data"]["action"];
  141. }
  142. else if ( isset ($_GET["action"])) {
  143. $action = $_GET["action"];
  144. }
  145. if ($account_link = get_record("studynotes_account_links", "system", "moodle", "external_id", $moodleid)) {
  146. $mbuser = $account_link->internal_id;
  147. if (! isset ($action)) {
  148. $helper->updateUser($mbuser, $fullname, 1, $email);
  149. }
  150. }
  151. else {
  152. if ($mbuser = $helper->registerUser($fullname, 1, $email)) {
  153. $account_link = (object)null;
  154. $account_link->external_id = $moodleid;
  155. $account_link->internal_id = $mbuser;
  156. $account_link->system = "moodle";
  157. insert_record("studynotes_account_links", $account_link, false);
  158. }
  159. else {
  160. error(get_string('error_linking', 'studynotes'));
  161. }
  162. }
  163. $auth = new MediabirdMoodleAuth($mbuser);
  164. //set up config
  165. MediabirdConfig::$latex_path = $CFG->studynotes_latex_path;
  166. MediabirdConfig::$convert_path = $CFG->studynotes_dvipng_path;
  167. //set up proxy
  168. if(isset($CFG->proxyhost) && strlen($CFG->proxyhost)>0 && (!isset($CFG->proxytype) || $CFG->proxytype == 'HTTP')) {
  169. MediabirdConfig::$proxy_address = $CFG->proxyhost;
  170. MediabirdConfig::$proxy_port = $CFG->proxyport;
  171. }
  172. MediabirdConfig::$uploads_folder = $CFG->dataroot.DIRECTORY_SEPARATOR."1".DIRECTORY_SEPARATOR."moddata".DIRECTORY_SEPARATOR."studynotes".DIRECTORY_SEPARATOR."uploads".DIRECTORY_SEPARATOR;
  173. if (!file_exists(MediabirdConfig::$uploads_folder.$auth->userId)) {
  174. make_mod_upload_directory(1);
  175. make_upload_directory("1/moddata/studynotes/uploads/".$auth->userId); // we store our images in a subfolder in here
  176. }
  177. MediabirdConfig::$cache_folder = $CFG->dataroot.DIRECTORY_SEPARATOR."temp".DIRECTORY_SEPARATOR."studynotes".DIRECTORY_SEPARATOR;
  178. if (!file_exists(MediabirdConfig::$cache_folder)) {
  179. make_upload_directory("temp/studynotes");
  180. }
  181. if ( isset ($action)) {
  182. if ($action == "changePass" || $action == "deleteAccount") {
  183. exit ;
  184. }
  185. if ($action == "load") {
  186. $urlToLoad = MediabirdUtility::getArgNoSlashes($_GET['url']);
  187. $html = MediabirdUtility::loadUrl($urlToLoad);
  188. if ($html == null) {
  189. echo $COULD_NOT_RETRIEVE_LABEL.$urlToLoad;
  190. }
  191. else {
  192. echo $html;
  193. }
  194. }
  195. else {
  196. echo studynotes_handle_session($action, $auth);
  197. }
  198. exit ;
  199. }
  200. add_to_log($course->id, "studynotes", "view", "view.php?id=$cm->id", "$studynotes->id");
  201. //set up plugins and markers from settings
  202. if ( isset ($CFG->studynotes_markers_available) && strlen($CFG->studynotes_markers_available) > 0) {
  203. $markersRaw = explode(",", $CFG->studynotes_markers_available);
  204. $markers = array ();
  205. foreach ($markersRaw as $marker) {
  206. if($marker != "importance" && $marker != "translation") {
  207. $markers[] = 'client.markers.'.ucfirst($marker).'Marker';
  208. }
  209. }
  210. $helper->defaultOptions['markerPlugins'] = $markers;
  211. }
  212. if ( isset ($CFG->studynotes_plugins_available) && strlen($CFG->studynotes_plugins_available) > 0) {
  213. $pluginsRaw = explode(",", $CFG->studynotes_plugins_available);
  214. $plugins = array ();
  215. foreach ($pluginsRaw as $plugin) {
  216. $plugins[] = 'client.pageplugins.displayplugins.'.ucfirst($plugin);
  217. }
  218. $helper->defaultOptions['displayPlugins'] = $plugins;
  219. }
  220. if (! isset ($_GET["frame"])) {
  221. /// Print the page header
  222. $strstudynotess = get_string("modulenameplural", "studynotes");
  223. $strstudynotes = get_string("modulename", "studynotes");
  224. $navigation = format_string($studynotes->name);
  225. print_header_simple(format_string($studynotes->name), "", $navigation, "", "", true, '', navmenu($course, $cm));
  226. $html = '<iframe src="'.$CFG->wwwroot.'/mod/studynotes/view.php?id='.$id.'&frame=true&nored=true" style="width: 100%; height: 540px;" scrolling="no" frameborder="no"></iframe>';
  227. echo $html;
  228. print_footer($course);
  229. }
  230. else {
  231. //set options for overlay
  232. if(!isset($_GET["nored"])) {
  233. $helper->defaultOptions['reduceFeatureSet'] = true;
  234. $fullUrl = $CFG->wwwroot.'/mod/studynotes/view.php?id='.$cm->id;
  235. $helper->defaultOptions['fullLocationFromOverlay'] = $fullUrl;
  236. }
  237. $html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'."\n";
  238. $html .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
  239. $html .= '<head>'."\n";
  240. $html .= '<meta http-equiv="Content-Type" content="text/xhtml; charset=UTF-8"/>'."\n";
  241. $html .= '<title>Mediabird Web2.0-Learning</title>'."\n";
  242. $html .= '<link type="text/css" rel="stylesheet" href="ext/design.css" />';
  243. $html .= '<link type="text/css" rel="stylesheet" href="css/style.css" />';
  244. $html .= '<script type="text/javascript" src="js/jquery.js"></script>';
  245. $html .= '<script type="text/javascript" src="js/client.js"></script>';
  246. $lang = current_language();
  247. if (strlen($lang) > 2) {
  248. $lang = substr($lang, 0, 2);
  249. }
  250. if ($lang == "de") {
  251. $helper->defaultOptions['language'] = MediabirdHtmlHelper::langGerman;
  252. }
  253. else if ($lang == "es") {
  254. $helper->defaultOptions['language'] = MediabirdHtmlHelper::langSpanish;
  255. }
  256. //fixme: provide help for spanish (let users translate help.en.js)
  257. $loadHelp = isset($_GET["nored"]) && ($lang=="de" || $lang=="es" || $lang=="en") && (!isset($CFG->studynotes_show_help) || $CFG->studynotes_show_help);
  258. if($loadHelp) {
  259. $html .= '<script type="text/javascript" src="js/help.'.$lang.'.js"></script>';
  260. }
  261. $html .= '</head>'."\n";
  262. if(isset($_GET["nored"])) {
  263. $html .= '<body class="margin">'."\n";
  264. }
  265. else {
  266. $html .= '<body>'."\n";
  267. }
  268. $html .= '<div id="mediabirdContainer"></div>'."\n";
  269. if(isset($_GET["nored"])) {
  270. $html .= '<div class="subcontainer">'."\n";
  271. $html .= '<p>&copy; 2008-2009 <a href="http://www.mediabird.net/" target="_blank" title="Mediabird Homepage">Mediabird</a>. All rights reserved. Version 0.5.6</p>'."\n";
  272. $html .= '</div>'."\n";
  273. }
  274. $helper->loadUser($auth);
  275. $options = array (
  276. 'dummyPath'=>'dummy.php',
  277. 'loadPath'=>'view.php?action=load&id='.$cm->id.'&url=',
  278. 'uploadPath'=>'view.php?action=upload&id='.$cm->id.'',
  279. 'prefixData'=>true,
  280. 'loadLogon'=>false,
  281. 'furtherArgs'=>'sessionPath: "view.php?id='.$cm->id.'"',
  282. 'imagePath'=>'images/',
  283. 'feedbackPath'=>'mailto:team@mediabird.net',
  284. 'SHIFT_RESEARCH_RIGHT' => 260,
  285. 'SHIFT_RESEARCH_LEFT' => 160
  286. );
  287. if ($loadHelp) {
  288. $options = array_merge(
  289. $options,
  290. array(
  291. 'SHIFT_RESEARCH_RIGHT' => 124,
  292. 'SHIFT_RESEARCH_RIGHT_WIDE' => 324,
  293. 'SHIFT_RESEARCH_LEFT' => 132
  294. )
  295. );
  296. }
  297. $options['linkPrefix'] = $CFG->wwwroot;
  298. $options['linkTarget'] = '_parent';
  299. if ( isset ($_GET["frame"]) && isset ($_GET["mb_url"])) {
  300. $options['linkUrl'] = $_GET["mb_url"];
  301. $options['linkTitle'] = isset($_GET["mb_title"]) ? $_GET["mb_title"] : get_string('moodle_ref_title', 'studynotes');
  302. }
  303. if ( isset ($_GET["frame"]) && isset ($_GET["mb_card_id"])) {
  304. $options['loadCard'] = intval($_GET["mb_card_id"]);
  305. }
  306. $script = $helper->bodyScript($options);
  307. if($loadHelp) {
  308. $script .='<script type="text/javascript">'."\n";
  309. $script .='//<![CDATA['."\n";
  310. $script .='(new mediabird.help()).load($("#mediabirdContainer div.mb-cont").css("left",-40));'."\n";
  311. $script .='//]]>'."\n";
  312. $script .='</script>'."\n";
  313. }
  314. $html .= $script."\n";
  315. $html .= '</body>'."\n";
  316. echo $html;
  317. }
  318. ?>