<?php

defined('_VALID') or die(RESTRICTED_ACCESS);
include_once('../configuration.php');
include_once('class.comments.php');
$commentsObj = new comments($configObj);
$action = $_REQUEST['action'];
$view = $_REQUEST['view'];
$configObj->glTplObj->change_path($configObj->currentModulePath . 'html/templates/');
$configObj->glTplObj->set('configObj', $configObj);
$configObj->glTplObj->set('commentsObj', $commentsObj);
//$configObj->glTplObj->set('contactusTab', true);
$configObj->glLibraryObj->settings();
$paramMain = $configObj->AllmoduleAccess[$configObj->ModuleName];
$configObj->glTplObj->set('paramMain', $paramMain);



switch ($view) {
    case 'newslatter' :
        switch ($action) {

            case 'delete':
                if ($configObj->isAjaxSet) {
                    $commentsObj->is_newslatterused(7);
                }

                $commentsObj->loadCount('CountRowsnews');
                break;

            case 'email':

                if ($_REQUEST['sub'] == 'reply') {
                    $id = $_REQUEST['userid'];
                    $commentsObj->varpostdata = $_REQUEST;
                    $sendmailstatus = $commentsObj->formemailnews($id);
                    $configObj->glLibraryObj->header_redirect('index.php?module=comments&view=newslatter&msg=send');
                } else {
                    echo $configObj->adminContentPanel = $configObj->glTplObj->process('reply_form.tpl.php');
                    exit;
                }
                break;

            case 'updatereaddata':

                $sql = "UPDATE " . DB_PREFIX . "newslatterleads SET chr_read='Y' where int_glcode=" . $_REQUEST['id'];
                $commentsObj->configObj->glDbObj->query($sql);
                echo $_REQUEST['id'];
                exit;
                break;

            case 'export':

                $tablename = "newslatterleads";
                $configObj->glLibraryObj->xlsSQL = $commentsObj->gettabledataData($tablename);
                $configObj->glLibraryObj->fileheader = "<center>Newsletter List\n</center>";
                $configObj->glLibraryObj->filename = "" . SITE_NAME . "_Newsletter_Leads" . "[" . date("Y-m-d") . "].xls";
                $configObj->glLibraryObj->dataArray = $allrecordsset;
                $configObj->glLibraryObj->generateXLSfile();
                break;

            default:
                if ($configObj->AllmoduleAccess['newslatter']['View'] == 'Y') {
                    if ($_REQUEST['msg']) {
                        if ($_REQUEST['msg'] == 'send') {
                            $messagebox = $configObj->glLibraryObj->message("Congrats! The Email has been sent successfully.");
                            $configObj->glTplObj->set('messagebox', $messagebox);
                        }
                    }
                    $commentsObj->load_newslatterleads();
                } else {
                    echo RESTRICTED_ACCESS;
                    exit;
                }
                break;
        }
        break;

    default:
        switch ($action) {
            case 'delete':
                if ($configObj->isAjaxSet) {
                    $commentsObj->is_contactused(7);
                }
                break;
                
                
            case 'insert_comments': 
                
             echo  $commentsObj->insert_comments($_REQUEST['varcomment'],$_REQUEST['varurl']);
             exit;
            break;
        
            case 'changestatus': 
                
             echo  $commentsObj->changestatus();
             exit;
            break;
        
             case 'changepriority': 
                
             echo $commentsObj->changepriority();
             exit;
            break;
        
             case 'insert_admincomments': 
                
             echo  $commentsObj->insert_admincomments($_REQUEST['id']);
             exit;
            break;
        
            case 'viewPopup': 
                
            echo $configObj->glTplObj->process('commentsform_tpl.php');
            exit;
            break;
         case 'addcomment': 
               
            echo $commentsObj->update_admincomments($_REQUEST['id']);
            exit;
            break;

            case 'email':

                if ($_REQUEST['sub'] == 'reply') {
                    $id = $_REQUEST['userid'];
                    $commentsObj->varpostdata = $_REQUEST;
                    $sendmailstatus = $commentsObj->formemail($id);
                    $configObj->glLibraryObj->header_redirect('index.php?module=comments&msg=send');
                } else {
                    echo $configObj->adminContentPanel = $configObj->glTplObj->process('reply_form.tpl.php');
                    exit;
                }
                break;

            case 'export':
                $tablename = "comments";
               
                $configObj->glLibraryObj->xlsSQL = $commentsObj->gettabledataData($tablename);
                $configObj->glLibraryObj->fileheader = "<center>Contact Us Leads\n</center>";
                $configObj->glLibraryObj->filename = "" . SITE_NAME . "_Contact_Us_Leads" . "-" . date("dmy") . "-" .time() . ".xls";
                $configObj->glLibraryObj->dataArray = $allrecordsset;
                $configObj->glLibraryObj->generateXLSfile();
                break;


            case 'updatereaddata':

                $sql = "UPDATE " . DB_PREFIX . "comments SET chr_read='Y' where int_glcode=" . $_REQUEST['id'];
                $commentsObj->configObj->glDbObj->query($sql);
                echo $_REQUEST['id'];
                exit;
                break;

            default:
                if ($_REQUEST['msg']) {
                    if ($_REQUEST['msg'] == 'send') {
                        $messagebox = $configObj->glLibraryObj->message("Congrats! The Email has been sent successfully.");
                        $configObj->glTplObj->set('messagebox', $messagebox);
                    }
                }
                $commentsObj->load_contactcomments();
                break;
        }
        break;
}
?>
