PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/userlinktable.php

https://github.com/eviweb/moodle-mod_turnitintool
PHP | 136 lines | 116 code | 15 blank | 5 comment | 35 complexity | 1c9c4b13ccbdf25fa9202a1003929629 MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /*
  3. * To change this template, choose Tools | Templates
  4. * and open the template in the editor.
  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. $param_pseudo = optional_param('pseudo', null, PARAM_INT); // module
  18. $param_displaystart = optional_param('iDisplayStart', null, PARAM_INT); // displaystart
  19. $param_displaylength = optional_param('iDisplayLength', null, PARAM_INT); // displaylength
  20. $aColumns = array( 'tu.userid', 'tu.turnitin_uid', 'tu.turnitin_utp', 'mu.firstname', 'mu.lastname', 'mu.email' );
  21. $sQuery = 'SELECT
  22. tu.id AS id,
  23. tu.userid AS userid,
  24. tu.turnitin_uid AS turnitin_uid,
  25. tu.turnitin_utp AS turnitin_utp,
  26. mu.firstname AS firstname,
  27. mu.lastname AS lastname,
  28. mu.email AS email
  29. FROM '.$CFG->prefix.'turnitintool_users tu
  30. LEFT JOIN
  31. '.$CFG->prefix.'user mu ON tu.userid = mu.id';
  32. $sCountQuery = 'SELECT
  33. tu.id AS id
  34. FROM
  35. '.$CFG->prefix.'turnitintool_users tu';
  36. $param_sortcol[0] = optional_param('iSortCol_0', null, PARAM_INT); // sortcol
  37. $param_sortingcols = optional_param('iSortingCols', 0, PARAM_INT); // sortingcols
  38. $sOrder = "";
  39. if ( !is_null( $param_sortcol[0] ) ) {
  40. $sOrder = " ORDER BY ";
  41. $startOrder = $sOrder;
  42. for ( $i=0; $i < intval( $param_sortingcols ); $i++ ) {
  43. $param_sortcol[$i] = optional_param('iSortCol_'.$i, null, PARAM_INT); // sortcol
  44. $param_sortable[$i] = optional_param('bSortable_'.$param_sortcol[$i], null, PARAM_TEXT); // sortable
  45. $param_sortdir[$i] = optional_param('sSortDir_'.$i, null, PARAM_TEXT); // sortdir
  46. if ( $param_sortable[$i] == "true" ) {
  47. $sOrder .= $aColumns[ $param_sortcol[$i] ] . " " . $param_sortdir[$i] . ", ";
  48. }
  49. }
  50. if ( $sOrder == $startOrder ) {
  51. $sOrder = "";
  52. } else {
  53. $sOrder = substr_replace( $sOrder, "", -2 );
  54. }
  55. }
  56. $param_search = optional_param('sSearch', null, PARAM_TEXT); // sortingcols
  57. $start = true;
  58. $sWhere = ' WHERE ( ';
  59. $bracket = false;
  60. for ( $i=0; $i < count($aColumns); $i++ ) {
  61. $param_searchable[$i] = optional_param('bSearchable_'.$i, null, PARAM_TEXT);
  62. $param_search_n[$i] = optional_param('sSearch_'.$i, null, PARAM_TEXT);
  63. if ( !is_null($param_searchable[$i]) && $param_searchable[$i] == "true" && ( $param_search != '' OR $param_search_n[$i] != '' ) ) {
  64. if ( !$start ) $sWhere .= " OR ";
  65. if ( $aColumns[$i] == 'tu.turnitin_uid' AND $param_search_n[$i] == '##linked##' ) {
  66. if ( $sWhere != ' WHERE ( ' ) {
  67. $sWhere = substr_replace( $sWhere, "", -3 );
  68. $sWhere = $sWhere . ' ) AND ( ';
  69. }
  70. $sWhere .= "tu.turnitin_uid = 0";
  71. if ( $bracket ) $sWhere .= " )";
  72. } else if ( $aColumns[$i] != ' ' ) {
  73. $sWhere .= "CAST(" . $aColumns[$i] . " AS CHAR) LIKE '%" . $param_search . "%'";
  74. $start = false;
  75. }
  76. }
  77. }
  78. if ( $sWhere == ' WHERE ( ' ) {
  79. $sWhere = "";
  80. } else {
  81. $sWhere .= " )";
  82. }
  83. $sLimit = "";
  84. if ( !is_null( $param_displaystart ) && $param_displaylength != '-1' ) {
  85. $limitfrom = $param_displaystart;
  86. $limitnum = $param_displaylength;
  87. } else {
  88. $limitfrom = ( isset($DB) AND is_callable(array($DB,'get_records_sql')) ) ? 0 : '';
  89. $limitnum = ( isset($DB) AND is_callable(array($DB,'get_records_sql')) ) ? 0 : '';
  90. }
  91. $sQuery .= $sWhere;
  92. $cResult = ( isset($DB) AND is_callable(array($DB,'get_records_sql')) ) ? $DB->get_records_sql( $sQuery, array() ) : get_records_sql( $sQuery );
  93. $iTotal = count( $cResult );
  94. $sQuery .= $sOrder . $sLimit;
  95. $rResult = ( isset($DB) AND is_callable(array($DB,'get_records_sql')) )
  96. ? $DB->get_records_sql( $sQuery, array(), $limitfrom, $limitnum )
  97. : get_records_sql( $sQuery, $limitfrom, $limitnum );
  98. $iFilteredTotal = $iTotal; //count( $rResult );
  99. $param_echo = optional_param('sEcho', 0, PARAM_INT); // echo
  100. $output = array(
  101. "sEcho" => $param_echo,
  102. "iTotalRecords" => $iTotal,
  103. "iTotalDisplayRecords" => $iFilteredTotal,
  104. "aaData" => array()
  105. );
  106. $rResult = ( !is_array( $rResult ) ) ? array() : $rResult;
  107. $i = 0;
  108. foreach ( $rResult as $result ) {
  109. // 'cs.fullname', 'tu.name', 'fl.filename', 'us.firstname', 'us.lastname', 'us.email', 'fl.timecreated'
  110. $row = array();
  111. $row[] = '<input type="checkbox" id="userlinks_'.$i.'" name="userlinks[]" value="'.$result->id.'" />';
  112. $row[] = ( $result->turnitin_uid == 0 ) ? '' : $result->turnitin_uid;
  113. $row[] = '&nbsp;';
  114. $row[] = ( !is_null( $result->firstname ) ) ? '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$result->userid.'">' .$result->lastname . ', ' . $result->firstname . '</a> (' . $result->email . ')'
  115. : get_string( 'nonmoodleuser', 'turnitintool' );
  116. $row[] = ( $result->turnitin_utp == 1 ) ? turnitintool_pseudoemail( $result->email ) : '-';
  117. $row[] = '&nbsp;';
  118. $output['aaData'][] = $row;
  119. $i++;
  120. }
  121. echo json_encode( $output );