<?php
/**
 * Manually Developed CI Controller
 *
 *
 * @package			AIR\controllers\AppIntegrator
 * @version			V1.2.0
 * @copyright		2015, BizyCorp Internal Systems Development
 * @license			private, All rights reserved
 * @author			MRM Roshan <roshan@ekwa.com>
 * 
 */
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
@session_start();
/**
 * Manually Developed CI Controller
 *
 * This controller facilitates the access of table countries
 *  
 * Usage:-
 *  
 *			 function index() 
 *			 function AppIntegrator_wb()
 *			 function key_validate(), Validates key entries 
 *			 function delete()			 
 *			 function createDropdown()
 *			 function is_name_uniqe(), Checks uniqness of a given name
 *			 function edit(), Prepares edit form for a given record 
 *			 function save(), Saves add/edit form data
 *			 function addForm(), Prepares add form to add new record
 *			 function replace_para_maccro(), Replaces parameter maccro values with values
 *   		 function crosscheck_uaacs_functions(), Crossches with supplied function ids and user ids
 *   		 function prepare_xml_feed_functions(), Prepares functions obtaind from xml feed
 *   		 function prepare_function_paras(), Prepares function pars obtaind from xml feed
 *   		 function prepare_qstring_builder(), Prepares querystring builder popup 
 * 
 *
 * @package			AIR\controllers\AppIntegrator
 * @version			V1.2.0
 * @copyright		2015, BizyCorp Internal Systems Development
 * @license			private, All rights reserved
 * @author			MRM Roshan
 * @created			July 2014  
 * @uses			
 * @see 
 * @modified		
 * @modification	
 */
class AppIntegrator extends CI_Controller{

	/**
	 * $debug 
	 * 
	 * @var boolien
	 */
	var $debug = true;
	/**
	 * $log_obj
	 * 
	 * @var obj
	 */
	private $log_obj;

  	/**
   	* Function Abstract __construct
   	*
   	*
   	* This constructer function checks for user session and loads the relevant models
   	*
   	* @param   None
   	* @return  void
   	* @access  public 
   	*/
	function __construct()	{
	
		parent::__construct();    
    	$this->load->model('AppIntegrator_model');
    
    	if(!isset($_SESSION['user_name'])){
    		echo "<center>Session expired! Please reload the page to login</center>";
    		exit;
    	} 	
    	$this->log_obj = new log_object();
    	$this->log_obj->set_userDetails(
    			$_SESSION['air_user_name'],
    			$_SESSION["air_user_type"]);
    	//if access log file path need to set to other folder
    	$this->log_obj->set_path('./application/logs/access');   	    	
	}//end function
	
	

	/**
	 * index() method
	 * 
	 * This is the main function that produce the AIR listings output using various view formats passed as params.	  
	 * 
	 * @param bool search 	Indicates if the URL consist of a SEARCH string for	data filteration
	 * 						TRUE  -	A user specified data filteration string is	provided as a SEARCH string
	 * 						FALSE -	No user specified data filtering is required
	 * 						DEFAULT VALUE -	FALSE
	 * @param int limit   	No of records to be feched from the selected data set
	 * 						DEFAULT VALUE -	0 = all records
	 * @param int offset  	Starting possition of the record set to be feched
	 * 						DEFAULT VALUE -	0 - from first record
	 * @param str file    	Name of the view to be used
	 * 						DEFAULT VALUR - pb_ms_gridfeed - HTML or XML fromated gid output
	 * @param str format  	Format of the output to be produced by the view
	 * 						VALUES	  -	'HTML' | 'XML' (Passthrough param to view)
     * @access public	 
     * @return array data feed for grid
	 */
	function index($search=FALSE,$limit=0,$offset=0,$file='appIntegrator_grid_index',$format='xml'){
		
		$this->debug = false;
					
		//if($this->debug) $this->output->enable_profiler(TRUE);
		
            if($search==true){ 
            	
                $searchobj_array = array();   
                           
                foreach((count($_POST)>0?$_POST:$_GET) as $key => $val){ 
                     $search_text=$val; //search text 

                     $pos = strrpos($key, '_'); 

                     $query_method = substr($key,$pos+1);  
  
                     $field= substr($key, 0, $pos);

                     //if filed has '.'
                     $field = str_replace('/','.',$field);

                     log_message('info',"field set of varialbe \$field in index():- $field");

                     //$search_obj= (objct) array('search_field' => $field, 'search_text' => $search_text,'query_method'=>$query_method);
                     $search_obj= array(
                     		'search_field' => $field, 
                     		'search_text' => $search_text,
                     		'query_method'=>$query_method);
                     
                     array_push($searchobj_array, $search_obj);  
                }                
                   $data['dataset'] = $this->AppIntegrator_model->get_data(array(
                   												'search'=>$searchobj_array,
                   												'limit' => $limit,
                   												'offset'=>$offset,
                   												'order_by'=>array('ar_applications.integration_id'=>'Asc')));
            }else {
                   $data['dataset'] = $this->AppIntegrator_model->get_data(array(
                   										'limit' => $limit,
                   										'offset'=>$offset,
                   										'order_by'=>array('ar_applications.integration_id'=>'Asc')));
            }   
       
            
            $wrapped_data['data'] = $data;
            $wrapped_data['format'] = $format;
            $wrapped_data['searchOn'] = $search;
            log_message('info','variable values of \$wrapped_data in index():-'.serialize($wrapped_data));
            
            //create access log
            $this->log_obj->set_otherDetails(
            		array(
            				'Mode'=>'Index function accessed',            				
            				'Data'=> ' Search: '.$search.'- limit:'.$limit.'- offset: '.$offset.' - view file:'.$file.' - Format:'.$format));
            $this->log_obj->init();
            
            $this->load->view($file,$wrapped_data);
	}//end of function
      
	

	/**
	 * AppIntegrator_wb()
	 *
	 * This method will call AIR work bench file for data listing and processing		 
	 *
	 * Send to view - $data array with template id
	 */	
	 public function AppIntegrator_wb(){
	
		$data['msg'] = '';
		$this->load->view('ai_wb',$data);
	
	}//end of function pb_wb();
	
	
	/**
	 * is_name_uniqe($id,$name)
	 * 
	 * This method checks for uniqeness of a given linkage name 
	 * 
	 * @param int $id
	 * @param string $name
	 */	
	public function is_name_uniqe($id,$name){
				
		$name = urldecode($name);		
		$searchobj_array[] = array(
				'search_field' => 'intergration_name',
				'search_text' => $name,
				'query_method'=>'equal');
		
		$dataset = $this->AppIntegrator_model->get_data(array(
				'search'=>$searchobj_array,
				'limit' => 10,
				'offset'=>0,
				'order_by'=>array('ar_applications.integration_id'=>'Asc')));
		
		if(count($dataset['result_set']) > 0 ){
			if(count($dataset['result_set']) == 1){
				if( $dataset['result_set'][1]['integration_id'] == $id){
						echo 1;
				}else{
					echo 0;
				}
			}else{
				echo 0;
			}
		}else{
			echo 1;
		}
		
	}//end of function 
	
	
	/**
	 * Function  edit ()
	 *
	 * @param string $ids
	 * @param string $form_lable
	 * @access public 
	 * @since 
	 * @modified           Jun 17, 2016 by Roshan Ruzaik <mrmroshan@yahoo.com>
	 * @modification Fixed bug id 21212       
	 * @return void
	 */
	
	public function edit($ids = null,$form_lable = null){
	
		//if($this->debug) $this->output->enable_profiler(TRUE);
		
		$msg = null;		
		$status = null;
		$integration_name = null;
		$disabled = null; // This para will make sure to disable all controllers of delete confirmation form
		
		if(empty($form_lable)){
			$form_lable = 'Edit Application Integration';
			$disabled = null;
			
		}else{
			$form_lable = 'Delete Application Integration';
			$disabled = ' disabled ';
		}
	
		if(!empty($ids)){				
						
			$searchobj_array = array();
			$search_obj= array(
						'search_field' => 'integration_id',
						'search_text' => $ids,
						'query_method'=> 'equal'	
			);					
			array_push($searchobj_array, $search_obj);			
								
			$data['dataset'] = $this->AppIntegrator_model->get_data(array(
					'search'=>$searchobj_array,
					'order_by'=>array('ar_applications.integration_id'=>'Asc')));
			
			if(!empty($data['dataset']['result_set'])){					

				$integration_name = $data['dataset']['result_set'][1]['intergration_name'];
				
				//prepare parameters list from json 
				$para_json = $data['dataset']['result_set'][1]['called_function_para'];
				$para_decode_json = json_decode($para_json,true);
				//var_dump($para_decode_json);exit;

				//if form is submitted
				if(isset($_POST['integration_id'])){
						
					//get para list as an array then create json string then again assign them to post for saving function
					$para = $_POST['called_function_para'];
					/*
					 * Note: At this point submitted AI add form data array contains parameter/get/post vars in $_POST['called_function_para'].
					 * What we want to do here is to replace all macro values (ex:-@@var_name@@) as php variable names (ex:-$var_name).
					 * To do this we use preg_replace_callback().
					*/
					$para = $this->replace_para_maccro($para);
					$_POST['called_function_para'] = json_encode($para);
							
					$this->save('update');
					$msg = array('msgType' =>'confirmation','msgText' => 'Integration data has been updated!');
					$status = 1;

					// now fetch updated record
					$searchobj_array = array();
					$search_obj= array(
							'search_field' => 'integration_id',
							'search_text' => $ids,
							'query_method'=> 'equal'
					);
					array_push($searchobj_array, $search_obj);
							
					$data['dataset'] = $this->AppIntegrator_model->get_data(array(
							'search'=>$searchobj_array,
							'order_by'=>array('ar_applications.integration_id'=>'Asc')));
				
				
				}//end if $_POST				
				
				$txtbox = null;				
				$i = 0;
				$v = null;				
				
				if(!empty($para_decode_json)){
				$txtbox .= "<div id=\"called_app_function_iddiv\"><br>".
						"Please provide values for following parameters<table width='100%' ><tbody>";
				
				foreach($para_decode_json as $para){
					 	
					if(!isset($para['txtQstring']) && !isset($para['url_first_part'])){
						if($para['para_type'] == 'parameter'){
								
  						$txtbox .= 
    						"<tr>".
  							"<td valign=\"top\"><b>".
  							$para['display_name'].  						
  							":</b></td>".
  							"</tr>".

  							"<tr>".
  							"<td valign=\"top\">".
  							"<input type=\"text\" name=\"called_function_para[".$i."][value]\" value=\"".$para['value']."\" $disabled>".
  							"<br>(".$para['help_text'].")".
  							//"<hr>".
  						
  							"<input type=\"hidden\" name=\"called_function_para[".$i."][display_name]\" value=\"".$para['display_name']."\">".
  							"<input type=\"hidden\" name=\"called_function_para[".$i."][data_type]\" value=\"".$para['data_type']."\">".
  							"<input type=\"hidden\" name=\"called_function_para[".$i."][help_text]\" value=\"".$para['help_text']."\">".
  							"<input type=\"hidden\" name=\"called_function_para[".$i."][para_type]\" value=\"parameter\">".  							  						
  							"</td>".
  							"</tr>";  						
						}//end if  	  						
					}	 							
					$i++;
				}
				
				$txtbox .= "</tbody>".
							"</table>";
				
				$txtbox .= "<br>".
						"Please provide values for following GET/POST querystring vars".
						"<table width='100%' >".
						"<tbody>";
				
				$i=0;
				foreach($para_decode_json as $para){
						
					//var_dump($para);
					if(!isset($para['txtQstring']) && !isset($para['url_first_part'])){
						if($para['para_type'] == 'qstring'){
				
							$txtbox .= "<tr>".
									"<td valign=\"top\"><b>".
									$para['display_name'].
									":</b></td>".
									"</tr>".
									
									"<tr>".
									"<td valign=\"top\">".
									"<input type=\"text\" name=\"called_function_para[".$i."][value]\" value=\"".$para['value']."\" $disabled>".
									"<br>(".$para['help_text'].")".									
				
									"<input type=\"hidden\" name=\"called_function_para[".$i."][display_name]\" value=\"".$para['display_name']."\">".
									"<input type=\"hidden\" name=\"called_function_para[".$i."][qvar_name]\" value=\"".$para['qvar_name']."\">".
									"<input type=\"hidden\" name=\"called_function_para[".$i."][data_type]\" value=\"".$para['data_type']."\">".				
									"<input type=\"hidden\" name=\"called_function_para[".$i."][help_text]\" value=\"".$para['help_text']."\">".
									"<input type=\"hidden\" name=\"called_function_para[".$i."][para_type]\" value=\"qstring\">".								
										
									
							"</td>".
							"</tr>";
							$v .= $para['value'].'/';
						}//end if
				
					}
						
					$i++;
				}//end foreach
				

				$txtbox .=  "</tbody>".
							"</table>";				
				$txtbox .=  '<hr>';
				
					if(isset($para_decode_json[($i - 1)]['txtQstring']) ){
									
						$txtbox .= 	"Type query string here:".
				  		"<input type=\"text\" ".
				  		"value=\"".$para_decode_json[($i-2)]['txtQstring']."\" ".
				  		"name=\"called_function_para[][txtQstring]\" ".
				  		"id=\"called_function_para[][txtQstring]\" $disabled>".
				  
				  		"<input type=\"button\" ".
				  		"value=\"Query String\" ".
				  		"name=\"btnCQueryString\" ".
				  		"id=\"btnCQueryString\" ".
				  		"onclick=\"function_qstring_builder('".urlencode(trim($para_decode_json[($i - 1 )]['url_first_part'] . $v))."')\" .$disabled>".
				  		"<div id=\"divQstringBuilder\"></div>";
				
					}
				
					if(isset($para_decode_json[($i - 1)]['url_first_part'])){
					
						$txtbox .= "<input type=\"hidden\" ".
						"value=\" ".$para_decode_json[($i - 1 )]['url_first_part'] . "\" ".
						"name=\"called_function_para[][url_first_part]\" ".
						"id=\"called_function_para[][url_first_part]\" >";				
					}
				
				}
	
				$data['disabled'] = $disabled;
				$data['msg'] = $msg;
				$data['dataString'] = '';
				$data['form_name'] = $form_lable;
				$data['integration_id'] = $data['dataset']['result_set'][1]['integration_id'];
				$data['intergration_name'] = $data['dataset']['result_set'][1]['intergration_name'];
				$data['calling_app_id'] = $data['dataset']['result_set'][1]['calling_app_id'];
				$data['calling_app_xml_url'] = $data['dataset']['result_set'][1]['calling_app_xml_url'];
				
				$data['calling_app_function_id'] = $data['dataset']['result_set'][1]['calling_app_function_id'];
				$calling_app_function_select = $this->prepare_xml_feed_functions($data['dataset']['result_set'][1]['calling_app_xml_url'],'calling_app_function_id');
				$calling_app_function_select = str_ireplace("value=\"".$data['calling_app_function_id']."\"", "value=\"".$data['calling_app_function_id']."\" selected=\"selected\" ", $calling_app_function_select);
				$calling_app_function_select = str_ireplace("<select ", "<select $disabled ", $calling_app_function_select);
				$data['calling_app_function_select'] = $calling_app_function_select;
				
				$data['called_app_id'] = $data['dataset']['result_set'][1]['called_app_id'];
				$data['called_app_xml_url'] = $data['dataset']['result_set'][1]['called_app_xml_url'];
				$data['called_app_function_id'] = $data['dataset']['result_set'][1]['called_app_function_id'];
				$called_app_function_select = $this->prepare_xml_feed_functions($data['dataset']['result_set'][1]['called_app_xml_url'],'called_app_function_id');
				$called_app_function_select = str_ireplace("value=\"".$data['called_app_function_id']."\"", "value=\"".$data['called_app_function_id']."\" selected=\"selected\" ", $called_app_function_select);
				$called_app_function_select = str_ireplace("<select ", "<select $disabled ", $called_app_function_select);
				//$called_app_function_select = str_ireplace("id='called_app_function_iddiv'></div>", " id='called_app_function_iddiv'>$txtbox</div>", $called_app_function_select);
				$data['called_app_function_select'] = $called_app_function_select;
				$data['called_app_function_qpara'] = $txtbox;
				$data['status'] = $status;
				
				
				
				if(!isset($_POST['integration_id'])){
					
					//To prevent log entry being added towice
					$this->log_obj->set_otherDetails(
							array(
									'Mode'=>'AIR '.$form_lable.' form was loaded for record Id:'.$ids,
									//'Data'=> 'Edit Data :'.print_r($data,true)));
									'Data'=> 'AIR record id: '.$ids));
					$this->log_obj->init();
				}
				
				
				$this->load->view("edit_ai_form",$data);
			}else{
				echo 'No records found';
			}
				
		}else{
			echo  'Please supply id values';
		}//end if
		

		
		
	}//end of function
	
	
 
/**
 * save($action,$callback)
 * 
 * This function save or update supplied data from add/edit form
 * 
 * @param string $action
 * @param string $callback
 * @return int new record id
 */        
  function save($action=null,$callback = null){

  	$debug = false;
  	
  	//if($this->debug) $this->output->enable_profiler(TRUE);
    $data=array();
    $key=array();
    $metadata = $this->AppIntegrator_model->getMetadata();
    $metadata = $metadata['PK'];
    
    if($debug)log_message('debug','Save data :-'.serialize($_POST));
        
    //process $_REQUEST array to indentify fileds and keys
    //$_REQUEST changed to avoide cookies. WCD
	
	foreach((count($_POST)>0?$_POST:$_GET) as $k => $v){
      	$end = substr(strrchr($k, "_"), 1);
      	if(stripos($metadata,$k) !== false) {          
          $key[$k] = $v;
      	}elseif($end =='skip') {
          //nothing do with skip       
      	}else {                        
           $data[$k]=$v;
      	}
      	
    }
    //print_r($task_master_data);	   
    
    $id = $this->AppIntegrator_model->save($data,$key);

    //create access log
    $id = ($action !='update')?$id:$key['integration_id'];
    $mode = ($action!='update')?'New AIR entry was added':"AIR entry id:$id has been updated";    
    $this->log_obj->set_otherDetails(
    		array(
    				'Mode'=>$mode,
    				'Data'=> 'Record id:'.$id));
    $this->log_obj->init();
    return $id;
  }//end of function

  
   
  /**
   * key_validate($action,$key) 
   * 
   * This function checks for duplicate key entries
   * 
   * @param string $action
   * @param array $key
   * @return boolean|multitype:string
   */
  function key_validate($action,$key) {
      
    //make overall validation true at the begining
    $overall_valid=true;
    $error_info=array();
    
    /*check for the primary key or composite key exists. Send key array to check.*/
    $key_exist=$this->AppIntegrator_model->exists($key);
    
    if($key_exist) {
    	
      if($action=='add') {
          //if the primary key exists this can not add. so validation fails and add information 
          //to error info array.
          $overall_valid=false;
          $error_info['primary_key']='Already exists';
      }
      if($action=='edit') {
          //in edit function the primary key should be there.
          //to error info array.
          $overall_valid=true;
      }
    }else {
      if($action=='add') {
          //if primary key not found it can be added
          $overall_valid=true;                   
      }
      if($action=='edit') {
          //if primary key not found it can not be edited         
          $overall_valid=false;
          $error_info['primary_key']='Doesnt exists';
      }
    }
      
    /*check each and every key is exists in specific tables*/
    foreach($key as $k => $v) {
    	
      if($k=='integration_id') {
      	
          $exists=$this->AppIntegrator_model->exists(array($k=>$v));
          
          //if the any key doesnt exists in specific table, key validation fails.
          if(!$exists) {
              $overall_valid=false;
              $error_info[$k]='Doesnt exists';
          } 
      }
      
        
    }    
    if($overall_valid==true){
        return true;
    }
    else  {
        return $error_info; //array('primary_key'=>'Already exists') or
                            //array('primary_key'=>'Doesnt exists','staff_id'=>'Doesnt exists')  
    }
  }


  /**
   * Function  delete ()
   * 
   * This function deletes given record by id 
   *
   * @param string $id
   * @access public 
   * @since 
   * @modified           Jun 17, 2016 by Roshan Ruzaik <mrmroshan@yahoo.com>
   * @modification     Fixed bug id 20500,20499,20501     
   * @return void
   */
	function delete($id = null)	{
		
		$debug = true;
        if($this->debug) $this->output->enable_profiler(TRUE);
		
		if($debug)log_message('info','delete string:-'.$id);
		
		$delete=array();
		echo $this->AppIntegrator_model->delete(array('integration_id' => $id));

		//create access log
		$this->log_obj->set_otherDetails(
				array(
						'Mode'=>'AIR record was deleted',
						'Data'=> 'Record id:'.$id));
		$this->log_obj->init();
		
		
	}//end of function

	
	
	/**
	 * Function  addForm ()
	 * 
	 * This function loads AIR links add form with pre defined structure which also validates 
	 * entered data when submitted
	 *
	 * @access protected 
	 * @since 
	 * @modified           Jun 17, 2016 by Roshan Ruzaik <mrmroshan@yahoo.com>
	 * @modification   Fixed bug id 21882       
	 * @return void
	 */
	function addForm(){
		
		$status =null;
		if($this->debug) $this->output->enable_profiler(FALSE);
		$calling_app_function_select = null;
		$called_app_function_select = null;
		$para = null;		
		
		if(isset($_POST) && !empty($_POST)){						
			
			//obtain applications secret and access keys
			$intergration_name = $_POST['intergration_name'];
			$calling_app_id = $_POST['calling_app_id'];
			$calling_app_xml_url = $_POST['calling_app_xml_url'];
			$calling_app_function_id = $_POST['calling_app_function_id'];
			
			$calling_app_function_select = $this->prepare_xml_feed_functions($calling_app_xml_url,'calling_app_function_id');
			$calling_app_function_select = str_ireplace("value=\"".$calling_app_function_id."\"", "value=\"".$calling_app_function_id."\" selected=\"selected\" ", $calling_app_function_select);
			
			//get para list as an array then create json string then again assign them to post for saving function
			$para = (isset($_POST['called_function_para']))?$_POST['called_function_para']:null;

			/*
			 * Note: At this point submitted AI add form data array contains parameter/get/post vars in $_POST['called_function_para'].
			 * What we want to do here is to replace all macro values (ex:-@@var_name@@) as php variable names (ex:-$var_name).
			 * To do this we use preg_replace_callback(). 
			*/
			if(!empty($para)){
				$para = $this->replace_para_maccro($para);
				$_POST['called_function_para'] = json_encode($para);
			}else{
				$_POST['called_function_para'] = null;
			}
			
									
			$called_app_id = $_POST['called_app_id'];
			$called_app_xml_url = $_POST['called_app_xml_url'];
			$called_app_function_id = $_POST['called_app_function_id'];
						
			$called_app_function_select = $this->prepare_xml_feed_functions($called_app_xml_url,'called_app_function_id');
			$called_app_function_select = str_ireplace("value=\"".$called_app_function_id."\"", "value=\"".$called_app_function_id."\" selected=\"selected\" ", $called_app_function_select);
				
			//with those values and ids get relevant xml feeds and do the cross check 
			try {
				$calling_app_uaacs_xml =  get_contents_with_session(UAACS_URL.'/API/APPAPI/index.php/main/app/t/'.$calling_app_id.'/1/1/');
				$calling_app_function_xml = get_contents_with_session($calling_app_xml_url);
			
				$called_app_uaacs_xml =  get_contents_with_session(UAACS_URL.'/API/APPAPI/index.php/main/app/t/'.$called_app_id.'/1/1/');
				$called_app_function_xml = get_contents_with_session($called_app_xml_url);
				 
			}catch (Exception $e)  {
				show_error("Sorry! An error occoured while fetching XML feed data from server");
				exit;
			}			
			
			$calling_app_uaacs_obj = simplexml_load_string($calling_app_uaacs_xml);
			$calling_app_function_obj = simplexml_load_string($calling_app_function_xml);
			
			$called_app_uaacs_obj = simplexml_load_string($called_app_uaacs_xml);
			$called_app_function_obj = simplexml_load_string($called_app_function_xml);
			
			//now cross check calling app and called app sharing functions agaist uaacs app feed of both.
			$calling_app_uaacs_function_list = $calling_app_uaacs_obj->functions;
			$calling_app_share_function_list = $calling_app_function_obj->functions->function;
			
			//calling application function id check up
			$calling_app_check = $this->crosscheck_uaacs_functions(
					$calling_app_uaacs_function_list, 
					$calling_app_share_function_list,
					'Calling Application');
			
			//var_dump($calling_app_check);
			if(!$calling_app_check['status']){
				//"Calling application or Called application function id mismatch found while cross checking against UAACS function ids"
				//$status[] =array('msg_type'=> 'validate_error','msg' => $calling_app_check['msg'].'<br>');
				$status['msg_type'] = 'validate_error';
				$status['msg'] = $calling_app_check['msg'].'<br>';
			}			
			
			$called_app_uaacs_function_list = $called_app_uaacs_obj->functions;
			$called_app_share_function_list = $called_app_function_obj->functions->function;
			
			//called application function id check up
			$called_app_check = $this->crosscheck_uaacs_functions(
					$called_app_uaacs_function_list, 
					$called_app_share_function_list,
					'Called Application');
			//var_dump($called_app_check);
			
			if(!$called_app_check['status']){
				//$status[] =array('msg_type'=> 'validate_error','msg' => $called_app_check['msg']);
				$status['msg_type'] ='validate_error';
				$status['msg'] = $called_app_check['msg'];
			}									
			
			$_POST['calling_app_access_key'] = (string)$calling_app_uaacs_obj->metadata->accessKey;
			$_POST['calling_app_secret_key'] = (string)$calling_app_uaacs_obj->metadata->secretKey;
			
			$_POST['called_app_access_key'] = (string)$called_app_uaacs_obj->metadata->accessKey;
			$_POST['called_app_secret_key'] = (string)$called_app_uaacs_obj->metadata->secretKey;			
			
			if(($calling_app_check['status'] == true) && ($called_app_check['status'] == true)){
				
				$is_exist = $this->AppIntegrator_model->exists(array(
										'intergration_name' => $intergration_name,
										'calling_app_id' => $calling_app_id,
										'calling_app_function_id' => $calling_app_function_id,
										'called_app_id' => $called_app_id,
										'called_app_function_id' => $called_app_function_id,)
									);
				$is_name_exist = $this->AppIntegrator_model->exists(array(
						'intergration_name' => $intergration_name)
						);
				
				if(!$is_name_exist){
					if(!$is_exist){
						$this->save(null,null);
						//$status[]= array('msg_type'=> 'success','msg' => 'Application integration created successfully!');
						$status['msg_type']= 'success';
						$status['msg'] = 'Application integration created successfully!';
						
					}else{
						//$status[] =array('msg_type'=> 'validate_error','msg' => "Given calling appilcation id,called application id, and respective patht information are already existing.");
						$status['msg_type'] = 'validate_error';
						$status['msg'] = "Given calling appilcation id,called application id, and respective patht information are already existing.";
						
						//create access log
						$this->log_obj->set_otherDetails(
								array(
										'Mode'=>'AIR add form error',
										'Data'=> 'Error :'.$status['msg']));
						$this->log_obj->init();
						
					}
				}else{
					//$status[] =array('msg_type'=> 'validate_error','msg' => "Integration name is already existing.");
					$status['msg_type'] = 'validate_error';
					$status['msg'] = "Integration name is already existing.";
					
					//create access log
					$this->log_obj->set_otherDetails(
							array(
									'Mode'=>'AIR add form error',
									'Data'=> 'Error :'.$status['msg']));
					$this->log_obj->init();
						
				}//is name 
			}//if check for status
			
		}//end of if POST
		
		$data['dataString'] = '';
		$data['form_name'] = 'Add New Application Integration';
		$data['intergration_name'] = (isset($_POST['intergration_name']))?$_POST['intergration_name']:null;
		$data['calling_app_id'] = (isset($_POST['calling_app_id']))?$_POST['calling_app_id']:null;
		$data['calling_app_xml_url'] = (isset($_POST['calling_app_xml_url']))?$_POST['calling_app_xml_url']:null;
		$data['calling_app_function_select'] = $calling_app_function_select;
		$data['called_app_id'] = (isset($_POST['called_app_id']))?$_POST['called_app_id']:null;
		$data['called_app_xml_url'] = (isset($_POST['called_app_xml_url']))?$_POST['called_app_xml_url']:null;
		$data['called_app_function_select'] = $called_app_function_select;
		$data['status'] = $status;
		$data['para'] = $para;

		if(!isset($_POST) && empty($_POST)){
			
			//To prevent log being added towice when loading and subittng the form
			//create access log
			$this->log_obj->set_otherDetails(
					array(
							'Mode'=>'AIR add new entry form was loaded',
							'Data'=> 'AIR record data:'.print_v($data,true)));
			$this->log_obj->init();
		}
		
		$this->load->view('add_new_app_form',$data);
		
	}//end of function
	
		
	/**
	 * replace_para_maccro($matches)
	 * 
	 * This function is used for replacing macro variables (ex:-@@var@@) of $para data.
	 *  
	 * @param array $para
	 * @return array
	 */	 
	 function replace_para_maccro($para){
	 
		/**
		 * replace_maccro($matches)
		 * This function is an internal function to replace maccro values 
		 * 
		 * @param string $matches
		 * @return string
		 */
		function replace_maccro($matches){
			$new_var = null;
			foreach($matches as $match){
				//replace @@var_name@@ as $var_name
				$match = explode('@@',$match);
				$new_var = 	'$'.$match[1];
			}
			return $new_var;
		}
		$i = 0;
		foreach($para as $p){
		
			$para[$i] = preg_replace_callback("/(@@\w*@@)/","replace_maccro",$p);
			$i++;
		}
		
		return $para;	
		//var_dump($para);exit;
	}//end of function 
	
	
	
	/**
	 * crosscheck_uaacs_functions($uaacs_functions_obj,$share_functions_obj )
	 * 
	 * This function crosschechks all function ids of $share_functions_obj against $uaacs_functions_obj
	 * This function checks all function ids of share functions obj are present on uaacs functions object.
	 * if any one function id is missing this will return false
	 *  
	 * @param object $uaacs_functions_obj
	 * @param object $share_functions_obj
	 * @param string $appType
	 * @return boolean
	 */
	function crosscheck_uaacs_functions($uaacs_functions_obj,$share_functions_obj,$appType = null){
	
		$debug = true;
		$functionArr = array();
		$checkArr = array();
		
		foreach($share_functions_obj as $function){
			
			$shareFunctionsArr[] = (int)$function['id'];
		}
		
		if($debug)log_message('debug',$appType.'crosscheck_uaacs_functions() $shareFunctionsArr:-'.serialize($shareFunctionsArr));
		 
		$functions = $uaacs_functions_obj->xpath("//function");
		 
		foreach($functions as $uaacs_function){
			$uaacsFunctionsArr[] = (int)$uaacs_function['funcId'];
		}
		if($debug)log_message('debug',$appType.' crosscheck_uaacs_functions() $uaacsFunctionsArr:-'.serialize($uaacsFunctionsArr));

		
		if(count(array_intersect($shareFunctionsArr, $uaacsFunctionsArr)) != count($shareFunctionsArr)){
			//return false;
			$checkArr['msg'] =  "Function id miss match found on $appType against $appType UAACS feed!";
			$checkArr['status'] = false;
			//var_dump($checkArr);exit;
			if($debug)log_message('debug',$appType.'crosscheck_uaacs_functions() $checkArr:-'.serialize($checkArr));				
			return $checkArr;
		}else{	
			
			$checkArr['status'] = true;		
			return $checkArr;
		}
		 
	}//end of function
	
  
	/**
 	* prepare_xml_feed_functions($editUrl,$editId)
 	* 
 	* This function prepares add/edit forms with proper form input elements after getting the share function xml feeds.
 	* 
 	* @param string $editUrl
 	* @param string $editId
 	* @return string
 	*/	
  public function prepare_xml_feed_functions($editUrl=null,$editId=null){
  	
  	$xmlUrl = (isset($editUrl))?$editUrl:$_GET['url'];
  	$selId = (isset($editId))?$editId:$_GET['selid'];
  	$xmlDoc = file_get_contents($xmlUrl);
  	$xmlObj = @simplexml_load_string($xmlDoc);
  	$select = null;
  	if(!$xmlObj){
  		echo "Above given XML feed URL is not valid.";
  		exit;
  	}
  	$function_id_options = array('' => 'Please select');
  	
  	$functions = $xmlObj->xpath("//function");
  	
  	foreach($functions as $function){
  		//var_dump($function['id']);exit;
  		//do type casting to get integer and string values of client object.
  		//otherwise will produce warning messages.
  		$funcId = intval($function['id']);
  		$funcName = (string)$function['name'];
  			
  		$function_id_options[$funcId] = $funcName;
  	}
  	
  	$select = '<select name="'.$selId.'" id="'.$selId.'" onChange="function_paras(this)">';
  	foreach($function_id_options as $k => $v){
  		$select .= '<option value="'.$k.'">'.$v.'</option>';
  	}
  	$select .= '</select>';
  	//$select .= "<div id='".$selId."div'></div>";
  	
  	//var_dump($select);exit;
  	if(empty($editUrl)){
  		echo $select;
  	}else{
  		return $select;	
  	}	  	
  	  	
  }//end of function
  
  
  /**
   * check_xmlfeed_and_app_id()
   *
   * This function maks sure both xml feed and application ids are correct combination.
   * accepts 2 query strings xml_feed_url and app_id
   *
   * string xml_feed_url
   * string app_id
   */
  
  public function check_xmlfeed_and_app_id(){
  	
  	$xml_url = (isset($_GET['xml_feed_url']))?$_GET['xml_feed_url']:null;
  	$app_id = (isset($_GET['app_id']))?$_GET['app_id']:null;
  	$xmlDoc = file_get_contents($xml_url);  	
  	$xmlObj = @simplexml_load_string($xmlDoc);
  	
  	if(!$xmlObj){
  		echo 2;
  		exit;
  	}
  	if((intval($xmlObj->app_id)) != $app_id){
  		echo 0;
  		exit;
  	}else{
  		echo 1;
  	}
  	
  	
  	
  }//end of fucntion
  
  
  
  /**
   * prepare_function_paras($editUrl,$func_id)
   * 
   * This function prepares add/edit form with parameters fields after getting information from share_function xml feed
   * 
   * @param string $editUrl
   * @param string $func_id
   */
  public function prepare_function_paras($editUrl = null,$func_id = null){  	  	

  	$xmlUrl = (isset($editUrl))?$editUrl:$_GET['url'];
  	$func_id = (isset($func_id))?$func_id:$_GET['func_id'];
  	$xmlDoc = file_get_contents($xmlUrl);
  
  	$xmlObj = simplexml_load_string($xmlDoc);
  	$para_out = null;
  	
  	$function_obj = $xmlObj->xpath("//function[@id = ".$func_id."]");
  	$para_list = $function_obj[0]->parameters;  	  	
  	$url_node = trim($function_obj[0]->url);
  	$url_method = (string)$function_obj[0]->url_method;
  	$qry_str_vars = $function_obj[0]->query_string_vars;;
  		
  	
  	$url_sub_parts = array();
  	$url_controller_function = null;  	
  	
  	//var_dump($url_node);exit;
  	
	if(!empty($url_node)){
		
  		//now process the url to break and add to parameter txt boxes.
  		$url_parts = explode('.php/',$url_node);
  		$url_sub_parts = explode('/', $url_parts[1]);
  		$url_controller_function = $url_sub_parts[0].'/'.$url_sub_parts[1].'/';
  		
  		// make sure to ignore url_sub_parts[0],[1] (controller/method/)
  		$url_sub_parts = array_slice($url_sub_parts, 2); //remove first two parts
  		//var_dump($url_sub_parts);exit;
	}else{
		$para_out .= '<br>Provided called app XML feed does not contain called app URL. Please check<br>';
	}  	
  	
	
	//for parameter listin. First check for empty values.	
	$i =0;
	$url_parameter_list = null;
  	if(!empty($para_list)){
  		
  		
  		$para_out .= "Please provide values for following parameter(s)<br><br>";
  		$para_out .= "<table width='100%' >";
  		  		
  		foreach($para_list as $para){
  			
  			//if($i==0) 				
  			
  			foreach($para  as $item){  				
  				
  				if(isset($item->editability)){
  					$editablility = (strtolower($item->editability)==='false' || $item->editability===false )?'readonly':true;
  				}else{
  					$editablility = null;
  				}
  								
  				$para_out .= 
  					
    					"<tr>".
  						"<td valign='top'><b>".  						
    					$item->display_name.    					  						
  						":</b></td>".
  						"</tr>".
  						
  						"<tr>".
  						"<td valign='top'>".
  						    					
    					"<input $editablility type=\"text\" ".
  						"name=\"called_function_para[".$i."][value]\" ".  						
  						"value=\"".$url_sub_parts[$i]."\" >".  				
  					
  						"<br>(".$item->help_text.")".
  						
  						"<input type=\"hidden\" ".
  						"name=\"called_function_para[".$i."][display_name]\" ".
  						"value=\"".$item->display_name."\" >".
  						
  						"<input type=\"hidden\" ".
  						"name=\"called_function_para[".$i."][help_text]\" ".
  						"value=\"".$item->help_text."\" >".
  						
  						"<input type=\"hidden\" ".
  						"name=\"called_function_para[".$i."][data_type]\" ".
  						"value=\"".$item->data_type."\" >".
  						  						
  						"<input type=\"hidden\" ".
  						"name=\"called_function_para[".$i."][para_type]\" ".
  						"value=\"parameter\" >".
  						
  						"</td>".
  						"</tr>";  				
  				$i++;
  				
  			}//end foreach	  			
  		}//end foreach	
  		
  		$para_out .= "</table>";  			
  	}//end if
  	
  	$para_out .= "<hr>";
  	
  	if(!empty($qry_str_vars)){
  			
  		
  		$para_out .= "Please provide values for following GET/POST querystring variable(s)<br><br>";
  		$para_out .= "<table width='100%' >";  		
  	
  		foreach($qry_str_vars as $vars){
  			
  			foreach($vars as $var){  						  			

  				if(isset($var->editability)){
  					$editablility = (strtolower($var->editability)==='false' || $var->editability===false )?'readonly':null;
  				}else{
  					$editablility = null;
  				}
  				$qstring_var = $var->getName();//get the element name
  				
  				$para_out .=
  				"<tr>".
  				"<td valign='top'><b>".
  				$var->display_name.
  				":</b></td>".
  				"</tr>".
  	
  				"<tr>".
  				"<td valign='top'>".
  				
  				"<input $editablility type=\"text\" ".
  				"name=\"called_function_para[".$i."][value]\" ".  				
  				"value=\"".$var->default."\" >".
  				
  				"<br>(".$var->help_text.")<hr>".
  	
  				"<input type=\"hidden\" ".
  				"name=\"called_function_para[".$i."][qvar_name]\" ".
  				"value=\"".$qstring_var."\" >".
  				
  				"<input type=\"hidden\" ".
  				"name=\"called_function_para[".$i."][display_name]\" ".
  				"value=\"".$var->display_name."\" >".
  				
  	
  				"<input type=\"hidden\" ".
  				"name=\"called_function_para[".$i."][help_text]\" ".
  				"value=\"".$var->help_text."\" >".
  	
  				"<input type=\"hidden\" ".
  				"name=\"called_function_para[".$i."][data_type]\" ".
  				"value=\"".$var->data_type."\" >".
  	
  				"<input type=\"hidden\" ".
  				"name=\"called_function_para[".$i."][default]\" ".
  				"value=\"".$var->default."\" >".
  				

  				"<input type=\"hidden\" ".
  				"name=\"called_function_para[".$i."][para_type]\" ".
  				"value=\"qstring\" >".
  	
  				"</td>".
  				"</tr>";
  				$i++;
  				
  			}//end foreach
  			
  		}//end foreach
  			
  		$para_out .= "</table>";
  		
  	}//end if
  	
  	  	
  	if(strtolower($url_method) == 'get'){
  		
  		//$para_out .= $url_node;
  		$para_out .= "Type query string here:<br><input type=\"text\" ".
  				"value=\"\" ".
  				"name=\"called_function_para[][txtQstring]\" ".
  				"id=\"called_function_para[][txtQstring]\" >";
  		
  		$para_out .= "<input type=\"button\" ".
    		"value=\"\" ".
  			"name=\"btnCQueryString\" ".
  			"id=\"btnCQueryString\" ".
  			"onclick=\"function_qstring_builder('".urlencode(trim($url_node))."')\" ". 
  			"value =\"Query String Helper\" ".
  			"style =\"\" >"; 
  		//background-image: url(\"http:\\\bizydads.com\frameworks\dhtmlx\dhtmlxToolbar\samples\common\imgs\help.gif\");background-repeat: no-repeat;\
  	
  		$para_out .= "<div id=\"divQstringBuilder\"></div>";  		
  	}
  	
  	//save main url's first part in order to re assemble in AIR when token is requested
  	if(!empty($url_node)){
  	$para_out .= "<input type=\"hidden\" ".
  			"value=\"" . $url_method .'@'. $url_parts[0]. ".php/" . $url_controller_function . "\" ".
  			"name=\"called_function_para[][url_first_part]\" ".
  			"id=\"called_function_para[][url_first_part]\" >";
  	}		
  	
  	echo $para_out;
  	
  }//end of function

  
  
  
  /**
 	* prepare_qstring_builder()
 	*	
 	* This fuction prepares querystring builder popup. So then users can specify required querystrings along with the url.
 	* This function is called by AJAX  
 	* 
 	*/  
  public function prepare_qstring_builder(){
  
  	$xmlUrl = (isset($editUrl))?$editUrl:$_GET['url'];
  	$xmlDoc = file_get_contents(trim($xmlUrl));
  	$xmlObj = simplexml_load_string($xmlDoc);  	
  	  	
  	$field_list = null;
  	$i = 0;
  	$field_list .= "<div id=\"divprevQstring\"></div>";
  	$field_list .= "<div style=\"padding-left:20px\" >";

  	if(!empty($xmlObj->row[0])){
  	foreach($xmlObj->row[0] as $row){
  		  		
  		//$field_list .= "<br><input type=\"checkbox\" name=\"".$row['fieldName']."\" value=\"".$row['fieldName']."\" onclick=\"updateQstring(this)\">".$row['fieldName'];
  		$field_list .= $row['fieldName'].'<br>';
  		$i++;  	
  	}
  	}else{
  		$field_list .= "Un common XML feed!";
  	}
  	$field_list .= "</div>";  	
  	
  	echo $field_list;
  	
  }//end of function
  
  
  
  
  
	/**
	 *	createDropdown()
	 *
	 *	createDropdown is the component function. Its main functionality is to produce a dropdown with pre populated table data
	 *
	 *  Parameter list :-
	 *
	 *   $data['selectByValue']  => null   - preselection of list items by value
	 *   $data['selectBYText']   => null   - preselection of list items by Text
	 *   $data['filterBy']       => null   - filter data set by a field or list
	 *   $data['outFormat']      => 'html' - Format of the output like HTML,XML Etc
	 *   $data['isMultiple']     => false  - is the drop down with multi select capable
	 *   $data['sort']           => 'asc'  - sort list text Ascending or Descending
	 *   $data['optionsOnly']    => false  - Specify the controller that output only <options> values
	 *
	 *    Usage :-
	 *
	 *    1) Format for internal functional call by passing data array
	 *
	 *    $data = array('selectByValue' => null,
	 *					'selectBYText' => null,
	 *					'outFormat' => 'html' ,
	 *					'isMultiple' => false,
	 *					'sort' => 'asc',
	 *					'optionsOnly' => false,
	 *					'filterBy' => array(
	 *									'search_field' => 'T.status',
	 *									'search_text' => '0',
	 *									'query_method'=>'equal',
	 *									'order_by' => 'asc'
	 *									)
	 *						)
	 *
	 *    2) Format of external call by URL
	 *
	 *    http://.../index.php/task_master/createDropdown/?sbv=null&sbt=null&format=html&multiple=false&sort=asc&filterby=status-0-equal
	 *
	 *    Description of parameter list,
	 *
	 *    sbv - selectByValue  => null
	 *    sbt - selectBYText   => null
	 *    format - outFormat   => 'html'
	 *    multiple - isMultiple=> false
	 *    sort - sort          => 'asc'
	 *    filterby - filterBy  => null
	 *    optionsOnly - options only listing
	 *    
	 *    @param array $data data array to create dropdown
	 *
	 */        
  public function createDropdown($data = false){
  
  	$dataset = null;
  	$selectByValue = null;
  	$selectBYText = null;
  	$outFormat = 'html' ;
  	$isMultiple = null;
  	$sort = null;
    $sort_array = array('ar_applications.integration_id' => 'ASC');
  	$filterBy = null;
   	$searchobj_array = null;
   	$optionsOnly = false;
  	
  	/*
  	 *	first check wether the call is internal(ie:internal function call) or external(ie:url call)
  	 *	to do this we can check $data variable.if this variable is an array it means its an internal call
  	 *	if $data is 'false' it means its an external call.
  	 */	
  		
  	if(is_array($data)){
  		
  		/* 
  		 * this is an internal call. so construct the search obj with passed array parameeters. 
  		 * extract the data and pass on to the view
  		 */
  		
  		$selectByValue = isset($data['selectByValue'])?$data['selectByValue']:null;
  		$selectBYText = isset($data['selectBYText'])?$data['selectBYText']:null;
  		$outFormat = isset($data['outFormat'])?$data['outFormat']:null;
  		$isMultiple = isset($data['isMultiple'])?$data['isMultiple']:false;
  		$sort = isset($data['sort'])?$data['sort']:'task_master.description=ASC';
  		$filterBy = isset($data['filterBy'])?$data['filterBy']:null;
  		$optionsOnly = isset($data['optionsOnly'])?$data['optionsOnly']:false;
  		
  	}else{
  		
  		/* 
  		 * this is an external url call. So process $_GET or $_POST parameeter values and using
  		 * these values construct search obj and fetch data for combo box
  		 */
  		if(count($_POST)>0 || count($_GET)>0){
  			
       		$myParams = count($_POST)>0? $_POST:$_GET;
  
  			$selectByValue = isset($myParams['sbv'])? $myParams['sbv']:null ;		
  			$selectByValue = (!empty($selectByValue))?$selectByValue:null; // set default values if not supplied.
  			 		
  			$selectBYText = isset($myParams['sbt'])?$myParams['sbt']:null;
  			$selectBYText = (!empty($selectBYText))?$selectBYText:null;
  			
  			$outFormat = isset($myParams['format'])?$myParams['format']:null;
  			$outFormat = ($outFormat != 'html' && !empty($outFormat))?$outFormat:'html';
  			
  			$isMultiple = isset($myParams['multiple'])?$myParams['multiple']:null;
  			$isMultiple = ($isMultiple == 'true')?true:false;
  			
  			$sort = isset($myParams['sort'])?$myParams['sort']:'ar_applications.calling_app_id=ASC';
  			//$sort = ($sort == 'desc')?'desc':'asc';
  			
  			$filterBy_string = isset($myParams['filterby'])? $myParams['filterby']:null;
  			$filterBy_string = (!empty($filterBy_string))?$filterBy_string:null;
  			
  			$optionsOnly = isset($myParams['optionsonly'])? $myParams['optionsonly']:false;
  			$optionsOnly = ($optionsOnly == 'true')? true:false;
  
  			
  			if(!empty($filterBy_string)){        
          		
  				$fieldPara = explode(',',$filterBy_string);          		
          		foreach ($fieldPara as $val )   {
             			$split =  explode('=',$val);
             			$filterBy[$split[0]]= $split[1];
          			}
  			}else{
  				
  				$filterBy = null;
  			}        
        	if (!empty($sort)){             
          		$sortPara = explode(',',$sort);
          		foreach ($sortPara as $val )   {
             		$split =  explode('=',$val);
             		$sort_array[$split[0]]= $split[1];
          		}
        	}  			
  		}
  	}//end of param check and config
  
  	// Construct search object if present 
  		
  	If ($filterBy){
  			
  		$searchobj_array = array();
  			
  		foreach($filterBy as $key => $val){
  	
  			$search_text = $val; //search text
  			$query_method = substr(strrchr($key, "_"), 1);
  			$pos = strrpos($key, '_');
  			$field = substr($key, 0, $pos);
  			$search_obj = array(
  					'search_field' => $field,
  					'search_text'  => $search_text,
  					'query_method' => $query_method
  			);
  				
  			array_push($searchobj_array, $search_obj);
  		}	
  	}//end if
    
      //Construct selection list. (Fixed)
      $selection = 
      		 'ar_applications.integration_id,
						ar_applications.calling_app_id,
						ar_applications.calling_app_access_key,
						ar_applications.calling_app_secret_key, 				
						ar_applications.called_app_id,
						ar_applications.called_app_access_key,
						ar_applications.called_app_secret_key,
						ar_applications.added_by,
						ar_applications.added_date_time,
					    ar_applications.updated_by,
						ar_applications.updated_date_time' ;
    
      // Fetch data from model
    
  	$dataset = $this->AppIntegrator_model->get_data(array(
  			'search' => $searchobj_array,
  			'selection' => $selection,
        	'order_by' => $sort_array));  
  
  	//var_dump($dataset); for debug
  	
  	// Construct data structure for view  	
  	$wrapped_data['data']['dataset'] = $dataset;	
    $wrapped_data['selectByValue'] = $selectByValue;
  	$wrapped_data['selectByText'] = $selectBYText;
  	$wrapped_data['outFormat'] = $outFormat;
  	$wrapped_data['isMultiple'] = $isMultiple;
  	$wrapped_data['optionsOnly'] = $optionsOnly;
  	
  	//create access log
  	$this->log_obj->set_otherDetails(
  			array(
  					'Mode'=>'AIR createDropdown() was accessed',
  					'Data'=> '-'));
  	$this->log_obj->init();
  	 
  	// load view file with assigned data array  
  	$this->load->view('ai_dropdown',$wrapped_data);	
  	
  }//end of function        
  
}//end of class
?>