Your IP : 216.73.216.40


Current Path : /var/www/html/mmishra/iws8/html/iport/
Upload File :
Current File : /var/www/html/mmishra/iws8/html/iport/class.commuter.php

<?php

class iCommuter {
	var $con;
	var $dateCreation;
	var $dateUpdation;
	var $status;
	var $loginID = 'erp';

	//config variables
	var $kmRate;
	var $facultyEmail;
	var $officerEmail;
	var $staffEmail;
	var $autoEmail;
	var $mailRecipants;

	//requisition variables
	var $rowID;
	var $userID;
	var $purpose;
	var $boardingPlace;
	var $dateBoarding;
	var $reachingPlace;
	var $dateReaching;
	var $kmDistance;
	var $passengers;
	var $vehicleID;
	var $kmCharge;
	var $amount;
	var $tripSharing;
	var $remark;
		
	//school variables
	var $schoolID;
	var $classSection;
	var $wardName;
	var $gender;
	var $photograph;
	
	//timing variables
	var $timeOpen;
	var $timeClose;
	var $timeSpecial;
	var $dateStart;
	var $dateClose;
	var $dateFrom;
	
	//holiday variables
	var $reason;
	var $message;
	var $dated;

	//school variables
	var $schoolName;
	var $phoneNo;
	var $address;
	
	
	public function __construct() {
		//initialize variables
		if (!$this->dated) $this->dated = date('Y-m-d');
		if (!$this->dateBoarding) $this->dateBoarding = date('Y-m-d');
		if (!$this->dateReaching) $this->dateReaching = date('Y-m-d');
		if (!$this->dateStart) $this->dateStart = date('Y-m-d');
		if (!$this->dateClose) $this->dateClose = date('Y-m-d');
		if (!$this->dateCreation) $this->dateCreation = date('Y-m-d');
		if (!$this->dateUpdation) $this->dateUpdation =  date('Y-m-d', strtotime("+15 days"));
		if (!$this->status) $this->status = 'Present';
		if (!$this->loginID) $this->loginID = 'erp';

	        //connect database
		$this->con = mysql_connect('localhost', 'root', 'irp2015');
        if (!$this->con) die('Could not connect: ' . mysql_error());
		mysql_select_db('iport');
		$this->getSysconfig();
	}

	function getSysconfig() {
		$tbl = 't_sysconfig';
		$rs = mysql_query("select * from $tbl");
		if (mysql_num_rows($rs)) {
			$o = mysql_fetch_object($rs);
			$this->rowID = $o->rowID;
			$this->kmRate = $o->kmRate;
			$this->facultyEmail = $o->facultyEmail;
			$this->officerEmail = $o->officerEmail;
			$this->staffEmail = $o->staffEmail;
			$this->autoEmail = $o->autoEmail;
			$this->dateCreation = $o->dateCreation;
			$this->dateUpdation = $o->dateUpdation;
			$this->loginID = $o->loginID;
		}
		$this->mailRecipants = "$this->facultyEmail, $this->officerEmail, $this->staffEmail";
	}
	
	function relatedLinks() {
		$str = "<div align='right'>";
		if ($this->loginID) $str .= "Last change by: $this->loginID";
		else $str .= "Select to change record <i class='fa fa-arrow-circle-right' aria-hidden='true'></i>";
		$str .= "</div>
		[ <i class='fa fa-car' aria-hidden='true'></i> <a href='?pg=requisition'>Vehicle Requisition</a> ]
		[ <i class='fa fa-ban' aria-hidden='true'></i> <a href='?pg=cancellation'>Cancel Requisition</a> ]
		<br>
		[ <i class='fa fa-child' aria-hidden='true'></i> <a href='?pg=wregistration'>Ward Registration</a> ]
		[ <i class='fa fa-clock-o' aria-hidden='true'></i> <a href='?pg=schooltiming'>School Timings</a> ]
		[ <i class='fa fa-window-close-o' aria-hidden='true'></i> <a href='?pg=holidaynotice'>Holiday Notice</a> ]
		<br>
		[ <i class='fa fa-address-card-o' aria-hidden='true'></i> <a href='?pg=feedback'>Service Feedback</a> ]";
		
		return $str;
	}


	//*******************************save requisition*****************************//	
	function saveRequisition() {
		$tbl = 't_requisitions';
		//maintain record	
		if (mysql_num_rows(mysql_query("select * from $tbl where rowID=$this->rowID"))) {
			mysql_query("update $tbl set userID='$this->userID',purpose='$this->purpose',
			dateBoarding='$this->dateBoarding',boardingPlace='$this->boardingPlace',
			dateReaching='$this->dateReaching',reachingPlace='$this->reachingPlace',
			kmDistance=$this->kmDistance,passengers='$this->passengers',remark='$this->remark',
			loginID='$this->loginID' where rowID=$this->rowID");
		} else {
			mysql_query("insert into $tbl(userID,purpose,dateBoarding,boardingPlace,
			dateReaching,reachingPlace,kmDistance,passengers,remark,loginID)
			values('$this->userID','$this->purpose','$this->dateBoarding','$this->boardingPlace',
			'$this->dateReaching','$this->reachingPlace',$this->kmDistance,'$this->passengers',
			'$this->remark','$this->loginID')");
			$this->rowID = mysql_insert_id();
			}
	}

	function deleteRequisition() {
		$tbl = 't_requisitions';
		mysql_query("delete from $tbl where rowID=$this->rowID");
		$this->rowID = 0;
	}

	function mailRequisition($flag='Submit') {
		if ($this->autoEmail == 'No') return 0;
		
		$this->getRequisition();
		if ($flag == 'Submit')
			$msg = "A requisition in '$this->purpose' account for booking of a vehicle has been submitted by '$this->loginID' with following details:";
		else if ($flag == 'Delete')
			$msg = "A requisition in '$this->purpose' account for booking of a vehicle has been taken back by '$this->loginID' with following details:";				
		else if ($flag == 'Cancel')
			$msg = "A requisition in '$this->purpose' account for booking of a vehicle has been cancelled by '$this->loginID' with following details:";
		else
			$msg = 'Not clear';
		$msg .= "<dir>
		Boarding Place: $this->boardingPlace<br>
		Boarding Date/Time: $this->dateBoarding<br>
		Destination: $this->reachingPlace<br>
		Commuter/s: $this->passengers<br>
		</dir>
		For information and necessary action at department pl.";
				
		autoMailer($this->mailRecipants, "Vehicle Requisition", $msg);
	}
	
	function cancelRequisition() {
		$tbl = 't_requisitions';
		if (mysql_num_rows(mysql_query("select * from $tbl where rowID=$this->rowID"))) {
			mysql_query("update $tbl set remark='$this->remark',status='Cencelled',loginID='$this->loginID' 
			where rowID=$this->rowID");
		}
	}

	function getRequisition() {
		$tbl = 't_requisitions';
		$rs = mysql_query("select * from $tbl where rowID=$this->rowID");
		if (mysql_num_rows($rs)) {
			$o = mysql_fetch_object($rs);
		    $this->rowID = $o->rowID;
			$this->userID = $o->userID;
			$this->purpose = $o->purpose;
			$this->boardingPlace = $o->boardingPlace;
			$this->dateBoarding = $o->dateBoarding;
			$this->reachingPlace = $o->reachingPlace;
			$this->dateReaching = $o->dateReaching;
			$this->kmDistance = $o->kmDistance;
			$this->passengers = $o->passengers;
			$this->tripSharing = $o->tripSharing;
			$this->vehicleID = $o->vehicleID;
			$this->kmCharge = $o->kmCharge;
			$this->amount = $o->amount;
			$this->remark = $o->remark;
			$this->status = $o->status;
			$this->dateCreation = $o->dateCreation;
			$this->dateUpdation = $o->dateUpdation;
			$this->loginID = $o->loginID;
		}
	}

	function listRequisitions($user, $pg='') {
		$tbl = 't_requisitions';
		$rs = mysql_query("select * from $tbl where loginID='$user' and status<>'Performed' order by dateBoarding desc limit 0,5");
		if (mysql_num_rows($rs)) {
			while ($o = mysql_fetch_object($rs)) {
				if ($this->rowID == $o->rowID)
					$str .= "[ <b>$o->dateBoarding</b> ]";
				else
					$str .= "[ <a href='?pg=$pg&rowID=$o->rowID'>$o->dateBoarding</a> ]";
			}
		} else 
			$str = 'None';
		
		return $str;
	}

	function pendingRequisitions($pg='') {
		$tbl = 't_requisitions';
		$rs = mysql_query("select * from $tbl where loginID='$this->rowID' and status='Pending' order by dateBoarding");
		if (mysql_num_rows($rs)) {
			while ($o = mysql_fetch_object($rs)) {
				$str .= "[ <a href='?pg=$pg&rowID=$o->rowID'>$o->dateBoarding</a> ]";
			}
		} else 
			$str = 'None';
		
		return $str;
	}

	function personalRequisitions($pg) {
		$tbl = 't_requisitions';
		$rs = mysql_query("select * from $tbl where date(dateBoarding)<'" .date("Y-m-d"). "' and purpose='Personal' and status='Confirmed' order by dateBoarding");
		if (mysql_num_rows($rs)) {
			$str = '<ol>';
			while ($o = mysql_fetch_object($rs)) {
				$str .= '<li>';
				if ($this->rowID == $o->rowID) 
					$str .= "<font color='red'>$o->loginID [ $o->dateBoarding</a> ] 
					from $o->boardingPlace to $o->reachingPlace</font> [ Run: $o->kmCharge Km, 
					Bill Amount: <i class='fa fa-inr' aria-hidden='true'></i> $o->amount ]";
				else 
					$str .= "<a href='?pg=$pg&rowID=$o->rowID'>$o->loginID</a> [ $o->dateBoarding</a> ]
					from $o->boardingPlace to $o->reachingPlace";
				$str .= '</li>';
			}
			$str .= '</ol>';
		} else 
			$str = 'None';
		
		return $str;

	}

	function requisitionListing($user=0) {
		$tbl = 't_requisitions';
		$sql = "select t.*,v.vehicleID from $tbl as t,t_vehicles as v where t.vehicleID=v.rowID";
		if ($user) 
			$sql .= " and t.loginID='$this->loginID'";
		else 
			$sql .= " and t.rowID=$this->rowID";
		$sql .= " order by t.dateBoarding desc";
		
		$rs = mysql_query($sql);
		if (mysql_num_rows($rs)) {
			while ($o = mysql_fetch_object($rs)) {
				$i++;
				$str .= "[ #{$i} ] By $o->loginID<br>
				Purpose: $o->purpose, Passengers: $o->passengers, Status: $o->status<br>
                		Boarding Datetime: $o->dateBoarding, Boarding Place: $o->boardingPlace<br>
                		Destination Datetime: $o->dateReaching, Destination: $o->reachingPlace<br>
                		Distance: $o->kmDistance Km, Vehicle: $o->vehicleID, Trip Sharing: $o->tripSharing, 
				Run: $o->kmCharge Km, Bill Amount: <i class='fa fa-inr' aria-hidden='true'></i> 
				$o->amount<br>Remark: $o->remark<br><br>";
			}
		} else 
			$str = 'None';
		
		return $str;
	}

	function billedRequisitions($pg='') {
		$tbl = 't_requisitions';
		$rs = mysql_query("select t.*,v.vehicleID from $tbl as t,t_vehicles as v where t.vehicleID=v.rowID and t.amount>0 order by t.dateBoarding desc limit 0,10");
		if (mysql_num_rows($rs)) {
			$str = '<ol>';
			while ($o = mysql_fetch_object($rs)) {
				$str .= '<li>';
				if ($this->rowID == $o->rowID) 
					$str .= "<font color='red'>$o->loginID [ $o->dateBoarding</a> ] 
					from $o->boardingPlace to $o->reachingPlace</font> [ Vehicle: $o->vehicleID, 
					Run: $o->kmCharge Km, 
					Bill Amount: <i class='fa fa-inr' aria-hidden='true'></i> $o->amount ]";
				else
					$str .= "<a href='?pg=$pg&rowID=$o->rowID'>$o->loginID</a> [ $o->dateBoarding ]
					from $o->boardingPlace to $o->reachingPlace</font> [ Vehicle: $o->vehicleID,
					Run: $o->kmCharge Km, 
					Bill Amount: <i class='fa fa-inr' aria-hidden='true'></i> $o->amount ]";
				$str .= '</li>';
			}
			$str .= '</ol>';
		} else 
			$str = 'None';
		
		return $str;
	}

	//******************************ward registration************************************//
	function saveWard() {
		$tbl = 't_wards';
		//maintain record	
		if (mysql_num_rows(mysql_query("select * from $tbl where rowID=$this->rowID"))) {
			mysql_query("update $tbl set parentID='$this->parentID',schoolID=$this->schoolID,classSection='$this->classSection',wardName='$this->wardName',
			gender='$this->gender',".($this->photograph ? "photograph='$this->photograph'," : '')."loginID='$this->loginID'
			where rowID=$this->rowID");
		} else {
			mysql_query("insert into $tbl(parentID,schoolID,classSection,wardName,gender,photograph,loginID)
			values($this->parentID,$this->schoolID,'$this->classSection','$this->wardName','$this->gender','$this->photograph','$this->loginID')");
		}
	}

	function deleteWard() {
		$tbl = 't_wards';
		mysql_query("delete from $tbl where rowID=$this->rowID");
	}

	function mailWard($flag='Submit') {
		if ($autoEmail == 'No') return 0;
		
		$this->getWard();
		$this->getschool();
		
		if ($flag == 'Submit')
			$msg = "A ward has been registered by '$this->loginID' with following details:";
		else if ($flag == 'Delete')
			$msg = "A ward has been unregistered by '$this->loginID' with following details:";				
		else
			$msg = 'Not clear';
		$msg .= "<dir>
		Ward Name: $this->wardName<br>
		Class/Section: $this->classSection<br>
		Gender: $this->gender<br>
		School Name: $this->schoolName<br>
		</dir>
		For information and necessary action at department pl.";
				
		autoMailer($this->mailRecipants, "Ward Registration", $msg);
	}
	
	function getWard() {
		$tbl = 't_wards';
		$rs = mysql_query("select * from $tbl where rowID=$this->rowID");
		if (mysql_num_rows($rs)) {
			$o = mysql_fetch_object($rs);
	        $this->rowID = $o->rowID;
	        $this->parentID = $o->parentID;
	        $this->schoolID = $o->schoolID;
	        $this->classSection = $o->classSection;
	        $this->wardName = $o->wardName;
	        $this->gender = $o->gender;
	        $this->photograph = $o->photograph;
	        $this->dateCreation = $o->dateCreation;
	        $this->dateUpdation = $o->dateUpdation;
	        $this->loginID = $o->loginID;
		}
	}

	function getWardDetail() {
		$tbl = 't_wards';
      	$str = 'No record available';
		$rs = mysql_query("select * from $tbl where rowID=$this->wardID");
       	if (mysql_num_rows($rs)) {
        	$o = mysql_fetch_object($rs);
        	$str = "<img src='uploads/$o->photograph' width='50' height='50'> $o->wardName";
      	}
		return $str;
 	}

	function listWards($user, $pg='') {
		$tbl = 't_wards';
		$rs = mysql_query("select * from $tbl where loginID='$user' order by wardName");
		while ($o = mysql_fetch_object($rs)) {
			if ($this->rowID == $o->rowID)
				$str .= "[ <b>$o->wardName</b> <img src='uploads/$o->photograph' width='40' height='40'> ]";
			else
				$str .= "[ <a href='?pg=$pg&rowID=$o->rowID'>$o->wardName <img src='uploads/$o->photograph' width='40' height='40'></a> ]";
		}
		return $str;
	}

	//******************************school timings************************************//
	function saveSchoolTiming() {
		$tbl = 't_schooltimings';
		//maintain record	
		if (mysql_num_rows(mysql_query("select * from $tbl where rowID=$this->rowID"))) {
			mysql_query("update $tbl set wardID='$this->wardID',timeOpen='$this->timeOpen',
			timeClose='$this->timeClose',timeSpecial='$this->timeSpecial',dateFrom='$this->dateFrom',
			remark='$this->remark',loginID='$this->loginID' where rowID=$this->rowID");
		} else {
			mysql_query("insert into $tbl(wardID,timeOpen,timeClose,timeSpecial,dateFrom,remark,loginID)
			values('$this->wardID','$this->timeOpen','$this->timeClose','$this->timeSpecial','$this->dateFrom','$this->remark','$this->loginID')");
		}
	}

        
	function deleteSchoolTiming() {
		$tbl = 't_schooltimings';
		mysql_query("delete from $tbl where rowID=$this->rowID");
	}

	function mailSchoolTiming($flag='Submit') {
		if ($autoEmail == 'No') return 0;
		
		$this->getSchoolTiming();
		$this->rowID = $this->wardID;
		$this->getWard();
		$this->rowID = $this->schoolID;
		$this->getSchool();
		
		if ($flag == 'Submit')
			$msg = "New school timing has been submitted by '$this->loginID' with following details:";
		else if ($flag == 'Delete')
			$msg = "School timing has been deleted by '$this->loginID' with following details:";				
		else
			$msg = 'Not clear';
		$msg .= "<dir>
		Ward Name: $this->wardName<br>
		School Name: $this->schoolName<br>
		Open Time: $this->timeOpen<br>
		Close Time: $this->timeClose<br>
		WEF Date: $this->dateFrom
		</dir>
		For information and necessary action at department pl.";
				
		autoMailer($this->mailRecipants, "School Timings", $msg);
}

	function getSchoolTiming() {
		$tbl = 't_schooltimings';
		$rs = mysql_query("select * from $tbl where rowID=$this->rowID");
		if (mysql_num_rows($rs)) {
  		    $o = mysql_fetch_object($rs);
		    $this->rowID = $o->rowID;
		    $this->wardID = $o->wardID;
		    $this->timeOpen = $o->timeOpen;
		    $this->timeClose = $o->timeClose;
		    $this->timeSpecial = $o->timeSpecial;
		    $this->dateFrom = $o->dateFrom;
			$this->remark = $o->remark;
		    $this->dateCreation = $o->dateCreation;
		    $this->dateUpdation = $o->dateUpdation;
		    $this->loginID = $o->loginID;
		}
	}

	function listSchoolTimings($pg='') {
		$tbl = 't_schooltimings';
		$str = "<ol>";
		$rs = mysql_query("select * from $tbl order by dateUpdation desc");
		while ($o = mysql_fetch_object($rs)) {
			$str .= "<li> <a href='?pg=$pg&rowID=$o->rowID'>".$this->getWardDetail()."</a></li>";
		}
		$str .= "</ol>";
		return $str;
	}

	function displaySchoolTimings() {
		$tbl = 't_schooltimings';
		$rs = mysql_query("select * from $tbl order by dateUpdation desc");
		while ($o = mysql_fetch_object($rs)) {
			$i++;
			$this->wardID = $o->wardID;
			
			$str .= "[ #{$i} ] ". $this->getWardDetail(). " --- ". $this->getWardSchool(). "
			<dir><i class='fa fa-clock-o' aria-hidden='true'></i> Opens: $o->timeOpen, Closes: $o->timeClose from $o->dateFrom</dir>
			<div align='right'>Submitted by $o->loginID	, Dated: $o->dateUpdation<br></div>";
		}

		return $str;
	}
	
	function schoolTimingAlerts($pg='') {
		$tbl = 't_schooltimings';
		$rs = mysql_query("select t.*,w.schoolID from $tbl as t, t_wards as w where t.wardID=w.rowID order by dateFrom desc limit 0,5");
		while ($o = mysql_fetch_object($rs)) {
			$i++;
			$str .= "[ #{$i} ] By <a href='?pg=$pg&rowID=$o->rowID'>$o->loginID</a><br> 
			<i class='fa fa-clock-o' aria-hidden='true'></i> Dated: $o->dateCreation, School: ";
		 
			$this->rowID = $o->schoolID;
			$this->getSchool();
			$str .= $this->schoolName;
			$this->rowID = $o->rowID;

			$str .= "<br>Opens: $o->timeOpen, Closes: $o->timeClose from $o->dateFrom<br><br>";
		}

		return $str;
	}

	
	//******************************holiday notices************************************//
	function saveHolidayNotice() {
		$tbl = 't_holidays';
		//maintain record	
		if (mysql_num_rows(mysql_query("select * from $tbl where rowID=$this->rowID"))) {
			mysql_query("update $tbl set wardID='$this->wardID',dateStart='$this->dateStart',dateClose='$this->dateClose',reason='$this->reason',
			loginID='$this->loginID' where rowID=$this->rowID");
		} else {
			mysql_query("insert into $tbl(wardID,dateStart,dateClose,reason,loginID)
			values('$this->wardID','$this->dateStart','$this->dateClose','$this->reason','$this->loginID')");
		}
	}

	function deleteHolidayNotice() {
		$tbl = 't_holidays';
		mysql_query("delete from $tbl where rowID=$this->rowID");
	}

	function mailHolidayNotice($flag='Submit') {
		if ($autoEmail == 'No') return 0;
		
		$this->getHolidayNotice();
		$this->rowID = $this->wardID;
		$this->getWard();
		$this->rowID = $this->schoolID;
		$this->getSchool();
		
		if ($flag == 'Submit')
			$msg = "A school holiday notice has been submitted by '$this->loginID' with following details:";
		else if ($flag == 'Delete')
			$msg = "A school holiday notice has been deleted by '$this->loginID' with following details:";				
		else
			$msg = 'Not clear';
		$msg .= "<dir>
		Ward Name: $this->wardName<br>
		School Name: $this->schoolName<br>
		Start Date: $this->dateStart<br>
		Close Date: $this->dateClose<br>
		On Account: $this->reason<br>
		</dir>
		For information and necessary action at department pl.";
				
		autoMailer($this->mailRecipants, "School Holiday Notice", $msg);
}
	function getHolidayNotice() {
		$tbl = 't_holidays';
		$rs = mysql_query("select * from $tbl where rowID=$this->rowID");
		if (mysql_num_rows($rs)) {
			$o = mysql_fetch_object($rs);
	 	        $this->rowID = $o->rowID;
		        $this->wardID = $o->wardID;
			$this->dateStart = $o->dateStart;
		        $this->dateClose = $o->dateClose;
		        $this->reason = $o->reason;
			$this->dateCreation = $o->dateCreation;
		        $this->dateUpdation = $o->dateUpdation;
		        $this->loginID = $o->loginID;
		}
	}

	function listHolidayNotices($pg = '') {
		$tbl = 't_holidays';
		$str = "<ol>";
		$rs = mysql_query("select * from $tbl order by dateCreation desc");
		while ($o = mysql_fetch_object($rs)) {
			$str .= "<li><a href='?pg=$pg&rowID=$o->rowID'>".$this->getWardDetail($o->wardID)."</a></li>";
		}
		$str .= "</ol>";
		return $str;
	}
	

	//******************************commuter feedback************************************//
	function saveServiceFeedback() {
		$tbl = 't_feedbacks';
		//maintain record	
		if (mysql_num_rows(mysql_query("select * from $tbl where rowID=$this->rowID"))) {
			mysql_query("update $tbl set message='$this->message',
			loginID='$this->loginID' where rowID=$this->rowID");
		} else {
			mysql_query("insert into $tbl(message,loginID)
			values('$this->message','$this->loginID')");
		}
	}

	function deleteServiceFeedback() {
		$tbl = 't_feedbacks';
		mysql_query("delete from $tbl where rowID=$this->rowID");
	}

	function mailServiceFeedback($flag='Submit') {
		if ($autoEmail == 'No') return 0;
		
		$this->getServiceFeedback();
		
		$msg = "A feedback has been submitted by '$this->loginID' as below:
		<dir> $this->message </dir>
		For information and necessary action at department pl.";
				
		autoMailer($this->mailRecipants, "Transport Service Feedback", $msg);
	}
	
	function getServiceFeedback() {
		$tbl = 't_feedbacks';
		$rs = mysql_query("select * from $tbl where rowID=$this->rowID");
		if (mysql_num_rows($rs)) {
			$o = mysql_fetch_object($rs);
		    $this->rowID = $o->rowID;
		    $this->message = $o->message;
		    $this->dated = $o->dateCreation;
		}
	}

	function listServiceFeedbacks($pg='') {
		$tbl = 't_feedbacks';
		$rs = mysql_query("select * from $tbl where loginID='$this->loginID' order by dateCreation desc");
		while ($o = mysql_fetch_object($rs)) {
			$i++;
			$str .= "[ #{$i} ] Dated: $o->dateCreation</a> ]<br>$o->message<br><br>";
		}
		return $str;
	}

	
	//**********************school functions********************//
	function saveSchool() {
		$tbl = 't_schools';
		//maintain record	
		if (mysql_num_rows(mysql_query("select * from $tbl where rowID=$this->rowID"))) {
			mysql_query("update $tbl set schoolName='$this->schoolName',
			phoneNo=$this->phoneNo,address='$this->address',
			kmDistance=$this->kmDistance,".($this->photograph ? "photograph='$this->photograph'," : '')."
			loginID='$this->loginID' where rowID=$this->rowID");
		} else {
			mysql_query("insert into $tbl(schoolName,phoneNo,address,kmDistance,photograph,loginID)
			values('$this->schoolName',$this->phoneNo,'$this->address',$this->kmDistance,'$this->photograph','$this->loginID')");
		}
	}

	function deleteSchool() {
		$tbl = 't_schools';
		mysql_query("delete from $tbl where rowID=$this->rowID");
		$this->rowID = 0;
	}

	function getSchool() {
		$tbl = 't_schools';
		$rs = mysql_query("select * from $tbl where rowID=$this->rowID");
		if (mysql_num_rows($rs)) {
			$o = mysql_fetch_object($rs);
			$this->rowID = $o->rowID;
			$this->schoolName = $o->schoolName;
			$this->phoneNo = $o->phoneNo;
			$this->address = $o->address;
			$this->kmDistance = $o->kmDistance;
			$this->photograph = $o->photograph;
			$this->dateCreation = $o->dateCreation;
			$this->dateUpdation = $o->dateUpdation;
			$this->loginID = $o->loginID;
		}
	}
	
	function getSchoolDetail() {
		$tbl = 't_schools';
       	$str = 'No record available';
		$rs = mysql_query("select * from $tbl where rowID=$this->rowID");
       	if (mysql_num_rows($rs)) {
        	$o = mysql_fetch_object($rs);
        	$str = "$o->schoolName <img src='uploads/$o->photograph' width='50' height='50'>";
       	}
		
		return $str;
 	}

	function listSchools($pg='') {
		$tbl = 't_schools';
		$str = "<ol>";
		$rs = mysql_query("select * from $tbl order by schoolName");
		while ($o = mysql_fetch_object($rs)) {
			$str .= "<li>";
			if ($this->rowID == $o->rowID) 
				$str .= "<img src='uploads/$o->photograph' width='50' height='50'> <b>$o->schoolName</b>";
			else 
				$str .= "<img src='uploads/$o->photograph' width='50' height='50'> <a href='?pg=$pg&rowID=$o->rowID'>$o->schoolName</a>";
			$str .= "</li>";
		}
		$str .= "</ol>";

		return $str;
	}

	function selectSchool($pg) {
		$tbl = 't_schools';
		$str = "<select name='schoolID' style='width:150px'><option value=''></option>";

		$rs = mysql_query("select * from $tbl order by schoolName");
		while ($o = mysql_fetch_object($rs)) {
       		$str .= "<option value='$o->rowID'".($this->schoolID == $o->rowID ? ' selected' : '').">$o->schoolName</option>";
		}
		$str .= "</select>";
		
		return $str;
	}

	function getWardSchool() {
		$tbl = 't_schools';
       	$str = 'No record available';
		$rs = mysql_query("select * from $tbl where rowID=$this->wardID");
       	if (mysql_num_rows($rs)) {
        	$o = mysql_fetch_object($rs);
        	$str = "<img src='uploads/$o->photograph' width='50' height='50'> $o->schoolName";
       	}
		
		return $str;
 	}
	function displaySchools() {
		$tbl = 't_schools';
		$str = "<table width='90%' border='1' style='border-collapse: collapse;'>
		<tr><th>No.</th><th>School Name</th><th>Address</th><th>Contact</th><th>Distance</th></tr>";
		
		$rs = mysql_query("select * from $tbl order by schoolName");
		while ($o = mysql_fetch_object($rs)) {
			$i++;
			$str .= "<tr><td>$i</td>
			<td><img src='uploads/$o->photograph' width='50' height='50'> $o->schoolName</td>
			<td>$o->address</td><td>$o->phoneNo</td><td>$o->kmDistance Km</td></tr>";
		}
		$str .= "</table>";

		return $str;
	}
}


?>