<?php $this->load->view("partial/header"); ?>
<div id="page_title" style="color:#FF0000;"><?php echo anchor("employees/sales_details/".$this->Employee->get_logged_in_employee_info()->person_id."/width:1000","<font style='color#FF0000;'>Synchronization</font>",array('class'=>'thickbox','title'=>"NON Sync - Sales Details - ".date("d/m/Y")));?></div>
<?php
//echo form_open('config/save/',array('id'=>'config_form'));
echo form_open_multipart('dbbackup/periodic_sync/',array('id'=>'dbbackup_form'));
if(count($message)){
	if($message['success']==false){
?>
<div style="background-color:#FF0000;height:30px; font-weight:bold;text-align:center;color:#FFFFFF;font-size: 16px;">
<?php echo $message['message'];?>

</div>
<?php
	}
	else if($message['success']==true){

?>
<div style="background-color:#24BD06;height:30px; font-weight:bold;text-align:center;color:#000000;font-size: 16px;">
<?php echo $message['message'];?>

</div>
<?php
	}
}
?>

<div id="config_wrapper">
<fieldset id="dbbackup_info">
<legend></legend>

<?php /*
echo form_submit(array(
'name'=>'submit',
'id'=>'submit',
'value'=>$this->lang->line('common_submit'),
'class'=>'submit_button float_right')
);*/

echo'</br></br></br><a href="' . base_url('index.php/dbbackup/challan_sync') . '" onclick="return confirm(\'Are you sure to challan sync?\')">Sync Challan</a></br></br></br>';
echo'<a href="' . base_url('index.php/dbbackup/regular_sync_customer') . '" onclick="return confirm(\'Are you sure to regular sync?\')">Sync Regular</a></br></br></br>';
echo'<a href="' . base_url('index.php/dbbackup/periodic_sync') . '" onclick="return confirm(\'Are you sure to periodic sync?\')">Sync Periodic</a></br></br></br>';
echo'<a href="' . base_url('index.php/dbbackup/otp_sync') . '" onclick="return confirm(\'Are you sure to facebook group member OTP sync?\')">Facebook Group Member OTP</a></br></br></br>';




?>
</fieldset>
</div>


<?php

/* LIVE SERVER CORRECTION */


$ip = LIVE_SERVER_IP;
exec("ping -n 1 $ip", $output, $status);





if($status==0){

	$client = new SoapClient(LIVE_SERVER_PATH.'/services/services.php?wsdl', array('trace' => 1, 'exceptions' => 0));



	$api_data = array();
	$api_data['api_user'] = API_USER;
	$api_data['api_password'] = API_PASSWORD;
	$api_data['location_code'] =LOCATION_CODE;

	$api_data_final = json_encode($api_data);
	$result = $client->__soapCall('regularSyncLiveServerPermission', array('data' => $api_data_final));

	$error_found=json_decode($result)->error_found;
	$message=json_decode($result)->message;

	if($error_found==1){
		return 4;///Un-authorized Access.
	}else{
		$json_data=json_decode($result)->data;


		if(count($json_data)){

			$first_row=0;
			foreach ($json_data as $key => $value) {


				if($first_row==0){
					echo '<table style="text-align:center; width:100%;">
					<tr style="text-align:center;padding:8px;">
					<td style="text-align:center;padding:8px;">
					<font style="color:#97FF00;font-weight:bold;background-color: #008148; padding:4px;">Live Server Update</font>
					</td>
					</tr>';
					$first_row=1;
				}

				$permission_id=$value->id;
				$permission_date=$value->execution_date;
				$safe_string_to_store = base64_encode(serialize($permission_id));
				$safe_string_to_date = base64_encode(serialize($permission_date));
				$link=LOCAL_PATH."/pdf_report/mpdf60/server_permission_update.php?id=".$safe_string_to_store."&date=".$safe_string_to_date;
				if($value->is_update_local==0){
					echo '<tr style="text-align:center;padding:8px;">
				<td style="text-align:center;padding:8px;">
				<font style="color:#000000;font-weight:bold;padding:4px;background-color: #f2c6bb;"><a href="' . $link . '" target="_blank">'.date("dS-M-Y",strtotime($value->execution_date)).'</a></font>
				</td>
			</tr>';
				}else{
					echo '<tr style="text-align:center;padding:8px;">
				<td style="text-align:center;padding:8px;">
				<font style="color:#000000;font-weight:bold;padding:4px;background-color: #baecd6;"><a href="' . $link . '" target="_blank">'.date("dS-M-Y",strtotime($value->execution_date)).'</a></font>
				</td>
			</tr>';
				}

			}
			if($first_row==1){
				echo '</table>';
				echo'</br></br></br>';
			}

		}
	}
}else{

	echo '<table style="text-align:center; width:100%;">
	<tr style="text-align:center;padding:8px;">
	<td style="text-align:center;padding:8px;">
	<font style="color:#FF0000;font-weight:bold;padding:4px;">Internet Connection Problem</font>
	</td>
	</tr>';
	echo '</table>';
	echo'</br></br></br>';
}






?>







<?php
echo form_close();
?>

<div id="feedback_bar"></div>
<script type='text/javascript'>

//validation and submit handling
$(document).ready(function()
{
	$('#dbbackup_form').validate({
		submitHandler:function(form)
		{
			$(form).ajaxSubmit({
				success:function(response)
				{
					if(response.success)
					{
						set_feedback(response.message,'success_message',false);
					}
					else
					{
						set_feedback(response.message,'error_message',true);
					}
				},
				dataType:'json'
			});

		},
		errorLabelContainer: "#error_message_box",
		wrapper: "li",
		rules:
		{
			company: "required",
			address: "required",
			phone: "required",
			default_tax_rate:
			{
				required:true,
				number:true
			},
			email:"email",
			return_policy: "required"
		},
		messages:
		{
			company: "<?php echo $this->lang->line('config_company_required'); ?>",
			address: "<?php echo $this->lang->line('config_address_required'); ?>",
			phone: "<?php echo $this->lang->line('config_phone_required'); ?>",
			default_tax_rate:
			{
				required:"<?php echo $this->lang->line('config_default_tax_rate_required'); ?>",
				number:"<?php echo $this->lang->line('config_default_tax_rate_number'); ?>"
			},
			email: "<?php echo $this->lang->line('common_email_invalid_format'); ?>",
			return_policy:"<?php echo $this->lang->line('config_return_policy_required'); ?>"

		}
	});
});
</script>
<?php $this->load->view("partial/footer_sync_invoice"); ?>
