<?php 
/********************************************************************************* 
 *  This file is part of Sentrifugo.
 *  Copyright (C) 2014 Sapplica
 *   
 *  Sentrifugo is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Sentrifugo is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Sentrifugo.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  Sentrifugo Support <support@sentrifugo.com>
 ********************************************************************************/
?>

<?php // Start :Condition to check whether organisation is created or not
    if($this->orgdata !='' && $this->orgdata == 'noorgdata'){?>
    <div class="ml-alert-1-info m1-info-set"><div class="style-1-icon info"></div>	
	 Organization information is not added yet.
			
</div>
<?php 
}else
{
	if(empty($this->datarr))
	{
		 if($this->configuremsg == 'notconfigurable' && $this->ermsg != 'nodata') { ?>
		<div class="ml-alert-1-info m1-info-set-2"><div class="style-1-icon info"></div>You cannot create a business unit as the site configuration is not yet set.</div>
	<?php }
	}
	 ?>

	<?php if($this->ermsg == 'nodata') { ?>
	<div class="ml-alert-1-info m1-info-set"><div class="style-1-icon info"></div>No data found.</div>
	<?php } else { ?>
	<?php sapp_Global::generateClientValidations($this->form);?>
	<?php if(isset($this->messages['msgtype']) && isset($this->messages['message']))
	{ ?>
		<div id="dispscreeningtype" class="settingssuccess">
			<?php 
					$flag = $this->messages['msgtype'];
					echo "<div id='messageData' class='ml-alert-1-$flag'><div style='display:block;'><span class='style-1-icon $flag'></span>";
					echo $this->messages['message'];
					echo "</div></div>";
			?>
		</div>	
		
	<?php } ?>
	<div class="total-form-controller">
	<div id="error_message" style="display:none;"></div>
	<form name="<?php echo $this->form->getName(); ?>" id="<?php echo $this->form->getId(); ?>" action="<?php echo $this->form->getAction();?>" method="<?php echo $this->form->getMethod(); ?>">
			<?php echo $this->form->id; ?>		  
				<div class="new-form-ui ">				  
				  <label class="required">Name</label>
				<div class="division"><?php echo $this->form->unitname; ?></div>
					<?php if(isset($this->msgarray['unitname'])){?>
					   <span class="errors" id="errors-<?php echo $this->form->unitname->getId(); ?>"><?php echo $this->msgarray['unitname'];?></span>
				  <?php }?>
				</div>
				
				<div class="new-form-ui">
				  <label class="required">Code <img class="tooltip" title="Example : DSTM, DST1, DS"  src="<?php echo $this->baseUrl().'/public/media/';?>images/help.png"></label>
				  
				<div class="division"><?php echo $this->form->unitcode; ?></div>	
					<?php if(isset($this->msgarray['unitcode'])){?>
					   <span class="errors" id="errors-<?php echo $this->form->unitcode->getId(); ?>"><?php echo $this->msgarray['unitcode'];?></span>
				  <?php }?>
				</div>
				
				<div class="new-form-ui textareaheight">
				  <label>Description</label>
				<div class="division"><?php echo $this->form->description; ?></div>
				</div>
							
				<div class="new-form-ui ">
				  <label>Started On <img title="<?php echo DATE_DESCRIPTION;?>" src="<?php echo $this->baseUrl().'/public/media/';?>images/help.png" /> </label>
				<div class="division"><?php echo $this->form->start_date;?></div>
					<?php if(isset($this->msgarray['start_date'])){?>
					   <span class="errors" id="errors-<?php echo $this->form->start_date->getId(); ?>"><?php echo $this->msgarray['start_date'];?></span>
				  <?php }?>
				</div>

				<div class="new-form-ui">
				  <label class="required">Time Zone</label>
				<div class="division"><?php echo $this->form->timezone; ?>
                					<?php if(isset($this->msgarray['timezone'])){?>
					   <span class="errors" id="errors-<?php echo $this->form->timezone->getId(); ?>"><?php echo $this->msgarray['timezone'];?></span>
				  <?php }?>

				<?php if(in_array('timezone',$this->popConfigPermission)){ ?>	
					<span class="add-coloum"  onclick="displaydeptform('<?php echo BASE_URL.'timezone/addpopup' ?>','Time zone');"> Add Time Zone </span>			
				<?php } ?>
				</div>
				</div>
				

				<div class="new-form-ui">
				  <label class="required">Country</label>
				<div class="division"><?php echo $this->form->country; ?>
					<?php if(isset($this->msgarray['country'])){?>
					   <span class="errors" id="errors-<?php echo $this->form->country->getId(); ?>"><?php echo $this->msgarray['country'];?></span>
				  <?php }?>
                
					<?php if(in_array('country',$this->popConfigPermission)) { ?>	
						<span class="add-coloum" onclick="displaydeptform('<?php echo BASE_URL.'countries/addpopup' ?>','Country');"> Add Country</span>			
					<?php } ?>
				</div>
				</div>
				
				<div class="new-form-ui container_left">
				  <label class="required">State</label>
				<div class="division"><?php echo $this->form->state; ?>
					<?php if(isset($this->msgarray['state'])){?>
					   <span class="errors" id="errors-<?php echo $this->form->state->getId(); ?>"><?php echo $this->msgarray['state'];?></span>
				  <?php } else {?>
					   <span class="errors" id="errors-<?php echo $this->form->state->getId(); ?>" style="display:none;"></span>
				  <?php }?>
                
					<?php if(in_array('state',$this->popConfigPermission)) { ?>	
						<span class="add-coloum" onclick="displaydeptform('<?php echo BASE_URL.'states/addpopup' ?>','State');"> Add State</span>			
					<?php } ?>
				</div>
				</div>
				
				<div class="new-form-ui container_left">
				  <label class="required">City</label>
				<div class="division"><?php echo $this->form->city; ?>
					<?php if(isset($this->msgarray['city'])){?>
					   <span class="errors" id="errors-<?php echo $this->form->city->getId(); ?>"><?php echo $this->msgarray['city'];?></span>
				  <?php } else {?>
				  <span class="errors" id="errors-<?php echo $this->form->city->getId(); ?>" style="display:none;"></span>
				  <?php }?>
					<?php if(in_array('city',$this->popConfigPermission)) { ?>	
						<span class="add-coloum" onclick="displaydeptform('<?php echo BASE_URL.'cities/addpopup' ?>','City');"> Add City</span>			
					<?php } ?>
				</div>
				</div>
				
				<div class="new-form-ui textareaheight">
				  <label class="required">Street Address 1</label>
				<div class="division"><?php echo $this->form->address1; ?></div>
					<?php if(isset($this->msgarray['address1'])){?>
					   <span class="errors" id="errors-<?php echo $this->form->address1->getId(); ?>"><?php echo $this->msgarray['address1'];?></span>
				  <?php }?>
				</div>
				
				<div class="new-form-ui textareaheight">
				  <label>Street Address 2</label>
				<div class="division"><?php echo $this->form->address2; ?></div>
				</div>
				
				<div class="new-form-ui textareaheight">
				  <label>Street Address 3</label>
				<div class="division"><?php echo $this->form->address3; ?></div>
				</div>						  			
			<div class="new-form-ui-submit">
			<?php echo $this->form->submit;
			if($this->deptData==0 && $this->unitid && $this->deptaddpermission == 'Yes') { ?>
			<input type="button" value="Add Department" onclick="displaydeptform('<?php echo BASE_URL;?>departments/editpopup/unitId/<?php echo $this->unitid;?>','');" id="createdept" name="createdept"/>
			<?php } ?>
			<button onclick="window.location.href='<?php echo BASE_URL;?>businessunits';" type="button" id="Cancel" name="Cancel">Cancel</button>
			</div>
	</form>
	 </div>
	<span id="error_message"></span>
	<?php 
	if($this->deptData>0) { 
	if($this->call == 'ajaxcall'){
		$div = ''; $endDiv = ''; 
	} else { 
		$div = '<div id="grid_'.$this->dataArray[0]['objectname'].'" class="all-grid-control">'; $endDiv = '</div>';
	}
		echo $div.'<div id="msg" style="display:none;font-style: oblique; font-weight: bold; color: green;""></div>'.$this->grid($this->dataArray[0]).$endDiv;
	}
	?>

	<div id="departmentsContainer"  style="display: none; overflow: auto;">
		<div class="heading">
			<a href="javascript:void(0)">
			<img src="<?php echo $this->baseUrl().'/public/media/';?>images/close.png" name="" align="right"
				border="0" hspace="3" vspace="5" class="closeAttachPopup"
				style="margin: -24px 8px 0 0;"> </a>
		</div>
			<iframe id="departmentsCont" class="business_units_iframe" frameborder="0"></iframe>
	</div>
	
	<div id="timezoneContainer"  style="display: none; overflow: auto;">
		<div class="heading">
			<a href="javascript:void(0)">
			<img src="<?php echo $this->baseUrl().'/public/media/';?>images/close.png" name="" align="right"
				border="0" hspace="3" vspace="5" class="closeAttachPopup"
				style="margin: -24px 8px 0 0;"> </a>
		</div>
			<iframe id="timezoneCont" class="business_units_iframe" frameborder="0"></iframe>
	</div>
	
	<div id="countriesContainer"  style="display: none; overflow: auto;">
		<div class="heading">
			<a href="javascript:void(0)">
			<img src="<?php echo $this->baseUrl().'/public/media/';?>images/close.png" name="" align="right"
				border="0" hspace="3" vspace="5" class="closeAttachPopup"
				style="margin: -24px 8px 0 0;"> </a>
		</div>
			<iframe id="countriesCont" class="business_units_iframe" frameborder="0"></iframe>
	</div>
	
	<div id="statesContainer"  style="display: none; overflow: auto;">
		<div class="heading">
			<a href="javascript:void(0)">
			<img src="<?php echo $this->baseUrl().'/public/media/';?>images/close.png" name="" align="right" border="0" hspace="3" vspace="5" class="closeAttachPopup" style="margin: -24px 8px 0 0;"> </a>
		</div>
		<iframe id="statesCont" class="business_units_iframe" frameborder="0"></iframe>
	</div>  

	<div id="citiesContainer"  style="display: none; overflow: auto;">
		<div class="heading">
			<a href="javascript:void(0)">
			<img src="<?php echo $this->baseUrl().'/public/media/';?>images/close.png" name="" align="right" border="0" hspace="3" vspace="5" class="closeAttachPopup" style="margin: -24px 8px 0 0;"> </a>
		</div>
		<iframe id="citiesCont" class="business_units_iframe" frameborder="0"></iframe>
	</div> 
	
	<script type='text/javascript'>
	$(document).ready(function(){
	var now = new Date();
	now.setDate(now.getDate()+1);
    var businessunitid = $('#id').val();
   // var yearrange = <?php echo "'".date("Y", strtotime("-50 years")).':'.(date('Y')+20)."'"; ?>;
   var yearrange = <?php echo "'".YEAR.':'.(date('Y')+5)."'"; ?>;
	$('#start_date').datepicker({
					showOn:'both',					
					yearRange: yearrange,
					dateFormat: '<?php echo DATEFORMAT_JS;?>',
					buttonImage: "<?php echo $this->baseUrl("public/media/images/cal.jpg");?>",
					buttonImageOnly: true,
					buttonText: "",
					changeMonth: true,
					changeYear: true,
                                        showButtonPanel: true ,
					onClose: function(){
					  
					  	$("#errors-start_date").remove();
					  validateorgstartdate(this,'businessunit',businessunitid);
					}
					
			});			
		});
	</script>
<?php }
}	// End :Condition to check whether organisation is created or not
?>