<? global $vis_language;?>
<section id="breadcrumb" class="row m-b m-l-none m-r-none">
    <div class="col-sm-6">
        <h3 class="m-b-xs text-black"><? echo $vis_language['TXTCONTRACT']; ?></h3>
        <ul class="breadcrumb bg-empty no-border m-b-xxs no-padder">
            <li><a class="link" href="#/home/quick_view/<? echo $vis_language['TXTHOME']; ?>"><? echo $vis_language['TXTHOME']; ?></a></li>
            <li class="active"><a class="link" href="javascript:void(0);" onclick="$('#vis_workpanel_div').visExecution('load_module','<? echo $vis_language['TXTCONTRACT'];?>',{'vis_module':'<?=$operation['vis_module'];?>','vis_operation':'contract'});"><? echo $vis_language['TXTCONTRACT'];?></a></li>
            <li class="active"><? echo $vis_language['TXTUPDATECONTRACT'];?></li>
        </ul>
    </div>
</section>
<section class="padder">
    <section class="panel panel-default">
        <header class="panel-heading sub_header"><? echo $vis_language['TXTUPDATECONTRACT']; ?></header>
        <div class="panel-body">
            <form class="form-horizontal" role="form" id="vis_update_contract_form" name="vis_update_contract_form" method="post">
				<input type="hidden" name="vis_contract_id" id="vis_contract_id" value="<?=$contract_details['contract_id']?>">
				<div class="form-group">
					<label for="vis_firstname" class="col-sm-2 control-label"><? echo $vis_language['TXTNAME']; ?></label>
					<div class="col-sm-10">
						<input type="text" class="form-control input-sm" data-type="text" data-required="true" name="vis_name" id="vis_name" value="<?=$contract_details['name']?>">
					</div>
				</div>
				<div class="form-group">
					<label for="vis_lastname" class="col-sm-2 control-label"><? echo $vis_language['TXTSTATUS']; ?></label>
					<div class="col-sm-10">
						<select class="form-control selectpicker" name="vis_status" id="vis_status">
							<option value="0"><? echo $vis_language['TXTDRAFT']; ?></option>
						</select>
					</div>
				</div>
				<div class="form-group">
					<label for="vis_lastname" class="col-sm-2 control-label"><? echo $vis_language['TXTCONTRACTNUMBER']; ?></label>
					<div class="col-sm-10">
						<input type="text" class="form-control input-sm start" data-type="text" data-required="true" name="vis_contract_num" id="vis_contract_num" value="<?=$contract_details['contract_number']?>">
					</div>
				</div>
				<div class="form-group">
					<label for="vis_firstname" class="col-sm-2 control-label"><? echo $vis_language['TXTCONTRACTTYPE']; ?></label>
					<div class="col-sm-10">
						<select class="form-control selectpicker" name="vis_contract_type" id="vis_contract_type" <? if(count($contract_type_details)>10) echo ' data-live-search="true"';?>>
							<option value=""><? echo $vis_language['TXTSELECT']; ?></option>
						<? 	for($j=0;$j<count($contract_type_details);$j++){
								$selected = ($contract_details['type']==$contract_type_details[$j]['contract_type_id']) ? 'selected="selected"': '';
								echo '<option value="'.$contract_type_details[$j]['contract_type_id'].'" '.$selected.'>'.$contract_type_details[$j]['name'].'</option>';
							}
						?>
						</select>
					</div>
				</div>
				<div class="form-group">
					<label for="vis_firstname" class="col-sm-2 control-label"><? echo $vis_language['TXTPRODUCT']; ?></label>
					<div class="col-sm-10">
						<select class="form-control selectpicker" name="vis_product" id="vis_product" <? if(count($ci_product_details)>10) echo ' data-live-search="true"';?> onchange="change_product();">
							<option value=""><? echo $vis_language['TXTSELECT']; ?></option>
							<?
							for($j=0;$j<count($ci_product_details);$j++){
								$selected = ($contract_details['product']==$ci_product_details[$j]['product_id'])?'selected="selected"': '';
								echo '<option value="'.$ci_product_details[$j]['product_id'].'" '.$selected.'>'.$ci_product_details[$j]['name'].'</option>';
							}
							?>
						</select>
					</div>
				</div>

				<div class="form-group">
					<label for="vis_firstname" class="col-sm-2 control-label"><? echo $vis_language['TXTVENDOR']; ?></label>
					<div class="col-sm-10" id="vendor_list">
						<select class="form-control selectpicker" name="vis_vendor" id="vis_vendor" >
							<option value=""><? echo $vis_language['TXTSELECT']; ?></option>
						</select>
					</div>
				</div>

				<div class="form-group">
					<label for="vis_firstname" class="col-sm-2 control-label"><? echo $vis_language['TXTLICENSECOUNT']; ?></label>
					<div class="col-sm-10">
						<input type="text" class="form-control input-sm" data-type="text" data-required="true" name="vis_license_count" id="vis_license_count"  value="<?=$contract_details['license_count']?>">
					</div>
				</div>
				<div class="form-group">
					<label for="vis_firstname" class="col-sm-2 control-label"><? echo $vis_language['TXTLICENSETYPE']; ?></label>
					<div class="col-sm-10">
						<select class="form-control selectpicker" name="vis_license_type" id="vis_license_type" <? if(count($license_type_details)>10) echo ' data-live-search="true"';?>>
							<option value=""><? echo $vis_language['TXTSELECT']; ?></option>
						<?
							for($j=0;$j<count($license_type_details);$j++){
								$selected = ($contract_details['license_type']==$license_type_details[$j]['license_type_id']) ? 'selected="selected"': '';
								echo '<option value="'.$license_type_details[$j]['license_type_id'].'" '.$selected.'>'.$license_type_details[$j]['name'].'</option>';
							}
						?>
						</select>
					</div>
				</div>

				<div class="form-group">
					<label for="vis_firstname" class="col-sm-2 control-label"><? echo $vis_language['TXTCOST']; ?></label>
					<div class="col-sm-10">
						<input type="text" class="form-control input-sm" data-type="text" data-required="true" name="vis_cost" id="vis_cost"  value="<?=$contract_details['cost']?>">
					</div>
				</div>
				<div class="form-group">
					<label for="vis_firstname" class="col-sm-2 control-label"><? echo $vis_language['TXTDESCRIPTION']; ?></label>
					<div class="col-sm-10">
						<textarea name="vis_description" id="vis_description" class="form-control" rows="10"><?=stripcslashes($contract_details['description'])?></textarea>
					</div>
				</div>
				<div class="form-group">
					<label for="vis_firstname" class="col-sm-2 control-label"><? echo $vis_language['TXTATTACHCI']; ?></label>
					<div class="col-sm-10">
						<input type="text" class="form-control input-sm" data-type="text" data-required="true" name="vis_start_date" id="vis_start_date"  value="<?=date("m/d/Y",$contract_details['start_date'])?>">
					</div>
				</div>
				<div class="form-group">
					<label for="vis_firstname" class="col-sm-2 control-label"><? echo $vis_language['TXTATTACHFILE']; ?></label>
					<div class="col-sm-10">
						<input type="file" name="files[]" multiple="multiple" onchange="$(this).visExecution('upload_file', {'vis_static_area':'#vis_csv_attachments', 'vis_form':'vis_update_contract_form', 'vis_form_attachment_area':'#vis_attachments'})" class="filestyle" data-input="false" data-icon="true" data-classButton="btn btn-link link" data-iconName="vh-chat" data-buttonText="<?=$vis_language['TXTCHOOSEFILE']?>" data-badge="true"/><input type="hidden" name="vis_location" value="<? echo VIS_DOMAIN; ?>" />
						<input type="hidden" name="vis_attachments" id="vis_attachments" value="<?=$contract_details['attach_file']?>" />
						<input type="hidden" name="vis_parent_type" value="4" />
						<div id="vis_csv_attachments">
						<?php
							if($contract_details['attach_file']!=''){
								for($j=0;$j<count($contract_details['files']);$j++){
						?>
							<div class="btn-group wrapper-xxs">
								<span class="btn btn-xs alert-success"><?php echo $contract_details['files'][$j]['file_name'];?></span>
								<button onclick="$(this).parent().remove(); $(this).visExecution('load_operations', {'vis_module':'ticket', 'vis_operation':'remove_attachment', 'vis_attachment_id':<?php echo $contract_details['files'][$j]['attachment_id'];?>});vis_remove_attachment(<?php echo $contract_details['files'][$j]['attachment_id'];?>,'vis_attachments');" data-dismiss="alert" type="button" class="btn btn-xs alert-success"><i class="vh vh-cross"></i></button>
							</div>
						<?php }}?>
						</div>
					</div>
				</div>
				<div class="form-group">
					<label for="vis_firstname" class="col-sm-2 control-label"><? echo $vis_language['TXTSTARTDATE']; ?></label>
					<div class="col-sm-10">
						<input type="text" class="form-control input-sm from_date" data-type="text" data-required="true" name="vis_start_date" id="vis_start_date"  value="<?=date("m/d/Y",$contract_details['start_date'])?>">
					</div>
				</div>
				<div class="form-group">
					<label for="vis_firstname" class="col-sm-2 control-label"><? echo $vis_language['TXTENDDATE']; ?></label>
					<div class="col-sm-10">
						<input type="text" class="form-control input-sm from_date" data-type="text" data-required="true" name="vis_end_date" id="vis_end_date"   value="<?=date("m/d/Y",$contract_details['end_date'])?>">
					</div>
				</div>
				<div class="form-group">
					<label for="vis_firstname" class="col-sm-2 control-label"><? echo $vis_language['TXTNOTIFYEXPIRY']; ?></label>
					<div class="col-sm-10">
						<label class="checkbox-inline i-checks">
							<input type="checkbox" name="vis_notify_expiry" value="1" id="vis_notify_expiry" onchange="check_expiry();" <?php echo ($contract_details['if_notify_expiry']==1)? 'checked="checked"':'';?>><i></i>
     					</label>
					</div>
				</div>
				<div id="notify_expiry">
					<div class="form-group">
						<label for="vis_notify_before" class="col-sm-2 control-label"><? echo $vis_language['TXTNOTIFYBEFORE']; ?></label>
						<div class="col-sm-10">
							<select class="form-control selectpicker" name="vis_notify_before" id="vis_notify_before">
								<?php $notify_before = $contract_details['notify_before'];?>
								<option value="8" <? echo ($notify_before==8)?'selected="selected"':'';?>>8 <? echo $vis_language['TXTDAYS']; ?></option>
								<option value="30" <? echo ($notify_before==30)?'selected="selected"':'';?>>30 <? echo $vis_language['TXTDAYS']; ?></option>
								<option value="45" <? echo ($notify_before==45)?'selected="selected"':'';?>>45 <? echo $vis_language['TXTDAYS']; ?></option>
							</select>
						</div>
					</div>
					<div class="form-group">
						<label for="vis_firstname" class="col-sm-2 control-label"><? echo $vis_language['TXTNOTIFYTO']; ?></label>
						<div class="col-sm-10">
							<input type="text" class="form-control input-sm" data-type="text" data-required="true" name="vis_notify_to" id="vis_notify_to"  value="<?=$contract_details['notify_to']?>">
						</div>
					</div>
				</div>

            </form>

            <div class="b-2x b-t m-b-md"></div>
				<div class="col-sm col-sm-offset-2">
					<button type="button" class="btn btn-primary" onclick="$(this).visExecution('submit_form',{'vis_module':'<?=$operation['vis_module'];?>', 'vis_operation':'edit_contract', 'vis_form':'vis_update_contract_form'})"><? echo $vis_language['TXTUPDATE']; ?></button>
				</div> <br/>
			</div>
    </section>
</section>
<script src="<?= VIS_PATH_SCRIPT; ?>file-input/bootstrap-filestyle.min.js"></script>
<script>
	change_product();
	check_expiry();
	<? if (!defined('VIS_HTML_EDITOR') || VIS_HTML_EDITOR == 1) { ?>
	$(function() {
            $('#vis_description').redactor({
				buttonSource: true,
				minHeight: 180, // pixels
                maxHeight: 180,
                imageUpload: false,
                imageUploadParam: 'files',
				plugins: ['source'],
                deniedTags: ['html', 'head', 'link', 'body', 'meta', 'script','applet']
				
            });
			$(".redactor-toolbar").attr('z-index', '3 !important');
        });
    <?php }?>
	$(".selectpicker").selectpicker();
	$('.from_date').datetimepicker({format: "MM/DD/YYYY"});

	function change_product(){
		var data = {'vis_product_id':$("#vis_product").val(), 'vis_vendor_id': '<?=$contract_details['vendor']?>'};
		$.ajax({
			url: 'index.php?vis_module=<?=$operation['vis_module'];?>&vis_operation=change_vendor',
			data: data,
			type: "POST",
			dataType: "json",
			success: function(data) {
				$("#vendor_list").html(data.list);
			},
			error: function(xhr, ajaxOptions, thrownError) {$("#vis_global_msg_div").visInterface("load_global_message", "Error: "+xhr.status+" - "+thrownError);}
		});
	}
	function check_expiry(){
		if ($('#vis_notify_expiry').is(":checked"))$('#notify_expiry').show();
		else $('#notify_expiry').hide();
	}
	function vis_remove_attachment(ticket_id, attach_location){
		var loc = '';
		loc = (attach_location != "" && typeof(attach_location) != "undefined") ? attach_location : "vis_image_attachments";
		$("#" + loc).val( $("#" + loc).val().replace(ticket_id + ',', '') );
	}

	 $(document).ready(function () {
		$(":file").filestyle({input: false});
	 });
</script>
</section>
