Location: PHPKode > projects > Shift Log > shiftlog_stable_1.9.4/shiftlog/includes/DropMenu.class.php
* Author(s): Gobinath  Modified by: Brandon Crabtree to be included in the program Shift Log
* DropMenu Class
* Explanation: purpose of this class is to Fetch values from the database and display in 2 Drop Down
* Reason : The second Drop Down WIll be based on the Selection of First
class DropMenu{

	 //Member varible Declaration
	 var $db_con;
	 var $rs_row;
 	 var $ERR_MSG; 
	 var $subcatArrayResult;
	 // Declare Array Variable;
	 var $catArray;
	 var $subcatArray;

     // Declare a variable for Assigning the Current Form Name
	 var $CurrectForm;
	function DropMenu($database){
     //Purpose: Constructer to Handle Database And Value initialize 
              $this->db_con=mysql_connect($database['server'],$database['user'],$database['password']) or die(mysql_error());
		      mysql_select_db($database['database'],$this->db_con) or die(mysql_error($this->db_con));	  
			  // Declare the variables as Array
	          $this->catArray = array();			  
	function close_DropMenu_database(){
	//Purpose: Close the Database Connectivity
	function DataFetch(){ 
	//Purpose: Fetch the Data From 2 Different Table and store it in array
	// Suggestions: If you have changed the Table Names Please Change it in the sql;
	    $catSql="SELECT * FROM category ORDER BY o_id";   
		while ($catRow = mysql_fetch_array($catResult,MYSQL_BOTH)){
					$this->catArray[$IDx][$i] = $catRow[$i];
			$subcatSql="select * from subcat WHERE cat_id='".$catRow["cat_id"]."' ORDER BY o_id";		   
			while($subcatRow = mysql_fetch_array($subcatResult)){
					    $this->subcatArray[$IDy][$i] = $subcatRow[$i];
			}// subcat While Loop Ends here;
		} // cat subcat Loop End 
	}// DataFetch Function Ends here
	function createfrmObject($frmObjName){ 
	//Purpose: Create the Javascript Dynamically
	    $this->CurrectForm= $frmObjName;
	    $DocElement = "document.".$this->CurrectForm.".subcat";
      echo "<script type=\"text/javascript\" language=\"javascript\">";
		  echo "<!--\n";
      echo "\rfunction changesubcat(obj){\r";
         echo "\rif(obj.value == '".$this->catArray[$i][0]."'){\r";
         echo "\r\t/* Value for the subcat Drop Down */\r";
         echo "\tdocument.$this->CurrectForm.subcat.options.length = 0;\r";
         echo "\t$DocElement.options[$DocElement.options.length] = new Option('','');\r";
             if ( $this->catArray[$i][0] == $this->subcatArray[$j][1]){
                echo "\t$DocElement.options[$DocElement.options.length] = new Option('".$this->subcatArray[$j][2]."','".$this->subcatArray[$j][0]."');\r";
         echo "\tdocument.$this->CurrectForm.subcat.disabled = false;\n\r";
         echo "\treturn true;\r";
         echo "}\r";
   		echo "}\r";
	 	  echo "-->\r";
	    echo "</script>";	
   function CreateSelect(){
        echo "Category&nbsp;<select name=\"cat\" size=\"1\" onChange='changesubcat(this)'>\r";
		    echo "<option value='0'>Select One</option>\r";
		         echo "<option value='".$this->catArray[$i][0]."'>".$this->catArray[$i][1]."</option>\r";
		    echo "</select> &nbsp; Subcategory&nbsp;";
        echo "<select name=\"subcat\" disabled>\r";
        echo "<option value=''></option>\r";		 
	      echo "</select>\r";
} // Class DropMenu Ends Here

Return current item: Shift Log