Sign in to follow this  
Followers 0
Iraklis

Charter System

3 posts in this topic

I have a problem....we are using a module from phpvms forum that our pilots can create charter flights.

Before the update of the tracker the system was working fine but now even when a pilot creates a flight and in the admin at Current Open Bids is ok the tracker does not see it.

with verison 1.0 of the tracker was working 100%.....

0

Share this post


Link to post
Share on other sites

 

Spoiler

 


<?php class CCFTracker extends CodonModule {
    
    public function index()
    {
        
        
        $allowcharter = '0';     // Set to 0 to not allow charter creation or 1 to allow charters.

        $connect_module_version = '2'; //DO NOT CHANGE THIS
        $revision = '3';              //DO NOT CHANGE THIS
        
        
        if(!$_SERVER['REQUEST_METHOD'] === 'POST')
		{ 
            echo "No Post Method";
            return;
        }
        
            $postText = file_get_contents('php://input');			
			$encoding = mb_detect_encoding($postText);
			$rec_xml = trim(iconv($encoding, "UTF-8", $postText));			
			$xml = simplexml_load_string($rec_xml);		
			
			if(!$xml)
			{
				echo "not valid xml file received!";
				return;	
			}
        
            $login = Auth::ProcessLogin($xml->PILOTID, $xml->PASSWORDD);		
					if ($login)
					{		
                        
                    $pilotid = PilotData::parsePilotID($xml->PILOTID);
					$pilotinfo = PilotData::getPilotData($pilotid);
                    
                    $pilotidfinal = PilotData::GetPilotCode($pilotinfo->code, $pilotinfo->pilotid);
                    
                        
                    $params = array();
                    $params['loginstatus']   	= "1";
					$params['statusmessage']	= "Logged In";
					$params['firstname'] 		= $pilotinfo->firstname;
					$params['lastname'] 		= $pilotinfo->lastname;
					$params['code']			    = $pilotinfo->code;
                    $params['pilotid']	        = $pilotinfo->pilotid;
                    $params['pilotidfinal']	    = $pilotidfinal;
                    $params['hub']			    = $pilotinfo->hub;
                    $params['totalflights']	    = $pilotinfo->totalflights;
                    $params['totalhours']	    = $pilotinfo->totalhours;
                    $params['rank']	            = $pilotinfo->rank;
                    $params['country']	        = Countries::getCountryName($pilotinfo->location);
                    $params['joindate']	        = date('Y-m-d', strtotime($pilotinfo->joindate));
                    $params['moduleversion']	= $connect_module_version;
					
                    if($allowcharter == '1')
                    {
                     $params['charters']	    = "true";
                    }
                    else
                    {
                     $params['charters']	    = "false";
                    }
                        
					$send = self::sendXML($params);
					}
					else
					{
                    $params = array();
                    $params['loginstatus']   	= "0";
                    $params['statusmessage']	= "Login Error! (Wrong pilotid or password)";
						
                    $send = self::sendXML($params);
					}

    
    }
    
    
    public function getflight()
    {
        if(!$_SERVER['REQUEST_METHOD'] === 'POST')
		{ 
            echo "No Post Method";
            return;
        }
        
            $postText = file_get_contents('php://input');			
			$encoding = mb_detect_encoding($postText);
			$rec_xml = trim(iconv($encoding, "UTF-8", $postText));			
			$xml = simplexml_load_string($rec_xml);		
			
			if(!$xml)
			{
				echo "not valid xml file received!";
				return;	
			}
        		
                    $pilotid = PilotData::parsePilotID($xml->PILOTID);
					$pilotinfo = PilotData::getPilotData($pilotid);
                        
                    $biddata = self::getLatestBid($pilotid);
					$aircraftinfo = OperationsData::getAircraftByReg($biddata->registration);
                    $dep = OperationsData::getAirportInfo($biddata->depicao);
                    $arr = OperationsData::getAirportInfo($biddata->arricao);
        
                    $pcrand = rand(60,100);
                        
                    if($biddata->flighttype == 'C')
                    {
                        $paxcargo = round(($aircraftinfo->maxcargo / 100) * $pcrand);
                    }
                        else
                    {
                        $paxcargo = round(($aircraftinfo->maxpax / 100) * $pcrand);
                    }
                        
                        
                    $params = array();
                        if($biddata)
                        { 
                    $params['successstatus']   	= "1";
					$params['statusmessage']	= "Flight Found!";
                        }
                        else
                        {
                    $params['successstatus']   	= "0";
                    $params['statusmessage']	= "No booked flights were found for your account!";     
                        }
					$params['flightnumber'] 	= $biddata->code.$biddata->flightnum;
                    $params['flcode'] 	        = $biddata->code;
                    $params['flflightnum'] 	    = $biddata->flightnum;
					$params['acregistration'] 	= $biddata->registration;
					$params['aircraftfullname'] = $aircraftinfo->fullname;
                    $params['flightlevel']	    = $biddata->flightlevel;
                    $params['depicao']	        = $biddata->depicao;
                    $params['arricao']		    = $biddata->arricao;
                    $params['route']	        = $biddata->route;
                    $params['deptime']	        = $biddata->deptime;
                    $params['arrtime']	        = $biddata->arrtime;
                    $params['flighttime']	    = $biddata->flighttime;
                    $params['flighttype']	    = $biddata->flighttype;
                    $params['notes']	        = $biddata->notes;
                    $params['paxcargo']	        = $paxcargo;
                    $params['deplat']	        = $dep->lat;
                    $params['deplng']	        = $dep->lng;
                    $params['arrlat']	        = $arr->lat;
                    $params['arrlng']	        = $arr->lng;
                    
                    
					$send = self::sendXML($params);
					
    }
    
    
    public function getflightbynum()
    {
        if(!$_SERVER['REQUEST_METHOD'] === 'POST')
		{ 
            echo "No Post Method";
            return;
        }
        
            $postText = file_get_contents('php://input');			
			$encoding = mb_detect_encoding($postText);
			$rec_xml = trim(iconv($encoding, "UTF-8", $postText));			
			$xml = simplexml_load_string($rec_xml);		
			
			if(!$xml)
			{
				echo "not valid xml file received!";
				return;	
			}
        		
                    $pilotid = PilotData::parsePilotID($xml->PILOTID);
					$pilotinfo = PilotData::getPilotData($pilotid);
                        
                   $flightinfo = SchedulesData::getProperFlightNum($xml->SEARCHFNUM);
					
					$params = array(
						's.code' => $flightinfo['code'],
						's.flightnum' => $flightinfo['flightnum'],
						's.enabled' => 1,
					);
					
					$biddata = SchedulesData::findSchedules($params, 1);
					$aircraftinfo = OperationsData::getAircraftByReg($biddata[0]->registration);
					
                        
                    $pcrand = rand(60,100);
                        
                    if($biddata[0]->flighttype == 'C')
                    {
                        $paxcargo = round(($aircraftinfo->maxcargo / 100) * $pcrand);
                    }
                        else
                    {
                        $paxcargo = round(($aircraftinfo->maxpax / 100) * $pcrand);
                    }
                        
                        
                    $params = array();
                        if($biddata)
                        { 
                    $params['successstatus']   	= "1";
					$params['statusmessage']	= "Flight Found!";
                        }
                        else
                        {
                    $params['successstatus']   	= "0";
                    $params['statusmessage']	= "No Flight found! Please make sure that you have entered the correct flightnumber.";     
                        }
					$params['flightnumber'] 	= $biddata[0]->code.$biddata[0]->flightnum;
                    $params['flcode'] 	        = $biddata[0]->code;
                    $params['flflightnum'] 	    = $biddata[0]->flightnum;
					$params['acregistration'] 	= $aircraftinfo->registration;
					$params['aircraftfullname'] = $aircraftinfo->fullname;
                    $params['flightlevel']	    = $biddata[0]->flightlevel;
                    $params['depicao']	        = $biddata[0]->depicao;
                    $params['arricao']		    = $biddata[0]->arricao;
                    $params['route']	        = $biddata[0]->route;
                    $params['deptime']	        = $biddata[0]->deptime;
                    $params['arrtime']	        = $biddata[0]->arrtime;
                    $params['flighttime']	    = $biddata[0]->flighttime;
                    $params['flighttype']	    = $biddata[0]->flighttype;
                    $params['notes']	        = $biddata[0]->notes;
                    $params['paxcargo']	        = $paxcargo;
                    
                    
					$send = self::sendXML($params);
					
    }
    
    
    public function getaircraft()
    {
        $login = Auth::ProcessLogin($this->post->PILOTID, $this->post->PASSWORD);	
        $pilotid = PilotData::parsePilotID($this->post->PILOTID);
		$pilotinfo = PilotData::getPilotData($pilotid);
        
        $xml = new SimpleXMLElement("<aircraftdata />");
		
		$info_xml = $xml->addChild('fleet');
        
        $status_xml = $xml->addChild('status');
					
        if ($login)
            {		
                        
        $results = self::getAircraftWithinRank($pilotinfo->ranklevel);
            if($results)
            { 
        $status_xml->addChild('successstatus', "1");
        $status_xml->addChild('statusmessage', "Success!");
            
		foreach($results as $row)
		{
            $aircraft_xml = $info_xml->addChild('aircraft');
            $aircraft_xml->addChild('acid', $row->id);
			$aircraft_xml->addChild('acicao', $row->icao);
			$aircraft_xml->addChild('acreg', $row->registration);
            $aircraft_xml->addChild('acdisp', $row->icao." - ".$row->registration);
		}
		
            }
            
             else
            
        {
             $status_xml->addChild('successstatus', "0");
             $status_xml->addChild('statusmessage', "No Aircraft found!");
        }

        }
        
        else
            
        {
             $status_xml->addChild('successstatus', "0");
             $status_xml->addChild('statusmessage', "Pilot Validation Error");
        }
        
        header('Content-type: text/xml');
		echo $xml->asXML();
        
    }
    
    
    public function createcharter()
    {
        $startcharternum = "9000";
        
        $login = Auth::ProcessLogin($this->post->PILOTID, $this->post->PASSWORD);	
        $params = array();
        
        if ($login)
        {		
             $pilotid = PilotData::parsePilotID($this->post->PILOTID);
             $pilotinfo = PilotData::getPilotData($pilotid);
             
            if (Config::Get('DISABLE_BIDS_ON_BID') == true && SchedulesData::getBids($pilotid)) {
            
                $params['successstatus']   	= "0";
                $params['statusmessage']	= "You have already booked another flight!";
              
        }
            else
            { 
            
             $code = $pilotinfo->code;
             $flightnum = self::getfreeflightnum($startcharternum, $code);
             $depicao = $this->post->DEPICAO;
             $arricao = $this->post->ARRICAO;
             $aircraft = $this->post->AIRCRAFT;
             $flightlevel = $this->post->FLIGHTLEVEL;
             $flighttime = $this->post->FLIGHTTIME;
             $route = $this->post->ROUTE;
             
             $f = explode(':', $flighttime);
             $deptime = date('H:i');
             $arrtime = date('H:i', strtotime("+ $f[0] hours $f[1] minutes"));
             $notes = "Charter created by CCFTracker";
             $daysofweek = "0123456";
             $price = "150";
             $flighttype = "H";
            
             $flighttime = str_replace(':', '.', $flighttime);
            
             $sql = "INSERT INTO ".TABLE_PREFIX."schedules (code, flightnum, depicao, arricao, aircraft, flightlevel, daysofweek, deptime, arrtime, flighttime, price, route, notes, flighttype, enabled) VALUES ('$code', '$flightnum', '$depicao', '$arricao', '$aircraft', '$flightlevel', '$daysofweek', '$deptime', '$arrtime', '$flighttime', '$price', '$route', '$notes', '$flighttype', '1')";
             DB::query($sql);
             $routeid = DB::$insert_id;
                
                self::addbid($routeid, $pilotid);
                
             $params['successstatus']   = "1";
             $params['statusmessage']	= "Charter Success";
            }
         }
        else
        {
             $params['successstatus']   	= "0";
             $params['statusmessage']	= "Pilot Validation Error!";
        }
        
        $send = self::sendXML($params);
    }
    
    public function addbid($routeid, $pilotid)
    {
        CodonEvent::Dispatch('bid_preadd', 'Schedules', $routeid);
        $ret = SchedulesData::AddBid($pilotid, $routeid);
        CodonEvent::Dispatch('bid_added', 'Schedules', $routeid);
    }
    
        public function getfreeflightnum($num, $code)
        {
            
            $sql = "SELECT flightnum FROM ".TABLE_PREFIX."schedules WHERE code = '$code' AND flightnum = '$num'";
            $result = DB::get_results($sql);
            
            if($result)
            {
                $num = $num + 1;
                return self::getfreeflightnum($num, $code);
            }
            else
            {
                return $num;
            }
            
        }
    
    public function getLatestBid($pilotid) {
        $pilotid = DB::escape($pilotid);
        $sql = 'SELECT s.*, b.bidid, a.id as aircraftid, a.name as aircraft, a.registration, a.maxpax, a.maxcargo
				FROM ' . TABLE_PREFIX . 'schedules s, 
					 ' . TABLE_PREFIX . 'bids b,
					 ' . TABLE_PREFIX . 'aircraft a
				WHERE b.routeid = s.id 
					AND b.aircraftid=a.id
					AND b.pilotid=' . $pilotid . '
				ORDER BY b.bidid DESC LIMIT 1';
        return DB::get_row($sql);
    }
    
    
    	public function sendXML($params)
	{
		$xml = new SimpleXMLElement("<sitedata />");
		
		$info_xml = $xml->addChild('info');
		foreach($params as $name => $value)
		{
			$info_xml->addChild($name, $value);
		}
		
		header('Content-type: text/xml'); 		
		$xml_string = $xml->asXML();
		echo $xml_string;
		
		return;	
	}
    
    
     public function posrep()
    {
        
        if(!$_SERVER['REQUEST_METHOD'] === 'POST')
		{ 
            echo "No Post Method";
            return;
        }
        
            $postText = file_get_contents('php://input');			
			$encoding = mb_detect_encoding($postText);
			$rec_xml = trim(iconv($encoding, "UTF-8", $postText));			
			$xml = simplexml_load_string($rec_xml);		
			
			if(!$xml)
			{
				echo "not valid xml file received!";
				return;	
			}
        
            $login = Auth::ProcessLogin($xml->pilotid, $xml->password);		
					if ($login)
					{
                        
                    $pilotid = PilotData::parsePilotID($xml->pilotid);
					$lat = str_replace(",", ".", $xml->latitude);
					$lon = str_replace(",", ".", $xml->longitude);
					
					# Get the distance remaining
					$depapt = OperationsData::GetAirportInfo($xml->depicao);
					$arrapt = OperationsData::GetAirportInfo($xml->arricao);
					$dist_remain = round(SchedulesData::distanceBetweenPoints(
						$lat, $lon,	$arrapt->lat, $arrapt->lng));
					
					# Estimate the time remaining
					if($xml->groundspeed > 0)
					{
						$Minutes = round($dist_remain / $xml->groundspeed * 60);
						$time_remain = self::ConvertMinutes2Hours($Minutes);
					}
					else
					{
						$time_remain = '00:00';
					}					
					
					$fields = array(
						'pilotid'        =>$pilotid,
						'flightnum'      =>$xml->flightnum,
						'pilotname'      =>$xml->pilotname,
						'aircraft'       =>$xml->aircraft,
						'lat'            =>$lat,
						'lng'            =>$lon,
						'heading'        =>$xml->heading,
						'alt'            =>$xml->altitude,
						'gs'             =>$xml->groundspeed,
						'depicao'        =>$xml->depicao,
						'arricao'        =>$xml->arricao,
						'deptime'        =>$xml->deptime,
						'arrtime'        =>'',
						'route'          =>$xml->route,
						'distremain'     =>$dist_remain,
						'timeremaining'  =>$time_remain,
						'phasedetail'    =>$xml->phasedetail,
						'online'         =>'',
						'client'         =>$xml->client,
						);
					
					
					ACARSData::UpdateFlightData($pilotid, $fields);	
                        
                    $params = array();
                    $params['successstatus']   = "1";
                    $params['statusmessage']	= "Position Report Success";
                        
					$send = self::sendXML($params);
					}
					else
					{
                    $params = array();
                    $params['successstatus']   = "0";
                    $params['statusmessage']	= "Position Report - Pilot Verification Error";
						
                    $send = self::sendXML($params);
					}

    
    }
    
    public function filepirep()
    {
        if(!$_SERVER['REQUEST_METHOD'] === 'POST')
		{ 
            echo "No Post Method";
            return;
        }
        
            $postText = file_get_contents('php://input');			
			$encoding = mb_detect_encoding($postText);
			$rec_xml = trim(iconv($encoding, "UTF-8", $postText));			
			$xml = simplexml_load_string($rec_xml);		
			
			if(!$xml)
			{
				echo "not valid xml file received!";
				return;	
			}
        
            $login = Auth::ProcessLogin($xml->pilotid, $xml->password);		
					if ($login)
					{
                        
                   $pilotid = PilotData::parsePilotID($xml->pilotid);
                  
                   $fllog = nl2br($xml->log);
                   $comments = nl2br($xml->comments);
				   $fllog = str_replace('\r\n', '*', $fllog);
                   $comments = str_replace('\r\n', '*', $comments);
                   $fllog = str_replace('\n', '*', $fllog);
                   $comments = str_replace('\n', '*', $comments);
                   $fllog = str_replace('\\n', '*', $fllog);
                   $comments = str_replace('\\n', '*', $comments);
                        
                        if(strlen($comments) < 10)
                        {
                            $comments = "";
                        }
                        
                        
					if(!OperationsData::GetAirportInfo($xml->depicao))
					{
						OperationsData::RetrieveAirportInfo($xml->depicao);
					}
					
					if(!OperationsData::GetAirportInfo($xml->arricao))
					{
						OperationsData::RetrieveAirportInfo($xml->arricao);
					}
											
					$fuelused = $xml->fuelused;
					
					if(Config::Get('LiquidUnit') == '1')
					{
						$fuelused = $fuelused * 6.84;
					}
	
					elseif(Config::Get('LiquidUnit') == '2')
					{
						$fuelused = $fuelused * .45359237;
					}			
					
					$aircraft = OperationsData::getAircraftByReg($xml->aircraft);
					
					$data = array(
						'pilotid'			=>$pilotid,
						'code'				=>$xml->code,
						'flightnum'			=>$xml->flightnum,
						'depicao'			=>$xml->depicao,
						'arricao'			=>$xml->arricao,
						'aircraft'			=>$aircraft->id,
						'flighttime'		=>$xml->flighttime,
						'flighttype'		=>$xml->flighttype,
						'submitdate'		=>'UTC_TIMESTAMP()',
						'comment'			=>$comments,
						'fuelused'			=>$fuelused,
						'route'          	=>$xml->route,
						'source'			=>$xml->client,
						'load'				=>$xml->load,
						'landingrate'		=>$xml->landingrate,
						'log'				=>$fllog
					);
					

					$result = ACARSData::FilePIREP($pilotid, $data);
                        
                    $params = array();
                    $params['successstatus']   = "1";
                    $params['statusmessage']	= "PIREP Filed!";
                        
					$send = self::sendXML($params);
					}
					else
					{
                    $params = array();
                    $params['successstatus']   = "0";
                    $params['statusmessage']	= "PIREP Report - Pilot Verification Error";
						
                    $send = self::sendXML($params);
					}
    }
    
    
    public static function getAircraftWithinRank($rank_level) {
        $sql = 'SELECT a.*, r.rank
				FROM ' . TABLE_PREFIX . 'aircraft a
				LEFT JOIN ' . TABLE_PREFIX . 'ranks r ON r.rankid=a.minrank
				WHERE a.ranklevel <= ' . $rank_level .' ORDER BY a.icao, a.registration';
        return DB::get_results($sql);
    }
    
    public function ConvertMinutes2Hours($Minutes)
	{
		if ($Minutes < 0)
		{
			$Min = Abs($Minutes);
		}
		else
		{
			$Min = $Minutes;
		}
		$iHours = Floor($Min / 60);
		$Minutes = ($Min - ($iHours * 60)) / 100;
		$tHours = $iHours + $Minutes;
		if ($Minutes < 0)
		{
			$tHours = $tHours * (-1);
		}
		$aHours = explode(".", $tHours);
		$iHours = $aHours[0];
		if (empty($aHours[1]))
		{
			$aHours[1] = "00";
		}
		$Minutes = $aHours[1];
		if (strlen($Minutes) < 2)
		{
			$Minutes = $Minutes ."0";
		}
		$tHours = $iHours .":". $Minutes;
		return $tHours;
	}
    
    
    public function recentflights()
    {
        $login = Auth::ProcessLogin($this->post->PILOTID, $this->post->PASSWORD);	
        $pilotid = PilotData::parsePilotID($this->post->PILOTID);
		$pilotinfo = PilotData::getPilotData($pilotid);
        
        $xml = new SimpleXMLElement("<recentflights />");
		
		        
        $status_xml = $xml->addChild('status');
					
        if ($login)
            {		
        $sql = "SELECT p.*, a.icao FROM ".TABLE_PREFIX."pireps p LEFT JOIN ".TABLE_PREFIX."aircraft a ON a.id = p.aircraft WHERE p.pilotid = '$pilotid' ORDER BY p.pirepid DESC LIMIT 5";   
        $results = DB::get_results($sql);
            if($results)
            { 
        $status_xml->addChild('successstatus', "1");
        $status_xml->addChild('statusmessage', "Success!");
            
		foreach($results as $row)
		{
            $flight_xml = $xml->addChild('flight');
            $flight_xml->addChild('Flightnum', $row->code.$row->flightnum);
			$flight_xml->addChild('From', $row->depicao);
			$flight_xml->addChild('To', $row->arricao);
            $flight_xml->addChild('Flighttime', $row->flighttime_stamp);
            $flight_xml->addChild('Aircraft', $row->icao);
            $flight_xml->addChild('Date', date('Y-m-d', strtotime($row->submitdate)));
		}
		
            }
            
             else
            
        {
             $status_xml->addChild('successstatus', "1");
             $status_xml->addChild('statusmessage', "No Flights found!");
        }

        }
        
        else
            
        {
             $status_xml->addChild('successstatus', "0");
             $status_xml->addChild('statusmessage', "Pilot Validation Error");
        }
        
        header('Content-type: text/xml');
		echo $xml->asXML();
    }
    
    
    public function getdeparrweather()
    {
        if(!$_SERVER['REQUEST_METHOD'] === 'POST')
		{ 
            echo "No Post Method";
            return;
        }
        
           
                    $pilotid = PilotData::parsePilotID($this->post->PILOTID);
					$pilotinfo = PilotData::getPilotData($pilotid);
                    
                        
                    
                        
                    $params = array();
                     
                    $params['successstatus']   	= "1";
					$params['statusmessage']	= "METARs Found!";
					$params['depmetar'] 	    = self::getmetarforicao($this->post->DEPICAO);
                    $params['arrmetar'] 	    = self::getmetarforicao($this->post->ARRICAO);
                    
                    
					$send = self::sendXML($params);
    }
    
    public function getweather()
    {
        if(!$_SERVER['REQUEST_METHOD'] === 'POST')
		{ 
            echo "No Post Method";
            return;
        }
        
           
                    $pilotid = PilotData::parsePilotID($this->post->PILOTID);
					$pilotinfo = PilotData::getPilotData($pilotid);
                    
                        
                    
                        
                    $params = array();
                     
                    $params['successstatus']   	= "1";
					$params['statusmessage']	= "METARs Found!";
					$params['reqmetar'] 	    = self::getmetarforicao($this->post->REQICAO);
                    
                    
					$send = self::sendXML($params);
    }
    
    
    public function getmetarforicao($icao)
    {
        $metar = self::get_data('http://metar.vatsim.net/metar.php?id='.$icao);
        return $metar;
    }
    
    
    public  function get_data($url) {
	$ch = curl_init();
	$timeout = 5;
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
	$data = curl_exec($ch);
	curl_close($ch);
	return $data;
}
    
    
    public function getchatmsg()
    {
         
        $login = Auth::ProcessLogin($this->post->PILOTID, $this->post->PASSWORD);	
        $pilotid = PilotData::parsePilotID($this->post->PILOTID);
		$pilotinfo = PilotData::getPilotData($pilotid);
        $now = date('Y-m-d H:i:s');
        
        $xml = new SimpleXMLElement("<chatdata />");
		$chatuser_xml = $xml->addChild('userlist');
        $chatmessages_xml = $xml->addChild('chatmessages');
        $status_xml = $xml->addChild('status');

					
        if ($login)
            {		
               
             $sessioncheck = self::checkchatsession($pilotid);
            
            if($sessioncheck)
            {
                self::updatesession($pilotid);
            }
            else
            {
                self::createsession($pilotid);
            }
            
            $status_xml->addChild('successstatus', "1");
            $status_xml->addChild('statusmessage', "Chat session created!"); 
            
            $results1 = self::getonlineuser();
            
            if($results1)
            { 
		    foreach($results1 as $row)
		    {
             $userpid = PilotData::GetPilotCode($row->code, $row->pilotid);
                
            $user_xml = $chatuser_xml->addChild('user');
            $user_xml->addChild('chatname', $userpid." ".$row->firstname." ".$row->lastname);
		    }
		
            }
            
            $results2 = self::getchatmessages();
            if($results2)
            { 
             
		    foreach($results2 as $row2)
		    {
            $userpid2 = PilotData::GetPilotCode($row2->code, $row2->pilotid);
            $message_xml = $chatmessages_xml->addChild('message');
            $message_xml->addChild('messageid', $row2->id);
            $message_xml->addChild('messagesender', "[".date('H:i', strtotime($row2->postdate))."] ".$userpid2." ".$row2->firstname." ".strtoupper($row2->lastname[0]).".");
            $message_xml->addChild('messagebody', utf8_decode($row2->message));
		    }
		
            }

        }
        else
        {
             $status_xml->addChild('successstatus', "0");
             $status_xml->addChild('statusmessage', "Couldnt start chatsession!");
        }
        
        header('Content-type: text/xml');
		echo $xml->asXML();
    }
    
    
    public function checkchatsession($pilotid)
    {
        $sql = "SELECT * FROM ccft_chatsessions WHERE pilotid = '$pilotid'";
        return DB::get_results($sql);
    }
    
    public function updatesession($pilotid)
    {
        $now = date('Y-m-d H:i:s');
        $sql = "UPDATE ccft_chatsessions SET logtime = '$now' WHERE pilotid = '$pilotid'";
        DB::query($sql);
    }
    
    public function createsession($pilotid)
    {
        $now = date('Y-m-d H:i:s');
        $sql = "INSERT INTO ccft_chatsessions (pilotid, logtime) VALUES('$pilotid', '$now')";
        DB::query($sql);
    }
    
    public function getonlineuser()
    {
        $sql = "SELECT s.*, p.code, p.pilotid, p.firstname, p.lastname FROM ccft_chatsessions s LEFT JOIN ".TABLE_PREFIX."pilots p ON s.pilotid = p.pilotid WHERE s.logtime > DATE_SUB(NOW(), INTERVAL 1 MINUTE) ORDER BY p.pilotid ASC";
   return DB::get_results($sql);
    }
    
    public function getchatmessages()
    {
        $sql = "SELECT m.*, p.code, p.pilotid, p.firstname, p.lastname FROM ccft_chatmessages m LEFT JOIN ".TABLE_PREFIX."pilots p ON m.	sentfrom = p.pilotid WHERE m.postdate > DATE_SUB(NOW(), INTERVAL 7 DAY) ORDER BY m.id ASC LIMIT 500";
   return DB::get_results($sql);
    }
    
    
    
    public function receivechatmsg()
    {
        $login = Auth::ProcessLogin($this->post->PILOTID, $this->post->PASSWORD);	
        $pilotid = PilotData::parsePilotID($this->post->PILOTID);
		$pilotinfo = PilotData::getPilotData($pilotid);

        $xml = new SimpleXMLElement("<chatdata />");
        $status_xml = $xml->addChild('status');

					
        if ($login)
            {	
            $status_xml->addChild('successstatus', "1");
            $status_xml->addChild('statusmessage', "Chat message sent!");
            
               $now = date('Y-m-d H:i:s');
               $message = DB::escape($this->post->CHATMSG);
               $message = utf8_encode($message);
               $sql = "INSERT INTO ccft_chatmessages (message, sentfrom, postdate) VALUES ('$message', '$pilotid', '$now')";
               DB::query($sql);
        }
        else
        {
             $status_xml->addChild('successstatus', "0");
             $status_xml->addChild('statusmessage', "Chat message send error!");
        }
        
        header('Content-type: text/xml');
		echo $xml->asXML();
    }
    
    
    
}
?>

 

 

0

Share this post


Link to post
Share on other sites

Hello Iraklis,

i see you made some changes to my CCFTracker Module.

Since i dont know the module you are using or its structure i probably wont be much of a help here. You should try to run the Database queries that you have changed directly in the SQL tab in phpmyadmin. That will tell you where the error is.

The client takes whatever flight it receives from the module so certainly the error must be somewhere in your modified database query.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0