示例#1
0
 public function addAction()
 {
     $this->view->messages = $this->_flashMessenger->getMessages();
     $this->_helper->layout->disableLayout();
     $formData = array();
     $formErrors = array();
     $formData = $this->getRequest()->getPost();
     if ($this->getRequest()->isPost() && isset($formData['add_author']) && $formData['add_author'] == 'Add Author') {
         $formData = $this->getRequest()->getPost();
         if (!isset($formData['first_name']) || trim($formData['first_name']) == "") {
             $formErrors['first_name'] = "Please enter first name";
         }
         if (!isset($formData['last_name']) || trim($formData['last_name']) == "") {
             $formErrors['last_name'] = "Please enter last name";
         }
         if (isset($formData['emailid']) && trim($formData['emailid']) != "") {
             if (!CommonFunctions::isValidEmail($formData['emailid'])) {
                 if (!array_key_exists('emailid', $formErrors)) {
                     $formErrors['emailid'] = "Please enter valid email";
                 }
             }
         }
         if ($formData['emailid'] != '') {
             if ($this->modelAuthor->isExist('emailid="' . $formData['emailid'] . '" and parent_id!="0"')) {
                 if (!array_key_exists('emailid', $formErrors)) {
                     $formErrors['emailid'] = "Email already exist";
                 }
             }
         }
         if (count($formErrors) == 0) {
             if ($this->getRequest()->isPost()) {
                 $activationCode = CommonFunctions::generateGUID();
                 $add_time = date('Y-m-d H:i:s');
                 //$formData['password']=CommonFunctions::getRandomNumberPassword(8);
                 $enc_password = md5($formData['password']);
                 $formData['parent_publisher_id'] = !empty($this->sessPublisherInfo->id) ? $this->sessPublisherInfo->id : 0;
                 $username_array = explode("@", $formData['emailid']);
                 $formData['username'] = $username_array[0];
                 $authorData = array('user_type' => 'author', 'parent_id' => $formData['parent_publisher_id'], 'username' => $formData['username'], 'emailid' => $formData['emailid'], 'password' => $enc_password, 'first_name' => $formData['first_name'], 'last_name' => $formData['last_name'], 'phone' => $formData['phone'], 'profile_status' => '1', 'updated_date' => date("Y-m-d H:i:s"), 'add_time' => $add_time);
                 $lastId = $this->modelAuthor->insert($authorData);
                 if ($lastId > 0) {
                     $this->_flashMessenger->addMessage('<div class="div-success">Author Added successfully</div>');
                     $this->_redirect('publisher/author/index/tab_ajax/author/');
                 }
             }
         } else {
             $this->view->errorMessage = '<div class="div-error">Please enter required fields to register.</div>';
         }
     } else {
         $formData['user_type'] = "";
         $formData['first_name'] = "";
         $formData['last_name'] = "";
         $formData['emailid'] = "";
         $formData['password'] = "";
     }
     $this->view->formData = $formData;
     $this->view->formErrors = $formErrors;
 }
    public function createAction()
    {
        $this->view->messages = $this->_flashMessenger->getMessages();
        $this->_helper->layout->disableLayout();
        $formData = array();
        $formErrors = array();
        $formData = $this->getRequest()->getPost();
        //print_r($formData);exit;
        if ($this->getRequest()->isPost() && isset($formData['create_group']) && $formData['create_group'] == 'Create') {
            if (!isset($formData['user_type']) || trim($formData['user_type']) == "") {
                $formErrors['user_type'] = "Please select user type ";
            }
            if (!isset($formData['first_name']) || trim($formData['first_name']) == "") {
                $formErrors['first_name'] = "Please enter first name";
            }
            if (!isset($formData['last_name']) || trim($formData['last_name']) == "") {
                $formErrors['last_name'] = "Please enter last name";
            }
            if (!isset($formData['emailid']) || trim($formData['emailid']) == "") {
                $formErrors['emailid'] = "Please enter email";
            }
            /*if(!(isset($formData['password'])) || trim($formData['password'])=="")
            		{
            			$formErrors['password']="******";
            		}
            		*/
            if (!CommonFunctions::isValidEmail($formData['emailid'])) {
                if (!array_key_exists('emailid', $formErrors)) {
                    $formErrors['emailid'] = "Please enter valid email";
                }
            }
            /*if($this->modelGroup->isExist('username="******"'))
            		{
            			if(!(array_key_exists('username',$formErrors)))
            			{
            				$formErrors['username']="******";
            			}
            		}
            		*/
            if ($this->modelPublisher->isExist('emailid="' . $formData['emailid'] . '"') || $this->modelCompany->isExist('user_email="' . $formData['emailid'] . '"')) {
                if (!array_key_exists('emailid', $formErrors)) {
                    $formErrors['emailid'] = "Email already exist";
                }
            }
            if (count($formErrors) == 0) {
                if ($this->getRequest()->isPost()) {
                    $activationCode = CommonFunctions::generateGUID();
                    $add_time = date('Y-m-d H:i:s');
                    $formData['password'] = CommonFunctions::getRandomNumberPassword(8);
                    $formData['publisher_author_id'] = !empty($this->parentPublisherId) ? $this->parentPublisherId : 0;
                    $username_array = explode("@", $formData['emailid']);
                    $formData['username'] = $username_array[0];
                    $groupUserData = array('parent_id' => $formData['publisher_author_id'], 'user_type' => $formData['user_type'], 'username' => $formData['username'], 'emailid' => $formData['emailid'], 'password' => $formData['password'], 'first_name' => $formData['first_name'], 'last_name' => $formData['last_name'], 'phone' => $formData['phone'], 'profile_status' => '1', 'updated_date' => date("Y-m-d H:i:s"), 'add_time' => $add_time);
                    $lastId = $this->modelPublisher->insert($groupUserData);
                    //$lastId=$this->modelGroup->insert($groupUserData);
                    if ($lastId > 0) {
                        $mailhost = SMTP_SERVER;
                        $mailconfig = array('ssl' => SMTP_SSL, 'port' => SMTP_PORT, 'auth' => SMTP_AUTH, 'username' => SMTP_USERNAME, 'password' => SMTP_PASSWORD);
                        $transport = new Zend_Mail_Transport_Smtp($mailhost, $mailconfig);
                        Zend_Mail::setDefaultTransport($transport);
                        $message = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
							<html xmlns="http://www.w3.org/1999/xhtml">
							<head>
							<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
							<title>Electronic Vendor Ltd</title>
							<style type="text/css">
							body{
							margin:0;
							padding:0px;
							}
							#container{
							width:700px;
							margin:0 auto;
							}
							#header{
							width:700px;
							float:left;
							padding:40px 0 10px 0;
							font-family:Arial, Helvetica, sans-serif;
							color:#3A3B3F;
							text-align:center;
							font-size:11px;
							
							}
							#header a{
							color:#3A3B3F;
							font-weight:bold;
							text-decoration:none;
							}
							#header a:hover{
							color:#40BBE3;
							}
							#logopart
							{
							border:0px solid red;
							width:698px;
							height:140px;
							background-color:#1B75BB;
							margin-left:0px;
							}
							#content{
							width:698px;
							float:left;
							padding:0px 0px 10px 0px;
							font-family:Arial, Helvetica, sans-serif;
							color:#3A3B3F;
							border:1px solid #D6D6D6;
							font-size:12px;
							}
							#content p{
							margin:0px 20px;
							padding:0px 0 20px 0;
							font-family:Arial, Helvetica, sans-serif;
							font-size:12px;
							color:#3A3B3F;
							}
							#content p.logo{
							margin:0px;
							padding:15px 0 0 20px;
							height:77px
							}
							#content p.title{
							margin:0px;
							font-size:20px;
							font-family:Arial, Helvetica, sans-serif;
							border-bottom:3px solid #D6D6D6;
							padding:0px 0 13px 0;
							margin:25px 20px 14px 20px;
							color:#3A3B3F;
							}
							#content p a{
							color:#40BBE3;
							text-decoration:none;
							}
							#content p a:hover{
							color:#3A3B3F;
							text-decoration:underline;
							}
							#content h2{
							margin:0px;
							padding:0 0 14px 0;
							font-size:14px;
							font-family:Arial, Helvetica, sans-serif;
							font-weight:bold;
							}
							#footer{
							width:700px;
							float:left;
							}
							#footer p{
							margin:0 0 0 0;
							padding:0 0 0 0;
							font-family:Arial, Helvetica, sans-serif;
							font-size:11px;
							color:#78797E;
							}
							#footer p.disclamer{
							margin: 0 0 0 0;
							padding:16px 6px 10px 6px;
							text-align: justify;
							border-bottom:1px solid #3A3B3F;
							color:#78797E;
							}
							#footer p.notice{
							margin: 0 0 15px 0;
							padding:16px 6px 10px 6px;
							text-align: justify;
							color:#78797E;
							}
							</style>
							</head>
							<body>
							
							<div id="container">
							<div id="header"></div>
							<div id="content">
							
							<div id="logopart">
							<p class="logo"><a href="' . SVN_URL . '" target="_blank">
							Electronic Vendor Ltd
							</a></p>
							</div>
							
							<p class="title">Group User Registration Email</p>
							<p>Your login details given below :</p>
							<p>Username:&nbsp;' . $formData['username'] . '</p>
							<p>Password:&nbsp;' . $formData['password'] . '</p>
							<BR />
							<p>&nbsp;</p>
							
							</div>
							<div id="footer">&nbsp;</div>
							</div>
							</body>
							</html>';
                        $mail = new Zend_Mail();
                        $mail->addTo($formData['emailid']);
                        $mail->setSubject("Group User Registration Email");
                        $mail->setBodyHtml($message);
                        $mail->setFrom(SETFROM, SETNAME);
                        if ($mail->send()) {
                            $this->_flashMessenger->addMessage('<div class="div-success">Group created successfully</div>');
                        } else {
                            $this->view->errorMessage = '<div class="div-error">Mail could not be sent. Try again later.</div>';
                        }
                        $this->_redirect('publisher/group/index/tab_ajax/group/');
                    }
                }
            } else {
                $this->view->errorMessage = '<div class="div-error">Please enter required fields to register.</div>';
            }
        } else {
            $formData['user_type'] = "";
            $formData['first_name'] = "";
            $formData['last_name'] = "";
            $formData['emailid'] = "";
            $formData['password'] = "";
        }
        $this->view->formData = $formData;
        $this->view->formErrors = $formErrors;
    }
    public function indexAction()
    {
        $this->view->messages = $this->_flashMessenger->getMessages();
        $formData = array();
        $formErrors = array();
        if ($this->getRequest()->isPost()) {
            $formData = $this->getRequest()->getPost();
            //print_r($formData);exit;
            //=====================START FORM VALIDATION===================================
            if (!isset($formData['first_name']) || trim($formData['first_name']) == "") {
                $formErrors['first_name'] = "Please enter your first name";
            }
            if (!isset($formData['last_name']) || trim($formData['last_name']) == "") {
                $formErrors['last_name'] = "Please enter your last name";
            }
            if (!isset($formData['user_email']) || trim($formData['user_email']) == "") {
                $formErrors['user_email'] = "Please enter your email";
            }
            if (!isset($formData['user_password']) || trim($formData['user_password']) == "") {
                $formErrors['user_password'] = "******";
            }
            /*if(!(isset($formData['verify_user_password'])) || trim($formData['verify_user_password'])=="")
            		{
            			$formErrors['verify_user_password']="******";
            		}
            		if($formData['user_password']!=$formData['verify_user_password'])
            		{
            			$formErrors['verify_user_password']="******";
            		}
            		*/
            if (!isset($formData['agree']) || trim($formData['agree']) == "") {
                $formErrors['agree'] = "Please check agree";
            }
            if (!CommonFunctions::isValidEmail($formData['user_email'])) {
                if (!array_key_exists('user_email', $formErrors)) {
                    $formErrors['user_email'] = "Please enter valid email";
                }
            }
            if ($this->modelCompany->isExist('user_email="' . $formData['user_email'] . '"') || $this->modelPublisher->isExist('emailid="' . $formData['user_email'] . '"') || $this->modelGroup->isExist('emailid="' . $formData['user_email'] . '"') || $this->modelMember->isExist('emailid="' . $formData['user_email'] . '"')) {
                if (!array_key_exists('user_email', $formErrors)) {
                    $formErrors['user_email'] = "Email already exist";
                }
            }
            //=====================END FORM VALIDATION===================================
            if (count($formErrors) == 0) {
                //$sessionPost = new Zend_Session_Namespace('step1Post');
                //$sessionPost->formData=$formData;
                //$this->_redirect('company/register/step2');
                $activationCode = CommonFunctions::generateGUID();
                $username_array = explode("@", $formData['user_email']);
                $formData['username'] = $username_array[0];
                $companyData = array('first_name' => $formData['first_name'], 'last_name' => $formData['last_name'], 'account_type' => 1, 'user_name' => $formData['username'], 'user_email' => $formData['user_email'], 'user_password' => $formData['user_password'], 'country' => $formData['country'], 'added_date' => date("Y-m-d H:i:s"), 'updated_date' => date("Y-m-d H:i:s"), 'activation_code' => $activationCode, 'status' => '0');
                $lastId = $this->modelCompany->insert($companyData);
                if ($lastId > 0) {
                    $mailhost = SMTP_SERVER;
                    $mailconfig = array('ssl' => SMTP_SSL, 'port' => SMTP_PORT, 'auth' => SMTP_AUTH, 'username' => SMTP_USERNAME, 'password' => SMTP_PASSWORD);
                    $transport = new Zend_Mail_Transport_Smtp($mailhost, $mailconfig);
                    Zend_Mail::setDefaultTransport($transport);
                    $message = '<!DOCTYPE html>
									<html>
									<head>
									<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
									<meta charset="utf-8">
									<meta name="viewport" content="width=device-width,initial-scale=1.0">
									<title>Evendor</title>
									</head>

									<body style="font-family: \'Calibri\', arial;">
									<div id="container" style="width:80%; margin:0 auto;">
									<header id="heder">
									<div style="padding:15px 0px; background:#000000;"><a href="' . $this->view->serverUrl() . $this->view->baseUrl() . '/" target="_blank"><img src="' . $this->view->serverUrl() . $this->view->baseUrl() . '/public/css/default/images/logo.png" style="border:none;" alt="E-Vendor"></a></div>
									</header>

									<div style="background:#656565; padding:15px; min-height:200px;">
										<aside> 
											<p style="color:#FFBF00; font-weight:bold;">User Registration Email</p>
											<p style="color:#ffffff; font-weight:bold;">Your login details given below :</p>
											<p style="color:#ffffff;"><label style="color:#FFBF00; font-weight:bold; display:inline-block; width:100px;">Username:</label>' . $formData['user_email'] . '</p>
											<p style="color:#ffffff;"><label style="color:#FFBF00; font-weight:bold; display:inline-block; width:100px;">Password:</label>' . $formData['user_password'] . '</p>
											<BR />
											<p style="color:#ffffff;">Activate your account by using given below link :</p>
											<BR />
											<p style="color:#ffffff;"><a href="' . $this->view->serverUrl() . $this->view->baseUrl() . '/company/register/verification/' . $activationCode . '">Account Activation Link</a></p>
											<br>
											<p>&nbsp;</p>
										</aside>
									</div>

									<div style="background:#000000;  text-align:center; color:#FFFFFF; font-size:14px; padding:15px;">
									<br>
									&copy; Copyright ' . date("Y") . ' All Rights Reserved By Electronic Vendor Ltd.
									</div>

									</div>
									</body>
									</html>';
                    $mail = new Zend_Mail();
                    $mail->addTo($formData['user_email']);
                    $mail->setSubject("Company Registration Email");
                    $mail->setBodyHtml($message);
                    $mail->setFrom(SETFROM, SETNAME);
                    if ($mail->send()) {
                        $this->_redirect('company/register/thanks');
                    } else {
                        $this->view->errorMessage = '<div class="div-error">Mail could not be sent. Try again later.</div>';
                    }
                }
            } else {
                $this->view->errorMessage = '<div class="div-error">Please enter required fieild to register.</div>';
            }
        }
        $this->view->formData = $formData;
        $this->view->formErrors = $formErrors;
    }
示例#4
0
    public function postAction()
    {
        // Database Object
        $db = Zend_Registry::get('db');
        $formData = $this->getRequest()->getPost();
        //print_r($formData);
        //exit;
        if (is_array($formData)) {
            if (get_magic_quotes_gpc()) {
                $json_data = stripslashes($formData['jsondata']);
            } else {
                $json_data = $formData['jsondata'];
            }
            /********** Json Object Array ************************/
            $jsonObj = json_decode($json_data);
            $jsonObj = $jsonObj[0];
            /********** Json Object Array ************************/
            /********** Json Array ********************/
            //$jsonArray = json_decode($json_data,true);
            /********** Json Array *******************/
            switch ($jsonObj->apicall) {
                case "UserRegistration":
                    $Errorresponse = "";
                    if (!isset($jsonObj->FirstName) || trim($jsonObj->FirstName) == "" || !isset($jsonObj->LastName) || trim($jsonObj->LastName) == "" || !isset($jsonObj->EmailId) || trim($jsonObj->EmailId) == "" || !isset($jsonObj->Password) || trim($jsonObj->Password) == "") {
                        $Errorresponse = '[{"ParameterMissing":{';
                        if (!isset($jsonObj->FirstName) || trim($jsonObj->FirstName) == "") {
                            $Errorresponse .= '"FirstName":"Please Enter First Name",';
                        }
                        if (!isset($jsonObj->LastName) || trim($jsonObj->LastName) == "") {
                            $Errorresponse .= '"LastName":"Please Enter Last Name",';
                        }
                        if (!isset($jsonObj->EmailId) || trim($jsonObj->EmailId) == "") {
                            $Errorresponse .= '"EmailId":"Please Enter Email Id",';
                        }
                        if (!isset($jsonObj->Password) || trim($jsonObj->Password) == "") {
                            $Errorresponse .= '"Password":"******",';
                        }
                        //if(!(isset($jsonObj->Country)) || trim($jsonObj->Country)=="")
                        //{
                        //$Errorresponse.='"Country":"Please Select A Country"';
                        //}
                        $Errorresponse .= '}}]';
                    }
                    if (!empty($Errorresponse)) {
                        //echo $Errorresponse;
                        $response = '{
								"Message":"All fields are compulsory.",
								"error":"true"
								}';
                        echo $response;
                    } else {
                        $sql = 'SELECT * FROM pclive_companies where user_email="' . $jsonObj->EmailId . '"';
                        $result = $db->query($sql);
                        $record = $result->FetchAll();
                        $sql1 = 'SELECT * FROM pclive_users where emailid="' . $jsonObj->EmailId . '"';
                        $result1 = $db->query($sql1);
                        $record1 = $result1->FetchAll();
                        if (count($record) > 0 || count($record1) > 0) {
                            $response = '{
								"Message":"Email Id already exists",
								"error":"true"
								}';
                            echo $response;
                        } else {
                            $user_name = explode("@", $jsonObj->EmailId);
                            $user_name = $user_name[0];
                            $activationCode = CommonFunctions::generateGUID();
                            $sql = "INSERT INTO pclive_companies (parent_id,group_id,first_name,last_name,account_type,user_name,user_email,user_password,country,status,added_date,updated_date,activation_code)VALUES('0','0','" . $jsonObj->FirstName . "','" . $jsonObj->LastName . "','2','{$user_name}','" . $jsonObj->EmailId . "','" . md5($jsonObj->Password) . "','226','0', NOW(),NOW(),'" . $activationCode . "')";
                            $result = $db->query($sql);
                            if ($result) {
                                $apikeysql = 'SELECT * FROM pclive_apikeys ORDER BY RAND() LIMIT 0,1';
                                $apikeyresult = $db->query($apikeysql);
                                $apikeyrecord = $apikeyresult->FetchAll();
                                if (count($apikeyrecord) == 1) {
                                    $response = '{
										"Message":"You have registered successfully.\\n Your account activation url is sent to your email.",
										"error":"false"
										}';
                                    $mailhost = SMTP_SERVER;
                                    $mailconfig = array('ssl' => SMTP_SSL, 'port' => SMTP_PORT, 'auth' => SMTP_AUTH, 'username' => SMTP_USERNAME, 'password' => SMTP_PASSWORD);
                                    $transport = new Zend_Mail_Transport_Smtp($mailhost, $mailconfig);
                                    Zend_Mail::setDefaultTransport($transport);
                                    $message = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
							<html xmlns="http://www.w3.org/1999/xhtml">
							<head>
							<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
							<title>Electronic Vendor Ltd</title>
							
							</head>
							<body>
							
							<p>Your login details given below :<br></p>
							<p>Username:&nbsp;' . $jsonObj->EmailId . '</p>
						<BR />
											<p style="color:#ffffff;">Activate your account by using given below link :</p>
											<BR />
											<p style="color:#ffffff;"><a href="' . $this->view->serverUrl() . $this->view->baseUrl() . '/user/register/verification/' . $activationCode . '">Account Activation Link</a></p>
										
							<br>
							<p>&nbsp;</p>
							</body>
							</html>';
                                    $mail = new Zend_Mail();
                                    $mail->addTo($jsonObj->EmailId);
                                    $mail->setSubject("Registration Email");
                                    $mail->setBodyHtml($message);
                                    $mail->setFrom(SETFROM, SETNAME);
                                    if ($mail->send()) {
                                        //$response ='{"Message":"Success", "Error":"False" }';
                                        //echo $response;
                                    }
                                }
                                echo $response;
                            } else {
                                $response = '{
										"Message":"Registration failed, please try later again.",
										"error":"true"
										}';
                                echo $response;
                            }
                        }
                        // Check Email Exists
                    }
                    break;
                case "UserLogin":
                    if (isset($jsonObj->EmailId) && !empty($jsonObj->EmailId) && isset($jsonObj->Password)) {
                        $sql = 'SELECT * FROM pclive_companies where user_email="' . $jsonObj->EmailId . '" AND user_password="******" AND   status=1 and account_type!=1';
                        $result = $db->query($sql);
                        $record = $result->FetchAll();
                        /*
                        $sql2 = 'SELECT * FROM pclive_users where emailid="'.$jsonObj->EmailId.'" AND password="******"';
                        					 
                        $result2 = $db->query($sql2);
                        $record2 = $result2->FetchAll();	
                        */
                        if (count($record) > 0) {
                            $apikeysql = 'SELECT * FROM pclive_apikeys ORDER BY RAND() LIMIT 0,1';
                            $apikeyresult = $db->query($apikeysql);
                            $apikeyrecord = $apikeyresult->FetchAll();
                            if (count($apikeyrecord) == 1) {
                                /*$response = '[{"LoginResponse":{
                                		"Message":"Success",
                                		"apikey":"'.$apikeyrecord[0]['apikey'].'"
                                		}}]';*/
                                $sql1 = "SELECT * FROM pclive_country where id='" . $record[0]['country'] . "' ";
                                $result1 = $db->query($sql1);
                                $record1 = $result1->FetchAll();
                                $response = '{
							"Message":"Success",
							"apikey":"' . $apikeyrecord[0]['apikey'] . '",
							"userid":"' . $record[0]['id'] . '",
							"UserType":"user",
							"countryid":"' . $record[0]['country'] . '",
							"Country" : "' . $record1[0]['country'] . '", 
							"FirstName" : "' . $record[0]['first_name'] . '",
							"LastName"	: "' . $record[0]['last_name'] . '","Username":"******","Userpassword":"******","error":"false"
							}';
                                //have to check fo device id
                                //if count<3 then onsert
                                $devicesql = 'SELECT * FROM  pclive_deviceID where user_publisher_id="' . $record[0]['id'] . '" and table_name="pclive_companies"';
                                $deviceresult = $db->query($devicesql);
                                $devicerecord = $deviceresult->FetchAll();
                                $devicesqln = 'SELECT * FROM  pclive_deviceID where user_publisher_id="' . $record[0]['id'] . '" and table_name="pclive_companies" and device_id="' . $jsonObj->DeviceId . '"';
                                $deviceresultn = $db->query($devicesqln);
                                $devicerecordn = $deviceresultn->FetchAll();
                                if (count($devicerecordn) == 0) {
                                    if (count($devicerecord) < 3) {
                                        //check with deviceID only, if exists then delete first
                                        $devicesqlnew = 'delete FROM  pclive_deviceID where device_id="' . $jsonObj->DeviceId . '" and table_name="pclive_companies"';
                                        $deviceresultnew = $db->query($devicesqlnew);
                                        //$devicerecordnew = $deviceresultnew->FetchAll();
                                        $devicesqlinsert = 'insert into pclive_deviceID set user_publisher_id="' . $record[0]['id'] . '", table_name="pclive_companies",device_id="' . $jsonObj->DeviceId . '",reg_id="' . $jsonObj->reg_id . '", os_type="' . $jsonObj->os_type . '"';
                                        $deviceinsertresult = $db->query($devicesqlinsert);
                                        //insert
                                    } else {
                                        //can not login with this device id
                                        $response = '{
							"Message":"You can not log in on more than 3 devices. Please log in on our website to manage your devices",
							"apikey":"",
							"error":"true"
							}';
                                    }
                                }
                            }
                            echo $response;
                        } else {
                            /* $response = '[{"LoginResponse":{
                            	  "Error":"Invalid User Id or Password"
                            	  }}]';*/
                            $response = '{
							"Message":"Invalid username or password.",
							"apikey":"",
							"error":"true"
							}';
                            echo $response;
                        }
                    } else {
                        /*$response = '[{"LoginResponse":{
                          "Error":"User Id does not exist"
                          }}]';*/
                        $response = '{
							"Message":"User Id does not exist.",
							"apikey":"",
							"error":"true"
							}';
                        echo $response;
                    }
                    break;
                case "UserLoginIphone":
                    if (isset($jsonObj->EmailId) && !empty($jsonObj->EmailId) && isset($jsonObj->Password)) {
                        $sql = 'SELECT * FROM pclive_companies where user_email="' . $jsonObj->EmailId . '" AND user_password="******" AND parent_id="0" and status=1 AND account_type<>"3"';
                        $result = $db->query($sql);
                        $record = $result->FetchAll();
                        if (count($record) > 0) {
                            $apikeysql = 'SELECT * FROM pclive_apikeys ORDER BY RAND() LIMIT 0,1';
                            $apikeyresult = $db->query($apikeysql);
                            $apikeyrecord = $apikeyresult->FetchAll();
                            if (count($apikeyrecord) == 1) {
                                /*$response = '[{"LoginResponse":{
                                		"Message":"Success",
                                		"apikey":"'.$apikeyrecord[0]['apikey'].'"
                                		}}]';*/
                                $response = '{
							"Message":"Success",
							"apikey":"' . $apikeyrecord[0]['apikey'] . '",
							"userid":"' . $record[0]['id'] . '",
							"countryid":"' . $record[0]['country'] . '","Username":"******","Userpassword":"******","error":"false"
							}';
                            }
                            echo $response;
                        } else {
                            /* $response = '[{"LoginResponse":{
                            	  "Error":"Invalid User Id or Password"
                            	  }}]';*/
                            $response = '{
							"Message":"Unsuccess",
							"apikey":"",
							"error":"Invalid User Id or Password"
							}';
                            echo $response;
                        }
                    } else {
                        /*$response = '[{"LoginResponse":{
                          "Error":"User Id does not exist"
                          }}]';*/
                        $response = '{
							"Message":"Unsuccess",
							"apikey":"",
							"error":"User Id does not exist"
							}';
                        echo $response;
                    }
                    break;
                case "UserDetail":
                    if (!empty($jsonObj->id) && $jsonObj->id > 0) {
                        $sql = 'SELECT * FROM pclive_companies where id="' . $jsonObj->id . '" AND parent_id="0" AND account_type<>"3"';
                        $result = $db->query($sql);
                        $record = $result->FetchAll();
                        if (count($record) > 0) {
                            if ($record[0]['account_type'] == 1) {
                                $record[0]['account_type'] = "Company";
                            } elseif ($record[0]['account_type'] == 2) {
                                $record[0]['account_type'] = "Individual";
                            } else {
                                $record[0]['account_type'] = $record[0]['account_type'];
                            }
                            $sql1 = "SELECT * FROM pclive_country where id='" . $record[0]['country'] . "' ";
                            $result1 = $db->query($sql1);
                            $record1 = $result1->FetchAll();
                            $response = '[{"UserDetail":{
							"UserType" 	: "' . $record[0]['account_type'] . '",
							"UserEmail"	: "' . $record[0]['user_email'] . '",
							"FirstName" : "' . $record[0]['first_name'] . '",
							"LastName"	: "' . $record[0]['last_name'] . '",
							"Countryid" : "' . $record[0]['country'] . '", 
							"Countryname" : "' . $record1[0]['country'] . '", 
							"JoinTime"	: "' . $record[0]['added_date'] . '"
							}}]';
                            echo $response;
                        } else {
                            $response = '[{"Error":{"Message":"Invalid User Id."}}]';
                            echo $response;
                        }
                    } else {
                        $response = '[{"Error":{"Message":"User Id does not exist"}}]';
                        echo $response;
                    }
                    break;
                case "UserDetailIphone":
                    if (!empty($jsonObj->id) && $jsonObj->id > 0) {
                        //$sql = 'SELECT * FROM pclive_companies where id="'.$jsonObj->id.'" AND parent_id="0" AND account_type<>"3"';
                        $sql = 'SELECT * FROM pclive_companies where id="' . $jsonObj->id . '" AND status=1 and account_type!=1';
                        $result = $db->query($sql);
                        $record = $result->FetchAll();
                        if (count($record) > 0) {
                            if ($record[0]['account_type'] == 1) {
                                $record[0]['account_type'] = "Company";
                            } elseif ($record[0]['account_type'] == 2) {
                                $record[0]['account_type'] = "Individual";
                            } else {
                                $record[0]['account_type'] = $record[0]['account_type'];
                            }
                            $sql1 = "SELECT * FROM pclive_country where id='" . $record[0]['country'] . "' ";
                            $result1 = $db->query($sql1);
                            $record1 = $result1->FetchAll();
                            $response = '{"UserDetail":{
							"UserType" 	: "' . $record[0]['account_type'] . '",
							"Username"	: "' . $record[0]['user_email'] . '",
							"FirstName" : "' . $record[0]['first_name'] . '",
							"LastName"	: "' . $record[0]['last_name'] . '",
							"countryid" : "' . $record[0]['country'] . '", 
							"Country" : "' . $record1[0]['country'] . '", 
							"country_flag_url" :"http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/public/uploads/users/' . $record1[0]['country_flag'] . '",
							"JoinTime"	: "' . $record[0]['added_date'] . '"
							 
							},"Message"  : "Success",
							 "error"    : "false" }';
                            echo $response;
                        } else {
                            $response = '{"Message":"User detail not found","error":"true"}';
                            echo $response;
                        }
                    } else {
                        $response = '{"Message":"User detail not found","error":"true"}';
                        echo $response;
                    }
                    break;
                case "UserSubscriptions":
                    if (!empty($jsonObj->id) && $jsonObj->id > 0) {
                        $sql = "SELECT s.id,s.product_id,s.store_id,s.status,s.added_date,s.updated_date, p.product_type,p.publisher_id,p.author_id,p.title,p.parent_brand_id,p.edition_id,p.description,p.isbn_number,p.publisher,p.total_pages,p.cat_id,p.file_name,p.file_size, pp.country_id,pp.language_id,pp.price FROM pclive_company_subscriptions as s INNER JOIN pclive_products as p ON s.product_id=p.id INNER JOIN pclive_product_prices as pp ON s.product_id=pp.product_id WHERE s.company_id<>0 AND s.company_id='{$jsonObj->id}' AND s.store_id=pp.country_id ORDER BY s.id ASC";
                        $result = $db->query($sql);
                        $records = $result->FetchAll();
                        if (count($records) > 0) {
                            $response = array();
                            foreach ($records as $key => $Parray) {
                                $book_thumb_qry = 'SELECT * from  pclive_product_images where product_id="' . $Parray['product_id'] . '" LIMIT 1';
                                $boothumb_result = $db->query($book_thumb_qry);
                                $book_thumb_record = $boothumb_result->FetchAll();
                                $book_thumb_info = $book_thumb_record[0];
                                $publisher_info_qry = 'SELECT first_name,last_name,emailid,publisher,country,phone from  pclive_users where id="' . $Parray['publisher_id'] . '"';
                                $publisher_info_result = $db->query($publisher_info_qry);
                                $publisher_info_record = $publisher_info_result->FetchAll();
                                $publisher_info = $publisher_info_record[0];
                                if (!empty($Parray['parent_brand_id'])) {
                                    $parent_brand_id_qry = 'SELECT title from pclive_products where id="' . $Parray['parent_brand_id'] . '"';
                                    $brand_info_result = $db->query($parent_brand_id_qry);
                                    $brand_info_record = $brand_info_result->FetchAll();
                                    $brand_info = $brand_info_record[0];
                                    $parent_brand_title_qry = 'SELECT brand from pclive_brands where id="' . $brand_info['title'] . '"';
                                    $parent_brand_info_result = $db->query($parent_brand_title_qry);
                                    $parent_brand_info_record = $parent_brand_info_result->FetchAll();
                                    $parent_brand_info = $parent_brand_info_record[0];
                                }
                                $store_info_qry = 'SELECT country from pclive_country where id="' . $Parray['store_id'] . '"';
                                $store_info_result = $db->query($store_info_qry);
                                $store_info_record = $store_info_result->FetchAll();
                                $store_info = $store_info_record[0];
                                $genre_info_qry = 'SELECT genre from  pclive_genres where id="' . $Parray['product_type'] . '"';
                                $genre_info_result = $db->query($genre_info_qry);
                                $genre_info_record = $genre_info_result->FetchAll();
                                $genre_info = $genre_info_record[0];
                                $cat_info_qry = 'SELECT category_name from   pclive_categories where id="' . $Parray['cat_id'] . '"';
                                $cat_info_result = $db->query($cat_info_qry);
                                $cat_info_record = $cat_info_result->FetchAll();
                                $cat_info = $cat_info_record[0];
                                $lan_info_qry = 'SELECT language_name from pclive_product_language where id="' . $Parray['language_id'] . '"';
                                $lan_info_result = $db->query($lan_info_qry);
                                $lan_info_record = $lan_info_result->FetchAll();
                                $lan_info = $lan_info_record[0];
                                if (strtolower(trim($cat_info['category_name'])) == strtolower(trim('eBook')) || strtolower(trim($cat_info['category_name'])) == strtolower(trim('eBooks'))) {
                                    $author_info_qry = 'SELECT first_name,last_name,emailid,phone from  pclive_users where id="' . $Parray['author_id'] . '"';
                                    $author_info_result = $db->query($author_info_qry);
                                    $author_info_record = $author_info_result->FetchAll();
                                    $author_info = $author_info_record[0];
                                } else {
                                    $edition_info_qry = 'SELECT edition from pclive_editions where id="' . $Parray['edition_id'] . '"';
                                    $edition_info_result = $db->query($edition_info_qry);
                                    $edition_info_record = $edition_info_result->FetchAll();
                                    $edition_info = $edition_info_record[0];
                                }
                                $response['Bookshelve'][$key]['ProductId'] = $Parray['product_id'];
                                if (!empty($parent_brand_info)) {
                                    $title = $Parray['title'] . "(" . ucfirst($parent_brand_info['brand']) . ")";
                                } else {
                                    $title = $Parray['title'];
                                }
                                $response['Bookshelve'][$key]['Title'] = $title;
                                //$thumbnail='<img src="'.$this->view->serverUrl().$this->view->baseUrl()."/".USER_UPLOAD_DIR.$book_thumb_info['image_name_thumb'].'" height="208" width="166">';
                                $thumbnail_path = $this->view->serverUrl() . $this->view->baseUrl() . "/" . USER_UPLOAD_DIR . $book_thumb_info['image_name_thumb'];
                                $response['Bookshelve'][$key]['ProductThumbnail'] = $thumbnail_path;
                                //$response['Bookshelve'][$key]['ProductThumbnail']=$thumbnail;
                                $response['Bookshelve'][$key]['StoreName'] = $store_info['country'];
                                //$response['Bookshelve'][$key]['StoreId']=$Parray['store_id'];
                                $response['Bookshelve'][$key]['Category'] = $cat_info['category_name'];
                                if (isset($edition_info) && !empty($edition_info)) {
                                    $response['Bookshelve'][$key]['Edition'] = $edition_info['edition'];
                                }
                                $response['Bookshelve'][$key]['Genre'] = $genre_info['genre'];
                                $response['Bookshelve'][$key]['Language'] = $lan_info['language_name'];
                                $response['Bookshelve'][$key]['Price'] = $Parray['price'];
                                //$response['Bookshelve'][$key]['TotalDownloads']=$Parray['total_downloads'];
                                $response['Bookshelve'][$key]['PublisherInfo'] = $publisher_info;
                                if (isset($author_info) && !empty($author_info)) {
                                    $response['Bookshelve'][$key]['AuthorInfo'] = $author_info;
                                }
                                $response['Bookshelve'][$key]['Edition'] = $edition_info['edition'];
                                $response['Bookshelve'][$key]['AddedDate'] = $Parray['added_date'];
                                $response['Bookshelve'][$key]['UpdatedDate'] = $Parray['updated_date'];
                            }
                            /*echo"<pre>";
                              print_r($response);
                              */
                            $response = json_encode($response);
                            echo stripslashes($response);
                        } else {
                            $response = '[{"Error":{"Message":"No Records Found."}}]';
                            echo $response;
                        }
                    } else {
                        $response = '[{"Error":{"Message":"User Id does not exist"}}]';
                        echo $response;
                    }
                    break;
                case "GetLibrary":
                    $main_array = array();
                    if (!empty($jsonObj->StoreId) && $jsonObj->StoreId > 0) {
                        $store_qry = 'SELECT is_store,is_store_status from  pclive_country where id="' . $jsonObj->StoreId . '" order by id desc LIMIT 1';
                        $store_result = $db->query($store_qry);
                        $store_record = $store_result->FetchAll();
                        $store_info = $store_record[0];
                        if ($store_info['is_store'] == 1 && $store_info['is_store_status'] == 1) {
                            $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id  WHERE prod.admin_approve='1'  AND prod.file_name!=''  AND storeprice.country_id='{$jsonObj->StoreId}' ORDER BY prod.cat_id ASC";
                        } else {
                            //default nigeria
                            $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id  WHERE prod.admin_approve='1'  AND prod.file_name!=''  AND storeprice.country_id=226 ORDER BY prod.cat_id ASC";
                        }
                    } else {
                        $sql = "SELECT prod.*,c.category_name,g.genre, storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id = storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id WHERE prod.admin_approve='1' AND prod.file_name!=''  ORDER BY prod.cat_id ASC";
                    }
                    $result = $db->query($sql);
                    $records = $result->FetchAll();
                    if (count($records) > 0) {
                        $response['Library'] = $records;
                        foreach ($records as $key => $Parray) {
                            $book_thumb_qry = 'SELECT * from  pclive_product_images where product_id="' . $Parray['product_id'] . '" order by id desc LIMIT 1';
                            $boothumb_result = $db->query($book_thumb_qry);
                            $book_thumb_record = $boothumb_result->FetchAll();
                            $book_thumb_info = $book_thumb_record[0];
                            if ($book_thumb_info['image_name_thumb'] != '') {
                                $thumbnail_path = $this->view->serverUrl() . $this->view->baseUrl() . "/" . USER_UPLOAD_DIR . $book_thumb_info['image_name_thumb'];
                            } else {
                                $thumbnail_path = "";
                            }
                            $bookname = str_replace(" ", "", $Parray['title']);
                            $response['Library'][$key]['ProductThumbnail'] = $thumbnail_path;
                            $response['Library'][$key]['Producturl'] = "http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/api/download/index/apicall/Bookdownload/apikey/" . $jsonObj->apikey . "/bookid/" . $Parray['product_id'] . "/bookname/" . $bookname;
                            //code to get publisher name from user table
                            $pub_qry = 'SELECT publisher from  pclive_users where id="' . $Parray['publisher_id'] . '" order by id desc LIMIT 1';
                            $pub_result = $db->query($pub_qry);
                            $pub_record = $pub_result->FetchAll();
                            $pub_info = $pub_record[0];
                            $response['Library'][$key]['publisher_name'] = $pub_info['publisher'];
                            //code to get author name from user table
                            $author_qry = 'SELECT first_name from  pclive_users where id="' . $Parray['author_id'] . '" order by id desc LIMIT 1';
                            $author_result = $db->query($author_qry);
                            $author_record = $author_result->FetchAll();
                            $author_info = $author_record[0];
                            if ($author_info['first_name'] == "") {
                                $response['Library'][$key]['author_name'] = "";
                            } else {
                                $response['Library'][$key]['author_name'] = $author_info['first_name'];
                            }
                            $review_qry = 'SELECT  avg(rating*1) as rate,`productid` FROM pclive_review where productid="' . $Parray['product_id'] . '" group by productid';
                            $review_result = $db->query($review_qry);
                            $review_record = $review_result->FetchAll();
                            $review_info = $review_record[0];
                            if (count($review_record) > 0) {
                                $rs = explode(".", $review_info['rate']);
                                if ($rs[1] != '') {
                                    if ("." . $rs[1] > 0.5) {
                                        $response['Library'][$key]['rating'] = $rs[0] + 1;
                                    } else {
                                        $response['Library'][$key]['rating'] = $rs[0] + 0.5;
                                    }
                                } else {
                                    $response['Library'][$key]['rating'] = $rs[0];
                                }
                            } else {
                                $response['Library'][$key]['rating'] = 0;
                            }
                            $response['Library'][$key]['books_status'] = "Yes";
                        }
                        /*echo"<pre>";
                          print_r($response);
                          */
                        $get_all_categories = "select * from pclive_genres where status='1' order by genre ASC";
                        $res_all_categories = $db->query($get_all_categories);
                        $data_categories = $res_all_categories->FetchAll();
                        $response['Allcategories'] = $data_categories;
                    } else {
                        $response['Library'][0]['books_status'] = "No";
                    }
                    //$response='{"Library":[{"id":"","product_type":"","publisher_id":"","author_id":"","title":"","edition_id":"","description":"","isbn_number":"","publisher":"","total_pages":"","cat_id":"","parent_brand_id":"","file_name":"","file_size":"","status":"","is_featured":"","admin_approve":"","publish_time":"","add_time":"","best_seller":"","category_name":"","genre":"","product_id":"","country_id":"","language_id":"","price":"","ProductThumbnail":"","Producturl":"","publisher_name":"","author_name":""}],"Allcategories":[{"id":"","parent_id":"","genre":"","added_date":"","updated_date":"","status":""}]}';
                    /*echo "<pre>";
                    		print_r($response);
                    		exit;*/
                    //$response = json_encode($response);
                    //$response =  str_replace("\\", '',$response);
                    //$response = stripslashes(json_encode($response, JSON_HEX_APOS));
                    $response = stripslashes(json_encode($response, JSON_HEX_APOS));
                    echo $response;
                    //echo stripslashes($response);
                    break;
                case "GetNewarrivalsIphone":
                    $main_array = array();
                    if (!empty($jsonObj->StoreId) && $jsonObj->StoreId > 0) {
                        $store_qry = 'SELECT is_store,is_store_status from  pclive_country where id="' . $jsonObj->StoreId . '" order by id desc LIMIT 1';
                        $store_result = $db->query($store_qry);
                        $store_record = $store_result->FetchAll();
                        $store_info = $store_record[0];
                        if ($store_info['is_store'] == 1 && $store_info['is_store_status'] == 1) {
                            $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id  WHERE prod.admin_approve='1'  AND prod.file_name!=''  AND storeprice.country_id='{$jsonObj->StoreId}' ORDER BY prod.cat_id ASC";
                        } else {
                            //default nigeria
                            $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id  WHERE prod.admin_approve='1'  AND prod.file_name!=''  AND storeprice.country_id=226 ORDER BY prod.cat_id ASC";
                        }
                    } else {
                        $sql = "SELECT prod.*,c.category_name,g.genre, storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id = storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id WHERE prod.admin_approve='1' AND prod.file_name!=''  ORDER BY prod.cat_id ASC";
                    }
                    $result = $db->query($sql);
                    $records = $result->FetchAll();
                    if (count($records) > 0) {
                        $response['Library'] = $records;
                        foreach ($records as $key => $Parray) {
                            $book_thumb_qry = 'SELECT * from  pclive_product_images where product_id="' . $Parray['product_id'] . '" order by id desc LIMIT 1';
                            $boothumb_result = $db->query($book_thumb_qry);
                            $book_thumb_record = $boothumb_result->FetchAll();
                            $book_thumb_info = $book_thumb_record[0];
                            if ($book_thumb_info['image_name_thumb'] != '') {
                                $thumbnail_path = $this->view->serverUrl() . $this->view->baseUrl() . "/" . USER_UPLOAD_DIR . $book_thumb_info['image_name_thumb'];
                            } else {
                                $thumbnail_path = "";
                            }
                            $bookname = str_replace(" ", "", $Parray['title']);
                            if (is_numeric($Parray['title'])) {
                                $bookbrand = "select * from pclive_brands where id='" . $Parray['title'] . "' ";
                                $bookbrand_result = $db->query($bookbrand);
                                $bookbrand_record = $bookbrand_result->FetchAll();
                                $bookbrand_info = $bookbrand_record[0];
                                $bookname = str_replace(" ", "", $bookbrand_info['brand']);
                            }
                            $response['Library'][$key]['ProductThumbnail'] = $thumbnail_path;
                            $response['Library'][$key]['Producturl'] = "http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/api/download/index/apicall/Bookdownload/apikey/" . $jsonObj->apikey . "/bookid/" . $Parray['product_id'] . "/bookname/" . $bookname;
                            //code to get publisher name from user table
                            $pub_qry = 'SELECT publisher from  pclive_users where id="' . $Parray['publisher_id'] . '" order by id desc LIMIT 1';
                            $pub_result = $db->query($pub_qry);
                            $pub_record = $pub_result->FetchAll();
                            $pub_info = $pub_record[0];
                            $response['Library'][$key]['publisher_name'] = $pub_info['publisher'];
                            //code to get author name from user table
                            $author_qry = 'SELECT first_name from  pclive_users where id="' . $Parray['author_id'] . '" order by id desc LIMIT 1';
                            $author_result = $db->query($author_qry);
                            $author_record = $author_result->FetchAll();
                            $author_info = $author_record[0];
                            if ($author_info['first_name'] == "") {
                                $response['Library'][$key]['author_name'] = "";
                            } else {
                                $response['Library'][$key]['author_name'] = $author_info['first_name'];
                            }
                            $review_qry = 'SELECT  avg(rating*1) as rate,`productid` FROM pclive_review where productid="' . $Parray['product_id'] . '" group by productid';
                            $review_result = $db->query($review_qry);
                            $review_record = $review_result->FetchAll();
                            $review_info = $review_record[0];
                            if (count($review_record) > 0) {
                                $rs = explode(".", $review_info['rate']);
                                if ($rs[1] != '') {
                                    if ("." . $rs[1] > 0.5) {
                                        $response['Library'][$key]['rating'] = $rs[0] + 1;
                                    } else {
                                        $response['Library'][$key]['rating'] = $rs[0] + 0.5;
                                    }
                                } else {
                                    $response['Library'][$key]['rating'] = $rs[0];
                                }
                            } else {
                                $response['Library'][$key]['rating'] = 0;
                            }
                            $response['Library'][$key]['books_status'] = "Yes";
                        }
                        $get_all_categories = "select * from pclive_genres where status='1' order by genre ASC";
                        $res_all_categories = $db->query($get_all_categories);
                        $data_categories = $res_all_categories->FetchAll();
                        $response['Allcategories'] = $data_categories;
                    } else {
                        $response['Library'][0]['books_status'] = "No";
                    }
                    //$response = stripslashes(json_encode($response, JSON_HEX_APOS));
                    //echo $response;
                    if (!empty($jsonObj->StoreId) && $jsonObj->StoreId > 0) {
                        $store_qry = 'SELECT is_store,is_store_status from  pclive_country where id="' . $jsonObj->StoreId . '" order by id desc LIMIT 1';
                        $store_result = $db->query($store_qry);
                        $store_record = $store_result->FetchAll();
                        $store_info = $store_record[0];
                        if ($store_info['is_store'] == 1 && $store_info['is_store_status'] == 1) {
                            $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id  WHERE prod.admin_approve='1'  AND prod.file_name!=''  AND storeprice.country_id='{$jsonObj->StoreId}' ORDER BY prod.id DESC";
                        } else {
                            //default nigeria
                            $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id  WHERE prod.admin_approve='1'  AND prod.file_name!=''  AND storeprice.country_id=226 ORDER BY prod.id DESC";
                        }
                    } else {
                        $sql = "SELECT prod.*,c.category_name,g.genre, storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id = storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id WHERE prod.admin_approve='1' AND prod.file_name!=''  ORDER BY prod.id DESC";
                    }
                    $result = $db->query($sql);
                    $records = $result->FetchAll();
                    if (count($records) > 0) {
                        $response['Newarrivals'] = $records;
                        foreach ($records as $key => $Parray) {
                            $book_thumb_qry = 'SELECT * from  pclive_product_images where product_id="' . $Parray['product_id'] . '" order by id desc LIMIT 1';
                            $boothumb_result = $db->query($book_thumb_qry);
                            $book_thumb_record = $boothumb_result->FetchAll();
                            $book_thumb_info = $book_thumb_record[0];
                            if ($book_thumb_info['image_name_thumb'] != '') {
                                $thumbnail_path = $this->view->serverUrl() . $this->view->baseUrl() . "/" . USER_UPLOAD_DIR . $book_thumb_info['image_name_thumb'];
                            } else {
                                $thumbnail_path = "";
                            }
                            $bookname = str_replace(" ", "", $Parray['title']);
                            if (is_numeric($Parray['title'])) {
                                $bookbrand = "select * from pclive_brands where id='" . $Parray['title'] . "' ";
                                $bookbrand_result = $db->query($bookbrand);
                                $bookbrand_record = $bookbrand_result->FetchAll();
                                $bookbrand_info = $bookbrand_record[0];
                                $bookname = str_replace(" ", "", $bookbrand_info['brand']);
                            }
                            $response['Newarrivals'][$key]['ProductThumbnail'] = $thumbnail_path;
                            $response['Newarrivals'][$key]['Producturl'] = "http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/api/download/index/apicall/Bookdownload/apikey/" . $jsonObj->apikey . "/bookid/" . $Parray['product_id'] . "/bookname/" . $bookname;
                            //code to get publisher name from user table
                            $pub_qry = 'SELECT publisher from  pclive_users where id="' . $Parray['publisher_id'] . '" order by id desc LIMIT 1';
                            $pub_result = $db->query($pub_qry);
                            $pub_record = $pub_result->FetchAll();
                            $pub_info = $pub_record[0];
                            $response['Newarrivals'][$key]['publisher_name'] = $pub_info['publisher'];
                            //code to get author name from user table
                            $author_qry = 'SELECT first_name from  pclive_users where id="' . $Parray['author_id'] . '" order by id desc LIMIT 1';
                            $author_result = $db->query($author_qry);
                            $author_record = $author_result->FetchAll();
                            $author_info = $author_record[0];
                            if ($author_info['first_name'] == "") {
                                $response['Newarrivals'][$key]['author_name'] = "";
                            } else {
                                $response['Newarrivals'][$key]['author_name'] = $author_info['first_name'];
                            }
                            $review_qry = 'SELECT  avg(rating*1) as rate,`productid` FROM pclive_review where productid="' . $Parray['product_id'] . '" group by productid';
                            $review_result = $db->query($review_qry);
                            $review_record = $review_result->FetchAll();
                            $review_info = $review_record[0];
                            if (count($review_record) > 0) {
                                $rs = explode(".", $review_info['rate']);
                                if ($rs[1] != '') {
                                    if ("." . $rs[1] > 0.5) {
                                        $response['Newarrivals'][$key]['rating'] = $rs[0] + 1;
                                    } else {
                                        $response['Newarrivals'][$key]['rating'] = $rs[0] + 0.5;
                                    }
                                } else {
                                    $response['Newarrivals'][$key]['rating'] = $rs[0];
                                }
                            } else {
                                $response['Newarrivals'][$key]['rating'] = 0;
                            }
                            $response['Newarrivals'][$key]['books_status'] = "Yes";
                        }
                    } else {
                        $response['Newarrivals'][0]['books_status'] = "No";
                    }
                    /*echo "<pre>";
                    		print_r($response);
                    		exit;*/
                    //$response = json_encode($response);
                    //$response =  str_replace("\\", '',$response);
                    $response = stripslashes(json_encode($response, JSON_HEX_APOS));
                    echo $response;
                    //echo stripslashes($response);
                    break;
                case "GetBestsellersIphone":
                    $main_array = array();
                    if (!empty($jsonObj->StoreId) && $jsonObj->StoreId > 0) {
                        $store_qry = 'SELECT is_store,is_store_status from  pclive_country where id="' . $jsonObj->StoreId . '" order by id desc LIMIT 1';
                        $store_result = $db->query($store_qry);
                        $store_record = $store_result->FetchAll();
                        $store_info = $store_record[0];
                        if ($store_info['is_store'] == 1 && $store_info['is_store_status'] == 1) {
                            $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id  WHERE prod.admin_approve='1'  AND prod.file_name!=''  AND storeprice.country_id='{$jsonObj->StoreId}' ORDER BY prod.cat_id ASC";
                        } else {
                            //default nigeria
                            $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id  WHERE prod.admin_approve='1'  AND prod.file_name!=''  AND storeprice.country_id=226 ORDER BY prod.cat_id ASC";
                        }
                    } else {
                        $sql = "SELECT prod.*,c.category_name,g.genre, storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id = storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id WHERE prod.admin_approve='1' AND prod.file_name!=''  ORDER BY prod.cat_id ASC";
                    }
                    $result = $db->query($sql);
                    $records = $result->FetchAll();
                    if (count($records) > 0) {
                        $response['Library'] = $records;
                        foreach ($records as $key => $Parray) {
                            $book_thumb_qry = 'SELECT * from  pclive_product_images where product_id="' . $Parray['product_id'] . '" order by id desc LIMIT 1';
                            $boothumb_result = $db->query($book_thumb_qry);
                            $book_thumb_record = $boothumb_result->FetchAll();
                            $book_thumb_info = $book_thumb_record[0];
                            if ($book_thumb_info['image_name_thumb'] != '') {
                                $thumbnail_path = $this->view->serverUrl() . $this->view->baseUrl() . "/" . USER_UPLOAD_DIR . $book_thumb_info['image_name_thumb'];
                            } else {
                                $thumbnail_path = "";
                            }
                            $bookname = str_replace(" ", "", $Parray['title']);
                            if (is_numeric($Parray['title'])) {
                                $bookbrand = "select * from pclive_brands where id='" . $Parray['title'] . "' ";
                                $bookbrand_result = $db->query($bookbrand);
                                $bookbrand_record = $bookbrand_result->FetchAll();
                                $bookbrand_info = $bookbrand_record[0];
                                $bookname = str_replace(" ", "", $bookbrand_info['brand']);
                            }
                            $response['Library'][$key]['ProductThumbnail'] = $thumbnail_path;
                            $response['Library'][$key]['Producturl'] = "http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/api/download/index/apicall/Bookdownload/apikey/" . $jsonObj->apikey . "/bookid/" . $Parray['product_id'] . "/bookname/" . $bookname;
                            //code to get publisher name from user table
                            $pub_qry = 'SELECT publisher from  pclive_users where id="' . $Parray['publisher_id'] . '" order by id desc LIMIT 1';
                            $pub_result = $db->query($pub_qry);
                            $pub_record = $pub_result->FetchAll();
                            $pub_info = $pub_record[0];
                            $response['Library'][$key]['publisher_name'] = $pub_info['publisher'];
                            //code to get author name from user table
                            $author_qry = 'SELECT first_name from  pclive_users where id="' . $Parray['author_id'] . '" order by id desc LIMIT 1';
                            $author_result = $db->query($author_qry);
                            $author_record = $author_result->FetchAll();
                            $author_info = $author_record[0];
                            if ($author_info['first_name'] == "") {
                                $response['Library'][$key]['author_name'] = "";
                            } else {
                                $response['Library'][$key]['author_name'] = $author_info['first_name'];
                            }
                            $review_qry = 'SELECT  avg(rating*1) as rate,`productid` FROM pclive_review where productid="' . $Parray['product_id'] . '" group by productid';
                            $review_result = $db->query($review_qry);
                            $review_record = $review_result->FetchAll();
                            $review_info = $review_record[0];
                            if (count($review_record) > 0) {
                                $rs = explode(".", $review_info['rate']);
                                if ($rs[1] != '') {
                                    if ("." . $rs[1] > 0.5) {
                                        $response['Library'][$key]['rating'] = $rs[0] + 1;
                                    } else {
                                        $response['Library'][$key]['rating'] = $rs[0] + 0.5;
                                    }
                                } else {
                                    $response['Library'][$key]['rating'] = $rs[0];
                                }
                            } else {
                                $response['Library'][$key]['rating'] = 0;
                            }
                            $response['Library'][$key]['books_status'] = "Yes";
                        }
                        $get_all_categories = "select * from pclive_genres where status='1' order by genre ASC";
                        $res_all_categories = $db->query($get_all_categories);
                        $data_categories = $res_all_categories->FetchAll();
                        $response['Allcategories'] = $data_categories;
                    } else {
                        $response['Library'][0]['books_status'] = "No";
                    }
                    if (!empty($jsonObj->StoreId) && $jsonObj->StoreId > 0) {
                        $store_qry = 'SELECT is_store,is_store_status from  pclive_country where id="' . $jsonObj->StoreId . '" order by id desc LIMIT 1';
                        $store_result = $db->query($store_qry);
                        $store_record = $store_result->FetchAll();
                        $store_info = $store_record[0];
                        if ($store_info['is_store'] == 1 && $store_info['is_store_status'] == 1) {
                            $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id  WHERE prod.admin_approve='1'  AND prod.file_name!=''  AND storeprice.country_id='{$jsonObj->StoreId}' ORDER BY prod.best_seller DESC";
                        } else {
                            //default nigeria
                            $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id  WHERE prod.admin_approve='1'  AND prod.file_name!=''  AND storeprice.country_id=226 ORDER BY prod.best_seller DESC";
                        }
                    } else {
                        $sql = "SELECT prod.*,c.category_name,g.genre, storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id = storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id WHERE prod.admin_approve='1' AND prod.file_name!=''  ORDER BY prod.best_seller DESC";
                    }
                    $result = $db->query($sql);
                    $records = $result->FetchAll();
                    if (count($records) > 0) {
                        $response['Bestsellers'] = $records;
                        foreach ($records as $key => $Parray) {
                            $book_thumb_qry = 'SELECT * from  pclive_product_images where product_id="' . $Parray['product_id'] . '" order by id desc LIMIT 1';
                            $boothumb_result = $db->query($book_thumb_qry);
                            $book_thumb_record = $boothumb_result->FetchAll();
                            $book_thumb_info = $book_thumb_record[0];
                            if ($book_thumb_info['image_name_thumb'] != '') {
                                $thumbnail_path = $this->view->serverUrl() . $this->view->baseUrl() . "/" . USER_UPLOAD_DIR . $book_thumb_info['image_name_thumb'];
                            } else {
                                $thumbnail_path = "";
                            }
                            $bookname = str_replace(" ", "", $Parray['title']);
                            if (is_numeric($Parray['title'])) {
                                $bookbrand = "select * from pclive_brands where id='" . $Parray['title'] . "' ";
                                $bookbrand_result = $db->query($bookbrand);
                                $bookbrand_record = $bookbrand_result->FetchAll();
                                $bookbrand_info = $bookbrand_record[0];
                                $bookname = str_replace(" ", "", $bookbrand_info['brand']);
                            }
                            $response['Bestsellers'][$key]['ProductThumbnail'] = $thumbnail_path;
                            $response['Bestsellers'][$key]['Producturl'] = "http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/api/download/index/apicall/Bookdownload/apikey/" . $jsonObj->apikey . "/bookid/" . $Parray['product_id'] . "/bookname/" . $bookname;
                            //code to get publisher name from user table
                            $pub_qry = 'SELECT publisher from  pclive_users where id="' . $Parray['publisher_id'] . '" order by id desc LIMIT 1';
                            $pub_result = $db->query($pub_qry);
                            $pub_record = $pub_result->FetchAll();
                            $pub_info = $pub_record[0];
                            $response['Bestsellers'][$key]['publisher_name'] = $pub_info['publisher'];
                            //code to get author name from user table
                            $author_qry = 'SELECT first_name from  pclive_users where id="' . $Parray['author_id'] . '" order by id desc LIMIT 1';
                            $author_result = $db->query($author_qry);
                            $author_record = $author_result->FetchAll();
                            $author_info = $author_record[0];
                            if ($author_info['first_name'] == "") {
                                $response['Bestsellers'][$key]['author_name'] = "";
                            } else {
                                $response['Bestsellers'][$key]['author_name'] = $author_info['first_name'];
                            }
                            $review_qry = 'SELECT  avg(rating*1) as rate,`productid` FROM pclive_review where productid="' . $Parray['product_id'] . '" group by productid';
                            $review_result = $db->query($review_qry);
                            $review_record = $review_result->FetchAll();
                            $review_info = $review_record[0];
                            if (count($review_record) > 0) {
                                $rs = explode(".", $review_info['rate']);
                                if ($rs[1] != '') {
                                    if ("." . $rs[1] > 0.5) {
                                        $response['Bestsellers'][$key]['rating'] = $rs[0] + 1;
                                    } else {
                                        $response['Bestsellers'][$key]['rating'] = $rs[0] + 0.5;
                                    }
                                } else {
                                    $response['Bestsellers'][$key]['rating'] = $rs[0];
                                }
                            } else {
                                $response['Bestsellers'][$key]['rating'] = 0;
                            }
                            $response['Bestsellers'][$key]['books_status'] = "Yes";
                        }
                    } else {
                        $response['Bestsellers'][0]['books_status'] = "No";
                    }
                    /*echo "<pre>";
                    		print_r($response);
                    		exit;*/
                    //$response = json_encode($response);
                    //$response =  str_replace("\\", '',$response);
                    $response = stripslashes(json_encode($response, JSON_HEX_APOS));
                    echo $response;
                    //echo stripslashes($response);
                    break;
                case "GetBestsellers":
                    $main_array = array();
                    if (!empty($jsonObj->StoreId) && $jsonObj->StoreId > 0) {
                        $store_qry = 'SELECT is_store,is_store_status from  pclive_country where id="' . $jsonObj->StoreId . '" order by id desc LIMIT 1';
                        $store_result = $db->query($store_qry);
                        $store_record = $store_result->FetchAll();
                        $store_info = $store_record[0];
                        if ($store_info['is_store'] == 1 && $store_info['is_store_status'] == 1) {
                            $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id  WHERE prod.admin_approve='1'  AND prod.file_name!=''  AND storeprice.country_id='{$jsonObj->StoreId}' ORDER BY prod.best_seller DESC";
                        } else {
                            //default nigeria
                            $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id  WHERE prod.admin_approve='1'  AND prod.file_name!=''  AND storeprice.country_id=226 ORDER BY prod.best_seller DESC";
                        }
                    } else {
                        $sql = "SELECT prod.*,c.category_name,g.genre, storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id = storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id WHERE prod.admin_approve='1' AND prod.file_name!=''  ORDER BY prod.best_seller DESC";
                    }
                    $result = $db->query($sql);
                    $records = $result->FetchAll();
                    if (count($records) > 0) {
                        $response['Bestsellers'] = $records;
                        foreach ($records as $key => $Parray) {
                            $book_thumb_qry = 'SELECT * from  pclive_product_images where product_id="' . $Parray['product_id'] . '" order by id desc LIMIT 1';
                            $boothumb_result = $db->query($book_thumb_qry);
                            $book_thumb_record = $boothumb_result->FetchAll();
                            $book_thumb_info = $book_thumb_record[0];
                            if ($book_thumb_info['image_name_thumb'] != '') {
                                $thumbnail_path = $this->view->serverUrl() . $this->view->baseUrl() . "/" . USER_UPLOAD_DIR . $book_thumb_info['image_name_thumb'];
                            } else {
                                $thumbnail_path = "";
                            }
                            $bookname = str_replace(" ", "", $Parray['title']);
                            $response['Bestsellers'][$key]['ProductThumbnail'] = $thumbnail_path;
                            $response['Bestsellers'][$key]['Producturl'] = "http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/api/download/index/apicall/Bookdownload/apikey/" . $jsonObj->apikey . "/bookid/" . $Parray['product_id'] . "/bookname/" . $bookname;
                            //code to get publisher name from user table
                            $pub_qry = 'SELECT publisher from  pclive_users where id="' . $Parray['publisher_id'] . '" order by id desc LIMIT 1';
                            $pub_result = $db->query($pub_qry);
                            $pub_record = $pub_result->FetchAll();
                            $pub_info = $pub_record[0];
                            $response['Bestsellers'][$key]['publisher_name'] = $pub_info['publisher'];
                            //code to get author name from user table
                            $author_qry = 'SELECT first_name from  pclive_users where id="' . $Parray['author_id'] . '" order by id desc LIMIT 1';
                            $author_result = $db->query($author_qry);
                            $author_record = $author_result->FetchAll();
                            $author_info = $author_record[0];
                            if ($author_info['first_name'] == "") {
                                $response['Bestsellers'][$key]['author_name'] = "";
                            } else {
                                $response['Bestsellers'][$key]['author_name'] = $author_info['first_name'];
                            }
                            $review_qry = 'SELECT  avg(rating*1) as rate,`productid` FROM pclive_review where productid="' . $Parray['product_id'] . '" group by productid';
                            $review_result = $db->query($review_qry);
                            $review_record = $review_result->FetchAll();
                            $review_info = $review_record[0];
                            if (count($review_record) > 0) {
                                $rs = explode(".", $review_info['rate']);
                                if ($rs[1] != '') {
                                    if ("." . $rs[1] > 0.5) {
                                        $response['Bestsellers'][$key]['rating'] = $rs[0] + 1;
                                    } else {
                                        $response['Bestsellers'][$key]['rating'] = $rs[0] + 0.5;
                                    }
                                } else {
                                    $response['Bestsellers'][$key]['rating'] = $rs[0];
                                }
                            } else {
                                $response['Bestsellers'][$key]['rating'] = 0;
                            }
                            $response['Bestsellers'][$key]['books_status'] = "Yes";
                        }
                        $get_all_categories = "select * from pclive_genres where status='1' order by genre ASC";
                        $res_all_categories = $db->query($get_all_categories);
                        $data_categories = $res_all_categories->FetchAll();
                        $response['Allcategories'] = $data_categories;
                        /*echo"<pre>";
                          print_r($response);
                          */
                    } else {
                        $response['Bestsellers'][0]['books_status'] = "No";
                    }
                    /*echo "<pre>";
                    		print_r($response);
                    		exit;*/
                    //$response = json_encode($response);
                    //$response =  str_replace("\\", '',$response);
                    $response = stripslashes(json_encode($response, JSON_HEX_APOS));
                    echo $response;
                    //echo stripslashes($response);
                    break;
                case "GetNewarrivals":
                    $main_array = array();
                    if (!empty($jsonObj->StoreId) && $jsonObj->StoreId > 0) {
                        $store_qry = 'SELECT is_store,is_store_status from  pclive_country where id="' . $jsonObj->StoreId . '" order by id desc LIMIT 1';
                        $store_result = $db->query($store_qry);
                        $store_record = $store_result->FetchAll();
                        $store_info = $store_record[0];
                        if ($store_info['is_store'] == 1 && $store_info['is_store_status'] == 1) {
                            $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id  WHERE prod.admin_approve='1'  AND prod.file_name!=''  AND storeprice.country_id='{$jsonObj->StoreId}' ORDER BY prod.id DESC";
                        } else {
                            //default nigeria
                            $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id  WHERE prod.admin_approve='1'  AND prod.file_name!=''  AND storeprice.country_id=226 ORDER BY prod.id DESC";
                        }
                    } else {
                        $sql = "SELECT prod.*,c.category_name,g.genre, storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id = storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id WHERE prod.admin_approve='1' AND prod.file_name!=''  ORDER BY prod.id DESC";
                    }
                    $result = $db->query($sql);
                    $records = $result->FetchAll();
                    if (count($records) > 0) {
                        $response['Newarrivals'] = $records;
                        foreach ($records as $key => $Parray) {
                            $book_thumb_qry = 'SELECT * from  pclive_product_images where product_id="' . $Parray['product_id'] . '" order by id desc LIMIT 1';
                            $boothumb_result = $db->query($book_thumb_qry);
                            $book_thumb_record = $boothumb_result->FetchAll();
                            $book_thumb_info = $book_thumb_record[0];
                            if ($book_thumb_info['image_name_thumb'] != '') {
                                $thumbnail_path = $this->view->serverUrl() . $this->view->baseUrl() . "/" . USER_UPLOAD_DIR . $book_thumb_info['image_name_thumb'];
                            } else {
                                $thumbnail_path = "";
                            }
                            $bookname = str_replace(" ", "", $Parray['title']);
                            $response['Newarrivals'][$key]['ProductThumbnail'] = $thumbnail_path;
                            $response['Newarrivals'][$key]['Producturl'] = "http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/api/download/index/apicall/Bookdownload/apikey/" . $jsonObj->apikey . "/bookid/" . $Parray['product_id'] . "/bookname/" . $bookname;
                            //code to get publisher name from user table
                            $pub_qry = 'SELECT publisher from  pclive_users where id="' . $Parray['publisher_id'] . '" order by id desc LIMIT 1';
                            $pub_result = $db->query($pub_qry);
                            $pub_record = $pub_result->FetchAll();
                            $pub_info = $pub_record[0];
                            $response['Newarrivals'][$key]['publisher_name'] = $pub_info['publisher'];
                            //code to get author name from user table
                            $author_qry = 'SELECT first_name from  pclive_users where id="' . $Parray['author_id'] . '" order by id desc LIMIT 1';
                            $author_result = $db->query($author_qry);
                            $author_record = $author_result->FetchAll();
                            $author_info = $author_record[0];
                            if ($author_info['first_name'] == "") {
                                $response['Newarrivals'][$key]['author_name'] = "";
                            } else {
                                $response['Newarrivals'][$key]['author_name'] = $author_info['first_name'];
                            }
                            $review_qry = 'SELECT  avg(rating*1) as rate,`productid` FROM pclive_review where productid="' . $Parray['product_id'] . '" group by productid';
                            $review_result = $db->query($review_qry);
                            $review_record = $review_result->FetchAll();
                            $review_info = $review_record[0];
                            if (count($review_record) > 0) {
                                $rs = explode(".", $review_info['rate']);
                                if ($rs[1] != '') {
                                    if ("." . $rs[1] > 0.5) {
                                        $response['Newarrivals'][$key]['rating'] = $rs[0] + 1;
                                    } else {
                                        $response['Newarrivals'][$key]['rating'] = $rs[0] + 0.5;
                                    }
                                } else {
                                    $response['Newarrivals'][$key]['rating'] = $rs[0];
                                }
                            } else {
                                $response['Newarrivals'][$key]['rating'] = 0;
                            }
                            $response['Newarrivals'][$key]['books_status'] = "Yes";
                        }
                        $get_all_categories = "select * from pclive_genres where status='1' order by genre ASC";
                        $res_all_categories = $db->query($get_all_categories);
                        $data_categories = $res_all_categories->FetchAll();
                        $response['Allcategories'] = $data_categories;
                        /*echo"<pre>";
                          print_r($response);
                          */
                    } else {
                        $response['Newarrivals'][0]['books_status'] = "No";
                    }
                    /*echo "<pre>";
                    		print_r($response);
                    		exit;*/
                    //$response = json_encode($response);
                    //$response =  str_replace("\\", '',$response);
                    $response = stripslashes(json_encode($response, JSON_HEX_APOS));
                    echo $response;
                    //echo stripslashes($response);
                    break;
                case "GetPurchaseHistory":
                    $main_array = array();
                    //$sql="SELECT prod.*,c.category_name,g.genre, FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id = storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id INNER JOIN pclive_credit_history hs on prod.id =hs.bookid 	WHERE hs.userid='$jsonObj->UserId' ORDER BY prod.cat_id ASC";
                    $sql = "SELECT prod.id, prod.title,prod.description,prod.file_size,prod.publisher_id,prod.author_id,c.category_name, g.genre, hs.price,hs.userid,hs.add_date FROM pclive_products AS prod INNER JOIN pclive_categories c ON c.id = prod.cat_id INNER JOIN pclive_genres g ON prod.product_type = g.id INNER JOIN pclive_credit_history hs ON prod.id = hs.bookid WHERE hs.userid ='{$jsonObj->UserId}' ORDER BY prod.cat_id ASC";
                    $result = $db->query($sql);
                    $records = $result->FetchAll();
                    if (count($records) > 0) {
                        $response['Purchase'] = $records;
                        foreach ($records as $key => $Parray) {
                            $book_thumb_qry = 'SELECT * from  pclive_product_images where product_id="' . $Parray['id'] . '" order by id desc LIMIT 1';
                            $boothumb_result = $db->query($book_thumb_qry);
                            $book_thumb_record = $boothumb_result->FetchAll();
                            $book_thumb_info = $book_thumb_record[0];
                            if ($book_thumb_info['image_name_thumb'] != '') {
                                $thumbnail_path = $this->view->serverUrl() . $this->view->baseUrl() . "/" . USER_UPLOAD_DIR . $book_thumb_info['image_name_thumb'];
                            } else {
                                $thumbnail_path = "";
                            }
                            $bookname = str_replace(" ", "", $Parray['title']);
                            $response['Purchase'][$key]['ProductThumbnail'] = $thumbnail_path;
                            $response['Purchase'][$key]['Producturl'] = "http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/api/download/index/apicall/Bookdownload/apikey/" . $jsonObj->apikey . "/bookid/" . $Parray['id'] . "/bookname/" . $bookname;
                            //code to get publisher name from user table
                            $pub_qry = 'SELECT publisher from  pclive_users where id="' . $Parray['publisher_id'] . '" order by id desc LIMIT 1';
                            $pub_result = $db->query($pub_qry);
                            $pub_record = $pub_result->FetchAll();
                            $pub_info = $pub_record[0];
                            $response['Purchase'][$key]['publisher_name'] = $pub_info['publisher'];
                            //code to get author name from user table
                            $author_qry = 'SELECT first_name from  pclive_users where id="' . $Parray['author_id'] . '" order by id desc LIMIT 1';
                            $author_result = $db->query($author_qry);
                            $author_record = $author_result->FetchAll();
                            $author_info = $author_record[0];
                            if ($author_info['first_name'] == "") {
                                $response['Purchase'][$key]['author_name'] = "";
                            } else {
                                $response['Purchase'][$key]['author_name'] = $author_info['first_name'];
                            }
                            $response['Purchase'][$key]['status'] = "Yes";
                            $amount_qry = "SELECT sum(`amount`) as total  FROM  pclive_payment_history where user_id='{$jsonObj->UserId}' group by user_id";
                            $amount_result = $db->query($amount_qry);
                            $amount_record = $amount_result->FetchAll();
                            $amount_info = $amount_record[0];
                            if (count($amount_record) > 0) {
                                $response['Amount'] = $amount_info['total'];
                            } else {
                                $response['Amount'] = 0;
                            }
                        }
                    } else {
                        //$response['Library']="No books available";
                        $response['Purchase'][0]['status'] = "No";
                    }
                    $response = stripslashes(json_encode($response, JSON_HEX_APOS));
                    echo $response;
                    break;
                case "GetPurchaseHistoryNew":
                    $main_array = array();
                    //$sql="SELECT prod.*,c.category_name,g.genre, FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id = storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id INNER JOIN pclive_credit_history hs on prod.id =hs.bookid 	WHERE hs.userid='$jsonObj->UserId' ORDER BY prod.cat_id ASC";
                    $sql = "SELECT prod.id, prod.title,prod.description,prod.file_size,prod.publisher_id,prod.author_id,prod.publish_time,c.category_name, g.genre, hs.price,hs.userid,hs.add_date FROM pclive_products AS prod INNER JOIN pclive_categories c ON c.id = prod.cat_id INNER JOIN pclive_genres g ON prod.product_type = g.id INNER JOIN pclive_credit_history hs ON prod.id = hs.bookid WHERE hs.userid ='{$jsonObj->UserId}' ORDER BY prod.cat_id ASC";
                    $result = $db->query($sql);
                    $records = $result->FetchAll();
                    if (count($records) > 0) {
                        $response['Purchase'] = $records;
                        foreach ($records as $key => $Parray) {
                            $book_thumb_qry = 'SELECT * from  pclive_product_images where product_id="' . $Parray['id'] . '" order by id desc LIMIT 1';
                            $boothumb_result = $db->query($book_thumb_qry);
                            $book_thumb_record = $boothumb_result->FetchAll();
                            $book_thumb_info = $book_thumb_record[0];
                            if ($book_thumb_info['image_name_thumb'] != '') {
                                $thumbnail_path = $this->view->serverUrl() . $this->view->baseUrl() . "/" . USER_UPLOAD_DIR . $book_thumb_info['image_name_thumb'];
                            } else {
                                $thumbnail_path = "";
                            }
                            $bookname = str_replace(" ", "", $Parray['title']);
                            $response['Purchase'][$key]['ProductThumbnail'] = $thumbnail_path;
                            $response['Purchase'][$key]['Producturl'] = "http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/api/download/index/apicall/Bookdownload/apikey/" . $jsonObj->apikey . "/bookid/" . $Parray['id'] . "/bookname/" . $bookname;
                            //code to get publisher name from user table
                            $pub_qry = 'SELECT publisher from  pclive_users where id="' . $Parray['publisher_id'] . '" order by id desc LIMIT 1';
                            $pub_result = $db->query($pub_qry);
                            $pub_record = $pub_result->FetchAll();
                            $pub_info = $pub_record[0];
                            $response['Purchase'][$key]['publisher_name'] = $pub_info['publisher'];
                            //code to get author name from user table
                            $author_qry = 'SELECT first_name from  pclive_users where id="' . $Parray['author_id'] . '" order by id desc LIMIT 1';
                            $author_result = $db->query($author_qry);
                            $author_record = $author_result->FetchAll();
                            $author_info = $author_record[0];
                            if ($author_info['first_name'] == "") {
                                $response['Purchase'][$key]['author_name'] = "";
                            } else {
                                $response['Purchase'][$key]['author_name'] = $author_info['first_name'];
                            }
                            $response['Purchase'][$key]['status'] = "Yes";
                            $amount_qry = "SELECT sum(`amount`) as total  FROM  pclive_payment_history where user_id='{$jsonObj->UserId}' group by user_id";
                            $amount_result = $db->query($amount_qry);
                            $amount_record = $amount_result->FetchAll();
                            $amount_info = $amount_record[0];
                            if (count($amount_record) > 0) {
                                $response['Amount'] = $amount_info['total'];
                            } else {
                                $response['Amount'] = 0;
                            }
                        }
                    } else {
                        //$response['Library']="No books available";
                        $response['Purchase'][0]['status'] = "No";
                    }
                    $sql1 = "select * from pclive_payment_history where user_id='{$jsonObj->UserId}'";
                    $result1 = $db->query($sql1);
                    $records1 = $result1->FetchAll();
                    if (count($records1) > 0) {
                        $response['PurchasePoint'] = $records1;
                        $credit = 0;
                        foreach ($records1 as $key => $Parray1) {
                            $credit += $Parray1['amount'];
                        }
                        $sql2 = "SELECT sum( `price` ) AS expense FROM pclive_credit_history where userid='{$jsonObj->UserId}' GROUP BY userid";
                        $result2 = $db->query($sql2);
                        $records2 = $result2->FetchAll();
                        $expense_info = $records2[0];
                        $balance = $credit - $expense_info['expense'];
                        $response['Balance'] = $balance;
                    } else {
                        //$response['Library']="No books available";
                        $response['PurchasePoint'][0]['status'] = "No";
                    }
                    $response = stripslashes(json_encode($response, JSON_HEX_APOS));
                    echo $response;
                    break;
                case "GetPurchaseHistoryNew1":
                    $main_array = array();
                    $TotalTransaction = 0;
                    if ($jsonObj->type == 'user') {
                        $sql = "SELECT prod.id, prod.title,prod.description,prod.file_size,prod.publisher_id,prod.author_id, prod.cat_id,prod.file_name,prod.publish_time,c.category_name, g.genre, hs.price,hs.userid,hs.add_date FROM pclive_products AS prod INNER JOIN pclive_categories c ON c.id = prod.cat_id INNER JOIN pclive_genres g ON prod.product_type = g.id INNER JOIN pclive_credit_history hs ON prod.id = hs.bookid INNER JOIN pclive_user_sub_details as chd WHERE hs.order_id=chd.order_id  and hs.userid ='" . $jsonObj->UserId . "' and hs.payment_status=1 GROUP BY prod.id ORDER BY hs.credit_id desc";
                        $result = $db->query($sql);
                        $records = $result->FetchAll();
                        if (count($records) > 0) {
                            $response['Purchase'] = $records;
                            foreach ($records as $key => $Parray) {
                                //get store_id from book_id and userid from pclive_credit_history
                                $retVal1 = array();
                                $select1 = 'SELECT store_id from  pclive_credit_history where bookid="' . $Parray['id'] . '" and userid="' . $Parray['userid'] . '" ';
                                $currency_result = $db->query($select1);
                                $retVal1 = $currency_result->FetchAll();
                                $select2 = 'SELECT  `currency_sign` from  `pclive_currency` INNER JOIN pclive_country ON pclive_currency.`currency_id`= pclive_country.`currency_id` where id="' . $retVal1[0]['store_id'] . '" ';
                                $currency_result1 = $db->query($select2);
                                $retVal2 = $currency_result1->FetchAll();
                                $response['Purchase'][$key]['priceText'] = $retVal2[0]['currency_sign'] . " " . $response['Purchase'][$key]['price'];
                                $book_thumb_qry = 'SELECT * from  pclive_product_images where product_id="' . $Parray['id'] . '" order by id desc LIMIT 1';
                                $boothumb_result = $db->query($book_thumb_qry);
                                $book_thumb_record = $boothumb_result->FetchAll();
                                $book_thumb_info = $book_thumb_record[0];
                                if ($book_thumb_info['image_name_thumb'] != '') {
                                    $thumbnail_path = $this->view->serverUrl() . $this->view->baseUrl() . "/" . USER_UPLOAD_DIR . $book_thumb_info['image_name_thumb'];
                                } else {
                                    $thumbnail_path = "";
                                }
                                $bookname = str_replace(" ", "", $Parray['title']);
                                if (is_numeric($Parray['title'])) {
                                    $bookbrand = "select * from pclive_brands where id='" . $Parray['title'] . "' ";
                                    $bookbrand_result = $db->query($bookbrand);
                                    $bookbrand_record = $bookbrand_result->FetchAll();
                                    $bookbrand_info = $bookbrand_record[0];
                                    $response['Purchase'][$key]['title'] = $bookbrand_info['brand'];
                                    $bookname = str_replace(" ", "", $bookbrand_info['brand']);
                                }
                                /*	
                                $this->modelBooks = new Publisher_Model_DbTable_Books();	
                                $getBrandInfo=$this->modelBooks->getBrandInfo($Parray['title']);
                                if(!empty($getBrandInfo) && is_numeric($Parray['title']))
                                {
                                	$bookname=$getBrandInfo['brand'];
                                }else
                                {
                                	$bookname=$Parray['title'];
                                }
                                
                                if(!empty($Parray['parent_brand_id']) && $Parray['cat_id']!='3')
                                {
                                $productInfo=$this->modelBooks->fetchRow('id="'.$Parray['parent_brand_id'].'"');
                                $getParentBrandInfo=$this->modelBooks->getBrandInfo($productInfo->title);
                                	if(!empty($getParentBrandInfo))
                                	{
                                		$bookname=$getParentBrandInfo['brand'].'-'.$bookname;
                                	}
                                //$all=getPublicationIdsByCategoryName();	
                                }
                                $response['Purchase'][$key]['title']=$bookname;	
                                $bookname= str_replace(" ","",$bookname);
                                */
                                $response['Purchase'][$key]['ProductThumbnail'] = $thumbnail_path;
                                $response['Purchase'][$key]['Producturl'] = "http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/api/download/index/apicall/Bookdownload/apikey/" . $jsonObj->apikey . "/bookid/" . $Parray['id'] . "/bookname/" . $bookname;
                                $response['Purchase'][$key]['publish_time'] = $Parray['publish_time'] . " 00:00:00";
                                //code to get publisher name from user table
                                $pub_qry = 'SELECT publisher from  pclive_users where id="' . $Parray['publisher_id'] . '" order by id desc LIMIT 1';
                                $pub_result = $db->query($pub_qry);
                                $pub_record = $pub_result->FetchAll();
                                $pub_info = $pub_record[0];
                                $response['Purchase'][$key]['publisher_name'] = $pub_info['publisher'];
                                $response['Purchase'][$key]['publisher'] = $pub_info['publisher'];
                                //code to get author name from user table
                                $author_qry = 'SELECT first_name,last_name from  pclive_users where id="' . $Parray['author_id'] . '" order by id desc LIMIT 1';
                                $author_result = $db->query($author_qry);
                                $author_record = $author_result->FetchAll();
                                $author_info = $author_record[0];
                                if ($author_info['first_name'] == "") {
                                    $response['Purchase'][$key]['author_name'] = "";
                                } else {
                                    $response['Purchase'][$key]['author_name'] = $author_info['first_name'] . " " . $author_info['last_name'];
                                }
                                $response['Purchase'][$key]['status'] = "Yes";
                                //calculate total purchase
                                $TotalTransaction += $Parray['price'];
                            }
                            $response['TotalTransaction'] = $TotalTransaction;
                        } else {
                            $response['TotalTransaction'] = "0";
                        }
                        //$response['Library']="No books available";
                        //$response['Purchase'][0]['status']="No";
                        $sql1 = "select * from pclive_payment_history where user_id='{$jsonObj->UserId}'";
                        $result1 = $db->query($sql1);
                        $records1 = $result1->FetchAll();
                        if (count($records1) > 0) {
                            $response['PurchasePoint'] = $records1;
                            $credit = 0;
                            foreach ($records1 as $key => $Parray1) {
                                $credit += $Parray1['amount'];
                            }
                            $sql2 = "SELECT sum( `price` ) AS expense FROM pclive_credit_history where userid='{$jsonObj->UserId}' and payment_status=1 GROUP BY userid";
                            $result2 = $db->query($sql2);
                            $records2 = $result2->FetchAll();
                            $expense_info = $records2[0];
                            $balance = $credit - $expense_info['expense'];
                            $response['Balance'] = $balance;
                            $amount_qry = "SELECT sum(`amount`) as total  FROM  pclive_payment_history where user_id='{$jsonObj->UserId}' group by user_id";
                            $amount_result = $db->query($amount_qry);
                            $amount_record = $amount_result->FetchAll();
                            $amount_info = $amount_record[0];
                            if (count($amount_record) > 0) {
                                $response['TotalPurchase'] = $amount_info['total'];
                            } else {
                                $response['TotalPurchase'] = 0;
                            }
                        } else {
                        }
                        //$response['Library']="No books available";
                        //$response['PurchasePoint'][0]['status']="No";
                        $response = stripslashes(json_encode($response, JSON_HEX_APOS));
                        echo $response;
                    } else {
                        //echo ">>>>there";
                        if (!empty($jsonObj->StoreId) && $jsonObj->StoreId > 0) {
                            $store_qry = 'SELECT is_store,is_store_status from  pclive_country where id="' . $jsonObj->StoreId . '" order by id desc LIMIT 1';
                            $store_result = $db->query($store_qry);
                            $store_record = $store_result->FetchAll();
                            $store_info = $store_record[0];
                            if ($store_info['is_store'] == 1 && $store_info['is_store_status'] == 1) {
                                $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id  WHERE prod.admin_approve='1'  AND prod.file_name!=''  AND storeprice.country_id='{$jsonObj->StoreId}' ORDER BY prod.cat_id ASC";
                            } else {
                                //default nigeria
                                $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id  WHERE prod.admin_approve='1'  AND prod.file_name!=''  AND storeprice.country_id=226 ORDER BY prod.cat_id ASC";
                            }
                        } else {
                            $sql = "SELECT prod.*,c.category_name,g.genre, storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id = storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id WHERE prod.admin_approve='1' AND prod.file_name!='' and prod.publisher_id='{$jsonObj->UserId}' group by prod.id ORDER BY prod.cat_id ASC";
                        }
                        $result = $db->query($sql);
                        $records = $result->FetchAll();
                        if (count($records) > 0) {
                            $response['Purchase'] = $records;
                            foreach ($records as $key => $Parray) {
                                $book_thumb_qry = 'SELECT * from  pclive_product_images where product_id="' . $Parray['product_id'] . '" order by id desc LIMIT 1';
                                $boothumb_result = $db->query($book_thumb_qry);
                                $book_thumb_record = $boothumb_result->FetchAll();
                                $book_thumb_info = $book_thumb_record[0];
                                if ($book_thumb_info['image_name_thumb'] != '') {
                                    $thumbnail_path = $this->view->serverUrl() . $this->view->baseUrl() . "/" . USER_UPLOAD_DIR . $book_thumb_info['image_name_thumb'];
                                } else {
                                    $thumbnail_path = "";
                                }
                                $bookname = str_replace(" ", "", $Parray['title']);
                                if (is_numeric($Parray['title'])) {
                                    $bookbrand = "select * from pclive_brands where id='" . $Parray['title'] . "' ";
                                    $bookbrand_result = $db->query($bookbrand);
                                    $bookbrand_record = $bookbrand_result->FetchAll();
                                    $bookbrand_info = $bookbrand_record[0];
                                    $bookname = str_replace(" ", "", $bookbrand_info['brand']);
                                }
                                $retVal = array();
                                $select = 'SELECT * from pclive_country where id="' . $Parray['country_id'] . '"';
                                $country_result = $db->query($select);
                                $retVal = $country_result->FetchAll();
                                $response['Purchase'][$key]['country_name'] = $retVal[0]['country'];
                                //echo ">>>>>".$retVal['currency_id'];
                                $retVal1 = array();
                                $select1 = 'SELECT * from pclive_currency where currency_id="' . $retVal[0]['currency_id'] . '"';
                                $currency_result = $db->query($select1);
                                $retVal1 = $currency_result->FetchAll();
                                $response['Purchase'][$key]['ProductThumbnail'] = $thumbnail_path;
                                $response['Purchase'][$key]['Producturl'] = "http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/api/download/index/apicall/Bookdownload/apikey/" . $jsonObj->apikey . "/bookid/" . $Parray['product_id'] . "/bookname/" . $bookname;
                                //code to get publisher name from user table
                                $pub_qry = 'SELECT publisher from  pclive_users where id="' . $Parray['publisher_id'] . '" order by id desc LIMIT 1';
                                $pub_result = $db->query($pub_qry);
                                $pub_record = $pub_result->FetchAll();
                                $pub_info = $pub_record[0];
                                $response['Purchase'][$key]['publisher_name'] = $pub_info['publisher'];
                                //code to get author name from user table
                                $author_qry = 'SELECT first_name,last_name from  pclive_users where id="' . $Parray['author_id'] . '" order by id desc LIMIT 1';
                                $author_result = $db->query($author_qry);
                                $author_record = $author_result->FetchAll();
                                $author_info = $author_record[0];
                                if ($author_info['first_name'] == "") {
                                    $response['Purchase'][$key]['author_name'] = "";
                                } else {
                                    $response['Purchase'][$key]['author_name'] = $author_info['first_name'] . " " . $author_info['last_name'];
                                }
                                // get symbol with price $retVal1[0]['currency_sign'];
                                $response['Purchase'][$key]['priceText'] = $retVal1[0]['currency_sign'] . " " . $response['Purchase'][$key]['price'];
                            }
                            $response['Message'] = "Success.";
                            $response['error'] = "false";
                        } else {
                            //$response = '[{"Error": {"Message":"No New Arrivals Found.","error":"true"}}]';
                            $response['Message'] = "No Books in library.";
                            $response['error'] = "true";
                        }
                        $response = stripslashes(json_encode($response, JSON_HEX_APOS));
                        echo $response;
                    }
                    break;
                case "GetPurchasePoint":
                    $main_array = array();
                    $sql = "select * from pclive_payment_history where user_id='{$jsonObj->UserId}'";
                    $result = $db->query($sql);
                    $records = $result->FetchAll();
                    if (count($records) > 0) {
                        $response['PurchasePoint'] = $records;
                        $credit = 0;
                        foreach ($records as $key => $Parray) {
                            $credit += $Parray['amount'];
                        }
                        $sql1 = "SELECT sum( `price` ) AS expense FROM pclive_credit_history where userid='{$jsonObj->UserId}' and payment_status=1 GROUP BY userid";
                        $result1 = $db->query($sql1);
                        $records1 = $result1->FetchAll();
                        $expense_info = $records1[0];
                        $balance = $credit - $expense_info['expense'];
                        $response['Balance'] = $balance;
                    } else {
                        //$response['Library']="No books available";
                        $response['PurchasePoint'][0]['status'] = "No";
                    }
                    $response = stripslashes(json_encode($response, JSON_HEX_APOS));
                    echo $response;
                    break;
                case "GetFeatured":
                    $main_array = array();
                    if (!empty($jsonObj->StoreId) && $jsonObj->StoreId > 0) {
                        $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id  WHERE prod.admin_approve='1'  AND prod.file_name!='' and is_featured=1  AND storeprice.country_id='{$jsonObj->StoreId}' ORDER BY prod.product_type*1 ASC";
                    } else {
                        $sql = "SELECT prod.*,c.category_name,g.genre, storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id = storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id WHERE prod.admin_approve='1' AND prod.file_name!='' and is_featured=1   ORDER BY prod.product_type*1 ASC";
                    }
                    $result = $db->query($sql);
                    $records = $result->FetchAll();
                    if (count($records) > 0) {
                        $response['Featured'] = $records;
                        foreach ($records as $key => $Parray) {
                            $book_thumb_qry = 'SELECT * from  pclive_product_images where product_id="' . $Parray['product_id'] . '" order by id desc LIMIT 1';
                            $boothumb_result = $db->query($book_thumb_qry);
                            $book_thumb_record = $boothumb_result->FetchAll();
                            $book_thumb_info = $book_thumb_record[0];
                            if ($book_thumb_info['image_name_thumb'] != '') {
                                $thumbnail_path = $this->view->serverUrl() . $this->view->baseUrl() . "/" . USER_UPLOAD_DIR . $book_thumb_info['image_name_thumb'];
                            } else {
                                $thumbnail_path = "";
                            }
                            $bookname = str_replace(" ", "", $Parray['title']);
                            $response['Featured'][$key]['ProductThumbnail'] = $thumbnail_path;
                            $response['Featured'][$key]['Producturl'] = "http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/api/download/index/apicall/Bookdownload/apikey/" . $jsonObj->apikey . "/bookid/" . $Parray['product_id'] . "/bookname/" . $bookname;
                            //code to get publisher name from user table
                            $pub_qry = 'SELECT publisher from  pclive_users where id="' . $Parray['publisher_id'] . '" order by id desc LIMIT 1';
                            $pub_result = $db->query($pub_qry);
                            $pub_record = $pub_result->FetchAll();
                            $pub_info = $pub_record[0];
                            $response['Featured'][$key]['publisher_name'] = $pub_info['publisher'];
                            //code to get author name from user table
                            $author_qry = 'SELECT first_name from  pclive_users where id="' . $Parray['author_id'] . '" order by id desc LIMIT 1';
                            $author_result = $db->query($author_qry);
                            $author_record = $author_result->FetchAll();
                            $author_info = $author_record[0];
                            if ($author_info['first_name'] == "") {
                                $response['Featured'][$key]['author_name'] = "";
                            } else {
                                $response['Featured'][$key]['author_name'] = $author_info['first_name'];
                            }
                        }
                    }
                    $response = stripslashes(json_encode($response, JSON_HEX_APOS));
                    echo $response;
                    break;
                case "Categories":
                    $get_all_categories = "select * from pclive_categories where status='1'";
                    $res_all_categories = $db->query($get_all_categories);
                    $data_categories = $res_all_categories->FetchAll();
                    $response['Allcategories'] = $data_categories;
                    $response = json_encode($response);
                    echo $response;
                    break;
                case "GetCountries":
                    $get_all_countries = "select * from pclive_country where status='1' order by country";
                    $res_all_countries = $db->query($get_all_countries);
                    $data_countries = $res_all_countries->FetchAll();
                    $response['Allcountries'] = $data_countries;
                    $response = json_encode($response);
                    echo $response;
                    break;
                case "GetStores_old":
                    $get_all_countries = "select id, country as store,country_flag from pclive_country where is_store_status='1' and is_store=1 and id!=248 order by country";
                    $res_all_countries = $db->query($get_all_countries);
                    $data_countries = $res_all_countries->FetchAll();
                    $response['Allstores'] = $data_countries;
                    foreach ($data_countries as $key => $Parray) {
                        //echo ">>>".$key;
                        //$response['Allstores'][$key]['id']=$Parray['id'];
                        $response['Allstores'][$key]['country_flag_url'] = "http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/public/uploads/users/" . $Parray['country_flag'];
                    }
                    $get_all_countries1 = "select id, country as store,country_flag from pclive_country where is_store_status='1' and is_store=1 and id=248 order by country";
                    $res_all_countries1 = $db->query($get_all_countries1);
                    $data_countries1 = $res_all_countries1->FetchAll();
                    $response['Allstores'] = $data_countries1;
                    foreach ($data_countries1 as $key1 => $Parray) {
                        //echo ">>>".$key;
                        //$response['Allstores'][$key]['id']=$Parray['id'];
                        $response['Allstores'][$key + 1]['id'] = $Parray['id'];
                        $response['Allstores'][$key + 1]['store'] = $Parray['store'];
                        $response['Allstores'][$key + 1]['country_flag'] = $Parray['country_flag'];
                        $response['Allstores'][$key + 1]['country_flag_url'] = "http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/public/uploads/users/" . $Parray['country_flag'];
                    }
                    $response = stripslashes(json_encode($response));
                    echo $response;
                    break;
                case "GetStores":
                    $get_all_countries = "select id, country as store,country_flag from pclive_country where is_store_status='1' and is_store=1 order by country";
                    $res_all_countries = $db->query($get_all_countries);
                    $data_countries = $res_all_countries->FetchAll();
                    $response['Allstores'] = $data_countries;
                    foreach ($data_countries as $key => $Parray) {
                        //echo ">>>".$key;
                        if ($Parray['id'] != 248) {
                            $response['Allstores'][$key]['id'] = $Parray['id'];
                            $response['Allstores'][$key]['store'] = $Parray['store'];
                            $response['Allstores'][$key]['country_flag'] = $Parray['country_flag'];
                            $response['Allstores'][$key]['country_flag_url'] = "http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/public/uploads/users/" . $Parray['country_flag'];
                        } else {
                            $response['Allstores'][$key]['id'] = '';
                            $response['Allstores'][$key]['store'] = '';
                            $response['Allstores'][$key]['country_flag'] = '';
                            $response['Allstores'][$key]['country_flag_url'] = '';
                            $tempid = $Parray['id'];
                            $tempstore = $Parray['store'];
                            $tempcountry_flag = $Parray['country_flag'];
                        }
                    }
                    $response['Allstores'][$key + 1]['id'] = $tempid;
                    $response['Allstores'][$key + 1]['store'] = $tempstore;
                    $response['Allstores'][$key + 1]['country_flag'] = $tempcountry_flag;
                    $response['Allstores'][$key + 1]['country_flag_url'] = "http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/public/uploads/users/" . $tempcountry_flag;
                    $response = stripslashes(json_encode($response));
                    echo $response;
                    break;
                case "StoreDownloads":
                    if (!empty($jsonObj->userid) && $jsonObj->userid > 0) {
                        if (!empty($jsonObj->bookid) && $jsonObj->bookid > 0 || !empty($jsonObj->StoreId) && $jsonObj->StoreId > 0) {
                            $chk_review = $db->query("select * from pclive_credit_history where userid='" . $jsonObj->userid . "' and bookid='" . $jsonObj->bookid . "'");
                            $records_review = $chk_review->FetchAll();
                            $chk_parent_id = $db->query("select parent_brand_id from pclive_products where id='" . $jsonObj->bookid . "'");
                            $records_partent = $chk_parent_id->FetchAll();
                            if ($records_partent[0]['parent_brand_id'] > 0) {
                                $chk_issue_downloaded = $db->query("select * from pclive_user_sub_details where user_id='" . $jsonObj->userid . "' and publication_id='" . $records_partent[0]['parent_brand_id'] . "'");
                                $records_issue_downloaded = $chk_issue_downloaded->FetchAll();
                                /*if($records_issue_downloaded[0]['issue_type']>0)
                                		{
                                			if($records_issue_downloaded[0]['issue_ids']!='')
                                			{
                                				$issids = explode(",",$records_issue_downloaded[0]['issue_ids']);
                                				if(!(@in_array($jsonObj->bookid,$issids)))
                                				{
                                					$remaining_downloads = $records_issue_downloaded[0]['number_of_issues']-$records_issue_downloaded[0]['number_of_downloaded'];
                                					$issue_ids = $records_issue_downloaded[0]['issue_ids'].",".$jsonObj->bookid;
                                					//$db->query("update pclive_user_sub_details set number_of_downloaded=number_of_downloaded+1,issue_ids='".$issue_ids."',remaining_downloads='".$remaining_downloads."' where user_id='".$jsonObj->userid."' and publication_id='".$records_partent[0]['parent_brand_id']."'");
                                					
                                				}
                                			}
                                			else
                                			{
                                				$remaining_downloads = $records_issue_downloaded[0]['number_of_issues']-1;
                                				$issue_ids = $jsonObj->bookid;
                                				//$db->query("update pclive_user_sub_details set number_of_downloaded=number_of_downloaded+1,issue_ids='".$issue_ids."',remaining_downloads='".$remaining_downloads."' where user_id='".$jsonObj->userid."' and publication_id='".$records_partent[0]['parent_brand_id']."'");
                                				
                                			}
                                		}
                                		else
                                		{
                                			//$db->query("update pclive_user_sub_details set number_of_downloaded=number_of_downloaded+1 where user_id='".$jsonObj->userid."' and publication_id='".$records_partent[0]['parent_brand_id']."'");
                                		}*/
                            } else {
                                //$remaining_downloads = $records_issue_downloaded[0]['number_of_issues']-1;
                                //	$issue_ids = $jsonObj->bookid;
                                //$db->query("update pclive_user_sub_details set number_of_downloaded=number_of_downloaded+1 where user_id='".$jsonObj->userid."' and publication_id='".$records_partent[0]['parent_brand_id']."'");
                            }
                            /*			
                            if(count($records_review)==0)
                            {
                            	$get_prname = $db->query("select * from pclive_products where id='".$jsonObj->bookid."'");
                            	$records_prname = $get_prname->FetchAll();	
                            	
                            	
                            	//$sql="insert into pclive_credit_history set userid='".$jsonObj->userid."',bookid='".$jsonObj->bookid."',price='".$jsonObj->price."',book_name='".$records_prname[0]['title']."', store_id='".$jsonObj->StoreId."', add_date=now()";
                            
                            	//$result = $db->query($sql);
                            						
                            	//$sql1="update pclive_products set best_seller=best_seller+1 where id=".$jsonObj->bookid."";
                            
                            	//$result1 = $db->query($sql1);
                             							 
                            	$response = '{"BookResponse":{
                            	  "error":"false","Message":"Successfully purchased."
                            	  }}';
                            	echo $response;
                            }
                            else
                            {
                            	
                            	$sql1="update pclive_products set no_download=no_download+1 where id=".$jsonObj->bookid."";
                            
                            	$result1 = $db->query($sql1);
                            	
                            
                            	$response = '{"BookResponse":{"Message":"You have already purchased.", "error":"true"}}';
                            	echo $response; 
                            }
                            */
                            $sql1 = "update pclive_products set no_download=no_download+1 where id=" . $jsonObj->bookid . "";
                            $result1 = $db->query($sql1);
                        } else {
                            $response = '{"BookResponse":{"Message":"Bookid or store does not exist.", "error":"true"}}';
                            echo $response;
                        }
                    } else {
                        $response = '{"BookResponse":{"Message":"Userid does not exist.", "error":"true"}}';
                        echo $response;
                    }
                    break;
                case "ReviewRating":
                    if (!empty($jsonObj->userid) && $jsonObj->userid > 0) {
                        if (!empty($jsonObj->bookid) && $jsonObj->bookid > 0) {
                            $chk_review = $db->query("select * from pclive_review where userid='" . $jsonObj->userid . "' and productid='" . $jsonObj->bookid . "'");
                            $records_review = $chk_review->FetchAll();
                            if (count($records_review) == 0) {
                                $sql = "insert into pclive_review set userid='" . $jsonObj->userid . "',rating='" . $jsonObj->rating . "',comments='" . $jsonObj->comments . "',productid='" . $jsonObj->bookid . "',add_time=now()";
                                $result = $db->query($sql);
                                $response = '[{"Error":{"Message":"You have rated succesfully."}}]';
                                echo $response;
                            } else {
                                $sql = "update pclive_review set rating='" . $jsonObj->rating . "', comments='" . $jsonObj->comments . "',add_time=now() where  userid='" . $jsonObj->userid . "' and productid='" . $jsonObj->bookid . "' ";
                                $result = $db->query($sql);
                                $response = '[{"Error":{"Message":"You have rated succesfully."}}]';
                                //$response = '[{"Error":{"Message":"You have already given your review for this book."}}]';
                                echo $response;
                            }
                        } else {
                            $response = '[{"Error":{"Message":"Book does not exists."}}]';
                            echo $response;
                        }
                    } else {
                        $response = '[{"Error":{"Message":"User Id does not exist"}}]';
                        echo $response;
                    }
                    break;
                case "ReviewRatingIphone":
                    if (!empty($jsonObj->userid) && $jsonObj->userid > 0) {
                        //echo ">>>>>".$jsonObj->comments;
                        //exit();
                        if (!empty($jsonObj->bookId) && $jsonObj->bookId > 0) {
                            $chk_review = $db->query("select * from pclive_review where userid='" . $jsonObj->userid . "' and productid='" . $jsonObj->bookId . "'");
                            $records_review = $chk_review->FetchAll();
                            if (count($records_review) == 0) {
                                $sql = "insert into pclive_review set userid='" . $jsonObj->userid . "',rating='" . urldecode($jsonObj->rating) . "',comments='" . str_replace("%0A", "\n", $jsonObj->comments) . "',productid='" . $jsonObj->bookId . "',add_time=now()";
                                $result = $db->query($sql);
                                $response = '{"Message":"You have rated succesfully.", "error":"false" }';
                                echo $response;
                            } else {
                                $sql = "update pclive_review set rating='" . $jsonObj->rating . "', comments='" . urldecode($jsonObj->comments) . "',add_time=now() where  userid='" . $jsonObj->userid . "' and productid='" . $jsonObj->bookId . "' ";
                                $result = $db->query($sql);
                                $response = '{"Message":"You have rated succesfully.", "error":"false" }';
                                //$response = '[{"Error":{"Message":"You have already given your review for this book."}}]';
                                echo $response;
                            }
                        } else {
                            $response = '{"Message":"Book does not exists.", "error":"true" }';
                            echo $response;
                        }
                    } else {
                        $response = '{"Message":"User Id does not exist.", "error":"true" }';
                        echo $response;
                    }
                    break;
                case "UserUpdate":
                    if (!empty($jsonObj->id) && $jsonObj->id > 0) {
                        $Errorresponse = "";
                        if (!isset($jsonObj->FirstName) || trim($jsonObj->FirstName) == "" || !isset($jsonObj->LastName) || trim($jsonObj->LastName) == "" || !isset($jsonObj->Country) || trim($jsonObj->Country) == "") {
                            $Errorresponse = '[{"ParameterMissing":{';
                            if (!isset($jsonObj->FirstName) || trim($jsonObj->FirstName) == "") {
                                //$Errorresponse.='"FirstName":"Please Enter First Name",';
                                $Errorresponse .= '{"Message":"Unsuccess", "Error":"Please Enter First Name" }';
                            }
                            if (!isset($jsonObj->LastName) || trim($jsonObj->LastName) == "") {
                                //$Errorresponse.='"LastName":"Please Enter Last Name",';
                                $Errorresponse .= '{"Message":"Unsuccess", "Error":"Please Enter Last Name" }';
                            }
                            if (!isset($jsonObj->Country) || trim($jsonObj->Country) == "") {
                                //$Errorresponse.='"Country":"Please Select A Country"';
                                $Errorresponse .= '{"Message":"Unsuccess", "Error":"Please Select A Country" }';
                            }
                            $Errorresponse .= '}}]';
                        }
                        if (!empty($Errorresponse)) {
                            echo $Errorresponse;
                        } else {
                            //if($jsonObj->Acounttype=="")
                            //$jsonObj->Acounttype=2;
                            $sql = "UPDATE pclive_companies SET first_name='{$jsonObj->FirstName}', last_name='{$jsonObj->LastName}', country='{$jsonObj->Country}'  where id='{$jsonObj->id}'";
                            $result = $db->query($sql);
                            if ($result) {
                                $response .= '{"Message":"Success", "UpdationResponse":"Record Updated Successfully" }';
                                echo $response;
                            } else {
                                $response .= '{"Message":"Unsuccess", "UpdationResponse":"Record cannot be modified" }';
                                echo $response;
                            }
                        }
                    } else {
                        $response .= '{"Message":"Unsuccess", "Error":"User Id does not exist" }';
                        echo $response;
                    }
                    break;
                    /*
                    
                    case "UserUpdateIphone":
                     
                    	if(!empty($jsonObj->id) && $jsonObj->id>0) 
                    	{	
                    		$Errorresponse="";
                    		if(!(isset($jsonObj->FirstName)) || trim($jsonObj->FirstName)=="" || !(isset($jsonObj->LastName)) || trim($jsonObj->LastName)=="" || !(isset($jsonObj->Country)) || trim($jsonObj->Country)=="")
                    		{
                    			$Errorresponse='[{"ParameterMissing":{';
                    			if(!(isset($jsonObj->FirstName)) || trim($jsonObj->FirstName)=="") 
                    			{
                    				//$Errorresponse.='"FirstName":"Please Enter First Name",';
                    				
                    				$Errorresponse.='{"Message":"Unsuccess", "Error":"Please Enter First Name" }';
                    				
                    			}
                    			
                    			if(!(isset($jsonObj->LastName)) || trim($jsonObj->LastName)=="") 
                    			{
                    				//$Errorresponse.='"LastName":"Please Enter Last Name",';
                    				$Errorresponse.='{"Message":"Unsuccess", "Error":"Please Enter Last Name" }';
                    			}
                    			
                    			if(!(isset($jsonObj->Country)) || trim($jsonObj->Country)=="") 
                    			{
                    				//$Errorresponse.='"Country":"Please Select A Country"';
                    				$Errorresponse.='{"Message":"Unsuccess", "Error":"Please Select A Country" }';
                    			}
                    			
                    			$Errorresponse.='}}]';
                    		}	
                    
                    		if(!empty($Errorresponse)) 
                    		{
                    			echo $Errorresponse;
                    		} 
                    		else 
                    		{
                    	    	
                    			
                    			$countrrep=str_replace(" ", "",$jsonObj->Country);
                    			//$sqlcountry="select id  from pclive_country where country='".$jsonObj->Country."'";
                    			$sqlcountry="select id FROM pclive_country
                    WHERE replace( country, ' ', '' ) = '".$countrrep."' ";
                    			$resultcountry = $db->query($sqlcountry);
                    			$data_country =  $resultcountry->FetchAll();
                    				
                    			
                    			//$sqlcountry="select id  from pclive_country where country='".$jsonObj->Country."'";
                    			$userinfo="select * FROM pclive_companies where id='$jsonObj->id'";
                    			$resultuserinfo = $db->query($userinfo);
                    			$data_userinfo =  $resultuserinfo->FetchAll();
                    			//if($jsonObj->Acounttype=="")
                    			//$jsonObj->Acounttype=2;
                    	    	
                    			
                    			$sql = "UPDATE pclive_companies SET first_name='$jsonObj->FirstName', last_name='$jsonObj->LastName', country='".$data_country[0]['id']."' where id='$jsonObj->id'";	
                    		 
                    			
                    			$result = $db->query($sql);
                    										
                    			if($result)
                    			{
                    				  $response.='{"Message":"Success", "UpdationResponse":"Record Updated Successfully" ,"UpdatedCountry":"'.$data_country[0]['id'].'","Userid":"'.$data_userinfo[0]['id'].'","Username":"******","Userpassword":"******"}';
                    				   
                    				  echo $response;
                    			}
                    			else
                    			{
                    				 $response.='{"Message":"Unsuccess", "UpdationResponse":"Record cannot be modified" }';
                    				 
                    				 echo $response;
                    			}
                    		}
                    	}
                    	else 
                    	{
                    	 
                    	 $response.='{"Message":"Unsuccess", "Error":"User Id does not exist" }';
                    	 echo $response;  
                    	}
                    
                    break;
                    */
                /*
                
                case "UserUpdateIphone":
                 
                	if(!empty($jsonObj->id) && $jsonObj->id>0) 
                	{	
                		$Errorresponse="";
                		if(!(isset($jsonObj->FirstName)) || trim($jsonObj->FirstName)=="" || !(isset($jsonObj->LastName)) || trim($jsonObj->LastName)=="" || !(isset($jsonObj->Country)) || trim($jsonObj->Country)=="")
                		{
                			$Errorresponse='[{"ParameterMissing":{';
                			if(!(isset($jsonObj->FirstName)) || trim($jsonObj->FirstName)=="") 
                			{
                				//$Errorresponse.='"FirstName":"Please Enter First Name",';
                				
                				$Errorresponse.='{"Message":"Unsuccess", "Error":"Please Enter First Name" }';
                				
                			}
                			
                			if(!(isset($jsonObj->LastName)) || trim($jsonObj->LastName)=="") 
                			{
                				//$Errorresponse.='"LastName":"Please Enter Last Name",';
                				$Errorresponse.='{"Message":"Unsuccess", "Error":"Please Enter Last Name" }';
                			}
                			
                			if(!(isset($jsonObj->Country)) || trim($jsonObj->Country)=="") 
                			{
                				//$Errorresponse.='"Country":"Please Select A Country"';
                				$Errorresponse.='{"Message":"Unsuccess", "Error":"Please Select A Country" }';
                			}
                			
                			$Errorresponse.='}}]';
                		}	
                
                		if(!empty($Errorresponse)) 
                		{
                			echo $Errorresponse;
                		} 
                		else 
                		{
                	    	
                			
                			$countrrep=str_replace(" ", "",$jsonObj->Country);
                			//$sqlcountry="select id  from pclive_country where country='".$jsonObj->Country."'";
                			$sqlcountry="select id FROM pclive_country
                WHERE replace( country, ' ', '' ) = '".$countrrep."' ";
                			$resultcountry = $db->query($sqlcountry);
                			$data_country =  $resultcountry->FetchAll();
                				
                			
                			//$sqlcountry="select id  from pclive_country where country='".$jsonObj->Country."'";
                			$userinfo="select * FROM pclive_companies where id='$jsonObj->id'";
                			$resultuserinfo = $db->query($userinfo);
                			$data_userinfo =  $resultuserinfo->FetchAll();
                			//if($jsonObj->Acounttype=="")
                			//$jsonObj->Acounttype=2;
                	    	
                			
                			$sql = "UPDATE pclive_companies SET first_name='$jsonObj->FirstName', last_name='$jsonObj->LastName', country='".$data_country[0]['id']."' where id='$jsonObj->id'";	
                		 
                			
                			$result = $db->query($sql);
                										
                			if($result)
                			{
                				  $response.='{"Message":"Success", "UpdationResponse":"Record Updated Successfully" ,"UpdatedCountry":"'.$data_country[0]['id'].'","Userid":"'.$data_userinfo[0]['id'].'","Username":"******","Userpassword":"******"}';
                				   
                				  echo $response;
                			}
                			else
                			{
                				 $response.='{"Message":"Unsuccess", "UpdationResponse":"Record cannot be modified" }';
                				 
                				 echo $response;
                			}
                		}
                	}
                	else 
                	{
                	 
                	 $response.='{"Message":"Unsuccess", "Error":"User Id does not exist" }';
                	 echo $response;  
                	}
                
                break;
                */
                case "UserUpdateIphone":
                    if (!empty($jsonObj->id) && $jsonObj->id > 0) {
                        $Errorresponse = "";
                        if (!isset($jsonObj->FirstName) || trim($jsonObj->FirstName) == "" || !isset($jsonObj->LastName) || trim($jsonObj->LastName) == "" || !isset($jsonObj->countryid) || trim($jsonObj->countryid) == "") {
                            $Errorresponse = '[{"ParameterMissing":{';
                            if (!isset($jsonObj->FirstName) || trim($jsonObj->FirstName) == "") {
                                //$Errorresponse.='"FirstName":"Please Enter First Name",';
                                $Errorresponse .= '{"Message":"Please Enter First Name.", "error":"true" }';
                            }
                            if (!isset($jsonObj->LastName) || trim($jsonObj->LastName) == "") {
                                //$Errorresponse.='"LastName":"Please Enter Last Name",';
                                $Errorresponse .= '{"Message":"Please Enter Last Name.", "error":"true" }';
                            }
                            if (!isset($jsonObj->countryid) || trim($jsonObj->countryid) == "") {
                                //$Errorresponse.='"Country":"Please Select A Country"';
                                $Errorresponse .= '{"Message":"Please Select A Country.", "error":"true" }';
                            }
                            $Errorresponse .= '}}]';
                        }
                        if (!empty($Errorresponse)) {
                            echo $Errorresponse;
                        } else {
                            //if($jsonObj->Acounttype=="")
                            //$jsonObj->Acounttype=2;
                            $sql = "UPDATE pclive_companies SET first_name='{$jsonObj->FirstName}', last_name='{$jsonObj->LastName}', country='{$jsonObj->countryid}'  where id='{$jsonObj->id}'";
                            $result = $db->query($sql);
                            if ($result) {
                                //$response.='{"Message":"Record Updated Successfully.", "error":"false" }';
                                $sql1 = "SELECT * FROM pclive_country where id='" . $jsonObj->countryid . "' ";
                                $result1 = $db->query($sql1);
                                $record1 = $result1->FetchAll();
                                //$sql = 'SELECT * FROM pclive_companies where id="'.$jsonObj->id.'" AND parent_id="0" AND account_type<>"3"';
                                $sql = 'SELECT * FROM pclive_companies where id="' . $jsonObj->id . '" AND status=1 and account_type!=1';
                                $result = $db->query($sql);
                                $record = $result->FetchAll();
                                $response = '{
							"Message":"Profile updated successfully.",
							"userid":"' . $jsonObj->id . '",
							"countryid":"' . $jsonObj->countryid . '",
							"Country" : "' . $record1[0]['country'] . '", 
							"FirstName" : "' . $jsonObj->FirstName . '",
							"LastName"	: "' . $jsonObj->FirstName . '","Username":"******","Userpassword":"******","error":"false"
							}';
                                echo $response;
                            } else {
                                $response .= '{"Message":"Request failed. Please try again.", "error":"true" }';
                                echo $response;
                            }
                        }
                    } else {
                        $response .= '{"Message":"Request failed. Please try again.", "error":"true" }';
                        echo $response;
                    }
                    break;
                case "ChangePwd":
                    if (!empty($jsonObj->id) && $jsonObj->id > 0) {
                        $Errorresponse = "";
                        if (!isset($jsonObj->NewPassword) || trim($jsonObj->NewPassword) == "" || !isset($jsonObj->NewConfPassword) || trim($jsonObj->NewConfPassword) == "") {
                            //$Errorresponse='[{"ParameterMissing":{';
                            if (!isset($jsonObj->NewPassword) || trim($jsonObj->NewPassword) == "") {
                                $Errorresponse .= '{"Message":"Unsuccess", "Error":"Please Enter Your New Password" }';
                            }
                            if (!isset($jsonObj->NewConfPassword) || trim($jsonObj->NewConfPassword) == "") {
                                $Errorresponse .= '{"Message":"Unsuccess", "Error":"Please Enter New Confirm Password" }';
                            }
                            if ($jsonObj->NewPassword != $jsonObj->NewConfPassword) {
                                $Errorresponse .= '{"Message":"Unsuccess", "Error":"Confirm Password does not Matched with New Password" }';
                            }
                            //$Errorresponse.='}}]';
                        }
                        /*
                        if($jsonObj->OldPassword!="") 
                        {
                        	$sql_oldpwd = "select * from pclive_companies where id='".$jsonObj->id."'";
                        	 
                        	
                        	$res_oldpwd = $db->query($sql_oldpwd);
                        	$data_oldpwd =  $res_oldpwd->FetchAll();
                         					
                        	 
                        	
                        	if(strcmp($data_oldpwd[0]['user_password'],$jsonObj->OldPassword)!=0)
                        	{
                        		//$Errorresponse.='"CurrentPassword":"******",';
                        	  
                        		$Errorresponse.='{"Message":"Unsuccess", "Error":"Wrong Current Password" }';
                        		
                        	}
                        	 
                        }
                        */
                        if (!empty($Errorresponse)) {
                            echo $Errorresponse;
                        } else {
                            $sql = "UPDATE pclive_companies SET user_password='******' where id='" . $jsonObj->id . "'";
                            $result = $db->query($sql);
                            $sql_oldpwd = "select * from pclive_companies where id='" . $jsonObj->id . "'";
                            $res_oldpwd = $db->query($sql_oldpwd);
                            $data_oldpwd = $res_oldpwd->FetchAll();
                            if ($result) {
                                $response .= '{"Message":"Success", "UpdationResponse":"Password changed successfully"  ,"UpdatedCountry":"' . $data_oldpwd[0]['country'] . '","Userid":"' . $data_oldpwd[0]['id'] . '","Username":"******","Userpassword":"******"}';
                                echo $response;
                            } else {
                                $response .= '{"Message":"Unsuccess", "Error":"Password cannot be modified" }';
                                echo $response;
                            }
                        }
                    } else {
                        $response = '{"Message":{"Unsuccess":"User Id does not exist"}}';
                        echo $response;
                    }
                    break;
                case "ChangePwdIphone":
                    if (!empty($jsonObj->id) && $jsonObj->id > 0) {
                        $Errorresponse = "";
                        if (!isset($jsonObj->NewPassword) || trim($jsonObj->NewPassword) == "" || !isset($jsonObj->NewConfPassword) || trim($jsonObj->NewConfPassword) == "") {
                            //$Errorresponse='[{"ParameterMissing":{';
                            if (!isset($jsonObj->NewPassword) || trim($jsonObj->NewPassword) == "") {
                                $Errorresponse .= '{"Message":"Request failed. Please try again.", "error":"true" }';
                            }
                            if (!isset($jsonObj->NewConfPassword) || trim($jsonObj->NewConfPassword) == "") {
                                $Errorresponse .= '{"Message":"Request failed. Please try again.",  "error":"true"  }';
                            }
                            if ($jsonObj->NewPassword != $jsonObj->NewConfPassword) {
                                $Errorresponse .= '{"Message":"Request failed. Please try again.", "error":"true"   }';
                            }
                            //$Errorresponse.='}}]';
                        }
                        /*
                        if($jsonObj->OldPassword!="") 
                        {
                        	$sql_oldpwd = "select * from pclive_companies where id='".$jsonObj->id."'";
                        	 
                        	
                        	$res_oldpwd = $db->query($sql_oldpwd);
                        	$data_oldpwd =  $res_oldpwd->FetchAll();
                         					
                        	 
                        	
                        	if(strcmp($data_oldpwd[0]['user_password'],$jsonObj->OldPassword)!=0)
                        	{
                        		//$Errorresponse.='"CurrentPassword":"******",';
                        	  
                        		$Errorresponse.='{"Message":"Unsuccess", "Error":"Wrong Current Password" }';
                        		
                        	}
                        	 
                        }
                        */
                        if (!empty($Errorresponse)) {
                            echo $Errorresponse;
                        } else {
                            $sql = "UPDATE pclive_companies SET user_password='******' where id='" . $jsonObj->id . "'";
                            $result = $db->query($sql);
                            $sql_oldpwd = "select * from pclive_companies where id='" . $jsonObj->id . "'";
                            $res_oldpwd = $db->query($sql_oldpwd);
                            $data_oldpwd = $res_oldpwd->FetchAll();
                            if ($result) {
                                $sql1 = "SELECT * FROM pclive_country where id='" . $data_oldpwd[0]['country'] . "' ";
                                $result1 = $db->query($sql1);
                                $record1 = $result1->FetchAll();
                                $response .= '{"Message":"Password changed successfully.", "error":"false", "FirstName":"' . $data_oldpwd[0]['first_name'] . '","LastName":"' . $data_oldpwd[0]['last_name'] . '","countryid":"' . $data_oldpwd[0]['country'] . '","Country":"' . $record1[0]['country'] . '","userid":"' . $data_oldpwd[0]['id'] . '","Username":"******","Userpassword":"******"}';
                                echo $response;
                            } else {
                                $response .= '{"Message":"Request failed. Please try again.", "error":"true"  }';
                                echo $response;
                            }
                        }
                    } else {
                        $response = '{"Message":"Request failed. Please try again.", "error":"true"  }';
                        echo $response;
                    }
                    break;
                case "Downloads":
                    if (!empty($jsonObj->id) && $jsonObj->id > 0) {
                        $sql = "SELECT s.id,s.product_id,s.store_id,s.total_downloads,s.downloaded_file_size,s.status,s.added_date,s.updated_date, p.product_type,p.publisher_id,p.author_id,p.title,p.file_name,p.file_size,p.parent_brand_id,p.edition_id,p.description,p.isbn_number,p.publisher,p.total_pages,p.cat_id,p.file_name,p.file_size, pp.country_id,pp.language_id,pp.price FROM pclive_company_subscriptions as s INNER JOIN pclive_products as p ON s.product_id=p.id INNER JOIN pclive_product_prices as pp ON s.product_id=pp.product_id WHERE s.company_id<>0 AND s.company_id='{$jsonObj->id}' AND s.store_id=pp.country_id ORDER BY s.id ASC";
                        $result = $db->query($sql);
                        $records = $result->FetchAll();
                        if (count($records) > 0) {
                            $response = array();
                            foreach ($records as $key => $Parray) {
                                $book_thumb_qry = 'SELECT * from  pclive_product_images where product_id="' . $Parray['product_id'] . '" LIMIT 1';
                                $boothumb_result = $db->query($book_thumb_qry);
                                $book_thumb_record = $boothumb_result->FetchAll();
                                $book_thumb_info = $book_thumb_record[0];
                                $publisher_info_qry = 'SELECT first_name,last_name,emailid,publisher,country,phone from  pclive_users where id="' . $Parray['publisher_id'] . '"';
                                $publisher_info_result = $db->query($publisher_info_qry);
                                $publisher_info_record = $publisher_info_result->FetchAll();
                                $publisher_info = $publisher_info_record[0];
                                if (!empty($Parray['parent_brand_id'])) {
                                    $parent_brand_id_qry = 'SELECT title from pclive_products where id="' . $Parray['parent_brand_id'] . '"';
                                    $brand_info_result = $db->query($parent_brand_id_qry);
                                    $brand_info_record = $brand_info_result->FetchAll();
                                    $brand_info = $brand_info_record[0];
                                    $parent_brand_title_qry = 'SELECT brand from pclive_brands where id="' . $brand_info['title'] . '"';
                                    $parent_brand_info_result = $db->query($parent_brand_title_qry);
                                    $parent_brand_info_record = $parent_brand_info_result->FetchAll();
                                    $parent_brand_info = $parent_brand_info_record[0];
                                }
                                $store_info_qry = 'SELECT country from pclive_country where id="' . $Parray['store_id'] . '"';
                                $store_info_result = $db->query($store_info_qry);
                                $store_info_record = $store_info_result->FetchAll();
                                $store_info = $store_info_record[0];
                                $genre_info_qry = 'SELECT genre from  pclive_genres where id="' . $Parray['product_type'] . '"';
                                $genre_info_result = $db->query($genre_info_qry);
                                $genre_info_record = $genre_info_result->FetchAll();
                                $genre_info = $genre_info_record[0];
                                $cat_info_qry = 'SELECT category_name from   pclive_categories where id="' . $Parray['cat_id'] . '"';
                                $cat_info_result = $db->query($cat_info_qry);
                                $cat_info_record = $cat_info_result->FetchAll();
                                $cat_info = $cat_info_record[0];
                                $lan_info_qry = 'SELECT language_name from pclive_product_language where id="' . $Parray['language_id'] . '"';
                                $lan_info_result = $db->query($lan_info_qry);
                                $lan_info_record = $lan_info_result->FetchAll();
                                $lan_info = $lan_info_record[0];
                                if (strtolower(trim($cat_info['category_name'])) == strtolower(trim('eBook')) || strtolower(trim($cat_info['category_name'])) == strtolower(trim('eBooks'))) {
                                    $author_info_qry = 'SELECT first_name,last_name,emailid,phone from  pclive_users where id="' . $Parray['author_id'] . '"';
                                    $author_info_result = $db->query($author_info_qry);
                                    $author_info_record = $author_info_result->FetchAll();
                                    $author_info = $author_info_record[0];
                                } else {
                                    $edition_info_qry = 'SELECT edition from pclive_editions where id="' . $Parray['edition_id'] . '"';
                                    $edition_info_result = $db->query($edition_info_qry);
                                    $edition_info_record = $edition_info_result->FetchAll();
                                    $edition_info = $edition_info_record[0];
                                }
                                $response['Downloads'][$key]['ProductId'] = $Parray['product_id'];
                                if (!empty($parent_brand_info)) {
                                    $title = $Parray['title'] . "(" . ucfirst($parent_brand_info['brand']) . ")";
                                } else {
                                    $title = $Parray['title'];
                                }
                                $response['Downloads'][$key]['Title'] = $title;
                                $response['Downloads'][$key]['FileName'] = $Parray['file_name'];
                                $file_size_array = explode(" ", $Parray['file_size']);
                                if (strtolower(trim($file_size_array[1])) == strtolower(trim('Mb'))) {
                                    $file_size_array[0] = round($file_size_array[0], 2);
                                } elseif (strtolower(trim($file_size_array[1])) == strtolower(trim('Kb'))) {
                                    $file_size_array[0] = round($file_size_array[0] / 1024, 2);
                                } elseif (strtolower(trim($file_size_array[1])) == strtolower(trim('Bytes'))) {
                                    $file_size_array[0] = round($file_size_array[0] / (1024 * 1024), 2);
                                } else {
                                    $file_size_array[0] = round($file_size_array[0], 2);
                                }
                                $response['Downloads'][$key]['FileSize'] = $file_size_array[0];
                                $response['Downloads'][$key]['DownloadedFileSize'] = $Parray['downloaded_file_size'];
                                //$thumbnail='<img src="'.$this->view->serverUrl().$this->view->baseUrl()."/".USER_UPLOAD_DIR.$book_thumb_info['image_name_thumb'].'" height="208" width="166">';
                                $thumbnail_path = $this->view->serverUrl() . $this->view->baseUrl() . "/" . USER_UPLOAD_DIR . $book_thumb_info['image_name_thumb'];
                                $response['Downloads'][$key]['ProductThumbnail'] = $thumbnail_path;
                                //$response['Downloads'][$key]['ProductThumbnail']=$thumbnail;
                                $response['Downloads'][$key]['StoreName'] = $store_info['country'];
                                //$response['Downloads'][$key]['StoreId']=$Parray['store_id'];
                                $response['Downloads'][$key]['Category'] = $cat_info['category_name'];
                                if (isset($edition_info) && !empty($edition_info)) {
                                    $response['Downloads'][$key]['Edition'] = $edition_info['edition'];
                                }
                                $response['Downloads'][$key]['Genre'] = $genre_info['genre'];
                                $response['Downloads'][$key]['Language'] = $lan_info['language_name'];
                                $response['Downloads'][$key]['Price'] = $Parray['price'];
                                $response['Downloads'][$key]['TotalDownloads'] = $Parray['total_downloads'];
                                $response['Downloads'][$key]['DownloadStatus'] = $Parray['status'];
                                $response['Downloads'][$key]['PublisherInfo'] = $publisher_info;
                                if (isset($author_info) && !empty($author_info)) {
                                    $response['Downloads'][$key]['AuthorInfo'] = $author_info;
                                }
                                $response['Downloads'][$key]['Edition'] = $edition_info['edition'];
                                $response['Downloads'][$key]['AddedDate'] = $Parray['added_date'];
                                $response['Downloads'][$key]['UpdatedDate'] = $Parray['updated_date'];
                            }
                            /*echo"<pre>";
                              print_r($response);
                              */
                            $response = json_encode($response);
                            echo stripslashes($response);
                        } else {
                            $response = '[{"Error":{"Message":"No Records Found."}}]';
                            echo $response;
                        }
                    } else {
                        $response = '[{"Error":{"Message":"User Id does not exist"}}]';
                        echo $response;
                    }
                    break;
                case "ForgotPassword":
                    $xml = simplexml_load_string($formData['xmldata']);
                    if ($xml === false) {
                        $response = '<?xml version="1.0" encoding="utf-8"?>
									<Error>
									<Message>Error : Invalid XML Format.</Message>
								   </Error>';
                        echo $response;
                    } else {
                        $sql = 'SELECT * FROM pclive_users where emailid="' . $xml->Email . '"';
                        $result = $db->query($sql);
                        $record = $result->FetchAll();
                        if (count($record) > 0) {
                            $mailhost = SMTP_SERVER;
                            $mailconfig = array('ssl' => SMTP_SSL, 'port' => SMTP_PORT, 'auth' => SMTP_AUTH, 'username' => SMTP_USERNAME, 'password' => SMTP_PASSWORD);
                            $transport = new Zend_Mail_Transport_Smtp($mailhost, $mailconfig);
                            Zend_Mail::setDefaultTransport($transport);
                            $message = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
							<html xmlns="http://www.w3.org/1999/xhtml">
							<head>
							<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
							<title>Electronic Vendor Ltd</title>
							<style type="text/css">
							body{
							margin:0;
							padding:0px;
							}
							#container{
							width:700px;
							margin:0 auto;
							}
							#header{
							width:700px;
							float:left;
							padding:40px 0 10px 0;
							font-family:Arial, Helvetica, sans-serif;
							color:#3A3B3F;
							text-align:center;
							font-size:11px;
							
							}
							#header a{
							color:#3A3B3F;
							font-weight:bold;
							text-decoration:none;
							}
							#header a:hover{
							color:#40BBE3;
							}
							#logopart
							{
							border:0px solid red;
							width:698px;
							height:140px;
							background-color:#1B75BB;
							margin-left:0px;
							}
							#content{
							width:698px;
							float:left;
							padding:0px 0px 10px 0px;
							font-family:Arial, Helvetica, sans-serif;
							color:#3A3B3F;
							border:1px solid #D6D6D6;
							font-size:12px;
							}
							#content p{
							margin:0px 20px;
							padding:0px 0 20px 0;
							font-family:Arial, Helvetica, sans-serif;
							font-size:12px;
							color:#3A3B3F;
							}
							#content p.logo{
							margin:0px;
							padding:15px 0 0 20px;
							height:77px
							}
							#content p.title{
							margin:0px;
							font-size:20px;
							font-family:Arial, Helvetica, sans-serif;
							border-bottom:3px solid #D6D6D6;
							padding:0px 0 13px 0;
							margin:25px 20px 14px 20px;
							color:#3A3B3F;
							}
							#content p a{
							color:#40BBE3;
							text-decoration:none;
							}
							#content p a:hover{
							color:#3A3B3F;
							text-decoration:underline;
							}
							#content h2{
							margin:0px;
							padding:0 0 14px 0;
							font-size:14px;
							font-family:Arial, Helvetica, sans-serif;
							font-weight:bold;
							}
							#footer{
							width:700px;
							float:left;
							}
							#footer p{
							margin:0 0 0 0;
							padding:0 0 0 0;
							font-family:Arial, Helvetica, sans-serif;
							font-size:11px;
							color:#78797E;
							}
							#footer p.disclamer{
							margin: 0 0 0 0;
							padding:16px 6px 10px 6px;
							text-align: justify;
							border-bottom:1px solid #3A3B3F;
							color:#78797E;
							}
							#footer p.notice{
							margin: 0 0 15px 0;
							padding:16px 6px 10px 6px;
							text-align: justify;
							color:#78797E;
							}
							</style>
							</head>
							
							<body>
							
							<div id="container">
							
							
							<div id="header"></div>
							
							<div id="content">
							
							<div id="logopart">
							<p class="logo"><a href="' . SVN_URL . '" target="_blank">
							Online & Offline
							</a></p>
							</div>
							
							<p class="title">Forgot Password Email</p>
							<p>Your login details given below :</p>
							<p>Username:&nbsp;' . $record[0]['username'] . '</p>
							<p>Password:&nbsp;' . $record[0]['password'] . '</p>
							
							<BR />
							<br>
							<p>&nbsp;</p>
							
							</div>
							<div id="footer">&nbsp;</div>
							</div>
							</body>
							</html>';
                            $mail = new Zend_Mail();
                            $mail->addTo($xml->Email);
                            $mail->setSubject("Forgot Password Email");
                            $mail->setBodyHtml($message);
                            $mail->setFrom(SETFROM, SETNAME);
                            if ($mail->send()) {
                                $response = '<?xml version="1.0" encoding="utf-8"?>
								<Success>
								<Message>Message : Password send successfully!. Please check your mail.</Message>
								</Success>';
                                echo $response;
                            } else {
                                $response = '<?xml version="1.0" encoding="utf-8"?>
								<Error>
								<Message>Error : Mail Could not be sent. Try again later!.</Message>
								</Error>';
                                echo $response;
                            }
                        } else {
                            $response = '<?xml version="1.0" encoding="utf-8"?>
								<Error>
								<Message>Error : No record found.</Message>
								</Error>';
                            echo $response;
                        }
                    }
                    // Validate XML
                    break;
                case "UserForgotPassword":
                    if (isset($jsonObj->EmailId) && !empty($jsonObj->EmailId)) {
                        $sql = 'SELECT * FROM pclive_companies where user_email="' . $jsonObj->EmailId . '"';
                        $result = $db->query($sql);
                        $record = $result->FetchAll();
                        $url = 'http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/user/auth/cngpwd/id/';
                        if (count($record) > 0) {
                            $mailhost = SMTP_SERVER;
                            $mailconfig = array('ssl' => SMTP_SSL, 'port' => SMTP_PORT, 'auth' => SMTP_AUTH, 'username' => SMTP_USERNAME, 'password' => SMTP_PASSWORD);
                            $transport = new Zend_Mail_Transport_Smtp($mailhost, $mailconfig);
                            Zend_Mail::setDefaultTransport($transport);
                            $message = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
							<html xmlns="http://www.w3.org/1999/xhtml">
							<head>
							<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
							<title>Electronic Vendor Ltd</title>
							
							</head>
							<body>
							
							<p>To set new password, click on the below link:<br></p>
							
							<p>URL:&nbsp;<a href=' . $url . base64_encode($record[0]['id']) . '/' . mt_rand() . '>' . $url . base64_encode($record[0]['id']) . '/' . mt_rand() . '</a></p>
							<BR />
							<br>
							<p>&nbsp;</p>
							</body>
							</html>';
                            $mail = new Zend_Mail();
                            $mail->addTo($jsonObj->EmailId);
                            $mail->setSubject("Forgot Password Email");
                            $mail->setBodyHtml($message);
                            $mail->setFrom(SETFROM, SETNAME);
                            if ($mail->send()) {
                                $response = '{"Message":"Success", "Error":"False" }';
                                echo $response;
                            } else {
                                $response = '{"Message":"Mail Could not be sent. Try again later", "Error":"true" }';
                                echo $response;
                            }
                        } else {
                            $response = '{"Message":"Please enter a valid user email", "Error":"true"}';
                            echo $response;
                        }
                        //	} // Validate XML
                    }
                    break;
                case "GetAllLibrary":
                    $main_array = array();
                    if (!empty($jsonObj->StoreId) && $jsonObj->StoreId > 0) {
                        $store_qry = 'SELECT is_store,is_store_status from  pclive_country where id="' . $jsonObj->StoreId . '" order by id desc LIMIT 1';
                        $store_result = $db->query($store_qry);
                        $store_record = $store_result->FetchAll();
                        $store_info = $store_record[0];
                        if ($store_info['is_store'] == 1 && $store_info['is_store_status'] == 1) {
                            $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id  WHERE prod.admin_approve='1'  AND prod.file_name!=''  AND storeprice.country_id='{$jsonObj->StoreId}' ORDER BY prod.cat_id ASC";
                        } else {
                            //default nigeria
                            $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id  WHERE prod.admin_approve='1'  AND prod.file_name!=''  AND storeprice.country_id=226 ORDER BY prod.cat_id ASC";
                        }
                    } else {
                        $sql = "SELECT prod.*,c.category_name,g.genre, storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id = storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id WHERE prod.admin_approve='1' AND prod.file_name!=''  ORDER BY prod.cat_id ASC";
                    }
                    $result = $db->query($sql);
                    $records = $result->FetchAll();
                    if (count($records) > 0) {
                        $response['Library'] = $records;
                        foreach ($records as $key => $Parray) {
                            $book_thumb_qry = 'SELECT * from  pclive_product_images where product_id="' . $Parray['product_id'] . '" order by id desc LIMIT 1';
                            $boothumb_result = $db->query($book_thumb_qry);
                            $book_thumb_record = $boothumb_result->FetchAll();
                            $book_thumb_info = $book_thumb_record[0];
                            if ($book_thumb_info['image_name_thumb'] != '') {
                                $thumbnail_path = $this->view->serverUrl() . $this->view->baseUrl() . "/" . USER_UPLOAD_DIR . $book_thumb_info['image_name_thumb'];
                            } else {
                                $thumbnail_path = "";
                            }
                            $bookname = str_replace(" ", "", $Parray['title']);
                            $response['Library'][$key]['ProductThumbnail'] = $thumbnail_path;
                            $response['Library'][$key]['Producturl'] = "http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/api/download/index/apicall/Bookdownload/apikey/" . $jsonObj->apikey . "/bookid/" . $Parray['product_id'] . "/bookname/" . $bookname;
                            //code to get publisher name from user table
                            $pub_qry = 'SELECT publisher from  pclive_users where id="' . $Parray['publisher_id'] . '" order by id desc LIMIT 1';
                            $pub_result = $db->query($pub_qry);
                            $pub_record = $pub_result->FetchAll();
                            $pub_info = $pub_record[0];
                            $response['Library'][$key]['publisher_name'] = $pub_info['publisher'];
                            //code to get author name from user table
                            $author_qry = 'SELECT first_name from  pclive_users where id="' . $Parray['author_id'] . '" order by id desc LIMIT 1';
                            $author_result = $db->query($author_qry);
                            $author_record = $author_result->FetchAll();
                            $author_info = $author_record[0];
                            if ($author_info['first_name'] == "") {
                                $response['Library'][$key]['author_name'] = "";
                            } else {
                                $response['Library'][$key]['author_name'] = $author_info['first_name'];
                            }
                            $review_qry = 'SELECT  avg(rating*1) as rate,`productid` FROM pclive_review where productid="' . $Parray['product_id'] . '" group by productid';
                            $review_result = $db->query($review_qry);
                            $review_record = $review_result->FetchAll();
                            $review_info = $review_record[0];
                            if (count($review_record) > 0) {
                                $rs = explode(".", $review_info['rate']);
                                if ($rs[1] != '') {
                                    if ("." . $rs[1] > 0.5) {
                                        $response['Library'][$key]['rating'] = $rs[0] + 1;
                                    } else {
                                        $response['Library'][$key]['rating'] = $rs[0] + 0.5;
                                    }
                                } else {
                                    $response['Library'][$key]['rating'] = $rs[0];
                                }
                            } else {
                                $response['Library'][$key]['rating'] = 0;
                            }
                            $response['Library'][$key]['books_status'] = "Yes";
                        }
                        $get_all_categories = "select * from pclive_genres where status='1' order by genre ASC";
                        $res_all_categories = $db->query($get_all_categories);
                        $data_categories = $res_all_categories->FetchAll();
                        $response['Allcategories'] = $data_categories;
                    } else {
                        $response['Library'][0]['books_status'] = "No";
                    }
                    //$response = stripslashes(json_encode($response, JSON_HEX_APOS));
                    //echo $response;
                    //new arrivals
                    if (!empty($jsonObj->StoreId) && $jsonObj->StoreId > 0) {
                        $store_qry = 'SELECT is_store,is_store_status from  pclive_country where id="' . $jsonObj->StoreId . '" order by id desc LIMIT 1';
                        $store_result = $db->query($store_qry);
                        $store_record = $store_result->FetchAll();
                        $store_info = $store_record[0];
                        if ($store_info['is_store'] == 1 && $store_info['is_store_status'] == 1) {
                            $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id  WHERE prod.admin_approve='1'  AND prod.file_name!=''  AND storeprice.country_id='{$jsonObj->StoreId}' ORDER BY prod.id DESC";
                        } else {
                            //default nigeria
                            $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id  WHERE prod.admin_approve='1'  AND prod.file_name!=''  AND storeprice.country_id=226 ORDER BY prod.id DESC";
                        }
                    } else {
                        $sql = "SELECT prod.*,c.category_name,g.genre, storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id = storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id WHERE prod.admin_approve='1' AND prod.file_name!=''  ORDER BY prod.id DESC";
                    }
                    $result = $db->query($sql);
                    $records = $result->FetchAll();
                    if (count($records) > 0) {
                        $response['Newarrivals'] = $records;
                        foreach ($records as $key => $Parray) {
                            $book_thumb_qry = 'SELECT * from  pclive_product_images where product_id="' . $Parray['product_id'] . '" order by id desc LIMIT 1';
                            $boothumb_result = $db->query($book_thumb_qry);
                            $book_thumb_record = $boothumb_result->FetchAll();
                            $book_thumb_info = $book_thumb_record[0];
                            if ($book_thumb_info['image_name_thumb'] != '') {
                                $thumbnail_path = $this->view->serverUrl() . $this->view->baseUrl() . "/" . USER_UPLOAD_DIR . $book_thumb_info['image_name_thumb'];
                            } else {
                                $thumbnail_path = "";
                            }
                            $bookname = str_replace(" ", "", $Parray['title']);
                            $response['Newarrivals'][$key]['ProductThumbnail'] = $thumbnail_path;
                            $response['Newarrivals'][$key]['Producturl'] = "http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/api/download/index/apicall/Bookdownload/apikey/" . $jsonObj->apikey . "/bookid/" . $Parray['product_id'] . "/bookname/" . $bookname;
                            //code to get publisher name from user table
                            $pub_qry = 'SELECT publisher from  pclive_users where id="' . $Parray['publisher_id'] . '" order by id desc LIMIT 1';
                            $pub_result = $db->query($pub_qry);
                            $pub_record = $pub_result->FetchAll();
                            $pub_info = $pub_record[0];
                            $response['Newarrivals'][$key]['publisher_name'] = $pub_info['publisher'];
                            //code to get author name from user table
                            $author_qry = 'SELECT first_name from  pclive_users where id="' . $Parray['author_id'] . '" order by id desc LIMIT 1';
                            $author_result = $db->query($author_qry);
                            $author_record = $author_result->FetchAll();
                            $author_info = $author_record[0];
                            if ($author_info['first_name'] == "") {
                                $response['Newarrivals'][$key]['author_name'] = "";
                            } else {
                                $response['Newarrivals'][$key]['author_name'] = $author_info['first_name'];
                            }
                            $review_qry = 'SELECT  avg(rating*1) as rate,`productid` FROM pclive_review where productid="' . $Parray['product_id'] . '" group by productid';
                            $review_result = $db->query($review_qry);
                            $review_record = $review_result->FetchAll();
                            $review_info = $review_record[0];
                            if (count($review_record) > 0) {
                                $rs = explode(".", $review_info['rate']);
                                if ($rs[1] != '') {
                                    if ("." . $rs[1] > 0.5) {
                                        $response['Newarrivals'][$key]['rating'] = $rs[0] + 1;
                                    } else {
                                        $response['Newarrivals'][$key]['rating'] = $rs[0] + 0.5;
                                    }
                                } else {
                                    $response['Newarrivals'][$key]['rating'] = $rs[0];
                                }
                            } else {
                                $response['Newarrivals'][$key]['rating'] = 0;
                            }
                            $response['Newarrivals'][$key]['books_status'] = "Yes";
                        }
                    } else {
                        $response['Newarrivals'][0]['books_status'] = "No";
                    }
                    //$response = stripslashes(json_encode($response, JSON_HEX_APOS));
                    //best seller
                    if (!empty($jsonObj->StoreId) && $jsonObj->StoreId > 0) {
                        $store_qry = 'SELECT is_store,is_store_status from  pclive_country where id="' . $jsonObj->StoreId . '" order by id desc LIMIT 1';
                        $store_result = $db->query($store_qry);
                        $store_record = $store_result->FetchAll();
                        $store_info = $store_record[0];
                        if ($store_info['is_store'] == 1 && $store_info['is_store_status'] == 1) {
                            $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id  WHERE prod.admin_approve='1'  AND prod.file_name!=''  AND storeprice.country_id='{$jsonObj->StoreId}' ORDER BY prod.best_seller DESC";
                        } else {
                            //default nigeria
                            $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id  WHERE prod.admin_approve='1'  AND prod.file_name!=''  AND storeprice.country_id=226 ORDER BY prod.best_seller DESC";
                        }
                    } else {
                        $sql = "SELECT prod.*,c.category_name,g.genre, storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id = storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id WHERE prod.admin_approve='1' AND prod.file_name!=''  ORDER BY prod.best_seller DESC";
                    }
                    $result = $db->query($sql);
                    $records = $result->FetchAll();
                    if (count($records) > 0) {
                        $response['Bestsellers'] = $records;
                        foreach ($records as $key => $Parray) {
                            $book_thumb_qry = 'SELECT * from  pclive_product_images where product_id="' . $Parray['product_id'] . '" order by id desc LIMIT 1';
                            $boothumb_result = $db->query($book_thumb_qry);
                            $book_thumb_record = $boothumb_result->FetchAll();
                            $book_thumb_info = $book_thumb_record[0];
                            if ($book_thumb_info['image_name_thumb'] != '') {
                                $thumbnail_path = $this->view->serverUrl() . $this->view->baseUrl() . "/" . USER_UPLOAD_DIR . $book_thumb_info['image_name_thumb'];
                            } else {
                                $thumbnail_path = "";
                            }
                            $bookname = str_replace(" ", "", $Parray['title']);
                            $response['Bestsellers'][$key]['ProductThumbnail'] = $thumbnail_path;
                            $response['Bestsellers'][$key]['Producturl'] = "http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/api/download/index/apicall/Bookdownload/apikey/" . $jsonObj->apikey . "/bookid/" . $Parray['product_id'] . "/bookname/" . $bookname;
                            //code to get publisher name from user table
                            $pub_qry = 'SELECT publisher from  pclive_users where id="' . $Parray['publisher_id'] . '" order by id desc LIMIT 1';
                            $pub_result = $db->query($pub_qry);
                            $pub_record = $pub_result->FetchAll();
                            $pub_info = $pub_record[0];
                            $response['Bestsellers'][$key]['publisher_name'] = $pub_info['publisher'];
                            //code to get author name from user table
                            $author_qry = 'SELECT first_name from  pclive_users where id="' . $Parray['author_id'] . '" order by id desc LIMIT 1';
                            $author_result = $db->query($author_qry);
                            $author_record = $author_result->FetchAll();
                            $author_info = $author_record[0];
                            if ($author_info['first_name'] == "") {
                                $response['Bestsellers'][$key]['author_name'] = "";
                            } else {
                                $response['Bestsellers'][$key]['author_name'] = $author_info['first_name'];
                            }
                            $review_qry = 'SELECT  avg(rating*1) as rate,`productid` FROM pclive_review where productid="' . $Parray['product_id'] . '" group by productid';
                            $review_result = $db->query($review_qry);
                            $review_record = $review_result->FetchAll();
                            $review_info = $review_record[0];
                            if (count($review_record) > 0) {
                                $rs = explode(".", $review_info['rate']);
                                if ($rs[1] != '') {
                                    if ("." . $rs[1] > 0.5) {
                                        $response['Bestsellers'][$key]['rating'] = $rs[0] + 1;
                                    } else {
                                        $response['Bestsellers'][$key]['rating'] = $rs[0] + 0.5;
                                    }
                                } else {
                                    $response['Bestsellers'][$key]['rating'] = $rs[0];
                                }
                            } else {
                                $response['Bestsellers'][$key]['rating'] = 0;
                            }
                            $response['Bestsellers'][$key]['books_status'] = "Yes";
                        }
                    } else {
                        $response['Bestsellers'][0]['books_status'] = "No";
                    }
                    //get featured
                    if (!empty($jsonObj->StoreId) && $jsonObj->StoreId > 0) {
                        $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id  WHERE prod.admin_approve='1'  AND prod.file_name!='' and is_featured=1  AND storeprice.country_id='{$jsonObj->StoreId}' ORDER BY prod.product_type*1 ASC";
                    } else {
                        $sql = "SELECT prod.*,c.category_name,g.genre, storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id = storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id WHERE prod.admin_approve='1' AND prod.file_name!='' and is_featured=1   ORDER BY prod.product_type*1 ASC";
                    }
                    $result = $db->query($sql);
                    $records = $result->FetchAll();
                    if (count($records) > 0) {
                        $response['Featured'] = $records;
                        foreach ($records as $key => $Parray) {
                            $book_thumb_qry = 'SELECT * from  pclive_product_images where product_id="' . $Parray['product_id'] . '" order by id desc LIMIT 1';
                            $boothumb_result = $db->query($book_thumb_qry);
                            $book_thumb_record = $boothumb_result->FetchAll();
                            $book_thumb_info = $book_thumb_record[0];
                            if ($book_thumb_info['image_name_thumb'] != '') {
                                $thumbnail_path = $this->view->serverUrl() . $this->view->baseUrl() . "/" . USER_UPLOAD_DIR . $book_thumb_info['image_name_thumb'];
                            } else {
                                $thumbnail_path = "";
                            }
                            $bookname = str_replace(" ", "", $Parray['title']);
                            $response['Featured'][$key]['ProductThumbnail'] = $thumbnail_path;
                            $response['Featured'][$key]['Producturl'] = "http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/api/download/index/apicall/Bookdownload/apikey/" . $jsonObj->apikey . "/bookid/" . $Parray['product_id'] . "/bookname/" . $bookname;
                            //code to get publisher name from user table
                            $pub_qry = 'SELECT publisher from  pclive_users where id="' . $Parray['publisher_id'] . '" order by id desc LIMIT 1';
                            $pub_result = $db->query($pub_qry);
                            $pub_record = $pub_result->FetchAll();
                            $pub_info = $pub_record[0];
                            $response['Featured'][$key]['publisher_name'] = $pub_info['publisher'];
                            //code to get author name from user table
                            $author_qry = 'SELECT first_name from  pclive_users where id="' . $Parray['author_id'] . '" order by id desc LIMIT 1';
                            $author_result = $db->query($author_qry);
                            $author_record = $author_result->FetchAll();
                            $author_info = $author_record[0];
                            if ($author_info['first_name'] == "") {
                                $response['Featured'][$key]['author_name'] = "";
                            } else {
                                $response['Featured'][$key]['author_name'] = $author_info['first_name'];
                            }
                        }
                    }
                    $response = stripslashes(json_encode($response, JSON_HEX_APOS));
                    echo $response;
                    break;
                case "GetAllFeaturedLibrary":
                    $main_array = array();
                    if (!empty($jsonObj->StoreId) && $jsonObj->StoreId > 0) {
                        $store_qry = 'SELECT is_store,is_store_status from  pclive_country where id="' . $jsonObj->StoreId . '" order by id desc LIMIT 1';
                        $store_result = $db->query($store_qry);
                        $store_record = $store_result->FetchAll();
                        $store_info = $store_record[0];
                        if ($store_info['is_store'] == 1 && $store_info['is_store_status'] == 1) {
                            $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id  WHERE prod.admin_approve='1'  AND prod.file_name!=''  AND storeprice.country_id='{$jsonObj->StoreId}' ORDER BY prod.cat_id ASC";
                        } else {
                            //default nigeria
                            $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id  WHERE prod.admin_approve='1'  AND prod.file_name!=''  AND storeprice.country_id=226 ORDER BY prod.cat_id ASC";
                        }
                    } else {
                        $sql = "SELECT prod.*,c.category_name,g.genre, storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id = storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id WHERE prod.admin_approve='1' AND prod.file_name!=''  ORDER BY prod.cat_id ASC";
                    }
                    $result = $db->query($sql);
                    $records = $result->FetchAll();
                    if (count($records) > 0) {
                        $response['Library'] = $records;
                        foreach ($records as $key => $Parray) {
                            $book_thumb_qry = 'SELECT * from  pclive_product_images where product_id="' . $Parray['product_id'] . '" order by id desc LIMIT 1';
                            $boothumb_result = $db->query($book_thumb_qry);
                            $book_thumb_record = $boothumb_result->FetchAll();
                            $book_thumb_info = $book_thumb_record[0];
                            if ($book_thumb_info['image_name_thumb'] != '') {
                                $thumbnail_path = $this->view->serverUrl() . $this->view->baseUrl() . "/" . USER_UPLOAD_DIR . $book_thumb_info['image_name_thumb'];
                            } else {
                                $thumbnail_path = "";
                            }
                            $bookname = str_replace(" ", "", $Parray['title']);
                            if (is_numeric($Parray['title'])) {
                                $bookbrand = "select * from pclive_brands where id='" . $Parray['title'] . "' ";
                                $bookbrand_result = $db->query($bookbrand);
                                $bookbrand_record = $bookbrand_result->FetchAll();
                                $bookbrand_info = $bookbrand_record[0];
                                $bookname = str_replace(" ", "", $bookbrand_info['brand']);
                            }
                            $response['Library'][$key]['ProductThumbnail'] = $thumbnail_path;
                            $response['Library'][$key]['Producturl'] = "http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/api/download/index/apicall/Bookdownload/apikey/" . $jsonObj->apikey . "/bookid/" . $Parray['product_id'] . "/bookname/" . $bookname;
                            //code to get publisher name from user table
                            $pub_qry = 'SELECT publisher from  pclive_users where id="' . $Parray['publisher_id'] . '" order by id desc LIMIT 1';
                            $pub_result = $db->query($pub_qry);
                            $pub_record = $pub_result->FetchAll();
                            $pub_info = $pub_record[0];
                            $response['Library'][$key]['publisher_name'] = $pub_info['publisher'];
                            //code to get author name from user table
                            $author_qry = 'SELECT first_name from  pclive_users where id="' . $Parray['author_id'] . '" order by id desc LIMIT 1';
                            $author_result = $db->query($author_qry);
                            $author_record = $author_result->FetchAll();
                            $author_info = $author_record[0];
                            if ($author_info['first_name'] == "") {
                                $response['Library'][$key]['author_name'] = "";
                            } else {
                                $response['Library'][$key]['author_name'] = $author_info['first_name'];
                            }
                            $review_qry = 'SELECT  avg(rating*1) as rate,`productid` FROM pclive_review where productid="' . $Parray['product_id'] . '" group by productid';
                            $review_result = $db->query($review_qry);
                            $review_record = $review_result->FetchAll();
                            $review_info = $review_record[0];
                            if (count($review_record) > 0) {
                                $rs = explode(".", $review_info['rate']);
                                if ($rs[1] != '') {
                                    if ("." . $rs[1] > 0.5) {
                                        $response['Library'][$key]['rating'] = $rs[0] + 1;
                                    } else {
                                        $response['Library'][$key]['rating'] = $rs[0] + 0.5;
                                    }
                                } else {
                                    $response['Library'][$key]['rating'] = $rs[0];
                                }
                            } else {
                                $response['Library'][$key]['rating'] = 0;
                            }
                            $response['Library'][$key]['books_status'] = "Yes";
                        }
                        $get_all_categories = "select * from pclive_genres where status='1' order by genre ASC";
                        $res_all_categories = $db->query($get_all_categories);
                        $data_categories = $res_all_categories->FetchAll();
                        $response['Allcategories'] = $data_categories;
                    } else {
                        $response['Library'][0]['books_status'] = "No";
                    }
                    //$response = stripslashes(json_encode($response, JSON_HEX_APOS));
                    //echo $response;
                    //get featured
                    if (!empty($jsonObj->StoreId) && $jsonObj->StoreId > 0) {
                        $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id  WHERE prod.admin_approve='1'  AND prod.file_name!='' and is_featured=1  AND storeprice.country_id='{$jsonObj->StoreId}' ORDER BY prod.product_type*1 ASC";
                    } else {
                        $sql = "SELECT prod.*,c.category_name,g.genre, storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id = storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id WHERE prod.admin_approve='1' AND prod.file_name!='' and is_featured=1   ORDER BY prod.product_type*1 ASC";
                    }
                    $result = $db->query($sql);
                    $records = $result->FetchAll();
                    if (count($records) > 0) {
                        $response['Featured'] = $records;
                        foreach ($records as $key => $Parray) {
                            $book_thumb_qry = 'SELECT * from  pclive_product_images where product_id="' . $Parray['product_id'] . '" order by id desc LIMIT 1';
                            $boothumb_result = $db->query($book_thumb_qry);
                            $book_thumb_record = $boothumb_result->FetchAll();
                            $book_thumb_info = $book_thumb_record[0];
                            if ($book_thumb_info['image_name_thumb'] != '') {
                                $thumbnail_path = $this->view->serverUrl() . $this->view->baseUrl() . "/" . USER_UPLOAD_DIR . $book_thumb_info['image_name_thumb'];
                            } else {
                                $thumbnail_path = "";
                            }
                            $bookname = str_replace(" ", "", $Parray['title']);
                            if (is_numeric($Parray['title'])) {
                                $bookbrand = "select * from pclive_brands where id='" . $Parray['title'] . "' ";
                                $bookbrand_result = $db->query($bookbrand);
                                $bookbrand_record = $bookbrand_result->FetchAll();
                                $bookbrand_info = $bookbrand_record[0];
                                $bookname = str_replace(" ", "", $bookbrand_info['brand']);
                            }
                            $response['Featured'][$key]['ProductThumbnail'] = $thumbnail_path;
                            $response['Featured'][$key]['Producturl'] = "http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/api/download/index/apicall/Bookdownload/apikey/" . $jsonObj->apikey . "/bookid/" . $Parray['product_id'] . "/bookname/" . $bookname;
                            //code to get publisher name from user table
                            $pub_qry = 'SELECT publisher from  pclive_users where id="' . $Parray['publisher_id'] . '" order by id desc LIMIT 1';
                            $pub_result = $db->query($pub_qry);
                            $pub_record = $pub_result->FetchAll();
                            $pub_info = $pub_record[0];
                            $response['Featured'][$key]['publisher_name'] = $pub_info['publisher'];
                            //code to get author name from user table
                            $author_qry = 'SELECT first_name from  pclive_users where id="' . $Parray['author_id'] . '" order by id desc LIMIT 1';
                            $author_result = $db->query($author_qry);
                            $author_record = $author_result->FetchAll();
                            $author_info = $author_record[0];
                            if ($author_info['first_name'] == "") {
                                $response['Featured'][$key]['author_name'] = "";
                            } else {
                                $response['Featured'][$key]['author_name'] = $author_info['first_name'];
                            }
                        }
                    }
                    $response = stripslashes(json_encode($response, JSON_HEX_APOS));
                    echo $response;
                    break;
                case "GetOnlyFeatured":
                    if ($jsonObj->UserId != '') {
                        $query_user = "******" . $jsonObj->UserId . "'";
                        $exe_user = $db->query($query_user);
                        $result_user = $exe_user->FetchAll();
                        $array_of_books = array();
                        $sql_books = "select * from pclive_group_subscriptions where company_id='" . $result_user[0]['parent_id'] . "' and group_id='" . $result_user[0]['group_id'] . "'";
                        $exe_books = mysql_query($sql_books);
                        if ($result_user[0]['group_status'] == '1') {
                            while ($result_books = mysql_fetch_array($exe_books)) {
                                $array_of_books[] = $result_books['publication_id'];
                            }
                        }
                        $implode_array_of_books = @implode(",", $array_of_books);
                    }
                    if (!empty($jsonObj->StoreId) && $jsonObj->StoreId > 0) {
                        $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id INNER JOIN pclive_product_images img ON prod.id=img.product_id WHERE prod.admin_approve='1'  AND prod.file_name!='' and is_featured=1  AND storeprice.country_id='{$jsonObj->StoreId}' AND prod.add_time >=DATE( DATE_SUB( NOW( ) , INTERVAL 30 DAY ) )  ORDER BY prod.product_type*1 ASC";
                    } else {
                        $sql = "SELECT prod.*,c.category_name,g.genre, storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id = storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id INNER JOIN pclive_product_images img ON prod.id=img.product_id WHERE prod.admin_approve='1' AND prod.file_name!='' and is_featured=1 AND prod.add_time\n>= DATE( DATE_SUB( NOW( ) , INTERVAL 30 DAY ) )  ORDER BY prod.product_type*1 ASC";
                    }
                    $result = $db->query($sql);
                    $records = $result->FetchAll();
                    if (count($records) > 0) {
                        $response['Featured'] = $records;
                        $ii = 0;
                        foreach ($records as $key => $Parray) {
                            //echo $Parray['id']." : - book array";
                            //echo $result_books[$ii]['publication_id']." : - subscription array";
                            $retVal = array();
                            $select = 'SELECT * from pclive_country where id="' . $Parray['country_id'] . '"';
                            $country_result = $db->query($select);
                            $retVal = $country_result->FetchAll();
                            $response['Featured'][$key]['country_name'] = $retVal[0]['country'];
                            //echo ">>>>>".$retVal['currency_id'];
                            $retVal1 = array();
                            $select1 = 'SELECT * from pclive_currency where currency_id="' . $retVal[0]['currency_id'] . '"';
                            $currency_result = $db->query($select1);
                            $retVal1 = $currency_result->FetchAll();
                            // get symbol with price $retVal1[0]['currency_sign'];
                            $response['Featured'][$key]['priceText'] = $retVal1[0]['currency_sign'] . " " . $response['Featured'][$key]['price'];
                            $book_thumb_qry = 'SELECT * from  pclive_product_images where product_id="' . $Parray['product_id'] . '" order by id desc LIMIT 1';
                            $boothumb_result = $db->query($book_thumb_qry);
                            $book_thumb_record = $boothumb_result->FetchAll();
                            $book_thumb_info = $book_thumb_record[0];
                            if ($book_thumb_info['image_name_thumb'] != '') {
                                $thumbnail_path = $this->view->serverUrl() . $this->view->baseUrl() . "/" . USER_UPLOAD_DIR . $book_thumb_info['image_name_thumb'];
                            } else {
                                $thumbnail_path = "";
                            }
                            $bookname = str_replace(" ", "", $Parray['title']);
                            if (is_numeric($Parray['title'])) {
                                $bookbrand = "select * from pclive_brands where id='" . $Parray['title'] . "' ";
                                $bookbrand_result = $db->query($bookbrand);
                                $bookbrand_record = $bookbrand_result->FetchAll();
                                $bookbrand_info = $bookbrand_record[0];
                                $response['Featured'][$key]['title'] = $bookbrand_info['brand'];
                                $bookname = str_replace(" ", "", $bookbrand_info['brand']);
                            }
                            /*		
                            $this->modelBooks = new Publisher_Model_DbTable_Books();	
                            $getBrandInfo=$this->modelBooks->getBrandInfo($Parray['title']);
                            if(!empty($getBrandInfo) && is_numeric($Parray['title']))
                            {
                            	$bookname=$getBrandInfo['brand'];
                            }else
                            {
                            	$bookname=$Parray['title'];
                            }
                            
                            if(!empty($Parray['parent_brand_id']) && $Parray['cat_id']!='3')
                            {
                            $productInfo=$this->modelBooks->fetchRow('id="'.$Parray['parent_brand_id'].'"');
                            $getParentBrandInfo=$this->modelBooks->getBrandInfo($productInfo->title);
                            	if(!empty($getParentBrandInfo))
                            	{
                            		$bookname=$getParentBrandInfo['brand'].'-'.$bookname;
                            	}
                            //$all=getPublicationIdsByCategoryName();	
                            }
                            $response['Featured'][$key]['title']=$bookname;	
                            $bookname= str_replace(" ","",$bookname);	
                            */
                            $response['Featured'][$key]['ProductThumbnail'] = $thumbnail_path;
                            $response['Featured'][$key]['Producturl'] = "http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/api/download/index/apicall/Bookdownload/apikey/" . $jsonObj->apikey . "/bookid/" . $Parray['product_id'] . "/bookname/" . $bookname;
                            $response['Featured'][$key]['publish_time'] = $Parray['publish_time'] . " 00:00:00";
                            //code to get publisher name from user table
                            $pub_qry = 'SELECT publisher from  pclive_users where id="' . $Parray['publisher_id'] . '" order by id desc LIMIT 1';
                            $pub_result = $db->query($pub_qry);
                            $pub_record = $pub_result->FetchAll();
                            $pub_info = $pub_record[0];
                            //$response['Featured'][$key]['publisher_name']=$pub_info['first_name']." ".$pub_info['last_name'];
                            //$response['Featured'][$key]['publisher']=$pub_info['first_name']." ".$pub_info['last_name'];
                            $response['Featured'][$key]['publisher_name'] = $pub_info['publisher'];
                            $response['Featured'][$key]['publisher'] = $pub_info['publisher'];
                            //code to get author name from user table
                            $author_qry = 'SELECT first_name,last_name from  pclive_users where id="' . $Parray['author_id'] . '" order by id desc LIMIT 1';
                            $author_result = $db->query($author_qry);
                            $author_record = $author_result->FetchAll();
                            $author_info = $author_record[0];
                            if ($author_info['first_name'] == "") {
                                $response['Featured'][$key]['author_name'] = "";
                            } else {
                                $response['Featured'][$key]['author_name'] = $author_info['first_name'] . " " . $author_info['last_name'];
                            }
                            $review_qry = 'SELECT  avg(rating*1) as rate,`productid` FROM pclive_review where productid="' . $Parray['product_id'] . '" group by productid';
                            $review_result = $db->query($review_qry);
                            $review_record = $review_result->FetchAll();
                            $review_info = $review_record[0];
                            if (count($review_record) > 0) {
                                $rs = explode(".", $review_info['rate']);
                                if ($rs[1] != '') {
                                    if ("." . $rs[1] > 0.5) {
                                        $response['Featured'][$key]['rating'] = $rs[0] + 1;
                                    } else {
                                        $response['Featured'][$key]['rating'] = $rs[0] + 0.5;
                                    }
                                } else {
                                    $response['Featured'][$key]['rating'] = $rs[0];
                                }
                            } else {
                                $response['Featured'][$key]['rating'] = 0;
                            }
                            $response['Featured'][$key]['books_status'] = "Yes";
                            $group_name = '';
                            $query_product_pub = "select parent_brand_id from pclive_products where id= '" . $Parray['id'] . "'";
                            $rs_product_pub = $db->query($query_product_pub);
                            $result_product_pub = $rs_product_pub->FetchAll();
                            if ($result_product_pub[0]['parent_brand_id'] > 0) {
                                $sql_issue = "select *,chd.subscription_type as subs_type,chd.group_id as grp_id,chd.start_date as start_date,chd.publication_id as publication_id,chd.number_of_issues,chd.number_of_downloaded,chd.remaining_downloads from  pclive_credit_history as ch,pclive_user_sub_details chd where ch.order_id=chd.order_id and publication_id='" . $result_product_pub[0]['parent_brand_id'] . "' and chd.user_id='" . $jsonObj->UserId . "' and ch.bookid='" . $Parray['product_id'] . "' and ch.payment_status='1'";
                                $rs_issue = $db->query($sql_issue);
                                $result_issue = $rs_issue->fetchAll();
                                if ($result_issue[0]['grp_id'] != 0) {
                                    $get_group_name = mysql_query("select * from pclive_company_groups where id= '" . $result_issue[0]['grp_id'] . "'");
                                    $result_group_name = mysql_fetch_array($get_group_name);
                                    $response['Featured'][$key]['is_free'] = "true";
                                    $response['Featured'][$key]['group_name'] = $result_group_name['group_name'];
                                    $group_name = $result_group_name['group_name'];
                                }
                                if (count($result_issue) > 0) {
                                    $response['Featured'][$key]['is_free'] = "purchased";
                                    $response['Featured'][$key]['group_name'] = $group_name;
                                    /*if($result_issue[0]['subs_type']>0 && $result_issue[0]['remaining_downloads']>0)
                                    		{
                                    			
                                    		
                                    			$start_date = explode(" ",$result_issue[0]['start_date']);
                                    			//$start_date ='2014-05-11';
                                    			$start_date = $start_date[0];
                                    			$query_subscribe_product = "select id from  pclive_products where parent_brand_id= '".$result_issue[0]['publication_id']."' and date_format(add_time,'%Y-%m-%d')>'".$start_date[0]."'";
                                    			$rs_subscribe_product = $db->query($query_subscribe_product);						
                                    			$result_subscribe_product = $rs_subscribe_product->FetchAll();
                                    			if(count($result_subscribe_product)>0 )
                                    			{
                                    				$response['Featured'][$key]['is_free']="purchased";
                                    				$response['Featured'][$key]['group_name']=$group_name;
                                    			}
                                    			else
                                    			{
                                    				$response['Featured'][$key]['is_free']="false";
                                    				$response['Featured'][$key]['group_name']=$group_name;
                                    			}
                                    		}
                                    		elseif($result_issue[0]['remaining_downloads']>0)
                                    		{
                                    			$response['Featured'][$key]['is_free']="purchased";
                                    			$response['Featured'][$key]['group_name']=$group_name;
                                    		}
                                    		else
                                    		{
                                    			$response['Featured'][$key]['is_free']="false";
                                    			$response['Featured'][$key]['group_name']=$group_name;
                                    		}	*/
                                } else {
                                    $response['Featured'][$key]['is_free'] = "false";
                                    $response['Featured'][$key]['group_name'] = $group_name;
                                }
                            } else {
                                //$sql_pub = "select * from pclive_credit_history";
                                //$query_pur_book = "select * from  pclive_credit_history where userid= '".$jsonObj->UserId."' and payment_status=1 and bookid= '".$Parray['product_id']."'";
                                //$rs_pur_book = $db->query($query_pur_book);
                                //	$result_book= $rs_pur_book->fetchAll();
                                $query_pur_book = "select *,chd.subscription_type as subs_type,chd.group_id as grp_id,chd.start_date as start_date,chd.publication_id as publication_id,chd.number_of_issues,chd.number_of_downloaded,chd.remaining_downloads from  pclive_credit_history as ch,pclive_user_sub_details chd where ch.order_id=chd.order_id and chd.product_id='" . $Parray['product_id'] . "' and chd.user_id='" . $jsonObj->UserId . "' and ch.bookid='" . $Parray['product_id'] . "' and ch.payment_status='1'";
                                $rs_book = $db->query($query_pur_book);
                                $result_book = $rs_book->fetchAll();
                                if (count($result_book) > 0) {
                                    if ($result_issue[0]['grp_id'] != 0) {
                                        $get_group_name = mysql_query("select * from pclive_company_groups where id= '" . $result_book[0]['grp_id'] . "'");
                                        $result_group_name = mysql_fetch_array($get_group_name);
                                        $response['Featured'][$key]['is_free'] = "true";
                                        $response['Featured'][$key]['group_name'] = $result_group_name['group_name'];
                                        $group_name = $result_group_name['group_name'];
                                    }
                                    $response['Featured'][$key]['is_free'] = "purchased";
                                    $response['Featured'][$key]['group_name'] = $group_name;
                                } else {
                                    if ($Parray['price'] == 0 || $Parray['price'] == '') {
                                        $response['Featured'][$key]['is_free'] = "free";
                                        $response['Featured'][$key]['group_name'] = $group_name;
                                    } else {
                                        $response['Featured'][$key]['is_free'] = "false";
                                        $response['Featured'][$key]['group_name'] = $group_name;
                                    }
                                }
                            }
                            /* if(in_array($Parray['id'],$array_of_books))
                            		 {
                            				 $get_group_name = mysql_query("select * from pclive_company_groups where id= '".$result_user[0]['group_id']."'");
                            				 $result_group_name = mysql_fetch_array($get_group_name);
                            				 $response['Featured'][$key]['is_free']="true";
                            				 $response['Featured'][$key]['group_name']= $result_group_name['group_name'];
                            		 }
                            		 else
                            		 {									
                            			$query_pur_book = "select * from  pclive_credit_history where userid= '".$jsonObj->UserId."' and payment_status=1 and bookid= '".$Parray['product_id']."'";
                            			$rs_pur_book = $db->query($query_pur_book);						
                            			$result_book= $rs_pur_book->FetchAll();	
                            			 if(count($result_book)>0)
                            			 {
                            				$response['Featured'][$key]['is_free']="purchased";									
                            			 }
                            			 else if($Parray['price']==0 || $Parray['price']=='')
                            			 {								 
                            			 $response['Featured'][$key]['is_free']="free";
                            			 }						 
                            			 else	
                            			 {								
                            			 $response['Featured'][$key]['is_free']="false";
                            			 }
                            			$response['Featured'][$key]['group_name']= "";
                            		 }*/
                            $ii++;
                        }
                        $response['Message'] = "Success.";
                        $response['error'] = "false";
                    } else {
                        //$response = '{"Message":"No Featured Books found","apikey":"","error":"true"}';
                        $response['Message'] = "No Featured Books found.";
                        $response['error'] = "true";
                    }
                    $response = stripslashes(json_encode($response, JSON_HEX_APOS));
                    echo $response;
                    break;
                case "GetOnlyBestSeller":
                    if ($jsonObj->UserId != '') {
                        $query_user = "******" . $jsonObj->UserId . "'";
                        $exe_user = $db->query($query_user);
                        $result_user = $exe_user->FetchAll();
                        $array_of_books = array();
                        $sql_books = "select * from pclive_group_subscriptions where company_id='" . $result_user[0]['parent_id'] . "' and group_id='" . $result_user[0]['group_id'] . "'";
                        $exe_books = mysql_query($sql_books);
                        if ($result_user[0]['group_status'] == '1') {
                            while ($result_books = mysql_fetch_array($exe_books)) {
                                $array_of_books[] = $result_books['publication_id'];
                            }
                        }
                        $implode_array_of_books = @implode(",", $array_of_books);
                    }
                    if (!empty($jsonObj->StoreId) && $jsonObj->StoreId > 0) {
                        $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id INNER JOIN pclive_product_images img ON prod.id=img.product_id WHERE prod.admin_approve='1'  AND prod.file_name!='' AND storeprice.country_id='{$jsonObj->StoreId}' AND prod.add_time >= DATE( DATE_SUB( NOW( ) , INTERVAL 30 DAY ) ) AND DATE( NOW( ) ) ORDER BY prod.best_seller DESC";
                    } else {
                        $sql = "SELECT prod.*,c.category_name,g.genre, storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id = storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id INNER JOIN pclive_product_images img ON prod.id=img.product_id WHERE prod.admin_approve='1' AND prod.file_name!='' AND prod.add_time >= DATE( DATE_SUB( NOW( ) , INTERVAL 30 DAY ) ) AND DATE( NOW( ) ) ORDER BY prod.best_seller DESC";
                    }
                    $result = $db->query($sql);
                    $records = $result->FetchAll();
                    if (count($records) > 0) {
                        $response['BestSeller'] = $records;
                        foreach ($records as $key => $Parray) {
                            $retVal = array();
                            $select = 'SELECT * from pclive_country where id="' . $Parray['country_id'] . '"';
                            $country_result = $db->query($select);
                            $retVal = $country_result->FetchAll();
                            //echo ">>>>>".$retVal['currency_id'];
                            $response['BestSeller'][$key]['country_name'] = $retVal[0]['country'];
                            $retVal1 = array();
                            $select1 = 'SELECT * from pclive_currency where currency_id="' . $retVal[0]['currency_id'] . '"';
                            $currency_result = $db->query($select1);
                            $retVal1 = $currency_result->FetchAll();
                            // get symbol with price $retVal1[0]['currency_sign'];
                            $response['BestSeller'][$key]['priceText'] = $retVal1[0]['currency_sign'] . " " . $response['BestSeller'][$key]['price'];
                            $book_thumb_qry = 'SELECT * from  pclive_product_images where product_id="' . $Parray['product_id'] . '" order by id desc LIMIT 1';
                            $boothumb_result = $db->query($book_thumb_qry);
                            $book_thumb_record = $boothumb_result->FetchAll();
                            $book_thumb_info = $book_thumb_record[0];
                            if ($book_thumb_info['image_name_thumb'] != '') {
                                $thumbnail_path = $this->view->serverUrl() . $this->view->baseUrl() . "/" . USER_UPLOAD_DIR . $book_thumb_info['image_name_thumb'];
                            } else {
                                $thumbnail_path = "";
                            }
                            $bookname = str_replace(" ", "", $Parray['title']);
                            if (is_numeric($Parray['title'])) {
                                $bookbrand = "select * from pclive_brands where id='" . $Parray['title'] . "' ";
                                $bookbrand_result = $db->query($bookbrand);
                                $bookbrand_record = $bookbrand_result->FetchAll();
                                $bookbrand_info = $bookbrand_record[0];
                                $response['BestSeller'][$key]['title'] = $bookbrand_info['brand'];
                                $bookname = str_replace(" ", "", $bookbrand_info['brand']);
                            }
                            /*	
                            $this->modelBooks = new Publisher_Model_DbTable_Books();	
                            $getBrandInfo=$this->modelBooks->getBrandInfo($Parray['title']);
                            if(!empty($getBrandInfo) && is_numeric($Parray['title']))
                            {
                            	$bookname=$getBrandInfo['brand'];
                            }else
                            {
                            	$bookname=$Parray['title'];
                            }
                            
                            if(!empty($Parray['parent_brand_id']) && $Parray['cat_id']!='3')
                            {
                            $productInfo=$this->modelBooks->fetchRow('id="'.$Parray['parent_brand_id'].'"');
                            $getParentBrandInfo=$this->modelBooks->getBrandInfo($productInfo->title);
                            	if(!empty($getParentBrandInfo))
                            	{
                            		$bookname=$getParentBrandInfo['brand'].'-'.$bookname;
                            	}
                            //$all=getPublicationIdsByCategoryName();	
                            }
                            $response['BestSeller'][$key]['title']=$bookname;	
                            $bookname= str_replace(" ","",$bookname);	
                            */
                            $response['BestSeller'][$key]['ProductThumbnail'] = $thumbnail_path;
                            $response['BestSeller'][$key]['Producturl'] = "http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/api/download/index/apicall/Bookdownload/apikey/" . $jsonObj->apikey . "/bookid/" . $Parray['product_id'] . "/bookname/" . $bookname;
                            $response['BestSeller'][$key]['publish_time'] = $Parray['publish_time'] . " 00:00:00";
                            //code to get publisher name from user table
                            $pub_qry = 'SELECT publisher from  pclive_users where id="' . $Parray['publisher_id'] . '" order by id desc LIMIT 1';
                            $pub_result = $db->query($pub_qry);
                            $pub_record = $pub_result->FetchAll();
                            $pub_info = $pub_record[0];
                            //$response['BestSeller'][$key]['publisher_name']=$pub_info['publisher'];
                            $response['BestSeller'][$key]['publisher_name'] = $pub_info['publisher'];
                            $response['BestSeller'][$key]['publisher'] = $pub_info['publisher'];
                            //code to get author name from user table
                            $author_qry = 'SELECT first_name,last_name from  pclive_users where id="' . $Parray['author_id'] . '" order by id desc LIMIT 1';
                            $author_result = $db->query($author_qry);
                            $author_record = $author_result->FetchAll();
                            $author_info = $author_record[0];
                            if ($author_info['first_name'] == "") {
                                $response['BestSeller'][$key]['author_name'] = "";
                            } else {
                                $response['BestSeller'][$key]['author_name'] = $author_info['first_name'] . " " . $author_info['last_name'];
                            }
                            $review_qry = 'SELECT  avg(rating*1) as rate,`productid` FROM pclive_review where productid="' . $Parray['product_id'] . '" group by productid';
                            $review_result = $db->query($review_qry);
                            $review_record = $review_result->FetchAll();
                            $review_info = $review_record[0];
                            if (count($review_record) > 0) {
                                $rs = explode(".", $review_info['rate']);
                                if ($rs[1] != '') {
                                    if ("." . $rs[1] > 0.5) {
                                        $response['BestSeller'][$key]['rating'] = $rs[0] + 1;
                                    } else {
                                        $response['BestSeller'][$key]['rating'] = $rs[0] + 0.5;
                                    }
                                } else {
                                    $response['BestSeller'][$key]['rating'] = $rs[0];
                                }
                            } else {
                                $response['BestSeller'][$key]['rating'] = 0;
                            }
                            $response['BestSeller'][$key]['books_status'] = "Yes";
                            $group_name = '';
                            $query_product_pub = "select parent_brand_id from pclive_products where id= '" . $Parray['id'] . "'";
                            $rs_product_pub = $db->query($query_product_pub);
                            $result_product_pub = $rs_product_pub->FetchAll();
                            if ($result_product_pub[0]['parent_brand_id'] > 0) {
                                $sql_issue = "select *,chd.subscription_type as subs_type,chd.group_id as grp_id,chd.start_date as start_date,chd.publication_id as publication_id,chd.number_of_issues,chd.number_of_downloaded,chd.remaining_downloads from  pclive_credit_history as ch,pclive_user_sub_details chd where ch.order_id=chd.order_id and publication_id='" . $result_product_pub[0]['parent_brand_id'] . "' and chd.user_id='" . $jsonObj->UserId . "' and ch.bookid='" . $Parray['product_id'] . "' and ch.payment_status='1'";
                                $rs_issue = $db->query($sql_issue);
                                $result_issue = $rs_issue->fetchAll();
                                if ($result_issue[0]['grp_id'] != 0) {
                                    $get_group_name = mysql_query("select * from pclive_company_groups where id= '" . $result_issue[0]['grp_id'] . "'");
                                    $result_group_name = mysql_fetch_array($get_group_name);
                                    $response['BestSeller'][$key]['is_free'] = "true";
                                    $response['BestSeller'][$key]['group_name'] = $result_group_name['group_name'];
                                    $group_name = $result_group_name['group_name'];
                                }
                                if (count($result_issue) > 0) {
                                    $response['BestSeller'][$key]['is_free'] = "purchased";
                                    $response['BestSeller'][$key]['group_name'] = $group_name;
                                    /*if($result_issue[0]['subs_type']>0 && $result_issue[0]['remaining_downloads']>0)
                                    		{
                                    			$start_date = explode(" ",$result_issue[0]['start_date']);
                                    			//$start_date ='2014-05-11';
                                    			$start_date = $start_date[0];
                                    			$query_subscribe_product = "select id from  pclive_products where parent_brand_id= '".$result_issue[0]['publication_id']."' and date_format(add_time,'%Y-%m-%d')>'".$start_date[0]."'";
                                    			$rs_subscribe_product = $db->query($query_subscribe_product);						
                                    			$result_subscribe_product = $rs_subscribe_product->FetchAll();
                                    			if(count($result_subscribe_product)>0 )
                                    			{
                                    				$response['BestSeller'][$key]['is_free']="purchased";
                                    				$response['BestSeller'][$key]['group_name']=$group_name;
                                    			}
                                    			else
                                    			{
                                    				$response['BestSeller'][$key]['is_free']="false";
                                    				$response['BestSeller'][$key]['group_name']=$group_name;
                                    			}
                                    		}
                                    		elseif($result_issue[0]['remaining_downloads']>0)
                                    		{
                                    			$response['BestSeller'][$key]['is_free']="purchased";
                                    			$response['BestSeller'][$key]['group_name']=$group_name;
                                    		}
                                    		else
                                    		{
                                    			$response['BestSeller'][$key]['is_free']="false";
                                    			$response['BestSeller'][$key]['group_name']=$group_name;
                                    		}*/
                                } else {
                                    $response['BestSeller'][$key]['is_free'] = "false";
                                    $response['BestSeller'][$key]['group_name'] = $group_name;
                                }
                            } else {
                                //$sql_pub = "select * from pclive_credit_history";
                                //$query_pur_book = "select * from  pclive_credit_history where userid= '".$jsonObj->UserId."' and payment_status=1 and bookid= '".$Parray['product_id']."'";
                                //$rs_pur_book = $db->query($query_pur_book);
                                //$result_book= $rs_pur_book->fetchAll();
                                $query_pur_book = "select *,chd.subscription_type as subs_type,chd.group_id as grp_id,chd.start_date as start_date,chd.publication_id as publication_id,chd.number_of_issues,chd.number_of_downloaded,chd.remaining_downloads from  pclive_credit_history as ch,pclive_user_sub_details chd where ch.order_id=chd.order_id and chd.product_id='" . $Parray['product_id'] . "' and chd.user_id='" . $jsonObj->UserId . "' and ch.bookid='" . $Parray['product_id'] . "' and ch.payment_status='1'";
                                $rs_book = $db->query($query_pur_book);
                                $result_book = $rs_book->fetchAll();
                                if (count($result_book) > 0) {
                                    if ($result_issue[0]['grp_id'] != 0) {
                                        $get_group_name = mysql_query("select * from pclive_company_groups where id= '" . $result_book[0]['grp_id'] . "'");
                                        $result_group_name = mysql_fetch_array($get_group_name);
                                        $response['BestSeller'][$key]['is_free'] = "true";
                                        $response['BestSeller'][$key]['group_name'] = $result_group_name['group_name'];
                                        $group_name = $result_group_name['group_name'];
                                    }
                                    $response['BestSeller'][$key]['is_free'] = "purchased";
                                    $response['BestSeller'][$key]['group_name'] = $group_name;
                                } else {
                                    if ($Parray['price'] == 0 || $Parray['price'] == '') {
                                        $response['BestSeller'][$key]['is_free'] = "free";
                                        $response['BestSeller'][$key]['group_name'] = $group_name;
                                    } else {
                                        $response['BestSeller'][$key]['is_free'] = "false";
                                        $response['BestSeller'][$key]['group_name'] = $group_name;
                                    }
                                }
                            }
                            /*
                            								if(in_array($Parray['id'],$array_of_books))
                            								{
                            									 $get_group_name = mysql_query("select * from pclive_company_groups where id= '".$result_user[0]['group_id']."'");
                            									 $result_group_name = mysql_fetch_array($get_group_name);
                            									 $response['BestSeller'][$key]['is_free']="true";
                            									 $response['BestSeller'][$key]['group_name']= $result_group_name['group_name'];
                            								}
                            								else
                            								{									
                            									$query_pur_book = "select * from  pclive_credit_history where userid= '".$jsonObj->UserId."' and payment_status=1 and bookid= '".$Parray['product_id']."'";
                            									$rs_pur_book = $db->query($query_pur_book);						
                            									$result_book= $rs_pur_book->FetchAll();	
                            									if(count($result_book)>0)
                            										$response['BestSeller'][$key]['is_free']="purchased";	
                            									else if($Parray['price']==0 || $Parray['price']=='')
                            									{						 
                            										$response['BestSeller'][$key]['is_free']="free";
                            									}	
                            									else										
                            										 $response['BestSeller'][$key]['is_free']="false";
                            										 $response['BestSeller'][$key]['group_name']= "";
                            								}*/
                        }
                        $response['Message'] = "Success.";
                        $response['error'] = "false";
                    } else {
                        // $response = '[{"Error": {"Message":"No Best Sellers Found.","error":"true"}}]';
                        $response['Message'] = "No Best Sellers Found.";
                        $response['error'] = "true";
                    }
                    $response = stripslashes(json_encode($response, JSON_HEX_APOS));
                    echo $response;
                    break;
                case "GetOnlyNewArrivals":
                    if ($jsonObj->UserId != '') {
                        $query_user = "******" . $jsonObj->UserId . "'";
                        $exe_user = $db->query($query_user);
                        $result_user = $exe_user->FetchAll();
                        $array_of_books = array();
                        $sql_books = "select * from pclive_group_subscriptions where company_id='" . $result_user[0]['parent_id'] . "' and group_id='" . $result_user[0]['group_id'] . "'";
                        $exe_books = mysql_query($sql_books);
                        if ($result_user[0]['group_status'] == '1') {
                            while ($result_books = mysql_fetch_array($exe_books)) {
                                $array_of_books[] = $result_books['publication_id'];
                            }
                        }
                        $implode_array_of_books = @implode(",", $array_of_books);
                    }
                    $date = date('Y-m-d', time() - 15 * 86400);
                    if (!empty($jsonObj->StoreId) && $jsonObj->StoreId > 0) {
                        //$sql="SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id  WHERE prod.admin_approve='1'  AND prod.file_name!='' AND storeprice.country_id='$jsonObj->StoreId'  and  date(add_time) >= '$date' ORDER BY prod.add_time DESC";
                        $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id INNER JOIN pclive_product_images img ON prod.id=img.product_id WHERE prod.admin_approve='1'  AND prod.file_name!='' AND storeprice.country_id='{$jsonObj->StoreId}' AND prod.add_time >=DATE( DATE_SUB( NOW( ) , INTERVAL 30 DAY ) )  ORDER BY prod.add_time DESC ";
                    } else {
                        //$sql="SELECT prod.*,c.category_name,g.genre, storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id = storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id WHERE prod.admin_approve='1' AND prod.file_name!='' and  date(add_time) >= '$date' ORDER BY prod.add_time DESC";
                        $sql = "SELECT prod.*,c.category_name,g.genre, storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id = storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id INNER JOIN pclive_product_images img ON prod.id=img.product_id WHERE prod.admin_approve='1' AND prod.file_name!='' AND prod.add_time >=DATE( DATE_SUB( NOW( ) , INTERVAL 30 DAY ) )  ORDER BY prod.add_time DESC ";
                    }
                    $result = $db->query($sql);
                    $records = $result->FetchAll();
                    if (count($records) > 0) {
                        $response['NewArrivals'] = $records;
                        foreach ($records as $key => $Parray) {
                            $retVal = array();
                            $select = 'SELECT * from pclive_country where id="' . $Parray['country_id'] . '"';
                            $country_result = $db->query($select);
                            $retVal = $country_result->FetchAll();
                            //echo ">>>>>".$retVal['currency_id'];
                            $response['NewArrivals'][$key]['country_name'] = $retVal[0]['country'];
                            $retVal1 = array();
                            $select1 = 'SELECT * from pclive_currency where currency_id="' . $retVal[0]['currency_id'] . '"';
                            $currency_result = $db->query($select1);
                            $retVal1 = $currency_result->FetchAll();
                            // get symbol with price $retVal1[0]['currency_sign'];
                            $response['NewArrivals'][$key]['priceText'] = $retVal1[0]['currency_sign'] . " " . $response['NewArrivals'][$key]['price'];
                            $book_thumb_qry = 'SELECT * from  pclive_product_images where product_id="' . $Parray['product_id'] . '" order by id desc LIMIT 1';
                            $boothumb_result = $db->query($book_thumb_qry);
                            $book_thumb_record = $boothumb_result->FetchAll();
                            $book_thumb_info = $book_thumb_record[0];
                            if ($book_thumb_info['image_name_thumb'] != '') {
                                $thumbnail_path = $this->view->serverUrl() . $this->view->baseUrl() . "/" . USER_UPLOAD_DIR . $book_thumb_info['image_name_thumb'];
                            } else {
                                $thumbnail_path = "";
                            }
                            $bookname = str_replace(" ", "", $Parray['title']);
                            if (is_numeric($Parray['title'])) {
                                $bookbrand = "select * from pclive_brands where id='" . $Parray['title'] . "' ";
                                $bookbrand_result = $db->query($bookbrand);
                                $bookbrand_record = $bookbrand_result->FetchAll();
                                $bookbrand_info = $bookbrand_record[0];
                                $response['NewArrivals'][$key]['title'] = $bookbrand_info['brand'];
                                $bookname = str_replace(" ", "", $bookbrand_info['brand']);
                            }
                            /*	
                            	$this->modelBooks = new Publisher_Model_DbTable_Books();	
                            $getBrandInfo=$this->modelBooks->getBrandInfo($Parray['title']);
                            if(!empty($getBrandInfo) && is_numeric($Parray['title']))
                            {
                            	$bookname=$getBrandInfo['brand'];
                            }else
                            {
                            	$bookname=$Parray['title'];
                            }
                            
                            if(!empty($Parray['parent_brand_id']) && $Parray['cat_id']!='3')
                            {
                            $productInfo=$this->modelBooks->fetchRow('id="'.$Parray['parent_brand_id'].'"');
                            $getParentBrandInfo=$this->modelBooks->getBrandInfo($productInfo->title);
                            	if(!empty($getParentBrandInfo))
                            	{
                            		$bookname=$getParentBrandInfo['brand'].'-'.$bookname;
                            	}
                            //$all=getPublicationIdsByCategoryName();	
                            }
                            $response['NewArrivals'][$key]['title']=$bookname;	
                            $bookname= str_replace(" ","",$bookname);
                            */
                            $response['NewArrivals'][$key]['ProductThumbnail'] = $thumbnail_path;
                            $response['NewArrivals'][$key]['Producturl'] = "http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/api/download/index/apicall/Bookdownload/apikey/" . $jsonObj->apikey . "/bookid/" . $Parray['product_id'] . "/bookname/" . $bookname;
                            $response['NewArrivals'][$key]['publish_time'] = $Parray['publish_time'] . " 00:00:00";
                            //code to get publisher name from user table
                            $pub_qry = 'SELECT publisher from  pclive_users where id="' . $Parray['publisher_id'] . '" order by id desc LIMIT 1';
                            $pub_result = $db->query($pub_qry);
                            $pub_record = $pub_result->FetchAll();
                            $pub_info = $pub_record[0];
                            //$response['NewArrivals'][$key]['publisher_name']=$pub_info['publisher'];
                            $response['NewArrivals'][$key]['publisher_name'] = $pub_info['publisher'];
                            $response['NewArrivals'][$key]['publisher'] = $pub_info['publisher'];
                            //code to get author name from user table
                            $author_qry = 'SELECT first_name,last_name from  pclive_users where id="' . $Parray['author_id'] . '" order by id desc LIMIT 1';
                            $author_result = $db->query($author_qry);
                            $author_record = $author_result->FetchAll();
                            $author_info = $author_record[0];
                            if ($author_info['first_name'] == "") {
                                $response['NewArrivals'][$key]['author_name'] = "";
                            } else {
                                $response['NewArrivals'][$key]['author_name'] = $author_info['first_name'] . " " . $author_info['last_name'];
                            }
                            $review_qry = 'SELECT  avg(rating*1) as rate,`productid` FROM pclive_review where productid="' . $Parray['product_id'] . '" group by productid';
                            $review_result = $db->query($review_qry);
                            $review_record = $review_result->FetchAll();
                            $review_info = $review_record[0];
                            if (count($review_record) > 0) {
                                $rs = explode(".", $review_info['rate']);
                                if ($rs[1] != '') {
                                    if ("." . $rs[1] > 0.5) {
                                        $response['NewArrivals'][$key]['rating'] = $rs[0] + 1;
                                    } else {
                                        $response['NewArrivals'][$key]['rating'] = $rs[0] + 0.5;
                                    }
                                } else {
                                    $response['NewArrivals'][$key]['rating'] = $rs[0];
                                }
                            } else {
                                $response['NewArrivals'][$key]['rating'] = 0;
                            }
                            $response['NewArrivals'][$key]['books_status'] = "Yes";
                            /*if(@in_array($Parray['id'],$array_of_books))
                            		{
                            			 $get_group_name = mysql_query("select * from pclive_company_groups where id= '".$result_user[0]['group_id']."'");
                            			 $result_group_name = mysql_fetch_array($get_group_name);
                            			 $response['Library'][$key]['is_free']="true";
                            			 $response['Library'][$key]['group_name']= $result_group_name['group_name'];
                            		}*/
                            //else
                            //{
                            //echo "<pre>";
                            //print_r($Parray);
                            $group_name = '';
                            $query_product_pub = "select parent_brand_id from pclive_products where id= '" . $Parray['id'] . "'";
                            $rs_product_pub = $db->query($query_product_pub);
                            $result_product_pub = $rs_product_pub->FetchAll();
                            if ($result_product_pub[0]['parent_brand_id'] > 0) {
                                $sql_issue = "select *,chd.subscription_type as subs_type,chd.group_id as grp_id,chd.start_date as start_date,chd.publication_id as publication_id,chd.number_of_issues,chd.number_of_downloaded,chd.remaining_downloads from  pclive_credit_history as ch,pclive_user_sub_details chd where ch.order_id=chd.order_id and publication_id='" . $result_product_pub[0]['parent_brand_id'] . "' and chd.user_id='" . $jsonObj->UserId . "' and ch.bookid='" . $Parray['product_id'] . "' and ch.payment_status='1'";
                                $rs_issue = $db->query($sql_issue);
                                $result_issue = $rs_issue->fetchAll();
                                if ($result_issue[0]['grp_id'] != 0) {
                                    $get_group_name = mysql_query("select * from pclive_company_groups where id= '" . $result_issue[0]['grp_id'] . "'");
                                    $result_group_name = mysql_fetch_array($get_group_name);
                                    $response['NewArrivals'][$key]['is_free'] = "true";
                                    $response['NewArrivals'][$key]['group_name'] = $result_group_name['group_name'];
                                    $group_name = $result_group_name['group_name'];
                                }
                                if (count($result_issue) > 0) {
                                    $response['NewArrivals'][$key]['is_free'] = "purchased";
                                    $response['NewArrivals'][$key]['group_name'] = $group_name;
                                    /*if($result_issue[0]['subs_type']>0 && $result_issue[0]['remaining_downloads']>0)
                                    		{
                                    			$start_date = explode(" ",$result_issue[0]['start_date']);
                                    			//$start_date ='2014-05-11';
                                    			$start_date = $start_date[0];
                                    			$query_subscribe_product = "select id from  pclive_products where parent_brand_id= '".$result_issue[0]['publication_id']."' and date_format(add_time,'%Y-%m-%d')>'".$start_date[0]."'";
                                    			$rs_subscribe_product = $db->query($query_subscribe_product);						
                                    			$result_subscribe_product = $rs_subscribe_product->FetchAll();
                                    			if(count($result_subscribe_product)>0 )
                                    			{
                                    				$response['NewArrivals'][$key]['is_free']="purchased";
                                    				$response['NewArrivals'][$key]['group_name']=$group_name;
                                    			}
                                    			else
                                    			{
                                    				$response['NewArrivals'][$key]['is_free']="false";
                                    				$response['NewArrivals'][$key]['group_name']=$group_name;
                                    			}
                                    		}
                                    		elseif($result_issue[0]['remaining_downloads']>0)
                                    		{
                                    			$response['NewArrivals'][$key]['is_free']="purchased";
                                    			$response['NewArrivals'][$key]['group_name']=$group_name;
                                    		}
                                    		else
                                    		{
                                    			$response['NewArrivals'][$key]['is_free']="false";
                                    			$response['NewArrivals'][$key]['group_name']=$group_name;
                                    		}	*/
                                } else {
                                    $response['NewArrivals'][$key]['is_free'] = "false";
                                    $response['NewArrivals'][$key]['group_name'] = $group_name;
                                }
                            } else {
                                //$sql_pub = "select * from pclive_credit_history";
                                //$query_pur_book = "select * from  pclive_credit_history where userid= '".$jsonObj->UserId."' and payment_status=1 and bookid= '".$Parray['product_id']."'";
                                //$rs_pur_book = $db->query($query_pur_book);
                                //$result_book= $rs_pur_book->fetchAll();
                                $query_pur_book = "select *,chd.subscription_type as subs_type,chd.group_id as grp_id,chd.start_date as start_date,chd.publication_id as publication_id,chd.number_of_issues,chd.number_of_downloaded,chd.remaining_downloads from  pclive_credit_history as ch,pclive_user_sub_details chd where ch.order_id=chd.order_id and chd.product_id='" . $Parray['product_id'] . "' and chd.user_id='" . $jsonObj->UserId . "' and ch.payment_status='1'";
                                $rs_book = $db->query($query_pur_book);
                                $result_book = $rs_book->fetchAll();
                                if (count($result_book) > 0) {
                                    if ($result_issue[0]['grp_id'] != 0) {
                                        $get_group_name = mysql_query("select * from pclive_company_groups where id= '" . $result_book[0]['grp_id'] . "'");
                                        $result_group_name = mysql_fetch_array($get_group_name);
                                        $response['NewArrivals'][$key]['is_free'] = "true";
                                        $response['NewArrivals'][$key]['group_name'] = $result_group_name['group_name'];
                                        $group_name = $result_group_name['group_name'];
                                    }
                                    $response['NewArrivals'][$key]['is_free'] = "purchased";
                                    $response['NewArrivals'][$key]['group_name'] = $group_name;
                                } else {
                                    if ($Parray['price'] == 0 || $Parray['price'] == '') {
                                        $response['NewArrivals'][$key]['is_free'] = "free";
                                        $response['NewArrivals'][$key]['group_name'] = $group_name;
                                    } else {
                                        $response['NewArrivals'][$key]['is_free'] = "false";
                                        $response['NewArrivals'][$key]['group_name'] = $group_name;
                                    }
                                }
                            }
                            //}
                            /*	if(in_array($Parray['id'],$array_of_books))
                            			{
                            				 $get_group_name = mysql_query("select * from pclive_company_groups where id= '".$result_user[0]['group_id']."'");
                            				 $result_group_name = mysql_fetch_array($get_group_name);
                            				 $response['NewArrivals'][$key]['is_free']="true";
                            				 $response['NewArrivals'][$key]['group_name']= $result_group_name['group_name'];
                            			}
                            			else
                            			{	
                            				$query_pur_book = "select * from  pclive_credit_history where userid= '".$jsonObj->UserId."' and payment_status=1 and bookid= '".$Parray['product_id']."'";
                            				$rs_pur_book = $db->query($query_pur_book);						
                            				$result_book= $rs_pur_book->FetchAll();	
                            				 if(count($result_book)>0)
                            					$response['NewArrivals'][$key]['is_free']="purchased";								
                            				else if($Parray['price']==0 || $Parray['price']=='')
                            				{						 
                            					$response['NewArrivals'][$key]['is_free']="free";
                            				}		
                            				else	
                            					$response['NewArrivals'][$key]['is_free']="false";
                            					$response['NewArrivals'][$key]['group_name']= "";
                            			}*/
                        }
                        $response['Message'] = "Success.";
                        $response['error'] = "false";
                    } else {
                        //$response = '[{"Error": {"Message":"No New Arrivals Found.","error":"true"}}]';
                        $response['Message'] = "No New Arrivals";
                        $response['error'] = "true";
                    }
                    $response = stripslashes(json_encode($response, JSON_HEX_APOS));
                    echo $response;
                    break;
                case "GetAllCategories":
                    $get_all_categories = "select * from pclive_genres where status='1' order by genre ASC";
                    $res_all_categories = $db->query($get_all_categories);
                    $data_categories = $res_all_categories->FetchAll();
                    if (count($data_categories) > 0) {
                        $response['Allcategories'] = $data_categories;
                        $response['Message'] = "Success.";
                        $response['error'] = "false";
                    } else {
                        //$response = '[{"Error": {"Message":"No Categories.","error":"true"}}]';
                        $response['Message'] = "No Categories Found.";
                        $response['error'] = "true";
                    }
                    $response = stripslashes(json_encode($response, JSON_HEX_APOS));
                    echo $response;
                    break;
                case "GetFullLibrary":
                    if ($jsonObj->UserId != '') {
                        $query_user = "******" . $jsonObj->UserId . "'";
                        $exe_user = $db->query($query_user);
                        $result_user = $exe_user->FetchAll();
                        $array_of_books = array();
                        $sql_books = "select * from pclive_group_subscriptions where company_id='" . $result_user[0]['parent_id'] . "' and group_id='" . $result_user[0]['group_id'] . "'";
                        $exe_books = mysql_query($sql_books);
                        if ($result_user[0]['group_status'] == '1') {
                            while ($result_books = mysql_fetch_array($exe_books)) {
                                $array_of_books[] = $result_books['publication_id'];
                            }
                        }
                        $implode_array_of_books = @implode(",", $array_of_books);
                    }
                    $main_array = array();
                    if (!empty($jsonObj->StoreId) && $jsonObj->StoreId > 0) {
                        $store_qry = 'SELECT is_store,is_store_status from  pclive_country where id="' . $jsonObj->StoreId . '" order by id desc LIMIT 1';
                        $store_result = $db->query($store_qry);
                        $store_record = $store_result->FetchAll();
                        $store_info = $store_record[0];
                        if ($store_info['is_store'] == 1 && $store_info['is_store_status'] == 1) {
                            $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id INNER JOIN pclive_product_images img ON prod.id=img.product_id  WHERE prod.admin_approve='1'  AND prod.file_name!=''  AND storeprice.country_id='{$jsonObj->StoreId}' ORDER BY prod.cat_id ASC";
                        } else {
                            //default nigeria
                            $sql = "SELECT prod.*,c.category_name,g.genre,storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id=storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id INNER JOIN pclive_product_images img ON prod.id=img.product_id  WHERE prod.admin_approve='1'  AND prod.file_name!=''  AND storeprice.country_id=226 ORDER BY prod.cat_id ASC";
                        }
                    } else {
                        $sql = "SELECT prod.*,c.category_name,g.genre, storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id = storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id INNER JOIN pclive_product_images img ON prod.id=img.product_id WHERE prod.admin_approve='1' AND prod.file_name!=''  ORDER BY prod.cat_id ASC";
                    }
                    $result = $db->query($sql);
                    $records = $result->FetchAll();
                    if (count($records) > 0) {
                        $response['Library'] = $records;
                        foreach ($records as $key => $Parray) {
                            $book_thumb_qry = 'SELECT * from  pclive_product_images where product_id="' . $Parray['product_id'] . '" order by id desc LIMIT 1';
                            $boothumb_result = $db->query($book_thumb_qry);
                            $book_thumb_record = $boothumb_result->FetchAll();
                            $book_thumb_info = $book_thumb_record[0];
                            if ($book_thumb_info['image_name_thumb'] != '') {
                                $thumbnail_path = $this->view->serverUrl() . $this->view->baseUrl() . "/" . USER_UPLOAD_DIR . $book_thumb_info['image_name_thumb'];
                            } else {
                                $thumbnail_path = "";
                            }
                            $bookname = str_replace(" ", "", $Parray['title']);
                            if (is_numeric($Parray['title'])) {
                                $bookbrand = "select * from pclive_brands where id='" . $Parray['title'] . "' ";
                                $bookbrand_result = $db->query($bookbrand);
                                $bookbrand_record = $bookbrand_result->FetchAll();
                                $bookbrand_info = $bookbrand_record[0];
                                $response['Library'][$key]['title'] = $bookbrand_info['brand'];
                                $bookname = str_replace(" ", "", $bookbrand_info['brand']);
                            }
                            /*	
                            $this->modelBooks = new Publisher_Model_DbTable_Books();	
                            $getBrandInfo=$this->modelBooks->getBrandInfo($Parray['title']);
                            if(!empty($getBrandInfo) && is_numeric($Parray['title']))
                            {
                            	$bookname=$getBrandInfo['brand'];
                            }else
                            {
                            	$bookname=$Parray['title'];
                            }
                            
                            if(!empty($Parray['parent_brand_id']) && $Parray['cat_id']!='3')
                            {
                            $productInfo=$this->modelBooks->fetchRow('id="'.$Parray['parent_brand_id'].'"');
                            $getParentBrandInfo=$this->modelBooks->getBrandInfo($productInfo->title);
                            	if(!empty($getParentBrandInfo))
                            	{
                            		$bookname=$getParentBrandInfo['brand'].'-'.$bookname;
                            	}
                            //$all=getPublicationIdsByCategoryName();	
                            }
                            $response['Library'][$key]['title']=$bookname;
                            $bookname= str_replace(" ","",$bookname);								
                            */
                            $retVal = array();
                            $select = 'SELECT * from pclive_country where id="' . $Parray['country_id'] . '"';
                            $country_result = $db->query($select);
                            $retVal = $country_result->FetchAll();
                            $response['Library'][$key]['country_name'] = $retVal[0]['country'];
                            //echo ">>>>>".$retVal['currency_id'];
                            $retVal1 = array();
                            $select1 = 'SELECT * from pclive_currency where currency_id="' . $retVal[0]['currency_id'] . '"';
                            $currency_result = $db->query($select1);
                            $retVal1 = $currency_result->FetchAll();
                            $response['Library'][$key]['ProductThumbnail'] = $thumbnail_path;
                            $response['Library'][$key]['Producturl'] = "http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/api/download/index/apicall/Bookdownload/apikey/" . $jsonObj->apikey . "/bookid/" . $Parray['product_id'] . "/bookname/" . $bookname;
                            $response['Library'][$key]['publish_time'] = $Parray['publish_time'] . " 00:00:00";
                            //code to get publisher name from user table
                            $pub_qry = 'SELECT publisher from  pclive_users where id="' . $Parray['publisher_id'] . '" order by id desc LIMIT 1';
                            $pub_result = $db->query($pub_qry);
                            $pub_record = $pub_result->FetchAll();
                            $pub_info = $pub_record[0];
                            //$response['Library'][$key]['publisher_name']=$pub_info['publisher'];
                            $response['Library'][$key]['publisher_name'] = $pub_info['publisher'];
                            $response['Library'][$key]['publisher'] = $pub_info['publisher'];
                            //code to get author name from user table
                            $author_qry = 'SELECT first_name,last_name from  pclive_users where id="' . $Parray['author_id'] . '" order by id desc LIMIT 1';
                            $author_result = $db->query($author_qry);
                            $author_record = $author_result->FetchAll();
                            $author_info = $author_record[0];
                            if ($author_info['first_name'] == "") {
                                $response['Library'][$key]['author_name'] = "";
                            } else {
                                $response['Library'][$key]['author_name'] = $author_info['first_name'] . " " . $author_info['last_name'];
                            }
                            // get symbol with price $retVal1[0]['currency_sign'];
                            $response['Library'][$key]['priceText'] = $retVal1[0]['currency_sign'] . " " . $response['Library'][$key]['price'];
                            $review_qry = 'SELECT  avg(rating*1) as rate,`productid` FROM pclive_review where productid="' . $Parray['product_id'] . '" group by productid';
                            $review_result = $db->query($review_qry);
                            $review_record = $review_result->FetchAll();
                            $review_info = $review_record[0];
                            if (count($review_record) > 0) {
                                $rs = explode(".", $review_info['rate']);
                                if ($rs[1] != '') {
                                    if ("." . $rs[1] > 0.5) {
                                        $response['Library'][$key]['rating'] = $rs[0] + 1;
                                    } else {
                                        $response['Library'][$key]['rating'] = $rs[0] + 0.5;
                                    }
                                } else {
                                    $response['Library'][$key]['rating'] = $rs[0];
                                }
                            } else {
                                $response['Library'][$key]['rating'] = 0;
                            }
                            $response['Library'][$key]['books_status'] = "Yes";
                            /*if(@in_array($Parray['id'],$array_of_books))
                            		{
                            			 $get_group_name = mysql_query("select * from pclive_company_groups where id= '".$result_user[0]['group_id']."'");
                            			 $result_group_name = mysql_fetch_array($get_group_name);
                            			 $response['Library'][$key]['is_free']="true";
                            			 $response['Library'][$key]['group_name']= $result_group_name['group_name'];
                            		}*/
                            //else
                            //{
                            //echo "<pre>";
                            //print_r($Parray);
                            $group_name = '';
                            $query_product_pub = "select parent_brand_id from pclive_products where id= '" . $Parray['id'] . "'";
                            $rs_product_pub = $db->query($query_product_pub);
                            $result_product_pub = $rs_product_pub->FetchAll();
                            if ($result_product_pub[0]['parent_brand_id'] > 0) {
                                $sql_issue = "select *,chd.subscription_type as subs_type,chd.group_id as grp_id,chd.start_date as start_date,chd.publication_id as publication_id,chd.number_of_issues,chd.number_of_downloaded,chd.remaining_downloads from  pclive_credit_history as ch,pclive_user_sub_details chd where ch.order_id=chd.order_id and publication_id='" . $result_product_pub[0]['parent_brand_id'] . "' and chd.user_id='" . $jsonObj->UserId . "' and ch.bookid='" . $Parray['product_id'] . "' and ch.payment_status='1'";
                                $rs_issue = $db->query($sql_issue);
                                $result_issue = $rs_issue->fetchAll();
                                if ($result_issue[0]['grp_id'] != 0) {
                                    $get_group_name = mysql_query("select * from pclive_company_groups where id= '" . $result_issue[0]['grp_id'] . "'");
                                    $result_group_name = mysql_fetch_array($get_group_name);
                                    $response['Library'][$key]['is_free'] = "true";
                                    $response['Library'][$key]['group_name'] = $result_group_name['group_name'];
                                    $group_name = $result_group_name['group_name'];
                                }
                                if (count($result_issue) > 0) {
                                    $response['Library'][$key]['is_free'] = "purchased";
                                    $response['Library'][$key]['group_name'] = $group_name;
                                    /*if($result_issue[0]['subs_type']>0 && $result_issue[0]['remaining_downloads']>0)
                                    		{
                                    			$start_date = explode(" ",$result_issue[0]['start_date']);
                                    			//$start_date ='2014-05-11';
                                    			$start_date = $start_date[0];
                                    			$query_subscribe_product = "select id from  pclive_products where parent_brand_id= '".$result_issue[0]['publication_id']."' and date_format(add_time,'%Y-%m-%d')>'".$start_date[0]."'";
                                    			$rs_subscribe_product = $db->query($query_subscribe_product);						
                                    			$result_subscribe_product = $rs_subscribe_product->FetchAll();
                                    			if(count($result_subscribe_product)>0 )
                                    			{
                                    				$response['Library'][$key]['is_free']="purchased";
                                    				$response['Library'][$key]['group_name']=$group_name;
                                    			}
                                    			else
                                    			{
                                    				$response['Library'][$key]['is_free']="false";
                                    				$response['Library'][$key]['group_name']=$group_name;
                                    			}
                                    		}
                                    		elseif($result_issue[0]['remaining_downloads']>0)
                                    		{
                                    			$response['Library'][$key]['is_free']="purchased";
                                    			$response['Library'][$key]['group_name']=$group_name;
                                    		}
                                    		else
                                    		{
                                    			$response['Library'][$key]['is_free']="false";
                                    			$response['Library'][$key]['group_name']=$group_name;
                                    		}	*/
                                } else {
                                    $response['Library'][$key]['is_free'] = "false";
                                    $response['Library'][$key]['group_name'] = $group_name;
                                }
                            } else {
                                //$sql_pub = "select * from pclive_credit_history";
                                //$query_pur_book = "select * from  pclive_credit_history where userid= '".$jsonObj->UserId."' and payment_status=1 and bookid= '".$Parray['product_id']."'";
                                //$rs_pur_book = $db->query($query_pur_book);
                                //$result_book= $rs_pur_book->fetchAll();
                                $query_pur_book = "select *,chd.subscription_type as subs_type,chd.group_id as grp_id,chd.start_date as start_date,chd.publication_id as publication_id,chd.number_of_issues,chd.number_of_downloaded,chd.remaining_downloads from  pclive_credit_history as ch,pclive_user_sub_details chd where ch.order_id=chd.order_id and chd.product_id='" . $Parray['product_id'] . "' and chd.user_id='" . $jsonObj->UserId . "' and ch.bookid='" . $Parray['product_id'] . "' and ch.payment_status='1'";
                                $rs_book = $db->query($query_pur_book);
                                $result_book = $rs_book->fetchAll();
                                if (count($result_book) > 0) {
                                    if ($result_issue[0]['grp_id'] != 0) {
                                        $get_group_name = mysql_query("select * from pclive_company_groups where id= '" . $result_book[0]['grp_id'] . "'");
                                        $result_group_name = mysql_fetch_array($get_group_name);
                                        $response['Library'][$key]['is_free'] = "true";
                                        $response['Library'][$key]['group_name'] = $result_group_name['group_name'];
                                        $group_name = $result_group_name['group_name'];
                                    }
                                    $response['Library'][$key]['is_free'] = "purchased";
                                    $response['Library'][$key]['group_name'] = $group_name;
                                } else {
                                    if ($Parray['price'] == 0 || $Parray['price'] == '') {
                                        $response['Library'][$key]['is_free'] = "free";
                                        $response['Library'][$key]['group_name'] = $group_name;
                                    } else {
                                        $response['Library'][$key]['is_free'] = "false";
                                        $response['Library'][$key]['group_name'] = $group_name;
                                    }
                                }
                            }
                            //}
                        }
                        $response['Message'] = "Success.";
                        $response['error'] = "false";
                    } else {
                        $response = '[{"Error": {"Message":"No New Arrivals Found.","error":"true"}}]';
                        $response['Message'] = "No Books in library.";
                        $response['error'] = "true";
                    }
                    ///echo "<pre>";
                    //	print_r($response);
                    //	exit;
                    $response = json_encode($response, JSON_HEX_APOS);
                    echo $response;
                    break;
                case "GetFullStoreLibrary":
                    if ($jsonObj->UserId != '') {
                        $query_user = "******" . $jsonObj->UserId . "'";
                        $exe_user = $db->query($query_user);
                        $result_user = $exe_user->FetchAll();
                        $array_of_books = array();
                        $sql_books = "select * from pclive_group_subscriptions where company_id='" . $result_user[0]['parent_id'] . "' and group_id='" . $result_user[0]['group_id'] . "'";
                        $exe_books = mysql_query($sql_books);
                        while ($result_books = mysql_fetch_array($exe_books)) {
                            $array_of_books[] = $result_books['publication_id'];
                        }
                        $implode_array_of_books = @implode(",", $array_of_books);
                    }
                    $main_array = array();
                    if (!empty($jsonObj->Keyword)) {
                        $sql = "SELECT prod.*,c.category_name,g.genre, storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id = storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id INNER JOIN pclive_product_images img ON prod.id=img.product_id WHERE prod.admin_approve='1' AND prod.file_name!='' and (prod.title like '%{$jsonObj->Keyword}%' or prod.description like '%{$jsonObj->Keyword}%')  ORDER BY prod.cat_id ASC";
                    } else {
                        $sql = "SELECT prod.*,c.category_name,g.genre, storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id = storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id INNER JOIN pclive_product_images img ON prod.id=img.product_id WHERE prod.admin_approve='1' AND prod.file_name!=''  ORDER BY prod.cat_id ASC";
                    }
                    $result = $db->query($sql);
                    $records = $result->FetchAll();
                    if (count($records) > 0) {
                        $response['Library'] = $records;
                        foreach ($records as $key => $Parray) {
                            $retVal = array();
                            $select = 'SELECT * from pclive_country where id="' . $Parray['country_id'] . '"';
                            $country_result = $db->query($select);
                            $retVal = $country_result->FetchAll();
                            $response['Library'][$key]['country_name'] = $retVal[0]['country'];
                            //echo ">>>>>".$retVal['currency_id'];
                            $retVal1 = array();
                            $select1 = 'SELECT * from pclive_currency where currency_id="' . $retVal[0]['currency_id'] . '"';
                            $currency_result = $db->query($select1);
                            $retVal1 = $currency_result->FetchAll();
                            // get symbol with price $retVal1[0]['currency_sign'];
                            $response['Library'][$key]['priceText'] = $retVal1[0]['currency_sign'] . " " . $response['Library'][$key]['price'];
                            //$response['Library'][$key]['price']=$response['Library'][$key]['price'];
                            $book_thumb_qry = 'SELECT * from  pclive_product_images where product_id="' . $Parray['product_id'] . '" order by id desc LIMIT 1';
                            $boothumb_result = $db->query($book_thumb_qry);
                            $book_thumb_record = $boothumb_result->FetchAll();
                            $book_thumb_info = $book_thumb_record[0];
                            if ($book_thumb_info['image_name_thumb'] != '') {
                                $thumbnail_path = $this->view->serverUrl() . $this->view->baseUrl() . "/" . USER_UPLOAD_DIR . $book_thumb_info['image_name_thumb'];
                            } else {
                                $thumbnail_path = "";
                            }
                            $bookname = str_replace(" ", "", $Parray['title']);
                            if (is_numeric($Parray['title'])) {
                                $bookbrand = "select * from pclive_brands where id='" . $Parray['title'] . "' ";
                                $bookbrand_result = $db->query($bookbrand);
                                $bookbrand_record = $bookbrand_result->FetchAll();
                                $bookbrand_info = $bookbrand_record[0];
                                $response['Library'][$key]['title'] = $bookbrand_info['brand'];
                                $bookname = str_replace(" ", "", $bookbrand_info['brand']);
                            }
                            /*	
                            	
                            $this->modelBooks = new Publisher_Model_DbTable_Books();	
                            $getBrandInfo=$this->modelBooks->getBrandInfo($Parray['title']);
                            if(!empty($getBrandInfo) && is_numeric($Parray['title']))
                            {
                            	$bookname=$getBrandInfo['brand'];
                            }else
                            {
                            	$bookname=$Parray['title'];
                            }
                            
                            if(!empty($Parray['parent_brand_id']) && $Parray['cat_id']!='3')
                            {
                            $productInfo=$this->modelBooks->fetchRow('id="'.$Parray['parent_brand_id'].'"');
                            $getParentBrandInfo=$this->modelBooks->getBrandInfo($productInfo->title);
                            	if(!empty($getParentBrandInfo))
                            	{
                            		$bookname=$getParentBrandInfo['brand'].'-'.$bookname;
                            	}
                            //$all=getPublicationIdsByCategoryName();	
                            }
                            $response['Library'][$key]['title']=$bookname;	
                            $bookname= str_replace(" ","",$bookname);
                            */
                            $response['Library'][$key]['ProductThumbnail'] = $thumbnail_path;
                            $response['Library'][$key]['Producturl'] = "http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/api/download/index/apicall/Bookdownload/apikey/" . $jsonObj->apikey . "/bookid/" . $Parray['product_id'] . "/bookname/" . $bookname;
                            $response['Library'][$key]['publish_time'] = $Parray['publish_time'] . " 00:00:00";
                            //code to get publisher name from user table
                            $pub_qry = 'SELECT publisher from  pclive_users where id="' . $Parray['publisher_id'] . '" order by id desc LIMIT 1';
                            $pub_result = $db->query($pub_qry);
                            $pub_record = $pub_result->FetchAll();
                            $pub_info = $pub_record[0];
                            $response['Library'][$key]['publisher_name'] = $pub_info['publisher'];
                            //code to get author name from user table
                            $author_qry = 'SELECT first_name,last_name from  pclive_users where id="' . $Parray['author_id'] . '" order by id desc LIMIT 1';
                            $author_result = $db->query($author_qry);
                            $author_record = $author_result->FetchAll();
                            $author_info = $author_record[0];
                            if ($author_info['first_name'] == "") {
                                $response['Library'][$key]['author_name'] = "";
                            } else {
                                $response['Library'][$key]['author_name'] = $author_info['first_name'] . " " . $author_info['last_name'];
                            }
                            $review_qry = 'SELECT  avg(rating*1) as rate,`productid` FROM pclive_review where productid="' . $Parray['product_id'] . '" group by productid';
                            $review_result = $db->query($review_qry);
                            $review_record = $review_result->FetchAll();
                            $review_info = $review_record[0];
                            if (count($review_record) > 0) {
                                $rs = explode(".", $review_info['rate']);
                                if ($rs[1] != '') {
                                    if ("." . $rs[1] > 0.5) {
                                        $response['Library'][$key]['rating'] = $rs[0] + 1;
                                    } else {
                                        $response['Library'][$key]['rating'] = $rs[0] + 0.5;
                                    }
                                } else {
                                    $response['Library'][$key]['rating'] = $rs[0];
                                }
                            } else {
                                $response['Library'][$key]['rating'] = 0;
                            }
                            $response['Library'][0]['books_status'] = 'Yes';
                            /*if(@in_array($Parray['id'],$array_of_books))
                            		{
                            			 $get_group_name = mysql_query("select * from pclive_company_groups where id= '".$result_user[0]['group_id']."'");
                            			 $result_group_name = mysql_fetch_array($get_group_name);
                            			 $response['Library'][$key]['is_free']="true";
                            			 $response['Library'][$key]['group_name']= $result_group_name['group_name'];
                            		}*/
                            //else
                            //{
                            //echo "<pre>";
                            //print_r($Parray);
                            $group_name = '';
                            $query_product_pub = "select parent_brand_id from pclive_products where id= '" . $Parray['id'] . "'";
                            $rs_product_pub = $db->query($query_product_pub);
                            $result_product_pub = $rs_product_pub->FetchAll();
                            if ($result_product_pub[0]['parent_brand_id'] > 0) {
                                $sql_issue = "select *,chd.subscription_type as subs_type,chd.group_id as grp_id,chd.start_date as start_date,chd.publication_id as publication_id,chd.number_of_issues,chd.number_of_downloaded,chd.remaining_downloads from  pclive_credit_history as ch,pclive_user_sub_details chd where ch.order_id=chd.order_id and publication_id='" . $result_product_pub[0]['parent_brand_id'] . "' and chd.user_id='" . $jsonObj->UserId . "' and ch.bookid='" . $Parray['product_id'] . "' and ch.payment_status='1'";
                                $rs_issue = $db->query($sql_issue);
                                $result_issue = $rs_issue->fetchAll();
                                if ($result_issue[0]['grp_id'] != 0) {
                                    $get_group_name = mysql_query("select * from pclive_company_groups where id= '" . $result_issue[0]['grp_id'] . "'");
                                    $result_group_name = mysql_fetch_array($get_group_name);
                                    $response['Library'][$key]['is_free'] = "true";
                                    $response['Library'][$key]['group_name'] = $result_group_name['group_name'];
                                    $group_name = $result_group_name['group_name'];
                                }
                                if (count($result_issue) > 0) {
                                    $response['Library'][$key]['is_free'] = "purchased";
                                    $response['Library'][$key]['group_name'] = $group_name;
                                    /*if($result_issue[0]['subs_type']>0 && $result_issue[0]['remaining_downloads']>0)
                                    		{
                                    			$start_date = explode(" ",$result_issue[0]['start_date']);
                                    			//$start_date ='2014-05-11';
                                    			$start_date = $start_date[0];
                                    			$query_subscribe_product = "select id from  pclive_products where parent_brand_id= '".$result_issue[0]['publication_id']."' and date_format(add_time,'%Y-%m-%d')>'".$start_date[0]."'";
                                    			$rs_subscribe_product = $db->query($query_subscribe_product);						
                                    			$result_subscribe_product = $rs_subscribe_product->FetchAll();
                                    			if(count($result_subscribe_product)>0 )
                                    			{
                                    				$response['Library'][$key]['is_free']="purchased";
                                    				$response['Library'][$key]['group_name']=$group_name;
                                    			}
                                    			else
                                    			{
                                    				$response['Library'][$key]['is_free']="false";
                                    				$response['Library'][$key]['group_name']=$group_name;
                                    			}
                                    		}
                                    		elseif($result_issue[0]['remaining_downloads']>0)
                                    		{
                                    			$response['Library'][$key]['is_free']="purchased";
                                    			$response['Library'][$key]['group_name']=$group_name;
                                    		}
                                    		else
                                    		{
                                    			$response['Library'][$key]['is_free']="false";
                                    			$response['Library'][$key]['group_name']=$group_name;
                                    		}	*/
                                } else {
                                    $response['Library'][$key]['is_free'] = "false";
                                    $response['Library'][$key]['group_name'] = $group_name;
                                }
                            } else {
                                //$sql_pub = "select * from pclive_credit_history";
                                //	$query_pur_book = "select * from  pclive_credit_history where userid= '".$jsonObj->UserId."' and payment_status=1 and bookid= '".$Parray['product_id']."'";
                                //$rs_pur_book = $db->query($query_pur_book);
                                //	$result_book= $rs_pur_book->fetchAll();
                                $query_pur_book = "select *,chd.subscription_type as subs_type,chd.group_id as grp_id,chd.start_date as start_date,chd.publication_id as publication_id,chd.number_of_issues,chd.number_of_downloaded,chd.remaining_downloads from  pclive_credit_history as ch,pclive_user_sub_details chd where ch.order_id=chd.order_id and chd.product_id='" . $Parray['product_id'] . "' and chd.user_id='" . $jsonObj->UserId . "' and ch.bookid='" . $Parray['product_id'] . "' and ch.payment_status='1'";
                                $rs_book = $db->query($query_pur_book);
                                $result_book = $rs_book->fetchAll();
                                if (count($result_book) > 0) {
                                    if ($result_issue[0]['grp_id'] != 0) {
                                        $get_group_name = mysql_query("select * from pclive_company_groups where id= '" . $result_book[0]['grp_id'] . "'");
                                        $result_group_name = mysql_fetch_array($get_group_name);
                                        $response['Library'][$key]['is_free'] = "true";
                                        $response['Library'][$key]['group_name'] = $result_group_name['group_name'];
                                        $group_name = $result_group_name['group_name'];
                                    }
                                    $response['Library'][$key]['is_free'] = "purchased";
                                    $response['Library'][$key]['group_name'] = $group_name;
                                } else {
                                    if ($Parray['price'] == 0 || $Parray['price'] == '') {
                                        $response['Library'][$key]['is_free'] = "free";
                                        $response['Library'][$key]['group_name'] = $group_name;
                                    } else {
                                        $response['Library'][$key]['is_free'] = "false";
                                        $response['Library'][$key]['group_name'] = $group_name;
                                    }
                                }
                            }
                            //}
                        }
                        $response['Message'] = "Success.";
                        $response['error'] = "false";
                    } else {
                        $response = '[{"Error": {"Message":"No New Arrivals Found.","error":"true"}}]';
                        $response['Message'] = "No Books in library.";
                        $response['error'] = "true";
                        $response['Library'][0]['books_status'] = 'No';
                    }
                    ///echo "<pre>";
                    //	print_r($response);
                    //	exit;
                    $response = json_encode($response, JSON_HEX_APOS);
                    echo $response;
                    break;
                case "GetFreeLibrary":
                    if ($jsonObj->UserId != '') {
                        $query_user = "******" . $jsonObj->UserId . "' and parent_id!=0 and group_id!=0 and group_status='1'";
                        $exe_user = $db->query($query_user);
                        $result_user = $exe_user->FetchAll();
                        if (count($result_user) > 0) {
                            $query_group_name = "select * from pclive_companies where id = '" . $jsonObj->UserId . "' and parent_id!=0 and group_id!=0";
                            $exe_group = $db->query($query_group_name);
                            $result_group = $exe_group->FetchAll();
                            // Get group name from group id
                            $get_group_name = mysql_query("select * from pclive_company_groups where id= '" . $result_group[0]['group_id'] . "'");
                            $result_group_name = mysql_fetch_array($get_group_name);
                            $query_free_book = "select bookid from  pclive_credit_history where userid = '" . $result_user[0]['parent_id'] . "' and payment_status=1 and group_id='" . $result_group[0]['group_id'] . "'";
                            $exe_free_book = $db->query($query_free_book);
                            $result_book = $exe_free_book->FetchAll();
                            $book_id_arr = array();
                            foreach ($result_book as $key1 => $book) {
                                $book_id_arr[] = $book['bookid'];
                            }
                            $bookstr = implode(",", $book_id_arr);
                            if (count($result_book) > 0) {
                                $main_array = array();
                                $sql = "SELECT prod.*,c.category_name,g.genre, storeprice.product_id, storeprice.country_id, storeprice.language_id, storeprice.price FROM pclive_products as prod INNER JOIN pclive_product_prices as storeprice ON prod.id = storeprice.product_id INNER JOIN pclive_categories c on c.id=prod.cat_id INNER JOIN pclive_genres g on prod.product_type=g.id INNER JOIN pclive_product_images img ON prod.id=img.product_id WHERE prod.admin_approve='1' AND prod.file_name!='' and prod.id in({$bookstr})  ORDER BY prod.cat_id ASC";
                                $result = $db->query($sql);
                                $records = $result->FetchAll();
                                if (count($records) > 0) {
                                    $response['groupBooks'] = $records;
                                    foreach ($records as $key => $Parray) {
                                        $retVal = array();
                                        $select = 'SELECT * from pclive_country where id="' . $Parray['country_id'] . '"';
                                        $country_result = $db->query($select);
                                        $retVal = $country_result->FetchAll();
                                        $response['groupBooks'][$key]['country_name'] = $retVal[0]['country'];
                                        //echo ">>>>>".$retVal['currency_id'];
                                        $retVal1 = array();
                                        $select1 = 'SELECT * from pclive_currency where currency_id="' . $retVal[0]['currency_id'] . '"';
                                        $currency_result = $db->query($select1);
                                        $retVal1 = $currency_result->FetchAll();
                                        // get symbol with price $retVal1[0]['currency_sign'];
                                        $response['groupBooks'][$key]['priceText'] = $retVal1[0]['currency_sign'] . " " . $response['groupBooks'][$key]['price'];
                                        $book_thumb_qry = 'SELECT * from  pclive_product_images where product_id="' . $Parray['product_id'] . '" order by id desc LIMIT 1';
                                        $boothumb_result = $db->query($book_thumb_qry);
                                        $book_thumb_record = $boothumb_result->FetchAll();
                                        $book_thumb_info = $book_thumb_record[0];
                                        if ($book_thumb_info['image_name_thumb'] != '') {
                                            $thumbnail_path = $this->view->serverUrl() . $this->view->baseUrl() . "/" . USER_UPLOAD_DIR . $book_thumb_info['image_name_thumb'];
                                        } else {
                                            $thumbnail_path = "";
                                        }
                                        $bookname = str_replace(" ", "", $Parray['title']);
                                        if (is_numeric($Parray['title'])) {
                                            $bookbrand = "select * from pclive_brands where id='" . $Parray['title'] . "' ";
                                            $bookbrand_result = $db->query($bookbrand);
                                            $bookbrand_record = $bookbrand_result->FetchAll();
                                            $bookbrand_info = $bookbrand_record[0];
                                            $response['groupBooks'][$key]['title'] = $bookbrand_info['brand'];
                                            $bookname = str_replace(" ", "", $bookbrand_info['brand']);
                                        }
                                        /*	
                                        $this->modelBooks = new Publisher_Model_DbTable_Books();	
                                        $getBrandInfo=$this->modelBooks->getBrandInfo($Parray['title']);
                                        if(!empty($getBrandInfo) && is_numeric($Parray['title']))
                                        {
                                        	$bookname=$getBrandInfo['brand'];
                                        }else
                                        {
                                        	$bookname=$Parray['title'];
                                        }
                                        
                                        if(!empty($Parray['parent_brand_id']) && $Parray['cat_id']!='3')
                                        {
                                        $productInfo=$this->modelBooks->fetchRow('id="'.$Parray['parent_brand_id'].'"');
                                        $getParentBrandInfo=$this->modelBooks->getBrandInfo($productInfo->title);
                                        	if(!empty($getParentBrandInfo))
                                        	{
                                        		$bookname=$getParentBrandInfo['brand'].'-'.$bookname;
                                        	}
                                        //$all=getPublicationIdsByCategoryName();	
                                        }
                                        $response['groupBooks'][$key]['title']=$bookname;	
                                        $bookname= str_replace(" ","",$bookname);
                                        */
                                        $response['groupBooks'][$key]['ProductThumbnail'] = $thumbnail_path;
                                        $response['groupBooks'][$key]['Producturl'] = "http://miprojects2.com.php53-6.ord1-1.websitetestlink.com/projects/evendor/api/download/index/apicall/Bookdownload/apikey/" . $jsonObj->apikey . "/bookid/" . $Parray['product_id'] . "/bookname/" . $bookname;
                                        $response['groupBooks'][$key]['publish_time'] = $Parray['publish_time'] . " 00:00:00";
                                        //code to get publisher name from user table
                                        $pub_qry = 'SELECT publisher from  pclive_users where id="' . $Parray['publisher_id'] . '" order by id desc LIMIT 1';
                                        $pub_result = $db->query($pub_qry);
                                        $pub_record = $pub_result->FetchAll();
                                        $pub_info = $pub_record[0];
                                        //$response['groupBooks'][$key]['publisher_name']=$pub_info['publisher'];
                                        //$response['groupBooks'][$key]['publisher_name']=$pub_info['first_name']." ".$pub_info['last_name'];
                                        //$response['groupBooks'][$key]['publisher']=$pub_info['first_name']." ".$pub_info['last_name'];
                                        $response['groupBooks'][$key]['publisher_name'] = $pub_info['publisher'];
                                        $response['groupBooks'][$key]['publisher'] = $pub_info['publisher'];
                                        //code to get author name from user table
                                        $author_qry = 'SELECT first_name,last_name from  pclive_users where id="' . $Parray['author_id'] . '" order by id desc LIMIT 1';
                                        $author_result = $db->query($author_qry);
                                        $author_record = $author_result->FetchAll();
                                        $author_info = $author_record[0];
                                        if ($author_info['first_name'] == "") {
                                            $response['groupBooks'][$key]['author_name'] = "";
                                        } else {
                                            $response['groupBooks'][$key]['author_name'] = $author_info['first_name'] . " " . $author_info['last_name'];
                                        }
                                        $review_qry = 'SELECT  avg(rating*1) as rate,`productid` FROM pclive_review where productid="' . $Parray['product_id'] . '" group by productid';
                                        $review_result = $db->query($review_qry);
                                        $review_record = $review_result->FetchAll();
                                        $review_info = $review_record[0];
                                        if (count($review_record) > 0) {
                                            $rs = explode(".", $review_info['rate']);
                                            if ($rs[1] != '') {
                                                if ("." . $rs[1] > 0.5) {
                                                    $response['groupBooks'][$key]['rating'] = $rs[0] + 1;
                                                } else {
                                                    $response['groupBooks'][$key]['rating'] = $rs[0] + 0.5;
                                                }
                                            } else {
                                                $response['groupBooks'][$key]['rating'] = $rs[0];
                                            }
                                        } else {
                                            $response['groupBooks'][$key]['rating'] = 0;
                                        }
                                        $response['groupBooks'][$key]['books_status'] = "Yes";
                                        $get_group_name = mysql_query("select * from pclive_company_groups where id= '" . $result_user[0]['group_id'] . "'");
                                        $result_group_name = mysql_fetch_array($get_group_name);
                                        $response['groupBooks'][$key]['is_free'] = "true";
                                        $response['groupBooks'][$key]['group_name'] = $result_group_name['group_name'];
                                    }
                                    $response['Message'] = "Success.";
                                    $response['error'] = "false";
                                }
                            } else {
                                $response['Message'] = "No group publication is subscribed for you.";
                                $response['error'] = "true";
                            }
                        } else {
                            $response['Message'] = "You are not a group user.";
                            $response['error'] = "true";
                        }
                    } else {
                        //$response = '[{"Error": {"Message":"No New Arrivals Found.","error":"true"}}]';
                        $response['Message'] = "User Id does not exist.";
                        $response['error'] = "true";
                    }
                    $response = stripslashes(json_encode($response, JSON_HEX_APOS));
                    echo $response;
                    break;
                case "purchasedBooks":
                    $query_pur_book = "select * from  pclive_credit_history where userid= '" . $jsonObj->userid . "' and payment_status=1 and bookid= '" . $jsonObj->bookid . "'";
                    $rs_pur_book = $db->query($query_pur_book);
                    $result_book = $rs_pur_book->FetchAll();
                    if (count($result_book) > 0) {
                        echo '{"Message":"success", "error":"false"}';
                    } else {
                        echo '{"Message":"You have to purchase from website", "error":"true"}';
                    }
                    break;
                case "pushNotification":
                    //$idreg="APA91bG-BjQAinY8ZzhFn0_3OT9CpO1_1vuWVStZsOiiX-Lj8gNCEchp-sUw77zFAWzV-KvGKAKk_IfvkixA1DyQ8jcc7iTKOlFv5a_Wa_htmsQqAXxfAgn1fsgaa-dtjHCiL2jA69JzyLMQDlMg6ndBvKvuxnMDCo07R6AnPpv13DvC8DY6a7E";
                    //$idreg="APA91bE3oteFpKRBhLyKlpa4OplH6-4lzpw47iSa8bSZzGlsgm8_YBoVEEhUpSjAvvIj-9jn1FmG2RgVIKpbOILKYddGBCP217XcO1wiN6APbxOicR87ISc2pdPDRpj40LAUvohR7m1ppkDjGoJsiKIEDNOJ68UAmA";
                    $idreg = "APA91bErTCy2Ubl6otSCoad0I4_gA6gYPdDDN_8c4cVGFPPKXRfIculGJMhNiT1zhyg8f_BQsjaTNYHSd1NtxwH0qh2NZVwwUu8LpiC102VlKkowsLgpXTAqCXMrru0zVs7cP5unwy5kBChXM6a9IpEDn1zI8AOouw";
                    //$idreg="APA91bErTCy2Ubl6otSCoad0I4_gA6gYPdDDN_8c4cVGFPPKXRfIculGJMhNiT1zhyg8f_BQsjaTNYHSd1NtxwH0qh2NZVwwUu8LpiC102VlKkowsLgpXTAqCXMrru0zVs7cP5unwy5kBChXM6a9IpEDn1zI8AOouw";
                    $regID = array($idreg);
                    // $message="You have registerted successfully";
                    $message = array("userID" => '7236');
                    $this->send_push_notification($regID, $message);
                    echo "PushNotification testing";
                    break;
                default:
                    echo "Sorry! Invalid Method Call";
            }
        } else {
            echo "Invalid Request Format";
        }
        exit;
    }
示例#5
0
    public function createAction()
    {
        $this->view->messages = $this->_flashMessenger->getMessages();
        $this->_helper->layout->disableLayout();
        $formData = array();
        $formErrors = array();
        $formData = $this->getRequest()->getPost();
        //print_r($formData);exit;
        if ($this->getRequest()->isPost() && isset($formData['create_member']) && $formData['create_member'] == 'Create') {
            if (!isset($formData['group_id']) || empty($formData['group_id'])) {
                $formErrors['group_id'] = "Please select a group";
            }
            if (!isset($formData['first_name']) || trim($formData['first_name']) == "") {
                $formErrors['first_name'] = "Please enter first name";
            }
            if (!isset($formData['last_name']) || trim($formData['last_name']) == "") {
                $formErrors['last_name'] = "Please enter last name";
            }
            if (!isset($formData['user_email']) || trim($formData['user_email']) == "") {
                $formErrors['user_email'] = "Please enter email";
            }
            if (!isset($formData['user_password']) || trim($formData['user_password']) == "") {
                $formErrors['user_password'] = "******";
            }
            if (!CommonFunctions::isValidEmail($formData['user_email'])) {
                if (!array_key_exists('user_email', $formErrors)) {
                    $formErrors['user_email'] = "Please enter valid email";
                }
            }
            /*if($this->modelCompany->isExist('username="******"'))
            		{
            			if(!(array_key_exists('username',$formErrors)))
            			{
            				$formErrors['username']="******";
            			}
            		}
            		*/
            if ($this->modelCompany->isExistCompany('user_email="' . $formData['user_email'] . '" and (account_type="1" or account_type="3")') || $this->modelPublisher->isExist('emailid="' . $formData['user_email'] . '"')) {
                if (!array_key_exists('user_email', $formErrors)) {
                    $formErrors['user_email'] = "Email already exist for company or member of company or publisher";
                }
            }
            if ($this->modelCompany->isExist('user_email="' . $formData['user_email'] . '" and (parent_id!="0" or group_id!="0")')) {
                if (!array_key_exists('user_email', $formErrors)) {
                    $formErrors['user_email'] = "Email already member of a group.";
                }
            }
            if (count($formErrors) == 0) {
                if ($this->getRequest()->isPost()) {
                    $groupName = $this->modelGroup->getInfoByGroupId($formData['group_id']);
                    ########################## get user who are not publisher,company and member of other company ######################
                    $memberData = $this->modelCompany->getNonMemberUser($formData['user_email']);
                    if (count($memberData) > 0) {
                        //$groupName = $this->modelGroup->getInfoByGroupId($formData['group_id']);
                        $activationCode = CommonFunctions::generateGUID();
                        $add_time = date('Y-m-d H:i:s');
                        $formData['user_password'] = empty($formData['user_password']) ? CommonFunctions::getRandomNumberPassword(8) : $formData['user_password'];
                        $formData['company_id'] = !empty($this->sessCompanyInfo->id) ? $this->sessCompanyInfo->id : 0;
                        $MemberUserData = array('parent_id' => $formData['company_id'], 'group_varify_id' => $formData['group_id'], 'user_email' => $formData['user_email'], 'account_type' => 3, 'status' => '1', 'updated_date' => date("Y-m-d H:i:s"), 'activation_code' => $activationCode, 'added_date' => $add_time);
                        $group_id = $formData['group_id'];
                        $lastId = $this->modelCompany->update($MemberUserData, "id='" . $memberData[0]['id'] . "'");
                        if ($memberData[0]['id'] != '') {
                            $mailhost = SMTP_SERVER;
                            $mailconfig = array('ssl' => SMTP_SSL, 'port' => SMTP_PORT, 'auth' => SMTP_AUTH, 'username' => SMTP_USERNAME, 'password' => SMTP_PASSWORD);
                            $transport = new Zend_Mail_Transport_Smtp($mailhost, $mailconfig);
                            Zend_Mail::setDefaultTransport($transport);
                            $varification_url = $this->view->serverUrl() . $this->view->baseUrl() . '/user/register/groupverification/code/' . $activationCode . '/id/' . $group_id;
                            $message = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
								<html xmlns="http://www.w3.org/1999/xhtml">
								<head>
								<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
								<title>Electronic Vendor Ltd</title>
								<style type="text/css">
								body{
								margin:0;
								padding:0px;
								}
								#container{
								width:700px;
								margin:0 auto;
								}
								#header{
								width:700px;
								float:left;
								padding:40px 0 10px 0;
								font-family:Arial, Helvetica, sans-serif;
								color:#3A3B3F;
								text-align:center;
								font-size:11px;
								
								}
								#header a{
								color:#3A3B3F;
								font-weight:bold;
								text-decoration:none;
								}
								#header a:hover{
								color:#40BBE3;
								}
								#logopart
								{
								border:0px solid red;
								width:698px;
								height:140px;
								background-color:#1B75BB;
								margin-left:0px;
								}
								#content{
								width:698px;
								float:left;
								padding:0px 0px 10px 0px;
								font-family:Arial, Helvetica, sans-serif;
								color:#3A3B3F;
								border:1px solid #D6D6D6;
								font-size:12px;
								}
								#content p{
								margin:0px 20px;
								padding:0px 0 20px 0;
								font-family:Arial, Helvetica, sans-serif;
								font-size:12px;
								color:#3A3B3F;
								}
								#content p.logo{
								margin:0px;
								padding:15px 0 0 20px;
								height:77px
								}
								#content p.title{
								margin:0px;
								font-size:20px;
								font-family:Arial, Helvetica, sans-serif;
								border-bottom:3px solid #D6D6D6;
								padding:0px 0 13px 0;
								margin:25px 20px 14px 20px;
								color:#3A3B3F;
								}
								#content p a{
								color:#40BBE3;
								text-decoration:none;
								}
								#content p a:hover{
								color:#3A3B3F;
								text-decoration:underline;
								}
								#content h2{
								margin:0px;
								padding:0 0 14px 0;
								font-size:14px;
								font-family:Arial, Helvetica, sans-serif;
								font-weight:bold;
								}
								#footer{
								width:700px;
								float:left;
								}
								#footer p{
								margin:0 0 0 0;
								padding:0 0 0 0;
								font-family:Arial, Helvetica, sans-serif;
								font-size:11px;
								color:#78797E;
								}
								#footer p.disclamer{
								margin: 0 0 0 0;
								padding:16px 6px 10px 6px;
								text-align: justify;
								border-bottom:1px solid #3A3B3F;
								color:#78797E;
								}
								#footer p.notice{
								margin: 0 0 15px 0;
								padding:16px 6px 10px 6px;
								text-align: justify;
								color:#78797E;
								}
								</style>
								</head>
								<body>
								
								<div id="container">
								<div id="header"></div>
								<div id="content">
								
								<div id="logopart">
								<p class="logo"><a href="' . SVN_URL . '" target="_blank">
								Electronic Vendor Ltd
								</a></p>
								</div>
								<p class="title">To be active member of this "' . $groupName['group_name'] . '" group click below link.</p>
								<BR />
								<p style="color:#ffffff;"><a href="' . $varification_url . '">Group Activation Link</a></p>
								<br>
								<p class="title">Membership of a ' . $groupName['group_name'] . ' group email</p>
								<p>Congrats you are member of a ' . $groupName['group_name'] . ' group :</p>							
								<BR />
								<p>&nbsp;</p>
								
								</div>
								<div id="footer">&nbsp;</div>
								</div>
								</body>
								</html>';
                            $mail = new Zend_Mail();
                            $mail->addTo($formData['user_email']);
                            $mail->setSubject("Membership of a " . $groupName['group_name'] . " group email.");
                            $mail->setBodyHtml($message);
                            $mail->setFrom(SETFROM, SETNAME);
                            if ($mail->send()) {
                                $this->_flashMessenger->addMessage('<div class="div-success">Individual member is updated to member of this group.User Name and password will remain same of the user.</div>');
                            } else {
                                $this->view->errorMessage = '<div class="div-error">Mail could not be sent. Try again later.</div>';
                            }
                            $this->_redirect('company/member/');
                        }
                    } else {
                        $activationCode = CommonFunctions::generateGUID();
                        $add_time = date('Y-m-d H:i:s');
                        $formData['user_password'] = empty($formData['user_password']) ? CommonFunctions::getRandomNumberPassword(8) : $formData['user_password'];
                        $formData['company_id'] = !empty($this->sessCompanyInfo->id) ? $this->sessCompanyInfo->id : 0;
                        $username_array = explode("@", $formData['user_email']);
                        $formData['user_name'] = $username_array[0];
                        $MemberUserData = array('parent_id' => $formData['company_id'], 'group_id' => $formData['group_id'], 'user_email' => $formData['user_email'], 'user_password' => md5($formData['user_password']), 'user_name' => $formData['user_name'], 'first_name' => $formData['first_name'], 'account_type' => 3, 'last_name' => $formData['last_name'], 'status' => '0', 'updated_date' => date("Y-m-d H:i:s"), 'activation_code' => $activationCode, 'added_date' => $add_time);
                        $lastId = $this->modelCompany->insert($MemberUserData);
                        if ($lastId > 0) {
                            $mailhost = SMTP_SERVER;
                            $mailconfig = array('ssl' => SMTP_SSL, 'port' => SMTP_PORT, 'auth' => SMTP_AUTH, 'username' => SMTP_USERNAME, 'password' => SMTP_PASSWORD);
                            $transport = new Zend_Mail_Transport_Smtp($mailhost, $mailconfig);
                            Zend_Mail::setDefaultTransport($transport);
                            $message = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
							<html xmlns="http://www.w3.org/1999/xhtml">
							<head>
							<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
							<title>Electronic Vendor Ltd</title>
							<style type="text/css">
							body{
							margin:0;
							padding:0px;
							}
							#container{
							width:700px;
							margin:0 auto;
							}
							#header{
							width:700px;
							float:left;
							padding:40px 0 10px 0;
							font-family:Arial, Helvetica, sans-serif;
							color:#3A3B3F;
							text-align:center;
							font-size:11px;
							
							}
							#header a{
							color:#3A3B3F;
							font-weight:bold;
							text-decoration:none;
							}
							#header a:hover{
							color:#40BBE3;
							}
							#logopart
							{
							border:0px solid red;
							width:698px;
							height:140px;
							background-color:#1B75BB;
							margin-left:0px;
							}
							#content{
							width:698px;
							float:left;
							padding:0px 0px 10px 0px;
							font-family:Arial, Helvetica, sans-serif;
							color:#3A3B3F;
							border:1px solid #D6D6D6;
							font-size:12px;
							}
							#content p{
							margin:0px 20px;
							padding:0px 0 20px 0;
							font-family:Arial, Helvetica, sans-serif;
							font-size:12px;
							color:#3A3B3F;
							}
							#content p.logo{
							margin:0px;
							padding:15px 0 0 20px;
							height:77px
							}
							#content p.title{
							margin:0px;
							font-size:20px;
							font-family:Arial, Helvetica, sans-serif;
							border-bottom:3px solid #D6D6D6;
							padding:0px 0 13px 0;
							margin:25px 20px 14px 20px;
							color:#3A3B3F;
							}
							#content p a{
							color:#40BBE3;
							text-decoration:none;
							}
							#content p a:hover{
							color:#3A3B3F;
							text-decoration:underline;
							}
							#content h2{
							margin:0px;
							padding:0 0 14px 0;
							font-size:14px;
							font-family:Arial, Helvetica, sans-serif;
							font-weight:bold;
							}
							#footer{
							width:700px;
							float:left;
							}
							#footer p{
							margin:0 0 0 0;
							padding:0 0 0 0;
							font-family:Arial, Helvetica, sans-serif;
							font-size:11px;
							color:#78797E;
							}
							#footer p.disclamer{
							margin: 0 0 0 0;
							padding:16px 6px 10px 6px;
							text-align: justify;
							border-bottom:1px solid #3A3B3F;
							color:#78797E;
							}
							#footer p.notice{
							margin: 0 0 15px 0;
							padding:16px 6px 10px 6px;
							text-align: justify;
							color:#78797E;
							}
							</style>
							</head>
							<body>
							
							<div id="container">
							<div id="header"></div>
							<div id="content">
							
							<div id="logopart">
							<p class="logo"><a href="' . SVN_URL . '" target="_blank">
							Electronic Vendor Ltd
							</a></p>
							</div>
							<BR />
							<p style="color:#ffffff;">Activate your account by using given below link :</p>
							<BR />
							<br>
							<p class="title">To activate your membership of ' . $groupName['group_name'] . ' and active member of this group please click below link.</p>
							<p style="color:#ffffff;"><a href="' . $this->view->serverUrl() . $this->view->baseUrl() . '/user/register/verificationwithgroup/' . $activationCode . '">Account Activation Link</a></p>
							<br>
							<p class="title">After activating your account login with following information.</p>
							<p>Your login details given below :</p>
							<p>Username:&nbsp;' . $formData['user_email'] . '</p>
							<p>Password:&nbsp;' . $formData['user_password'] . '</p>
							<p>Password:&nbsp;' . $groupName['group_name'] . '</p>
							<BR />
							<p>&nbsp;</p>
							</div>
							<div id="footer">&nbsp;</div>
							</div>
							</body>
							</html>';
                            $mail = new Zend_Mail();
                            $mail->addTo($formData['user_email']);
                            $mail->setSubject("Member Registration Email");
                            $mail->setBodyHtml($message);
                            $mail->setFrom(SETFROM, SETNAME);
                            if ($mail->send()) {
                                $this->_flashMessenger->addMessage('<div class="div-success">Member created successfully</div>');
                            } else {
                                $this->view->errorMessage = '<div class="div-error">Mail could not be sent. Try again later.</div>';
                            }
                            $this->_redirect('company/member/');
                        }
                    }
                }
            } else {
                //$this->view->errorMessage = '<div class="div-error">Please enter required fields properly.</div>';
                //$this->_redirect('company/member/');
            }
        } else {
            $formData['first_name'] = "";
            $formData['last_name'] = "";
            $formData['user_email'] = "";
            $formData['user_password'] = "";
        }
        $this->view->formData = $formData;
        $this->view->formErrors = $formErrors;
        $sessionMsg = new Zend_Session_Namespace('step1Msg');
        $sessionMsg->formData = $formData;
        $sessionMsg->formErrors = $formErrors;
        $sessionMsg->errorMessage = $this->view->errorMessage;
        $this->_redirect('company/member/');
    }
 public function indexAction()
 {
     $this->view->messages = $this->_flashMessenger->getMessages();
     $formData = array();
     $formErrors = array();
     if ($this->getRequest()->isPost()) {
         $formData = $this->getRequest()->getPost();
         //print_r($formData);exit;
         //=====================START FORM VALIDATION===================================
         if (!isset($formData['first_name']) || trim($formData['first_name']) == "") {
             $formErrors['first_name'] = "Please enter your first name";
         }
         if (!isset($formData['last_name']) || trim($formData['last_name']) == "") {
             $formErrors['last_name'] = "Please enter your last name";
         }
         if (!isset($formData['user_name']) || trim($formData['user_name']) == "") {
             $formErrors['user_name'] = "Please enter user name";
         }
         if (!isset($formData['user_email']) || trim($formData['user_email']) == "") {
             $formErrors['user_email'] = "Please enter your email";
         }
         if (!isset($formData['user_password']) || trim($formData['user_password']) == "") {
             $formErrors['user_password'] = "******";
         }
         if (!isset($formData['user_password']) || trim($formData['user_password']) == "") {
             $formErrors['user_password'] = "******";
         }
         if (!isset($formData['verify_user_password']) || trim($formData['verify_user_password']) == "") {
             $formErrors['verify_user_password'] = "******";
         }
         if (!isset($formData['agree']) || trim($formData['agree']) == "") {
             $formErrors['agree'] = "Please check agree";
         }
         if ($formData['user_password'] != $formData['verify_user_password']) {
             $formErrors['verify_user_password'] = "******";
         }
         if (!CommonFunctions::isValidEmail($formData['user_email'])) {
             if (!array_key_exists('user_email', $formErrors)) {
                 $formErrors['user_email'] = "Please enter valid email";
             }
         }
         if ($this->modelCandidates->isExist('user_name="' . $formData['user_name'] . '"')) {
             if (!array_key_exists('user_name', $formErrors)) {
                 $formErrors['user_name'] = "Username already exist";
             }
         }
         if ($this->modelCandidates->isExist('user_email="' . $formData['user_email'] . '"')) {
             if (!array_key_exists('user_email', $formErrors)) {
                 $formErrors['user_email'] = "Email already exist";
             }
         }
         //=====================END FORM VALIDATION===================================
         if (count($formErrors) == 0) {
             //======inserting data to the candidate table===============
             $activationCode = CommonFunctions::generateGUID();
             $activationStartTime = strtotime(date('Y-m-d H:i:s'));
             $activationExpireTime = strtotime(date('Y-m-d H:i:s', strtotime("+1 days")));
             //echo "TIME::::".$activationStartTime."====TIME 2:::".strtotime(date('Y-m-d H:i:s'))."===EXPIRE TIME:::".$activationExpireTime;exit;
             $candidateData = array('user_name' => $formData['user_name'], 'user_email' => $formData['user_email'], 'user_password' => $formData['user_password'], 'added_date' => date("Y-m-d H:i:s"), 'updated_date' => date("Y-m-d H:i:s"), 'status' => 0, 'activation_code' => $activationCode, 'activation_start_time' => $activationStartTime, 'activation_expire_time' => $activationExpireTime);
             $lastId = $this->modelCandidates->insert($candidateData);
             if ($lastId) {
                 //======inserting data to the candidate profile table===============
                 $agree = isset($formData['agree']) && $formData['agree'] != "" ? 1 : 0;
                 $signup_newsletter = isset($formData['signup_newsletter']) && $formData['signup_newsletter'] != "" ? 1 : 0;
                 $notify_jobs = isset($formData['notify_jobs']) && $formData['notify_jobs'] != "" ? 1 : 0;
                 $profileData = array('user_id' => $lastId, 'first_name' => $formData['first_name'], 'last_name' => $formData['last_name'], 'agree' => $agree, 'signup_newsletter' => $signup_newsletter, 'notify_jobs' => $notify_jobs, 'added_date' => date("Y-m-d H:i:s"), 'updated_date' => date("Y-m-d H:i:s"));
                 $this->modelCandidateProfiles->insert($profileData);
                 $sessionPost = new Zend_Session_Namespace('step1Post');
                 $sessionPost->user_id = $lastId;
                 $this->_redirect('user/register/step2');
             } else {
                 $this->view->errorMessage = '<div class="div-error">Sorry, unable to register, please try later.</div>';
             }
         } else {
             $this->view->errorMessage = '<div class="div-error">Please enter email required field to register.</div>';
         }
     }
     $this->view->formData = $formData;
     $this->view->formErrors = $formErrors;
 }
 public function step2Action()
 {
     $this->view->messages = $this->_flashMessenger->getMessages();
     $sessionPost = new Zend_Session_Namespace('step1Post');
     if (isset($sessionPost) && $sessionPost != null && isset($sessionPost->formData) && count($sessionPost->formData) > 0) {
         //print_r($sessionPost->formData);
         $step1formData = $sessionPost->formData;
         $formData = array();
         $formErrors = array();
         $formData['business_name'] = $step1formData['business_name'];
         if ($this->getRequest()->isPost()) {
             $formData = $this->getRequest()->getPost();
             //print_r($formData);exit;
             //=====================START FORM VALIDATION===================================
             if (!isset($formData['business_name']) || trim($formData['business_name']) == "") {
                 $formErrors['business_name'] = "Please enter your business name";
             }
             //=====================END FORM VALIDATION===================================
             if (count($formErrors) == 0) {
                 //======inserting data to the candidate table===============
                 $activationCode = CommonFunctions::generateGUID();
                 $activationStartTime = strtotime(date('Y-m-d H:i:s'));
                 $activationExpireTime = strtotime(date('Y-m-d H:i:s', strtotime("+1 days")));
                 //echo "TIME::::".$activationStartTime."====TIME 2:::".strtotime(date('Y-m-d H:i:s'))."===EXPIRE TIME:::".$activationExpireTime;exit;
                 $compData = array('user_name' => $step1formData['user_name'], 'user_email' => $step1formData['user_email'], 'user_password' => $step1formData['user_password'], 'added_date' => date("Y-m-d H:i:s"), 'updated_date' => date("Y-m-d H:i:s"), 'status' => 1, 'activation_code' => $activationCode, 'activation_start_time' => $activationStartTime, 'activation_expire_time' => $activationExpireTime);
                 $lastId = $this->modelCompany->insert($compData);
                 if ($lastId) {
                     //========unset the session for step1 form data====
                     Zend_Session::namespaceUnset('step1Post');
                     //=================================================
                     //======inserting data to the company profile table===============
                     $agree = isset($step1formData['agree']) && $step1formData['agree'] != "" ? 1 : 0;
                     $signup_newsletter = isset($step1formData['signup_newsletter']) && $step1formData['signup_newsletter'] != "" ? 1 : 0;
                     $notify_jobs = isset($step1formData['notify_jobs']) && $step1formData['notify_jobs'] != "" ? 1 : 0;
                     $profileData = array('company_id' => $lastId, 'business_name' => $formData['business_name'], 'contact_name' => $step1formData['contact_name'], 'post_code' => $formData['post_code'], 'state' => $formData['state'], 'industry_1' => $formData['industry_1'], 'industry_2' => $formData['industry_2'], 'about_us' => $formData['about_us'], 'opening_hours' => $formData['opening_hours'], 'telephone' => $formData['telephone'], 'website' => $formData['website'], 'abn' => $formData['abn'], 'acn' => $formData['acn'], 'facebook_url' => $formData['facebook_url'], 'twitter_url' => $formData['twitter_url'], 'shifte_url' => $formData['shifte_url'], 'agree' => $agree, 'signup_newsletter' => $signup_newsletter, 'notify_jobs' => $notify_jobs, 'added_date' => date("Y-m-d H:i:s"), 'updated_date' => date("Y-m-d H:i:s"));
                     $profileId = $this->modelCompanyProfiles->insert($profileData);
                     if ($profileId > 0) {
                         /**** Uploading Logo File on Server*****/
                         $upload = new Zend_File_Transfer_Adapter_Http();
                         $upload->setDestination(COMPANY_UPLOAD_DIR);
                         $files = $upload->getFileInfo();
                         if (isset($files) && count($files) > 0) {
                             $i = 1;
                             foreach ($files as $file => $info) {
                                 if ($info['name'] != "") {
                                     if ($upload->isValid($file)) {
                                         try {
                                             // upload received file(s)
                                             $upload->receive($file);
                                         } catch (Zend_File_Transfer_Exception $e) {
                                             //echo $e->getMessage();//exit;
                                         }
                                         // so, Finally lets See the Data that we received on Form Submit
                                         $name = $upload->getFileName($file);
                                         $size = $upload->getFileSize($file);
                                         # Returns the mimetype for the '$file' form element
                                         $mimeType = $upload->getMimeType($file);
                                         $renameFile = time() . $i . '.jpg';
                                         $fullFilePath = COMPANY_UPLOAD_DIR . $renameFile;
                                         //Rename uploaded file using Zend Framework
                                         $filterFileRename = new Zend_Filter_File_Rename(array('target' => $fullFilePath, 'overwrite' => true));
                                         $filterFileRename->filter($name);
                                         $logoData = array('logo' => $renameFile);
                                         $this->modelCompanyProfiles->update($logoData, 'id=' . $profileId);
                                     }
                                 }
                                 $i++;
                             }
                         }
                         /*****End Uploading************/
                     }
                     $this->_redirect('company/register/thanks');
                 } else {
                     $this->view->errorMessage = '<div class="div-error">Please enter required fieild to register.</div>';
                 }
             } else {
                 $this->view->errorMessage = '<div class="div-error">Sorry, unable to register, please try later.</div>';
             }
         }
         $this->view->formData = $formData;
         $this->view->formErrors = $formErrors;
         $this->view->industryList = $this->modelIndustries->fetchAll('status=1');
     } else {
         $this->_flashMessenger->addMessage('<div class="div-error">Please enter required fieild to register.</div>');
         $this->_redirect('company/register/');
     }
 }