All pastes #394319 Raw Edit

Mine

public php v1 · immutable
·published 2007-03-14 06:10 UTC
rendered paste body
<?php// --------------------------------------------------------------------------------// Oprpg.net, Experimental 1.0.0.1// --------------------------------------------------------------------------------// License Private - Alexander Toney - July 2005// http://www.z15engineering.com// --------------------------------------------------------------------------------//// Presentation :////// Description :////// Warning://   This library and the associated files are professional work.//   It should not have unexpected results. However if any damage is caused by//   this software the author can not be responsible.//   The use of this software is at the risk of the user.// Contacts://   Alex Toney, toneyalex@gmail.com//// --------------------------------------------------------------------------------// $Id: common_class.php,v 1.1 2006/01/15 05:08:35 cvs Exp $// --------------------------------------------------------------------------------//class common{	/**	 * Enter description here...	 *	 * @var unknown_type	 */	public $Broom;	/**	 * Gives a Specified Item	 *	 * @param String $Username	 * @param Integer $ItemId	 */	function AddItem($Username,$ItemId){		mysql_query("INSERT INTO inventory VALUES('','$Username','$ItemId')") or die(mysql_error());		return true;	}	/**	 * Takes a specified item	 *	 * @param String $Username	 * @param Integer $ItemId	 */	function TakeItem($Username,$ItemId){		mysql_query("DELETE FROM inventory WHERE username='$Username' AND tid='$ItemId'") or die(mysql_error());		return true;	}	/**	 * Sets Up an event	 *	 * @param String $Username	 * @param String $Event	 */	function TriggerEvent($Username,$Event){		mysql_query("INSERT INTO events (username,event) VALUES ('$Username','$Event'") or die(mysql_error());		return true;	}	/**	 * Checks the amount of money the user has	 *	 * @param unknown_type $username	 * @return unknown	 */	function GetMoneyAmount($Username) {		$info = mysql_query("SELECT * FROM members WHERE username = '$Username'") or die(mysql_error());		$info = mysql_fetch_object($info);		return $info->knuts;	}	/**	 * Enter description here...	 *	 * @param unknown_type $Username	 * @param unknown_type $Level	 */	function MomAccess($Username,$Level){		$MinistrySql = mysql_query("SELECT COUNT(*) as Count FROM op_mom_appointments WHERE Username='$Username' AND Level='$Level'");		$Ministry    = mysql_fetch_object($MinistrySql);		if($Ministry->Count <= 0){			message('Pass invalid','Your pass has either expired or you do not have one.<br> Go to <a href="/ministry.php?level=8">The Atrium</a> to apply');		}		$MinistrySql = mysql_query("SELECT * FROM op_mom_appointments WHERE Username='$Username'");		$Ministry    = mysql_fetch_object($MinistrySql);		if($Ministry->Date < time()){			message('Pass invalid','Your pass has either expired or you do not have one.<br> Go to <a href="/ministry.php?level=8">The Atrium</a> to apply');		}	}	/**	 * Enter description here...	 *	 * @param unknown_type $Username	 * @param unknown_type $level	 */	function RenewMomAccess($Username,$level){		$MinistrySql = mysql_query("SELECT COUNT(*) as Count FROM op_mom_appointments WHERE username='$username' AND Level='$level'");		$Ministry    = mysql_fetch_object($MinistrySql);		if($Ministry->Count <= 0){			$nextWeek = time() + (7 * 24 * 60 * 60);			mysql_query("INSERT INTO op_mom_appointments VALUES('','$nextWeek','$Username','$level')");			message('Thanks...','Thanks for applying for a pass you will be granted access to the area soon');		}		else{			$nextWeek = time() + (7 * 24 * 60 * 60);			mysql_query("UPDATE op_mom_appointments SET Date='$nextWeek' WHERE Username='$username' AND Level='$level'");			message('Thanks...','Thanks for updating your pass. You will be granted access to the area soon');		}	}	/**	 * Enter description here...	 *	 * @param unknown_type $Username	 * @param unknown_type $Broom	 */	function SetBroom($Username,$Broom){		$BroomSQL = mysql_query("SELECT * FROM items WHERE id='$Broom'");		$Broom    = mysql_fetch_object($BroomSQL);		mysql_query("UPDATE members SET Broom='$Broom->name' WHERE username='$Username'");		$this->Broom = $Broom->name;	}	/**	 * Enter description here...	 *	 * @param unknown_type $title	 * @param unknown_type $Message	 * @param unknown_type $Time	 * @param unknown_type $Redirect	 */	function Message($title,$Message,$Time=0,$Redirect="") {		$bordercolor = "#000000";		$bgcolor = "#FFFFFF";		echo "   	 <center>  	  <br><br>   	 <table cellspacing=\"1\" cellpadding=\"2\" width=\"75%\" bgcolor=\"$bordercolor\">   	  <tr style=\"background-color: $bgcolor\">   	   <td>       <b><u><center>$title  	    </td> 	    </tr> 	    <tr style=\"background-color: $bgcolor\"> 	     <td>  	     <center>$Message   	   </td>    	 </tr>    	</table>  		";		if (!empty($Redirect)) {			echo "<meta http-equiv=\"refresh\" content=\"1;url=$redirect\">";		}		if ($Time == 0) {			include("/home/op/public_html/footer.php");			die();		}	}	/**	 * Enter description here...	 *	 */	function MembersOnly() {		global $username;		if (!$username) {			message("OPRPG...","This page is for members only so please either login or register.");		}	}	/**	 * Enter description here...	 *	 * @param unknown_type $location	 * @return unknown	 */	function SetLocation($location){		if(!is_null($location)){			define('OP_PAGE',$location);			return true;		}		else{			return false;		}	}	/**	 * Enter description here...	 *	 * @param unknown_type $Username	 * @param unknown_type $location	 */	function LogTime($Username,$location,$session){		$Time = time();		mysql_query("INSERT INTO op_time_log VALUES('','$Username','$Time','$location','$session')");		mysql_query("INSERT INTO op_time_log_keep VALUES('','$Username','$Time','$location','$session')");	}		/*** Returns conditional probability of $A given $B and $Data.* $Data is an indexed array.  Each element of the $Data array* consists of an A measurement and B measurment on a sample* item.*/	function getConditionalProbabilty($A, $B, $Data) {		$NumAB   = 0;		$NumB    = 0;		$NumData = count($Data);		for ($i=0; $i < $NumData; $i++) {			if (in_array($B, $Data[$i])) {				$NumB++;				if (in_array($A, $Data[$i])) {					$NumAB++;				}			}		}		return $NumAB / $NumB;	}}class weather{	/**	 * Enter description here...	 *	 * @var unknown_type	 */	public $weathernow;	/**	 * Enter description here...	 *	 * @var unknown_type	 */	public $decay;	/**	 * Enter description here...	 *	 * @return weather	 */	function weather (){		$sql   = "SELECT * FROM layout";		$query = mysql_query($sql);		$weather = mysql_fetch_object($query);	}	/**	 * Enter description here...	 *	 * @return unknown	 */	function rand_weather(){		$weather = $this->weather();		if($weather <= 30){			$this->weathernow = rand(1,40);		}		if($weather <= 40){			$this->weathernow = rand(20,50);		}		if($weather <= 50){			$this->weathernow = rand(30,60);		}		if($weather <= 60){			$this->weathernow = rand(40,70);		}		if($weather <= 70){			$this->weathernow = rand(50,80);		}		if($weather <= 80){			$this->weathernow = rand(60,90);		}		if($weather <= 90){			$this->weathernow = rand(70,100);		}		if($weather <= 100){			$this->weathernow = rand(80,110);		}		return($this->weathernow);	}	//decaying function	/**	 * Enter description here...	 *	 */	function weather_decay(){		$from=weather::weather();		$to=weather::rand_weather();		$time=rand(1,10);		$diff=$to-$from;		$decay=$time/$diff;	}	/**	 * Enter description here...	 *	 */	function change_weather(){		$time = time();		$from = weather::weather();		$weatherdiff=$decay+$from;		$sql="UPDATE weather SET";		mysql_query($sql);	}}    /**    * Bayes    *    * Calculates posterior probabilities for m hypotheses and n evidence    * alternatives.  The code was inspired by a procedural TrueBasic version    * (Bayes.tru) bundled with Grimstead and Snell's excellent online    * textbook "Introduction to Probability".    */    class Bayes {      /**      * Number of evidence alternatives (that is, number of rows).      */      var $m;      /**      * Number of hypothesis alternatives (that is, number of columns).      */      var $n;      /**      * Output labels for evidence alternatives.      */      var $row_labels = array();           /**      * Output labels for hypothesis alternatives.      */       var $column_labels = array();      /**      * Vector container for prior probabilities.      */      var $priors = array();      /**      * Matrix container for likelihood of evidence e given hypothesis h.      */      var $likelihoods = array();      /**      * Matrix container for posterior probabilties.      */      var $posterior = array();      /**      * Vector container for evidence probabilties.      */      var $evidence = array();      /**      * Initialize the Bayes algorithm by setting the priors, likelihoods      * and dimensions of the likelihood and posterior matrices.      */      function Bayes($priors, $likelihoods) {        $this->priors = $priors;        $this->likelihoods = $likelihoods;        $this->m = count($this->likelihoods);  // num rows        $this->n = count($this->likelihoods[0]); // num cols        return true;      }           /**      * Output method for setting row labels prior to display.      */      function setRowLabels($row_labels) {        $this->row_labels = $row_labels;        return true;      }      /**      * Output method for setting column labels prior to display.      */      function setColumnLabels($column_labels) {        $this->column_labels = $column_labels;        return true;      }      /**      * Compute the posterior probability matrix given the priors and      * likelihoods.      *      * The first set of loops computes the denominator of the canonical      * Bayes equation. The probability appearing in the denominator      * serves a normalizing role in the computation - it ensures that      * posterior probabilities sum to 1.      *      * The second set of loops:      *      *   1. multiplies the prior[$h] by the likelihood[$h][$e]      *   2. divides the result by the denominator      *   3. assigns the result to the posterior[$e][$h] probability matrix      */      function getPosterior() {        // Find probability of evidence e        for($e=0; $e < $this->n; $e++) {          for ($h=0; $h < $this->m; $h++) {            $this->evidence[$e] += $this->priors[$h]               * $this->likelihoods[$h][$e];          }        }        // Find probability of hypothesis given evidence        for($e=0; $e < $this->n; $e++) {          for ($h=0; $h < $this->m; $h++) {            $this->posterior[$e][$h] = $this->priors[$h] * $this->likelihoods[$h][$e] / $this->evidence[$e];          }        }        return true;      }           /**      * Output method for displaying posterior probability matrix      */      function toHTML($number_format="%01.3f") {        ?>        <table border='1' cellpadding='5' cellspacing='0'>          <tr>            <td> </td>            <?php            for ($h=0; $h < $this->m; $h++) {              ?>              <td align='center'>                 <b><?php echo $this->column_labels[$h] ?></b>              </td>              <?php            }            ?>          </tr>          <?php          for($e=0; $e < $this->n; $e++) {            ?>            <tr>              <td><b><?php echo $this->row_labels[$e] ?></b></td>              <?php              for ($h=0; $h < $this->m; $h++) {                ?>                <td align='right'>                   <?php printf($number_format, $this->posterior[$e][$h]) ?>                </td>                <?php              }              ?>            </tr>            <?php          }          ?>        </table>        <?php      }    }?>