*** crot/crot_cron.php	2011-10-18 02:11:17.000000000 +0200
--- crot2/crot_cron.php	2012-04-20 14:24:29.041426867 +0200
***************
*** 37,48 ****
  if (empty($gram_size)||empty($window_size)) {
          die('The plugin is not properly set. Please set the plugin in admin/plugins/plagiarism prevention menu');    /// the initial settigns were not properly set up
  }
  
  // main loop on crot_files table - check if there are files marked for the check up 
- $link = mysql_connect("$CFG->dbhost", "$CFG->dbuser", "$CFG->dbpass") or die("Could not connect");
- mysql_select_db("$CFG->dbname") or die ("Could not select database");
  $sql_query = "SELECT cf.* FROM {plagiarism_crot_files} cf where cf.status = 'queue'";
  $files = $DB->get_records_sql($sql_query);
  if (!empty($files)){
      foreach ($files as $afile){
          try {
--- 37,46 ----
***************
*** 69,82 ****
        // insert into plagiarism_crot_documents  
        //  $docrecord = new object();
        //  $docrecord->crot_submission_id = $afile->id;
  	  //  $docrecord->content = addslashes($atext);
        //  $docid = $DB->insert_record('plagiarism_crot_documents', $docrecord);
!         $content = addslashes($atext);
!         $query = "INSERT INTO {$CFG->prefix}plagiarism_crot_documents (content, crot_submission_id) VALUES ('$content','$afile->id')";
!         mysql_query($query);
!         $docid = mysql_insert_id();
          
          // fingerprinting - calculate and store the fingerprints into the table
  		$atext=mb_strtolower($atext, "utf-8");
  		
  		// get f/print
--- 67,85 ----
        // insert into plagiarism_crot_documents  
        //  $docrecord = new object();
        //  $docrecord->crot_submission_id = $afile->id;
  	  //  $docrecord->content = addslashes($atext);
        //  $docid = $DB->insert_record('plagiarism_crot_documents', $docrecord);
!         $content = addslashes($atext);
! 	
! 	//Insert the record using Moodle DML function instead of MySQL
! 	//Patched by Henrik Thorn, 2012/04/20. 
! 	$record = new object();
! 	$record->content = $atext;
! 	$record->crot_submission_id = $afile->id;  
! 	$docid = $DB->insert_record('plagiarism_crot_documents', $record, true, false);
! 	
          
          // fingerprinting - calculate and store the fingerprints into the table
  		$atext=mb_strtolower($atext, "utf-8");
  		
  		// get f/print
***************
*** 216,241 ****
  				// insert doc into crot_doc table
  			//	$wdocrecord->crot_submission_id = 0;	
  			//	$wdocrecord->content = addslashes($result);
  			//	$wdocid = $DB->insert_record("plagiarism_crot_documents", $wdocrecord);
                  $wdoc_content = addslashes($result);
!                 $query = "INSERT INTO {$CFG->prefix}plagiarism_crot_documents (content, crot_submission_id) VALUES ('$wdoc_content','0')";
!                 mysql_query($query);
!                 $wdocid = mysql_insert_id();
                  	
  				// insert doc into web_doc table
  			/*	$webdocrecord->document_id = $wdocid;
  				$webdocrecord->related_doc_id = $docid;
  				$webdocrecord->link=urlencode($manUrl->mainUrl);
  				$webdocrecord->link_live=urlencode($manUrl->msUrl);
  				$webdocrecord->is_from_cache=false;
  				$webdocid = $DB->insert_record("plagiarism_crot_web_documents", $webdocrecord);*/
                  $weblink = urlencode($manUrl->mainUrl);
                  $weblinklive = urlencode($manUrl->msUrl);
!                 $query = "INSERT INTO {$CFG->prefix}plagiarism_crot_web_documents (document_id,link,link_live,is_from_cache,related_doc_id) VALUES ('$wdocid','$weblink','$weblinklive','false','$docid')";			
!                 mysql_query($query);
!                 $webdocid = mysql_insert_id();
  				// fingerprinting - calculate and store the fingerprints into the table
  				$result=mb_convert_case($result, MB_CASE_LOWER, "UTF-8");
  
  				$fingerp = array();
  				try {
--- 219,257 ----
  				// insert doc into crot_doc table
  			//	$wdocrecord->crot_submission_id = 0;	
  			//	$wdocrecord->content = addslashes($result);
  			//	$wdocid = $DB->insert_record("plagiarism_crot_documents", $wdocrecord);
                  $wdoc_content = addslashes($result);
! 
! 		//Insert record with Moodle DML instead of MySQL. 
! 		//Edited by Henrik Thorn 2012/04/20
! 		$wdoc_record = new object();                
! 		$wdoc_record->content = $result;
! 		$wdocid = $DB->insert_record('plagiarism_crot_documents', $wdoc_record, true, false);
! 		
                  	
  				// insert doc into web_doc table
  			/*	$webdocrecord->document_id = $wdocid;
  				$webdocrecord->related_doc_id = $docid;
  				$webdocrecord->link=urlencode($manUrl->mainUrl);
  				$webdocrecord->link_live=urlencode($manUrl->msUrl);
  				$webdocrecord->is_from_cache=false;
  				$webdocid = $DB->insert_record("plagiarism_crot_web_documents", $webdocrecord);*/
                  $weblink = urlencode($manUrl->mainUrl);
                  $weblinklive = urlencode($manUrl->msUrl);
! 
! 		//Insert record with Moodle DML instead of MySQL. 
! 		//Edited by Henrik Thorn 2012/04/20
! 		$webdoc_record = new object();                
! 		$webdoc_record->document_id = $wdocid;
! 		$webdoc_record->link = $weblink;
! 		$webdoc_record->link_live = $weblinklive;
! 		$webdoc_record->is_from_cache = 'false';
! 		$webdoc_record->related_doc_id = $docid;
! 
! 		$webdocid = $DB->insert_record('plagiarism_crot_web_documents', $webdoc_record, true, false);
!                 
  				// fingerprinting - calculate and store the fingerprints into the table
  				$result=mb_convert_case($result, MB_CASE_LOWER, "UTF-8");
  
  				$fingerp = array();
  				try {
42,43d41
< $link = mysql_connect("$CFG->dbhost", "$CFG->dbuser", "$CFG->dbpass") or die("Could not connect");
< mysql_select_db("$CFG->dbname") or die ("Could not select database");
74,77c72,80
<         $content = addslashes($atext);
<         $query = "INSERT INTO {$CFG->prefix}plagiarism_crot_documents (content, crot_submission_id) VALUES ('$content','$afile->id')";
<         mysql_query($query);
<         $docid = mysql_insert_id();
---
>         $content = addslashes($atext);
> 	
> 	//Insert the record using Moodle DML function instead of MySQL
> 	//Patched by Henrik Thorn, 2012/04/20. 
> 	$record = new object();
> 	$record->content = $atext;
> 	$record->crot_submission_id = $afile->id;  
> 	$docid = $DB->insert_record('plagiarism_crot_documents', $record, true, false);
> 	
221,223c224,230
<                 $query = "INSERT INTO {$CFG->prefix}plagiarism_crot_documents (content, crot_submission_id) VALUES ('$wdoc_content','0')";
<                 mysql_query($query);
<                 $wdocid = mysql_insert_id();
---
> 
> 		//Insert record with Moodle DML instead of MySQL. 
> 		//Edited by Henrik Thorn 2012/04/20
> 		$wdoc_record = new object();                
> 		$wdoc_record->content = $result;
> 		$wdocid = $DB->insert_record('plagiarism_crot_documents', $wdoc_record, true, false);
> 		
234,236c241,252
<                 $query = "INSERT INTO {$CFG->prefix}plagiarism_crot_web_documents (document_id,link,link_live,is_from_cache,related_doc_id) VALUES ('$wdocid','$weblink','$weblinklive','false','$docid')";			
<                 mysql_query($query);
<                 $webdocid = mysql_insert_id();
---
> 
> 		//Insert record with Moodle DML instead of MySQL. 
> 		//Edited by Henrik Thorn 2012/04/20
> 		$webdoc_record = new object();                
> 		$webdoc_record->document_id = $wdocid;
> 		$webdoc_record->link = $weblink;
> 		$webdoc_record->link_live = $weblinklive;
> 		$webdoc_record->is_from_cache = 'false';
> 		$webdoc_record->related_doc_id = $docid;
> 
> 		$webdocid = $DB->insert_record('plagiarism_crot_web_documents', $webdoc_record, true, false);
>                 
*** crot/crot_cron.php	2011-10-18 02:11:17.000000000 +0200
--- crot2/crot_cron.php	2012-04-20 14:24:29.041426867 +0200
***************
*** 37,48 ****
  if (empty($gram_size)||empty($window_size)) {
          die('The plugin is not properly set. Please set the plugin in admin/plugins/plagiarism prevention menu');    /// the initial settigns were not properly set up
  }
  
  // main loop on crot_files table - check if there are files marked for the check up 
- $link = mysql_connect("$CFG->dbhost", "$CFG->dbuser", "$CFG->dbpass") or die("Could not connect");
- mysql_select_db("$CFG->dbname") or die ("Could not select database");
  $sql_query = "SELECT cf.* FROM {plagiarism_crot_files} cf where cf.status = 'queue'";
  $files = $DB->get_records_sql($sql_query);
  if (!empty($files)){
      foreach ($files as $afile){
          try {
--- 37,46 ----
***************
*** 69,82 ****
        // insert into plagiarism_crot_documents  
        //  $docrecord = new object();
        //  $docrecord->crot_submission_id = $afile->id;
  	  //  $docrecord->content = addslashes($atext);
        //  $docid = $DB->insert_record('plagiarism_crot_documents', $docrecord);
!         $content = addslashes($atext);
!         $query = "INSERT INTO {$CFG->prefix}plagiarism_crot_documents (content, crot_submission_id) VALUES ('$content','$afile->id')";
!         mysql_query($query);
!         $docid = mysql_insert_id();
          
          // fingerprinting - calculate and store the fingerprints into the table
  		$atext=mb_strtolower($atext, "utf-8");
  		
  		// get f/print
--- 67,85 ----
        // insert into plagiarism_crot_documents  
        //  $docrecord = new object();
        //  $docrecord->crot_submission_id = $afile->id;
  	  //  $docrecord->content = addslashes($atext);
        //  $docid = $DB->insert_record('plagiarism_crot_documents', $docrecord);
!         $content = addslashes($atext);
! 	
! 	//Insert the record using Moodle DML function instead of MySQL
! 	//Patched by Henrik Thorn, 2012/04/20. 
! 	$record = new object();
! 	$record->content = $atext;
! 	$record->crot_submission_id = $afile->id;  
! 	$docid = $DB->insert_record('plagiarism_crot_documents', $record, true, false);
! 	
          
          // fingerprinting - calculate and store the fingerprints into the table
  		$atext=mb_strtolower($atext, "utf-8");
  		
  		// get f/print
***************
*** 216,241 ****
  				// insert doc into crot_doc table
  			//	$wdocrecord->crot_submission_id = 0;	
  			//	$wdocrecord->content = addslashes($result);
  			//	$wdocid = $DB->insert_record("plagiarism_crot_documents", $wdocrecord);
                  $wdoc_content = addslashes($result);
!                 $query = "INSERT INTO {$CFG->prefix}plagiarism_crot_documents (content, crot_submission_id) VALUES ('$wdoc_content','0')";
!                 mysql_query($query);
!                 $wdocid = mysql_insert_id();
                  	
  				// insert doc into web_doc table
  			/*	$webdocrecord->document_id = $wdocid;
  				$webdocrecord->related_doc_id = $docid;
  				$webdocrecord->link=urlencode($manUrl->mainUrl);
  				$webdocrecord->link_live=urlencode($manUrl->msUrl);
  				$webdocrecord->is_from_cache=false;
  				$webdocid = $DB->insert_record("plagiarism_crot_web_documents", $webdocrecord);*/
                  $weblink = urlencode($manUrl->mainUrl);
                  $weblinklive = urlencode($manUrl->msUrl);
!                 $query = "INSERT INTO {$CFG->prefix}plagiarism_crot_web_documents (document_id,link,link_live,is_from_cache,related_doc_id) VALUES ('$wdocid','$weblink','$weblinklive','false','$docid')";			
!                 mysql_query($query);
!                 $webdocid = mysql_insert_id();
  				// fingerprinting - calculate and store the fingerprints into the table
  				$result=mb_convert_case($result, MB_CASE_LOWER, "UTF-8");
  
  				$fingerp = array();
  				try {
--- 219,257 ----
  				// insert doc into crot_doc table
  			//	$wdocrecord->crot_submission_id = 0;	
  			//	$wdocrecord->content = addslashes($result);
  			//	$wdocid = $DB->insert_record("plagiarism_crot_documents", $wdocrecord);
                  $wdoc_content = addslashes($result);
! 
! 		//Insert record with Moodle DML instead of MySQL. 
! 		//Edited by Henrik Thorn 2012/04/20
! 		$wdoc_record = new object();                
! 		$wdoc_record->content = $result;
! 		$wdocid = $DB->insert_record('plagiarism_crot_documents', $wdoc_record, true, false);
! 		
                  	
  				// insert doc into web_doc table
  			/*	$webdocrecord->document_id = $wdocid;
  				$webdocrecord->related_doc_id = $docid;
  				$webdocrecord->link=urlencode($manUrl->mainUrl);
  				$webdocrecord->link_live=urlencode($manUrl->msUrl);
  				$webdocrecord->is_from_cache=false;
  				$webdocid = $DB->insert_record("plagiarism_crot_web_documents", $webdocrecord);*/
                  $weblink = urlencode($manUrl->mainUrl);
                  $weblinklive = urlencode($manUrl->msUrl);
! 
! 		//Insert record with Moodle DML instead of MySQL. 
! 		//Edited by Henrik Thorn 2012/04/20
! 		$webdoc_record = new object();                
! 		$webdoc_record->document_id = $wdocid;
! 		$webdoc_record->link = $weblink;
! 		$webdoc_record->link_live = $weblinklive;
! 		$webdoc_record->is_from_cache = 'false';
! 		$webdoc_record->related_doc_id = $docid;
! 
! 		$webdocid = $DB->insert_record('plagiarism_crot_web_documents', $webdoc_record, true, false);
!                 
  				// fingerprinting - calculate and store the fingerprints into the table
  				$result=mb_convert_case($result, MB_CASE_LOWER, "UTF-8");
  
  				$fingerp = array();
  				try {
