<?php
/****************************
 * File : appconfig.php
 * Author : Cygnusa
 * @2018
 *
 *    CONFIG & CONSTANT
 ****************************/

/*************** ENVIRONMENT *****************/
$ENVIRONMENT = 'production';
switch ($ENVIRONMENT) {
    case 'development':
        //error_reporting(E_ALL);
        error_reporting(E_ALL ^ E_NOTICE);
        break;
    case 'testing':
    case 'production':
        error_reporting(0);
        break;
    default:
        exit('The application environment is not set correctly.');
        break;
}

/*************** API SUPPORTING DEVICES *****************/
define('DEVICE_TYPE', 'web|app');

/*************** PHP SETTINGS *****************/
@ini_set('max_execution_time', 1400);
@ini_set("memory_limit", "1024M");
ini_set('post_max_size', '512M');
define("MAX_SIZE", "10000000");

/*************** APPLICATION DIRECTORY *****************/
defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__)));
define('CONTROLLER_PATH', DIRECTORY_SEPARATOR . "controller");

/*************** TIMEZONE SETTINGS *****************/
date_default_timezone_set('Asia/Kolkata');
//date_default_timezone_set('America/Los_Angeles');

if ($_SERVER['HTTP_HOST'] == "localhost:81" || $_SERVER['HTTP_HOST'] == "localhost" ) {
    //LOCAL Connections
    /***************** DATABASE *******************/
    define('HOST', "localhost");
    define('DBNAME', "dev_hyperm_v2");
    define('DBUSER', "root");
    define('DBPASSWORD', "");
    define('DBPORT', "");
    /***************** SITEURL *******************/
    $SITE_URL = (isset($_SERVER['HTTPS']) ? "https" : "http") . '://' . $_SERVER['HTTP_HOST'] . '/';
    define('IS_LIVE_SERVER', "0");

    define('PORTALLINK', $SITE_URL);
    define('APPLINK', "https://appstack.cygnusa.in/");

}  else {
    //Production ONLINE Connections
    /***************** DATABASE *******************/
    define('HOST', "");
    define('DBNAME', "dev_hyperm_v2");
    define('DBUSER', "root");
    define('DBPASSWORD', "jdEidf8&engfjyD3");
    define('DBPORT', "port=3306;");

    /***************** SITEURL *******************/
    $SITE_URL=(isset($_SERVER['HTTPS']) ? "https" : "http").'://'.$_SERVER['HTTP_HOST'].'/';
    define('IS_LIVE_SERVER', "1");

    define('PORTALLINK', $SITE_URL);
    define('APPLINK', "https://appstack.cygnusa.in/");
}
define('SITE_URL', $SITE_URL);

/***************** TABLES *******************/
define('DMS_DEALER', "tbl__dms_dealer");
define('DMS_EMPLOYEE', "tbl__dms_employee");
define('DMS_EMPLOYEE_LOG', "tbl__dms_employee_log");

define('DMS_HOUSER', "tbl__dms_houser");
define('DMS_EMPLOYEE_SALES', "tbl__dms_employee_sales");

define('TABLE_COUNTRY', "tbl__country");
define('TABLE_STATE', "tbl__state");
define('TABLE_MODEL', "tbl__model");

define('TABLE_SITE_SETTING', "tbl__site_settings");
define('TABLE_TEMP_REGISTRATION', "tbl__temp_registration");

define('TABLE_DSE_ACTIVE_DEACTIVE_LIST', "tbl__dse_active_deactive_list");

//1 Administrator
//2 Admin

//3 HO Manager
//4 Zonal Manager
//5 Trainer
//6 Regional Manager
//7 Area Manager

//8 Sales Manager
//9 Team Leader
//10 Employee
//11 Sales Executive Insurance
//12 Sales Executive Accessories
//13 Tele Sales Executive
//14 Dealer
//15 International Bike Sales Executive

define('TABLE_ROLE', "tbl__role");
define('TABLE_USER', "tbl__user");
define('TABLE_LOCALEY', "tbl__localey");
define('TABLE_MASTER_LANGUAGE', "tbl__master_language");
define('TABLE_USER_LOG', "tbl__userlog");
define('TABLE_USER_DEVICES', "tbl__userdevice");
define('TABLE_PERMISSION', "tbl__permission");
define('TABLE_MODULE', "tbl__module");
define('TABLE_STATUS', "tbl__status");

define('TABLE_QUESTION', "tbl__question");
define('TABLE_QUESTIONOPTION', "tbl__questionoption");
define('TABLE_QUESTIONTYPE', "tbl__questiontype");

define('TABLE_TRAINING_LEVEL', "tbl__training_level");
define('TABLE_CATEGORY', "tbl__category");
define('TABLE_ASSET_TOPIC', "tbl__asset_topics");
define('TABLE_ASSET_CONTENT', "tbl__asset_content");
define('TABLE_ASSET_FILE', "tbl__asset_file");
define('TABLE_FILETYPE', "tbl__filetype");
define('TABLE_EXPIREDTYPE', "tbl__expiredtype");
define('TABLE_USER_COMPLETE_CONTENT', "tbl__user_complete_content");

define('TABLE_ASSESSMENT', "tbl__assessment");
define('TABLE_ASSESSMENTRESULT', "tbl__assessmentresult");
define('TABLE_ASSESSMENT_QUESTION', "tbl__assessmentquest");
define('TABLE_ASSESSMENT_USER', "tbl__assessmentuser");
define('TABLE_ASSESSMENT_USERRESULT', "tbl__assessmentuserresult");
define('TABLE_SURVEY_RATING', "tbl__survey_rating");

define('TABLE_USER_EPOINTS', "tbl__user_epoints");
define('TABLE_USER_EPOINTS_HISTORY', "tbl__user_epoints_history");
define('TABLE_USER_SALETARGET', "tbl__user_saletarget");
define('TABLE_USER_LEARNING', "tbl__user_learning");
//USER CERTIFICATION LOG
define('TABLE_USER_LEARNING_UPLOADLOG', "tbl__user_learning_upload_log");
define('TABLE_USER_STATUS_HISTORY', "tbl__userstatushistory");

define('TABLE_NOTIFICATION', "tbl__notification");
define('TABLE_NOTIFICATION_USER', "tbl__notification_user");
define('TABLE_NOTIFICATION_TYPE', "tbl__notification_type");

define('TABLE_BANNERS', "tbl__banners");
define('TABLE_BULLETIN', "tbl__bulletin");
define('TABLE_BULLETINSTATUS', "tbl__user_bulletinstatus"); // 19 march

define('TABLE_SMS_LOG', "tbl__sms_log");

define('TABLE_TRAINING_SCHEDULE', "tbl__training_schedule");
define('TABLE_TRAINING_RESCHEDULE_LIST', "tbl__training_reschedule_list");
define('TABLE_TRAINING_DECLINE_REASON_LIST', "tbl__training_decline_reason_list");
define('TABLE_TRAINING_LEVEL_SCORE', "tbl__training_level_score");
define('TABLE_TRAINING_LEVEL_SCORE_NAMES', "tbl__training_level_score_names");
define('TABLE_TRAINING_PARTICIPANT', "tbl__training_participant");
define('TABLE_TRAINING_PARTICIPANT_ATTENDANCE', "tbl__training_participant_attendance");
define('TABLE_TRAINING_ASSESSMENT', "tbl__training_assessment");
define('TABLE_TRAINING_SURVEY', "tbl__training_survey");
define('TABLE_TRAINING_FEEDBACK_QUESTION', "tbl__training_feedback_question");
define('TABLE_QUERY_LOG', "tbl__query_log");

define('TABLE_WOOHOO_TOKEN', "tbl__woohoo_token");
define('TABLE_WOOHOO_LOG', "tbl__woohoo_log");

define('TABLE_WOOHOO_CATEGORY', "tbl__woohoo_category");
define('TABLE_WOOHOO_CATEGORY_DETAILS', "tbl__woohoo_category_details");
define('TABLE_WOOHOO_PRODUCT', "tbl__woohoo_product");
define('TABLE_USER_WALLET', "tbl__user_wallet");
define('TABLE_USER_WALLET_HISTORY', "tbl__user_wallet_history");
define('TABLE_ORDER', "tbl__order");
define('TABLE_USER_RANKLIST', "tbl__user_ranklist");
define('TABLE_USER_WALLET_APPROVE', "tbl__user_wallet_approve");
define('TABLE_USER_SALESTARGET_APPROVE', "tbl__user_saletarget_approve"); //TABLE NOT USING
define('TABLE_USER_SALESTARGET_LOG', "tbl__user_saletarget_log"); //TABLE NOT USING
define('TABLE_USER_SALESTARGET_STATUS', "tbl__user_saletarget_status");
define('TABLE_USER_SALESTARGET_SET', "tbl__user_saletarget_set");

//360 table
define('TABLE_COMPARE_MODEL', "tbl__ex_model");
define('TABLE_COMPARE_CATEGORY', "tbl__ex_comparecategory");
define('TABLE_COMPARE_FIELDS', "tbl__ex_comparefields");
define('TABLE_COMPARE_VALUE', "tbl__ex_comparevalue");
define('TABLE_IMAGE_VIEW_TYPE', "tbl__ex_imageviewtype");
define('TABLE_MODEL_IMAGE_VIEW', "tbl__ex_modelimageview");
define('TABLE_MODEL_VIEW_HOTSPOT', "tbl__ex_modelviewhotspot");
define('TABLE_MODEL_VARIANT', "tbl__ex_modelvariant");
define('TABLE_MODEL_VARIANT_COLOR', "tbl__ex_modelvariantcolor");

define('TABLE_MODEL_360VARIANT', "tbl__ex_360variant");
define('TABLE_MODEL_360IMAGE', "tbl__ex_360image");
define('TABLE_MODEL_360IMAGE_HOTSPOT', "tbl__ex_360hotspot");
define('TABLE_MODEL_360ASSETS_VERSION', "tbl__ex_assets_version");
define('TABLE_HOTSPOT_CONTENT', "tbl__ex_hotspot_content");
define('TABLE_EXPLORE_ACCESSORIES_CATEGORY', "tbl__ex_accessoriescategory");
define('TABLE_EXPLORE_ACCESSORIES', "tbl__ex_modelaccessories");
define('TABLE_EXPLORE_ENQUIRY', "tbl__ex_enquiry");

//NEW CONTENT 07 JAN 2020
define('TABLE_EXPLORE_CONTENT', "tbl__ex_cuscontent");
define('TABLE_EXPLORE_FILE', "tbl__ex_cusfile");

define('TABLE_USER_ACCESSCOUNT', "tbl__user_accesscount");

//CUSTOMER EXP TABLES
define('TABLE__CUSTOMEREXP', "tbl__user_customerexp");
define('TABLE__EXPQUESTIONTYPE', "tbl__ex_questiontype");
define('TABLE__EXPQUESTION', "tbl__ex_question");
define('TABLE__EXPQUESTIONOPTION', "tbl__ex_questionoption");
define('TABLE__FEEDBACKUSER', "tbl__ex_feedbackuser");
define('TABLE__FEEDBACKRESULT', "tbl__ex_feedbackresult");

define('TABLE_TRAINERBATCH', "tbl__trainerbatch");
define('TABLE_TRAINERBATCHUSER', "tbl__trainerbatchuser");

//LOCK ACCESS
define('TABLE_LOCK_ACCESS', "tbl__lockauthrozation");

//EMAIL LOG

define('TABLE_EMAIL_LOG', "tbl__email_log");

//ENQUIRY LOG
define('DMS_ENQUIRY_MASTER', "tbl__dms_enquirymaster");
define('DMS_ENQUIRY_BUYERTYPE', "tbl__dms_enquirybuyertype");
define('DMS_ENQUIRY_TITLE', "tbl__dms_enquirytitle");
define('DMS_ENQUIRY_ORGANISATION', "tbl__dms_enquiryorganisation");
define('DMS_ENQUIRY_COMMUNICATE', "tbl__dms_enquirycommunicate");
define('DMS_ENQUIRY_ACTIONPLAN', "tbl__dms_enquiryactionplan");
define('DMS_ENQUIRY_PURPOSE', "tbl__dms_enquirypurpose");
define('DMS_ENQUIRY_MODEL', "tbl__dms_enquirymodel");
//define('DMS_ENQUIRY_VARIANT',"tbl__dms_enquiryvariant");
define('DMS_ENQUIRY_PROFESSION', "tbl__dms_enquiryprofession");
define('DMS_ENQUIRY_SOURCE', "tbl__dms_enquirysource");
define('DMS_ENQUIRY_CUSTTYPE', "tbl__dms_enquirycusttype");
define('DMS_ENQUIRY_CUSTAGE', "tbl__dms_enquirycustage");
define('DMS_ENQUIRY_MODE', "tbl__dms_enquirymodeofcontact");
define('DMS_ENQUIRY_STAGETYPE', "tbl__dms_enquirystagetype");
define('DMS_ENQUIRY_STATUS', "tbl__dms_enquirystatus");
define('DMS_CRON_LOG', "tbl__cron_log");
define('DMS_ENQUIRY_REASON', "tbl__dms_enquiryreason");
define('DMS_ENQUIRY_SUBREASON', "tbl__dms_enquirysubreason");
define('DMS_ENQUIRY_LOSTMODEL', "tbl__dms_enquirylostmodel");

define('TABLE_ENQUIRY_OTP', "tbl__enquiry_otp");
define('TABLE_LEAD', "tbl__lead");
define('TABLE_ENQUIRYPLANNER', "tbl__enquiryplanner");
define('TABLE_QUOTATIONSHARE', "tbl__quotationshare");
define('TABLE_ENQBROCHURESHARE', "tbl__enquirybrochureshare");

//VIDEO TRAINING
define('TABLE_VIDEOTRAININGSCHEDULE', "tbl__videotrainingschedule");
define('TABLE_VIDEOSCHEDULEUSER', "tbl__videoscheduleuser");
define('TABLE_VIDEOTRAININGTIMER', "tbl__videotrainingtimer");
define('TABLE_VIDEOTRAININGMSG', "tbl__videotrainingmsg");
define('TABLE_VIDEOTRAININGTITLE', "tbl__videotrainingtitle");

/***************** VIEWS *******************/
define('VIEW_ASM_SALES', "view_asm_sales");
define('VIEW_RM_SALES', "view_rm_sales");
define('VIEW_ZM_SALES', "view_zm_sales");
define('VIEW_ZONE_SALES', "view_zone_sales");
define('VIEW_ASM_SALESTARGET', "view_asm_salestarget");
define('VIEW_RM_SALESTARGET', "view_rm_salestarget");
define('VIEW_ZM_SALESTARGET', "view_zm_salestarget");
define('VIEW_ZONE_SALESTARGET', "view_zone_salestarget");

//define('VIEW_TRAINING_CONTENT',"view_training_content");
//define('VIEW_ASSET_TOPIC_CONTENT',"view_asset_topic_content");

/************ S3 URL **************/
define('S3_BANNER_IMAGE_URL', 'Hyper-M/hypermupload/banner/'); //IN S3_BUCKET
define('S3_PROFILE_IMAGE_URL', 'Hyper-M/hypermupload/profile/'); //IN S3_BUCKET
//define('S3_SUPPLIER_IMAGE_URL','Hyper-M/hypermupload//supplier/');  //IN S3_BUCKET
define('S3_TOPICS_URL', 'Hyper-M/hypermupload/topics/'); //IN S3_BUCKET
define('S3_ASSESSMENT_URL', 'Hyper-M/hypermupload/assessment/'); //IN S3_BUCKET
define('S3_QUESTION_URL', 'Hyper-M/hypermupload/question/'); //IN S3_BUCKET
define('S3_REPORT_URL', 'Hyper-M/hypermupload/report/'); //IN S3_BUCKET
define('S3_BULLETIN_URL', 'Hyper-M/hypermupload/bulletin/'); //IN S3_BUCKET
define('S3_LOG_URL', 'Hyper-M/hypermupload/log/'); //IN S3_BUCKET
define('S3_TRAINING_URL', 'Hyper-M/hypermupload/training/'); //IN S3_BUCKET
define('S3_CRTRAINING_URL', 'Hyper-M/hypermupload/crtraining/');

define('S3_CUS_CONTENT_URL', 'Hyper-M/hypermupload/cuscontent/'); //IN S3_BUCKET
define('S3_SEGMENTLOG_URL', 'Hyper-M/hypermupload/segmentlog/'); //IN S3_BUCKET

/************ COMMON URL **************/
define('NOIMAGE_URL', SITE_URL . 'images/noimage.jpg');
define('TRAININGIMAGE_URL', SITE_URL . 'images/noimage.jpg');
define('SURVEYIMAGE_URL', SITE_URL . 'images/survey_logo.jpg');
define('USER_NOIMAGE_URL', SITE_URL . 'images/no_user.png');
define('BULLETIN_NOIMAGE_URL', SITE_URL . 'images/noimage.jpg');

/************ COMMON CONSTANT **************/
define('NOW', date('Y-m-d H:i:s'));
define('CUR_DATE', date('Y-m-d'));
define('TIMETOKEN', date('YmdHis'));
define('OTP_EXPIRY_MIN', 1);
define('ENQUIRY_OTP_EXPIRY_MIN', 5);

define('RECORD_LIMIT', 50);
define('SUPPORT_EMAIL', '');
define('CUSTOMER_EXPERIENCE_EMAIL', '');

define('PASSWORD_EXPIRY_DAY', 100);
define('ASSESSMENT_EXPIRY_DAY', 30);
define('CONTENT_FILE_TYPE', 'pdf|mp4|mp3');
define('PROJECTNAME', 'HYPER-M');
define('TRAINER_BUFFER_DATE', '10'); //IN DATE

define('ASSESSMENT_PASS_PERCENT', '80'); //IN DATE

if (IS_LIVE_SERVER == 1) {
    //define('DEALER_SETSALE_DATE','05'); //IN DATE
    //define('AM_SETSALE_DATE','07'); //IN DATE
    define('DEALER_SETSALE_DATE', '05'); //IN DATE
    define('AM_SETSALE_DATE', '07'); //IN DATE

} else {
    define('DEALER_SETSALE_DATE', '05'); //IN DATE
    define('AM_SETSALE_DATE', '07'); //IN DATE
}
define('APP_URLANDRIOD', "");
define('APP_URLIOS', "");

//LOCK ACCESS
define('LOCK_ACCESS_ENABLE', '1'); //0-disable,1-enable
define('LOCK_ACCESS_COUNT', 10);
define('LOCK_ACCESS_MINUTES', 10);

define('DEVELOPMENT_SUPPORT_MAIL', '');
/************ SMTP **************/
define('SMTP_HOST', '');
define('SMTP_PORT', );
define('SMTP_USERNAME', '');
define('SMTP_PASSWORD', '');

//REGISTER REWARD
define('REGISTER_REWARD_LIMIT', "500"); //Registered on App (Fastest 500)
define('REWARD_POINT_ONE', "250");
define('REWARD_POINT_TWO', "100");
define('REWARD_POINT_TWO', "100");

//28 FEB 2020 NEW REWARDS
define("REWARD_TARGET_SETTING", "500");

//SET TARGET VALUES
define('SET_TARGET', "5");

define('SEGMENT_MIN_TARGET_STUDENT', "6");
define('SEGMENT_MIN_TARGET_PARENT', "18");

//REWARD POINTS
define('REWARD_POINTS_BRONZE', "1000");
define('REWARD_POINTS_SILVER', "3000");
define('REWARD_POINTS_GOLD', "3500");

/************ DMS API URL **************/
if (IS_LIVE_SERVER == 1) {
    //LIVE
    define('URL', '');
    define('TOKEN', '');
} else {
    //DEV
    define('URL', '');
    define('TOKEN', '');
}
/************ WEB URL **************/
define('ASSEST_URL', SITE_URL . 'internal/');

/************ LANGUAGE ************/
define('LANGUAGE_ARR', 'en_us');

/************ MODEL ID for image IN ex_model ************/
define('STUDEND_ID', '3');
define('PARENT_ID', '4');

/************ AMAZON S3 ACCESS**************/
if ($_SERVER['HTTP_HOST'] == "localhost:81" || $_SERVER['HTTP_HOST'] == "localhost") {
    define('S3_ACCESSKEY','AKIA2P6OKHL66GTRBY7Q');
	define('S3_SECRET_ACCESS','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');
	define('S3_REGION','ap-south-1');
	define('S3_BUCKET','my-cygnusa-bucket-s3');
} else {
    define('S3_ACCESSKEY','AKIA2P6OKHL66GTRBY7Q');
	define('S3_SECRET_ACCESS','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');
	define('S3_REGION','ap-south-1');
	define('S3_BUCKET','my-cygnusa-bucket-s3');
}


if (IS_LIVE_SERVER == '1') {
    /************ SMS ************/

    $username = 'lokesh.b@cygnusa.in';
    $hash = '';
    $senderid = 'HYPERM';
    $sms_apiurl = "https://hyper-m.cygnusa.in/_api/";
    define('SMS_USERNAME', $username);
    define('SMS_HASH', $hash);
    define('SMS_SENDERID', $senderid);
    define('SMS_APIURL', $sms_apiurl);

} else {
    /************ SMS ************/
    
	$username = 'lokesh.b@cygnusa.in';
    $hash = '';
    $senderid = 'HYPERM';
    $sms_apiurl = "https://hyper-m.cygnusa.in/_api/";
    define('SMS_USERNAME', $username);
    define('SMS_HASH', $hash);
    define('SMS_SENDERID', $senderid);
    define('SMS_APIURL', $sms_apiurl);
}

/********** GENERAL FUNCTIONS ************/
//define('LOGINTYPE',"login_id");    //both,email,mobile,login_id
//define('LAST_PASSWORD_',"login_id");

// LOGIN METHOD SINGLE USER MULTIPLE
define('IS_MULTI_LOGIN', 1);

/************ API KEY **************/
if ($_SERVER['HTTP_HOST'] == "localhost:81" || $_SERVER['HTTP_HOST'] == "localhost") {
    define("GOOGLE_API_KEY", "");
    define("GOOGLE_FCM_URL", "https://fcm.googleapis.com/fcm/send");

} else {

    define("GOOGLE_API_KEY", "");
    define("GOOGLE_FCM_URL", "https://fcm.googleapis.com/fcm/send");

}
//WOOHOO API KEYS
if ($_SERVER['HTTP_HOST'] == "localhost:81" || $_SERVER['HTTP_HOST'] == "localhost") {
    $woohoo_consumerKey='';
    $woohoo_consumerSecret='';
    $woohoo_username='';
    $woohoo_password='';
    $temporaryCredentialsRequestUrl='';
    $authorizationUrl='';
    $accessTokenRequestUrl='';
    $woohoo_url='';
    $authorizationCodeUrl='';
    $tokengenerateUrl='';
} else {
    $woohoo_consumerKey='';
    $woohoo_consumerSecret='';
    $woohoo_username='';
    $woohoo_password='';
    $temporaryCredentialsRequestUrl='';
    $authorizationUrl='';
    $accessTokenRequestUrl='';
    $woohoo_url='';
    $authorizationCodeUrl='';
    $tokengenerateUrl='';
}
define("WOOHOO_CONSUMERKEY", $woohoo_consumerKey);
define("WOOHOO_CONSUMERSECRET", $woohoo_consumerSecret);
define("WOOHOO_USERNAME", $woohoo_username);
define("WOOHOO_PASSWORD", $woohoo_password);

define("WOOHOO_TEMPCREDENTIALSREQUESTURL", $temporaryCredentialsRequestUrl);
define("WOOHOO_AUTHORIZATIONURL", $authorizationUrl);
define("WOOHOO_ACCESSTOKENREQUESTURL", $accessTokenRequestUrl);
define("WOOHOO_API_URL", $woohoo_url);

define("WOOHOO_AUTHORIZATION_CODE_URL", $authorizationCodeUrl);
define("WOOHOO_AUTHORIZATION_TOKEN_URL", $tokengenerateUrl);

/************ EXPLORE TOKEN **************/
define("MODE_ONE_TOKEN", '');
define("MODE_TWO_TOKEN", '');

//CLASS AUTO LOADER
function my_autoloader($class)
{

    if (!(strpos($class, 'Aws') !== false || strpos($class, 'GuzzleHttp') !== false || strpos($class, 'JmesPath') !== false || strpos($class, 'Psr') !== false || strpos($class, 'Net') !== false || strpos($class, 'System') !== false || strpos($class, 'Math') !== false || strpos($class, 'File') !== false || strpos($class, 'Crypt') !== false)) {
        return include APPLICATION_PATH . CONTROLLER_PATH . DIRECTORY_SEPARATOR . $class . '.php';
    } else {
        return null;
    }
}

//ESCAPE STRING
function escape_str($str, $like = false)
{
    global $db;
    if (is_array($str)) {
        foreach ($str as $key => $val) {
            $str[$key] = escape_str($val, $like);
        }

        return $str;
    } else if (is_object($str)) {
        foreach ($str as $key => $val) {
            $str->$key = escape_str($val, $like);
        }
        return $str;
    }
    if (function_exists('mysql_real_escape_string') and is_resource($db)) {
        $str = mysql_real_escape_string($str, $db);
    } else {
        $str = addslashes($str);
    }
    if ($like === true) {
        $str = str_replace(array('%', '_'), array('\\%', '\\_'), $str);
    }
    return $str;
}

//STRIP VALUE
function stripslashesFull($input)
{
    if (is_array($input)) {

        $input = @array_map('stripslashesFull', $input);
    } elseif (is_object($input)) {
        $vars = @get_object_vars($input);
        foreach ($vars as $k => $v) {
            $input->{$k} = stripslashesFull($v);
        }
    } else {
        $input = @stripslashes($input);
    }
    return $input;
}

//SEND MAIL
function commonSendMail($obj)
{
    // // if (IS_LIVE_SERVER != '1') {
    //     $obj->to = '';
    //     $obj->to = 'lokesh.b@cygnusa.in';
    //     $obj->cc[] = 'muthuramanr@cygnusa.in';
    //     $obj->subject = 'HYPER-M :' . $obj->subject;
    // // }

    // require_once dirname(__FILE__) . '/phpmailer/PHPMailerAutoload.php';
    // require_once dirname(__FILE__) . '/phpmailer/class.phpmailer.php';

    // $mail = new PHPMailer;

    // $obj->replayto = SUPPORT_EMAIL;
    // if (!isset($obj->from) && $obj->from == '') {
    //     $obj->from = SUPPORT_EMAIL;

    // }
    // $mail->isSMTP(); // telling the class to use SMTP
    // $mail->SMTPAuth = false; // enable SMTP authentication
    // //$mail->SMTPSecure = 'none';    // sets the prefix to the servier
    // //$mail->SMTPDebug = 2;
    // $mail->Host = SMTP_HOST; // sets   as the SMTP server
    // $mail->Port = SMTP_PORT; // set the SMTP port for the   server
    // //$mail->Username = SMTP_USERNAME; //   username
    // //$mail->Password = SMTP_PASSWORD; //   password
    // //    $mail->SMTPOptions = array(
    // //        'ssl' => array(
    // //            'verify_peer' => false,
    // //            'verify_peer_name' => false,
    // //            'allow_self_signed' => true
    // //        )
    // //   );

    // $mail->setFrom($obj->from); //Set who the message is to be sent from
    // if (isset($obj->FromName)) {
    //     $mail->FromName = $obj->FromName;
    // }

    // $mail->addReplyTo($obj->replayto);
    // //$mail->addAddress($obj->to);

    // //TO EMAIL
    // $to_email = '';
    // if (isset($obj->to)) {
    //     if (is_array($obj->to)) {
    //         foreach ($obj->to as $res_to) {
    //             $mail->addAddress($res_to);
    //         }
    //         $to_email = @implode(',', $obj->to);
    //     } else if (is_string($obj->to)) {
    //         $mail->addAddress($obj->to);
    //         $to_email = $obj->to;
    //     }
    // }
    // //CC EMAIL
    // $cc_email = '';
    // if (isset($obj->cc)) {
    //     if (is_array($obj->cc)) {
    //         foreach ($obj->cc as $res_cc) {
    //             $mail->AddCC($res_cc);
    //         }
    //         $cc_email = @implode(',', $obj->cc);
    //     } else if (is_string($obj->cc)) {
    //         $mail->AddCC($obj->cc);
    //         $cc_email = $obj->cc;
    //     }
    // }
    // if (isset($obj->attachment_file)) {
    //     $file_count = count($obj->attachment_file);
    //     for ($x = 0; $x < $file_count; $x++) {
    //         if (!empty($obj->attachment_file[$x])) {
    //             $mail->addAttachment($obj->attachment_file[$x]);
    //         }
    //     }
    // }

    // $mail->isHTML(true);
    // $mail->Subject = $obj->subject;
    // $contentmail = $obj->message;
    // $mail->Body = $contentmail;

    // global $conn;

    // if (isset($conn)) {
    //     $insert = "INSERT INTO " . TABLE_EMAIL_LOG . " (`to_mail`, `from_mail`, `cc_mail`, `subject`, `is_success`, `created_on`) VALUES ('" . escape_str($to_email) . "','" . escape_str($obj->from) . "','" . escape_str($cc_email) . "','" . escape_str($obj->subject) . "', '0','" . NOW . "' )";
    //     $insertquery = $conn->executeQuery($insert);
    //     $logid = $conn->lastinsetid();
    // }

    // if (!$mail->send()) {

    //     $headers = "From: " . $obj->from . " \r\n";
    //     //$headers .= "Reply-To: ".$replayto." \r\n";
    //     $headers .= "MIME-Version: 1.0\r\n";
    //     $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    //     // @mail(SUPPORT_EMAIL, "Mail delivery report", "FROM : " . $obj->from . ", TO :" . $obj->to . " mail not delivered", $headers);

    // } else {
    //     if (isset($conn)) {
    //         $conn->executeQuery("UPDATE " . TABLE_EMAIL_LOG . " SET is_success='1' WHERE id='" . $logid . "'");
    //     }
    // }

}

//RESPONSE STATUS
function responsestatus($obj)
{
    header("HTTP/1.1 " . $obj->status . " " . $obj->statustext);
    header('Access-Control-Allow-Origin: *');
    header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
    header('Access-Control-Allow-Headers: Content-Type, Content-Range, Content-Disposition, Content-Description');
    header("Content-Type:application/json");
    exit;
}

//RESPONSE STATUS
function quotes_array($str)
{
    return "'" . $str . "'";
}

//EXCEL COLUMN FROM NUMBER
function getColumnFromNumber($num)
{
    $numeric = $num % 26;
    $letter = chr(65 + $numeric);
    $num2 = intval($num / 26);
    if ($num2 > 0) {
        return getColumnFromNumber($num2 - 1) . $letter;
    } else {
        return $letter;
    }
}

function arrSortObjsByKey($key, $order = 'DESC')
{
    return function ($a, $b) use ($key, $order) {
        // Swap order if necessary
        if ($order == 'DESC') {
            list($a, $b) = array($b, $a);
        }
        // Check data type
        if (is_numeric($a->$key)) {
            return $a->$key - $b->$key; // compare numeric
        } else {
            return strnatcasecmp($a->$key, $b->$key); // compare string
        }
    };
}

// buildBaseString FOR CURL WOOHOO
function buildBaseString($baseURI, $method, $params)
{
    $r = array();
    ksort($params);
    foreach ($params as $key => $value) {
        $r[] = "$key=" . rawurlencode($value);
    }

    return $method . "&" . rawurlencode($baseURI) . '&' . rawurlencode(implode('&', $r));
}

// buildAuthorizationHeader FOR CURL WOOHOO
function buildAuthorizationHeader($oauth)
{
    $r = 'Authorization: OAuth ';
    $values = array();
    foreach ($oauth as $key => $value) {
        $values[] = "$key=\"" . rawurlencode($value) . "\"";
    }

    $r .= implode(', ', $values);
    return $r;
}

function maskenquiry($var)
{
    if ($var != '' && strlen($var) > 2) {
        $len = strlen($var) - 2;
        $var = substr_replace($var, str_repeat("X", $len), 0, $len);
    }
    return $var;
}

//WOOHO
/**
 * JSON encoded API request body parameters. This should be empty string in-case of API HTTP method is GET & DELETE
 *
 * @var string $requestBody
 */
//$requestBody = '{"q" : [{"f" : 1, "d" : 2}], "a" : "something"}';

/**
 * API HTTP method
 *
 * @var string $requestHttpMethod
 */
//$requestHttpMethod = 'post';

/**
 * Absolute API endpoint URL. In-case if you are passing query parameter this should be in filled with query parameters as well
 *
 * Make sure you configure this endpoint in database, because the endpoint will change for production environment
 *
 * @var string $absApiUrl
 */
//$absApiUrl = 'https://<This will be shared as part of provisioning the partner>/rest/v3/orders';

/**
 * This will be shared as part of provisioning the partner
 *
 * @var string $clientSecret
 */
//$clientSecret = 'secret string';

/**
 * Sorts the parameters according to the ASCII table.
 *
 * @param array $params
 */
function sortParams(array &$params)
{
    ksort($params);
    foreach ($params as $key => &$value) {
        $value = is_object($value) ? (array) $value : $value;
        if (is_array($value)) {
            sortParams($value);
        }
    }
}

/**
 * Sort all query parameters in the request according to the parameter name in ASCII table.
 *
 * @param string $queryParam
 * @return string
 */
function sortQueryParams($queryParam)
{
    $query = explode('&', $queryParam);
    asort($query, SORT_STRING);

    return implode('&', $query);
}

/**
 * Concat the (request method(upper case), request host, request URL), encoded request parameters and encoded query parameters using & as the separator.
 *
 * @param string $absApiUrl
 * @param string $requestHttpMethod
 * @param string $requestBody
 *
 * @return string
 */
function getConcatenateBaseString($absApiUrl, $requestHttpMethod, $requestBody)
{
    $baseStrings = [];

    $baseStrings[] = strtoupper($requestHttpMethod);
    $url = explode('?', $absApiUrl);
    $apiUrl = $url[0];
    if (isset($url[1])) {
        $baseStrings[] = rawurlencode($apiUrl . '?' . sortQueryParams($url[1]));
    } else {
        $baseStrings[] = rawurlencode($apiUrl);
    }

    if ($requestBody) {
        $jsonDecodedRequestBody = json_decode($requestBody, true);
        sortParams($jsonDecodedRequestBody);
        $baseStrings[] = rawurlencode(
            json_encode($jsonDecodedRequestBody, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)
        );
    }

    return implode('&', $baseStrings);
}
