<?php
session_start();
$companyname=$_SESSION['companyname'];
$companytype=$_SESSION['companytype'];
$companymailid=$_SESSION['companymailid'];
$adminemailid=$_SESSION['emailid'];
$responsible=$_SESSION['responsible_employee'];
    $createby=$_SESSION['emailid'];
    $createtype=$_SESSION['employeetype'];
//include '../Control/sales.php';
class contactctrl{
    
    public function salesinsertcontact($companyname, $companymailid, $contid, $contnametitle, $contfirstname, $contlastname, $contjobtitle, $contaddressline, $contaddresscity, $contaddressstate, $contaddresscountry, $contaddresspincode, $contstatus, $conttag, $contleadsource, $contbackground, $contowner, $contmakeprivate, $contbirthdate, $contdatetime, $contcreatedby, $contcreatedtype, $orgid,  $orgname, $orgdesc, $orgphone, $orgurl, $orgadd, $orgcity, $orgstate, $orgcountry, $orgpincode, $contphone, $contphonetype, $contemail, $contemailtype, $conturl, $conturltype){
        require_once ('../Model/contact.php');
        $dbobj=new contactdb();
        $em=$dbobj-> sales_insert_contact($companyname, $companymailid, $contid, $contnametitle, $contfirstname, $contlastname, $contjobtitle, $contaddressline, $contaddresscity, $contaddressstate, $contaddresscountry, $contaddresspincode, $contstatus, $conttag, $contleadsource, $contbackground, $contowner, $contmakeprivate, $contbirthdate, $contdatetime, $contcreatedby, $contcreatedtype);
        //print_r($em);
        if($em=="yes"){
        require_once ('sales.php');
        $ctrlobj=new salesctrl();
        $cr=$ctrlobj->salesselectedid("sales_contact", $contid);  
        $count=$cr->rowCount();
        require_once ('../Model/organization.php');
        $dbobj1=new organizationdb();
         $result1=$dbobj1->sales_insert_organization($companyname, $companymailid, $orgid, $contid, $orgname, $orgdesc, $orgphone, $orgurl, $orgadd, $orgcity, $orgstate, $orgcountry, $orgpincode, $contcreatedby, $contcreatedtype, $contdatetime);   
        
        require_once ('../Model/phone_email_url.php');
        $dbobj2=new phone_email_urldb();
        for($i=0;$i<count($contphone);$i++){
            $name=$contphone[$i];
            if($name!=""){
            $type=$contphonetype[$i];
            $result2=$dbobj2->sales_insert_phone_email_url("sales_phone", $companyname, $companymailid, $contid, $name, $type, $contcreatedby, $contcreatedtype, $contdatetime);
            //print_r($result2);
            }
            
        }
        for($i=0;$i<count($contemail);$i++){
            $name=$contemail[$i];
            if($name!=""){
            $type=$contemailtype[$i];
            $result2=$dbobj2->sales_insert_phone_email_url("sales_email", $companyname, $companymailid, $contid, $name, $type, $contcreatedby, $contcreatedtype, $contdatetime);
            //print_r($result2);
            }
            
        }
        for($i=0;$i<count($conturl);$i++){
            $name=$conturl[$i];
            if($name!=""){
            $type=$conturltype[$i];
            $result2=$dbobj2->sales_insert_phone_email_url("sales_url", $companyname, $companymailid, $contid, $name, $type, $contcreatedby, $contcreatedtype, $contdatetime);
            //print_r($result2);
            }
            
        }
        }
        $dbobj=null;
        $dbobj1=null;
        $dbobj2=null;
        return $em;
    }


    
    public function salesupdatecontact($companyname, $companymailid, $contid, $contnametitle, $contfirstname, $contlastname, $contjobtitle, $contaddressline, $contaddresscity, $contaddressstate, $contaddresscountry, $contaddresspincode, $contstatus, $conttag, $contleadsource, $contbackground, $contowner, $contmakeprivate, $contbirthdate, $contdatetime, $contcreatedby, $contcreatedtype, $orgid,  $orgname, $orgdesc, $orgphone, $orgurl, $orgadd, $orgcity, $orgstate, $orgcountry, $orgpincode, $contphone, $contphonetype, $contemail, $contemailtype, $conturl, $conturltype){
        require_once ('../Model/contact.php');
        $dbobj=new contactdb();
        $em=$dbobj-> sales_update_contact($companyname, $companymailid, $contid, $contnametitle, $contfirstname, $contlastname, $contjobtitle, $contaddressline, $contaddresscity, $contaddressstate, $contaddresscountry, $contaddresspincode, $contstatus, $conttag, $contleadsource, $contbackground, $contowner, $contmakeprivate, $contbirthdate, $contdatetime, $contcreatedby, $contcreatedtype);
        //print_r($em);
        if($em=="yes"){
        require_once ('../Model/organization.php');
        $dbobj1=new organizationdb();
        if($orgid!=""){
        $result1=$dbobj1->sales_update_organization($companyname, $companymailid, $orgid, $contid, $orgname, $orgdesc, $orgphone, $orgurl, $orgadd, $orgcity, $orgstate, $orgcountry, $orgpincode, $contcreatedby, $contcreatedtype, $contdatetime);
        }else{
        require_once('../Control/sales.php');
        $objsales=new salesctrl();
        $corg=$objsales->salesselectall($companyname, $companymailid, "sales_organization", "all");
        $cont_org=$corg->rowCount();
        $orgid=str_replace(' ', '', $orgname)."_".$cont_org;
        $result1=$dbobj1->sales_insert_organization($companyname, $companymailid, $orgid, $contid, $orgname, $orgdesc, $orgphone, $orgurl, $orgadd, $orgcity, $orgstate, $orgcountry, $orgpincode, $contcreatedby, $contcreatedtype, $contdatetime);    
        }
        require_once ('../Model/phone_email_url.php');
        $dbobj2=new phone_email_urldb();
        $dbobj2->sales_url_phone_email_delete("sales_phone", $contid);
        $dbobj2->sales_url_phone_email_delete("sales_email", $contid);
        $dbobj2->sales_url_phone_email_delete("sales_url", $contid);
        for($i=0;$i<count($contphone);$i++){
            $name=$contphone[$i];
            if($name!=""){
            $type=$contphonetype[$i];
            $result2=$dbobj2->sales_insert_phone_email_url("sales_phone", $companyname, $companymailid, $contid, $name, $type, $contcreatedby, $contcreatedtype, $contdatetime);
           // print_r($result2);
            }
            
        }
        for($i=0;$i<count($contemail);$i++){
            $name=$contemail[$i];
            if($name!=""){
            $type=$contemailtype[$i];
            $result2=$dbobj2->sales_insert_phone_email_url("sales_email", $companyname, $companymailid, $contid, $name, $type, $contcreatedby, $contcreatedtype, $contdatetime);
        //print_r($result2);
            }
            
        }
        for($i=0;$i<count($conturl);$i++){
            $name=$conturl[$i];
            if($name!=""){
            $type=$conturltype[$i];
            $result2=$dbobj2->sales_insert_phone_email_url("sales_url", $companyname, $companymailid, $contid, $name, $type, $contcreatedby, $contcreatedtype, $contdatetime);
       // print_r($result2);
            }
            
        }
        }
        $dbobj=null;
        $dbobj1=null;
        $dbobj2=null;
        return $em;
    }
    
    public function salesupdatecontacttagstatusblob($cont_id, $colmun, $value){
        require_once ('../Model/contact.php');
        $dbobj=new contactdb();
        $em=$dbobj->sales_update_contact_tag_status_blob($cont_id, $colmun, $value);
        //$dbobj=null;
        return $em;
    }
    
    public function salescallinsertupdatedelete($type, $id, $cont_id, $cphone, $cdescr, $cresult, $cdate, $ctime, $cdatetime, $cby, $ctype){
        require_once ('../Model/contact.php');
        $dbobj=new contactdb();
        $em=$dbobj->sales_call_insert_update_delete($type, $id, $cont_id, $cphone, $cdescr, $cresult, $cdate, $ctime, $cdatetime, $cby, $ctype);
        //$dbobj=null;
        return $em;
    }
    
    public function salesdealinsertupdatedelete($type, $id, $contid, $ddealname, $damount, $dmonth, $dcommissionpercentage, $dcommissionamount, $ddescr, $dstage, $ddate, $dclosedate, $ddatetime, $dby, $dtype, $dealby){
        require_once ('../Model/contact.php');
        $dbobj=new contactdb();
        $em=$dbobj->sales_deal_insert_update_delete($type, $id, $contid, $ddealname, $damount, $dmonth, $dcommissionpercentage, $dcommissionamount, $ddescr, $dstage, $ddate, $dclosedate, $ddatetime, $dby, $dtype, $dealby);
       
        return $em;
    }
    
    public function salesnextactioninsertupdatedelete($type, $id, $contid, $nadescr, $nastatus, $nadate, $nadatetime, $naby, $natype, $natime, $naassign,$selectoption){
        require_once ('../Model/contact.php');
        $dbobj=new contactdb();
        $em=$dbobj->sales_nextaction_insert_update_delete($type, $id, $contid, $nadescr, $nastatus, $nadate, $nadatetime, $naby, $natype, $natime, $naassign,$selectoption);
        print_r($em);
        return $em;
    }
    
    public function salesnotesinsertupdatedelete($type, $id, $contid, $descr, $relates, $ndate, $ndatetime, $nby, $ntype){
        require_once ('../Model/contact.php');
        $dbobj=new contactdb();
        $em=$dbobj->sales_notes_insert_update_delete($type, $id, $contid, $descr, $relates, $ndate, $ndatetime, $nby, $ntype);
        //$dbobj=null;
        return $em;
    }
    
    public function salesselectnextactionpending($contid){
        require_once ('../Model/contact.php');
        $dbobj=new contactdb();
        $em=$dbobj->sales_select_nextaction_pending($contid);
        //$dbobj=null;
        return $em;
    }
    
    
    public function salesdealupdatestageclosedatedelete($type,$change,$ddatetime,$dby,$dtype,$id){
        require_once ('../Model/contact.php');
        $dbobj=new contactdb();
        $em=$dbobj->sales_deal_update_stage_closedate_delete($type,$change,$ddatetime,$dby,$dtype,$id);
        //$dbobj=null;
        return $em;
    }
    
    
    public function sales_select_contact_alphabet($companyname,$companymailid){
        require_once ('../Model/contact.php');
        $dbobj=new contactdb();
        $em=$dbobj->sales_select_contact_alphabet($companyname,$companymailid);
        return $em;
    }
    
    
    public function sales_select_employee_contact_alphabet($companyname,$adminemailid){
        require_once ('../Model/contact.php');
        $dbobj=new contactdb();
        $em=$dbobj->sales_select_employee_contact_alphabet($companyname,$adminemailid);
        return $em;
    }
    
    public function sales_select_organization_alphabet($companyname,$companymailid){
        require_once ('../Model/contact.php');
        $dbobj=new contactdb();
        $em=$dbobj->sales_select_organization_alphabet($companyname,$companymailid);
        return $em;
    }
    
    
    public function sales_select_employee_contact_org_alphabet($companyname,$adminemailid){
        require_once ('../Model/contact.php');
        $dbobj=new contactdb();
        $em=$dbobj->sales_select_employee_contact_org_alphabet($companyname,$adminemailid);
        return $em;
    }
    
    public function sales_select_contact_organization($companyname,$companymailid){
        require_once ('../Model/contact.php');
        $dbobj=new contactdb();
        $em=$dbobj->sales_select_contact_organization($companyname,$companymailid);
        return $em;
    }
    
    public function sales_employee_select_all($companyname,$adminemailid,$tablename1,$type){
        require_once ('../Model/contact.php');
        $dbobj=new contactdb();
        $em=$dbobj->sales_employee_select_all($companyname,$adminemailid,$tablename1,$type);
        return $em;
    }
    
    public function sales_contact_star_update($cid,$value){
        require_once ('../Model/contact.php');
        $dbobj=new contactdb();
        $em=$dbobj->sales_contact_star_update($cid,$value);
        return $em;
    }
    
    
    public function salesselectnextactiongetid($contid,$nadatetime){
        require_once ('../Model/contact.php');
        $dbobj=new contactdb();
        $em=$dbobj->sales_select_nextaction_get_id($contid,$nadatetime);
        //$dbobj=null;
        foreach($em as $row){
            $id=$row['id'];
        }
        return $id;
    }
    
    public function salesselectdealgetid($contid,$nadatetime){
        require_once ('../Model/contact.php');
        $dbobj=new contactdb();
        $em=$dbobj->sales_select_deal_get_id($contid,$nadatetime);
        //$dbobj=null;
        foreach($em as $row){
            $id=$row['id'];
        }
        return $id;
    }
    
    public function salesselectcallgetid($contid,$nadatetime){
        require_once ('../Model/contact.php');
        $dbobj=new contactdb();
        $em=$dbobj->sales_select_call_get_id($contid,$nadatetime);
        //$dbobj=null;
        foreach($em as $row){
            $id=$row['id'];
        }
        return $id;
    }
    
    public function salesselectnotegetid($contid,$nadatetime){
        require_once ('../Model/contact.php');
        $dbobj=new contactdb();
        $em=$dbobj->sales_select_note_get_id($contid,$nadatetime);
        //$dbobj=null;
        foreach($em as $row){
            $id=$row['id'];
        }
        return $id;
    }
}
?>


<?php
if(isset($_POST['insert_contact'])){
    
    require_once('../Model/address.php');
    $objaddress=new addressdb();
    require_once('../Model/sales.php');
    $objsales=new salesdb();
    require_once ('../Model/contact.php');
        $dbobj=new contactdb();
    $ccont=$objsales->sales_select_all($companyname, $companymailid, "sales_contact", "all");
    $cont_count=$ccont->rowCount();
    
    $firstname=$_POST['firstname'];
    $lastname=$_POST['lastname'];
    $cont_organization=$_POST['cont_organization'];
    
    $contfirstname1=str_replace(' ', '', $firstname);
    $contlastname1=str_replace(' ', '', $lastname);
    $contorganization1=str_replace(' ', '', $cont_organization);
    $companynamehgu1=str_replace(' ', '', $companyname);
    if($contfirstname1==""){
        $contfirstname1="V";
    }
    if($contlastname1==""){
        $contlastname1="E";
    }
    if($contorganization1==""){
        $contorganization1="L";
    }
    $contid=$companynamehgu1."_".$contfirstname1[0]."_".$contlastname1[0]."_".$contorganization1[0]."_".$cont_count;
    $corg=$objsales->sales_select_all($companyname, $adminemailid, "sales_organization", "all");
    $cont_org=$corg->rowCount();
    $orgid=str_replace(' ', '', $contorganization1)."_".$cont_org."_".$companynamehgu1;
    
    $cont_make_private=$_POST['cont_make_private'];
    if(($cont_make_private=="on")||($contmakeprivate=="yes")){
        $contmakeprivate="yes";
    }else{
        $contmakeprivate="no";
    }
    $cont_title=$_POST['cont_title'];
    $cont_job_title=$_POST['cont_job_title'];
    $cont_address=$_POST['cont_address'];
    $cont_country=$_POST['cont_country'];
    $cont_state=$_POST['cont_state'];
    $cont_city=$_POST['cont_city'];
    $cont_pincode=$_POST['cont_pincode'];
    $cont_status=$_POST['cont_status'];
    $cont_tag=$_POST['cont_tag'];
    $cont_lead=$_POST['cont_lead'];
    $cont_background=$_POST['cont_background'];
    $cont_owner=$_POST['cont_owner'];
    $cont_birthday=$_POST['cont_birthday'];
    date_default_timezone_set("Asia/Kolkata");
    $contdatetime=date("Y-m-d H:i:s");
        $em=$dbobj-> sales_insert_contact($companyname, $companymailid, $contid, $cont_title, $firstname, $lastname, $cont_job_title, $cont_address, $cont_city, $cont_state, $cont_country, $cont_pincode, $cont_status, $cont_tag, $cont_lead, $cont_background, $cont_owner, $contmakeprivate, $cont_birthday, $contdatetime, $createby, $createtype);
        print_r($em);
        if($em=="yes"){
        require_once ('sales.php');
        $ctrlobj=new salesctrl();
        $cr=$ctrlobj->salesselectedid("sales_contact", $contid);  
        $count=$cr->rowCount();
        require_once ('../Model/organization.php');
        $dbobj1=new organizationdb();
        
    $cont_organization1=$_POST['cont_organization1'];
    $cont_org_desc=$_POST['cont_org_desc'];
    $cont_org_phone=$_POST['cont_org_phone'];
    $cont_org_url=$_POST['cont_org_url'];
    $cont_org_address=$_POST['cont_org_address'];
    $cont_org_country=$_POST['cont_org_country'];
    $cont_org_state=$_POST['cont_org_state'];
    $cont_org_city=$_POST['cont_org_city'];
    $cont_org_pincode=$_POST['cont_org_pincode'];
    
         $result1=$dbobj1->sales_insert_organization($companyname, $companymailid, $orgid, $contid, $cont_organization, $cont_org_desc, $cont_org_phone, $cont_org_url, $cont_org_address, $cont_org_city, $cont_org_state, $cont_org_country, $cont_org_pincode, $createby, $createtype, $contdatetime);   
        
        
            print_r($result1);
    $cont_phone_number=$_POST['cont_phone_number'];
    $cont_phone_type=$_POST['cont_phone_type'];
    
        require_once ('../Model/phone_email_url.php');
        $dbobj2=new phone_email_urldb();
        $contphone=json_decode($cont_phone_number);
        $contphonetype=json_decode($cont_phone_type);
        for($i=0;$i<count($contphone);$i++){
            $name=$contphone[$i];
            if($name!=""){
            $type=$contphonetype[$i];
            $result2=$dbobj2->sales_insert_phone_email_url("sales_phone", $companyname, $companymailid, $contid, $name, $type, $createby, $createtype, $contdatetime);
            print_r($result2);
            }
            
        }
        
    $cont_email_name=$_POST['cont_email_name'];
    $cont_email_type=$_POST['cont_email_type'];
    
        $contemail=json_decode($cont_email_name);
        $contemailtype=json_decode($cont_email_type);
        for($i=0;$i<count($contemail);$i++){
            $name=$contemail[$i];
            if($name!=""){
            $type=$contemailtype[$i];
            $result2=$dbobj2->sales_insert_phone_email_url("sales_email", $companyname, $companymailid, $contid, $name, $type, $createby, $createtype, $contdatetime);
            print_r($result2);
            }
            
        }
    
    $cont_url_name=$_POST['cont_url_name'];
    $cont_url_type=$_POST['cont_url_type'];
    
        $conturl=json_decode($cont_url_name);
        $conturltype=json_decode($cont_url_type);
        for($i=0;$i<count($conturl);$i++){
            $name=$conturl[$i];
            if($name!=""){
            $type=$conturltype[$i];
            $result2=$dbobj2->sales_insert_phone_email_url("sales_url", $companyname, $companymailid, $contid, $name, $type, $createby, $createtype, $contdatetime);
            print_r($result2);
            }
            
        }
        }
}
?>




<?php
if(isset($_POST['update_contact'])){
    
    require_once('../Model/address.php');
    $objaddress=new addressdb();
    require_once('../Model/sales.php');
    $objsales=new salesdb();
    require_once ('../Model/contact.php');
    $dbobj=new contactdb();
    $ccont=$objsales->sales_select_all($companyname, $companymailid, "sales_contact", "all");
    $cont_count=$ccont->rowCount();
    
    $firstname=$_POST['firstname'];
    $lastname=$_POST['lastname'];
    $cont_organization=$_POST['cont_organization'];
    
    $contfirstname1=str_replace(' ', '', $firstname);
    $contlastname1=str_replace(' ', '', $lastname);
    $contorganization1=str_replace(' ', '', $cont_organization);
    if($contfirstname1==""){
        $contfirstname1="V";
    }
    if($contlastname1==""){
        $contlastname1="E";
    }
    if($contorganization1==""){
        $contorganization1="L";
    }
    $contid=$_POST['cont_id'];
    $corg=$objsales->sales_select_all($companyname, $companymailid, "sales_organization", "all");
    $cont_org=$corg->rowCount();
    
    $cont_make_private=$_POST['cont_make_private'];
    if(($cont_make_private=="on")||($contmakeprivate=="yes")){
        $contmakeprivate="yes";
    }else{
        $contmakeprivate="no";
    }
    $cont_title=$_POST['cont_title'];
    $cont_job_title=$_POST['cont_job_title'];
    $cont_address=$_POST['cont_address'];
    $cont_country=$_POST['cont_country'];
    $cont_state=$_POST['cont_state'];
    $cont_city=$_POST['cont_city'];
    $cont_pincode=$_POST['cont_pincode'];
    $cont_status=$_POST['cont_status'];
    $cont_tag=$_POST['cont_tag'];
    $cont_lead=$_POST['cont_lead'];
    $cont_background=$_POST['cont_background'];
    $cont_owner=$_POST['cont_owner'];
    $cont_birthday=$_POST['cont_birthday'];
    date_default_timezone_set("Asia/Kolkata");
    $contdatetime=date("Y-m-d H:i:s");
    $em=$dbobj-> sales_update_contact($companyname, $companymailid, $contid, $cont_title, $firstname, $lastname, $cont_job_title, $cont_address, $cont_city, $cont_state, $cont_country, $cont_pincode, $cont_status, $cont_tag, $cont_lead, $cont_background, $cont_owner, $contmakeprivate, $cont_birthday, $contdatetime, $createby, $createtype);
    print_r($em);
    if($em=="yes"){
    require_once ('sales.php');
    $ctrlobj=new salesctrl();
    $cr=$ctrlobj->salesselectedid("sales_contact", $contid);  
    $count=$cr->rowCount();
    require_once ('../Model/organization.php');
    $dbobj1=new organizationdb();
        
    $cont_organization1=$_POST['cont_organization1'];
    $cont_org_desc=$_POST['cont_org_desc'];
    $cont_org_phone=$_POST['cont_org_phone'];
    $cont_org_url=$_POST['cont_org_url'];
    $cont_org_address=$_POST['cont_org_address'];
    $cont_org_country=$_POST['cont_org_country'];
    $cont_org_state=$_POST['cont_org_state'];
    $cont_org_city=$_POST['cont_org_city'];
    $cont_org_pincode=$_POST['cont_org_pincode'];
    
        
    $orgid=$_POST['oid'];
    
    require_once ('../Model/phone_email_url.php');
    $dbobj2=new phone_email_urldb();
    $dbobj2->sales_url_phone_email_delete("sales_phone", $contid);
    $dbobj2->sales_url_phone_email_delete("sales_email", $contid);
    $dbobj2->sales_url_phone_email_delete("sales_url", $contid);
        
        
        if($orgid!=""){
        $result1=$dbobj1->sales_update_organization($companyname, $companymailid, $orgid, $contid, $cont_organization1, $cont_org_desc, $cont_org_phone, $cont_org_url, $cont_org_address, $cont_org_city, $cont_org_state, $cont_org_country, $cont_org_pincode, $createby, $createtype, $contdatetime);
        }else{
        require_once('../Control/sales.php');
        $objsales=new salesctrl();
        $corg=$objsales->salesselectall($companyname, $companymailid, "sales_organization", "all");
        $cont_org=$corg->rowCount();
        $orgid=str_replace(' ', '', $orgname)."_".$cont_org;
        $result1=$dbobj1->sales_insert_organization($companyname, $companymailid, $orgid, $contid, $cont_organization1, $cont_org_desc, $cont_org_phone, $cont_org_url, $cont_org_address, $cont_org_city, $cont_org_state, $cont_org_country, $cont_org_pincode, $createby, $createtype, $contdatetime);    
        }
            print_r($result1);
    $cont_phone_number=$_POST['cont_phone_number'];
    $cont_phone_type=$_POST['cont_phone_type'];
    
        require_once ('../Model/phone_email_url.php');
        $dbobj2=new phone_email_urldb();
        $contphone=json_decode($cont_phone_number);
        $contphonetype=json_decode($cont_phone_type);
        for($i=0;$i<count($contphone);$i++){
            $name=$contphone[$i];
            if($name!=""){
            $type=$contphonetype[$i];
            $result2=$dbobj2->sales_insert_phone_email_url("sales_phone", $companyname, $companymailid, $contid, $name, $type, $createby, $createtype, $contdatetime);
            print_r($result2);
            }
            
        }
        
    $cont_email_name=$_POST['cont_email_name'];
    $cont_email_type=$_POST['cont_email_type'];
    
        $contemail=json_decode($cont_email_name);
        $contemailtype=json_decode($cont_email_type);
        for($i=0;$i<count($contemail);$i++){
            $name=$contemail[$i];
            if($name!=""){
            $type=$contemailtype[$i];
            $result2=$dbobj2->sales_insert_phone_email_url("sales_email", $companyname, $companymailid, $contid, $name, $type, $createby, $createtype, $contdatetime);
            print_r($result2);
            }
            
        }
    
    $cont_url_name=$_POST['cont_url_name'];
    $cont_url_type=$_POST['cont_url_type'];
    
        $conturl=json_decode($cont_url_name);
        $conturltype=json_decode($cont_url_type);
        for($i=0;$i<count($conturl);$i++){
            $name=$conturl[$i];
            if($name!=""){
            $type=$conturltype[$i];
            $result2=$dbobj2->sales_insert_phone_email_url("sales_url", $companyname, $companymailid, $contid, $name, $type, $createby, $createtype, $contdatetime);
            print_r($result2);
            }
            
        }
        }
}
?>

<?php
if(isset($_POST['staron'])){
    echo $value=$_POST['staron'];
    $cont_id=$_POST['cont_id'];
    
    require_once ('../Model/contact.php');
    $dbobj=new contactdb();
    date_default_timezone_set("Asia/Kolkata");
    $DateandTime=date("Y-m-d H:i:s");
    $result=$dbobj->sales_contact_star_update($cont_id, "1");
}
if(isset($_POST['staroff'])){
    $value=$_POST['staroff'];
    $cont_id=$_POST['cont_id'];
    
    require_once ('../Model/contact.php');
    $dbobj=new contactdb();
    date_default_timezone_set("Asia/Kolkata");
    $DateandTime=date("Y-m-d H:i:s");
    $result=$dbobj->sales_contact_star_update($cont_id, "0");
    
}
?>

<?php
if(isset($_POST['updatephoto'])){
    $cont_id=$_POST['cont_id'];
    $file_name = $_FILES['files']['name'];
    $target_dir = "../View/Image/";
    $target_file = $target_dir . $file_name;
    move_uploaded_file($_FILES['files']['tmp_name'], $target_file);
    $logopath=$target_file;
    require_once ('../Model/contact.php');
    $dbobj=new contactdb();
    $result=$dbobj->sales_update_contact_photo($cont_id, $logopath);
    //print_r($result);
}
?>

<?php
if(isset($_POST['deletecontact'])){
    $companyname=$_SESSION['companyname'];
    $companytype=$_SESSION['companytype'];
    $companymailid=$_SESSION['companymailid'];
    $adminemailid=$_SESSION['emailid'];
    $responsible=$_SESSION['responsible_employee'];
    $createby=$_SESSION['emailid'];
    $createtype=$_SESSION['employeetype'];
    require_once ('../Model/contact.php');
    $dbobj=new contactdb();
    date_default_timezone_set("Asia/Kolkata");
    $DateandTime=date("Y-m-d H:i:s");
    $cont=$_POST['deletecontact'];
    $cont_array=array();
    $cont_array=explode("@#", $cont);
    for($i=0;$i<count($cont_array);$i++){
        $contid=$cont_array[$i];
        $result1=$dbobj->sales_delete_contact($contid, $createby, $createtype, $DateandTime);  
    }
    return $result1;
}
?>