<?php
class Azure extends Controller
{
	function Azure()
	{
		parent::Controller();
	}

  function status(){

			$Stop = false;
			$RefreshInterval = 1000;
			$ARCHlineShutdownTimeout = 600;
			$VmName = $this->uri->segment(3);
			$LastActivity = $this->uri->segment(4);
			$RdpPart = $this->uri->segment(5);

			$RdpFileBase64Decoded = "";
			if( $RdpPart != "Unknown" )
				$RdpFileBase64Decoded = base64_decode($RdpPart);

			$SessionID = $this->uri->segment(6);
			$CpuUsage = $this->uri->segment(7);
			$this->load->model('mclusers');
			$this->mclusers->update_VMStats($VmName, $RdpFileBase64Decoded, $LastActivity, $CpuUsage, $SessionID);
			$data = $this->mclusers->get_VMStats($VmName);
			
			
			print "<?xml version=\"1.0\" encoding=\"utf-16\"?>\n";
			print "<ServerData xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">";
			print "<VmName>$VmName</VmName>";
			print "<RefreshInterval>".$RefreshInterval."</RefreshInterval>";
			print "<MaxIdleTime>".$data['MaxIdleTime']."</MaxIdleTime>";
			print "<ARCHlineShutdownTimeout>".$ARCHlineShutdownTimeout."</ARCHlineShutdownTimeout>";
			print "<MaxUsingTime>".$data['MaxUsingTime']."</MaxUsingTime>";
			if( $Stop )
				print "<Stop>true</Stop>";
			else
				print "<Stop>false</Stop>";
			print "<SubscriptionName>".$data['SubscriptionName']."</SubscriptionName>";
			print "<StorageAccountName>".$data['StorageAccountName']."</StorageAccountName>";
			print "<ProgramID>".$data['UserName']."</ProgramID>";
			print "<SessionID>".$data['SessionID']."</SessionID>";
			print "<RoleSize>".$data['RoleSize']."</RoleSize>";
			print "</ServerData>";
  }
  function status_test(){
			$stop = $this->uri->segment(3);
			print "<?xml version=\"1.0\" encoding=\"utf-16\"?>\n";
			print "<ServerData xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">";
			print "<RefreshInterval>1000</RefreshInterval>";
			print "<MaxIdleTime>30</MaxIdleTime>";
			print "<Stop>".$stop."</Stop>";
			print "<SubscriptionName>12 - Month Plan</SubscriptionName>";
			print "<StorageAccountName>cadlinevirtualmachines</StorageAccountName>";
			print "</ServerData>";
  }
  }
  ?>