<?php
/****************************
 * File : support.php
 * Author : Cygnusa
 * @2018
 ****************************/

//SECURITY
if (!defined('APPLICATION_PATH')) {
    exit('No direct script access allowed');
}

class support
{

    //FUNCTION LISTS
    public function __construct($parent)
    {
        //GET PAGE MESSAGE
        $this->page_data = globalfunc::getMessage($parent, $parent->lang, 'support');
        if (count($parent->params) == 0) {
            //$this->topicsfunc($parent);
        } else {
            $qry_params = explode("?", $parent->params[0]);
            $parameter_val = strtolower($qry_params[0]);

            switch ($parameter_val) {
                case "topic":
                case "content":
                case "registereduser":
                case "assessment":
                case "dmsemployee":
                case "dmsmanager":
                case "dmsdealer":
                case "dmssales":
                case "dmstarget":
                case "dmsrewardpoints":
                case "lastaccess":
                case "customerexperience":
                case "enquiry":
                case "activesmpin":
                case "loginlog":
                case "dealerenquiryinactive":

                    $this->$parameter_val($parent);
                    break;
                default:
                    $this->topicsfunc($parent);
                    break;
            }

        }

        $parent->response(array('response' => 'failed', 'message' => 'PAGE NOT FOUND'), 404);
    }

    /* /////////////////////////////// TOPICS //////////////////////////////////////////////// */
    private function topic($parent)
    {

        globalfunc::checkMethodType($parent, array('GET'));
        globalfunc::checkParamCount($parent, 1);

        $data_arr = array();
        $limit_str = globalfunc::setPageLimit($parent, $parent->params[0]);
        $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';

        echo '<!DOCTYPE html><html>
<head><meta charset="UTF-8"><h3>HYPER-M - TOPIC LIST</h3></head><body>'
            . '<table border="1"><tr><th>#</th><th>Category</th><th>Category id</th><th>Topic</th><th>Topic id</th><th>User type</th><th>Topic image</th></tr>';
        $query_category = $parent->selectQuery(TABLE_CATEGORY, "`cateid`, `catename`", "1=1 ORDER BY cateid ", "");
        if ($query_category['nr']) {
            $sno = 1;
            $s3 = awsfileserver::connectS3();
            foreach ($query_category['result'] as $res_cat) {
                $user_cond = " AND cateid='" . $res_cat->cateid . "' ";
                $getuser_topics_arr = $parent->selectQuery(TABLE_ASSET_TOPIC, "*", " status='1' AND is_deleted='0' " . $user_cond . " ORDER BY position ASC, assettopicid ASC " . $limit_cond, "");
                if ($getuser_topics_arr['nr']) {
                    //CONNECT S3

                    foreach ($getuser_topics_arr['result'] as $res) {
                        $res->image_url = TRAININGIMAGE_URL;
                        if ($res->image) {
                            $res->image_url = awsfileserver::getS3FileUrl($s3, S3_BUCKET, S3_TOPICS_URL . $res->image);
                        }
                        $user_type = ($res->user_type == '0') ? "Normal" : "Super Bike";

                        //$data_arr[]=$res;
                        echo '<tr><td>' . $sno++ . '</td><td>' . $res_cat->catename . '</td><td>' . $res_cat->cateid . '</td><td>' . $res->topicname . '</td><td>' . $res->assettopicid . '</td><td>' . $user_type . '</td><td><img src="' . $res->image_url . '" style="width:100px;"></td></tr>';
                    }
                }
            }
        }
        echo '</table></body></html>';exit;

    }
    /* //////////////////////////////////////////////////////////////////////////////////////////// */

    /* /////////////////////////////// TOPICS CONTENT LIST //////////////////////////////////////////////// */
    private function content($parent)
    {
        globalfunc::checkMethodType($parent, array('GET'));
        globalfunc::checkParamCount($parent, 1);

        $data_arr = array();

        echo '<!DOCTYPE html><html>
<head><meta charset="UTF-8"><h3>HYPER-M - CONTENT LIST</h3></head><body>'
            . '<table border="1"><tr><th>#</th><th>Category</th><th>Category id</th><th>Topic</th><th>Topic id</th><th>Content id</th><th>Topic image</th><th>Content title</th><th>Content description</th><th>Content file urls</th></tr>';
        $query_category = $parent->selectQuery(TABLE_CATEGORY, "`cateid`, `catename`", "1=1 ORDER BY cateid ", "");

        if ($query_category['nr']) {
            $sno = 0;
            $s3 = awsfileserver::connectS3();
            foreach ($query_category['result'] as $res_cat) {
                $user_cond = " AND cateid='" . $res_cat->cateid . "' ";
                $getuser_topics_arr = $parent->selectQuery(TABLE_ASSET_TOPIC, "*", " status='1' AND is_deleted='0' " . $user_cond . " ORDER BY position ASC, assettopicid ASC ");
                if ($getuser_topics_arr['nr']) {
                    //CONNECT S3

                    foreach ($getuser_topics_arr['result'] as $res) {
                        $res->image_url = TRAININGIMAGE_URL;
                        if ($res->image) {
                            $res->image_url = awsfileserver::getS3FileUrl($s3, S3_BUCKET, S3_TOPICS_URL . $res->image);
                        }

                        $usercond = " AND assettopicid='" . $res->assettopicid . "' ";
                        $orderby_cond = ($res->listorder == '1') ? "ORDER BY uploaddate DESC,contentid ASC " : "ORDER BY uploaddate ASC,contentid ASC ";
                        $getuser_content_arr = $parent->selectQuery(TABLE_ASSET_CONTENT, "*", " status='1' AND is_deleted='0' " . $usercond . " " . $orderby_cond, "");
                        if ($getuser_content_arr['nr']) {

                            foreach ($getuser_content_arr['result'] as $res_con) {
                                $res_con->content_files = $this->getContentFiles($parent, $s3, $res_con->contentid);
                                if (count($res_con->content_files) > 0) {
                                    $table_value = '<table border="1" style="margin:2px;"><tr><th>#</th><th>Language</th><th>Thumb nail</th><th>Content</th></tr>';
                                    foreach ($res_con->content_files as $res_file) {
                                        $m = 0;

                                        $table_value .= '<tr><td>' . ++$m . '</td><td>' . $res_file->language_title . '</td><td><img src="' . $res_file->thumb_fileurl . '" style="width:100px;"></td><td><a href="' . $res_file->file_url . '">Download</a></td></tr>';
                                    }
                                    $table_value .= '</table>';
                                }

                                echo '<tr><td>' . ++$sno . '</td><td>' . $res_cat->catename . '</td><td>' . $res_cat->cateid . '</td><td>' . $res->topicname . '</td><td>' . $res->assettopicid . '</td><td>' . $res_con->contentid . '</td><td><img src="' . $res->image_url . '" style="width:100px;"></td><td>' . $res_con->title . '</td><td>' . $res_con->description . '</td><td>' . $table_value . '</td></tr>';
                            }
                        }
                    }
                }
            }
        }
        echo '</table></body></html>';exit;

    }
    /* //////////////////////////////////////////////////////////////////////////////////////////// */

    /* /////////////////////////////// TOPIC CONTENT  //////////////////////////////////////////////// */
    private function getContentFiles($parent, $s3, $contentid)
    {
        $data_arr = array();
        //GET FILES ONLY ONE FILE
        $getuser_contentfiles_arr = $parent->selectQuery(TABLE_ASSET_FILE . " as f JOIN " . TABLE_MASTER_LANGUAGE . " as l ON l.language_id=f.language_id", " f.`language_id`, f.`filepath`,f.filetypeid, f.`thumbpath`, f.`filetypeid`, f.`filetype`, f.`filesize`, f.`filequality`, l.`language_code`, l. `language_title`", " f.contentid='" . $contentid . "'", "");
        if ($getuser_contentfiles_arr['nr']) {
            foreach ($getuser_contentfiles_arr['result'] as $tkey => $res) {
                //S3 FILE URL
                $fileurl = '';
                if ($res->filepath != '') {
                    $url = awsfileserver::getS3FileUrl($s3, S3_BUCKET, S3_TOPICS_URL . $res->filepath);
                    //PDF ISSUE FIX FOR WEB DEVICE
                    $url = (strtolower($parent->device_type) == 'web' && $res->filetypeid == '1') ? projectfunc::pdfUrlStr($parent, $url) : $url;
                    $fileurl = $url;
                }
                $getuser_contentfiles_arr['result'][$tkey]->file_url = $fileurl;
                //S3 THUMBIMAGE URL
                $thumb_fileurl = '';
                if ($res->thumbpath != '') {
                    $thumb_fileurl = awsfileserver::getS3FileUrl($s3, S3_BUCKET, S3_TOPICS_URL . $res->thumbpath);
                }
                $getuser_contentfiles_arr['result'][$tkey]->thumb_fileurl = $thumb_fileurl;
            }

            $data_arr = $getuser_contentfiles_arr['result'];
        }

        return $data_arr;
    }
    /* //////////////////////////////////////////////////////////////////////////////////////////// */

    /* /////////////////////////////// REGISTERED USER //////////////////////////////////////////////// */
    private function registereduser($parent)
    {

        globalfunc::checkMethodType($parent, array('GET'));
        globalfunc::checkParamCount($parent, 1);

        $data_arr = array();
        $limit_str = globalfunc::setPageLimit($parent, $parent->params[0]);
        $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';

        $cond = '';
        //FILTER
        $filter_arr = globalfunc::getFilterValues($parent, $parent->params[0]);
        if (count($filter_arr) > 0) {
            //smpin
            if (isset($filter_arr['role']) && $filter_arr['role'] != '') {
                $cond = " AND u.role='" . $filter_arr['role'] . "'";
            }

        }

        $query_group = $parent->selectQuery(TABLE_USER . " u JOIN " . TABLE_ROLE . " r ON u.role=r.id LEFT JOIN " . DMS_DEALER . " d ON d.dealer_code=u.dealer_code", "COUNT(u.userid) ucount , r.rolename ", "u.is_deleted=0 AND u.role>2 " . $cond . " GROUP BY u.role", "");

        echo '<!DOCTYPE html><html>
<head><meta charset="UTF-8"><h3>HYPER-M - REGISTERED USER LIST</h3></head><body>'
            . '<table border="1"><tr><th>ROLE</th><th>TOTAL REGISTER</th></tr>';

        if ($query_group['nr']) {
            foreach ($query_group['result'] as $res) {
                echo '<tr><td>' . $res->rolename . '</td><td>' . $res->ucount . '</td></tr>';
            }
        }
        echo '</table></br></br>'
            . '<table border="1"><tr><th>#</th><th>USERID</th><th>ROLE</th><th>SMPIN</th><th>EMP CODE</th><th>NAME</th><th>Segment</th><th>DEALER CODE</th><th>DEALER</th><th>Zone</th><th>City</th><th>ZM</th><th>RM</th><th>AM</th><th>MOBILE</th><th>EMAIL</th><th>REGISTERED DATE</th></tr>';
        $query_user = $parent->selectQuery(TABLE_USER . " u JOIN " . TABLE_ROLE . " r ON u.role=r.id LEFT JOIN " . DMS_DEALER . " d ON d.dealer_code=u.dealer_code", "u.smpin,u.emp_code,u.fname, u.`lname`,u.segment, u.`emailid`, u.`mobileno`,u.created_on,r.rolename,u.dealer_code,d.dealer_name,d.city,d.zone,d.`zm_name`, d.`rm_name`, d.`am_name`,u.userid", "u.is_deleted=0 AND u.role>2 " . $cond . " ORDER BY u.created_on ", "");
        if ($query_user['nr']) {
            $sno = 1;
            //$s3=awsfileserver::connectS3();
            foreach ($query_user['result'] as $res_user) {
                $dealer_code = ($res_user->dealer_code != '') ? $res_user->dealer_code : '';
                $dealer_data = ($res_user->dealer_code != '') ? $res_user->dealer_name : '';
                $segment = '';
                switch ($res_user->segment) {
                    case '0':$segment = 'Student Learner';
                        break;
                    case '1':$segment = 'Parents/Guardian';
                        break;
                    case '2':$segment = 'Instructor';
                        break;

                }

                echo '<tr><td>' . $sno++ . '</td><td>' . $res_user->userid . '</td><td>' . $res_user->rolename . '</td><td>' . $res_user->smpin . '</td><td>' . $res_user->emp_code . '</td><td>' . $res_user->fname . " " . $res_user->lname . '</td><td>' . $segment . '</td><td>' . $dealer_code . '</td><td>' . $dealer_data . '</td><td>' . $res_user->zone . '</td><td>' . $res_user->city . '</td><td>' . $res_user->zm_name . '</td><td>' . $res_user->rm_name . '</td><td>' . $res_user->am_name . '</td><td>' . $res_user->mobileno . '</td><td>' . $res_user->emailid . '</td><td>' . date('d-m-Y h:i A ', strtotime($res_user->created_on)) . '</td></tr>';

            }
        }
        echo '</table></body></html>';exit;

    }
    /* //////////////////////////////////////////////////////////////////////////////////////////// */

    /* /////////////////////////////// ASSESSMENT //////////////////////////////////////////////// */
    private function assessment($parent)
    {

        globalfunc::checkMethodType($parent, array('GET'));
        globalfunc::checkParamCount($parent, 1);

        $data_arr = array();
        $limit_str = globalfunc::setPageLimit($parent, $parent->params[0]);
        $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';

        echo '<!DOCTYPE html><html>
<head><meta charset="UTF-8"><h3>HYPER-M - ASSESSMENT LIST</h3></head><body>'
            . '<table border="1"><tr><th>#</th><th>ASSESSMENT</th><th>SCORE</th><th>ATTENDED ON</th><th>SMPIN</th><th>NAME</th><th>MOBILE</th><th>DEALER CODE</th><th>DEALER</th><th>CITY</th><th>ZONE</th></tr>';
        //SELECT a.assessmentname,au.highscore,u.smpin, u.fname, u.`lname`, u.`mobileno`,u.dealer_code,d.dealer_name,d.city,d.zone FROM `tbl__assessmentuser` au JOIN tbl__assessment a On a.assessmentid=au.assessmentid JOIN tbl__user u On au.userid=u.userid JOIN tbl__role r ON u.role=r.id LEFT JOIN tbl__dms_dealer d ON d.dealer_code=u.dealer_code WHERE a.assettypeid=1 ORDER BY a.assessmentid ASC

        $query_res = $parent->selectQuery(TABLE_ASSESSMENT_USER . "  au JOIN " . TABLE_ASSESSMENT . " a On a.assessmentid=au.assessmentid JOIN " . TABLE_USER . " u On au.userid=u.userid JOIN " . TABLE_ROLE . " r ON u.role=r.id LEFT JOIN " . DMS_DEALER . " d ON d.dealer_code=u.dealer_code ", "a.assessmentname,au.highscore,au.modified_on,u.smpin, u.fname, u.`lname`, u.`mobileno`,u.dealer_code,d.dealer_name,d.city,d.zone", "a.assettypeid=1 ORDER BY a.assessmentid ASC,au.highscore DESC,au.modified_on ASC ", "");
        if ($query_res['nr']) {
            $sno = 1;
            //$s3=awsfileserver::connectS3();
            foreach ($query_res['result'] as $res) {
                $dealer_code = ($res_user->dealer_code != '') ? $res_user->dealer_code : '';

                echo '<tr><td>' . $sno++ . '</td><td>' . $res->assessmentname . '</td><td>' . $res->highscore . '</td><td>' . date('d-m-Y h:i A', strtotime($res->modified_on)) . '</td><td>' . $res->modified_on . '</td><td>' . $res->smpin . '</td><td>' . $res->fname . " " . $res->lname . '</td><td>' . $res->mobileno . '</td><td>' . $dealer_code . '</td><td>' . $res->dealer_name . '</td><td>' . $res->city . '</td><td>' . $res->zone . '</td></tr>';

            }
        }
        echo '</table></body></html>';exit;

    }
    /* //////////////////////////////////////////////////////////////////////////////////////////// */

/* /////////////////////////////// dmsemployee //////////////////////////////////////////////// */
    private function dmsemployee($parent)
    {

        globalfunc::checkMethodType($parent, array('GET'));
        globalfunc::checkParamCount($parent, 1);

        $data_arr = array();
        $limit_str = globalfunc::setPageLimit($parent, $parent->params[0]);
        $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';

        $cond = '';
        //FILTER
        $filter_arr = globalfunc::getFilterValues($parent, $parent->params[0]);
        if (count($filter_arr) > 0) {
            //smpin
            if (isset($filter_arr['smpin']) && $filter_arr['smpin'] != '') {
                $cond .= " AND u.smpin LIKE '%" . escape_str($filter_arr['smpin']) . "%' ";
            }
            //emp_code
            if (isset($filter_arr['emp_code']) && $filter_arr['emp_code'] != '') {
                $cond .= " AND u.emp_code LIKE '%" . escape_str($filter_arr['emp_code']) . "%' ";
            }
            //fname
            if (isset($filter_arr['fname']) && $filter_arr['fname'] != '') {
                $cond .= " AND u.fname LIKE '%" . escape_str($filter_arr['fname']) . "%' ";
            }
            //lname
            if (isset($filter_arr['lname']) && $filter_arr['lname'] != '') {
                $cond .= " AND u.lname LIKE '%" . escape_str($filter_arr['lname']) . "%' ";
            }
            //dealer_code
            if (isset($filter_arr['dealer_code']) && $filter_arr['dealer_code'] != '') {
                $cond .= " AND u.dealer_code LIKE '%" . escape_str($filter_arr['dealer_code']) . "%' ";
            }
            //role
            if (isset($filter_arr['role']) && $filter_arr['role'] != '') {
                $cond .= " AND u.role LIKE '%" . escape_str($filter_arr['role']) . "%' ";
            }
            //role
            if (isset($filter_arr['mobile']) && $filter_arr['mobile'] != '') {
                $cond .= " AND u.mobile LIKE '%" . escape_str($filter_arr['mobile']) . "%' ";
            }
            //city
            if (isset($filter_arr['city']) && $filter_arr['city'] != '') {
                $cond .= " AND d.city LIKE '%" . escape_str($filter_arr['city']) . "%' ";
            }
            //zone
            if (isset($filter_arr['zone']) && $filter_arr['zone'] != '') {
                $cond .= " AND d.zone LIKE '%" . escape_str($filter_arr['zone']) . "%' ";
            }

        }

        $query_group = $parent->selectQuery(DMS_EMPLOYEE, "COUNT(id) ucount ", "status=1", "");
        echo '<!DOCTYPE html><html>
<head><meta charset="UTF-8"><h3>HYPER-M - EMPLOYEE MASTER DATA </h3></head><body>'
            . '<table border="1"><th>TOTAL COUNT</th></tr>';

        if ($query_group['nr']) {
            foreach ($query_group['result'] as $res) {
                echo '<tr><td>' . $res->ucount . '</td></tr>';
            }
        }
        echo '</table></br></br>'
            . '<table border="1"> ';
        $query_user = $parent->selectQuery(DMS_EMPLOYEE . " u LEFT JOIN " . DMS_DEALER . " d ON d.dealer_code=u.dealer_code", "u.`smpin`, u.`emp_code`, u.`fname`,u. `lname`, u.segment,u.`dealer_code`,u. `role`, u.`emailid`, u.`mobile`,u.is_current,d.dealer_name,d.city,d.zone,u.created_on,u.modified_on", "u.status='1' " . $cond, "");
        if ($query_user['nr']) {
            $sno = 0;
            //$s3=awsfileserver::connectS3();
            foreach ($query_user['result'] as $res_user) {
                if ($sno == 0) {
                    $arr = array_keys((array) $res_user);
                    //print_r(array_keys($a)); exit;
                    echo '<tr><th>#</th>';
                    foreach ($arr as $head) {
                        echo '<th>' . $head . '</td>';
                    }
                    echo '</tr>';
                    $sno++;
                }

                echo '<tr><td>' . $sno++ . '</td>';
                foreach ($res_user as $val) {
                    echo '<td>' . $val . '</td>';
                }
                echo '</tr>';

            }
        }
        echo '</table></body></html>';exit;

    }
    /* //////////////////////////////////////////////////////////////////////////////////////////// */

/* /////////////////////////////// dmsmanager //////////////////////////////////////////////// */
    private function dmsmanager($parent)
    {

        globalfunc::checkMethodType($parent, array('GET'));
        globalfunc::checkParamCount($parent, 1);

        $data_arr = array();
        $limit_str = globalfunc::setPageLimit($parent, $parent->params[0]);
        $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';

        $query_group = $parent->selectQuery(DMS_HOUSER, "COUNT(id) ucount ", "status=1", "");

        $cond = '';
        //FILTER
        $filter_arr = globalfunc::getFilterValues($parent, $parent->params[0]);
        if (count($filter_arr) > 0) {

            //emp_code
            if (isset($filter_arr['emp_code']) && $filter_arr['emp_code'] != '') {
                $cond .= " AND  emp_code LIKE '%" . escape_str($filter_arr['emp_code']) . "%' ";
            }
            //fname
            if (isset($filter_arr['fname']) && $filter_arr['fname'] != '') {
                $cond .= " AND  fname LIKE '%" . escape_str($filter_arr['fname']) . "%' ";
            }
            //lname
            if (isset($filter_arr['lname']) && $filter_arr['lname'] != '') {
                $cond .= " AND  lname LIKE '%" . escape_str($filter_arr['lname']) . "%' ";
            }

            //role
            if (isset($filter_arr['role']) && $filter_arr['role'] != '') {
                $cond .= " AND  role LIKE '%" . escape_str($filter_arr['role']) . "%' ";
            }
            //role
            if (isset($filter_arr['mobile']) && $filter_arr['mobile'] != '') {
                $cond .= " AND  mobile LIKE '%" . escape_str($filter_arr['mobile']) . "%' ";
            }

            //zone
            if (isset($filter_arr['zone']) && $filter_arr['zone'] != '') {
                $cond .= " AND  zone LIKE '%" . escape_str($filter_arr['zone']) . "%' ";
            }

        }

        echo '<!DOCTYPE html><html>
<head><meta charset="UTF-8"><h3>HYPER-M - MANAGER MASTER DATA</h3></head><body>'
            . '<table border="1"><th>TOTAL COUNT</th></tr>';

        if ($query_group['nr']) {
            foreach ($query_group['result'] as $res) {
                echo '<tr><td>' . $res->ucount . '</td></tr>';
            }
        }
        echo '</table></br></br>'
            . '<table border="1"> ';
        $query_user = $parent->selectQuery(DMS_HOUSER, "`emp_code`, `fname`, `lname`, `role`, `emailid`, `mobile`, `dealer_code`, `zone`, `created_on`, `modified_on`", "status='1'" . $cond, "");
        if ($query_user['nr']) {
            $sno = 0;
            //$s3=awsfileserver::connectS3();
            foreach ($query_user['result'] as $res_user) {
                if ($sno == 0) {
                    $arr = array_keys((array) $res_user);
                    //print_r(array_keys($a)); exit;
                    echo '<tr><th>#</th>';
                    foreach ($arr as $head) {
                        echo '<th>' . $head . '</td>';
                    }
                    echo '</tr>';
                    $sno++;
                }
                echo '<tr><td>' . $sno++ . '</td>';
                foreach ($res_user as $val) {
                    echo '<td>' . $val . '</td>';
                }
                echo '</tr>';

            }
        }
        echo '</table></body></html>';exit;

    }
    /* //////////////////////////////////////////////////////////////////////////////////////////// */

    /* /////////////////////////////// dmsdealer //////////////////////////////////////////////// */
    private function dmsdealer($parent)
    {

        globalfunc::checkMethodType($parent, array('GET'));
        globalfunc::checkParamCount($parent, 1);

        $data_arr = array();
        $limit_str = globalfunc::setPageLimit($parent, $parent->params[0]);
        $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';

        $query_group = $parent->selectQuery(DMS_DEALER, "COUNT(id) ucount ", "status=1 AND is_deleted='0'", "");

        $cond = '';
        //FILTER
        $filter_arr = globalfunc::getFilterValues($parent, $parent->params[0]);
        if (count($filter_arr) > 0) {

            //dealer_code
            if (isset($filter_arr['dealer_code']) && $filter_arr['dealer_code'] != '') {
                $cond .= " AND  dealer_code LIKE '%" . escape_str($filter_arr['dealer_code']) . "%' ";
            }
            //dealer_name
            if (isset($filter_arr['dealer_name']) && $filter_arr['dealer_name'] != '') {
                $cond .= " AND  dealer_name LIKE '%" . escape_str($filter_arr['dealer_name']) . "%' ";
            }
            //city
            if (isset($filter_arr['city']) && $filter_arr['city'] != '') {
                $cond .= " AND  city LIKE '%" . escape_str($filter_arr['lname']) . "%' ";
            }

            //state
            if (isset($filter_arr['state']) && $filter_arr['state'] != '') {
                $cond .= " AND  state LIKE '%" . escape_str($filter_arr['state']) . "%' ";
            }
            //mobile
            if (isset($filter_arr['mobile']) && $filter_arr['mobile'] != '') {
                $cond .= " AND  mobile LIKE '%" . escape_str($filter_arr['mobile']) . "%' ";
            }

            //zone
            if (isset($filter_arr['zone']) && $filter_arr['zone'] != '') {
                $cond .= " AND  zone LIKE '%" . escape_str($filter_arr['zone']) . "%' ";
            }

            //zm_name
            if (isset($filter_arr['zm_name']) && $filter_arr['zm_name'] != '') {
                $cond .= " AND  zm_name LIKE '%" . escape_str($filter_arr['zm_name']) . "%' ";
            }

            //rm_name
            if (isset($filter_arr['rm_name']) && $filter_arr['rm_name'] != '') {
                $cond .= " AND  rm_name LIKE '%" . escape_str($filter_arr['rm_name']) . "%' ";
            }

            //am_name
            if (isset($filter_arr['am_name']) && $filter_arr['am_name'] != '') {
                $cond .= " AND  am_name LIKE '%" . escape_str($filter_arr['am_name']) . "%' ";
            }

            //zm_email
            if (isset($filter_arr['zm_email']) && $filter_arr['zm_email'] != '') {
                $cond .= " AND  zm_email LIKE '%" . escape_str($filter_arr['zm_email']) . "%' ";
            }

            //rm_email
            if (isset($filter_arr['rm_email']) && $filter_arr['rm_email'] != '') {
                $cond .= " AND  rm_email LIKE '%" . escape_str($filter_arr['rm_email']) . "%' ";
            }

            //am_email
            if (isset($filter_arr['am_email']) && $filter_arr['am_email'] != '') {
                $cond .= " AND  am_email LIKE '%" . escape_str($filter_arr['am_email']) . "%' ";
            }

            //zm_mobile
            if (isset($filter_arr['zm_mobile']) && $filter_arr['zm_mobile'] != '') {
                $cond .= " AND  zm_mobile LIKE '%" . escape_str($filter_arr['zm_mobile']) . "%' ";
            }

            //rm_mobile
            if (isset($filter_arr['rm_mobile']) && $filter_arr['rm_mobile'] != '') {
                $cond .= " AND  rm_mobile LIKE '%" . escape_str($filter_arr['rm_mobile']) . "%' ";
            }

            //zm_mobile
            if (isset($filter_arr['am_mobile']) && $filter_arr['am_mobile'] != '') {
                $cond .= " AND  am_mobile LIKE '%" . escape_str($filter_arr['am_mobile']) . "%' ";
            }
        }

        echo '<!DOCTYPE html><html>
<head><meta charset="UTF-8"><h3>HYPER-M - DEALER DATA</h3></head><body>'
            . '<table border="1"><th>TOTAL COUNT</th></tr>';

        if ($query_group['nr']) {
            foreach ($query_group['result'] as $res) {
                echo '<tr><td>' . $res->ucount . '</td></tr>';
            }
        }
        echo '</table></br></br>'
            . '<table border="1"> ';
        $query_user = $parent->selectQuery(DMS_DEALER, " `dealer_code`, `dealer_name`,address,email,phone, `city`, `state`, `zone`,  `zm_name`, `rm_name`, `am_name`, `zm_email`, `rm_email`, `am_email`, `zm_mobile`, `rm_mobile`, `am_mobile`  ", "status='1' AND is_deleted=0" . $cond, "");
        if ($query_user['nr']) {
            $sno = 0;
            //$s3=awsfileserver::connectS3();
            foreach ($query_user['result'] as $res_user) {
                if ($sno == 0) {
                    $arr = array_keys((array) $res_user);
                    //print_r(array_keys($a)); exit;
                    echo '<tr><th>#</th>';
                    foreach ($arr as $head) {
                        echo '<th>' . $head . '</td>';
                    }
                    echo '</tr>';
                    $sno++;
                }
                echo '<tr><td>' . $sno++ . '</td>';
                foreach ($res_user as $val) {
                    echo '<td>' . $val . '</td>';
                }
                echo '</tr>';

            }
        }
        echo '</table></body></html>';exit;

    }
    /* //////////////////////////////////////////////////////////////////////////////////////////// */

    /* /////////////////////////////// dmssales //////////////////////////////////////////////// */
    private function dmssales($parent)
    {

        globalfunc::checkMethodType($parent, array('GET'));
        globalfunc::checkParamCount($parent, 1);

        $data_arr = array();
        $limit_str = globalfunc::setPageLimit($parent, $parent->params[0]);
        $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';

        $cond = '';
        //print_r($parent->params);exit;
        $filter_arr = globalfunc::getFilterValues($parent, $parent->params[0]);

        //print_r( $filter_arr);
        if (isset($filter_arr['year']) && $filter_arr['year'] != '' && isset($filter_arr['month']) && $filter_arr['month'] != '') {
            $cond = " AND sale_date>='" . date('Y-m-d', strtotime($filter_arr['year'] . "-" . $filter_arr['month'] . "-01")) . "' AND sale_date<='" . date('Y-m-t', strtotime($filter_arr['year'] . "-" . $filter_arr['month'] . "-01")) . "'";
        }

        if (isset($filter_arr['model']) && $filter_arr['model'] != '') {
            $cond .= " AND model LIKE '%" . escape_str($filter_arr['model']) . "%'";
        }
        if (isset($filter_arr['smpin']) && $filter_arr['smpin'] != '') {
            $cond .= " AND smpin LIKE '%" . escape_str($filter_arr['smpin']) . "%'";
        }

        echo '<!DOCTYPE html><html>
<head><meta charset="UTF-8"><h3>HYPER-M - DSE SALES DATA</h3></head><body>';
        echo '</table></br></br>'
            . '<table border="1"> ';
        $query_user = $parent->selectQuery(DMS_EMPLOYEE_SALES, " `smpin`, `model`, `sale_date`, `sales_count`, `created_on`, `modified_on` ", "1=1 " . $cond, "");
        if ($query_user['nr']) {
            $sno = 0;
            //$s3=awsfileserver::connectS3();
            foreach ($query_user['result'] as $res_user) {
                if ($sno == 0) {
                    $arr = array_keys((array) $res_user);
                    //print_r(array_keys($a)); exit;
                    echo '<tr><th>#</th>';
                    foreach ($arr as $head) {
                        echo '<th>' . $head . '</td>';
                    }
                    echo '</tr>';
                    $sno++;
                }
                echo '<tr><td>' . $sno++ . '</td>';
                foreach ($res_user as $val) {
                    echo '<td>' . $val . '</td>';
                }
                echo '</tr>';

            }
        }
        echo '</table></body></html>';exit;

    }
    /* //////////////////////////////////////////////////////////////////////////////////////////// */

    /* /////////////////////////////// dmstarget //////////////////////////////////////////////// */
    private function dmstarget($parent)
    {

        globalfunc::checkMethodType($parent, array('GET'));
        globalfunc::checkParamCount($parent, 1);

        $data_arr = array();
        $limit_str = globalfunc::setPageLimit($parent, $parent->params[0]);
        $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';

        $cond = '';
        //print_r($parent->params);exit;
        $filter_arr = globalfunc::getFilterValues($parent, $parent->params[0]);

        //print_r( $filter_arr);
        if (isset($filter_arr['year']) && $filter_arr['year'] != '' && isset($filter_arr['month']) && $filter_arr['month'] != '') {
            $cond = " AND sale_month>='" . date('Y-m-d', strtotime($filter_arr['year'] . "-" . $filter_arr['month'] . "-01")) . "' AND sale_month<='" . date('Y-m-t', strtotime($filter_arr['year'] . "-" . $filter_arr['month'] . "-01")) . "'";
        }

        if (isset($filter_arr['model']) && $filter_arr['model'] != '') {
            $cond .= " AND model LIKE '%" . escape_str($filter_arr['model']) . "%'";
        }
        if (isset($filter_arr['smpin']) && $filter_arr['smpin'] != '') {
            $cond .= " AND smpin LIKE '%" . escape_str($filter_arr['smpin']) . "%'";
        }

        echo '<!DOCTYPE html><html>
<head><meta charset="UTF-8"><h3>HYPER-M - DSE TARGET DATA</h3></head><body>';
        echo '</table></br></br>'
            . '<table border="1"> ';
        $query_user = $parent->selectQuery(TABLE_USER_SALETARGET, " `smpin`, `model`, `sale_month`, `target`, `created_on`, `modified_on` ", "1=1 " . $cond, "");
        if ($query_user['nr']) {
            $sno = 0;
            //$s3=awsfileserver::connectS3();
            foreach ($query_user['result'] as $res_user) {
                if ($sno == 0) {
                    $arr = array_keys((array) $res_user);
                    //print_r(array_keys($a)); exit;
                    echo '<tr><th>#</th>';
                    foreach ($arr as $head) {
                        echo '<th>' . $head . '</td>';
                    }
                    echo '</tr>';
                    $sno++;
                }
                echo '<tr><td>' . $sno++ . '</td>';
                foreach ($res_user as $val) {
                    echo '<td>' . $val . '</td>';
                }
                echo '</tr>';

            }
        }
        echo '</table></body></html>';exit;

    }
    /* //////////////////////////////////////////////////////////////////////////////////////////// */

    /* /////////////////////////////// dmsrewardpoints //////////////////////////////////////////////// */
    private function dmsrewardpoints($parent)
    {

        globalfunc::checkMethodType($parent, array('GET'));
        globalfunc::checkParamCount($parent, 1);

        $data_arr = array();
        $limit_str = globalfunc::setPageLimit($parent, $parent->params[0]);
        $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';

        $cond = '';
        //FILTER
        $filter_arr = globalfunc::getFilterValues($parent, $parent->params[0]);
        if (count($filter_arr) > 0) {
            //smpin
            if (isset($filter_arr['smpin']) && $filter_arr['smpin'] != '') {
                $cond .= " AND u.smpin LIKE '%" . escape_str($filter_arr['smpin']) . "%' ";
            }
            //emp_code
            if (isset($filter_arr['emp_code']) && $filter_arr['emp_code'] != '') {
                $cond .= " AND u.emp_code LIKE '%" . escape_str($filter_arr['emp_code']) . "%' ";
            }
            //fname
            if (isset($filter_arr['fname']) && $filter_arr['fname'] != '') {
                $cond .= " AND u.fname LIKE '%" . escape_str($filter_arr['fname']) . "%' ";
            }
            //lname
            if (isset($filter_arr['lname']) && $filter_arr['lname'] != '') {
                $cond .= " AND u.lname LIKE '%" . escape_str($filter_arr['lname']) . "%' ";
            }
            //dealer_code
            if (isset($filter_arr['dealer_code']) && $filter_arr['dealer_code'] != '') {
                $cond .= " AND u.dealer_code LIKE '%" . escape_str($filter_arr['dealer_code']) . "%' ";
            }
            //role
            if (isset($filter_arr['role']) && $filter_arr['role'] != '') {
                $cond .= " AND u.role LIKE '%" . escape_str($filter_arr['role']) . "%' ";
            }
            //role
            if (isset($filter_arr['mobile']) && $filter_arr['mobile'] != '') {
                $cond .= " AND u.mobile LIKE '%" . escape_str($filter_arr['mobile']) . "%' ";
            }
            //city
            if (isset($filter_arr['city']) && $filter_arr['city'] != '') {
                $cond .= " AND d.city LIKE '%" . escape_str($filter_arr['city']) . "%' ";
            }
            //zone
            if (isset($filter_arr['zone']) && $filter_arr['zone'] != '') {
                $cond .= " AND d.zone LIKE '%" . escape_str($filter_arr['zone']) . "%' ";
            }

        }

        $query_group = $parent->selectQuery(DMS_EMPLOYEE, "COUNT(id) ucount ", "status=1", "");
        echo '<!DOCTYPE html><html>
<head><meta charset="UTF-8"><h3>HYPER-M - EMPLOYEE MASTER DATA </h3></head><body>'
            . '<table border="1"><th>TOTAL COUNT</th></tr>';

        if ($query_group['nr']) {
            foreach ($query_group['result'] as $res) {
                echo '<tr><td>' . $res->ucount . '</td></tr>';
            }
        }
        echo '</table></br></br>'
            . '<table border="1"> ';
        $query_user = $parent->selectQuery(DMS_EMPLOYEE . " u JOIN " . TABLE_USER . " as user ON user.smpin=u.smpin AND user.role>7 AND user.role<14 LEFT JOIN " . DMS_DEALER . " d ON d.dealer_code=u.dealer_code LEFT JOIN " . TABLE_USER_EPOINTS . " p ON u.smpin=p.smpin", "u.`smpin`, u.`emp_code`, u.`fname`,u. `lname`,p.points, u.`dealer_code`,u. `role`, u.`emailid`, u.`mobile`,d.dealer_name,d.city,d.zone,u.created_on,u.modified_on", "u.status='1' " . $cond . " ORDER BY p.points DESC ", "");
        if ($query_user['nr']) {
            $sno = 0;
            //$s3=awsfileserver::connectS3();
            foreach ($query_user['result'] as $res_user) {
                if ($sno == 0) {
                    $arr = array_keys((array) $res_user);
                    //print_r(array_keys($a)); exit;
                    echo '<tr><th>#</th>';
                    foreach ($arr as $head) {
                        echo '<th>' . $head . '</td>';
                    }
                    echo '</tr>';
                    $sno++;
                }

                echo '<tr><td>' . $sno++ . '</td>';
                foreach ($res_user as $val) {
                    echo '<td>' . $val . '</td>';
                }
                echo '</tr>';

            }
        }
        echo '</table></body></html>';exit;

    }
    /* //////////////////////////////////////////////////////////////////////////////////////////// */

    /* /////////////////////////////// LAST ACCESS USER //////////////////////////////////////////////// */
    private function lastaccess($parent)
    {
        globalfunc::checkMethodType($parent, array('GET'));
        globalfunc::checkParamCount($parent, 1);

        $data_arr = array();
        $limit_str = globalfunc::setPageLimit($parent, $parent->params[0]);
        $limit_cond = ($limit_str) ? " LIMIT " . $limit_str : '';

        // $query_group=$parent->selectQuery(TABLE_USER." u JOIN ".TABLE_ROLE." r ON u.role=r.id LEFT JOIN ".DMS_DEALER." d ON d.dealer_code=u.dealer_code" ,"COUNT(u.userid) ucount , r.rolename ","u.is_deleted=0 AND u.role>7 AND u.role<14 GROUP BY u.role","");

        echo '<!DOCTYPE html><html>
<head><meta charset="UTF-8"><h3>HYPER-M - REGISTERED USER LIST</h3></head><body>'
            . '<table border="1"><tr><th>#</th><th>ROLE</th><th>SMPIN</th><th>EMP CODE</th><th>NAME</th><th>DEALER CODE</th><th>DEALER</th><th>Zone</th><th>City</th><th>ZM</th><th>RM</th><th>AM</th><th>MOBILE</th><th>EMAIL</th><th>REGISTERED DATE</th><th>LAST ACCESS DATE</th></tr>';
        $query_user = $parent->selectQuery(TABLE_USER . " u LEFT JOIN " . TABLE_USER_LOG . " l ON u.userid=l.userid JOIN " . TABLE_ROLE . " r ON u.role=r.id LEFT JOIN " . DMS_DEALER . " d ON d.dealer_code=u.dealer_code", "u.smpin,u.emp_code,u.fname, u.`lname`, u.`emailid`, u.`mobileno`,u.created_on,r.rolename,u.dealer_code,d.dealer_name,d.city,d.zone,d.`zm_name`, d.`rm_name`, d.`am_name`,MAX(l.created_on) as last_access", "u.is_deleted=0 AND u.role>7 AND u.role<14 GROUP BY u.userid ORDER BY last_access DESC", "");
        if ($query_user['nr']) {
            $sno = 1;
            //$s3=awsfileserver::connectS3();
            foreach ($query_user['result'] as $res_user) {
                $dealer_code = ($res_user->dealer_code != '') ? $res_user->dealer_code : '';
                $dealer_data = ($res_user->dealer_code != '') ? $res_user->dealer_name : '';
                //,<br>'.$res_user->city.',<br>'.$res_user->zone
                $last_access = ($res_user->last_access) ? date('d-m-Y h:i A ', strtotime($res_user->last_access)) : '';

                echo '<tr><td>' . $sno++ . '</td><td>' . $res_user->rolename . '</td><td>' . $res_user->smpin . '</td><td>' . $res_user->emp_code . '</td><td>' . $res_user->fname . " " . $res_user->lname . '</td><td>' . $dealer_code . '</td><td>' . $dealer_data . '</td><td>' . $res_user->zone . '</td><td>' . $res_user->city . '</td><td>' . $res_user->zm_name . '</td><td>' . $res_user->rm_name . '</td><td>' . $res_user->am_name . '</td><td>' . $res_user->mobileno . '</td><td>' . $res_user->emailid . '</td><td>' . date('d-m-Y h:i A ', strtotime($res_user->created_on)) . '</td><td>' . $last_access . '</td></tr>';

            }
        }
        echo '</table></body></html>';exit;

    }
    /* //////////////////////////////////////////////////////////////////////////////////////////// */

    /* /////////////////////////////// CUSTOMER EXPERIENCE //////////////////////////////////////////////// */
    private function customerexperience($parent)
    {
        globalfunc::checkMethodType($parent, array('GET'));
        globalfunc::checkParamCount($parent, 1);

        echo '<!DOCTYPE html><html>
<head><meta charset="UTF-8"><h3>HYPER-M - CUSTOMER EXPERIENCE LIST</h3></head><body>'
            . '<table border="1">';

        // SELECT   FROM tbl__user_customerexp cust LEFT JOIN tbl__ex_enquiry enq ON enq.customerid=cust.id LEFT JOIN tbl__ex_model vm ON vm.model_id=enq.model_id LEFT JOIN tbl__ex_modelvariant vv ON vv.model_id=enq.model_id INNER JOIN tbl__user usr ON usr.userid=cust.userid INNER JOIN tbl__dms_dealer dlr ON dlr.dealer_code=usr.dealer_code WHERE dlr.dealer_code='97105'

        $query_user = $parent->selectQuery(TABLE__CUSTOMEREXP . " cust LEFT JOIN " . TABLE_EXPLORE_ENQUIRY . " enq ON enq.customerid=cust.id LEFT JOIN " . TABLE_COMPARE_MODEL . " vm ON vm.model_id=enq.model_id LEFT JOIN " . TABLE_MODEL_VARIANT . " vv ON vv.model_id=enq.model_id INNER JOIN " . TABLE_USER . " usr ON usr.userid=cust.userid INNER JOIN " . DMS_DEALER . " dlr ON dlr.dealer_code=usr.dealer_code", "CONCAT(CONCAT(cust.salutation, ' ', cust.firstname), ' ', cust.lastname) customer_name, cust.mobile customer_mobile, cust.email customer_email, vm.model_name, vv.title varient, usr.dealer_code, dlr.dealer_name, dlr.am_name area_manager,  dlr.rm_name regional_manager,  dlr.zm_name zone_manager, cust.created_on customer_created, enq.created_on enquiry_on, IF(ISNULL(enq.created_on),'Not Done', 'DONE') enquiry_status ", "1=1 ORDER BY cust.created_on ASC", "");
        if ($query_user['nr']) {
            $sno = 1;
            //$s3=awsfileserver::connectS3();
            foreach ($query_user['result'] as $Key => $res_user) {
                if ($Key == 0) {
                    echo "<tr><th>#</th>";

                    foreach ($res_user as $key => $res) {
                        echo "<th>" . $key . "</th>";
                    }
                    echo "</tr>";
                }

                echo "<tr><td>" . ($Key + 1) . "</td>";
                foreach ($res_user as $key => $res) {
                    echo "<td>" . $res . "</td>";
                }
                echo "</tr>";

            }
        }
        echo '</table></body></html>';exit;

    }
    /* //////////////////////////////////////////////////////////////////////////////////////////// */

    private function activesmpin($parent)
    {
        globalfunc::checkMethodType($parent, array('GET'));
        globalfunc::checkParamCount($parent, 2);

        $smpin = escape_str($parent->params[1]);

        //USER TABLE
        $query_arr = $parent->selectQuery(TABLE_USER . " u LEFT JOIN " . DMS_DEALER . " d ON d.dealer_code=u.dealer_code", "u.userid, u.`smpin`, u.`fname`, u.`lname`, u.`emailid`,u. `mobileno`,u.`dealer_code`, d.`dealer_name`, d.`city`, d.`state`, d.`zone`", "u.is_deleted=0 AND u.status!=1 AND u.role>7 AND role!=14 AND u.smpin='" . $smpin . "'", "1");
        if ($query_arr['nr'] > 0) {
            $updatequery = $parent->executeQuery("UPDATE " . TABLE_USER . " SET status='1' WHERE  smpin='" . $smpin . "' AND userid='" . $query_arr['result'][0]->userid . "'");
            echo '<!DOCTYPE html><html>
<head><meta charset="UTF-8"><h3>HYPER-M - USER DETAILS</h3></head><body> <h1>User data Activated</h1>'
                . '<table border="1">';

            foreach ($query_arr['result'] as $Key => $res_user) {
                if ($Key == 0) {
                    echo "<tr><th>#</th>";

                    foreach ($res_user as $key => $res) {
                        echo "<th>" . $key . "</th>";
                    }
                    echo "</tr>";
                }

                echo "<tr><td>" . ($Key + 1) . "</td>";
                foreach ($res_user as $key => $res) {
                    echo "<td>" . $res . "</td>";
                }
                echo "</tr>";

            }
            echo '</table></body></html>';exit;
        } else {
            //USER TABLE

            $query_arr = $parent->selectQuery(TABLE_USER . " u LEFT JOIN " . DMS_DEALER . " d ON d.dealer_code=u.dealer_code", "u.userid, u.`smpin`, u.`fname`, u.`lname`, u.`emailid`,u. `mobileno`,u.`dealer_code`, d.`dealer_name`, d.`city`, d.`state`, d.`zone`,u.is_deleted,u.status,u.inactivated_on,u.created_on,u.modified_on", " u.role>7 AND role!=14 AND u.smpin='" . $smpin . "'", "1");

            echo '<!DOCTYPE html><html>
	<head><meta charset="UTF-8"><h3>HYPER-M - USER DETAILS</h3></head><body>';

            echo "<h1>User not inactive please check database.</h1>";

            if ($query_arr['nr'] > 0) {
                echo "<h2>User table</h2><br>";
                echo '<table border="1">';

                foreach ($query_arr['result'] as $Key => $res_user) {
                    if ($Key == 0) {
                        echo "<tr><th>#</th>";

                        foreach ($res_user as $key => $res) {
                            echo "<th>" . $key . "</th>";
                        }
                        echo "</tr>";
                    }

                    echo "<tr><td>" . ($Key + 1) . "</td>";
                    foreach ($res_user as $key => $res) {
                        echo "<td>" . $res . "</td>";
                    }
                    echo "</tr>";

                }
                echo '</table>';

            } else {
                echo "<h2>User table data not found</h2><br>";
            }

            //EMPLOLYEE TABLE
            $query_arr = $parent->selectQuery(DMS_EMPLOYEE . " u LEFT JOIN " . DMS_DEALER . " d ON d.dealer_code=u.dealer_code", "u.*, d.`dealer_name`, d.`city`, d.`state`, d.`zone` ", "  u.smpin='" . $smpin . "'", "1");

            if ($query_arr['nr'] > 0) {

                echo '<table border="1">';

                echo "<h2>Employee table </h2><br>";
                foreach ($query_arr['result'] as $Key => $res_user) {
                    if ($Key == 0) {
                        echo "<tr><th>#</th>";

                        foreach ($res_user as $key => $res) {
                            echo "<th>" . $key . "</th>";
                        }
                        echo "</tr>";
                    }

                    echo "<tr><td>" . ($Key + 1) . "</td>";
                    foreach ($res_user as $key => $res) {
                        echo "<td>" . $res . "</td>";
                    }
                    echo "</tr>";

                }
                echo '</table>';

            } else {
                echo "<h2>Emplolyee table data not found</h2><br>";
            }

            echo '</table></body></html>';exit;
        }
    }
    private function loginlog($parent)
    {
        globalfunc::checkMethodType($parent, array('GET'));
        $query_arr = $parent->selectQuery(TABLE_USER, "userid,CONCAT(fname,lname) as name,emp_code", " role=5 ", "");

        echo '<!DOCTYPE html><html>
	<head><meta charset="UTF-8"></head><body><h3>HYPER-M - LOGIN DETAILS</h3>';
        $month = "10";
        $year = "2019";
        $start_date = $year . "-" . $month . "-01";
        $start_time = strtotime($start_date);

        $end_time = strtotime("+1 month", $start_time);

        for ($i = $start_time; $i < $end_time; $i += 86400) {
            $list[] = date('Y-m-d', $i);
        }
        //print_r($list);
        echo '<table border="1"><tr><th>Name</th><th>EMP CODE</th>';
        foreach ($list as $res) {
            echo '<th>' . date('d-m-Y', strtotime($res)) . '</th>';
        }
        echo '</tr>';

        if ($query_arr['nr'] > 0) {
            foreach ($query_arr['result'] as $res_val) {
                echo '<tr><td>' . $res_val->name . '</td><td>' . $res_val->emp_code . '</td>';
                foreach ($list as $res) {

                    $log_arr = $parent->selectQuery(TABLE_USER_LOG, "MAX(created_on)as tdate", " userid='" . $res_val->userid . "' AND date_format(created_on,'%Y-%m-%d')='" . $res . "'", "1");
                    $date_str = ($log_arr['nr'] > 0 && $log_arr['result'][0]->tdate != '') ? date('h:i A', strtotime($log_arr['result'][0]->tdate)) : '';
                    echo '<td>' . $date_str . '</td>';
                }
                echo '</tr>';
            }
        }
        echo '</table></body></html>';exit;
    }

    private function dealerenquiryinactive($parent)
    {
        globalfunc::checkParamCount($parent, 2);
        if (IS_LIVE_SERVER) {
            $parent->response(array('response' => 'failed', 'message' => 'PAGE NOT FOUND'), 404);
        }

        echo $dealer_code = escape_str($parent->params[1]);

        if ($dealer_code) {
            $parent->executeQuery(" UPDATE " . DMS_DEALER . " SET is_enquirymodule='0' WHERE dealer_code='" . $dealer_code . "'");
        }

        $parent->response(array('response' => 'success', 'message' => "SUCCESS"), 200);
    }
}
