<?php

class Ambient_Routee_IndexController extends Mage_Core_Controller_Front_Action {

//    public function IndexAction() {
//        $this->loadLayout();
//        $this->getLayout()->getBlock("head")->setTitle($this->__("Titlename"));
//        $breadcrumbs = $this->getLayout()->getBlock("breadcrumbs");
//        $breadcrumbs->addCrumb("home", array(
//            "label" => $this->__("Home Page"),
//            "title" => $this->__("Home Page"),
//            "link" => Mage::getBaseUrl()
//        ));
//        $breadcrumbs->addCrumb("titlename", array(
//            "label" => $this->__("Titlename"),
//            "title" => $this->__("Titlename")
//        ));
//        $this->renderLayout();
//    }

    public function IndexAction() {
        $uuid = Mage::getStoreConfig('routeesection/routeegroup/routee_mmid');
        
        //customer add
        $event = "CustomerAdd";

        $reqdata = array();
        $customerreq = array();
        $addressreq = array();

        $customerreq['id'] = "1";
        $customerreq['firstname'] = "testfname";
        $customerreq['lastname'] = "testlname";
        $customerreq['birthday'] = "11/11/1987";
        $customerreq['email'] = "testambient123@gmail.com";
        $customerreq['phone'] = "0123456789";

        $addressreq['country'] = "India";
        $addressreq['city'] = "Jaipur";
        $addressreq['address1'] = "test address";
        $addressreq['postcode'] = "123456";
        $addressreq['company'] = "test company";

        $reqdata['customer'] = $customerreq;
        $reqdata['addresses'] = $addressreq;

        $eventdata = array();
        $eventdata['data'] = $reqdata;
        $eventdata['uuid'] = $uuid;
        $eventdata['event'] = $event;

        $customerdata = Mage::helper('core')->jsonEncode($eventdata);

        $url = "https://idata.routee.net/api/event";

        $c = curl_init();
        curl_setopt($c, CURLOPT_URL, $url);
        curl_setopt($c, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
        curl_setopt($c, CURLOPT_POST, true);
        curl_setopt($c, CURLOPT_POSTFIELDS, $customerdata);
        curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($c, CURLOPT_TIMEOUT, 30);

        $response = curl_exec($c);
        $curlInfo = curl_getinfo($c);
        curl_close($c);

        echo "<pre>";
        print_r($response);
        print_r($curlInfo);
    }

}
