<? global $vis_language;?>
<link rel="stylesheet" type="text/css" href="<?= VIS_PATH_SCRIPT; ?>bootstrap-fileupload/bootstrap-fileupload.css" />
<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 $operation['view_title'];?></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><a class="link" href="#/setting/setting_menu/<? echo $vis_language['TXTSETTINGS'];?>" onclick="$('#vis_workpanel_div').visExecution('load_module','<? echo $vis_language['TXTSETTINGS']; ?>',{'vis_module':'setting','vis_operation':'setting_menu'});"><? echo $vis_language['TXTSETTINGS']; ?></a></li>
      <li><a class="link" href="#/setting/view_service_item/<? echo $vis_language['TXTSERVICEITEM']; ?>" onclick="$('#vis_workpanel_div').visExecution('load_module','<? echo $vis_language['TXTSERVICEITEM']; ?>',{'vis_module':'setting','vis_operation':'view_service_item'});" class="link"><? echo $operation['view_title']; ?></a> </li>
      <li class="active"><? echo $vis_language['TXTUPDATESERVICEITEM'];?></li>
    </ul>
  </div>
</section>
<section id="item_display" class="padder">
  <section class="panel panel-default">
    <header class="panel-heading sub_header"><? echo $vis_language['TXTUPDATESERVICEITEM']; ?></header>
    <div class="panel-body">
       <form class="form-horizontal" id="vis_service_item_form" name="vis_service_item_form" method="post" enctype="multipart/form-data" >
       <input class="form-control input-sm" type="hidden" name="vis_item_id" id="vis_item_id" value="<? echo $service_details['item_id']?>">
        <div class="form-group">
          <label class="col-sm-2 control-label"><? echo $vis_language['TXTNAME']; ?></label>
          <div class="col-sm-10">
            <input class="form-control input-sm" type="text" name="vis_name" id="vis_name" value="<? echo htmlentities($service_details['name'], ENT_COMPAT, 'UTF-8')?>">
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-2 control-label">
            <?= $vis_language['TXTSERVICECATEGORY']; ?>
          </label>
          <div class='col-sm-10'>
            <select class='form-control input-sm selectpicker' onchange="get_dept_list(this.value);" name="vis_category_id" id="vis_category_id" <? if(count($service_cat_details) > 10) echo 'data-live-search="true"' ?>>
              <option value="0">-- <? echo $vis_language['TXTSELECT']; ?> --</option>
              <? for($i=0;$i<count($service_cat_details);$i++){
				   if($service_details['category_id']==$service_cat_details[$i]['category_id'])
				      $chk='selected="selected"';
				   else
				   	  $chk='';
				   echo '<option '.$chk.' value="'.$service_cat_details[$i]['category_id'].'">'.$service_cat_details[$i]['name'].'</option>';
			  }
				   ?>
            </select>
          </div>
        </div>
		
		 <div class="form-group">
          <label class="col-sm-2 control-label">
            <?= $vis_language['TXTDEPARTMENT']?>
          </label>
          <div class='col-sm-10'  id="vis_dept_list">
            <select class='form-control input-sm <? if(!is_mobile()) echo 'selectpicker'; ?>' name="vis_domain_department" id="vis_domain_department" <? if(count($department_details) > 10) echo 'data-live-search="true"' ?>>
							<!--<option value="0">-- <? echo $vis_language['TXTSELECTDEPARTMENT']; ?> --</option>-->
							<? for($i=0;$i<count($department_details);$i++){
								if($service_details['item_department_id']==$department_details[$i]['department_id'])
				      $chk1='selected="selected"';
				   else
				   	  $chk1='';
							 echo '<option '.$chk1.' value="'.$department_details[$i]['department_id'].'">'.$department_details[$i]['department_name'].'</option>';	
							}?>
				</select>
          </div>
        </div>
		
        <!--<div class="form-group">
          <label class="col-sm-2 control-label">
            <?= $vis_language['TXTCIPRODUCT']; ?>
          </label>
          <div class='col-sm-10'>
            <select class='form-control input-sm selectpicker' name="vis_product_id" id="vis_product_id" <? if(count($product_detail) > 10) echo 'data-live-search="true"' ?>>
              <option value="0">-- <? echo $vis_language['TXTSELECT']; ?> --</option>
              <? for($i=0;$i<count($product_details);$i++){
				  if($service_details['ci_product_id']==$product_details[$i]['product_id'])
				      $chk='selected="selected"';
				   else
				   	  $chk='';
				   echo '<option '.$chk.' value="'.$product_details[$i]['product_id'].'">'.$product_details[$i]['name'].'</option>';
			  }?>
            </select>
          </div>
        </div>-->
        <div class="form-group">
          <label class="col-sm-2 control-label"><? echo $vis_language['TXTDESCRIPTION']; ?></label>
          <div class="col-sm-10">
            <textarea class="form-control input-sm" type="text" name="vis_description" id="vis_description" ><?php echo $service_details['description']; ?></textarea>
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-2 control-label"><? echo $vis_language['TXTCOST']; ?></label>
          <div class="col-sm-5">
            <input class="form-control input-sm" type="text" name="vis_cost" id="vis_cost" value="<?php echo $service_details['cost']; ?>">
          </div>
          <div class="form-group">
          <div class="col-sm-5">
          <div class="radio i-checks m-r-lg pull-left">
            <label><input <?php echo ($service_details['cost_status']==1)?'checked':''; ?> type="checkbox" name="vis_cost_visible" id="vis_cost_yes" />
            <i></i> <?php echo $vis_language['TXTVISIBLETOCLIENTPORTAL'];?></label>
            </div>
          </div>
        </div>
        </div>
        <div class="form-group">
          <label class="col-sm-2 control-label"><? echo $vis_language['TXTESTIMATEDDELIVERY']; ?></label>
          <div class="col-sm-3">
            <input class="form-control input-sm" type="text" name="vis_estimated_dlv" id="vis_estimated_dlv" value="<?php echo $service_details['estimated_delivery']; ?>" >
          </div>
		   <label class="col-sm-1 control-label"><? echo $vis_language['TXTHOURS']; ?></label>
          <div class="col-sm-1">
            
			<select class='form-control input-sm selectpicker' name="vis_estimated_hrs" id="vis_estimated_hrs"  data-live-search="true" >
              <? for($i=0;$i<24;$i++){ 
				  if($service_details['estimated_delivery_hrs']==$i)
				      $chk='selected="selected"';
				   else
				   	  $chk='';
				   echo '<option '.$chk.' value="'.$i.'">'.$i.'</option>';
			  }
				   ?>
            </select>
			
			
			
			
          </div>
          <div class="form-group">
          <div class="col-sm-5">
          <div class="radio i-checks m-r-lg pull-left">
            <label><input <?php echo ($service_details['estimate_status']==1)?'checked':''; ?> type="checkbox" name="vis_estimate_visible" id="vis_estimate_yes" />
            <i></i> <?php echo $vis_language['TXTVISIBLETOCLIENTPORTAL'];?></label>
            </div>
          </div>
        </div>
        </div>
         <div class="form-group">
           <label class="col-sm-2 control-label"><? echo $vis_language['TXTQUANTITY']; ?></label>
           <div class="col-sm-10">
            <div class="radio i-checks m-r-lg">
                <label><input <?php echo ($service_details['quantity_status']==1)?'checked':''; ?> type="checkbox" name="vis_quantity_visible" id="vis_estimate_yes" />
                <i></i> <?php echo $vis_language['TXTVISIBLETOCLIENTPORTAL'];?></label>
            </div>
          </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2"><?= $vis_language['TXTITEMIMAGE']; ?></label>
            <div class="col-sm-10">
                <div class="fileinput fileinput-new" data-provides="fileinput">
                    <div id="store_image" class="fileinput-new thumbnail" style="width: 200px; height: 150px;">
                <? if($service_details['item_image']!=''){?>
                        <img src="<? echo VIS_PATH_PROFILE.$service_details['item_image'];?>" title="Item Image" />
                <? }else{?>
                		<img src="<? echo VIS_PATH_PROFILE.'item_default.png';?>" title="Default" />
                <? }?>
                    </div>
                    <a class="close pull-right m-t-n-md fileinput-exists" data-dismiss="fileinput">&times;</a>
                    <div id="preview" class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 150px; line-height: 20px;"></div>

                    <div>
                     <span class="btn btn-white btn-file btn btn-link link">
                    <span class="fileinput-new"><? echo $vis_language['TXTSELECTIMAGE']; ?></span>
                     <span id="change" class="fileinput-exists"><? echo $vis_language['TXTCHANGE']; ?></span>
                     	<input type="file" onselect="show_image();" class="default" />
                     </span>
                       <!-- <a href="#" class="btn btn-danger fileinput-exists" data-dismiss="fileinput"><i class="fa fa-trash"></i> Remove</a>-->
                    </div>
                </div>
            </div>
        </div>
		 <div class="form-group">
          <label class="col-sm-2 control-label"><? echo $vis_language['TXTSTATUS']; ?></label>
          <div class="col-sm-2">
           <select class='form-control input-sm selectpicker' name="vis_status" id="vis_status" >
           		<option value="0"><?php echo $vis_language['TXTDRAFT'] ?></option>
                <option <?php echo ($service_details['status']==1)?'selected="selected"':''; ?> value="1"><?php echo $vis_language['TXTPUBLISHED'] ?></option>
           </select>
          </div>
        </div>
        <div class="line b-b line-lg pull-in"></div>
        <br/>
        <div class="form-group">
          <div class="col-sm-4 col-sm-offset-2">
            <button type="submit" class="btn btn-primary" onclick="uploadFiles();"><? echo $vis_language['TXTUPDATE']; ?></button>
          </div>
        </div>
      </form>
    </div>
  </section>
</section>
<div id="loading" class="h4 font-bold" style="margin-top:20%; text-align:center;font-weight:bold; display:none;"></div>
<!--<script src="<?= VIS_PATH_SCRIPT; ?>file-input/bootstrap-filestyle.min.js"></script>-->
<script type="text/javascript" src="<?= VIS_PATH_SCRIPT; ?>bootstrap-fileupload/bootstrap-fileupload.js"></script>
<script type="text/javascript">
function uploadFiles()
{
	$("#vis_service_item_form").submit(function(event){
 	var formdata= new FormData();
    $('#loading').html('Loading...').show();
	$('#item_display').hide();
	formdata.append("data", $('form').serialize());
    formdata.append("image", $('input[type=file]')[0].files[0]);

    event.stopImmediatePropagation();
//var formData = new FormData($('form')[0]);
    event.preventDefault();
  $.ajax({
    url: 'index.php?vis_module=setting&vis_operation=update_service_item',
    type: 'POST',
    data: formdata,
    async: false,
    cache: true,
    contentType: false,
    processData: false,
    success: function (returndata) {
		if(returndata==1){
		 $('#loading').html('Loading...').hide();
		 //$("#vis_global_msg_div").visInterface("load_global_message", " '<?= $vis_language['MSGSUCCOPRT'];?>'");
		 $("#vis_global_msg_div").visInterface("load_global_message", "<?= $vis_language['MSGSUCCOPRT'];?>");
		 $("#vis_workpanel_div").visExecution("load_module","<?=$vis_language['TXTSERVICEITEM'];?>",{"vis_module":"setting", "vis_operation":"view_service_item"});
		}else{
			$('#item_display').show();
			$('#loading').html('Loading...').hide();
			$("#vis_global_msg_div").visInterface("load_global_message", returndata);
		}
      //alert(returndata);
    }
  });

});
}

function toggle_dept_list(){
   if($('#vis_department_all').is(":checked")) $('#vis_dept_list_section').hide();
   else $('#vis_dept_list_section').show();
}
$(document).ready( function ready(){
	    category_id = document.getElementById('vis_category_id').value;
	   get_dept_list(category_id);
   });
  function get_dept_list(category_id){
	 
	   $.ajax({
            url: 'index.php',
            data: {'vis_module':"setting", 'vis_operation':"edit_service_item", 'vis_category_id':category_id ,'flag':1,'vis_action':"<?echo $operation['vis_action']; ?>"},
            type: "POST",
            dataType: "json",
            success: function(data) {
                   $("#vis_dept_list").html(data.depts);
                     // $("#vis_org_list").html(data.org);
                   // $(".selectpicker").selectpicker();
                 }
        });
        
    }
/*function remove_image(){
	$('.fileupload-preview').toggle();
	//$('.fileupload-new').toggle();
	$('input[type=file]').val('');
	//$('#change').toggle();
}
*/
/*function show_image(){
	alert('tejas');
	$('#store_image').html().hide();
	$('#preview').html().show();
	//$('input[type=file]').val('');
	//$('#change').toggle();
}*/
</script>
