PageRenderTime 56ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/connectors/moodle/copy_to_moodle/segue_link.php

https://github.com/adamfranco/segue-1.x
PHP | 777 lines | 455 code | 128 blank | 194 comment | 78 complexity | 8f882596fbd9ee9945c5d2f9080ba69d MD5 | raw file
  1. <?php // $Id$
  2. require_once("../config.php");
  3. require_once("../lib/datalib.php");
  4. require_once("../lib/moodlelib.php");
  5. require_once("../course/lib.php");
  6. require_once("connector.conf.php");
  7. error_reporting(E_ALL & ~E_NOTICE);
  8. ob_start();
  9. $cid = mysql_pconnect($dblink_host,$dblink_user,$dblink_pass);
  10. mysql_select_db($dblink_db);
  11. //printpre($_REQUEST);
  12. //printpre($_SESSION);
  13. //print "Moodle-Segue API<hr>";
  14. /******************************************************************************
  15. * start HTML output
  16. ******************************************************************************/
  17. ?>
  18. <html>
  19. <head>
  20. <title>Segue - Measure Connection</title>
  21. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  22. <style type="text/css">
  23. a {
  24. color: #003366;
  25. text-decoration: none;
  26. }
  27. a:hover {
  28. text-decoration: underline;
  29. }
  30. .error {
  31. margin-top: 10px;
  32. color: #990000;
  33. font-size: 14px;
  34. }
  35. .back {
  36. font-size: 16px;
  37. align: center;
  38. padding: 5px;
  39. }
  40. .connection {
  41. font-size: 16px;
  42. text-align: center;
  43. padding: 10px;
  44. margin: 50px;
  45. border: 1px dotted #666666;
  46. }
  47. </style>
  48. </head>
  49. <body>
  50. <?
  51. /******************************************************************************
  52. * Provide links back to referer and/or Measure home
  53. ******************************************************************************/
  54. print "<div class='connection'>";
  55. print "Connnecting to Moodle...<br/><br/>";
  56. if ($_SERVER['HTTP_REFERER']) print "<a href='".$_SERVER['HTTP_REFERER']."'>&lt;&lt; back</a> | ";
  57. print "<a href='".$segue_url."'>Segue Home</a>";
  58. print "</div>";
  59. //exit;
  60. /******************************************************************************
  61. * if id in request from Measure, then build url back to Segue
  62. ******************************************************************************/
  63. if ($_REQUEST['id']) {
  64. /******************************************************************************
  65. * Check if the user has a referer listed, if so take them there.
  66. ******************************************************************************/
  67. $query = "
  68. SELECT
  69. referer
  70. FROM
  71. authentication
  72. LEFT JOIN
  73. user_link ON auth_id = FK_auth_id
  74. WHERE
  75. user_link.system = 'moodle'
  76. AND user_link.user_id = '".addslashes($_SESSION['USER']->id)."'
  77. ";
  78. $r = mysql_query($query, $cid);
  79. if (mysql_num_rows($r)) {
  80. $a = mysql_fetch_assoc($r);
  81. if ($a['referer']) {
  82. //print "Segue site url: ".$a['referer']."<br \>";
  83. header("Location: ".$a['referer']);
  84. exit;
  85. }
  86. }
  87. /******************************************************************************
  88. * otherwise, go to the corresponding Segue site
  89. ******************************************************************************/
  90. $query = "
  91. SELECT
  92. site_slot
  93. FROM
  94. segue_moodle
  95. WHERE
  96. FK_moodle_site_id = '".addslashes($_REQUEST['id'])."'
  97. ";
  98. //print $query."<br>";
  99. //exit;
  100. $r = mysql_query($query, $cid);
  101. $a = mysql_fetch_assoc($r);
  102. //if no corresponding site, go to Segue home
  103. if (mysql_num_rows($r) == 0) {
  104. $admin_report = "No matching Segue site...<br>";
  105. //print $segue_url;
  106. link_log(0, 0, $category="errors",$description="No linked Segue site");
  107. header("Location: ".$PHP_SELF);
  108. exit;
  109. }
  110. //if corresponding site, go to home page of that site
  111. $segue_slot = $a['site_slot'];
  112. // print "Segue site url: ".$segue_url."sites/".$segue_slot."<br \>";
  113. header("Location: ".$segue_url."sites/".$segue_slot);
  114. exit;
  115. }
  116. /******************************************************************************
  117. * Validate request array values from Segue
  118. ******************************************************************************/
  119. if (!isset($_REQUEST['userid']) || !$_REQUEST['userid']) {
  120. print "<div class='error'>No user id passed...</div>";
  121. print "</body</html>";
  122. link_log(0, $_REQUEST['siteid'], $category="errors",$description="No Segue user id passed");
  123. exit;
  124. } else if (!isset($_REQUEST['auth_token']) || !$_REQUEST['auth_token']) {
  125. print "<div class='error'>No authentication token passed...</div>";
  126. print "</body</html>";
  127. link_log($_REQUEST['userid'], $_REQUEST['siteid'], $category="errors",$description="No authentication token passed");
  128. exit;
  129. } else if (!isset($_REQUEST['siteid']) || !$_REQUEST['siteid']) {
  130. print "<div class='error'>No site id passed...</div>";
  131. print "</body</html>";
  132. link_log($_REQUEST['userid'], $_REQUEST['siteid'], $category="errors",$description="No site id passed");
  133. exit;
  134. } else {
  135. $segue_user_id = $_REQUEST['userid'];
  136. $auth_token = $_REQUEST['auth_token'];
  137. /******************************************************************************
  138. * Check that Segue user id and auth_token from request array
  139. * match what is in the authentication table in the segue-moodle link database
  140. ******************************************************************************/
  141. $query = "
  142. SELECT
  143. auth_token
  144. FROM
  145. authentication
  146. WHERE
  147. user_id = '".addslashes($_REQUEST['userid'])."'
  148. AND auth_token = '".addslashes($_REQUEST['auth_token'])."'
  149. AND DATE_ADD(auth_time, INTERVAL 1 MINUTE) > NOW()
  150. ";
  151. //print $query."<br>";
  152. //exit;
  153. $r = mysql_query($query, $cid);
  154. $a = mysql_fetch_assoc($r);
  155. // failed auth_token test
  156. if (mysql_num_rows($r) == 0) {
  157. print "<div class='error'>No matching authentication token or user id or authentication token has expired...</div>";
  158. print "</body</html>";
  159. link_log($_REQUEST['userid'], $_REQUEST['siteid'], $category="errors",$description="auth_token expired or not passed or no user id");
  160. exit;
  161. }
  162. /******************************************************************************
  163. * Check for corresponding Moodle user
  164. ******************************************************************************/
  165. $query = "
  166. SELECT
  167. user_link.system, user_link.user_id
  168. FROM
  169. user_link
  170. INNER JOIN
  171. authentication
  172. ON
  173. FK_auth_id = auth_id
  174. WHERE
  175. authentication.system = 'segue'
  176. AND
  177. user_link.system = 'moodle'
  178. AND
  179. authentication.user_id = '".addslashes($segue_user_id)."'
  180. ";
  181. // print $query."<br>";
  182. //exit;
  183. $r = mysql_query($query, $cid);
  184. $a = mysql_fetch_assoc($r);
  185. $moodle_user_id = $a['user_id'];
  186. // print "moodle_user_id:".$moodle_user_id."<br \>";
  187. // exit;
  188. /******************************************************************************
  189. * If corresponding Moodle user found in user_link table
  190. * make sure that user still exists in Moodle user table
  191. ******************************************************************************/
  192. // if ($moodle_user_id != 0) {
  193. // $record = get_record('user', 'id', $moodle_user_id);
  194. // if (!$record || $record->deleted == '1') {
  195. // print "corresponding Moodle user no longer exists";
  196. //
  197. // //delete Moodle user from user_link table
  198. // $query = "
  199. // DELETE FROM
  200. // user_link
  201. // WHERE
  202. // user_id = '".addslashes($moodle_user_id)."'
  203. // ";
  204. //
  205. // print $query."<br>";
  206. // //exit;
  207. // $r = mysql_query($query, $cid);
  208. // $moodle_user_id = 0;
  209. // }
  210. // }
  211. }
  212. //print "moodle_user_id:".$moodle_user_id."<br \>";
  213. //print "segue_user_id:".$segue_user_id."<br \>";
  214. //exit;
  215. /******************************************************************************
  216. * If no record of linked Moodle user in linking table, check to see
  217. * if there is a LDAP Moodle user with same username
  218. ******************************************************************************/
  219. if ($moodle_user_id == 0) {
  220. // get info about the linked user
  221. $query = "
  222. SELECT
  223. username, firstname, lastname, email, auth_id
  224. FROM
  225. authentication
  226. WHERE
  227. user_id = '".addslashes($_REQUEST['userid'])."'
  228. AND auth_token = '".addslashes($_REQUEST['auth_token'])."'
  229. AND DATE_ADD(auth_time, INTERVAL 1 MINUTE) > NOW()
  230. ";
  231. $r = mysql_query($query, $cid);
  232. // failed auth_token test
  233. if (mysql_num_rows($r) == 0) {
  234. print "<div class='error'>No matching authentication token or user id...</div>";
  235. print "</body</html>";
  236. exit;
  237. }
  238. // passed auth_token test so get Segue user info
  239. while ($a = mysql_fetch_assoc($r)) {
  240. $firstname = ereg_replace("['\"]", "", $a['firstname']);
  241. $lastname = ereg_replace("['\"]", "", $a['lastname']);
  242. $email = $a['email'];
  243. $user_uname = $a['username'];
  244. $auth_id = $a['auth_id'];
  245. }
  246. /******************************************************************************
  247. * Check for LDAP Moodle user with same username
  248. * If one exists then update linking table
  249. ******************************************************************************/
  250. if ($user = get_record('user', 'username', $user_uname)) {
  251. //verify user is an LDAP user
  252. if ($user->auth == "ldap") {
  253. $moodle_user_id = $user->id;
  254. //update user_link table
  255. $query = "
  256. UPDATE
  257. user_link
  258. SET
  259. user_id = '".addslashes($moodle_user_id)."',
  260. system = 'moodle'
  261. WHERE
  262. FK_auth_id = '".addslashes($auth_id)."'
  263. ";
  264. // print $query."<br>";
  265. // exit;
  266. $r = mysql_query($query, $cid);
  267. }
  268. /******************************************************************************
  269. * If No LDAP Moodle user with same username, then
  270. * Create new Moodle user if no user exists that corresponds to Segue user
  271. * add key to that user in user_link table in segue-moodle database
  272. * New Moodle user code is adapted from:
  273. * moodle/admin/users.php
  274. ******************************************************************************/
  275. } else {
  276. $admin_report .= "<hr>Creating new Moodle user...<br>";
  277. // get info about the linked user
  278. // $query = "
  279. // SELECT
  280. // username, firstname, lastname, email, auth_id
  281. // FROM
  282. // authentication
  283. // WHERE
  284. // user_id = '".addslashes($_REQUEST['userid'])."'
  285. // AND auth_token = '".addslashes($_REQUEST['auth_token'])."'
  286. // AND DATE_ADD(auth_time, INTERVAL 1 MINUTE) > NOW()
  287. //
  288. // ";
  289. //
  290. // // print $query."<br>";
  291. // //exit;
  292. // $r = mysql_query($query, $cid);
  293. //
  294. // // failed auth_token test
  295. // if (mysql_num_rows($r) == 0) {
  296. // print "<div class='error'>No matching authentication token or user id...</div>";
  297. // print "</body</html>";
  298. // exit;
  299. //
  300. // // passed auth_token test so get Segue user info
  301. // } else {
  302. // while ($a = mysql_fetch_assoc($r)) {
  303. // $firstname = ereg_replace("['\"]", "", $a['firstname']);
  304. // $lastname = ereg_replace("['\"]", "", $a['lastname']);
  305. // $email = $a['email'];
  306. // $user_uname = $a['username'];
  307. // $auth_id = $a['auth_id'];
  308. // }
  309. //
  310. // // print "firstname: ".$firstname."<br \>";
  311. // // print "lastname: ".$lastname."<br \>";
  312. // // print "email: ".$email."<br \>";
  313. // // print "user_uname: ".$user_uname."<br \>";
  314. // // print "auth_id: ".$auth_id."<br \>";
  315. //
  316. // }
  317. // //exit;
  318. //create new moodle user (need user fname, lname, email)
  319. // adapted from: moodle/admin/users.php
  320. $user->firstname = $firstname;
  321. $user->username = $user_uname;
  322. $user->lastname = $lastname;
  323. $user->email = $email;
  324. $user->firstaccess = time();
  325. $user->auth = "ldap";
  326. $user->password = "not cached";
  327. $user->lang = "en_utf8";
  328. $user->mnethostid = 1;
  329. $user->confirmed = 1;
  330. // printpre ($user);a
  331. // exit;
  332. if (! ($user->id = insert_record("user", $user)) ) {
  333. error("Could not add your record to the database!");
  334. } else {
  335. $moodle_user_id = $user->id;
  336. //update user_link table
  337. $query = "
  338. UPDATE
  339. user_link
  340. SET
  341. user_id = '".addslashes($moodle_user_id)."',
  342. system = 'moodle'
  343. WHERE
  344. FK_auth_id = '".addslashes($auth_id)."'
  345. ";
  346. // print $query."<br>";
  347. // exit;
  348. $r = mysql_query($query, $cid);
  349. }
  350. // print "new moodle user_id: ".$moodle_user_id."<br>";
  351. link_log($_REQUEST['userid'], $_REQUEST['siteid'], $category="user_added",$description="Measure user created");
  352. //exit;
  353. }
  354. }
  355. /******************************************************************************
  356. * end new Moodle user
  357. ******************************************************************************/
  358. /******************************************************************************
  359. * Check for corresponding Moodle site
  360. ******************************************************************************/
  361. $query = "
  362. SELECT
  363. FK_moodle_site_id
  364. FROM
  365. segue_moodle
  366. WHERE
  367. FK_segue_site_id = '".addslashes($_REQUEST['siteid'])."'
  368. ";
  369. //print $query."<br>";
  370. //exit;
  371. $r = mysql_query($query, $cid);
  372. $a = mysql_fetch_assoc($r);
  373. $moodle_site_id = $a['FK_moodle_site_id'];
  374. /******************************************************************************
  375. * Get the Segue site owner and title from the site_link table
  376. ******************************************************************************/
  377. //print "<hr>Segue site owner and title site";
  378. $query = "
  379. SELECT
  380. site_title, site_slot, site_owner_id, site_theme
  381. FROM
  382. segue_moodle
  383. WHERE
  384. FK_segue_site_id = '".addslashes($_REQUEST['siteid'])."'
  385. ";
  386. //print $query."<br>";
  387. //exit;
  388. $r = mysql_query($query, $cid);
  389. while ($a = mysql_fetch_assoc($r)) {
  390. $site_title = $a['site_title'];
  391. $site_slot = $a['site_slot'];
  392. $site_owner_id = $a['site_owner_id'];
  393. $site_theme = $a['site_theme'];
  394. }
  395. //print "site_title: ".$site_title."<br \>";
  396. //print "site_slot: ".$site_slot."<br \>";
  397. //print "site_owner_id: ".$site_owner_id."<br \>";
  398. //print "site_theme: ".$site_theme."<br \><hr>";
  399. if ($site_theme == "shadowbox") {
  400. $site_theme = "standardlogo";
  401. } else if ($site_theme == "beveledge") {
  402. $site_theme = "standardlogo";
  403. } else if ($site_theme == "tornpaper") {
  404. $site_theme = "standardlogo";
  405. } else {
  406. $site_theme = "standardlogo";
  407. }
  408. //exit;
  409. /******************************************************************************
  410. * Make sure corresponding Moodle site still exists in Moodle
  411. ******************************************************************************/
  412. if (isset($moodle_site_id) && $moodle_site_id != 0) {
  413. if (!$site = get_record('course', 'id', $moodle_site_id)) {
  414. print "corresponding Moodle site no longer exists";
  415. link_log($_REQUEST['userid'], $_REQUEST['siteid'], $category="error",$description="linked Measure site deleted");
  416. //delete Moodle site from segue_moodle table
  417. $query = "
  418. DELETE FROM
  419. segue_moodle
  420. WHERE
  421. FK_moodle_site_id = '".addslashes($moodle_site_id)."'
  422. ";
  423. $r = mysql_query($query, $cid);
  424. // print $query."<br>";
  425. // exit;
  426. $moodle_site_id = 0;
  427. $moodle_site_deleted = 1;
  428. }
  429. }
  430. //print "moodle_site_id: ".$moodle_site_id."<br \>";
  431. //exit;
  432. /******************************************************************************
  433. * if no corresponding Moodle site, then create one
  434. * and add key to that site in segue-moodle table
  435. * new Moodle site code adapted from:
  436. * moodle/course/edit.php
  437. ******************************************************************************/
  438. if ($moodle_site_id == 0 && $segue_user_id == $site_owner_id) {
  439. // print "<hr>Creating new Moodle site...<br>";
  440. require_once("../course/lib.php");
  441. require_once($CFG->libdir."/blocklib.php");
  442. // print "<hr>Creating new Moodle site...<br>";
  443. fix_course_sortorder();
  444. $form->startdate = make_timestamp($form->startyear, $form->startmonth, $form->startday);
  445. $form->format = 'topics';
  446. $form->timecreated = time();
  447. $form->sortorder = 100;
  448. $form->fullname = $site_title;
  449. $form->shortname = $site_slot;
  450. $form->summary = "These are assessments for ".$site_title;
  451. $form->theme = $site_theme;
  452. $form->visible = 1;
  453. $form->category = 1;
  454. $form->enrollable = 0;
  455. $form->teacher = "Instructor";
  456. $form->teachers = "Instructors";
  457. $form->student = "Participant";
  458. $form->students = "Participants";
  459. if ($newcourseid = insert_record('course', $form)) { // Set up new course
  460. $page = page_create_object(PAGE_COURSE_VIEW, $newcourseid);
  461. blocks_repopulate_page($page); // Return value not checked because you can always edit later
  462. $section = NULL;
  463. $section->course = $newcourseid; // Create a default section.
  464. $section->section = 0;
  465. $section->id = insert_record("course_sections", $section);
  466. fix_course_sortorder();
  467. add_to_log(SITEID, "course", "new", "view.php?id=$newcourseid", "$form->fullname (ID $newcourseid)");
  468. fix_course_sortorder();
  469. }
  470. /******************************************************************************
  471. * Update the segue_moodle link table
  472. ******************************************************************************/
  473. $moodle_site_id = $newcourseid;
  474. if ($moodle_site_deleted == 1) {
  475. $query = "
  476. INSERT INTO
  477. segue_moodle
  478. SET
  479. FK_moodle_site_id = '".addslashes($moodle_site_id)."',
  480. FK_segue_site_id = '".addslashes($_REQUEST['siteid'])."'
  481. ";
  482. } else {
  483. $query = "
  484. UPDATE
  485. segue_moodle
  486. SET
  487. FK_moodle_site_id = '".addslashes($moodle_site_id)."'
  488. WHERE
  489. FK_segue_site_id = '".addslashes($_REQUEST['siteid'])."'
  490. ";
  491. }
  492. $r = mysql_query($query, $cid);
  493. // print $query."<br>";
  494. //exit;
  495. // print "new moodle site_id: ".$moodle_site_id."<br>";
  496. link_log($_REQUEST['userid'], $_REQUEST['siteid'], $category="site_added",$description="Measure site created");
  497. //exit;
  498. }
  499. /******************************************************************************
  500. * end new Moodle site
  501. ******************************************************************************/
  502. /******************************************************************************
  503. * if the Segue user is not the site owner, then enrol them as student
  504. * code adapted from:
  505. * moodle/course/student.php
  506. ******************************************************************************/
  507. if ($segue_user_id != $site_owner_id){
  508. //print "<hr>Adding student to site<br>";
  509. //print "moodle_site_id: ".$moodle_site_id;
  510. $addstudent = $moodle_user_id;
  511. $timestart = $timeend = 0;
  512. if (! enrol_student($addstudent, $moodle_site_id, $timestart, $timeend)) {
  513. error("Could not add student with id $addstudent to this course!");
  514. }
  515. /******************************************************************************
  516. * if new course id and the auth user is the site owner then make that user a teacher
  517. * moodle_site_id, moodle_user_id and site_owner_id set above
  518. * segue_user_id from request array
  519. * code adapted from:
  520. * moodle/course/info.php
  521. ******************************************************************************/
  522. } else if ($newcourseid && $segue_user_id == $site_owner_id) {
  523. // print "<hr>New Moodle Course created<br>";
  524. // print "newcourseid: ".$newcourseid."<br>";
  525. // print "moodle_user_id: ".$moodle_user_id."<br>";
  526. //need to get the context for the new course
  527. $context = get_context_instance(CONTEXT_COURSE, $newcourseid);
  528. $contextid = $context->id;
  529. // print $contextid;
  530. // exit;
  531. // change role to teacher
  532. $newteacher = NULL;
  533. $newteacher->userid = $moodle_user_id;
  534. $newteacher->contextid = $contextid;
  535. $newteacher->roleid = 3;
  536. // $newteacher->authority = 1; // First teacher is the main teacher
  537. // $newteacher->editall = 1; // Course creator can edit their own course
  538. $newteacher->enrol = "manual"; // enroll the teacher in the course
  539. if (!$newteacher->id = insert_record("role_assignments", $newteacher)) {
  540. error("Could not add you to this new course!");
  541. }
  542. // print "moodle_user_id: ".$moodle_user_id." made the owner of new moodle course id:".$newcourseid."<br>";
  543. //exit;
  544. $USER->teacher[$newcourseid] = true;
  545. $USER->teacheredit[$newcourseid] = true;
  546. }
  547. //exit;
  548. /******************************************************************************
  549. * end Moodle permissions assignment (i.e. adding teacher, students)
  550. ******************************************************************************/
  551. /******************************************************************************
  552. * Log into Moodle
  553. * Login code adapted from:
  554. * moodle/login/index.php
  555. * Moodle functions get_record (datalib.php) and
  556. * get_complete_user_record (lib/moodlelib.php) when passed 'user' or 'username'
  557. ******************************************************************************/
  558. $user_id = $moodle_user_id;
  559. if ($user = get_record('user', 'id', $user_id)) {
  560. // print "<hr>logging into Moodle...";
  561. $user = get_complete_user_data('username', $user->username);
  562. $USER = $user;
  563. add_to_log(SITEID, 'user', 'login', "view.php?id=$USER->id&course=".SITEID, $USER->id, 0, $USER->id);
  564. update_user_login_times();
  565. set_moodle_cookie($USER->username);
  566. set_login_session_preferences();
  567. //Select password change url
  568. if (is_internal_auth($USER->auth) || $CFG->{'auth_'.$USER->auth.'_stdchangepassword'}){
  569. $passwordchangeurl=$CFG->wwwroot.'/login/change_password.php';
  570. } elseif($CFG->changepassword) {
  571. $passwordchangeurl=$CFG->changepassword;
  572. } else {
  573. $passwordchangeurl = '';
  574. }
  575. // check whether the user should be changing password
  576. if (get_user_preferences('auth_forcepasswordchange', false) || $frm->password == 'changeme'){
  577. if ($passwordchangeurl != '') {
  578. redirect($passwordchangeurl);
  579. } else {
  580. error("You cannot proceed without changing your password.
  581. However there is no available page for changing it.
  582. Please contact your Moodle Administrator.");
  583. }
  584. }
  585. /// Prepare redirection
  586. if (user_not_fully_set_up($USER)) {
  587. $urltogo = $CFG->wwwroot.'/user/edit.php?id='.$USER->id.'&amp;course='.SITEID;
  588. // We don't delete $SESSION->wantsurl yet, so we get there later
  589. } else if (isset($SESSION->wantsurl) and (strpos($SESSION->wantsurl, $CFG->wwwroot) === 0)) {
  590. $urltogo = $SESSION->wantsurl; /// Because it's an address in this site
  591. unset($SESSION->wantsurl);
  592. } else {
  593. // no wantsurl stored or external - go to homepage
  594. $urltogo = $CFG->wwwroot.'/';
  595. unset($SESSION->wantsurl);
  596. }
  597. /// Go to my-moodle page instead of homepage if mymoodleredirect enabled
  598. if (!isadmin() and !empty($CFG->mymoodleredirect) and !isguest()) {
  599. if ($urltogo == $CFG->wwwroot or $urltogo == $CFG->wwwroot.'/' or $urltogo == $CFG->wwwroot.'/index.php') {
  600. $urltogo = $CFG->wwwroot.'/my/';
  601. }
  602. }
  603. reset_login_count();
  604. //$urltogo = $CFG->wwwroot."/mod/quiz/view.php?id=$module_id";
  605. $urltogo = $CFG->wwwroot.'/course/view.php?id='.$moodle_site_id;
  606. //$urltogo = $CFG->wwwroot;
  607. if ($_REQUEST[mod]) {
  608. $module_url = $CFG->wwwroot."/mod/".$_REQUEST[mod]."/view.php?id=".$module_id;
  609. // print $module_url;
  610. header("Location: ".$module_url);
  611. } else {
  612. //print "<hr>Go to: <a href='".$CFG->wwwroot."/mod/".$_REQUEST[mod]."/view.php?id=$module_id'>module id= ".$module_id."</a> | ";
  613. // print "<a href='".$urltogo."'>Moodle Home</a><hr>";
  614. }
  615. redirect($urltogo);
  616. }
  617. function printpre($array, $return=FALSE) {
  618. $string = "\n<pre>";
  619. $string .= print_r($array, TRUE);
  620. $string .= "\n</pre>";
  621. if ($return)
  622. return $string;
  623. else
  624. print $string;
  625. }
  626. function link_log($auth_id="",$site_link_id="",$category="event",$description="") {
  627. global $dblink_host,$dblink_user,$dblink_pass;
  628. $cid = mysql_pconnect($dblink_host,$dblink_user,$dblink_pass);
  629. $query = "
  630. INSERT INTO
  631. logs
  632. SET
  633. FK_auth_id = '".addslashes($auth_id)."',
  634. FK_site_link = '".addslashes($site_link_id)."',
  635. category = '".addslashes($category)."',
  636. description = '".addslashes($description)."'
  637. ";
  638. //print $query;
  639. //exit;
  640. $r = mysql_query($query, $cid);
  641. }
  642. ?>