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

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

class savejson
{
                    
	function __construct($parent)
	{
        //GET PAGE MESSAGE
		$this->page_data=globalfunc::getMessage($parent,$parent->lang,'user');		 
        $this->saveFunc($parent);
		$parent->response(array('response'=>'failed', 'message' => 'PAGE NOT FOUND'), 404);
	}
	private function isJson($string)
    {
        json_decode($string);
        return (json_last_error() == JSON_ERROR_NONE);
    }
	/* /////////////////////////////// USER SIGNUP //////////////////////////////////////////////// */
	private function saveFunc($parent)
    {	
		globalfunc::checkMethodType($parent,array('POST'));		 
		globalfunc::checkParamCount($parent,0);
		$REQUEST_KEYS=array('data'=>'string');
		globalfunc::mandatoryKey($parent,$REQUEST_KEYS);
        
        $data=$parent->_request['data'];
        //print_r($data);
        if(!($data!='' && $this->isJson($data))) $parent->response(array('response'=>'failed', 'message' => 'INVALID JSON'), 406);
         
        $insert_str = "INSERT INTO ".TABLE_LEAD."(`lead_json`,  `created_on`) VALUES ( '".escape_str($data)."', '".NOW."')";
        $parent->executeQuery($insert_str);
        
        $parent->response(array('response'=>'success',  'message'=>$this->page_data['success1']),200);
    }
            
}

?>