Sindbad~EG File Manager

Current Path : /home/beeson/public_html/helpwithmath_old/
Upload File :
Current File : //home/beeson/public_html/helpwithmath_old/TestTimeLimited.php

<?php 
// This page is just for testing. 
 
require_once('DB.php');
require_once('query.php');
require_once('queryWebGrades.php');
require_once('dates.php');
session_start();

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 recognized,  $flag > 20 (indicating not a PREPAID version) and they are not enrolled in WebGrades:  8
// 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($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.
	    return $secretNumber;    // user is enrolled in a real class currently
   if($flag <= 20)    // and not enrolled in a WebGrades class
        return 8;
   // 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
	   }
   return 9;  // email recognized but time limit expired.
}

$ProductID = 9;
if($ProductID == 7)   
    $_SESSION['WhichDisk'] =  7;
else if($ProductID==8)
    $_SESSION['WhichDisk'] = 3;
else
    $_SESSION['WhichDisk'] = 1;

$_SESSION['OK'] = "ok";
$_SESSION['ProductType'] = "paid";
$days = 153;
$_SESSION['TimeLimit'] = $days; 
// next fetch the product name from the database using $ProductID
$sql = "SELECT ProductName FROM `Products` WHERE ProductID='$ProductID';";
$result = query($sql);
$result->fetchInto($r);
$ProductName = $r[0];
// next fetch the email address from the database
if(isset($CustomerID))
{ $sql = "SELECT Email FROM `Customers` WHERE CustomerID='$CustomerID';";
  $result = query($sql);
  $result->fetchInto($r);
  $Email = $r[0];
}
  else 
     $Email = "testing2011@gmail.com";


  
  
 ?> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<body onmousemove="closesubnav(event);"> 
 <div class="style1" id="pageName"> 
  <p></p>
<?php 
 include ('include/head.php'); 
 include ('include/body.php'); 

$found = false;
// see if this email is already in the WebGrades database
$sql = "SELECT StudentNumber FROM `Students` WHERE Email='$Email';";
echo $sql; echo "<br>";
$results = queryWebGrades($sql);
if($results!= NULL)
    { $results->fetchInto($r);
	  if($r != NULL)
	       { $StudentNumber = $r[0];
	         $found = true;
			 echo "found <br>";
		   }
	}
if($found == false) 
    { // enter this new student
	  $sql = "INSERT INTO `Students` (Email,FirstName,LastName) VALUES('$Email','','');";
	  queryWebGrades($sql);  // store the new record
	  // Now we need to bear in mind that when a student registers for WebGrades, his email might already be there with empty name strings.
	  echo "not found, and then entered. <br>";
	}
$deleted = false;
if($Email=="beesonpublic@gmail.com")
      { // remove old entry from Expiration database
	     $sql = "DELETE FROM `Expiration` WHERE StudentID='$StudentNumber' AND ProductID='$ProductID';";
		 queryWebGrades($sql);
		 $deleted = true;
	   }



// compute the expiration date, which will be $days days from now
$today = getdate();
 
$months = $days/30;  // so it will be 5 when days is 153 
$ExpirationDatePHPArray = add_months($today, $months);
$ExpirationDateSQLFormat = SqlDate($ExpirationDatePHPArray);


 // see if there's already an entry in the Expiration table for this student and product 
 $sql = "SELECT * FROM `Expiration` WHERE StudentID='$StudentNumber' AND ProductID='$ProductID';";
  echo $sql; echo "<br>";
 $result = queryWebGrades($sql);
 $result->fetchInto($r);
 if($r != NULL) 
     {  $todayflag = false;   // don't touch the existing database entry entry.  They can download again, but the expiration date won't change. 
	    echo "not inserting<br>";
	 }
 else 
    { $sql = "INSERT INTO `Expiration` (StudentID, ProductID, ExpirationDate) VALUES('$StudentNumber', '$ProductID', '$ExpirationDateSQLFormat');";
	  echo "inserting <br>";
      queryWebGrades($sql);
	  $todayflag = true;
	}  
	
$rval = validateNumber($Email, 29);
echo "validateNumber returned $rval <br>";
?>
 
<h3> This page allows you to download your copy of <?php echo $ProductName ?>. </h3>
<body>
<p></p>
 <form action="download4.php">
   <input type="submit" value="Download Now">
 </form>
 <p></p>
 <p> This copy will expire on <?php echo format_date($ExpirationDatePHPArray) ?>, which is five months from 
      <?php  if($todayflag) 
	              echo "today.";
               else 
                  echo "the date of your first download. ";
	 
      ?> 
 </p> 
   </div>   
<?php include ('include/footer.php'); ?>
</body>
</html>

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