<?php
session_start();
include ('sesssion_clear.php');
$companyname=$_SESSION['companyname'];
$adminemailid=$_SESSION['emailid'];
$cont_id=$_GET['cid'];
$page=$_GET['page'];
//if(($adminemailid !="")&&($companyname!="")){
require_once('../Control/address.php');
$objaddress=new addressctrl();
require_once('../Control/sales.php');
$objsales=new salesctrl();
require_once('../Control/contact.php');
$objcontact=new contactctrl();
$res_contact=$objsales->salesselectcontid("sales_contact",$cont_id);
foreach($res_contact as $row_contact){
$id=$row_contact['id'];
$cont_id=$row_contact['cont_id'];
$cont_name_title=$row_contact['cont_name_title'];
$cont_first_name=$row_contact['cont_first_name'];
$cont_last_name=$row_contact['cont_last_name'];
$cont_job_title=$row_contact['cont_job_title'];
$cont_address_line=$row_contact['cont_address_line'];
$cont_address_city=$row_contact['cont_address_city'];
$cont_address_state=$row_contact['cont_address_state'];
$cont_address_country=$row_contact['cont_address_country'];
$cont_address_pincode=$row_contact['cont_address_pincode'];
$cont_status=$row_contact['cont_status'];
$cont_tag=$row_contact['cont_tag'];
$cont_lead_source=$row_contact['cont_lead_source'];
$cont_background=$row_contact['cont_background'];
$cont_owner=$row_contact['cont_owner'];
$cont_make_private=$row_contact['cont_make_private'];
$cont_birthdate=$row_contact['cont_birthdate'];
$cont_star=$row_contact['cont_star'];
$cont_disabled_field=$row_contact['cont_disabled_field'];
$cont_imagepath=$row_contact['cont_imagepath'];
$cont_nastatus=$row_contact['cont_nastatus'];
$cont_na_closingcomment=$row_contact['cont_na_closingcomment'];
}
$res_org=$objsales->salesselectcontid("sales_organization",$cont_id);
foreach($res_org as $row_org){
$oid=$row_org['id'];
$org_id=$row_org['org_id'];
$cont_id=$row_org['cont_id'];
$org_name=$row_org['org_name'];
$org_desc=$row_org['org_desc'];
$org_phone=$row_org['org_phone'];
$org_url=$row_org['org_url'];
$org_add=$row_org['org_add'];
$org_city=$row_org['org_city'];
$org_state=$row_org['org_state'];
$org_country=$row_org['org_country'];
$org_pincode=$row_org['org_pincode'];
}

?>
<html>
    
    <head>
        
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="../../Bootstrap/css/bootstrap.min.css">
        <script src="../../Bootstrap/jquery.min.js"></script>
        <script src="../../Bootstrap/js/bootstrap.min.js"></script>
        <script src="../../Bootstrap/bootstrapAlert.js"></script>
        <link rel="stylesheet" href="../../font-awesome-4.7.0/css/font-awesome.min.css">
        
        <!-- FormValidation CSS file -->
        <link rel="stylesheet" href="../../Formvalidation/formValidation.min.css">
        <!-- FormValidation plugin and the class supports validating Bootstrap form -->
        <script src="../../Formvalidation/formValidation.min.js"></script>
        <script src="../../Formvalidation/framework.min.js"></script>
        <!-- Edit Select Picker -->
        <script src="../../Editablepicker/jquery-editable-select.min.js"></script>
        <link href="../../Editablepicker/jquery-editable-select.min.css" rel="stylesheet">
        <!-- Select Picker -->
        <script src="../../Selectpicker/bootstrap-select.js"></script>
        <link href="../../Selectpicker/bootstrap-select.min.css" rel="stylesheet">
        <!-- Date Picker -->
        <link rel="stylesheet" href="../../Datepicker/jquery-ui.css">
        <script src="../../Datepicker/jquery-ui.js"></script>
        <!-- SweetAlert -->
        <link rel="stylesheet" href="../../SweetAlert/sweetalert.css">
        <link rel="stylesheet" href="../../SweetAlert/sweetalert.min.css.map">
        <script src="../../SweetAlert/sweetalert.js"></script>



<script>
$(function(){
    var newdate = new Date();

    newdate.setDate(newdate.getYear() - 20); // minus the date
    
    var date1=newdate.getFullYear() + "-" +(newdate.getMonth()+1) + "-" +newdate.getDate();
    //alert(date1);

    $('#cont_birthday').datepicker({
        dateFormat: 'yy-mm-dd',
        changeMonth: true,
        changeYear: true,
        setDate: date1,
        numberOfMonths: 1,
        showButtonPanel: true,
        closeText: 'Clear',
        onClose: function (dateText, obj) {
            if ($(window.event.srcElement).hasClass('ui-datepicker-close'))
                $("#cont_birthday").val('');
        }
}); 
});

 
 </script>
    </head>
    
    <body>
        
        <script>
            $(document).on("click", "#hidecontacttext", function(){
                $("#showcontacttext").show();
                $("#hidecontacttext").hide();
                $("#showorgtext").hide();
                $("#hideorgtext").show();
                $("#contactfield").show();
                $("#orgfield").hide();
            });
            $(document).on("click", "#hideorgtext", function(){
                $("#showcontacttext").hide();
                $("#hidecontacttext").show();
                $("#showorgtext").show();
                $("#hideorgtext").hide();
                $("#contactfield").hide();
                $("#orgfield").show();
            });
        </script>
        <div class="row">
            
            
                
            <div class="col-sm-9">
                <form >
                    <div class="add_header">
                        <span id="showcontacttext" style="cursor:pointer;border-bottom:2px solid blue;padding:10px 50px 20px 20px;font-size:15px;"><b>Contact Info</b></span> 
                        <span id="hidecontacttext" style="cursor:pointer;color:blue;display:none;padding:10px 50px 20px 20px;font-size:15px;"><b>Contact Info</b></span>
                        <span id="showorgtext" style="cursor:pointer;border-bottom:2px solid blue;display:none;padding:10px 50px 20px 20px;font-size:15px;"><b>Organization Info</b></span> 
                        <span id="hideorgtext" style="cursor:pointer;color:blue;padding:10px 50px 20px 20px;font-size:15px;"><b>Organization Info</b></span>    
                        
                        <span class="pull-right">
                            <a style="cursor:pointer;padding:10px;" onclick="funccancel()">Cancel</a>
                            <input type="button" class="btn btn-primary" id="updatecontact" value="Update" name="Save">
                        </span>
                    </div>
                    <hr>
                    
<script>
    function funccancel(){
        var page="<?php echo $page;?>";
        window.location.replace(page);
    }
</script>                    
<script>
    
$(document).on("click", "#updatecontact", function() {
    var cont_id="<?php echo $cont_id;?>";
    var oid="<?php echo $oid;?>";
    var firstname=$("#cont_first_name").val();
    var lastname=$("#cont_last_name").val();
    var cont_organization=$("#cont_organization").val();
    if((lastname=="")&&(cont_organization=="")){
        swal("", "Fill the Last Name or Organization", "warning");
        return;
    }else{
        var cont_title=$("#cont_title").val();
        var cont_job_title=$("#cont_job_title").val();
        var cont_phone_number=$("input[name='cont_phone_number[]']").map(function(){return $(this).val();}).get();
        var cont_phone_type=$("select[name='cont_phone_type[]']").map(function(){return $(this).val();}).get();
        var cont_email_name=$("input[name='cont_email_name[]']").map(function(){return $(this).val();}).get();
        var cont_email_type=$("select[name='cont_email_type[]']").map(function(){return $(this).val();}).get();
        var cont_url_name=$("input[name='cont_url_name[]']").map(function(){return $(this).val();}).get();
        var cont_url_type=$("select[name='cont_url_type[]']").map(function(){return $(this).val();}).get();
        
        var phonecheck=false;
        for(var ijk=0;ijk<cont_phone_number.length;ijk++){
            if(cont_phone_number[ijk]!=""){
                phonecheck=true;
                break;
            }
        }
        
        var emailcheck=false;
        for(var ijk=0;ijk<cont_email_name.length;ijk++){
            if(cont_email_name[ijk]!=""){
                emailcheck=true;
                break;
            }
        }
        if((phonecheck==false)&&(emailcheck==false)){
            swal("", "Fill the Phone Number or Email", "warning");
            return;
        }
        
        var cont_add=$("#cont_add").val();
        var cont_address="";
        var cont_country="";
        var cont_state="";
        var cont_city="";
        var cont_pincode="";
        if(cont_add=="yes"){
            cont_address=$("#cont_address").val();
            cont_country=$("#cont_country").val();
            cont_state=$("#cont_state").val();
            cont_city=$("#cont_city").val();
            cont_pincode=$("#cont_pincode").val();
        }
        
        var cont_status=$("#cont_status").val();
        var cont_tag=$("#cont_tag").val();
        var cont_lead=$("#cont_lead").val();
        var cont_background=$("#cont_background").val();
        var cont_owner=$("#cont_owner").val();
        var cont_make_private=$("#cont_make_private").val();
        var cont_birthday=$("#cont_birthday").val();
        
        var cont_organization1=$("#cont_organization1").val();
        var cont_org_desc=$("#cont_org_desc").val();
        var cont_org_phone=$("#cont_org_phone").val();
        var cont_org_url=$("#cont_org_url").val();
        
        var cont_org_add=$("#cont_org_add").val();
        var cont_org_address="";
        var cont_org_country="";
        var cont_org_state="";
        var cont_org_city="";
        var cont_org_pincode="";
        if(cont_org_add=="yes"){
            cont_org_address=$("#cont_org_address").val();
            cont_org_country=$("#cont_org_country").val();
            cont_org_state=$("#cont_org_state").val();
            cont_org_city=$("#cont_org_city").val();
            cont_org_pincode=$("#cont_org_pincode").val();
        }
        
        var dataa = new FormData();
        dataa.append("cont_id",cont_id);
        dataa.append("oid",oid);
        dataa.append("firstname",firstname);
        dataa.append("lastname",lastname);
        dataa.append("cont_organization",cont_organization);
        dataa.append("cont_title",cont_title);
        dataa.append("cont_job_title",cont_job_title);
        
        var cont_phone_number1=JSON.stringify(cont_phone_number);
        dataa.append("cont_phone_number",cont_phone_number1);
        
        var cont_phone_type1=JSON.stringify(cont_phone_type);
        dataa.append("cont_phone_type",cont_phone_type1);
        
        var cont_email_name1=JSON.stringify(cont_email_name);
        dataa.append("cont_email_name",cont_email_name1);
        
        var cont_email_type1=JSON.stringify(cont_email_type);
        dataa.append("cont_email_type",cont_email_type1);
        
        var cont_url_name1=JSON.stringify(cont_url_name);
        dataa.append("cont_url_name",cont_url_name1);
        
        var cont_url_type1=JSON.stringify(cont_url_type);
        dataa.append("cont_url_type",cont_url_type1);
        
        dataa.append("cont_address",cont_address);
        dataa.append("cont_country",cont_country);
        dataa.append("cont_state",cont_state);
        dataa.append("cont_city",cont_city);
        dataa.append("cont_pincode",cont_pincode);
        dataa.append("cont_status",cont_status);
        dataa.append("cont_tag",cont_tag);
        dataa.append("cont_lead",cont_lead);
        dataa.append("cont_background",cont_background);
        dataa.append("cont_owner",cont_owner);
        dataa.append("cont_make_private",cont_make_private);
        dataa.append("cont_birthday",cont_birthday);
        dataa.append("cont_organization1",cont_organization1);
        dataa.append("cont_org_desc",cont_org_desc);
        dataa.append("cont_org_phone",cont_org_phone);
        dataa.append("cont_org_url",cont_org_url);
        dataa.append("cont_org_address",cont_org_address);
        dataa.append("cont_org_country",cont_org_country);
        dataa.append("cont_org_state",cont_org_state);
        dataa.append("cont_org_city",cont_org_city);
        dataa.append("cont_org_pincode",cont_org_pincode);
        dataa.append("update_contact","update");
        $.ajax({
            url : "../Control/contact.php",
            type: 'POST',
            data : dataa,
            cache       : false,
            contentType : false,
            processData : false,
            success:function(data)
            {
                var page="<?php echo $page;?>";
                window.location.replace(page);
            },
            error: function(xhr) {
                alert('Error!  Status = ' + xhr.status + " Message = " + xhr.statusText);
                //console.log('Error!  Status = ' + xhr.status + " Message = " +  xhr.statusText);
            }
        });
    }
});
               
</script>
                    <span id="contactfield">
                        
                        <div id="messages"></div>
                        <div class="row" style="padding:5px 0px;">
                            <div class="col-sm-3">
                                <span class="pull-right" style="padding:7px 0px;">Name</span>
                            </div>
                                <span class="col-sm-2">
                                    <select name="cont_title" id="cont_title" class="form-control" title="title">
                                        <option value="<?php echo $cont_name_title;?>"><?php echo $cont_name_title;?></option>
                                        <option value="Mr">Mr</option>
                                        <option value="Mrs">Mrs</option>
                                        <?php 
                                        foreach($res_title as $row_title){
                                        $c_name=$row_title['contacttitle_name'];
                                        echo "<option value='".$c_name."'>".$c_name."</option>";
                                        }
                                        ?>
                                    </select>
                                </span>
                                <span class="col-sm-3">
                                    <input name="cont_first_name" id="cont_first_name" type="text" value="<?php echo $cont_first_name;?>" autocomplete="off" class="form-control" placeholder="First Name">
                                </span>
                                <span class="col-sm-4">
                                    <input name="cont_last_name" id="cont_last_name" type="text" value="<?php echo $cont_last_name;?>" autocomplete="off" class="form-control" placeholder="Last Name">
                                </span>
                        </div>
                        
                        <div class="row" style="padding:5px 0px;">
                            <div class="col-sm-3">
                                <span class="pull-right" style="padding:7px 0px;">Job Title</span>
                            </div>
                            <div class="col-sm-9">
                                <input name="cont_job_title" id="cont_job_title" type="text" value="<?php echo $cont_job_title;?>" autocomplete="off" class="form-control" placeholder="Job Title">
                            </div>
                        </div>
                        
                        <div class="row" style="padding:5px 0px;">
                            <div class="col-sm-3">
                                <span class="pull-right" style="padding:7px 0px;">Organization</span>
                            </div>
                            <div class="col-sm-9">
                                <input name="cont_organization" id="cont_organization" type="text" value="<?php echo $org_name;?>" autocomplete="off" class="form-control" placeholder="Organization">
                            </div>
                        </div>
                                   
<?php
    
$resultphone=$objsales->salesselectcontid("sales_phone", $cont_id);
//print_r($resultorganization);
$s_phone_number_array=array();
$s_phone_type_array=array();
foreach($resultphone as $rowphone){
$s_phone_number=$rowphone['phone_number'];
array_push($s_phone_number_array, $s_phone_number);
$s_phone_type=$rowphone['phone_type'];
array_push($s_phone_type_array, $s_phone_type);
}

?>

                        <div class="field_wrapper_phone_1" style="padding:5px 0px;">
                            
                            <?php
                            for($iii=1;$iii<count($s_phone_number_array);$iii++){
                            ?>
                            
                            <div class="row" style="padding:0px 0px;">
                                <div class="col-sm-3">
                                    <span class="pull-right" style="padding:7px 0px;">Phone</span>
                                </div>
                                <div class="col-sm-6">
                                    <input class="form-control"  name="cont_phone_number[]" value="<?php echo $s_phone_number_array[$iii];?>" autocomplete="off" id="cont_phone_number" type="text" placeholder="Phone Number">
                                </div>
                                <div class="col-sm-3 form-group">
                                    <div class="input-group">
                                    <select class="form-control" name="cont_phone_type[]" id="cont_phone_type">
                                        <option value="<?php echo $s_phone_type_array[$iii];?>" selected><?php echo $s_phone_type_array[$iii];?></option>
                                        <option>Work</option>
                                        <option>Mobile</option>
                                        <option>Home</option>
                                        <option>Direct</option>
                                        <option>Fax</option>
                                        <option>Skype</option>
                                        <option>Other</option>
                                    </select>
                                    <span class="input-group-addon" style="background-color:red;color:white;cursor:pointer;" id="remove_button_phone_1">-</span>
                                    </div>
                                </div>
                            </div>
                            <?php
                            }
                            ?>
                            
                        </div>
                        
             

                        <div class="row" style="padding:0px 0px;">
                            <div class="col-sm-3">
                                <span class="pull-right" style="padding:7px 0px;">Phone</span>
                            </div>
                            <div class="col-sm-6">
                                <input class="form-control"  name="cont_phone_number[]" value="<?php echo $s_phone_number_array[0];?>" autocomplete="off" id="cont_phone_number" type="text" placeholder="Phone Number">
                            </div>
                            <div class="col-sm-3 form-group">
                                <div class="input-group">
                                <select class="form-control" name="cont_phone_type[]" id="cont_phone_type">
                                    <option value="<?php echo $s_phone_type_array[0];?>" selected><?php echo $s_phone_type_array[0];?></option>
                                    <option>Work</option>
                                    <option>Mobile</option>
                                    <option>Home</option>
                                    <option>Direct</option>
                                    <option>Fax</option>
                                    <option>Skype</option>
                                    <option>Other</option>
                                </select>
                                <span class="input-group-addon" style="background-color:green;color:white;cursor:pointer;" id="add_button_phone_1" style="background-color:green">+</span>
                                </div>
                            </div>
                        </div>
                        <script type="text/javascript">
                            $(document).ready(function(){
                                var maxField = 10; //Input fields increment limitation
                                var addButton_1 = $('#add_button_phone_1'); //Add button selector
                                var wrapper_1 = $('.field_wrapper_phone_1'); //Input field wrapper
                                var inputphone1 = '<div><div class="row"><div class="col-sm-3"><span class="pull-right" style="padding:7px 0px;">Phone</span></div>';
                                inputphone1 +='<div class="col-sm-6"><input name="cont_phone_number[]" autocomplete="off" id="cont_phone_number" type="text" class="form-control" placeholder="Phone Number"></div>';    
                                inputphone1 += '<div class="form-group col-sm-3"><div class="input-group">';
                                inputphone1 +='<select class="form-control" name="cont_phone_type[]" id="cont_phone_type"><option>Work</option><option>Mobile</option><option>Home</option><option>Direct</option><option>Fax</option><option>Skype</option><option>Other</option></select>';
                                inputphone1 +='<div class="input-group-addon" style="background-color:red;color:white;cursor:pointer;" id="remove_button_phone_1">-</div>';
                                inputphone1 +='</div></div><hr></div>'; //New input field html 
                                var xphone1 = 1; //Initial field counter is 1
                                $(addButton_1).click(function(){ //Once add button is clicked
                                    if(xphone1 < maxField){ //Check maximum number of input fields
                                        xphone1++; //Increment field counter
                                        $(wrapper_1).append(inputphone1); // Add field html
                                    }
                                });
                                $(wrapper_1).on('click', '#remove_button_phone_1', function(e){ //Once remove button is clicked
                                    e.preventDefault();
                                    $(this).parent('div').parent('div').parent('div').remove(); //Remove field html
                                    xphone1--; //Decrement field counter
                                });
                            });
                        </script>
                     
<?php
    
$result_email=$objsales->salesselectcontid("sales_email", $cont_id);
$email_name_array=array();
$email_type_array=array();
foreach($result_email as $row_email){
$email_name=$row_email['email_name'];
array_push($email_name_array, $email_name);
$email_type=$row_email['email_type'];
array_push($email_type_array, $email_type);
}
?>                        
                        <div class="field_wrapper_email_1" style="padding:5px 0px;">
                        <?php
                        for($jjj=1;$jjj<count($email_name_array);$jjj++){
                        ?>
                        
                        <div class="row" style="padding:0px 0px;">
                            <div class="col-sm-3">
                                <span class="pull-right" style="padding:7px 0px;">Email</span>
                            </div>
                            <div class="col-sm-6">
                                <input class="form-control" value="<?php echo $email_name_array[$jjj];?>"  name="cont_email_name[]" autocomplete="off" id="cont_email_name" type="text" placeholder="Email">
                            </div>
                            <div class="col-sm-3 form-group">
                                <div class="input-group">
                                <select class="form-control" name="cont_email_type[]" id="cont_email_type">
                                    <option value="<?php echo $email_type_array[$jjj];?>" selected><?php echo $email_type_array[$jjj];?></option>
                                    <option>Work</option>
                                    <option>Home</option>
                                    <option>Other</option>
                                </select>
                                <span class="input-group-addon" style="background-color:red;color:white;cursor:pointer;" id="remove_button_email_1">-</span>
                            </div>
                            </div>
                        </div>
                        
                        <?php
                        }
                        ?>
                        </div>
                        
                        <div class="row" style="padding:0px 0px;">
                            <div class="col-sm-3">
                                <span class="pull-right" style="padding:7px 0px;">Email</span>
                            </div>
                            <div class="col-sm-6">
                                <input class="form-control" value="<?php echo $email_name_array[0];?>"  name="cont_email_name[]" autocomplete="off" id="cont_email_name" type="text" placeholder="Email">
                            </div>
                            <div class="col-sm-3 form-group">
                                <div class="input-group">
                                <select class="form-control" name="cont_email_type[]" id="cont_email_type">
                                    <option value="<?php echo $email_type_array[0];?>"><?php echo $email_type_array[0];?></option>
                                    <option>Work</option>
                                    <option>Home</option>
                                    <option>Other</option>
                                </select>
                                <span class="input-group-addon" style="background-color:green;color:white;cursor:pointer;" id="add_button_email_1" style="background-color:green">+</span>
                            </div>
                            </div>
                        </div>
                        <script type="text/javascript">
                            $(document).ready(function(){
                                var maxField = 10; //Input fields increment limitation
                                var addButton_eml_1 = $('#add_button_email_1'); //Add button selector
                                var wrapper_eml_1 = $('.field_wrapper_email_1'); //Input field wrapper
                                var inputeml1 = '<div><div class="row"><div class="col-sm-3"><span class="pull-right" style="padding:7px 0px;">Email</span></div>';
                                inputeml1 +='<div class="col-sm-6"><input name="cont_email_name[]" autocomplete="off" id="cont_email_name" type="text" class="form-control" placeholder="Email"></div>';       
                                inputeml1 += '<div class="form-group col-sm-3"><div class="input-group">';
                                inputeml1 +='<select class="form-control" name="cont_email_type[]" id="cont_email_type"><option>Work</option><option>Home</option><option>Other</option></select>';
                                inputeml1 +='<div class="input-group-addon" style="background-color:red;color:white;cursor:pointer;" id="remove_button_email_1">-</div>';
                                inputeml1 +='</div></div><hr></div>'; //New input field html 
                                var xeml1 = 1; //Initial field counter is 1
                                $(addButton_eml_1).click(function(){ //Once add button is clicked
                                    if(xeml1 < maxField){ //Check maximum number of input fields
                                        xeml1++; //Increment field counter
                                        $(wrapper_eml_1).append(inputeml1); // Add field html
                                    }
                                });
                                $(wrapper_eml_1).on('click', '#remove_button_email_1', function(e){ //Once remove button is clicked
                                    e.preventDefault();
                                    $(this).parent('div').parent('div').parent('div').remove(); //Remove field html
                                    xeml1--; //Decrement field counter
                                });
                            });
                        </script>
             
                     
<?php
    
$result_url=$objsales->salesselectcontid("sales_url", $cont_id);
$url_name_array=array();
$url_type_array=array();
foreach($result_url as $row_url){
$url_name=$row_url['url_name'];
array_push($url_name_array, $url_name);
$url_type=$row_url['url_type'];
array_push($url_type_array, $url_type);
}
?>                            
                        <div class="field_wrapper_url_1">
                            <?php
                            for($kkk=1;$kkk<count($url_name_array);$kkk++){
                            ?>
                            <div class="row" style="padding:0px 0px;">
                                <div class="col-sm-3">
                                    <span class="pull-right" style="padding:7px 0px;">URL</span>
                                </div>
                                <div class="col-sm-6">
                                    <input class="form-control" value="<?php echo $url_name_array[$kkk];?>"  name="cont_url_name[]" autocomplete="off" id="cont_url_name" type="text" placeholder="Url">
                                </div>
                                <div class="col-sm-3 form-group">
                                    <div class="input-group">
                                        <select class="form-control" name="cont_url_type[]" id="cont_url_type">
                                            <option value="<?php echo $url_type_array[$kkk];?>" selected><?php echo $url_type_array[$kkk];?></option>
                                            <option>Website</option>
                                            <option>Blog</option>
                                            <option>Twitter</option>
                                            <option>LinkedIn</option>
                                            <option>Xing</option>
                                            <option>Facebook</option>
                                            <option>Google+</option>
                                            <option>Other</option>
                                        </select>
                                        <span class="input-group-addon" style="background-color:green;color:white;cursor:pointer;" id="add_button_url_1" style="background-color:green">+</span>
                                    </div>
                                </div>
                            </div>
                            <?php
                            }
                            ?>
                        </div>
                        
                        <div class="row" style="padding:0px 0px;">
                            <div class="col-sm-3">
                                <span class="pull-right" style="padding:7px 0px;">URL</span>
                            </div>
                            <div class="col-sm-6">
                                <input class="form-control" value="<?php echo $url_name_array[0];?>"  name="cont_url_name[]" autocomplete="off" id="cont_url_name" type="text" placeholder="Url">
                            </div>
                            <div class="col-sm-3 form-group">
                                <div class="input-group">
                                    <select class="form-control" name="cont_url_type[]" id="cont_url_type">
                                        <option value="<?php echo $url_type_array[0];?>" selected><?php echo $url_type_array[0];?></option>
                                        <option>Website</option>
                                        <option>Blog</option>
                                        <option>Twitter</option>
                                        <option>LinkedIn</option>
                                        <option>Xing</option>
                                        <option>Facebook</option>
                                        <option>Google+</option>
                                        <option>Other</option>
                                    </select>
                                    <span class="input-group-addon" style="background-color:green;color:white;cursor:pointer;" id="add_button_url_1" style="background-color:green">+</span>
                                </div>
                            </div>
                        </div>
                        
                        <script type="text/javascript">
                            $(document).ready(function(){
                                var maxField = 10; //Input fields increment limitation
                                var addButton_url_1 = $('#add_button_url_1'); //Add button selector
                                var wrapper__url_1 = $('.field_wrapper_url_1'); //Input field wrapper
                                var inputurl1 = '<div><div class="row"><div class="form-group col-sm-3"><span class="pull-right" style="padding:7px 0px;">URL</span></div>';
                                inputurl1 +='<div class="col-sm-6"><input name="cont_url_name[]" autocomplete="off" id="cont_url_name" type="text" class="form-control" placeholder="Url"></div>'; 
                                inputurl1 +='<div class="form-group col-sm-3"><div class="input-group">';
                                inputurl1 +='<select class="form-control" name="cont_url_type[]" id="cont_url_type"><option>Website</option><option>Blog</option><option>Twitter</option><option>LinkedIn</option><option>Xing</option><option>Facebook</option><option>Google+</option><option>Other</option></select>';
                                inputurl1 +='<div class="input-group-addon" style="background-color:red;color:white;cursor:pointer;" id="remove_button_url_1">-</div>';
                                inputurl1 +='</div></div><hr></div>'; //New input field html 
                                var xurl1 = 1; //Initial field counter is 1
                                $(addButton_url_1).click(function(){ //Once add button is clicked
                                    if(xurl1 < maxField){ //Check maximum number of input fields
                                        xurl1++; //Increment field counter
                                        $(wrapper__url_1).append(inputurl1); // Add field html
                                    }
                                });
                                $(wrapper__url_1).on('click', '#remove_button_url_1', function(e){ //Once remove button is clicked
                                    e.preventDefault();
                                    $(this).parent('div').parent('div').parent('div').remove(); //Remove field html
                                    xurl1--; //Decrement field counter
                                });
                            });
                        </script>
                        
                        <script>
                            $(document).on("focus", "#cont_address1", function(){
                                $("#cont_address1").hide();
                                $("#cont_address").show();
                                $("#showaddressenter").show();
                                $("#cont_address").focus();
                                $("#cont_add").val("yes");
                            });
                        </script>
                        <div class="row" style="padding:5px 0px;">
                            <div class="col-sm-3">
                                <span class="pull-right" style="padding:7px 0px;">Address</span>
                                <input type="hidden" id="cont_add" value="yes">
                            </div>
                            <div class="col-sm-9">
                                <textarea name="cont_address1" id="cont_address1" class="form-control" autocomplete="off" placeholder="Address" style="display:none;"></textarea>
                                <textarea name="cont_address" id="cont_address" class="form-control" autocomplete="off" placeholder="Address"><?php echo $cont_address_line;?></textarea>
                            </div>
                        </div>
                        
                        <span id="showaddressenter">
                            <?php
                            $res_country=$objaddress->allcountry();
                            ?>
                            
                            <?php
                            $res_state=$objsales->salesselectedid("states", $cont_address_state);
                            foreach($res_state as $row_state){
                            $s_name=$row_state['name'];
                            $s_id=$row_state['id'];
                            }
                            ?>
                            <div class="row" style="padding:5px 0px;">
                                <div class="col-sm-3">
                                </div>
                                    <span class="col-sm-5">
                                        <select class="form-control cont_country" data-live-search="true" data-size="5" id="cont_country" title="Country"  name="cont_country" required width="70%">
                                            <?php 
                                            foreach($res_country as $row_country){
                                            $c_name=$row_country['name'];
                                            $c_id=$row_country['id'];
                                            if($cont_address_country==$c_id){
                                                echo "<option value='".$c_id."' selected>".$c_name."</option>";
                                            }else{
                                                echo "<option value='".$c_id."'>".$c_name."</option>";
                                            }
                                            }
                                            ?>
                                        </select>
                                    </span>
                                    <span class="col-sm-4">
                                        <select class="form-control cont_state" name="cont_state" id="cont_state"  title="State" data-live-search="true" data-size="5">
                                            <option value="<?php echo $s_id;?>" selected><?php echo $s_name;?></option>
                                        </select>
                                    </span>
                            </div>
                            
                            <?php
                            $res_city=$objsales->salesselectedid("cities", $cont_address_city);
                            foreach($res_city as $row_city){
                            $ci_name=$row_city['name'];
                            $ci_id=$row_city['id'];
                            }
                            ?>
                            <div class="row" style="padding:5px 0px;">
                                <div class="col-sm-3">
                                </div>
                                <div class="col-sm-5">
                                    <select class="form-control cont_city" name="cont_city" id="cont_city" title="City" data-live-search="true" data-size="5">
                                        <option value="<?php echo $ci_id;?>" selected><?php echo $ci_name;?></option>
                                    </select>
                                </div>
                                <div class="col-sm-4">
                                    <input type="text" name="cont_pincode" value="<?php echo $cont_address_pincode;?>" id="cont_pincode" autocomplete="off" class="form-control" title="Pincode" placeholder="Pincode">
                                </div>
                            </div>
                        
                        </span>
                        
                                              
              
                        <?php
                        $res_sales=$objsales->salesselectall($companyname, $adminemailid, "sales_status", "no");
                        //print_r($res_sales);
                        ?>    
                        <div class="row" style="padding:5px 0px;">
                            <div class="col-sm-3">
                                <span class="pull-right" style="padding:7px 0px;">Status</span>
                            </div>
                            <div class="col-sm-9">
                                <select class="form-control" name="cont_status" id="cont_status">
                                    <?php 
                                    foreach($res_sales as $row_sales){
                                    $s_name=$row_sales['status_name'];
                                    $s_id=$row_sales['id'];
                                    if($s_id==$cont_status){
                                    echo "<option value='".$s_id."' selected>".$s_name."</option>";
                                    }else{
                                    echo "<option value='".$s_id."'>".$s_name."</option>";
                                    }
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>
              
                        <?php
                        $res_sales=$objsales->salesselectall($companyname, $adminemailid, "sales_tag", "no");
                        //print_r($res_sales);
                        ?>    
                        <div class="row" style="padding:5px 0px;">
                            <div class="col-sm-3">
                                <span class="pull-right" style="padding:7px 0px;">Tag</span>
                            </div>
                            <div class="col-sm-9">
                                <select class="form-control" name="cont_tag" id="cont_tag">
                                    <option></option>
                                    <?php 
                                    foreach($res_sales as $row_sales){
                                    $t_name=$row_sales['tag_name'];
                                    $t_id=$row_sales['id'];
                                    if($t_id==$cont_tag){
                                    echo "<option value='".$t_id."' selected>".$t_name."</option>";
                                    }else{
                                    echo "<option value='".$t_id."'>".$t_name."</option>";
                                    }
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>
              
                        <?php
                        $res_sales=$objsales->salesselectall($companyname, $adminemailid, "sales_lead_source", "no");
                        //print_r($res_sales);
                        ?>    
                        <div class="row" style="padding:5px 0px;">
                            <div class="col-sm-3">
                                <span class="pull-right" style="padding:7px 0px;">Lead Source</span>
                            </div>
                            <div class="col-sm-9">
                                <select class="form-control" name="cont_lead" id="cont_lead">
                                
                                    <?php 
                                    foreach($res_sales as $row_sales){
                                    $l_name=$row_sales['lead_name'];
                                    $l_id=$row_sales['id'];
                                    if($l_id==$cont_lead_source){
                                        echo "<option value='".$l_id."' selected>".$l_name."</option>";
                                    }else{
                                        echo "<option value='".$l_id."'>".$l_name."</option>";
                                    }
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>
                        <div class="row" style="padding:5px 0px;">
                            <div class="col-sm-3">
                                <span class="pull-right" style="padding:7px 0px;">Background</span>
                            </div>
                            <div class="col-sm-9">
                                <textarea name="cont_background" id="cont_background" autocomplete="off" class="form-control" placeholder="Background"><?php echo $cont_background;?></textarea>
                            </div>
                        </div>
                        <?php
                        $res_sales=$objsales->salesselectall($companyname, $adminemailid, "signupdetails", "no");
                        ?>                  
                        <div class="row" style="padding:5px 0px;">
                            <div class="col-sm-3">
                                <span class="pull-right" style="padding:7px 0px;">Owner</span>
                            </div>
                            <div class="col-sm-5">
                                <select class="form-control" name="cont_owner" id="cont_owner">
                                    <?php 
                                    foreach($res_sales as $row_sales){
                                        $s_employeename=$row_sales['employeename'];
                                        $s_emailid=$row_sales['emailid'];
                                        if($s_emailid==$cont_owner){
                                            if($adminemailid==$s_emailid){
                                                echo "<option value='".$s_emailid."' selected>me</option>";
                                            }else{
                                                echo "<option value='".$s_emailid."' selected>".$s_employeename."(".$s_emailid.")</option>";
                                            }
                                        }else{
                                            if($adminemailid==$s_emailid){
                                            echo "<option value='".$s_emailid."'>me</option>";
                                            }else{
                                                echo "<option value='".$s_emailid."'>".$s_employeename."(".$s_emailid.")</option>";
                                            }
                                        }
                                    }
                                    ?>
                                </select>
                            </div>
                            <?php
                            if(($cont_make_private=="yes")||($cont_make_private=="on")){
                            $cont_make_private1="on";
                            }else{
                                $cont_make_private1="off";
                            }
                            ?>
                            <div class="col-md-4">
                                <div class="form-check">
                                    <label class="form-check-label">
                                      <input type="checkbox" <?php  if(($cont_make_private=="yes")||($cont_make_private=="on")){ echo "checked"; }?> autocomplete="<?php echo $cont_make_private1;?>" class="form-check-input" id="cont_make_private1" name="cont_make_private1">
                                      Make Private
                                    </label>
                                </div>
                            </div>
                        </div>
                        
                        <input type="hidden" class="form-check-input"  autocomplete="<?php echo $cont_make_private1;?>" id="cont_make_private" name="cont_make_private">
                            <script>
                                $(document).ready(function(){
                                   $("#cont_make_private1").change(function(){
                                       //alert("zx");
                                        if (this.checked)
                                        {
                                           // alert("on");
                                            $("#cont_make_private").val("yes");
                                        }else{
                                            //alert("off");
                                            $("#cont_make_private").val("no");
                                        }
                                   });
                                });
                            </script>
                        <div class="row" style="padding:5px 0px;">
                            <div class="col-sm-3">
                                <span class="pull-right" style="padding:7px 0px;">Birthday</span>
                            </div>
                            <div class="col-sm-9">
                                <input type="text" value="<?php echo $cont_birthdate;?>" class="form-control" autocomplete="off" name="cont_birthday" id="cont_birthday" readonly>
                            </div>
                        </div>
                        
                    </span>
                    
                    <span id="orgfield" style="display:none;">
                        
                        
                        <div class="row" style="padding:5px 0px;">
                            <div class="col-sm-3">
                                <span class="pull-right" style="padding:7px 0px;">Organization</span>
                            </div>
                            <div class="col-sm-9">
                                <input name="cont_organization1" value="<?php echo $org_name;?>" autocomplete="off" id="cont_organization1" type="text" class="form-control" placeholder="Organization" maxlength="100" autocomplete="off" tabindex="47">
                            </div>
                        </div>
                        
                        <style>
                            #cont_organization1{
                                font-family: "Open Sans Bold", Arial, Helvetica, sans-serif;
                                font-weight: normal;
                                padding-left: 23px;
                                background: #fff url(Image/organizationicon.png) 5px 7px no-repeat;
                                background-size: 12px 12px;
                            }
                            #cont_organization{
                                font-family: "Open Sans Bold", Arial, Helvetica, sans-serif;
                                font-weight: normal;
                                padding-left: 23px;
                                background: #fff url(Image/organizationicon.png) 5px 7px no-repeat;
                                background-size: 12px 12px;
                            }
                        </style>
                        <script>
                            $(document).on("change", "#cont_organization", function(){
                               var value1=$("#cont_organization").val();
                               $("#cont_organization1").val(value1);
                            });
                            $(document).on("change", "#cont_organization1", function(){
                               var value1=$("#cont_organization1").val();
                               $("#cont_organization").val(value1);
                            });
                        </script>
                        
                        <div class="row" style="padding:5px 0px;">
                            <div class="col-sm-3">
                                <span class="pull-right" style="padding:7px 0px;">Description</span>
                            </div>
                            <div class="col-sm-9">
                                <textarea name="cont_org_desc" autocomplete="off" id="cont_org_desc" class="form-control" placeholder="Organization Description" rows="6"><?php echo $org_desc;?></textarea>
                            </div>
                        </div>
                        
                        <div class="row" style="padding:5px 0px;">
                            <div class="col-sm-3">
                                <span class="pull-right" style="padding:7px 0px;">Org-phone</span>
                            </div>
                            <div class="col-sm-9">
                                <input name="cont_org_phone" value="<?php echo $org_phone;?>" autocomplete="off" id="cont_org_phone" type="text" class="form-control" placeholder="Organization Phone">
                            </div>
                        </div>
                        
                        <div class="row" style="padding:5px 0px;">
                            <div class="col-sm-3">
                                <span class="pull-right" style="padding:7px 0px;">Org-url</span>
                            </div>
                            <div class="col-sm-9">
                                <input name="cont_org_url" value="<?php echo $org_url;?>" autocomplete="off" id="cont_org_url" type="text" class="form-control" placeholder="Organization Url">
                            </div>
                        </div>
                        
                        <script>
                            $(document).on("focus", "#cont_org_address1", function(){
                                $("#cont_org_address1").hide();
                                $("#cont_org_address").show();
                                $("#showorgaddressenter").show();
                                $("#cont_org_address").focus();
                                $("#cont_org_add").val("yes");
                            });
                        </script>
                        <div class="row" style="padding:5px 0px;">
                            <div class="col-sm-3">
                                <span class="pull-right" style="padding:7px 0px;">Address</span>
                                <input type="hidden" id="cont_org_add" value="yes">
                            </div>
                            <div class="col-sm-9">
                                <textarea name="cont_org_address1" id="cont_org_address1" class="form-control" style="display:none;" placeholder="Address"><?php echo $org_pincode;?></textarea>
                                <textarea name="cont_org_address" autocomplete="off" id="cont_org_address" class="form-control" placeholder="Address"><?php echo $org_add;?></textarea>
                            </div>
                        </div>
                        
                        <span id="showorgaddressenter">
                            <?php
                            $res_country1=$objaddress->allcountry();
                            ?>
                            
                            <?php
                            $res_state=$objsales->salesselectedid("states", $org_state);
                            foreach($res_state as $row_state){
                            $s_name=$row_state['name'];
                            $s_id=$row_state['id'];
                            }
                            ?>
                            <div class="row" style="padding:5px 0px;">
                                <div class="col-sm-3">
                                </div>
                                    <span class="col-sm-5">
                                        <select class=" form-control cont_org_country" data-live-search="true" data-size="5" id="cont_org_country" title="select the Country"  name="cont_org_country" required width="70%">
                                            
                                            <?php 
                                            foreach($res_country1 as $row_country){
                                            $c_name=$row_country['name'];
                                            $c_id=$row_country['id'];
                                            if($c_id==$org_country){
                                            echo "<option value='".$c_id."' selected>".$c_name."</option>";
                                            }else{
                                            echo "<option value='".$c_id."'>".$c_name."</option>";
                                            }
                                            }
                                            ?>
                                        </select>
                                    </span>
                                    
                            
                                    <span class="col-sm-4">
                                        <select class="form-control cont_org_state" name="cont_org_state" id="cont_org_state" title="state" data-live-search="true" data-size="5">
                                            <option value="<?php echo $s_id;?>"><?php echo $s_name;?></option>
                                        </select>
                                    </span>
                            </div>
                            
                            
                            <?php
                            $res_state=$objsales->salesselectedid("cities", $org_city);
                            foreach($res_state as $row_state){
                            $c_name=$row_state['name'];
                            $c_id=$row_state['id'];
                            }
                            ?>
                            <div class="row" style="padding:5px 0px;">
                                <div class="col-sm-3">
                                </div>
                                <div class="col-sm-5">
                                    <select class="form-control cont_org_city" name="cont_org_city" id="cont_org_city" title="City" data-live-search="true" data-size="5">
                                        <option value="<?php echo $c_id;?>"><?php echo $c_name;?></option>
                                    </select>
                                </div>
                                <div class="col-sm-4">
                                    <input type="text" autocomplete="off" name="cont_org_pincode" id="cont_org_pincode" value="<?php echo $org_pincode;?>" class="form-control" title="Pincode" placeholder="Pincode"></textarea>
                                </div>
                            </div>
                        
                        </span>
                        
                        
                        <br><br>
                        <p class="delete-info">Organizations are only deleted when you delete the last contact in it</p>
                        
                        <style>
                            .delete-info{
                                float: right;
                                font-family: "Open Sans Italic", Arial, Helvetica, sans-serif;
                                font-size: 12px;
                                color: #999;
                            }
                        </style>
                        
                    </span>
                    
                </form>
                    
            </div>
            
            <div class="col-sm-3">
                
                <div class="yellow-msg" style="margin-top:70px;padding:5px;">
                    <span class="pull-right" id="hideuploadsetting" style="cursor:pointer;">x</span>
                      Need to <a>import contacts in bulk</a><br>
                      Or <a>Add custom fields</a>?
                </div>
                
                <script>
                    $(document).on("click", "#hideuploadsetting", function(){
                       $(".yellow-msg").hide();
                    });
                </script>
                <style>
                    .yellow-msg{
                        background-color: #fff1a8;
                        color: #666;
                        font-family: "Open Sans Italic", Arial, Helvetica, sans-serif;
                        font-size: 12px;
                    }
                </style>
                
            </div>  
        </div>
        <br>
        <br>

             
<script>
    $(document).ready(function(){
       $('#cont_org_country').selectpicker(); 
       $('#cont_state').selectpicker(); 
       $('#cont_city').selectpicker(); 
    });
</script>
<script>
    $(document).ready(function(){
        $("#cont_org_country").change(function(){
            var value1=$(this).val();
            //alert(value1);
            $.post("../Control/address.php", {stateallfromcountry: value1}, function(result){
                //alert(result);
        $("#cont_org_state").html(result);
        $("#cont_org_state").selectpicker("refresh");
    });
        });
    });
</script>
<script>
    $(document).ready(function(){
        $("#cont_org_state").change(function(){
            var value1=$(this).val();
            //alert(value1);
            $.post("../Control/address.php", {cityallfromstate: value1}, function(result){
                //alert(result);
        $("#cont_org_city").html(result);
        $("#cont_org_city").selectpicker("refresh");
    });
        });
    });
</script>
<script>
    $(document).ready(function(){
       $('#cont_country').selectpicker(); 
       $('#cont_state').selectpicker(); 
       $('#cont_city').selectpicker(); 
    });
</script>
<script>
    $(document).ready(function(){
        $("#cont_country").change(function(){
            var value1=$(this).val();
            //alert(value1);
            $.post("../Control/address.php", {stateallfromcountry: value1}, function(result){
                //alert(result);
        $("#cont_state").html(result);
        $("#cont_state").selectpicker("refresh");
    });
        });
    });
</script>
<script>
    $(document).ready(function(){
        $("#cont_state").change(function(){
            var value1=$(this).val();
            //alert(value1);
            $.post("../Control/address.php", {cityallfromstate: value1}, function(result){
                //alert(result);
        $("#cont_city").html(result);
        $("#cont_city").selectpicker("refresh");
    });
        });
    });
</script>        
    </body>
    
</html>

<?php
/*}else{
echo "<script> location.replace('http://fieldcloud.in/Login.php') </script>";
}*/
?>