PageRenderTime 67ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 1ms

/comms.php

https://github.com/eviweb/moodle-mod_turnitintool
PHP | 1512 lines | 1094 code | 64 blank | 354 comment | 115 complexity | 941084525f2d3786372102ea01727b2c MD5 | raw file
Possible License(s): GPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * The Turnitin API Communication Class
  4. *
  5. * @package turnitintool
  6. * @subpackage classes
  7. * @copyright 2012 Turnitin
  8. */
  9. class turnitintool_commclass {
  10. /**
  11. * @var string $apiurl The API Url
  12. */
  13. var $apiurl;
  14. /**
  15. * @var boolean $encrypt The encrypt parameter for API calls
  16. */
  17. var $encrypt;
  18. /**
  19. * @var int $accountid The Account ID parameter for API calls
  20. */
  21. var $accountid;
  22. /**
  23. * @var int $utp The user type parameter for API calls
  24. */
  25. var $utp;
  26. /**
  27. * @var int $uid The User ID parameter for API calls
  28. */
  29. var $uid;
  30. /**
  31. * @var string $ufn The User Firstname parameter for API calls
  32. */
  33. var $ufn;
  34. /**
  35. * @var string $uln The User Lastname parameter for API calls
  36. */
  37. var $uln;
  38. /**
  39. * @var string $uem The User Email parameter for API calls
  40. */
  41. var $uem;
  42. /**
  43. * @var string $tiisession Turnitin Session ID parameter for API calls
  44. */
  45. var $tiisession;
  46. /**
  47. * @var object $loaderbar The Loader Bar Object NULL if no loaderbar is to be displayed
  48. */
  49. var $loaderbar;
  50. /**
  51. * @var string $result The entires xml result from the API call
  52. */
  53. var $result;
  54. /**
  55. * @var int $rcode The RCODE returned by the API call
  56. */
  57. var $rcode;
  58. /**
  59. * @var string $rmessage The RMESSAGE returned by the API call
  60. */
  61. var $rmessage;
  62. /**
  63. * @var string $curlerror The curl_error returned by the API call if connection issues occur in curl
  64. */
  65. var $curlerror;
  66. /**
  67. * A backward compatible constructor / destructor method that works in PHP4 to emulate the PHP5 magic method __construct
  68. * Disabled to remove strict warnings, only useful for PHP 4 and there shouldn't be too many PHP 4 installs around by now
  69. */
  70. /*function turnitintool_commclass($iUid,$iUfn,$iUln,$iUem,$iUtp,&$iLoaderBar) {
  71. if (version_compare(PHP_VERSION,"5.0.0","<")) {
  72. $this->__construct($iUid,$iUfn,$iUln,$iUem,$iUtp,$iLoaderBar);
  73. }
  74. }*/
  75. /**
  76. * The constructor for the class, Calls the startsession() method if we are using sessions
  77. *
  78. * @param int $iUid The User ID passed in the class creation call
  79. * @param string $iUfn The User First Name passed in the class creation call
  80. * @param string $iUln The User Last Name passed in the class creation call
  81. * @param string $iUem The User Email passed in the class creation call
  82. * @param int $iUtp The User Type passed in the class creation call
  83. * @param object $iLoaderBar The Loader Bar object passed in the class creation call (may be NULL if no loaderbar is to be used)
  84. * @param boolean $iUseSession Determines whether we start a session for this call (set to false for SSO calls)
  85. */
  86. function __construct($iUid,$iUfn,$iUln,$iUem,$iUtp,&$iLoaderBar) {
  87. global $CFG;
  88. $this->callback=false;
  89. $this->apiurl=$CFG->turnitin_apiurl;
  90. $this->accountid=$CFG->turnitin_account_id;
  91. $this->uid=$iUid;
  92. // Convert the email, firstname and lastname to psuedos for students if the option is set in config
  93. // Unless the user is already logged as a tutor then use real details
  94. if ( isset( $CFG->turnitin_enablepseudo ) AND $CFG->turnitin_enablepseudo == 1 AND $iUtp == 1 AND !turnitintool_istutor( $iUem ) ) {
  95. $iUfn = turnitintool_pseudofirstname();
  96. $iUln = turnitintool_pseudolastname( $iUem );
  97. $iUem = turnitintool_pseudoemail( $iUem );
  98. }
  99. $this->ufn=$iUfn;
  100. $this->uln=$iUln;
  101. $this->uem=$iUem;
  102. $this->utp=$iUtp;
  103. $this->loaderbar =& $iLoaderBar;
  104. }
  105. /**
  106. * Calls FID1, FCMD 2 with create_session set to 1 in order to create a session for this user / object call
  107. */
  108. function startSession() {
  109. global $CFG;
  110. $assigndata=array('gmtime'=>$this->tiiGmtime(),
  111. 'encrypt'=>TURNITINTOOL_ENCRYPT,
  112. 'aid'=>$this->accountid,
  113. 'diagnostic'=>0,
  114. 'fid'=>1,
  115. 'fcmd'=>2,
  116. 'utp'=>$this->utp,
  117. 'uid'=>$this->uid,
  118. 'uem'=>$this->uem,
  119. 'ufn'=>$this->ufn,
  120. 'uln'=>$this->uln
  121. );
  122. $assigndata['dis']=$this->disableEmail();
  123. $assigndata['md5']=$this->doMD5($assigndata);
  124. $assigndata['create_session']=1;
  125. $assigndata['src']=TURNITINTOOL_APISRC;
  126. $assigndata['apilang']=$this->getLang();
  127. $this->result=$this->doRequest("POST", $this->apiurl, $assigndata,true);
  128. $this->tiisession=$this->getSessionid();
  129. sleep(TURNITINTOOL_LATENCY_SLEEP);
  130. }
  131. /**
  132. * Calls FID18, FCMD 2 to kill the session for this user / object call
  133. */
  134. function endSession() {
  135. $assigndata=array('gmtime'=>$this->tiiGmtime(),
  136. 'encrypt'=>TURNITINTOOL_ENCRYPT,
  137. 'aid'=>$this->accountid,
  138. 'diagnostic'=>0,
  139. 'fid'=>18,
  140. 'fcmd'=>2,
  141. 'utp'=>$this->utp,
  142. 'uid'=>$this->uid,
  143. 'uem'=>$this->uem,
  144. 'ufn'=>$this->ufn,
  145. 'uln'=>$this->uln
  146. );
  147. $assigndata['dis']=$this->disableEmail();
  148. $assigndata['md5']=$this->doMD5($assigndata);
  149. $assigndata['session-id']=$this->tiisession;
  150. $assigndata['src']=TURNITINTOOL_APISRC;
  151. $assigndata['apilang']=$this->getLang();
  152. $this->result=$this->doRequest("POST", $this->apiurl, $assigndata,true);
  153. }
  154. /**
  155. * disableEmail - determines whether to use dis=0 or dis=1
  156. *
  157. * @param boolean $submission true for a submission call false otherwise
  158. * @return string 1 or 0
  159. */
  160. function disableEmail($submission=false) {
  161. global $CFG;
  162. if ( ($this->utp==1 AND $CFG->turnitin_receiptemail!="1" AND $submission) OR // If student and submission and sends receipts = no
  163. ($this->utp==1 AND $CFG->turnitin_studentemail!="1" AND !$submission) OR // If student and not submission and student emails = no
  164. ($this->utp==2 AND $CFG->turnitin_tutoremail!="1") ) { // If instructor and instructor emails = no
  165. return "1";
  166. } else {
  167. return "0";
  168. }
  169. }
  170. /**
  171. * Converts XML string to array using SimpleXMLElement
  172. *
  173. * @param string $string
  174. * @return boolean
  175. */
  176. function xmlToSimple( $string, $error = true ) {
  177. try {
  178. @$this->simplexml = new SimpleXMLElement( $string );
  179. } catch ( Exception $e ) {
  180. if ( $error ) {
  181. turnitintool_print_error('apiunavailable','turnitintool',NULL,NULL,__FILE__,__LINE__);
  182. exit();
  183. }
  184. return false;
  185. }
  186. return true;
  187. }
  188. /**
  189. * Returns a multidimensional array built in the format array[OBJECTID][fieldname]
  190. *
  191. * @return array
  192. */
  193. function getSubmissionArray() {
  194. $output=array();
  195. $this->xmlToSimple( $this->result );
  196. $objects = $this->simplexml->object;
  197. if ( !isset( $objects ) ) {
  198. return $output;
  199. }
  200. foreach ( $objects as $object ) {
  201. $objectid = (string)$object->objectID;
  202. $output[$objectid]["userid"] = (string)$object->userid;
  203. $output[$objectid]["firstname"] = (string)$object->firstname;
  204. $output[$objectid]["lastname"] = (string)$object->lastname;
  205. $output[$objectid]["title"] = html_entity_decode( (string)$object->title, ENT_QUOTES, "UTF-8" );
  206. $output[$objectid]["similarityscore"] = ( !is_null( $object->similarityScore ) AND $object->similarityScore != "-1" ) ? $object->similarityScore : null;
  207. $transsimilarityscore = (integer)$object->translated_matching->similarityScore < 0 ? null : $object->translated_matching->similarityScore;
  208. if ( !is_null( $transsimilarityscore ) ) {
  209. if ( (integer)$object->overlap > (integer)$object->translated_matching->overlap ) {
  210. $output[$objectid]["transmatch"] = 0;
  211. $high_overlap = $object->overlap;
  212. $similarityscore = $object->similarityScore;
  213. } else {
  214. $output[$objectid]["transmatch"] = 1;
  215. $high_overlap = $object->translated_matching->overlap;
  216. $similarityscore = $object->translated_matching->similarityScore;
  217. }
  218. } else {
  219. $high_overlap = $object->overlap;
  220. $output[$objectid]["transmatch"] = 0;
  221. $similarityscore = $object->similarityScore;
  222. }
  223. // note overlap is the Originality Percentage Score
  224. $output[$objectid]["overlap"] = ( !is_null( $high_overlap ) AND $similarityscore != "-1" ) ? (string)$high_overlap : null;
  225. $score = (string)$object->score;
  226. $output[$objectid]["grademark"] = ( $score === '0' OR ( !is_null( $score ) AND $score != "-1" ) ) ? $score : null;
  227. $anon = (string)$object->anon;
  228. $output[$objectid]["anon"] = ( !is_null( $anon ) AND $anon != "-1" ) ? $anon : null;
  229. $grademarkstatus = (string)$object->gradeMarkStatus;
  230. $output[$objectid]["grademarkstatus"]=(!is_null( $grademarkstatus ) AND $grademarkstatus != "-1" ) ? $grademarkstatus : null;
  231. $date_submitted = (string)$object->date_submitted;
  232. $output[$objectid]["date_submitted"]=( !is_null( $date_submitted ) AND $date_submitted != "-1" ) ? $date_submitted : null;
  233. $student_view = isset($object->student_responses) ? (string)$object->student_responses->student_response->response_time : null;
  234. $output[$objectid]["student_view"]=( isset( $object->student_responses ) AND !is_null( $student_view ) AND !empty( $student_view ) ) ? $student_view : 0;
  235. }
  236. return $output;
  237. }
  238. /**
  239. * Returns the Session ID for the API call
  240. *
  241. * @return string The Session ID String or Empty if not available
  242. */
  243. function getSessionid() {
  244. if ( $this->xmlToSimple( $this->result ) AND !is_null( $this->simplexml->sessionid ) ) {
  245. return (string)$this->simplexml->sessionid;
  246. } else {
  247. return '';
  248. }
  249. }
  250. /**
  251. * Returns the Return Message (rmessage) for the API call
  252. *
  253. * @return string The RMESSAGE or Empty if not available
  254. */
  255. function getRmessage() {
  256. if ( $this->xmlToSimple( $this->result ) ) {
  257. return (string)$this->simplexml->rmessage;
  258. } else if (strlen($this->curlerror)>0) {
  259. return 'CURL ERROR: '.$this->curlerror;
  260. } else {
  261. return '';
  262. }
  263. }
  264. /**
  265. * Returns the User ID for the API call
  266. *
  267. * @return integer The USERID or Empty if not available
  268. */
  269. function getUserID() {
  270. if ( $this->xmlToSimple( $this->result ) ) {
  271. return (integer)$this->simplexml->userid;
  272. } else {
  273. return '';
  274. }
  275. }
  276. /**
  277. * Returns the Class ID for the API call
  278. *
  279. * @return integer The CLASSID or Empty if not available
  280. */
  281. function getClassID() {
  282. if ( $this->xmlToSimple( $this->result ) ) {
  283. return (integer)$this->simplexml->classid;
  284. } else {
  285. return '';
  286. }
  287. }
  288. /**
  289. * Returns the Return Code (rcode) for the API call
  290. *
  291. * @return integer The RCODE or NULL if not available
  292. */
  293. function getRcode() {
  294. if ( $this->xmlToSimple( $this->result ) ) {
  295. return (integer)$this->simplexml->rcode;
  296. } else {
  297. return NULL;
  298. }
  299. }
  300. /**
  301. * Returns the Error State for the API call
  302. *
  303. * @return boolean True API call success or False API failure
  304. */
  305. function getRerror() {
  306. if (is_null($this->getRcode()) OR $this->getRcode()>=TURNITINTOOL_API_ERROR_START) {
  307. return true;
  308. } else {
  309. return false;
  310. }
  311. }
  312. /**
  313. * Checks the availability of the API
  314. *
  315. * @return boolean Returns a true if the API has returned an RCODE or false if unavailable
  316. */
  317. function getAPIunavailable() {
  318. if (is_null($this->getRcode())) {
  319. return true;
  320. } else {
  321. return false;
  322. }
  323. }
  324. /**
  325. * Returns the Object ID (objectid) for the API call
  326. *
  327. * @return integer The OBJECTID or Empty String if not available
  328. */
  329. function getObjectid() {
  330. if ( $this->xmlToSimple( $this->result ) ) {
  331. return (integer)$this->simplexml->objectID;
  332. } else {
  333. return '';
  334. }
  335. }
  336. /**
  337. * Returns the Assignment ID (ASSIGNMENTID) for the API call
  338. *
  339. * @return integer The ASSIGNMENTID or Empty String if not available
  340. */
  341. function getAssignid() {
  342. if ( $this->xmlToSimple( $this->result ) ) {
  343. return (integer)$this->simplexml->assignmentid;
  344. } else {
  345. return '';
  346. }
  347. }
  348. /**
  349. * Returns the Originality Score (ORIGINALITYSCORE) for the API call
  350. *
  351. * @return string The ORIGINALITYSCORE or Empty String if not available
  352. */
  353. function getScore() {
  354. if ( $this->xmlToSimple( $this->result ) AND !is_null( $this->simplexml->originalityscore ) ) {
  355. return (string)$this->simplexml->originalityscore;
  356. } else {
  357. return '';
  358. }
  359. }
  360. /**
  361. * Returns the Overall Grade (SCORE) for the API call
  362. *
  363. * @return string The SCORE or Empty String if not available
  364. */
  365. function getGrade() {
  366. if ( $this->xmlToSimple( $this->result ) AND !is_null( $this->simplexml->originalityscore ) ) {
  367. return (string)$this->simplexml->score;
  368. } else {
  369. return '';
  370. }
  371. }
  372. /**
  373. * Does a HTTPS Request using cURL and returns the result
  374. *
  375. * @param string $method The request method to use POST or GET
  376. * @param string $url The URL to send the request to
  377. * @param string $vars A query string style name value pair string (e.g. name=value&name2=value2)
  378. * @param boolean $timeout Whether to timeout after 240 seconds or not timeout at all
  379. * @param string $status The status to pass to the loaderbar redraw method
  380. * @return string The result of the HTTPS call
  381. */
  382. function doRequest($method, $url, $vars, $timeout=true, $status="") {
  383. global $CFG;
  384. $this->result=NULL;
  385. if (is_callable(array($this->loaderbar,'redrawbar'))) {
  386. $this->loaderbar->redrawbar($status);
  387. }
  388. if ($timeout) {
  389. set_time_limit(240);
  390. } else {
  391. set_time_limit(0);
  392. }
  393. $ch = curl_init();
  394. $useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
  395. curl_setopt($ch, CURLOPT_URL, $url);
  396. curl_setopt($ch, CURLOPT_HEADER, 0);
  397. curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
  398. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  399. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  400. curl_setopt($ch, CURLOPT_ENCODING, '');
  401. curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
  402. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
  403. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
  404. $cacertfile = $CFG->dataroot . '/moodleorgca.crt';
  405. if ( is_readable( $cacertfile ) ) {
  406. curl_setopt( $ch, CURLOPT_CAINFO, $cacertfile );
  407. }
  408. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
  409. if (isset($CFG->turnitin_proxyurl) AND !empty($CFG->turnitin_proxyurl)) {
  410. curl_setopt($ch, CURLOPT_PROXY, $CFG->turnitin_proxyurl.':'.$CFG->turnitin_proxyport);
  411. }
  412. if (isset($CFG->turnitin_proxyuser) AND !empty($CFG->turnitin_proxyuser)) {
  413. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
  414. curl_setopt($ch, CURLOPT_PROXYUSERPWD, sprintf('%s:%s', $CFG->turnitin_proxyuser, $CFG->turnitin_proxypassword));
  415. }
  416. if ($timeout) {
  417. curl_setopt($ch, CURLOPT_TIMEOUT, 240);
  418. }
  419. if ($method == 'POST') {
  420. //curl_setopt($ch, CURLOPT_POST, 1);
  421. curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
  422. }
  423. $data = curl_exec($ch);
  424. if ($data) {
  425. $result=$data;
  426. } else {
  427. $result=curl_error($ch);
  428. $this->curlerror=$result;
  429. }
  430. $this->doLogging($vars,$result);
  431. return utf8_decode($result);
  432. curl_close($ch);
  433. fclose($temp_pem);
  434. }
  435. /**
  436. * Logging function to log outgoing API calls and the return XML
  437. *
  438. * @param string $vars The query variables passed to the API
  439. * @param string $result The Result of the query
  440. */
  441. function doLogging($vars,$result) {
  442. global $CFG;
  443. if ( $CFG->turnitin_enablediagnostic AND !empty( $vars ) ) {
  444. $this->result=$result;
  445. // ###### DELETE SURPLUS LOGS #########
  446. $numkeeps=10;
  447. $prefix="commslog_";
  448. $dirpath=$CFG->dataroot."/temp/turnitintool/logs";
  449. if (!file_exists($dirpath)) {
  450. mkdir($dirpath,0777,true);
  451. }
  452. $dir=opendir($dirpath);
  453. $files=array();
  454. while ($entry=readdir($dir)) {
  455. if (substr(basename($entry),0,1)!="." AND substr_count(basename($entry),$prefix)>0) {
  456. $files[]=basename($entry);
  457. }
  458. }
  459. sort($files);
  460. for ($i=0;$i<count($files)-$numkeeps;$i++) {
  461. unlink($dirpath."/".$files[$i]);
  462. }
  463. // ####################################
  464. $newline = "\r\n";
  465. $filepath=$dirpath."/".$prefix.date('Ymd',time()).".log";
  466. $file=fopen($filepath,'ab');
  467. $fid = isset($vars["fid"]) ? $vars["fid"] : "N/A";
  468. $fcmd = isset($vars["fcmd"]) ? $vars["fcmd"] : "N/A";
  469. $output="== FID:".$fid." | FCMD:".$fcmd." ===========================================================".$newline;
  470. $output.="== RESPONSE =====================================================================".$newline;
  471. $output.="CALL DATE TIME: ".date('r',time()).$newline;
  472. $output.="URL: ".$this->apiurl.$newline;
  473. $output.="------------------------------------------------------------------------------".$newline;
  474. $output.="REQUEST VARS: ".PHP_EOL.str_replace("\n","\r\n",str_replace("\r\r\n","\r\n",print_r($vars,true))).$newline;
  475. $output.="------------------------------------------------------------------------------".$newline;
  476. $output.="RESPONSE: ".PHP_EOL.PHP_EOL.str_replace("\n","\r\n",str_replace("\r\r\n","\r\n",$result)).$newline;
  477. $output.="##############################################################################".$newline.$newline;
  478. fwrite($file,$output);
  479. fclose($file);
  480. }
  481. }
  482. /**
  483. * Call to API FID4, FCMD6 that deletes an assignment from Turnitin
  484. *
  485. * @param object $post The post object that contains the necessary query parameters for the call
  486. * @param string $status The status to pass to the loaderbar class
  487. */
  488. function deleteAssignment($post,$status) {
  489. global $CFG;
  490. if (!turnitintool_check_config()) {
  491. turnitintool_print_error('configureerror','turnitintool',NULL,NULL,__FILE__,__LINE__);
  492. exit();
  493. }
  494. $assigndata=array('gmtime'=>$this->tiiGmtime(),
  495. 'encrypt'=>TURNITINTOOL_ENCRYPT,
  496. 'aid'=>$this->accountid,
  497. 'diagnostic'=>0,
  498. 'fcmd'=>6,
  499. 'cid'=>$post->cid,
  500. 'ctl'=>stripslashes($post->ctl),
  501. 'assignid'=>$post->assignid,
  502. 'assign'=>stripslashes($post->name),
  503. 'utp'=>2,
  504. 'fid'=>4,
  505. 'uid'=>$this->uid,
  506. 'uem'=>$this->uem,
  507. 'ufn'=>$this->ufn,
  508. 'uln'=>$this->uln
  509. );
  510. $assigndata['dis']=$this->disableEmail();
  511. $assigndata["md5"]=$this->doMD5($assigndata);
  512. $assigndata['session-id']=$this->tiisession;
  513. $assigndata['src']=TURNITINTOOL_APISRC;
  514. $assigndata['apilang']=$this->getLang();
  515. $this->result=$this->doRequest("POST", $this->apiurl, $assigndata,true,$status);
  516. }
  517. /**
  518. * Call to API FID4, FCMD2/FCMD3 that creates/updates an assignment in Turnitin
  519. *
  520. * @param object $post The post object that contains the necessary query parameters for the call
  521. * @param string $do The call type 'INSERT' or 'UPDATE'
  522. * @param string $status The status to pass to the loaderbar class
  523. */
  524. function createAssignment($post,$do='INSERT',$status) {
  525. global $CFG;
  526. if (!turnitintool_check_config()) {
  527. turnitintool_print_error('configureerror','turnitintool',NULL,NULL,__FILE__,__LINE__);
  528. exit();
  529. }
  530. if ($do!='INSERT') {
  531. $thisfcmd=3;
  532. $userid=$this->uid;
  533. } else {
  534. $thisfcmd=2;
  535. $userid='';
  536. }
  537. // Use the Moodle Default Timezone and fallback on Server timzone if config not set
  538. $timezone = isset( $CFG->timezone ) ? $CFG->timezone : 20;
  539. $assigndata=array('gmtime'=>$this->tiiGmtime(),
  540. 'encrypt'=>TURNITINTOOL_ENCRYPT,
  541. 'aid'=>$this->accountid,
  542. 'diagnostic'=>0,
  543. 'fcmd'=>$thisfcmd,
  544. 'cid'=>$post->cid,
  545. 'ctl'=>stripslashes($post->ctl),
  546. 'assignid'=>$post->assignid,
  547. 'utp'=>2,
  548. 'dtstart'=>userdate($post->dtstart,'%Y-%m-%d %H:%M:%S',$timezone,false), // Default Moodle Timezone
  549. 'dtdue'=>userdate($post->dtdue,'%Y-%m-%d %H:%M:%S',$timezone,false), // Default Moodle Timezone
  550. 'dtpost'=>userdate($post->dtpost,'%Y-%m-%d %H:%M:%S',$timezone,false), // Default Moodle Timezone
  551. 'fid'=>4,
  552. 'uid'=>$userid,
  553. 'uem'=>$this->uem,
  554. 'ufn'=>$this->ufn,
  555. 'uln'=>$this->uln
  556. );
  557. if ($do!='INSERT') {
  558. $assigndata['newassign']=stripslashes($post->name);
  559. $assigndata['assign']=stripslashes($post->currentassign);
  560. } else {
  561. $assigndata['assign']=stripslashes($post->name);
  562. }
  563. $assigndata['dis']=$this->disableEmail();
  564. $assigndata["md5"]=$this->doMD5($assigndata);
  565. $assigndata['session-id']=$this->tiisession;
  566. $assigndata["s_view_report"]=$post->s_view_report;
  567. if (isset($post->max_points)) {
  568. $assigndata["max_points"]=$post->max_points;
  569. }
  570. if (isset($post->report_gen_speed)) {
  571. $assigndata["report_gen_speed"]=$post->report_gen_speed;
  572. }
  573. if (isset($post->anon)) {
  574. $assigndata["anon"]=$post->anon;
  575. }
  576. if (isset($post->late_accept_flag)) {
  577. $assigndata["late_accept_flag"]=$post->late_accept_flag;
  578. }
  579. if (isset($post->submit_papers_to)) {
  580. $assigndata["submit_papers_to"]=$post->submit_papers_to;
  581. }
  582. if (isset($post->s_paper_check)) {
  583. $assigndata["s_paper_check"]=$post->s_paper_check;
  584. }
  585. if (isset($post->internet_check)) {
  586. $assigndata["internet_check"]=$post->internet_check;
  587. }
  588. if (isset($post->journal_check)) {
  589. $assigndata["journal_check"]=$post->journal_check;
  590. }
  591. // Add Exclude small matches, biblio, quoted etc 20100920
  592. if (isset($post->exclude_biblio)) {
  593. $assigndata["exclude_biblio"]=$post->exclude_biblio;
  594. }
  595. if (isset($post->exclude_quoted)) {
  596. $assigndata["exclude_quoted"]=$post->exclude_quoted;
  597. }
  598. if (isset($post->exclude_value)) {
  599. $assigndata["exclude_value"]=$post->exclude_value;
  600. }
  601. if (isset($post->exclude_type) AND $assigndata["exclude_value"]==0) {
  602. $assigndata["exclude_type"]=0;
  603. } else if (isset($post->exclude_type)) {
  604. $assigndata["exclude_type"]=$post->exclude_type;
  605. }
  606. if (isset($post->erater) AND $post->erater != 0) {
  607. $assigndata["erater"]=$post->erater;
  608. $assigndata["ets_handbook"]=$post->erater_handbook;
  609. $assigndata["ets_dictionary"]=$post->erater_dictionary;
  610. $assigndata["ets_spelling"]=$post->erater_spelling;
  611. $assigndata["ets_grammar"]=$post->erater_grammar;
  612. $assigndata["ets_usage"]=$post->erater_usage;
  613. $assigndata["ets_mechanics"]=$post->erater_mechanics;
  614. $assigndata["ets_style"]=$post->erater_style;
  615. }
  616. if (isset($post->transmatch)) {
  617. $assigndata["translated_matching"]=$post->transmatch;
  618. }
  619. if (isset($post->idsync)) {
  620. $assigndata['idsync']=$post->idsync;
  621. }
  622. $assigndata['src']=TURNITINTOOL_APISRC;
  623. $assigndata['apilang']=$this->getLang();
  624. $this->result=$this->doRequest("POST", $this->apiurl, $assigndata,true,$status);
  625. }
  626. /**
  627. * Call to API FID2, FCMD4 that changes the owner tutor for a Turnitin class
  628. *
  629. * @param object $post The post object that contains the necessary query parameters for the call
  630. * @param string $status The status to pass to the loaderbar class
  631. */
  632. function changeOwner($post,$status) {
  633. $assigndata=array('gmtime'=>$this->tiiGmtime(),
  634. 'encrypt'=>TURNITINTOOL_ENCRYPT,
  635. 'aid'=>$this->accountid,
  636. 'diagnostic'=>0,
  637. 'fcmd'=>4,
  638. 'cid'=>$post->cid,
  639. 'ctl'=>stripslashes($post->ctl),
  640. 'tem'=>$this->uem,
  641. 'utp'=>2,
  642. 'fid'=>2,
  643. 'uid'=>$this->uid,
  644. 'uem'=>$this->uem,
  645. 'ufn'=>$this->ufn,
  646. 'uln'=>$this->uln
  647. );
  648. $assigndata['dis']=$this->disableEmail();
  649. $assigndata['md5']=$this->doMD5($assigndata);
  650. $assigndata['session-id']=$this->tiisession;
  651. $assigndata['src']=TURNITINTOOL_APISRC;
  652. $assigndata['apilang']=$this->getLang();
  653. $assigndata['new_teacher_email']=$post->new_teacher_email;
  654. $this->result=$this->doRequest("POST", $this->apiurl, $assigndata,true,$status);
  655. }
  656. /**
  657. * Call to API FID5, FCMD2 that submits a paper to Turnitin
  658. *
  659. * @param object $post The post object that contains the necessary query parameters for the call
  660. * @param string $filedata The filepath / filedata of the file to upload
  661. * @param string $status The status to pass to the loaderbar class
  662. */
  663. function submitPaper($post,$filedata,$status) {
  664. $assigndata=array('gmtime'=>$this->tiiGmtime(),
  665. 'encrypt'=>TURNITINTOOL_ENCRYPT,
  666. 'aid'=>$this->accountid,
  667. 'diagnostic'=>0,
  668. 'fcmd'=>2,
  669. 'cid'=>$post->cid,
  670. 'ctl'=>stripslashes($post->ctl),
  671. 'assignid'=>$post->assignid,
  672. 'assign'=>stripslashes($post->assignname),
  673. 'tem'=>$post->tem,
  674. 'ptype'=>2,
  675. 'ptl'=>stripslashes($post->papertitle),
  676. 'utp'=>1,
  677. 'fid'=>5,
  678. 'uid'=>$this->uid,
  679. 'uem'=>$this->uem,
  680. 'ufn'=>$this->ufn,
  681. 'uln'=>$this->uln,
  682. 'oid'=>$post->oid
  683. );
  684. $assigndata['dis']=$this->disableEmail(true);
  685. $assigndata['md5']=$this->doMD5($assigndata);
  686. $assigndata['session-id']=$this->tiisession;
  687. $assigndata['src']=TURNITINTOOL_APISRC;
  688. $assigndata['apilang']=$this->getLang();
  689. $assigndata['pdata']='@'.$filedata;
  690. $this->result=$this->doRequest("POST", $this->apiurl, $assigndata,false,$status);
  691. }
  692. /**
  693. * Call to API FID4, FCMD7 that queries the settings for the Turnitin assignment
  694. *
  695. * @param object $post The post object that contains the necessary query parameters for the call
  696. * @param string $status The status to pass to the loaderbar class
  697. */
  698. function queryAssignment($post,$status) {
  699. $assigndata=array('gmtime'=>$this->tiiGmtime(),
  700. 'encrypt'=>TURNITINTOOL_ENCRYPT,
  701. 'aid'=>$this->accountid,
  702. 'diagnostic'=>0,
  703. 'fcmd'=>7,
  704. 'cid'=>$post->cid,
  705. 'ctl'=>stripslashes($post->ctl),
  706. 'assignid'=>$post->assignid,
  707. 'assign'=>stripslashes($post->assign),
  708. 'utp'=>2,
  709. 'fid'=>4,
  710. 'uid'=>$this->uid,
  711. 'uem'=>$this->uem,
  712. 'ufn'=>$this->ufn,
  713. 'uln'=>$this->uln
  714. );
  715. $assigndata['dis']=$this->disableEmail();
  716. $assigndata['md5']=$this->doMD5($assigndata);
  717. $assigndata['session-id']=$this->tiisession;
  718. $assigndata['src']=TURNITINTOOL_APISRC;
  719. $assigndata['apilang']=$this->getLang();
  720. $this->result=$this->doRequest("POST", $this->apiurl, $assigndata,true,$status);
  721. }
  722. /**
  723. * Converts the Turnitin Assignment settings to an object in the correct format for a create/update assignment call
  724. *
  725. * @param object $post The post object that contains the necessary query parameters for the call
  726. * @param string $status The status to pass to the loaderbar class
  727. */
  728. function getAssignmentObject() {
  729. $output=new object();
  730. $xmlcall=$this->xmlToSimple($this->result);
  731. if ( isset($this->simplexml->object->assign) ) {
  732. $output->assign = (string)$this->simplexml->object->assign;
  733. $output->dtstart = (integer)$this->simplexml->object->dtstart;
  734. $output->dtdue = (integer)$this->simplexml->object->dtdue;
  735. $output->dtpost = (integer)$this->simplexml->object->dtpost;
  736. $output->ainst = (string)$this->simplexml->object->ainst;
  737. $output->report_gen_speed = (integer)$this->simplexml->object->generate;
  738. $output->s_view_report = (boolean)$this->simplexml->object->sviewreports;
  739. $output->late_accept_flag = (boolean)$this->simplexml->object->latesubmissions;
  740. $output->submit_papers_to = (integer)$this->simplexml->object->repository;
  741. $output->s_paper_check = (boolean)$this->simplexml->object->searchpapers;
  742. $output->internet_check = (boolean)$this->simplexml->object->searchinternet;
  743. $output->journal_check = (boolean)$this->simplexml->object->searchjournals;
  744. $output->anon = (boolean)$this->simplexml->object->anon;
  745. $output->maxpoints = (integer)$this->simplexml->object->maxpoints;
  746. return $output;
  747. } else {
  748. return $output;
  749. }
  750. }
  751. /**
  752. * Call to API FID3, FCMD2 to join the user to a Turnitin Class
  753. *
  754. * @param object $post The post object that contains the necessary query parameters for the call
  755. * @param string $status The status to pass to the loaderbar class
  756. */
  757. function joinClass($post,$status) {
  758. $assigndata=array('gmtime'=>$this->tiiGmtime(),
  759. 'encrypt'=>TURNITINTOOL_ENCRYPT,
  760. 'aid'=>$this->accountid,
  761. 'diagnostic'=>0,
  762. 'fcmd'=>2,
  763. 'cid'=>$post->cid,
  764. 'ctl'=>stripslashes($post->ctl),
  765. 'tem'=>stripslashes($post->tem),
  766. 'utp'=>1,
  767. 'fid'=>3,
  768. 'uid'=>$this->uid,
  769. 'uem'=>$this->uem,
  770. 'ufn'=>$this->ufn,
  771. 'uln'=>$this->uln
  772. );
  773. $assigndata['dis']=$this->disableEmail();
  774. $assigndata['md5']=$this->doMD5($assigndata);
  775. $assigndata['session-id']=$this->tiisession;
  776. $assigndata['src']=TURNITINTOOL_APISRC;
  777. $assigndata['apilang']=$this->getLang();
  778. $this->result=$this->doRequest("POST", $this->apiurl, $assigndata,true,$status);
  779. }
  780. /**
  781. * Call to API FID1, FCMD2 to create a user on the Turnitin System
  782. *
  783. * @param object $post The post object that contains the necessary query parameters for the call
  784. * @param string $status The status to pass to the loaderbar class
  785. */
  786. function createUser($post,$status) {
  787. $assigndata=array('gmtime'=>$this->tiiGmtime(),
  788. 'encrypt'=>TURNITINTOOL_ENCRYPT,
  789. 'aid'=>$this->accountid,
  790. 'diagnostic'=>0,
  791. 'fcmd'=>2,
  792. 'utp'=>$this->utp,
  793. 'fid'=>1,
  794. 'uid'=>$this->uid,
  795. 'uem'=>$this->uem,
  796. 'ufn'=>$this->ufn,
  797. 'uln'=>$this->uln
  798. );
  799. $assigndata['dis']=$this->disableEmail();
  800. $assigndata['md5']=$this->doMD5($assigndata);
  801. $assigndata['session-id']=$this->tiisession;
  802. if (isset($post->idsync)) {
  803. $assigndata['idsync']=$post->idsync;
  804. }
  805. $assigndata['src']=TURNITINTOOL_APISRC;
  806. $assigndata['apilang']=$this->getLang();
  807. $this->result=$this->doRequest("POST", $this->apiurl, $assigndata,true,$status);
  808. }
  809. /**
  810. * Call to API FID1, FCMD2 to create a class on the Turnitin System
  811. *
  812. * @param object $post The post object that contains the necessary query parameters for the call
  813. * @param string $status The status to pass to the loaderbar class
  814. */
  815. function createClass($post,$status,$type="INSERT") {
  816. if (!isset($post->cid)) {
  817. $post->cid="";
  818. $userid="";
  819. } else {
  820. $userid=$this->uid;
  821. }
  822. $ced = isset( $post->ced ) ? $post->ced : null;
  823. if ( $type == "INSERT" ) {
  824. $fcmd = 2;
  825. } else {
  826. $fcmd = 3;
  827. }
  828. $assigndata=array('gmtime'=>$this->tiiGmtime(),
  829. 'encrypt'=>TURNITINTOOL_ENCRYPT,
  830. 'aid'=>$this->accountid,
  831. 'diagnostic'=>0,
  832. 'fcmd'=>$fcmd,
  833. 'utp'=>2,
  834. 'fid'=>2,
  835. 'cid'=>$post->cid,
  836. 'ctl'=>stripslashes($post->ctl),
  837. 'uid'=>$userid,
  838. 'uem'=>$this->uem,
  839. 'ced'=>$ced,
  840. 'ufn'=>$this->ufn,
  841. 'uln'=>$this->uln
  842. );
  843. $assigndata['dis']=$this->disableEmail();
  844. $assigndata['md5']=$this->doMD5($assigndata);
  845. $assigndata['session-id']=$this->tiisession;
  846. if (isset($post->idsync)) {
  847. $assigndata['idsync']=$post->idsync;
  848. }
  849. $assigndata['src']=TURNITINTOOL_APISRC;
  850. $assigndata['apilang']=$this->getLang();
  851. $this->result=$this->doRequest("POST", $this->apiurl, $assigndata,true,$status);
  852. }
  853. /**
  854. * Call to API FID6, FCMD2 to get the Originality Report score
  855. *
  856. * @param object $post The post object that contains the necessary query parameters for the call
  857. * @param string $status The status to pass to the loaderbar class
  858. */
  859. function getReportScore($post,$status) {
  860. if (!turnitintool_check_config()) {
  861. turnitintool_print_error('configureerror','turnitintool',NULL,NULL,__FILE__,__LINE__);
  862. exit();
  863. }
  864. $assigndata=array('gmtime'=>$this->tiiGmtime(),
  865. 'encrypt'=>TURNITINTOOL_ENCRYPT,
  866. 'aid'=>$this->accountid,
  867. 'diagnostic'=>0,
  868. 'fcmd'=>2,
  869. 'oid'=>$post->paperid,
  870. 'utp'=>$post->utp,
  871. 'fid'=>6,
  872. 'uid'=>$this->uid,
  873. 'uem'=>$this->uem,
  874. 'ufn'=>$this->ufn,
  875. 'uln'=>$this->uln
  876. );
  877. $assigndata['dis']=$this->disableEmail();
  878. $assigndata["md5"]=$this->doMD5($assigndata);
  879. $assigndata['session-id']=$this->tiisession;
  880. $assigndata['src']=TURNITINTOOL_APISRC;
  881. $assigndata['apilang']=$this->getLang();
  882. $this->result=$this->doRequest("POST", $this->apiurl, $assigndata,true,$status);
  883. }
  884. /**
  885. * Call to API FID15, FCMD2 to get the GradeMark score
  886. *
  887. * @param object $post The post object that contains the necessary query parameters for the call
  888. * @param string $status The status to pass to the loaderbar class
  889. */
  890. function getGradeMark($post,$status) {
  891. if (!turnitintool_check_config()) {
  892. turnitintool_print_error('configureerror','turnitintool',NULL,NULL,__FILE__,__LINE__);
  893. exit();
  894. }
  895. $assigndata=array('gmtime'=>$this->tiiGmtime(),
  896. 'encrypt'=>TURNITINTOOL_ENCRYPT,
  897. 'aid'=>$this->accountid,
  898. 'diagnostic'=>0,
  899. 'fcmd'=>2,
  900. 'oid'=>$post->oid,
  901. 'utp'=>2,
  902. 'fid'=>15,
  903. 'uid'=>$this->uid,
  904. 'uem'=>$this->uem,
  905. 'ufn'=>$this->ufn,
  906. 'uln'=>$this->uln
  907. );
  908. $assigndata['dis']=$this->disableEmail();
  909. $assigndata["md5"]=$this->doMD5($assigndata);
  910. $assigndata['session-id']=$this->tiisession;
  911. $assigndata['src']=TURNITINTOOL_APISRC;
  912. $assigndata['apilang']=$this->getLang();
  913. $this->result=$this->doRequest("POST", $this->apiurl, $assigndata,true,$status);
  914. }
  915. /**
  916. * Call to API FID10, FCMD2 to list the Submissions for an Assignment
  917. *
  918. * @param object $post The post object that contains the necessary query parameters for the call
  919. * @param string $status The status to pass to the loaderbar class
  920. */
  921. function listSubmissions($post,$status) {
  922. if (!turnitintool_check_config()) {
  923. turnitintool_print_error('configureerror','turnitintool',NULL,NULL,__FILE__,__LINE__);
  924. exit();
  925. }
  926. $fcmd = (isset($post->fcmd) AND $post->fcmd==4) ? 4 : 2;
  927. $tem = (isset($post->tem)) ? $post->tem : '';
  928. $assigndata=array('gmtime'=>$this->tiiGmtime(),
  929. 'encrypt'=>TURNITINTOOL_ENCRYPT,
  930. 'aid'=>$this->accountid,
  931. 'diagnostic'=>0,
  932. 'fcmd'=>$fcmd,
  933. 'assignid'=>$post->assignid,
  934. 'assign'=>$post->assign,
  935. 'cid'=>$post->cid,
  936. 'ctl'=>$post->ctl,
  937. 'tem'=>$tem,
  938. 'utp'=>$this->utp,
  939. 'fid'=>10,
  940. 'uid'=>$this->uid,
  941. 'uem'=>$this->uem,
  942. 'ufn'=>$this->ufn,
  943. 'uln'=>$this->uln
  944. );
  945. $assigndata['dis']=$this->disableEmail();
  946. $assigndata["md5"]=$this->doMD5($assigndata);
  947. if ( !is_null( $this->tiisession ) ) $assigndata['session-id']=$this->tiisession;
  948. $assigndata['src']=TURNITINTOOL_APISRC;
  949. $assigndata['apilang']=$this->getLang();
  950. $this->result=$this->doRequest("POST", $this->apiurl, $assigndata,true,$status);
  951. }
  952. /**
  953. * Call to API FID10, FCMD2 to list the Enrolled users
  954. *
  955. * @param object $post The post object that contains the necessary query parameters for the call
  956. * @param string $status The status to pass to the loaderbar class
  957. */
  958. function listEnrollment($post,$status) {
  959. if (!turnitintool_check_config()) {
  960. turnitintool_print_error('configureerror','turnitintool','',NULL,__FILE__,__LINE__);
  961. exit();
  962. }
  963. $assigndata=array('gmtime'=>$this->tiiGmtime(),
  964. 'encrypt'=>TURNITINTOOL_ENCRYPT,
  965. 'aid'=>$this->accountid,
  966. 'diagnostic'=>0,
  967. 'fcmd'=>5,
  968. 'cid'=>$post->cid,
  969. 'ctl'=>$post->ctl,
  970. 'utp'=>$this->utp,
  971. 'fid'=>19,
  972. 'uid'=>$this->uid,
  973. 'uem'=>$this->uem,
  974. 'ufn'=>$this->ufn,
  975. 'uln'=>$this->uln
  976. );
  977. $assigndata['dis']=$this->disableEmail();
  978. $assigndata["md5"]=$this->doMD5($assigndata);
  979. $assigndata['session-id']=$this->tiisession;
  980. $assigndata['src']=TURNITINTOOL_APISRC;
  981. $assigndata['apilang']=$this->getLang();
  982. $this->result=$this->doRequest("POST", $this->apiurl, $assigndata,true,$status);
  983. }
  984. /**
  985. * Call to API FID19, FCMD2 to unenrol user from class
  986. *
  987. * @param object $post The post object that contains the necessary query parameters for the call
  988. * @param string $status The status to pass to the loaderbar class
  989. */
  990. function unenrolUser($post,$status) {
  991. if (!turnitintool_check_config()) {
  992. turnitintool_print_error('configureerror','turnitintool','',NULL,__FILE__,__LINE__);
  993. exit();
  994. }
  995. $assigndata=array('gmtime'=>$this->tiiGmtime(),
  996. 'encrypt'=>TURNITINTOOL_ENCRYPT,
  997. 'aid'=>$this->accountid,
  998. 'diagnostic'=>0,
  999. 'fcmd'=>2,
  1000. 'cid'=>$post->cid,
  1001. 'ctl'=>$post->ctl,
  1002. 'utp'=>$this->utp,
  1003. 'fid'=>19,
  1004. 'uid'=>$this->uid,
  1005. 'uem'=>$this->uem,
  1006. 'ufn'=>$this->ufn,
  1007. 'uln'=>$this->uln
  1008. );
  1009. $assigndata['dis']=$this->disableEmail();
  1010. $assigndata["md5"]=$this->doMD5($assigndata);
  1011. $assigndata['session-id']=$this->tiisession;
  1012. $assigndata['src']=TURNITINTOOL_APISRC;
  1013. $assigndata['apilang']=$this->getLang();
  1014. $this->result=$this->doRequest("POST", $this->apiurl, $assigndata,true,$status);
  1015. }
  1016. /**
  1017. * Call to API FID2, FCMD2 to update the class having the effect of enrolling the tutor to that class
  1018. *
  1019. * @param object $post The post object that contains the necessary query parameters for the call
  1020. * @param string $status The status to pass to the loaderbar class
  1021. */
  1022. function enrolTutor($post,$status) {
  1023. if (!turnitintool_check_config()) {
  1024. turnitintool_print_error('configureerror','turnitintool','',NULL,__FILE__,__LINE__);
  1025. exit();
  1026. }
  1027. $assigndata=array('gmtime'=>$this->tiiGmtime(),
  1028. 'encrypt'=>TURNITINTOOL_ENCRYPT,
  1029. 'aid'=>$this->accountid,
  1030. 'diagnostic'=>0,
  1031. 'fcmd'=>2,
  1032. 'cid'=>$post->cid,
  1033. 'ctl'=>$post->ctl,
  1034. 'utp'=>$this->utp,
  1035. 'fid'=>2,
  1036. 'uid'=>$this->uid,
  1037. 'uem'=>$this->uem,
  1038. 'ufn'=>$this->ufn,
  1039. 'uln'=>$this->uln
  1040. );
  1041. $assigndata['dis']=$this->disableEmail();
  1042. $assigndata["md5"]=$this->doMD5($assigndata);
  1043. $assigndata['session-id']=$this->tiisession;
  1044. $assigndata['src']=TURNITINTOOL_APISRC;
  1045. $assigndata['apilang']=$this->getLang();
  1046. $this->result=$this->doRequest("POST", $this->apiurl, $assigndata,true,$status);
  1047. }
  1048. /**
  1049. * Output an array of tutors from a listEnrollment call
  1050. *
  1051. * @param object $post The post object that contains the necessary query
  1052. * parameters for the listEnrollment call
  1053. * @param string $status The status to pass to the loaderbar class
  1054. * return array Returns an array of tutors with key of Turnitin UID
  1055. */
  1056. function getTutors($post,$status) {
  1057. $this->listEnrollment($post,$status);
  1058. $result=null;
  1059. $this->xmlToSimple( $this->result );
  1060. if ( isset( $this->simplexml->instructors->instructor ) ) $result = $this->simplexml->instructors->instructor;
  1061. return $result;
  1062. }
  1063. /**
  1064. * Output an array of students from a listEnrollment call
  1065. *
  1066. * @param object $post The post object that contains the necessary query
  1067. * parameters for the listEnrollment call
  1068. * @param string $status The status to pass to the loaderbar class
  1069. * return array Returns an array of tutors with key of Turnitin UID
  1070. */
  1071. function getStudents($post,$status) {
  1072. $this->listEnrollment($post,$status);
  1073. $result=null;
  1074. $this->xmlToSimple( $this->result );
  1075. if ( isset( $this->simplexml->students->student ) ) $result = $this->simplexml->students->student;
  1076. return $result;
  1077. }
  1078. /**
  1079. * Call to API FID6, FCMD1 to Single Sign On to Turnitin's Originality Report for the submission
  1080. *
  1081. * @param object $post The post object that contains the necessary query parameters for the call
  1082. * @return string Returns the URL to access the Originality Report
  1083. */
  1084. function getReportLink($post) {
  1085. $assigndata=array('gmtime'=>$this->tiiGmtime(),
  1086. 'encrypt'=>TURNITINTOOL_ENCRYPT,
  1087. 'aid'=>$this->accountid,
  1088. 'diagnostic'=>0,
  1089. 'fcmd'=>1,
  1090. 'oid'=>$post->paperid,
  1091. 'utp'=>$this->utp,
  1092. 'fid'=>6,
  1093. 'uid'=>$this->uid,
  1094. 'uem'=>$this->uem,
  1095. 'ufn'=>$this->ufn,
  1096. 'uln'=>$this->uln
  1097. );
  1098. $assigndata['md5']=$this->doMD5($assigndata);
  1099. $assigndata['src']=TURNITINTOOL_APISRC;
  1100. $assigndata['apilang']=$this->getLang();
  1101. $keys = array_keys($assigndata);
  1102. $values = array_values($assigndata);
  1103. $querystring='';
  1104. for ($i=0;$i<count($values); $i++) {
  1105. if ($i!=0) {
  1106. $querystring .= '&';
  1107. }
  1108. $querystring .= $keys[$i].'='.urlencode($values[$i]);
  1109. }
  1110. return $this->apiurl."?".$querystring;
  1111. }
  1112. /**
  1113. * Call to API FID13, FCMD1 to Single Sign On to Turnitin's GradeMark for the submission
  1114. *
  1115. * @param object $post The post object that contains the necessary query parameters for the call
  1116. * @return string Returns the URL to access the GradeMark
  1117. */
  1118. function getGradeMarkLink($post) {
  1119. $assigndata=array('gmtime'=>$this->tiiGmtime(),
  1120. 'encrypt'=>TURNITINTOOL_ENCRYPT,
  1121. 'aid'=>$this->accountid,
  1122. 'diagnostic'=>0,
  1123. 'fcmd'=>1,
  1124. 'oid'=>$post->paperid,
  1125. 'utp'=>$this->utp,
  1126. 'fid'=>13,
  1127. 'uid'=>$this->uid,
  1128. 'uem'=>$this->uem,
  1129. 'ufn'=>$this->ufn,
  1130. 'uln'=>$this->uln
  1131. );
  1132. $assigndata['md5']=$this->doMD5($assigndata);
  1133. $assigndata['src']=TURNITINTOOL_APISRC;
  1134. $assigndata['apilang']=$this->getLang();
  1135. $keys = array_keys($assigndata);
  1136. $values = array_values($assigndata);
  1137. $querystring='';
  1138. for ($i=0;$i<count($values); $i++) {
  1139. if ($i!=0) {
  1140. $querystring .= '&';
  1141. }
  1142. $querystring .= $keys[$i].'='.urlencode($values[$i]);
  1143. }
  1144. return $this->apiurl."?".$querystring;
  1145. }
  1146. /**
  1147. * Call to API FID7, FCMD1 to Single Sign On to Turnitin's Submission View for the submission
  1148. *
  1149. * @param object $post The post object that contains the necessary query parameters for the call
  1150. * @return string Returns the URL to access the Submission View
  1151. */
  1152. function getSubmissionURL($post) {
  1153. $assigndata=array('gmtime'=>$this->tiiGmtime(),
  1154. 'encrypt'=>TURNITINTOOL_ENCRYPT,
  1155. 'aid'=>$this->accountid,
  1156. 'diagnostic'=>0,
  1157. 'fcmd'=>1,
  1158. 'oid'=>$post->paperid,
  1159. 'utp'=>$this->utp,
  1160. 'fid'=>7,
  1161. 'assignid'=>$post->assignid,
  1162. 'assign'=>$post->assign,
  1163. 'ctl'=>$post->ctl,
  1164. 'cid'=>$post->cid,
  1165. 'uid'=>$this->uid,
  1166. 'tem'=>$post->tem,
  1167. 'uem'=>$this->uem,
  1168. 'ufn'=>$this->ufn,
  1169. 'uln'=>$this->uln
  1170. );
  1171. $assigndata['md5']=$this->doMD5($assigndata);
  1172. $assigndata['src']=TURNITINTOOL_APISRC;
  1173. $assigndata['apilang']=$this->getLang();
  1174. $keys = array_keys($assigndata);
  1175. $values = array_values($assigndata);
  1176. $querystring='';
  1177. for ($i=0;$i<count($values); $i++) {
  1178. if ($i!=0) {
  1179. $querystring .= '&';
  1180. }
  1181. $querystring .= $keys[$i].'='.urlencode($values[$i]);
  1182. }
  1183. return $this->apiurl."?".$querystring;
  1184. }
  1185. /**
  1186. * Call to API FID7, FCMD2 to download the original paper of the submission
  1187. *
  1188. * @param object $post The post object that contains the necessary query parameters for the call
  1189. * @return string Returns the URL to access the Download Link
  1190. */
  1191. function getSubmissionDownload($post) {
  1192. $assigndata=array('gmtime'=>$this->tiiGmtime(),
  1193. 'encrypt'=>TURNITINTOOL_ENCRYPT,
  1194. 'aid'=>$this->accountid,
  1195. 'diagnostic'=>0,
  1196. 'fcmd'=>2,
  1197. 'oid'=>$post->paperid,
  1198. 'utp'=>$this->utp,
  1199. 'fid'=>7,
  1200. 'assignid'=>$post->assignid,
  1201. 'assign'=>$post->assign,
  1202. 'ctl'=>$post->ctl,
  1203. 'cid'=>$post->cid,
  1204. 'uid'=>$this->uid,
  1205. 'tem'=>$post->tem,
  1206. 'uem'=>$this->uem,
  1207. 'ufn'=>$this->ufn,
  1208. 'uln'=>$this->uln
  1209. );
  1210. $assigndata['md5']=$this->doMD5($assigndata);
  1211. $assigndata['src']=TURNITINTOOL_APISRC;
  1212. $assigndata['apilang']=$this->getLang();
  1213. $keys = array_keys($assigndata);
  1214. $values = array_values($assign

Large files files are truncated, but you can click here to view the full file