PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/extras.php

https://github.com/eviweb/moodle-mod_turnitintool
PHP | 601 lines | 519 code | 70 blank | 12 comment | 58 complexity | 927168bfee557502505a96930cf6fbf5 MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php // $Id: extras.php,v 1.2 2010/06/25 11:49:46 paul.dawson Exp $
  2. /**
  3. * @package turnitintool
  4. * @copyright 2012 Turnitin
  5. */
  6. require_once('../../config.php');
  7. require_once('../../course/lib.php');
  8. require_once($CFG->libdir.'/adminlib.php');
  9. require_once($CFG->libdir.'/tablelib.php');
  10. require_once("lib.php");
  11. if (!is_callable('groups_get_activity_group')) {
  12. $adminroot = admin_get_root();
  13. admin_externalpage_setup('managemodules',$adminroot);
  14. } else {
  15. admin_externalpage_setup('managemodules');
  16. }
  17. if (isset($PAGE) AND @is_callable(array($PAGE->requires, 'js'))) { // Are we using new moodle or old?
  18. $jsurl = new moodle_url($CFG->wwwroot.'/mod/turnitintool/scripts/jquery-1.7.2.min.js');
  19. $PAGE->requires->js($jsurl,true);
  20. $jsurl = new moodle_url($CFG->wwwroot.'/mod/turnitintool/scripts/datatables.min.js');
  21. $PAGE->requires->js($jsurl);
  22. $jsurl = new moodle_url($CFG->wwwroot.'/mod/turnitintool/scripts/datatables.plugins.js');
  23. $PAGE->requires->js($jsurl);
  24. $jsurl = new moodle_url($CFG->wwwroot.'/mod/turnitintool/scripts/turnitintool.js');
  25. $PAGE->requires->js($jsurl,true);
  26. $cssurl = new moodle_url($CFG->wwwroot.'/mod/turnitintool/styles.css');
  27. $PAGE->requires->css($cssurl);
  28. } else {
  29. require_js($CFG->wwwroot.'/mod/turnitintool/scripts/jquery-1.7.2.min.js');
  30. require_js($CFG->wwwroot.'/mod/turnitintool/scripts/turnitintool.js');
  31. }
  32. $a = optional_param('a', 0, PARAM_INT); // turnitintool ID
  33. $s = optional_param('s', 0, PARAM_INT); // submission ID
  34. $type = optional_param('type', 0, PARAM_INT); // submission ID
  35. if (!turnitintool_check_config()) {
  36. print_error('configureerror','turnitintool');
  37. exit();
  38. }
  39. /// Print the main part of the page
  40. $param_do=optional_param('do',null,PARAM_CLEAN);
  41. $param_unlink=optional_param('unlink',null,PARAM_CLEAN);
  42. $param_relink=optional_param('relink',null,PARAM_CLEAN);
  43. $param_filedate=optional_param('filedate',null,PARAM_CLEAN);
  44. $param_fileid=optional_param('fileid',null,PARAM_CLEAN);
  45. $param_filerem=optional_param('filerem',null,PARAM_CLEAN);
  46. $param_filehash=optional_param('filehash',null,PARAM_CLEAN);
  47. $post["userlinks"] = isset( $_REQUEST['userlinks'] ) ? $_REQUEST["userlinks"] : array();
  48. foreach ( $post["userlinks"] as $key => $value ) {
  49. $param_userlinks[$key] = clean_param( $value, PARAM_INT );
  50. }
  51. if (!is_null($param_do) AND ( $param_do=="viewreport" OR $param_do=="savereport" ) ) {
  52. if ($param_do=='viewreport') {
  53. echo '<pre>';
  54. echo "====== Turnitintool Data Dump Output ======
  55. ";
  56. } else if ($param_do=='savereport') {
  57. $filename='tii_datadump_'.$CFG->turnitin_account_id.'_'.date('dmYhm',time()).'.txt';
  58. header('Content-type: text/plain');
  59. header('Content-Disposition: attachment; filename="'.$filename.'"');
  60. echo "====== Turnitintool Data Dump File ======
  61. ";
  62. }
  63. $tables = array('turnitintool_users','turnitintool_courses','turnitintool','turnitintool_parts','turnitintool_submissions');
  64. foreach ($tables as $table) {
  65. echo "== ".$table." ==
  66. ";
  67. if ($data=turnitintool_get_records($table)) {
  68. $headers=array_keys(get_object_vars(current($data)));
  69. $columnwidth=25;
  70. echo str_pad('',(($columnwidth+2)*count($headers)),"=");
  71. if ($table=='turnitintool_users') {
  72. echo str_pad('',$columnwidth+2,"=");
  73. }
  74. echo "
  75. ";
  76. foreach ($headers as $header) {
  77. echo ' '.str_pad($header,$columnwidth," ",1).'|';
  78. }
  79. if ($table=='turnitintool_users') {
  80. echo ' '.str_pad('Name',$columnwidth," ",1).'|';
  81. }
  82. echo "
  83. ";
  84. echo str_pad('',(($columnwidth+2)*count($headers)),"=");
  85. if ($table=='turnitintool_users') {
  86. echo str_pad('',$columnwidth+2,"=");
  87. }
  88. echo "
  89. ";
  90. foreach ($data as $datarow) {
  91. $datarow=get_object_vars($datarow);
  92. foreach ($datarow as $datacell) {
  93. echo ' '.htmlspecialchars(str_pad(substr($datacell,0,$columnwidth),$columnwidth," ",1)).'|';
  94. }
  95. if ($table=='turnitintool_users' AND $moodleuser=turnitintool_get_record('user','id',$datarow['userid'])) {
  96. echo ' '.str_pad(substr($moodleuser->firstname.' '.$moodleuser->lastname,0,$columnwidth),$columnwidth," ",1).'|';
  97. } else {
  98. echo ' '.str_pad(' ',$columnwidth," ",1).'|';
  99. }
  100. echo "
  101. ";
  102. }
  103. echo str_pad('',(($columnwidth+2)*count($headers)),"-");
  104. if ($table=='turnitintool_users') {
  105. echo str_pad('',$columnwidth+2,"-");
  106. }
  107. echo "
  108. ";
  109. } else {
  110. echo get_string('notavailableyet','turnitintool')."
  111. ";
  112. }
  113. }
  114. if ($param_do=='viewreport') {
  115. echo "</pre>";
  116. }
  117. } else if (!is_null($param_do) AND $param_do=="unlinkusers") {
  118. if (!is_null($param_unlink) AND isset($param_userlinks) AND count($param_userlinks)>0) {
  119. foreach ($param_userlinks as $userlink) {
  120. $user = new stdClass();
  121. $user->id = $userlink;
  122. if ( $tuser = turnitintool_get_record('turnitintool_users','id',$userlink) AND $muser = turnitintool_get_record('user','id',$tuser->userid) ) {
  123. $user->turnitin_uid = 0;
  124. turnitintool_update_record('turnitintool_users',$user);
  125. } else {
  126. turnitintool_delete_records_select('turnitintool_users','id',$userlink);
  127. }
  128. }
  129. }
  130. if (!is_null($param_relink) AND isset($param_userlinks) AND count($param_userlinks)>0) {
  131. $loaderbar = new turnitintool_loaderbarclass(count($param_userlinks));
  132. foreach ($param_userlinks as $userlink) {
  133. if ( $tuser = turnitintool_get_record('turnitintool_users','id',$userlink) AND $muser = turnitintool_get_record('user','id',$tuser->userid) ) {
  134. // Get the email address if the user has been deleted
  135. if ( empty( $muser->email ) OR strpos( $muser->email, '@' ) === false ) {
  136. $split=explode('.',$muser->username);
  137. array_pop($split);
  138. $muser->email=join('.',$split);
  139. }
  140. $tuser->turnitin_utp = ( $tuser->turnitin_utp != 0 ) ? $tuser->turnitin_utp : 1;
  141. $tii = new turnitintool_commclass(null,$muser->firstname,$muser->lastname,$muser->email,$tuser->turnitin_utp,$loaderbar);
  142. $tii->createUser($post,get_string('userprocess','turnitintool'));
  143. $user = new stdClass();
  144. $user->id = $userlink;
  145. $user->turnitin_uid = ( $tii->getRerror() ) ? 0 : $tii->getUserID();
  146. turnitintool_update_record('turnitintool_users',$user);
  147. unset($tii);
  148. } else {
  149. turnitintool_delete_records('turnitintool_users','id',$userlink);
  150. }
  151. }
  152. unset($loader);
  153. turnitintool_redirect($CFG->wwwroot.'/mod/turnitintool/extras.php?do=unlinkusers');
  154. }
  155. turnitintool_header(NULL,NULL,$_SERVER["REQUEST_URI"],get_string("modulenameplural", "turnitintool"), $SITE->fullname);
  156. echo '<div id="turnitintool_style">';
  157. turnitintool_box_start('generalbox boxaligncenter', 'general');
  158. echo '<b>'.get_string('unlinkrelinkusers','turnitintool').'</b><br /><br />';
  159. // 'tu.userid', 'tu.turnitin_uid', 'tu.turnitin_utp', 'mu.firstname', 'mu.lastname', 'mu.email', 'tu.turnitin_uid'
  160. if ( isset($CFG->turnitin_enablepseudo) AND $CFG->turnitin_enablepseudo == 1 ) {
  161. $pseudo = 1;
  162. $pseudo_visible = 'true';
  163. } else {
  164. $pseudo = 0;
  165. $pseudo_visible = 'false';
  166. }
  167. echo '
  168. <style>
  169. #unlink .header.sort div {
  170. background: url(pix/sortnone.png) no-repeat right center;
  171. }
  172. #unlink .header.asc div {
  173. background: url(pix/sortdown.png) no-repeat right center;
  174. }
  175. #unlink .header.desc div {
  176. background: url(pix/sortup.png) no-repeat right center;
  177. }
  178. #turnitintool_style .paginate_disabled_previous {
  179. background: url(pix/prevdisabled.png) no-repeat left center;
  180. }
  181. #turnitintool_style .paginate_enabled_previous {
  182. background: url(pix/prevenabled.png) no-repeat left center;
  183. }
  184. #turnitintool_style .paginate_disabled_next {
  185. background: url(pix/nextdisabled.png) no-repeat right center;
  186. }
  187. #turnitintool_style .paginate_enabled_next {
  188. background: url(pix/nextenabled.png) no-repeat right center;
  189. }
  190. #turnitintool_style .dataTables_processing {
  191. background: url(pix/loaderanim.gif) no-repeat center top;
  192. }
  193. </style>
  194. <script type="text/javascript">
  195. jQuery(document).ready(function() {
  196. jQuery.fn.dataTableExt.oStdClasses.sSortable = "header sort";
  197. jQuery.fn.dataTableExt.oStdClasses.sSortableNone = "header nosort";
  198. jQuery.fn.dataTableExt.oStdClasses.sSortAsc = "header asc";
  199. jQuery.fn.dataTableExt.oStdClasses.sSortDesc = "header desc";
  200. jQuery.fn.dataTableExt.oStdClasses.sWrapper = "submissionTable";
  201. jQuery.fn.dataTableExt.oStdClasses.sStripeOdd = "row r0";
  202. jQuery.fn.dataTableExt.oStdClasses.sStripeEven = "row r1";
  203. jQuery("#unlink").dataTable( {
  204. "bProcessing": true,
  205. "bServerSide": true,
  206. "aoColumns": [
  207. { "sClass": "toggle c0", "sWidth": "5%" },
  208. { "sClass": "turnitin_uid c1", "sWidth": "15%" },
  209. {},
  210. { "sClass": "fullname c2", "sWidth": "'.(($pseudo) ? '40%' : '75%' ).'" },
  211. { "sClass": "pseudo c3", "sWidth": "35%" },
  212. {}
  213. ],
  214. "aoColumnDefs": [
  215. { "bSearchable": true, "bVisible": true, "bSortable": false, "aTargets": [ 0 ] },
  216. { "bSearchable": true, "bVisible": true, "aTargets": [ 1 ] },
  217. { "bSearchable": true, "bVisible": false, "aTargets": [ 2 ] },
  218. { "bSearchable": true, "bVisible": true, "aTargets": [ 3 ] },
  219. { "bSearchable": true, "bVisible": '.$pseudo_visible.', "aTargets": [ 4 ] },
  220. { "bSearchable": true, "bVisible": false, "aTargets": [ 5 ] }
  221. ],
  222. "aaSortingFixed": [[ 0, "asc" ]],
  223. "sAjaxSource": "userlinktable.php?pseudo='.$pseudo.'",
  224. "oLanguage": '.turnitintool_datatables_strings().',
  225. "sDom": "r<\"dt_page nav\"pi><\"top\"lf>t<\"bottom\"><\"dt_page\"pi>",
  226. "bStateSave": true
  227. } );
  228. var oTable = jQuery(".dataTable").dataTable();
  229. oTable.fnSetFilteringDelay(1000);
  230. jQuery("#unlink_filter").append( "<label id=\"check_filter\"><input class=\"linkcheck\" type=\"checkbox\" /> ' . get_string( 'unlinkedusers', 'turnitintool' ) . '</label>" );
  231. var oSettings = oTable.fnSettings();
  232. if ( oSettings ) {
  233. var checkval = oSettings.aoPreSearchCols[1].sSearch;
  234. if ( checkval == "##linked##" ) {
  235. jQuery("#check_filter .linkcheck").attr( "checked", "checked" );
  236. }
  237. }
  238. jQuery("#check_filter input").change( function () {
  239. var filter = "";
  240. if (this.checked) {
  241. filter = "##linked##";
  242. }
  243. oTable.fnFilter( filter, 1 );
  244. } );
  245. jQuery("#toggle").change( function () {
  246. checkUncheckAll(this,\'userlinks\');
  247. } );
  248. } );
  249. </script>';
  250. echo '<form method="POST" id="turnitin_unlink" action="'.$CFG->wwwroot.'/mod/turnitintool/extras.php?do=unlinkusers">
  251. ';
  252. echo '
  253. <table id="unlink">
  254. <thead>
  255. <tr>
  256. <th class="toggle"><div><input type="checkbox" name="toggle" id="toggle" /></div></th>
  257. <th class="turnitin_uid"><div>'.get_string( 'turnitinid', 'turnitintool' ).'</div></th>
  258. <th></th>
  259. <th class="fullname"><div>'.get_string( 'usersunlinkrelink', 'turnitintool' ).'</div></th>
  260. <th class="pseudo"><div>'.get_string( 'pseudoemailaddress', 'turnitintool' ).'</div></th>
  261. <th></th>
  262. </tr>
  263. </thead>
  264. <tbody></tbody>
  265. </table>';
  266. echo '<input style="margin-top: 7px;" name="unlink" value="Unlink Users" type="submit" /> <input style="margin-top: 7px;" name="relink" value="Relink Users" type="submit" /></form>
  267. ';
  268. turnitintool_box_end();
  269. echo '</div>';
  270. if (isset($PAGE) AND @is_callable(array($PAGE->requires, 'js'))) { // Are we using new moodle or old?
  271. // We already added the Moodle 2.0+ stuff
  272. } else {
  273. // These need to go to the botton here to avoid conflicts
  274. require_js($CFG->wwwroot.'/mod/turnitintool/scripts/datatables.min.js');
  275. require_js($CFG->wwwroot.'/mod/turnitintool/scripts/datatables.plugins.js');
  276. require_js($CFG->wwwroot.'/mod/turnitintool/scripts/inboxtable.js');
  277. }
  278. turnitintool_footer();
  279. } else if ( !is_null($param_do) AND ( $param_do=="commslog" OR $param_do=="activitylog" ) ) {
  280. $logsdir = $CFG->dataroot . "/temp/turnitintool/logs/";
  281. $savefile = $param_do.'_'.$param_filedate.'.log';
  282. if ( !is_null( $param_filedate ) ) {
  283. header("Content-type: plain/text; charset=UTF-8");
  284. send_file( $logsdir.$savefile, $savefile, false );
  285. } else {
  286. turnitintool_header(NULL,NULL,$_SERVER["REQUEST_URI"],get_string("modulenameplural", "turnitintool"), $SITE->fullname);
  287. turnitintool_box_start('generalbox boxwidthwide boxaligncenter', 'general');
  288. $label = 'commslog';
  289. $tabs[] = new tabobject( $label, $CFG->wwwroot.'/mod/turnitintool/extras.php?do='.$label,
  290. ucfirst( $label ), ucfirst( $label ), false );
  291. $label = 'activitylog';
  292. $tabs[] = new tabobject( $label, $CFG->wwwroot.'/mod/turnitintool/extras.php?do='.$label,
  293. ucfirst( $label ), ucfirst( $label ), false );
  294. $inactive = array( $param_do );
  295. $selected = $param_do;
  296. print_tabs( array( $tabs ), $selected, $inactive );
  297. if ( file_exists( $logsdir ) AND $readdir = opendir( $logsdir ) ) {
  298. $output = '';
  299. while ( false !== ( $entry = readdir( $readdir ) ) ) {
  300. if ( substr_count( $entry, $param_do ) > 0 ) {
  301. $split = preg_split( "/_/", $entry );
  302. $pop = array_pop( $split );
  303. $date = str_replace( '.log', '', $pop );
  304. $year = substr( $date, 0, 4 );
  305. $month = substr( $date, 4, 2 );
  306. $day = substr( $date, 6, 2 );
  307. $output .= '<a href="'.$CFG->wwwroot.'/mod/turnitintool/extras.php?do=' . $param_do . '&filedate=' . $date . '">' . ucfirst($param_do) . ' (' . userdate( strtotime( $year . '-' . $month . '-' . $day ), '%Y-%m-%d %H:%M:%S' ) . ')</a><br />'.PHP_EOL;
  308. }
  309. }
  310. echo $output;
  311. } else {
  312. echo get_string("nologsfound");
  313. }
  314. echo "<br />";
  315. turnitintool_box_end();
  316. turnitintool_footer();
  317. }
  318. } else if ( !is_null($param_do) AND $param_do=="files" ) {
  319. if (!is_callable("get_file_storage")) {
  320. turnitintool_print_error( "moodle2only", "turnitintool" );
  321. exit();
  322. }
  323. if ( !is_null( $param_fileid ) ) {
  324. if ( $filedata = $DB->get_record( "files", array( "id" => $param_fileid, "component" => "mod_turnitintool", "pathnamehash" => $param_filehash ) ) ) {
  325. $submission = $DB->get_record( "turnitintool_submissions", array( "id" => $filedata->itemid ) );
  326. } else {
  327. turnitintool_print_error( "submissiongeterror", "turnitintool" );
  328. exit();
  329. }
  330. if ( !is_null( $param_filerem ) ) {
  331. $fs = get_file_storage();
  332. $file = $fs->get_file($filedata->contextid,'mod_turnitintool','submission',$filedata->itemid,'/',$filedata->filename);
  333. $file->delete();
  334. turnitintool_redirect($CFG->wwwroot.'/mod/turnitintool/extras.php?do=files');
  335. exit();
  336. } else {
  337. $fs = get_file_storage();
  338. $file = $fs->get_file($filedata->contextid,'mod_turnitintool','submission',$filedata->itemid,'/',$filedata->filename);
  339. $filename = isset( $submission->submission_filename ) ? $submission->submission_filename : $filedata->filename;
  340. try {
  341. send_stored_file($file, 0, 0, true, $filename );
  342. } catch ( Exception $e ) {
  343. send_stored_file($file, 0, 0, true, array( "filename" => $filename ) );
  344. }
  345. }
  346. } else {
  347. turnitintool_header(NULL,NULL,$_SERVER["REQUEST_URI"],get_string("modulenameplural", "turnitintool"), $SITE->fullname);
  348. $modules = $DB->get_record( 'modules', array( 'name' => 'turnitintool' ) );
  349. echo '
  350. <style>
  351. #files .header.sort div {
  352. background: url(pix/sortnone.png) no-repeat right center;
  353. }
  354. #files .header.asc div {
  355. background: url(pix/sortdown.png) no-repeat right center;
  356. }
  357. #files .header.desc div {
  358. background: url(pix/sortup.png) no-repeat right center;
  359. }
  360. #files a.fileicon {
  361. padding-left: 18px;
  362. display: inline-block;
  363. min-height: 16px;
  364. background: url(pix/fileicon.gif) no-repeat left center;
  365. }
  366. #turnitintool_style .paginate_disabled_previous {
  367. background: url(pix/prevdisabled.png) no-repeat left center;
  368. }
  369. #turnitintool_style .paginate_enabled_previous {
  370. background: url(pix/prevenabled.png) no-repeat left center;
  371. }
  372. #turnitintool_style .paginate_disabled_next {
  373. background: url(pix/nextdisabled.png) no-repeat right center;
  374. }
  375. #turnitintool_style .paginate_enabled_next {
  376. background: url(pix/nextenabled.png) no-repeat right center;
  377. }
  378. #turnitintool_style .dataTables_processing {
  379. background: url(pix/loaderanim.gif) no-repeat center top;
  380. }
  381. </style>
  382. <script type="text/javascript">
  383. jQuery(document).ready(function() {
  384. jQuery.fn.dataTableExt.oStdClasses.sSortable = "header sort";
  385. jQuery.fn.dataTableExt.oStdClasses.sSortAsc = "header asc";
  386. jQuery.fn.dataTableExt.oStdClasses.sSortDesc = "header desc";
  387. jQuery.fn.dataTableExt.oStdClasses.sWrapper = "submissionTable";
  388. jQuery.fn.dataTableExt.oStdClasses.sStripeOdd = "row r0";
  389. jQuery.fn.dataTableExt.oStdClasses.sStripeEven = "row r1";
  390. jQuery("#files").dataTable( {
  391. "fnDrawCallback": function ( oSettings ) {
  392. if ( oSettings.aiDisplay.length == 0 )
  393. {
  394. return;
  395. }
  396. var nTrs = jQuery("#files tbody tr");
  397. var iColspan = nTrs[0].getElementsByTagName("td").length;
  398. var sLastGroup = "";
  399. for ( var i=0 ; i<nTrs.length ; i++ )
  400. {
  401. var iDisplayIndex = oSettings._iDisplayStart + i;
  402. var sGroup = oSettings.aoData[ oSettings.aiDisplay[i] ]._aData[0];
  403. if ( sGroup != sLastGroup )
  404. {
  405. var nGroup = document.createElement( "tr" );
  406. var nCell = document.createElement( "td" );
  407. nCell.colSpan = iColspan;
  408. nCell.className = "group";
  409. nCell.innerHTML = sGroup;
  410. nGroup.appendChild( nCell );
  411. nTrs[i].parentNode.insertBefore( nGroup, nTrs[i] );
  412. sLastGroup = sGroup;
  413. }
  414. }
  415. },
  416. "bProcessing": true,
  417. "bServerSide": true,
  418. "aoColumns": [
  419. null,
  420. null,
  421. null,
  422. { "sClass": "filename c0", "sWidth": "40%" },
  423. null,
  424. { "sClass": "fullname c1", "sWidth": "35%" },
  425. null,
  426. { "sClass": "created c2", "sWidth": "22%" },
  427. { "sClass": "remove c3", "sWidth": "3%" }
  428. ],
  429. "aoColumnDefs": [
  430. { "bSearchable": true, "bVisible": false, "aTargets": [ 0 ] },
  431. { "bSearchable": true, "bVisible": false, "aTargets": [ 1 ] },
  432. { "bSearchable": true, "bVisible": false, "aTargets": [ 2 ] },
  433. { "bSearchable": true, "bVisible": true, "aTargets": [ 3 ] },
  434. { "bSearchable": true, "bVisible": false, "aTargets": [ 4 ] },
  435. { "bSearchable": true, "bVisible": true, "aTargets": [ 5 ] },
  436. { "bSearchable": true, "bVisible": false, "aTargets": [ 6 ] },
  437. { "bSearchable": true, "bVisible": true, "aTargets": [ 7 ] },
  438. { "bSearchable": true, "bVisible": true, "aTargets": [ 8 ] }
  439. ],
  440. "aaSortingFixed": [[ 0, "asc" ]],
  441. "sAjaxSource": "filestable.php?module='.$modules->id.'",
  442. "oLanguage": '.turnitintool_datatables_strings().',
  443. "sDom": "r<\"dt_page\"pi><\"top nav\"lf>t<\"bottom\"><\"dt_page\"pi>",
  444. "bStateSave": true
  445. } );
  446. var oTable = jQuery(".dataTable").dataTable();
  447. oTable.fnSetFilteringDelay(1000);
  448. jQuery("#files_filter").append( "<label id=\"check_filter\"><input class=\"deletecheck\" type=\"checkbox\" /> ' . get_string( 'deletable', 'turnitintool' ) . '</label>" );
  449. var oSettings = oTable.fnSettings();
  450. if ( oSettings ) {
  451. var checkval = oSettings.aoPreSearchCols[8].sSearch;
  452. if ( checkval == "##deletable##" ) {
  453. jQuery("#check_filter .deletecheck").attr( "checked", "checked" );
  454. }
  455. }
  456. jQuery("#check_filter input").change( function () {
  457. var filter = "";
  458. if (this.checked) {
  459. filter = "##deletable##";
  460. }
  461. oTable.fnFilter( filter, 8 );
  462. } );
  463. } );
  464. </script>';
  465. echo '<div id="turnitintool_style">';
  466. turnitintool_box_start('generalbox boxaligncenter', 'general');
  467. echo '
  468. <b>' . get_string( 'filebrowser', 'turnitintool' ) . '</b><br /><br />
  469. <table id="files">
  470. <thead>
  471. <tr>
  472. <th></th>
  473. <th></th>
  474. <th></th>
  475. <th class="filename"><div>' . get_string( 'filename', 'turnitintool' ) . '</div></th>
  476. <th></th>
  477. <th class="fullname"><div>' . get_string( 'user', 'turnitintool' ) . '</div></th>
  478. <th></th>
  479. <th class="created"><div>' . get_string( 'created', 'turnitintool' ) . '</div></th>
  480. <th class="delete"><div>&nbsp;</div></th>
  481. </tr>
  482. </thead>
  483. <tbody></tbody>
  484. </table></div>';
  485. turnitintool_box_end();
  486. if (isset($PAGE) AND @is_callable(array($PAGE->requires, 'js'))) { // Are we using new moodle or old?
  487. // We already added the Moodle 2.0+ stuff
  488. } else {
  489. // These need to go to the botton here to avoid conflicts
  490. require_js($CFG->wwwroot.'/mod/turnitintool/scripts/datatables.min.js');
  491. require_js($CFG->wwwroot.'/mod/turnitintool/scripts/datatables.plugins.js');
  492. require_js($CFG->wwwroot.'/mod/turnitintool/scripts/inboxtable.js');
  493. }
  494. turnitintool_footer();
  495. }
  496. } else {
  497. $post = new stdClass();
  498. $post->utp='2';
  499. $loaderbar = new turnitintool_loaderbarclass(3);
  500. $tii = new turnitintool_commclass(turnitintool_getUID($USER),$USER->firstname,$USER->lastname,$USER->email,2,$loaderbar);
  501. $tii->startSession();
  502. $result=$tii->createUser($post,get_string('connecttesting','turnitintool'));
  503. $rcode=$tii->getRcode();
  504. $rmessage=$tii->getRmessage();
  505. $tiiuid=$tii->getUserID();
  506. $tii->endSession();
  507. turnitintool_header(NULL,NULL,$_SERVER["REQUEST_URI"],get_string("modulenameplural", "turnitintool"), $SITE->fullname);
  508. turnitintool_box_start('generalbox boxwidthwide boxaligncenter', 'general');
  509. if ($rcode>=TURNITINTOOL_API_ERROR_START OR empty($rcode)) {
  510. if (empty($rmessage)) {
  511. $rmessage=get_string('connecttestcommerror','turnitintool');
  512. }
  513. turnitintool_print_error('connecttesterror','turnitintool',$CFG->wwwroot.'/admin/module.php?module=turnitintool',$rmessage,__FILE__,__LINE__);
  514. } else {
  515. $data=new object();
  516. $data->userid=$USER->id;
  517. $data->turnitin_uid=$tiiuid;
  518. $data->turnitin_utp=$tii->utp;
  519. if ($tiiuser=turnitintool_get_record('turnitintool_users','userid',$USER->id)) {
  520. $data->id=$tiiuser->id;
  521. turnitintool_update_record('turnitintool_users',$data);
  522. } else {
  523. turnitintool_insert_record('turnitintool_users',$data);
  524. }
  525. print_string('connecttestsuccess','turnitintool');
  526. }
  527. turnitintool_box_end();
  528. turnitintool_footer();
  529. }
  530. /* ?> */