<?php 

// Include main file
include_once('../libs/main.php');

// Check admin Login
include_once('checkLogin.php');

$successMsg = '';

if(isset($_REQUEST['successMsg'])){
	$successMsg = $_REQUEST['successMsg'];
}

if(isset($_REQUEST['failedMsg'])){
	$failedMsg = $_REQUEST['failedMsg'];
}

// Logical section of page
$settingObj =  new  setting();

$adminlogObj = new admin_log();
$filename=basename($_SERVER['SCRIPT_FILENAME']);

if($filename == 'setting.php')
{
    $module_id = $adminlogObj->getModuleId($filename);
    $page_id = $adminlogObj->getPageId($filename);
}

if(isset($_POST['submit'])){
	
    if(isset($_POST['settings']) && count($_POST['settings']) > 0 ){
        foreach ($_POST['settings'] as $key => $val){
            if($key == 'DEFAULT_REFERRAL_POINT')
            {
                $fields_rp = array('setting_value');
                $where_rp=array('setting_name='=>$key);
                $data =array('fields'=>$fields_rp,'where'=>$where_rp);
                $settingDetail_rp = $settingObj->fromFields($data);
                if($settingDetail_rp->setting_value != $val)
                {
                    $setting_detail = '';
                    $setting_detail = "<b>Edit Setting Old DEFAULT REFERRAL POINT</b>: "." ".$settingDetail_rp->setting_value." <b>To</b> ".$val;
                    $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$setting_detail);

                }
            }
            if($key == 'DEFAULT_REFERRAL_CODE')
            {
                $fields_rp = array('setting_value');
                $where_rp=array('setting_name='=>$key);
                $data =array('fields'=>$fields_rp,'where'=>$where_rp);
                $settingDetail_rp = $settingObj->fromFields($data);
                if($settingDetail_rp->setting_value != $val)
                {
                    $setting_detail = '';
                    $setting_detail = "<b>Edit Setting Old DEFAULT REFERRAL CODE</b>: "." ".$settingDetail_rp->setting_value." <b>To</b> ".$val;
                    $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$setting_detail);

                }
            }
            if($key == 'SMS_API')
            {
                $fields_rp = array('setting_value');
                $where_rp=array('setting_name='=>$key);
                $data =array('fields'=>$fields_rp,'where'=>$where_rp);
                $settingDetail_rp = $settingObj->fromFields($data);
                if($settingDetail_rp->setting_value != $val)
                {
                    $setting_detail = '';
                    $setting_detail = "<b>Edit Setting Old SMS API</b>: "." ".$settingDetail_rp->setting_value." <b>To</b> ".$val;
                    $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$setting_detail);

                }
            }

            if($key == 'EMAIL_ENABLED')
            {
                $fields_rp = array('setting_value');
                $where_rp=array('setting_name='=>$key);
                $data =array('fields'=>$fields_rp,'where'=>$where_rp);
                $settingDetail_rp = $settingObj->fromFields($data);
                if($settingDetail_rp->setting_value != $val)
                {
                    $setting_detail = '';
                    $setting_detail = "<b>Edit Setting Old EMAIL ENABLED</b>: "." ".$settingDetail_rp->setting_value." <b>To</b> ".$val;
                    $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$setting_detail);

                }
            }

            if($key == 'CLAIM_NEW_LEAD_POINT')
            {
                $fields_rp = array('setting_value');
                $where_rp=array('setting_name='=>$key);
                $data =array('fields'=>$fields_rp,'where'=>$where_rp);
                $settingDetail_rp = $settingObj->fromFields($data);
                if($settingDetail_rp->setting_value != $val)
                {
                    $setting_detail = '';
                    $setting_detail = "<b>Edit Setting Old CLAIM NEW LEAD POINT</b>: "." ".$settingDetail_rp->setting_value." <b>To</b> ".$val;
                    $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$setting_detail);

                }
            }

            if($key == 'NEW_LEAD_AMOUNT_CHARGE')
            {
                $fields_rp = array('setting_value');
                $where_rp=array('setting_name='=>$key);
                $data =array('fields'=>$fields_rp,'where'=>$where_rp);
                $settingDetail_rp = $settingObj->fromFields($data);
                if($settingDetail_rp->setting_value != $val)
                {
                    $setting_detail = '';
                    $setting_detail = "<b>Edit Setting Old NEW LEAD AMOUNT CHARGE</b>: "." ".$settingDetail_rp->setting_value." <b>To</b> ".$val;
                    $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$setting_detail);

                }
            }

            if($key == 'OLD_LEAD_AMOUNT_CHARGE')
            {
                $fields_rp = array('setting_value');
                $where_rp=array('setting_name='=>$key);
                $data =array('fields'=>$fields_rp,'where'=>$where_rp);
                $settingDetail_rp = $settingObj->fromFields($data);
                if($settingDetail_rp->setting_value != $val)
                {
                    $setting_detail = '';
                    $setting_detail = "<b>Edit Setting Old OLD LEAD AMOUNT CHARGE</b>: "." ".$settingDetail_rp->setting_value." <b>To</b> ".$val;
                    $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$setting_detail);

                }
            }

            if($key == 'CLAIM_OLD_LEAD_POINT')
            {
                $fields_rp = array('setting_value');
                $where_rp=array('setting_name='=>$key);
                $data =array('fields'=>$fields_rp,'where'=>$where_rp);
                $settingDetail_rp = $settingObj->fromFields($data);
                if($settingDetail_rp->setting_value != $val)
                {
                    $setting_detail = '';
                    $setting_detail = "<b>Edit Setting Old CLAIM OLD LEAD POINT</b>: "." ".$settingDetail_rp->setting_value." <b>To</b> ".$val;
                    $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$setting_detail);

                }
            }

            if($key == 'PRESCREENING')
            {
                $fields_rp = array('setting_value');
                $where_rp=array('setting_name='=>$key);
                $data =array('fields'=>$fields_rp,'where'=>$where_rp);
                $settingDetail_rp = $settingObj->fromFields($data);
                if($settingDetail_rp->setting_value != $val)
                {
                    $setting_detail = '';
                    $setting_detail = "<b>Edit Setting Old PRESCREENING</b>: "." ".$settingDetail_rp->setting_value." <b>To</b> ".$val;
                    $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$setting_detail);

                }
            }

            if($key == 'STRIPE_SECRET_KEY')
            {
                $fields_rp = array('setting_value');
                $where_rp=array('setting_name='=>$key);
                $data =array('fields'=>$fields_rp,'where'=>$where_rp);
                $settingDetail_rp = $settingObj->fromFields($data);
                if($settingDetail_rp->setting_value != $val)
                {
                    $setting_detail = '';
                    $setting_detail = "<b>Edit Setting Old STRIPE SECRET KEY</b>: "." ".$settingDetail_rp->setting_value." <b>To</b> ".$val;
                    $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$setting_detail);

                }
            }

            if($key == 'TERMOFUSE')
            {
                $fields_rp = array('setting_value');
                $where_rp=array('setting_name='=>$key);
                $data =array('fields'=>$fields_rp,'where'=>$where_rp);
                $settingDetail_rp = $settingObj->fromFields($data);
                if($settingDetail_rp->setting_value != $val)
                {
                    $setting_detail = '';
                    $setting_detail = "<b>Edit Setting Old TERMOFUSE</b>: "." ".$settingDetail_rp->setting_value." <b>To</b> ".$val;
                    $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$setting_detail);

                }
            }

            if($key == 'PRIVACY')
            {
                $fields_rp = array('setting_value');
                $where_rp=array('setting_name='=>$key);
                $data =array('fields'=>$fields_rp,'where'=>$where_rp);
                $settingDetail_rp = $settingObj->fromFields($data);
                if($settingDetail_rp->setting_value != $val)
                {
                    $setting_detail = '';
                    $setting_detail = "<b>Edit Setting Old PRIVACY</b>: "." ".$settingDetail_rp->setting_value." <b>To</b> ".$val;
                    $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$setting_detail);

                }
            }

            if($key == 'COUNTRY_CODE')
            {
                $fields_rp = array('setting_value');
                $where_rp=array('setting_name='=>$key);
                $data =array('fields'=>$fields_rp,'where'=>$where_rp);
                $settingDetail_rp = $settingObj->fromFields($data);
                if($settingDetail_rp->setting_value != $val)
                {
                    $setting_detail = '';
                    $setting_detail = "<b>Edit Setting Old COUNTRY CODE</b>: "." ".$settingDetail_rp->setting_value." <b>To</b> ".$val;
                    $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$setting_detail);

                }
            }

            if($key == 'PAUSE_LIMIT')
            {
                $fields_rp = array('setting_value');
                $where_rp=array('setting_name='=>$key);
                $data =array('fields'=>$fields_rp,'where'=>$where_rp);
                $settingDetail_rp = $settingObj->fromFields($data);
                if($settingDetail_rp->setting_value != $val)
                {
                    $setting_detail = '';
                    $setting_detail = "<b>Edit Setting Old PAUSE LIMIT</b>: "." ".$settingDetail_rp->setting_value." <b>To</b> ".$val;
                    $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$setting_detail);

                }
            }

            if($key == 'SMS_RESEND_LIMIT')
            {
                $fields_rp = array('setting_value');
                $where_rp=array('setting_name='=>$key);
                $data =array('fields'=>$fields_rp,'where'=>$where_rp);
                $settingDetail_rp = $settingObj->fromFields($data);
                if($settingDetail_rp->setting_value != $val)
                {
                    $setting_detail = '';
                    $setting_detail = "<b>Edit Setting Old SMS RESEND LIMIT</b>: "." ".$settingDetail_rp->setting_value." <b>To</b> ".$val;
                    $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$setting_detail);

                }
            }

            
            $data=array('setting_value'=>$val);
            $where=array('setting_name='=>$key);
            $settingObj->updateFromFields($data,$where);
        }
    }	
    $successMsg ="setting updated successfully";			
}		
$orderby=array('setting_id asc');
$data=array('orderBy'=>$orderby);
$settingDetail = $settingObj->getAllRecords($data);

// Include Template 
include_once('../libs/routs.php')

?>