Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

<?php
if (!defined('BASEPATH'))
        exit('No direct script access allowed');


/*
 * Model for home
 */ 

 
Class Oauth_model extends CI_Model {

        var $url = '';
        var $parser_model;
        var $parser;
        var $current_client;

        function __construct() {
                
                // Call the Model constructor
                parent::__construct();
                //load appropriate parser
                $current_client =$this -> config -> item('current_client');
                $model = $current_client.'_model';
                $this->load->model($model);
                $this->parser = $this-> $model;
                $this->current_client=$this -> config -> item('current_client');
                
                
        }

        
        function getLogin($get=array(),$post=array(),$module=array())
        {
        
                $output =array();
                if(isset($module) and !empty($module))
                {
                        if(isset($module['header']) and !empty($module['header']))
                        {
                                foreach($module['header'] as $header)
                                {

                                        $this->curlURL($header,'get');
                                }
                        }
                        if(isset($module['footer']) and !empty($module['footer']))
                        {
                                foreach($module['footer'] as $footer)
                                {
                                        $this->curlURL($footer,'get');
                                }
                        }
                        if(isset($module['response']) and !empty($module['response']))
                        {
                                foreach($module['response'] as $response)
                                {
                                        if(isset($post) and !empty($post))
                                        {
                                                if($this->current_client=='prestashop' || $this->current_client=='magento' )
                                                $this->curlURL($response,'post',$post);
                                        else
                                                $this->curlURL($response,'post',$post);

                                        }
                                }
                        }

                        
                }
                
                //add_call( KEY, METHOD, URL, array of PARAMS, array of CURL_OPTS )
                //$this->curlURL('products','get',$get);
                $responses = $this->mcurl->execute();
                 //die();
                if(isset($responses) and !empty($responses))
                $responses = $this->parser->parse_response($responses,$module);
        
                
                return $responses;
        }
        function getSignup($get=array(),$post=array(),$module=array())
        {
                $prestaresponse ='';
                
                $output =array();
                if(isset($module) and !empty($module))
                {
                        if(isset($module['header']) and !empty($module['header']))
                        {
                                foreach($module['header'] as $header)
                                {

                                        $this->curlURL($header,'get');
                                }
                        }
                        if(isset($module['footer']) and !empty($module['footer']))
                        {
                                foreach($module['footer'] as $footer)
                                {
                                        $this->curlURL($footer,'get');
                                }
                        }
                        if(isset($module['response']) and !empty($module['response']))
                        {
                                foreach($module['response'] as $response)
                                {
                                        if(isset($post) and !empty($post))
                                        {
                                                if($this->current_client=='prestashop' || $this->current_client=='magento' )
                                                $this->curlURL($response,'post',$post);
                                        else
                                                $this->curlURL($response,'post',$post);

                                        }
                                }
                        }

                        
                }
                
                //add_call( KEY, METHOD, URL, array of PARAMS, array of CURL_OPTS )
                //$this->curlURL('products','get',$get);
                $responses = $this->mcurl->execute();
                if(isset($prestaresponse) and !empty($prestaresponse))
                        {$responses=array_merge($responses,$prestaresponse);}
                if(isset($responses) and !empty($responses))
                $responses = $this->parser->parse_response($responses,$module);
        
                
                return $responses;
        }
function curlURL($configurl=null,$methodtype='get',$parameter=array())
{

                $params ='';
                $display='';
                $url = $this->config->item('curl_base_url');
                $productsurl =$this->config->item($configurl);
                if(isset($productsurl['url']) and !empty($productsurl['url']))
                        {
                                $url .=$productsurl['url'];
                                if($productsurl['display'])
                                {$display=$productsurl['display'];}
                        if(empty($parameter)){$parameter=$productsurl['params'];}
                        

                if(isset($parameter) and !empty($parameter) and $methodtype=='get')
                {
                        $params = $this->parser->prepareParams($parameter,$display,$configurl);

                }
                if(isset($parameter) and !empty($parameter) and $methodtype=='post')
                {
                        $params = $this->parser->prepareParams($parameter,$display,$configurl);
                        $methodtype ='post';
                }
                if(!isset($parameter) || empty($parameter))
                        {$params =$this->parser->prepareParams('',$display,$configurl);}
                //$methodtype = 'post';
                return $this->mcurl->add_call($configurl,$methodtype,$url,$params);
        }
        else
                {return '';}

}
function __addPrestaCurl($response,$post,$resource)
{
        $outputresponse =array();
        $outputresponse['method']='post';
        $errors=array();

        if(isset($post) and !empty($post))
        {
                $data =$post;
        }
        

//error_reporting(E_ALL);
//ini_set('display_errors', '1');

// Here we use the WebService to get the schema of "customers" resource
try
{
   
    $opt = array('resource' => $resource);
    $url =$this->config->item('curl_base_url').$resource;
   $xml = $this->prestashopwebservice->get(array('url' => $url.'?schema=blank'));
   $resources = $xml->children()->children();
    //print_r($resources);
   $outputresponse['url']=$url;
   $outputresponse['params']='';



}
catch (PrestaShopWebserviceException $e)
{
    // Here we are dealing with errors
    $trace = $e->getTrace();
    if ($trace[0]['args'][0] == 404) $errors[]= 'Bad ID';
    else if ($trace[0]['args'][0] == 401) $errors[]= 'Bad auth key';
    else $errors[]= 'Other error';
}

if (count($data) > 0)
{
        //print_r($data);
// Here we have XML before update, lets update XML
    foreach ($resources as $nodeKey => $node)
    {
        
        $resources->$nodeKey = @$data[$nodeKey];

    }
    try
    {
        $opt = array('resource' => 'customers');
       
            $opt['postXml'] = $xml->asXML();
           
            $xml = $this->prestashopwebservice->add($opt);

             $outputresponse['response']=$xml;
            
       
    }
    catch (PrestaShopWebserviceException $ex)
    {
        // Here we are dealing with errors
        $trace = $ex->getTrace();
        if ($trace[0]['args'][0] == 404) $errors[]= 'Bad ID';
        else if ($trace[0]['args'][0] == 401) $errors[]= 'Bad auth key';
        else $errors[]= 'Other error<br />'.$ex->getMessage();
    }
}

return array($response=>$outputresponse,'errors'=>$errors);
}

}