<?php
class IndexController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
        /* DO NOT REMEMBER HOW TO USE THIS
        $ajaxContext = $this->_helper->getHelper('AjaxContext');
        $ajaxContext->addActionContext('jsonstatusupdate', 'html')
                    ->initContext();
        */

    }

    public function indexAction()
    {
        // action body
    }
    /**
     * An action for testing actions!
     */
    public function testAction() {
        /* test code */

    }
     /**
     * An action for testing Widgets!
     */
    public function testwidgetAction() {
        /* test code */
        $this->view->addHelperPath('Zend/Dojo/View/Helper', 'Zend_Dojo_View_Helper');
    }

	    public function	presencepanetestAction() {
        /* test code */
        $this->view->addHelperPath('Zend/Dojo/View/Helper', 'Zend_Dojo_View_Helper');
    }
	
    public function jsonstatusupdateAction() {


        /* Check if this is a real AJAX request, else
         * just output nothing.
         */
        if (!$this->_request->isXmlHttpRequest()) {
            return  $this->_helper->redirector->gotoSimple(
                    array('controller' => 'index',
                          'action'     => 'index'));
        }


        /* Set the view to a generic json sending view we created.
         * Notice that in future there may be a method to directly
         * set this for dojo+json output.
         * For autocompletition there is already one indeed, cause dojo
         * needs some compatibility flags enabled (and maybe some
         * meta/header) set. */
        $this->_helper->viewRenderer('json');

        $reply = array(
            "status" => "present"
        );
        $this->view->json = Zend_Json::encode($reply);
 
/* Other way to send json, in dojo style format
        $data = new Zend_Dojo_Data();
        $data->setIdentifier('imgid')->addItems($imagelist);
        $this->view->json = $data;
 */
    }
        public function jsonchangestatusAction() {

         // This URL must is intented to be authenticated, so reachable only
         // by authernticated users.


        /* Check if this is a real AJAX request, else
         * just output nothing.
         */

        if (!$this->_request->isXmlHttpRequest()) {
            return  $this->_helper->redirector->gotoSimple(
                    array('controller' => 'index',
                          'action'     => 'index'));
        }


        /* Set the view to a generic json sending view we created.
         * Notice that in future there may be a method to directly
         * set this for dojo+json output.
         * For autocompletition there is already one indeed, cause dojo
         * needs some compatibility flags enabled (and maybe some
         * meta/header) set. */
        $this->_helper->viewRenderer('json');
        if("enter" == $this->getRequest()->getParam('request')) {
            $replystatus = "present";
        } else if("leave" == $this->getRequest()->getParam('request')){
            $replystatus = "absent";
        } else {
            // This is just to show that an error status is supported
            // and will trigger error on the other side
            $replystatus = "error";
        }
        $reply = array(
            "status" => $replystatus
        );
        $this->view->json = Zend_Json::encode($reply);

/* Other way to send json, in dojo style format
        $data = new Zend_Dojo_Data();
        $data->setIdentifier('imgid')->addItems($imagelist);
        $this->view->json = $data;
 */
    }
}

