Jump to content

Need help with this class file.


magic2goodil

Recommended Posts

Hey, I am working on a calendar class for a charity project I am doing for a church.

 

Everything was working perfect until I tried to use the set_mode() function.

 

The set_mode() function is supposed to check the session for a username and password and then run the function validUser() on them.  The validUser() function of course checks them through the database and if the combination is correct then the private variable $mode is set to admin, otherwise it is not set.  Everything works fine if the mode is set to admin, but if the user/pass do not match, aka !validUser, then the calendar suddenly does not print at all like it is supposed to.  The oddest thing ever though, is when i enter an incorrect password, it messes up, but if i enter a password of "" it reads that as incorret but the calendar prints out in user mode exactly as it should...I find that odd, since using a wrong password of say "p" should still be just as wrong as "". 

 

The correct user and pass for now on my local server is "j" for both user and pass.  When I set them both as such it goes to admin mode just fine.  Can anyone tellme what I have done wrong in my code to make it print out a blank white page when the password is incorrect with a value and not incorrect as just "".

 

<?php


session_start();

$_SESSION['user'] = "j";
$_SESSION['pass'] = "o";


/****************************************
*					*
* Calendar class created to create a    *
* calendar system for holding events	*
* contained on each specified calendar	*
* day.  Each calendar object can access	*
* mysql database to pull in 		*
* Calendar_Event objects.  Calendar 	*
* class also has funtions designed to	*
* write the calendar to the screen, 	*
* as well as: add, edit, and delete 	*
* Calendar_Events.			*
*					*
* @author:	Josh Robison		*
* @date:	February 18, 2007	*
* @version:	1.0			*
*					*
****************************************/

class Calendar {


private $mode;
public $theDay;
public $theMonth;
public $theYear;

public function Calendar($Month,$Year) {

	//constructor.



		$theDay = date("d");
		$theMonth = $Month;
		$theYear = $Year;



	$this->set_mode();

	$this->draw($theDay,$theMonth,$theYear);


}



private function set_mode() {

	//takes in $_SESSION to check for valid Admin
	//if valid Admin, sets $mode to admin
	//else mode stays as user by default.

	if (!empty($_SESSION['user']) && !empty($_SESSION['pass'])) {


		if($this->validUser($_SESSION['user'],$_SESSION['pass'])) {

			$this->mode = "admin";


		}



	}




}



private function get_mode() {

	//returns private variable $mode

	return $this->mode;

}




/********************************************************
*							*
* Used to build the calendarArray and prepare it to be	*
* drawn to the screen.  If a day has an event, then the	*
* number of events for that day are added to.		*
*							*
********************************************************/

public function build($myMonth,$myYear) {

	//uses date() to get the day, month, and year.
	//builds a calendar array from this.
	//takes in mysql array from calendar database
	//iterates through new calendar array checking for days 
	//that match.


	$conn = mysql_connect("localhost","root","******") or die(mysql_error());
	$db = mysql_select_db("Calendar") or die(mysql_error());
	$query = "SELECT `Day` FROM `Events` WHERE `Month` = '$myMonth' and `Year` = '$myYear' ORDER BY `Day` ASC";
	$result = mysql_query($query) or die(mysql_error());
	$days_in_month = date('t', strtotime($myYear . '-' . $myMonth)); 
	$calendarArray = array($days_in_month);

		for($i=0;$i<$days_in_month;$i++) {

			$calendarArray[$i] = 0;


		}





	for($i=0;$i<$days_in_month;$i++) {

		$q = $i+1;


		for($z=0;$z<mysql_num_rows($result);$z++) {

			if($q == mysql_result($result, $z)) {


				 $calendarArray[$i]+=1;

			}	

		}

	}  

	return $calendarArray;      

}

/********************************************************
*							*
* Used to draw the calendar system to the screen.  	*		
* Highlights the days with events in green as well as 	*
* makes them links.  If in admin mode, all days without *
* events are highlighted in blue when moved over and 	*
* can be clicked on to add events to them.  The current	*
* day of the week is highlighted in red.		*	
*							*
********************************************************/

public function draw($myDay, $myMonth,$myYear)	{

	$days_in_month = date('t', strtotime($myYear . '-' . $myMonth)); 
	//draws the calendar to the screen

	echo '
	<table width="158" bgcolor="#FFFFFF" style="border: 1px solid #000000;">
  		<tr>

  		<td width="20"><div align="center"><a href="'.$_SERVER["PHP_SELF"].'?mo='. date("F", mktime(0,0,0,date("m", strtotime($myMonth)),"-1",(int)$myYear)) .'&yr='.$this->getPrev($myMonth,$myYear).'"><img src="left_arrow.JPG" border="0"></a></div></td>
    		<td width="20"><div align="center" style="font-size:12px; color: #000000; font-weight: bold;"><strong>'.$myMonth.' ' .$myYear. '</strong></div></td>
	<td width="20"><div align="center"><a href="'.$_SERVER["PHP_SELF"].'?mo='. date("F", mktime(0,0,0,date("m", strtotime($myMonth)),$days_in_month+1,(int)$myYear)).'&yr='.$this->getNext($myMonth,$myYear,$days_in_month).'"><img src="right_arrow.JPG" border="0"></a></div></td>
    
  		</tr>
	</table>

	<table width="158" bgcolor="#000066" style="border: 1px solid #FFFFFF;border-top:0px;">
  		<tr>

    		<td width="20"><div align="center"style=" color: #FFFFFF; font-weight: bold;">S</div></td>
    		<td width="20"><div align="center" style=" color: #FFFFFF; font-weight: bold;">M</div></td>
    		<td width="20"><div align="center" style=" color: #FFFFFF; font-weight: bold;">T</div></td>
    		<td width="20"><div align="center" style=" color: #FFFFFF; font-weight: bold;">W</div></td>
    		<td width="20"><div align="center" style=" color: #FFFFFF; font-weight: bold;">T</div></td>
    		<td width="20"><div align="center"style=" color: #FFFFFF; font-weight: bold;">F</div></td>
    		<td width="20"><div align="center" style=" color: #FFFFFF; font-weight: bold;">S</div></td>

	</tr>
	</table>

	<table width="158" bgcolor="#999999" style="border: 1px solid #000000;border-top:0px;"><tr>';

	$count = 0;

	$calendarArray = $this->build($myMonth,$myYear); //building calendarArray

	//pulling from array and beginning to iterate through it.

	for($i=0;$i<count($calendarArray);$i++) {

		$q = $i+1; //used to get the real day of the week, not the array number

		/****************************************************************
		*								*
		* Checks to see if a week has been drawn to the calendar.  If 	*
		* it has been, then the drawing is bumped down a row to start 	*
		* the next week.						*
		*								*
		****************************************************************/

		if(($count) % 7 == 0 && $count > 0) {

			echo '</tr><tr>';

		}

		/****************************************************************
		*								*
		* Checking to see if this is the first day of the month.  If it	*
		* is, then the day or the week is checked and the appropriate 	*
		* number of days before the correct day are printed out.	*
		*								*		
		****************************************************************/

		if($q == 1) {

			$day = date("D", mktime(0, 0, 0, date("m", strtotime($myMonth)),'1',(int)$myYear));

			switch($day) {

				case "Sun":
				$spaces=0;
				break;

				case "Mon":
				$spaces=1;
				break;

				case "Tue":
				$spaces=2;
				break;

				case "Wed":
				$spaces=3;
				break;

				case "Thu":
				$spaces=4;
				break;

				case "Fri":
				$spaces=5;
				break;

				case "Sat":
				$spaces=6;
				break;

			}

			//writing number of blank days before 1st of month.

			for($z=0;$z<$spaces;$z++) {

				echo '<td width="20"><div align="center">   </div></td>';
				$count++;


			}

		} //done writing spaces



		//ADDING ADMIN FUNCTIONS

		if($this->get_mode() == "admin") {


		//checking to see if there are events for this day, if so write with link and 
		//highlighted green.

		if($calendarArray[$i] != 0) {

			//if day is TODAY, highlight in red

			if((int)date("d") == $q) {

			echo 	'<style type="text/css">
				A:link {text-decoration: none;color:black;}
				A:visited {text-decoration: none;color:black;}
				A:active {text-decoration: none}
				A:hover {color: white;}
				</style>

				<td width="20" style="background: #FF0000;border:1px solid #000000;" onMouseOver="this.style.background = \'blue\';document.all.day'.$q.'.style.color=\'white\';" onMouseOut="this.style.background = \'#0FFF00\';document.all.day'.$q.'.style.color=\'black\';"><div align="center" name="day'.$q.'" style="color: #000000; font-weight:bold;"><a href="getEvent.php?month='.$myMonth.'&day='.$q.'&year='.$myYear.'&num='.$calendarArray[$i].'">'. $q .'</a></div></td>';

			}		


			//else do not highlight

			else {	


			echo 	'<style type="text/css">
				A:link {text-decoration: none;color:black;}
				A:visited {text-decoration: none;color:black;}
				A:active {text-decoration: none}
				A:hover {color: red;}
				</style>

				<td width="20" style="background: #0FFF00;border:1px solid #000000;" onMouseOver="this.style.background = \'blue\';document.all.day'.$q.'.style.color=\'white\';" onMouseOut="this.style.background = \'#0FFF00\';document.all.day'.$q.'.style.color=\'black\';"><div align="center" name="day'.$q.'" style="color: #000000; font-weight:bold;"><a href="getEvent.php?month='.$myMonth.'&day='.$q.'&year='.$myYear.'&num='.$calendarArray[$i].'">'. $q .'</a></div></td>';

			}

			$count++;
		}


		//if no events, then write the day as normal.

		else {

			//if day is TODAY, highlight in red

			if((int)date("d") == $q) {

				echo 	'<td width="20" style="background: #FF0000;border:1px solid #000000;" onMouseOver="this.style.background = \'blue\';document.all.day'.$q.'.style.color=\'white\';"  onMouseOut="this.style.background = \'#FF0000\';document.all.day'.$q.'.style.color=\'black\';" onClick="a = confirm(\'Add Event?\');if(a) { alert(\'Yes\');}"><div align="center" name="day'.$q.'" style="color: #000000; font-weight: bold;">'.$q .'</div></td>';

			}

			//else do not highlight

			else {

				echo 	'<td width="20" style="background: #FFFFFF;border:1px solid #000000;" onMouseOver="this.style.background = \'blue\';document.all.day'.$q.'.style.color=\'white\';"  onMouseOut="this.style.background = \'#FFFFFF\';document.all.day'.$q.'.style.color=\'black\';" onClick="a = confirm(\'Add Event?\');if(a) { alert(\'Yes\');}"><div align="center" name="day'.$q.'" style="color: #000000; font-weight: bold;">'.$q .'</div></td>';

			}


			$count++;
		}


		} //END ADMIN 


		// NOT ADMIN!!

		else {


			//checking to see if there are events for this day, if so write with link and 
			//highlighted green.

			if($calendarArray[$i] != 0) {

				//if day is TODAY, highlight in red

				if((int)date("d") == $q) {

				echo 	'<style type="text/css">
					A:link {text-decoration: none;color:black;}
					A:visited {text-decoration: none;color:black;}
					A:active {text-decoration: none}
					A:hover {color: white;}
					</style>

					<td width="20" style="background: #FF0000;border:1px solid #000000;"><div align="center" name="day'.$q.'" style="color: #000000; font-weight:bold;"><a href="getEvent.php?month='.$myMonth.'&day='.$q.'&year='.$myYear.'&num='.$calendarArray[$i].'">'. $q .'</a></div></td>';

				}		


				//else do not highlight

				else {	


				echo 	'<style type="text/css">
					A:link {text-decoration: none;color:black;}
					A:visited {text-decoration: none;color:black;}
					A:active {text-decoration: none}
					A:hover {color: red;}
					</style>

					<td width="20" style="background: #0FFF00;border:1px solid #000000;"><div align="center" name="day'.$q.'" style="color: #000000; font-weight:bold;"><a href="getEvent.php?month='.$myMonth.'&day='.$q.'&year='.$myYear.'&num='.$calendarArray[$i].'">'. $q .'</a></div></td>';

				}

				$count++;
			}


			//if no events, then write the day as normal.

			else {

				//if day is TODAY, highlight in red

				if((int)date("d") == $q) {

					echo 	'<td width="20" style="background: #FF0000;border:1px solid #000000;"><div align="center" name="day'.$q.'" style="color: #000000; font-weight: bold;">'.$q .'</div></td>';

				}

				//else do not highlight

				else {

					echo 	'<td width="20" style="background: #FFFFFF;border:1px solid #000000;"><div align="center" name="day'.$q.'" style="color: #000000; font-weight: bold;">'.$q .'</div></td>';

				}


				$count++;
			}


		}// END NOT ADMIN




	} //end loop through calendarArray



		echo '</tr></table>';

} //end draw




//takes in a username and password and validates whether they are a registered user.

private function validUser($user,$pass) {

	$conn = mysql_connect("localhost","root","******") or die(mysql_error());
	$db = mysql_select_db("admin") or die(mysql_error());
	$query = "SELECT * from `main` where `User` = '$user' and `Pass` = '$pass'";
	$result = mysql_query($query) or die(mysql_error());
	$row = mysql_num_rows($result) or die(mysql_error());


	if($row == 1) {


		return true;

	}


	mysql_free_result($result);
	mysql_close($conn);

	return false;
}



//prepares to change year backward if previous month is December

public function getPrev($myMonth,$myYear) {

	if(date("F", mktime(0,0,0,date("m", strtotime($myMonth)),"-1",(int)$myYear)) == "December") {

		$q = (int)($myYear - 1);
		return $q;

	} 


	else {

	return (int)$myYear;

	}


}

//prepares to change year forward if next month is January

public function getNext($myMonth,$myYear,$days_in_month) {

	if(date("F", mktime(0,0,0,date("m", strtotime($myMonth)),$days_in_month+1,(int)$myYear)) == "January") {

		$q = (int)($myYear + 1);
		return $q;

	} 


	else {

	return (int)$myYear;

	}


}




}

?>

Link to comment
https://forums.phpfreaks.com/topic/39668-need-help-with-this-class-file/
Share on other sites

I made a couple of modifications to the code.

 

I changed !empty to isset in the set_mode() function.

 

I also added and else in the set_mode() function.

 

It now works the same for incorrect password of "" as it does for any other incorrect password.

 

Question is, what did I do wrong, and why is it printing a blank white screen when it's not in admin mode..

 

Heres the newer code:

<?php


session_start();

$_SESSION['user'] = "j";
$_SESSION['pass'] = "";


/****************************************
*					*
* Calendar class created to create a    *
* calendar system for holding events	*
* contained on each specified calendar	*
* day.  Each calendar object can access	*
* mysql database to pull in 		*
* Calendar_Event objects.  Calendar 	*
* class also has funtions designed to	*
* write the calendar to the screen, 	*
* as well as: add, edit, and delete 	*
* Calendar_Events.			*
*					*
* @author:	Josh Robison		*
* @date:	February 18, 2007	*
* @version:	1.0			*
*					*
****************************************/

class Calendar {


private $mode;
public $theDay;
public $theMonth;
public $theYear;

public function Calendar($Month,$Year) {

	//constructor.



		$theDay = date("d");
		$theMonth = $Month;
		$theYear = $Year;



	$this->set_mode();

	$this->draw($theDay,$theMonth,$theYear);


}



private function set_mode() {

	//takes in $_SESSION to check for valid Admin
	//if valid Admin, sets $mode to admin
	//else mode stays as user by default.

	if (isset($_SESSION['user']) && isset($_SESSION['pass'])) {


		if($this->validUser($_SESSION['user'],$_SESSION['pass'])) {

			$this->mode = "admin";


		}

		else {

			$this->mode = "user";

		}


	}




}



private function get_mode() {

	//returns private variable $mode

	return $this->mode;

}




/********************************************************
*							*
* Used to build the calendarArray and prepare it to be	*
* drawn to the screen.  If a day has an event, then the	*
* number of events for that day are added to.		*
*							*
********************************************************/

public function build($myMonth,$myYear) {

	//uses date() to get the day, month, and year.
	//builds a calendar array from this.
	//takes in mysql array from calendar database
	//iterates through new calendar array checking for days 
	//that match.


	$conn = mysql_connect("localhost","root","******") or die(mysql_error());
	$db = mysql_select_db("Calendar") or die(mysql_error());
	$query = "SELECT `Day` FROM `Events` WHERE `Month` = '$myMonth' and `Year` = '$myYear' ORDER BY `Day` ASC";
	$result = mysql_query($query) or die(mysql_error());
	$days_in_month = date('t', strtotime($myYear . '-' . $myMonth)); 
	$calendarArray = array($days_in_month);

		for($i=0;$i<$days_in_month;$i++) {

			$calendarArray[$i] = 0;


		}





	for($i=0;$i<$days_in_month;$i++) {

		$q = $i+1;


		for($z=0;$z<mysql_num_rows($result);$z++) {

			if($q == mysql_result($result, $z)) {


				 $calendarArray[$i]+=1;

			}	

		}

	}  

	return $calendarArray;      

}

/********************************************************
*							*
* Used to draw the calendar system to the screen.  	*		
* Highlights the days with events in green as well as 	*
* makes them links.  If in admin mode, all days without *
* events are highlighted in blue when moved over and 	*
* can be clicked on to add events to them.  The current	*
* day of the week is highlighted in red.		*	
*							*
********************************************************/

public function draw($myDay, $myMonth,$myYear)	{

	$days_in_month = date('t', strtotime($myYear . '-' . $myMonth)); 
	//draws the calendar to the screen

	echo '
	<table width="158" bgcolor="#FFFFFF" style="border: 1px solid #000000;">
  		<tr>

  		<td width="20"><div align="center"><a href="'.$_SERVER["PHP_SELF"].'?mo='. date("F", mktime(0,0,0,date("m", strtotime($myMonth)),"-1",(int)$myYear)) .'&yr='.$this->getPrev($myMonth,$myYear).'"><img src="left_arrow.JPG" border="0"></a></div></td>
    		<td width="20"><div align="center" style="font-size:12px; color: #000000; font-weight: bold;"><strong>'.$myMonth.' ' .$myYear. '</strong></div></td>
	<td width="20"><div align="center"><a href="'.$_SERVER["PHP_SELF"].'?mo='. date("F", mktime(0,0,0,date("m", strtotime($myMonth)),$days_in_month+1,(int)$myYear)).'&yr='.$this->getNext($myMonth,$myYear,$days_in_month).'"><img src="right_arrow.JPG" border="0"></a></div></td>
    
  		</tr>
	</table>

	<table width="158" bgcolor="#000066" style="border: 1px solid #FFFFFF;border-top:0px;">
  		<tr>

    		<td width="20"><div align="center"style=" color: #FFFFFF; font-weight: bold;">S</div></td>
    		<td width="20"><div align="center" style=" color: #FFFFFF; font-weight: bold;">M</div></td>
    		<td width="20"><div align="center" style=" color: #FFFFFF; font-weight: bold;">T</div></td>
    		<td width="20"><div align="center" style=" color: #FFFFFF; font-weight: bold;">W</div></td>
    		<td width="20"><div align="center" style=" color: #FFFFFF; font-weight: bold;">T</div></td>
    		<td width="20"><div align="center"style=" color: #FFFFFF; font-weight: bold;">F</div></td>
    		<td width="20"><div align="center" style=" color: #FFFFFF; font-weight: bold;">S</div></td>

	</tr>
	</table>

	<table width="158" bgcolor="#999999" style="border: 1px solid #000000;border-top:0px;"><tr>';

	$count = 0;

	$calendarArray = $this->build($myMonth,$myYear); //building calendarArray

	//pulling from array and beginning to iterate through it.

	for($i=0;$i<count($calendarArray);$i++) {

		$q = $i+1; //used to get the real day of the week, not the array number

		/****************************************************************
		*								*
		* Checks to see if a week has been drawn to the calendar.  If 	*
		* it has been, then the drawing is bumped down a row to start 	*
		* the next week.						*
		*								*
		****************************************************************/

		if(($count) % 7 == 0 && $count > 0) {

			echo '</tr><tr>';

		}

		/****************************************************************
		*								*
		* Checking to see if this is the first day of the month.  If it	*
		* is, then the day or the week is checked and the appropriate 	*
		* number of days before the correct day are printed out.	*
		*								*		
		****************************************************************/

		if($q == 1) {

			$day = date("D", mktime(0, 0, 0, date("m", strtotime($myMonth)),'1',(int)$myYear));

			switch($day) {

				case "Sun":
				$spaces=0;
				break;

				case "Mon":
				$spaces=1;
				break;

				case "Tue":
				$spaces=2;
				break;

				case "Wed":
				$spaces=3;
				break;

				case "Thu":
				$spaces=4;
				break;

				case "Fri":
				$spaces=5;
				break;

				case "Sat":
				$spaces=6;
				break;

			}

			//writing number of blank days before 1st of month.

			for($z=0;$z<$spaces;$z++) {

				echo '<td width="20"><div align="center">   </div></td>';
				$count++;


			}

		} //done writing spaces



		//ADDING ADMIN FUNCTIONS

		if($this->get_mode() == "admin") {


		//checking to see if there are events for this day, if so write with link and 
		//highlighted green.

		if($calendarArray[$i] != 0) {

			//if day is TODAY, highlight in red

			if((int)date("d") == $q) {

			echo 	'<style type="text/css">
				A:link {text-decoration: none;color:black;}
				A:visited {text-decoration: none;color:black;}
				A:active {text-decoration: none}
				A:hover {color: white;}
				</style>

				<td width="20" style="background: #FF0000;border:1px solid #000000;" onMouseOver="this.style.background = \'blue\';document.all.day'.$q.'.style.color=\'white\';" onMouseOut="this.style.background = \'#0FFF00\';document.all.day'.$q.'.style.color=\'black\';"><div align="center" name="day'.$q.'" style="color: #000000; font-weight:bold;"><a href="getEvent.php?month='.$myMonth.'&day='.$q.'&year='.$myYear.'&num='.$calendarArray[$i].'">'. $q .'</a></div></td>';

			}		


			//else do not highlight

			else {	


			echo 	'<style type="text/css">
				A:link {text-decoration: none;color:black;}
				A:visited {text-decoration: none;color:black;}
				A:active {text-decoration: none}
				A:hover {color: red;}
				</style>

				<td width="20" style="background: #0FFF00;border:1px solid #000000;" onMouseOver="this.style.background = \'blue\';document.all.day'.$q.'.style.color=\'white\';" onMouseOut="this.style.background = \'#0FFF00\';document.all.day'.$q.'.style.color=\'black\';"><div align="center" name="day'.$q.'" style="color: #000000; font-weight:bold;"><a href="getEvent.php?month='.$myMonth.'&day='.$q.'&year='.$myYear.'&num='.$calendarArray[$i].'">'. $q .'</a></div></td>';

			}

			$count++;
		}


		//if no events, then write the day as normal.

		else {

			//if day is TODAY, highlight in red

			if((int)date("d") == $q) {

				echo 	'<td width="20" style="background: #FF0000;border:1px solid #000000;" onMouseOver="this.style.background = \'blue\';document.all.day'.$q.'.style.color=\'white\';"  onMouseOut="this.style.background = \'#FF0000\';document.all.day'.$q.'.style.color=\'black\';" onClick="a = confirm(\'Add Event?\');if(a) { alert(\'Yes\');}"><div align="center" name="day'.$q.'" style="color: #000000; font-weight: bold;">'.$q .'</div></td>';

			}

			//else do not highlight

			else {

				echo 	'<td width="20" style="background: #FFFFFF;border:1px solid #000000;" onMouseOver="this.style.background = \'blue\';document.all.day'.$q.'.style.color=\'white\';"  onMouseOut="this.style.background = \'#FFFFFF\';document.all.day'.$q.'.style.color=\'black\';" onClick="a = confirm(\'Add Event?\');if(a) { alert(\'Yes\');}"><div align="center" name="day'.$q.'" style="color: #000000; font-weight: bold;">'.$q .'</div></td>';

			}


			$count++;
		}


		} //END ADMIN 


		// NOT ADMIN!!

		else {


			//checking to see if there are events for this day, if so write with link and 
			//highlighted green.

			if($calendarArray[$i] != 0) {

				//if day is TODAY, highlight in red

				if((int)date("d") == $q) {

				echo 	'<style type="text/css">
					A:link {text-decoration: none;color:black;}
					A:visited {text-decoration: none;color:black;}
					A:active {text-decoration: none}
					A:hover {color: white;}
					</style>

					<td width="20" style="background: #FF0000;border:1px solid #000000;"><div align="center" name="day'.$q.'" style="color: #000000; font-weight:bold;"><a href="getEvent.php?month='.$myMonth.'&day='.$q.'&year='.$myYear.'&num='.$calendarArray[$i].'">'. $q .'</a></div></td>';

				}		


				//else do not highlight

				else {	


				echo 	'<style type="text/css">
					A:link {text-decoration: none;color:black;}
					A:visited {text-decoration: none;color:black;}
					A:active {text-decoration: none}
					A:hover {color: red;}
					</style>

					<td width="20" style="background: #0FFF00;border:1px solid #000000;"><div align="center" name="day'.$q.'" style="color: #000000; font-weight:bold;"><a href="getEvent.php?month='.$myMonth.'&day='.$q.'&year='.$myYear.'&num='.$calendarArray[$i].'">'. $q .'</a></div></td>';

				}

				$count++;
			}


			//if no events, then write the day as normal.

			else {

				//if day is TODAY, highlight in red

				if((int)date("d") == $q) {

					echo 	'<td width="20" style="background: #FF0000;border:1px solid #000000;"><div align="center" name="day'.$q.'" style="color: #000000; font-weight: bold;">'.$q .'</div></td>';

				}

				//else do not highlight

				else {

					echo 	'<td width="20" style="background: #FFFFFF;border:1px solid #000000;"><div align="center" name="day'.$q.'" style="color: #000000; font-weight: bold;">'.$q .'</div></td>';

				}


				$count++;
			}


		}// END NOT ADMIN




	} //end loop through calendarArray



		echo '</tr></table>';

} //end draw




//takes in a username and password and validates whether they are a registered user.

private function validUser($user,$pass) {

	$conn = mysql_connect("localhost","root","******") or die(mysql_error());
	$db = mysql_select_db("admin") or die(mysql_error());
	$query = "SELECT * from `main` where `User` = '$user' and `Pass` = '$pass'";
	$result = mysql_query($query) or die(mysql_error());
	$row = mysql_num_rows($result) or die(mysql_error());


	if($row == 1) {

		mysql_free_result($result);
		mysql_close($conn);

		return true;

	}


	mysql_free_result($result);
	mysql_close($conn);

	return false;
}



//prepares to change year backward if previous month is December

public function getPrev($myMonth,$myYear) {

	if(date("F", mktime(0,0,0,date("m", strtotime($myMonth)),"-1",(int)$myYear)) == "December") {

		$q = (int)($myYear - 1);
		return $q;

	} 


	else {

	return (int)$myYear;

	}


}

//prepares to change year forward if next month is January

public function getNext($myMonth,$myYear,$days_in_month) {

	if(date("F", mktime(0,0,0,date("m", strtotime($myMonth)),$days_in_month+1,(int)$myYear)) == "January") {

		$q = (int)($myYear + 1);
		return $q;

	} 


	else {

	return (int)$myYear;

	}


}




}

?>

anyone that can help?

I have been up and down this code all night and day and I see nothing wrong...I even cleared everything from the else in correspondence to the if($this->get_mode() == "admin") and I put just a simple echo and it didn't even do that.

 

I am soooo confused what is wrong.

Alright so basically what I figured out is that when the password is incorrect, the else statement is never executed inside of set_mode() nor is the else executed towards the bottom that says that the mode is not set to admin.  I have looked this code up and down about 50 times and I see no reason why they are not correctly executing.  In all my years in coding I have never seen this happen.  Is there a bug in the new release of php5 or something?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.