<?php
session_start();
include('sesssion_clear.php');
$adminemailid=$_SESSION['emailid'];
$companyname=$_SESSION['companyname'];
$companytype=$_SESSION['companytype'];
$createtype=$_SESSION['employeetype'];

if(($adminemailid !="")&&($companyname!="")){
if(isset($_POST['updatetag'])){
    $tag_id=$_POST['updatetag'];
    $cont_id=$_POST['cont_id'];
    
    require_once ('../Control/contact.php');
    $ctrlobj=new contactctrl();
    $result=$ctrlobj->salesupdatecontacttagstatusblob($cont_id, "tag", $tag_id);
    if($result=="success"){
        echo "yes";
    }
}
if(isset($_POST['updatestatus'])){
    $status_id=$_POST['updatestatus'];
    $cont_id=$_POST['cont_id'];
    
    require_once ('../Control/contact.php');
    $ctrlobj=new contactctrl();
    $result=$ctrlobj->salesupdatecontacttagstatusblob($cont_id, "status", $status_id);
    if($result=="success"){
        echo "yes";
    }
}
if(isset($_POST['updatesignup'])){
    $email_id1223=$_POST['updatesignup'];
    $cont_id=$_POST['cont_id'];
    
    require_once ('../Control/contact.php');
    $ctrlobj=new contactctrl();
    $result=$ctrlobj->salesupdatecontacttagstatusblob($cont_id, "signup", $email_id1223);
    if($result=="success"){
        echo "yes";
    }
}
if(isset($_POST['updateimage'])){
    $img=$_POST['updateimage'];
    $cont_id=$_POST['cont_id'];
    
    require_once ('../Control/contact.php');
    $ctrlobj=new contactctrl();
    $result=$ctrlobj->salesupdatecontacttagstatusblob($cont_id, "status", $img);
    if($result=="success"){
        echo "yes";
    }
}
if(isset($_POST['insertcall'])){
    $cdate=$_POST['insertcall'];
    $cphone=$_POST['callphone'];
    $cont_id=$_POST['cid'];
    $cdescr=$_POST['calldesc'];
    $cresult=$_POST['callresult'];
    $ctime=$_POST['calltime'];
    $sendemailcheckbox=$_POST['sendemailcheckbox'];
    
    require_once ('../Control/contact.php');
    $ctrlobj=new contactctrl();
    date_default_timezone_set("Asia/Kolkata");
    $DateandTime=date("Y-m-d H:i:s");
    $result=$ctrlobj->salescallinsertupdatedelete("insert", "", $cont_id, $cphone, $cdescr, $cresult, $cdate, $ctime, $DateandTime, $adminemailid, $createtype);
    if($result=="success"){
        $result1=$ctrlobj->salesselectcallgetid($cont_id,$DateandTime);
        echo $result1;
        
        
        include('../Model/configuration.php');
        require_once('../Control/employee.php');
        $objemployee=new employeectrl();
        require_once('../Control/activity.php');
        $objactivity=new activityctrl();
        for($gfg=0;$gfg<count($sendemailcheckbox);$gfg++){
            $eid=$sendemailcheckbox[$gfg];
            $contactname=$objemployee->salesemployeename($eid);
            $rowact=$objactivity->salescontactdetails($cont_id);
            foreach($rowact as $row_act){
                $cont_first_name=$row_act['cont_first_name'];
                $cont_last_name=$row_act['cont_last_name'];
                $org_name=$row_act['org_name'];
            }
            $lastshownote="";
            if($cont_first_name!=""){
                $lastshownote.=$cont_first_name." ";
            }
            $lastshownote.=$cont_last_name;
            $to = $eid;
            
            $sqlans1="SELECT `c_ans_name` FROM `sales_call_answer_type` WHERE `id`='".$cresult."'";
            $resultans1 = $pdo->query($sqlans1);
            foreach($resultans1 as $rowans1){
                $c_ans_name=$rowans1['c_ans_name'];
            }
            if(strtoupper($c_ans_name)==strtoupper("Interested")){
                $coversation="<b>Call:</b> Conversation: Interested, called ".$lastshownote." at ".$ctime." <br>";
            }else if(strtoupper($c_ans_name)==strtoupper(" Not Interested")){
                $coversation="<b>Call:</b> Conversation: Not Interested, called ".$lastshownote." at ".$ctime." <br>";
            }else{
                $coversation="<b>Call:</b>  ".$c_ans_name.", called ".$lastshownote." at ".$ctime." <br>";
            }
            $coversation.="<b>Note: </b>".$cdescr;
            $subject = $companyname." added a call in Fieldcloud Sales";
            $htmlContent = '
                <html>
                <head>
                    <title></title>
                </head>
                <body style="background-color:#f4f4f4;    padding: 20px;">
                    <center>
                    <div style="max-width:600px;padding-bottom:30px;">
                    <div style="float:right;color:grey;"><b>FieldCloud Sales</b></div></div>
                    <div style="max-width:600px;height:100%;">
                        <div style="background-color: #ffffff;border-top: 1px solid #ff9300;border-bottom: 1px solid #ff9300;padding: 20px;border-collapse: collapse;text-align: left;">
                            <b><span style="color:#ffa200">✔</span>'.$companyname.'  added a call to:</b><br><br><a style="color:##26abe2;text-decoration: underline;cursor:pointer;" href="http://fieldcloud.in/Sales/">'.$contactname.'</a><br>'.$coversation.'
                        </div>
                        <div style="text-align:left;font-size:10px;color:grey;">Note: You were sent this email because CCL L. wanted to let you know the call was added.</div>
                    </div>
                    </center>
                </body>
                </html>';
            
            // Set content-type header for sending HTML email
            $headers = "MIME-Version: 1.0" . "\r\n";
            $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
            
            // Additional headers
            $headers .= 'From: b2lmobitechpvtltd@gmail.com' . "\r\n";
            $headers .= 'Cc: velemailid@gmail.com' . "\r\n";
            $headers .= 'Bcc: velmurugan9cs24@gmail.com' . "\r\n";
            
            // Send email
            
            if(mail($to,$subject,$htmlContent,$headers)){
                $successMsg = 'Email has sent successfully.';
            }else{
                $errorMsg = 'Email sending fail.';
            }
        }
        
    }
}
if(isset($_POST['updatecall'])){
    $id=$_POST['updatecall'];
    $cdate=$_POST['calldate'];
    $cphone=$_POST['callphone'];
    $cont_id=$_POST['cid'];
    $cdescr=$_POST['calldesc'];
    $cresult=$_POST['callresult'];
    $ctime=$_POST['calltime'];
    require_once ('../Control/contact.php');
    $ctrlobj=new contactctrl();
    date_default_timezone_set("Asia/Kolkata");
    $DateandTime=date("Y-m-d H:i:s");
    $result=$ctrlobj->salescallinsertupdatedelete("update", $id, $cont_id, $cphone, $cdescr, $cresult, $cdate, $ctime, $DateandTime, $adminemailid, $createtype);
    //echo 'salescallinsertupdatedelete("update", "'.$id.'", "'.$cont_id.'", "'.$cphone.'", "'.$cdescr.'", "'.$cresult.'", "'.$cdate.'", "'.$ctime.'", "'.$DateandTime.'", "'.$adminemailid.'", $createtype)';
    if($result=="success"){
        echo "yes";
    }
}
if(isset($_POST['deletecall'])){
    $id=$_POST['deletecall'];
    
    require_once ('../Control/contact.php');
    $ctrlobj=new contactctrl();
    date_default_timezone_set("Asia/Kolkata");
    $DateandTime=date("Y-m-d H:i:s");
    $result=$ctrlobj->salescallinsertupdatedelete("delete", $id, "", "", "", "", "", "", $DateandTime, $adminemailid, $createtype);
    if($result=="success"){
        echo "yes";
    }
}
if(isset($_POST['insertdeal'])){
    $ddealname=$_POST['insertdeal'];
    $contid=$_POST['contid'];
    $ddate=$_POST['dealdate'];
    $dealby=$_POST['dealby_id'];
    $damount=$_POST['dealamount'];
    $dmonth=$_POST['dealmonth'];
    $dclosedate=$_POST['dealclosedate'];
    $dstage=$_POST['dealstageid'];
    $ddescr=$_POST['dealdesc'];
    $dcommissionpercentage=$_POST['dealcommission'];
    $dcommissionamount=$_POST['dealcommissionamount'];
    require_once ('../Control/contact.php');
    $ctrlobj=new contactctrl();
    date_default_timezone_set("Asia/Kolkata");
    $DateandTime=date("Y-m-d H:i:s");
    $result=$ctrlobj->salesdealinsertupdatedelete("insert", "", $contid, $ddealname, $damount, $dmonth, $dcommissionpercentage, $dcommissionamount, $ddescr, $dstage, $ddate, $dclosedate, $DateandTime, $adminemailid, $createtype, $dealby);
    //echo 'salesdealinsertupdatedelete("insert", "", '.$contid.', '.$ddealname.', '.$damount.', '.$dmonth.', '.$dcommissionpercentage.', '.$dcommissionamount.', '.$ddescr.', '.$dstage.', '.$ddate.', '.$dclosedate.', '.$DateandTime.', '.$adminemailid.', $createtype, '.$dealby.')';
    print_r($result);
    if($result=="success"){
        $result1=$ctrlobj->salesselectdealgetid($contid,$DateandTime);
        echo $result1;
    }
}
if(isset($_POST['updatedeal'])){
    $did=$_POST['updatedeal'];
    $ddealname=$_POST['dealname'];
    $contid=$_POST['contid'];
    $ddate=$_POST['dealdate'];
    $dealby=$_POST['dealby_id'];
    $damount=$_POST['dealamount'];
    $dmonth=$_POST['dealmonth'];
    $dclosedate=$_POST['dealclosedate'];
    $dstage=$_POST['dealstageid'];
    $ddescr=$_POST['dealdesc'];
    $dcommissionpercentage=$_POST['dealcommission'];
    $dcommissionamount=$_POST['dealcommissionamount'];
    require_once ('../Control/contact.php');
    $ctrlobj=new contactctrl();
    date_default_timezone_set("Asia/Kolkata");
    $DateandTime=date("Y-m-d H:i:s");
    $result=$ctrlobj->salesdealinsertupdatedelete("update", $did, $contid, $ddealname, $damount, $dmonth, $dcommissionpercentage, $dcommissionamount, $ddescr, $dstage, $ddate, $dclosedate, $DateandTime, $adminemailid, $createtype, $dealby);
    //echo 'salesdealinsertupdatedelete("insert", "", '.$contid.', '.$ddealname.', '.$damount.', '.$dmonth.', '.$dcommissionpercentage.', '.$dcommissionamount.', '.$ddescr.', '.$dstage.', '.$ddate.', '.$dclosedate.', '.$DateandTime.', '.$adminemailid.', $createtype, '.$dealby.')';
    if($result=="success"){
        echo "yes";
    }
}
if(isset($_POST['updatedealstage'])){
    $dstage=$_POST['updatedealstage'];
    $id=$_POST['dealstageid'];
    
    require_once ('../Control/contact.php');
    $ctrlobj=new contactctrl();
    date_default_timezone_set("Asia/Kolkata");
    $DateandTime=date("Y-m-d H:i:s");
    $result=$ctrlobj->salesdealupdatestageclosedatedelete("stage", $dstage, $DateandTime, $adminemailid, $createtype, $id);
   //print_r($result);
    if($result=="success"){
        echo "yes";
    }
}
if(isset($_POST['updatedealclosedate'])){
    $dclosedate=$_POST['updatedealclosedate'];
    $id=$_POST['dealstageid'];
    
    require_once ('../Control/contact.php');
    $ctrlobj=new contactctrl();
    date_default_timezone_set("Asia/Kolkata");
    $DateandTime=date("Y-m-d H:i:s");
    $result=$ctrlobj->salesdealupdatestageclosedatedelete("closedate", $dclosedate, $DateandTime, $adminemailid, $createtype, $id);
    if($result=="success"){
        echo "yes";
    }
}
if(isset($_POST['deletedeal'])){
    $id=$_POST['deletedeal'];
    
    require_once ('../Control/contact.php');
    $ctrlobj=new contactctrl();
    date_default_timezone_set("Asia/Kolkata");
    $DateandTime=date("Y-m-d H:i:s");
    $result=$ctrlobj->salesdealupdatestageclosedatedelete("delete", "", $DateandTime, $adminemailid, $createtype, $id);
    if($result=="success"){
        echo "yes";
    }
}
if(isset($_POST['insertnextaction'])){//nextactiondate nextactiontime cid
    $nadescr=$_POST['insertnextaction'];
    $nadate=$_POST['nextactiondate'];
    $natime=$_POST['nextactiontime'];
    $contid=$_POST['cid'];
    $naassign=$_POST['naassign'];
    $selectoption=$_POST['selectoption'];
    if($selectoption=="7 days"){
        $selectoption="Date";
    }
    if($selectoption=="2 Weeks Time"){
        $selectoption="Date";
    }
    if($selectoption=="30 days Time"){
        $selectoption="Date";
    }
    if($selectoption=="31 days Time"){
        $selectoption="Date";
    }
    if($selectoption=="Tomorrow"){
        $selectoption="Date";
    }
    if($selectoption=="ASAP"){
        $nadate="0000-00-00";
        $natime="00:00:00";
    }
    if($selectoption=="Waiting"){
        $nadate="0000-00-00";
        $natime="00:00:00";
    }
    
    require_once ('../Control/contact.php');
    $ctrlobj=new contactctrl();
    date_default_timezone_set("Asia/Kolkata");
    $DateandTime=date("Y-m-d H:i:s");
    $day=date('D');
    $month=date('M');
    $year=date('Y');
    $date=date('d');
    $asdate=$nadate[8].$nadate[8];
    $months = array(1 => 'Jan.', 2 => 'Feb.', 3 => 'Mar.', 4 => 'Apr.', 5 => 'May', 6 => 'Jun.', 7 => 'Jul.', 8 => 'Aug.', 9 => 'Sep.', 10 => 'Oct.', 11 => 'Nov.', 12 => 'Dec.');
    $m=intval($nadate[5].$nadate[6]);
    $asmonth=$months[$m];
    $result=$ctrlobj->salesnextactioninsertupdatedelete("insert", "", $contid, $nadescr, "pending", $nadate, $DateandTime, $adminemailid, $createtype, $natime, $naassign, $selectoption);
    if($result=="success"){
        $result1=$ctrlobj->salesselectnextactiongetid($contid,$DateandTime);
        echo "#@".$result1;
        include('../Model/configuration.php');
        require_once('../Control/employee.php');
        $objemployee=new employeectrl();
        require_once('../Control/activity.php');
        $objactivity=new activityctrl();
            $rowact=$objactivity->salescontactdetails($contid);
            foreach($rowact as $row_act){
                $cont_first_name=$row_act['cont_first_name'];
                $cont_last_name=$row_act['cont_last_name'];
                $org_name=$row_act['org_name'];
            }
            $lastshownote="";
            if($cont_first_name!=""){
                $lastshownote.=$cont_first_name." ";
            }
            $lastshownote.=$cont_last_name;
            $to = $naassign;
            
            $coversation="<b>Note: </b>".$descr;
            $subject = "Next Action assigned to You in ".$companyname;
            $htmlContent = '
                <html>
                <head>
                    <title></title>
                </head>
                <body style="background-color:#f4f4f4;    padding: 20px;">
                    <center>
                    <div style="max-width:600px;padding-bottom:30px;">
                    <div style="float:right;color:grey;"><b>FieldCloud Sales</b></div></div>
                    <div style="max-width:600px;height:100%;">
                        <div style="background-color: #ffffff;padding: 20px;border-collapse: collapse;text-align: left;">
                            <b><h1>'.$companyname.'  assigned Next Action to You</b></h1><br><br>
                            Today is '.$day.','.$month.$date.','.$year.'<br>
                            Email notification from <a style="color:##26abe2;text-decoration: underline;cursor:pointer;" href="http://fieldcloud.in/Sales/">Fieldcloud Sales.</a><br>
                            <h3>Next Action for following contact has been assigned to you:</h3>
                            <div style="background-color:grey;padding:4px;"><span style="text-align:left;color:#15c;">'.$lastshownote.'</span>
                            <span style="text-align:center;">
                            <span style="background-color:#bdac92;padding: 2px 8px 2px 4px;">'.$asmonth.' '.$asdate.'</span> &nbsp;'.$nadescr.'</span></div>
                            <br><br><br>
                            <div style="border-top: 1px solid #cccccc;color: #808080;font-size: 12px;padding: 20px 0 60px 0;">This is an automated email sent from your account and ONLY to your email address.<br>Delivered by
                            <a style="text-decoration: underline;cursor:pointer;" href="http://fieldcloud.in/Sales/">Fieldcloud Sales.</a></div>
                        </div>
                    </div>
                    </center>
                </body>
                </html>';
            
            // Set content-type header for sending HTML email
            $headers = "MIME-Version: 1.0" . "\r\n";
            $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
            
            // Additional headers
            $headers .= 'From: b2lmobitechpvtltd@gmail.com' . "\r\n";
            $headers .= 'Cc: velemailid@gmail.com' . "\r\n";
            $headers .= 'Bcc: velmurugan9cs24@gmail.com' . "\r\n";
            
            // Send email
            
            if(mail($to,$subject,$htmlContent,$headers)){
                $successMsg = 'Email has sent successfully.';
            }else{
                $errorMsg = 'Email sending fail.';
            }
    }
}
if(isset($_POST['insertnextaction1'])){//nextactiondate nextactiontime cid
    $nadescr=$_POST['insertnextaction1'];
    $nadate=$_POST['nextactiondate'];
    $natime=$_POST['nextactiontime'];
    $contid=$_POST['cid'];
    $naassign=$_POST['naassign'];
    $selectoption=$_POST['selectoption'];
    if($selectoption=="7 days"){
        $selectoption="Date";
    }
    if($selectoption=="2 Weeks Time"){
        $selectoption="Date";
    }
    if($selectoption=="30 days Time"){
        $selectoption="Date";
    }
    if($selectoption=="31 days Time"){
        $selectoption="Date";
    }
    if($selectoption=="Tomorrow"){
        $selectoption="Date";
    }
    if($selectoption=="ASAP"){
        $nadate="0000-00-00";
        $natime="00:00:00";
    }
    if($selectoption=="Waiting"){
        $nadate="0000-00-00";
        $natime="00:00:00";
    }
    
    require_once ('../Control/contact.php');
    $ctrlobj=new contactctrl();
    date_default_timezone_set("Asia/Kolkata");
    $DateandTime=date("Y-m-d H:i:s");
    $result=$ctrlobj->salesnextactioninsertupdatedelete("insert1", "", $contid, $nadescr, "pending", $nadate, $DateandTime, $adminemailid, $createtype, $natime, $naassign, $selectoption);
    if($result=="success"){
        $result1=$ctrlobj->salesselectnextactiongetid($contid,$DateandTime);
        echo "#@".$result1;
    }
}
if(isset($_POST['updatenextaction'])){
    $nadescr=$_POST['updatenextaction'];
    $nadate=$_POST['nextactiondate'];
    $natime=$_POST['nextactiontime'];
    $contid=$_POST['cid'];
    $id=$_POST['nid'];
    $naassign=$_POST['naassign'];
    $selectoption=$_POST['selectoption'];
    
    require_once ('../Control/contact.php');
    $ctrlobj=new contactctrl();
    date_default_timezone_set("Asia/Kolkata");
    $DateandTime=date("Y-m-d H:i:s");
    $result=$ctrlobj->salesnextactioninsertupdatedelete("update", $id, $contid, $nadescr, "pending", $nadate, $DateandTime, $adminemailid, $createtype, $natime, $naassign, $selectoption);
    echo 'salesnextactioninsertupdatedelete("update", "'.$id.'", "'.$contid.'", "'.$nadescr.'", "pending", "'.$nadate.'", "'.$DateandTime.'", "'.$adminemailid.'", "'.$createtype.'", "'.$natime.'", "'.$naassign.'", "'.$selectoption.'")';
    if($result=="success"){
        echo "#@yes";
    }
}
if(isset($_POST['updatenextaction1'])){
    $nadescr=$_POST['updatenextaction1'];
    $nadate=$_POST['nextactiondate'];
    $natime=$_POST['nextactiontime'];
    $contid=$_POST['cid'];
    $id=$_POST['nid'];
    $naassign=$_POST['naassign'];
    $selectoption=$_POST['selectoption'];
    
    require_once ('../Control/contact.php');
    $ctrlobj=new contactctrl();
    date_default_timezone_set("Asia/Kolkata");
    $DateandTime=date("Y-m-d H:i:s");
    $result=$ctrlobj->salesnextactioninsertupdatedelete("update1", $id, $contid, $nadescr, "pending", $nadate, $DateandTime, $adminemailid, $createtype, $natime, $naassign, $selectoption);
    if($result=="success"){
        echo "#@yes";
    }
}
if(isset($_POST['deletenextaction'])){
    $id=$_POST['deletenextaction'];
    
    require_once ('../Control/contact.php');
    $ctrlobj=new contactctrl();
    date_default_timezone_set("Asia/Kolkata");
    $DateandTime=date("Y-m-d H:i:s");
    $result=$ctrlobj->salesnextactioninsertupdatedelete("delete", $id, "", "", "", "", $DateandTime, $adminemailid, $createtype, "", "", "");
    if($result=="success"){
        echo "yes";
    }
}
if(isset($_POST['completednextaction'])){
    $id=$_POST['completednextaction'];
    $status=$_POST['status'];
    
    require_once ('../Control/contact.php');
    $ctrlobj=new contactctrl();
    date_default_timezone_set("Asia/Kolkata");
    $DateandTime=date("Y-m-d H:i:s");
    $result=$ctrlobj->salesnextactioninsertupdatedelete("status", $id, "", "", $status, "", $DateandTime, $adminemailid, $createtype, "", "", "");
    //print_r($result);
    if($result=="success"){
        echo "yes";
    }
}
if(isset($_POST['pendingnextaction'])){
    $id=$_POST['pendingnextaction'];
    $status="pending";
    
    require_once ('../Control/contact.php');
    $ctrlobj=new contactctrl();
    date_default_timezone_set("Asia/Kolkata");
    $DateandTime=date("Y-m-d H:i:s");
    $result=$ctrlobj->salesnextactioninsertupdatedelete("status1", $id, "", "", $status, "", $DateandTime, $adminemailid, $createtype, "", "", "");
    //print_r($result);
    if($result=="success"){
        echo "yes";
    }
}
if(isset($_POST['insertnote'])){
    $descr=$_POST['insertnote'];
    $contid=$_POST['cid'];
    $relates=$_POST['notedeal'];
    $ndate=$_POST['date1'];  
    $sendemailcheckbox=$_POST['sendnoteemail'];
    
    require_once ('../Control/contact.php');
    $ctrlobj=new contactctrl();
    date_default_timezone_set("Asia/Kolkata");
    $DateandTime=date("Y-m-d H:i:s");
    $result=$ctrlobj->salesnotesinsertupdatedelete("insert", "", $contid, $descr, $relates, $ndate, $DateandTime, $adminemailid, $createtype);
    if($result=="success"){
        $result1=$ctrlobj->salesselectnotegetid($contid,$DateandTime);
        echo $result1;
        
        include('../Model/configuration.php');
        require_once('../Control/employee.php');
        $objemployee=new employeectrl();
        require_once('../Control/activity.php');
        $objactivity=new activityctrl();
        for($gfg=0;$gfg<count($sendemailcheckbox);$gfg++){
            $eid=$sendemailcheckbox[$gfg];
            $contactname=$objemployee->salesemployeename($eid);
            $rowact=$objactivity->salescontactdetails($contid);
            foreach($rowact as $row_act){
                $cont_first_name=$row_act['cont_first_name'];
                $cont_last_name=$row_act['cont_last_name'];
                $org_name=$row_act['org_name'];
            }
            $lastshownote="";
            if($cont_first_name!=""){
                $lastshownote.=$cont_first_name." ";
            }
            $lastshownote.=$cont_last_name;
            $to = $eid;
            
            $coversation="<b>Note: </b>".$descr;
            $subject = $companyname." added a Note in Fieldcloud Sales";
            $htmlContent = '
                <html>
                <head>
                    <title></title>
                </head>
                <body style="background-color:#f4f4f4;    padding: 20px;">
                    <center>
                    <div style="max-width:600px;padding-bottom:30px;">
                    <div style="float:right;color:grey;"><b>FieldCloud Sales</b></div></div>
                    <div style="max-width:600px;height:100%;">
                        <div style="background-color: #ffffff;border-top: 1px solid #ff9300;border-bottom: 1px solid #ff9300;padding: 20px;border-collapse: collapse;text-align: left;">
                            <b><span style="color:#ffa200">✔</span>'.$companyname.'  added a note to:</b><br><br><a style="color:##26abe2;text-decoration: underline;cursor:pointer;" href="http://fieldcloud.in/Sales/">'.$contactname.'</a><br>'.$coversation.'
                        </div>
                        <div style="text-align:left;font-size:10px;color:grey;">Note: You were sent this email because CCL L. wanted to let you know the note was added.</div>
                    </div>
                    </center>
                </body>
                </html>';
            
            // Set content-type header for sending HTML email
            $headers = "MIME-Version: 1.0" . "\r\n";
            $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
            
            // Additional headers
            $headers .= 'From: b2lmobitechpvtltd@gmail.com' . "\r\n";
            $headers .= 'Cc: velemailid@gmail.com' . "\r\n";
            $headers .= 'Bcc: velmurugan9cs24@gmail.com' . "\r\n";
            
            // Send email
            
            if(mail($to,$subject,$htmlContent,$headers)){
                $successMsg = 'Email has sent successfully.';
            }else{
                $errorMsg = 'Email sending fail.';
            }
        }
        
    }
}
if(isset($_POST['updatenote'])){
    $id=$_POST['updatenote'];
    $contid=$_POST['cid'];
    $descr=$_POST['desc'];
    $relates=$_POST['notedeal'];
    $ndate=$_POST['date1'];  
    $sendnoteemail=$_POST['sendnoteemail'];
    
    require_once ('../Control/contact.php');
    $ctrlobj=new contactctrl();
    date_default_timezone_set("Asia/Kolkata");
    $DateandTime=date("Y-m-d H:i:s");
    $result=$ctrlobj->salesnotesinsertupdatedelete("update", $id, $contid, $descr, $relates, $ndate, $DateandTime, $adminemailid, $createtype);
    if($result=="success"){
        echo "yes";
    }
}
if(isset($_POST['deletenote'])){
    $id=$_POST['deletenote'];
    
    require_once ('../Control/contact.php');
    $ctrlobj=new contactctrl();
    date_default_timezone_set("Asia/Kolkata");
    $DateandTime=date("Y-m-d H:i:s");
    $result=$ctrlobj->salesnotesinsertupdatedelete("delete", $id, "", "", "", "", $DateandTime, $adminemailid, $createtype);
    if($result=="success"){
        echo "yes";
    }
}
if(isset($_POST['close_contact'])){
    $cid=$_POST['close_contact'];
    
    require_once ('../Control/sales.php');
    $ctrlobj=new salesctrl();
    date_default_timezone_set("Asia/Kolkata");
    $DateandTime=date("Y-m-d H:i:s");
    $result=$ctrlobj->sales_contact_update_closedate($cid, $DateandTime,  $adminemailid, $createtype);
    echo "#@".$DateandTime;
}

if(isset($_POST['comment_contact'])){
    $cid=$_POST['comment_contact'];
    $comment=$_POST['comment'];
    
    require_once ('../Control/sales.php');
    $ctrlobj=new salesctrl();
    date_default_timezone_set("Asia/Kolkata");
    $DateandTime=date("Y-m-d H:i:s");
    $result=$ctrlobj->sales_contact_update_closecomment($cid, $comment,  $adminemailid, $createtype, $DateandTime);
    print_r($result);
    if($result=="success"){
        echo "yes";
    }
}


if(isset($_POST['totalnextaction'])){
    $cid=$_POST['totalnextaction'];
    $emp=$_POST['emp'];
    
    include('../Model/configuration.php');
    $sql1="SELECT cont_id FROM `sales_nextaction` WHERE `cont_id`='".$cid."' and `na_assign`='".$emp."' and `na_delete`='no' and `na_status`='pending'";
    $result1 = $pdo->query($sql1);
    echo "#@".$result1->rowcount();
}

?>

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