Sindbad~EG File Manager

Current Path : /usr/home/beeson/public_html/helpwithmath/
Upload File :
Current File : /usr/home/beeson/public_html/helpwithmath/WebGrades.php.backup

<?php 
// M. Beeson 8.16.10 
// Web service to support the WebGrades version of MathXpert
// last modified 8.15.11
 
require_once('DB.php');
require_once('queryWebGrades.php');

function submitHomework($SecretNumber, $Filename, $Topic, $ProblemNumber) 
// Store the given number in the webgrades database
// return 0 for success or 1 for invalid studentNumber
// or 2 if for some reason the database entry failed.

{  $SubmissionDate = date("Y-m-d");   // today's date  in format 2010-08-13  (SQL wants that format for insertion)
   $StudentNumber = (int) ($SecretNumber / 23);  // secret numbers are congruent to 17 mod 23.  StudentNumbers use all numbers starting at 1.
   $sql = "SELECT * FROM `Homework`  WHERE StudentNumber='$StudentNumber' AND Filename='$Filename' AND Topic='$Topic' AND ProblemNumber='$ProblemNumber';";   
   $r = QueryWebGrades($sql);
   if(is_string($r))
        return 2;
   if($r->fetchRow()==NULL)  // it hasn't already been submitted  
      {  $sql = "INSERT INTO `Homework` (Topic, Filename, SubmissionDate, StudentNumber, ProblemNumber) VALUES('$Topic','$Filename','$SubmissionDate','$StudentNumber','$ProblemNumber');";
         $r=QueryWebGrades($sql);  // insert this data into the database. 
		 if(is_string($r))
		      return 2; 
	  }
    return 0;  // If we get here, it succeeded
} 
 


function validateNumber($Email, $flag)
// flag % 20 will be used to identify the ProductID idnentifying which CallHome MathXpert Assistant the user is trying to run.
// These ProductIDs are presently 1,2,3 for Calculus, Precalcus, Algebra; 4,5,6 for the Lab Editions of those three,  
// then 7,8,9 for the CallHome editions of Calculus, Precalculus, and Algebra, and 10 for the Grapher.
// if flag <= 20  then enrollment in WebGrades is sufficient to run; otherwise you must also have purchased the product from HelpWithMath.  
//   
// check if a user with this email is allowed to run MathXpert, and if they are enrolled in WebGrades. 
// The possible return values are:
// if enrolled in WebGrades and allowed to run:  a secret number, at least 17, given by (17 + 23*StudentNumber).
// if email is recognized and they are allowed to run, but not enrolled in WebGrades:  10
// if email is recognized but time limit has expired:  9
// if email is not recognized:  0
 
{  if(strcasecmp($Email,"testing2011@gmail.com")==0)
       return 40;   // just for testing a valid response
   $sql = "SELECT * FROM `Students` WHERE Email='$Email';";  // = is case-insensitive in SQL  
   $result = queryWebGrades($sql);
   if($result==NULL)
       { return 0; // should never happen, even if there's no data  
	   }
   $result->fetchInto($r);
   if($r == NULL)
       { return 0; // no student with that email is (or ever was) enrolled or purchased a CallHome version --unrecognized email
	   }
   $enrolled = false;
   $StudentNumber = $r[0];
   $SecretNumber = 17 + 23 * $StudentNumber;
   // now determine if the student is CURRENTLY enrolled in a WebGrades class	 
   $sql = "SELECT * FROM `Classes`  JOIN `Enrolled` ON Classes.ClassID=Enrolled.ClassID WHERE Enrolled.StudentNumber='$StudentNumber' AND CURDATE() <= Classes.EndDate;";
   $result = queryWebGrades($sql);
   if($result == NULL)
      $enrolled = false;
   else
     {  $result->fetchInto($r);
       if($r != NULL )
          $enrolled = true;
	   else
	      $enrolled = false;
	 }
	if($enrolled)   // using the line just below disables the Lab Edition in Fall 2012.   
   // if($flag <= 20 && $enrolled)   // a pre-paid version distributed with a WebGrades class, e.g. in the back of a textbook.   They will have to enroll for WebGrades
                               // before such a version  will run unless they have purchased it.
	    return $SecretNumber;    // user is enrolled in a real class currently
   // now check if user has purchased and their license has not expired
   $flag = $flag % 20;  // the ProductID 
   $sql = "SELECT * FROM `Expiration` WHERE StudentID='$StudentNumber' AND ProductID >= '$flag' AND CURDATE() <= Expiration.ExpirationDate;";
  // echo $sql; echo "<br>";
   $result = queryWebGrades($sql);
   if($result != NULL &&  $result->fetchRow() != NULL)
       { if($enrolled) 
	         return $SecretNumber;
		 return 10;  // allowed to run, but not enrolled in WebGrades
	   }
   $sql = "SELECT * FROM `Expiration` WHERE StudentID='$StudentNumber' AND ProductID >= '$flag' AND CURDATE() > Expiration.ExpirationDate;";
   $result = queryWebGrades($sql);
   if($result != NULL && $result->fetchRow() != NULL)
       return 9;  // email recognized but time limit expired.
   return 10;   // should never get here!  But if you do, let them run.
}


ini_set("soap.wsdl_cache_enabled", "0");     
$server = new SoapServer("WebGrades.wsdl"); 
$server->addFunction("submitHomework"); 
$server->addFunction("validateNumber");
$server->handle(); 

?>

 




 


Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists