<?php
require_once("../config/config.php");
$lead = mysqli_query($link1,"select  * from sf_lead_master where lid='".$_REQUEST['id']."'");
$lrow = mysqli_fetch_assoc($lead);
////// final submit form ////
@extract($_POST);
if($_POST['Submit']=='Save'){
	$folder="doc_attach/lead";
	///// attachment 
	if ($_FILES["visiting_card"]["size"]>2097152){
		$msgg="File size should be less than or equal to 2 mb";
		header("Location:lead_edit.php?msg=$msgg&sts=fail&page=lead");
	}
	else{ 
		$file_name = $_FILES['visiting_card']['name'];
		$file_tmp =$_FILES['visiting_card']['tmp_name'];
		$up=move_uploaded_file($file_tmp,"../".$folder."/".time().$file_name);
		$path1="../".$folder."/".time().$file_name;	
		$img_name1=time().$file_name;
		
		$res_q = mysqli_query($link1,"update sf_lead_master set partyid='".$party_id."', party_address='".cleanData($party_add)."', intial_remark='".$remark."', priority='".$priority."', vcard_url='".$path1."', sales_executive='".$designation."', dept_id='".$dept."', party_state='".$locationstate."', party_city='".$locationcity."', party_country='".$circle."', lead_source='".$source."', update_by='".$_SESSION['userid']."' where lid='".$lrow['lid']."'");
		if($res_q){	
                       $phone =mysqli_fetch_array(mysqli_query($link1,"select phone,empname from hrms_employe_master where empid = '".$dept."' "));
		
		       if($phone['phone']){
			$sms_msg="Dear ".$phone['empname'].", Lead  data is updated ".$reference." ";
			$res = file_get_contents("http://sms.foxxglove.com/api/mt/SendSMS?user=cancrm&password=123456&senderid=CANCRM&channel=Trans&DCS=0&flashsms=0&number=".$phone['phone']."&text=".urlencode($sms_msg));
			  }
			dailyActivity($_SESSION['userid'],$lrow['reference'],"LEAD","EDIT",$ip,$link1,"");
			//mysqli_query($link1,"insert into sf_status_history set party_id='".$party_id."', status_id='7', trans_type='add_lead', trans_no='".$lrow['reference']."'");
			include "lead_editmail.php";
			//$msgg="Lead is edited successfully with reference <font size='4'>".$lrow['reference']."</font>";
			//header("Location:lead_list.php?msg=$msgg&sts=success&page=lead".$pagenav);
		}
		else{
			$msgg="Request could not be processed";
			header("Location:lead_list.php?msg=$msgg&sts=fail&page=lead".$pagenav);
		}	
	}
}
?>

<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <title><?=siteTitle?></title>
 <script src="../js/jquery.min.js"></script>
 <link href="../css/font-awesome.min.css" rel="stylesheet">
 <link href="../css/abc.css" rel="stylesheet">
 <script src="../js/bootstrap.min.js"></script>
 <link href="../css/abc2.css" rel="stylesheet">
 <link rel="stylesheet" href="../css/bootstrap.min.css">
 <script>
	$(document).ready(function(){
        $("#frm1").validate();
    });
 </script>
 <script type="text/javascript" src="../js/jquery.validate.js"></script>
 <script language="javascript" type="text/javascript">
/////////// function to get state on the basis of circle
  $(document).ready(function(){
	$('#circle').change(function(){
	  var name=$('#circle').val();
	  $.ajax({
	    type:'post',
		url:'../includes/getAzaxFields.php',
		data:{circle:name},
		success:function(data){
	    $('#statediv').html(data);
	    }
	  });
    });
  });
 /////////// function to get city on the basis of state
 function get_citydiv(){
	  var name=$('#locationstate').val();
	  $.ajax({
	    type:'post',
		url:'../includes/getAzaxFields.php',
		data:{state:name},
		success:function(data){
	    $('#citydiv').html(data);
	    }
	  });
   
 }
  $(function() {
		$('.pop').on('click', function() {
			$('.imagepreview').attr('src', $(this).find('img').attr('src'));
			$('.imagepreview').css("width","auto");
			$('.imagepreview').css("height","auto");
			$('#imagemodal').modal('show');   
		});		
});
 </script>
<body>
<div class="container-fluid">
  <div class="row content">
	<?php 
    include("../includes/leftnav2.php");
    ?>
    <div class="col-sm-9">
      <h2 align="center"><i class="fa fa-child"></i> Edit Lead</h2><br/><br/>
      <?php if($_REQUEST['msg']!=''){?>
			<h4><span <?php if($_REQUEST['sts']=="success"){ echo "class='info-success' style='color: #090;'"; } if($_REQUEST['sts']=="fail"){ echo "class='info-fail' style='color:#FF0033'";}?>>
			<?php echo $_REQUEST['msg'];?>
			</span>
            </h4>
        <?php }?>
      <div class="form-group"  id="page-wrap" style="margin-left:10px;" >
          <form  name="frm1" id="frm1" class="form-horizontal" action="" method="post" enctype="multipart/form-data">
          <div class="form-group">
            <div class="col-md-6"><label class="col-md-6 control-label">Party Name(Customer) <span class="red_small">*</span></label>
              <div class="col-md-6">
                 <input type="text" autocomplete="off" id="basic_autocomplete_field" name="party_id" class="form-control entername" value="<?=$lrow["partyid"]?>"/>
              </div>
            </div>
            <div class="col-md-6"><label class="col-md-6 control-label">Sales Executive <span class="red_small">*</span></label>
              <div class="col-md-6">
               <select name="designation" class="form-control" id="designation" required>
               		<option value="">Select Sales Executive</option>
					<?php 
                    //$childNode = getChildNod($_SESSION["uid"]);
                    if($childNode){
                        $userList = $childNode.",'".$_SESSION["userid"]."'"; 
                    }else{
                        $userList = "'".$_SESSION["userid"]."'"; 
                    }
                    $sales=mysqli_query($link1,"select username,name from admin_users where username in (".$userList.") and status='active' order by name asc");
                    while($srow=mysqli_fetch_assoc($sales))
                    {
                    ?>
                    <option value="<?php echo $srow['username'];?>"<?php if($lrow['sales_executive']==$srow['username']){echo "selected='selected'";}?>><?php echo $srow['name'];?></option>
					<?php }?>
				</select>
              </div>
            </div>
          </div>
          <div class="form-group">
            <div class="col-md-6"><label class="col-md-6 control-label">Circle <span class="red_small">*</span></label>
              <div class="col-md-6">
                 <select name="circle" id="circle" class="form-control required" required>
                  <option value="">--Please Select--</option>
                  <option value="EAST"<?php if($lrow["party_country"]=="EAST"){ echo "selected";}?>>EAST</option>
                  <option value="NORTH"<?php if($lrow["party_country"]=="NORTH"){ echo "selected";}?>>NORTH</option>
                  <option value="SOUTH"<?php if($lrow["party_country"]=="SOUTH"){ echo "selected";}?>>SOUTH</option>
                  <option value="WEST"<?php if($lrow["party_country"]=="WEST"){ echo "selected";}?>>WEST</option>
                </select>           
              </div>
            </div>
            <div class="col-md-6"><label class="col-md-6 control-label">State <span class="red_small">*</span></label>
              <div class="col-md-6" id="statediv">
                <select name="locationstate" id="locationstate" class="form-control required" required>
                  <option value=''>--Please Select--</option>
                   <?php 
				 $state_query="select distinct(state) from state_master where zone='".$lrow["party_country"]."' order by state";
				 $state_res=mysqli_query($link1,$state_query);
				 while($row_res = mysqli_fetch_array($state_res)){?>
                   <option value="<?=$row_res["state"]?>"<?php if($lrow["party_state"]==$row_res["state"]){ echo "selected";}?>><?=$row_res['state']?></option>
	             <?php }?>
                
                </select>
              </div>
            </div>
          </div>
          
          <div class="form-group">
            <div class="col-md-6"><label class="col-md-6 control-label">City <span class="red_small">*</span></label>
              <div class="col-md-6" id="citydiv">
                <select name="locationcity" id="locationcity" class="form-control required" required>
               <option value=''>--Please Select-</option>
               <?php 
			     $city_query="SELECT distinct city FROM district_master where state='".$lrow["party_state"]."' order by city";
				 $city_res=mysqli_query($link1,$city_query);
				 while($row_city = mysqli_fetch_array($city_res)){?>
                   <option value="<?=$row_city["city"]?>"<?php if($lrow["party_city"]==$row_city["city"]){ echo "selected";}?>><?=$row_city['city']?></option>
	             <?php }?>
               </select> 
              </div>
            </div>
            <div class="col-md-6"><label class="col-md-6 control-label">Party Address <span class="red_small">*</span></label>
              <div class="col-md-6">
               <textarea name="party_add" id="party_add" class="form-control addressfield"><?php echo $lrow['party_address'];?></textarea>
              </div>
            </div>
          </div>
		  <div class="form-group">
            <div class="col-md-6"><label class="col-md-6 control-label">Priority <span class="red_small">*</span></label>
              <div class="col-md-6">
                <select name="priority" class="form-control" id="priority" required>
                	<option value="">Select Priority</option>                             
                    <option value="Cold"<?php if($lrow['priority']=='Cold'){echo "selected='selected'";}?>>Cold</option>
                    <option value="Warm"<?php if($lrow['priority']=='Warm'){echo "selected='selected'";}?>>Warm</option>
                    <option value="Hot"<?php if($lrow['priority']=='Hot'){echo "selected='selected'";}?>>Hot</option>
                </select>      
              </div>
            </div>
            <div class="col-md-6"><label class="col-md-6 control-label">Remark<span class="red_small">*</span></label>
              <div class="col-md-6">
              <textarea name="remark" id="remark" class="form-control addressfield"><?php echo $lrow['intial_remark'];?></textarea>
              </div>
            </div>
          </div>		 
		  <div class="form-group">
            <div class="col-md-6"><label class="col-md-6 control-label">Transfer To <span class="red_small">*</span></label>
              <div class="col-md-6">
                 <select name="dept" class="form-control" id="dept" required>
              		<option value="">Select </option>
              		<?php $dept=mysqli_query($link1,"select empname,empid  from hrms_employe_master where status='active'");while($drow=mysqli_fetch_assoc($dept)){?>
            		<option value="<?php echo $drow['empid'];?>"<?php if($drow['empid']==$lrow['dept_id']){echo "selected='selected'";}?>><?php echo ucwords($drow['empname']); ?></option>
            		<?php } ?>
             	</select> 
              </div>
            </div>
            <div class="col-md-6"><label class="col-md-6 control-label">Attach Visiting Card(Allowed jpg, png, gif, jpeg and Upload upto 2 MB)  <span class="red_small">*</span></label>
              <div class="col-md-6">
              <input type="file" class="form-control" name="visiting_card" id="visiting_card" accept="image/*"/>
              <div id="image-holder"></div>
              <?php if($lrow['vcard_url']!=''){?><br/><a href="#" class="pop">
    					<img src="<?php echo $lrow['vcard_url'];?>" style="width: auto; height: auto; display:none">
						<strong>Click To View Visiting Card</strong></a><?php } ?>
              </div>
            </div>
          </div>
		  <div class="form-group">
            <div class="col-md-6"><label class="col-md-6 control-label">Lead Source </label>
              <div class="col-md-6">
                <select name="source" class="form-control" id="source" required>
                	<option value="">Select Source</option>
                    <?php $source=mysqli_query($link1,"select * from sf_source_master");while($srow=mysqli_fetch_assoc($source)){?>
                    <option value="<?php echo $srow['id'];?>"<?php if($srow['id']==$lrow['lead_source']){echo "selected='selected'";}?>><?php echo ucwords($srow['source']); ?></option>
                    <?php } ?>
                </select> 
              </div>
            </div>
            <div class="col-md-6"><label class="col-md-6 control-label"></label>
              <div class="col-md-6">
              
              </div>
            </div>
          </div>
          <div class="form-group">
            <div class="col-md-12" align="center">
              <input type="submit" class="btn btn-primary" name="Submit" id="save" value="Save" title="" <?php if($_POST['Submit']=='Save'){?>disabled<?php }?>>
              <input title="Back" type="button" class="btn btn-primary" value="Back" onClick="window.location.href='lead_list.php?<?=$pagenav?>'">
            </div>
          </div>
    </form>
      </div><!--End form group-->
    </div><!--End col-sm-9-->
  </div><!--End row content-->
</div><!--End container fluid-->
<div class="modal fade" id="imagemodal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content" align="center">              
      <div class="modal-body">
      	<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <img src="" class="imagepreview" style="width: 100%;" >
      </div>
    </div>
  </div>
</div>
<?php
include("../includes/footer.php");
include("../includes/connection_close.php");
?>
</body>
</html>