<?
$_DEBUG = false;
include("constants.ini");//this must come first
include("IDEA.ini");
include("GUI.php");
if ($_DEBUG){
	$Event = intval($Event);
	echo "Count of event is ".count($IDEA['Events']);
	echo "input Event is ".$Event;
	echo "input Event name is ".$IDEA['Events'][$Event]['Name'];
	echo "input Event ID is ".$IDEA['Events'][$Event]['ID'];
}
$Event = intval($Event);
for ($i=0;$i<count($IDEA['Events']);$i++){
	if($_DEBUG){
		echo "Event ID ".$IDEA['Events'][$i]['ID']."<br>";
	}
    if (strcmp(strval($Event),strval($IDEA['Events'][$i]['ID']))==0){
    //if (strval($Event) == strval($IDEA['Events'][$i]['ID'])){
       /*
        *Obtain Functions from INI file
        */
        $Functions = $IDEA['Events'][$i]['Functions'];
        $Functions = explode(" ",$Functions);
        if($_DEBUG){
        	for ($p=0;$p<count($Functions);$p++)
                    echo "Function $p of Event ".$Event." is ".$Functions[$p]."<br>";
        }
        /*
         *For each of the functions found for the event
         *locate it in the Functions declarations in the INI
         *and obtain information on the found function
         */
        for ($j=0;$j<count($Functions);$j++){//for each of the functions found
			if($_DEBUG){
				echo "Function $j of ".count($Functions)."<br>";
			}
			$Command = $IDEA[$Functions[$j]]['Command'];
            if($_DEBUG){
                        echo "Command for Function $Functions[$j] is ".$Command."<br>";
            }
            /*
             *Obtain parameters
             */
            $Params = explode(" ",$IDEA[$Functions[$j]]['Params']);
            if($_DEBUG){
            	for ($m=0;$m<count($Params);$m++){
            	    echo "Param $m is ".$Params[$m]." value is ";
            	    echo $$Params[$m]."<br>";
            	}
            }
            /*
             *Form command
             */
             for ($k=0;$k<count($Params);$k++){
                 //$Command .= " ".escapeshellarg($$Params[$k]);
				 $Command .= " ".urlencode($$Params[$k]);
             }
             if($_DEBUG){
                         echo "command now is ".$Command."<br>";
             }
             /*
              **Execute command
              */
              $return = `$Command`;
              $return = trim($return);
              if($_DEBUG){
                          echo "return value from command is *".$return."*<br>";
              }
              /*
               **Obtain return parameters from INI file
               */

               $Returns = $IDEA[$Functions[$j]]['Returns'];


			   $$Returns = urldecode($return);

				if ($_DEBUG){
					echo "return var is put into ".$Returns."<br>";
					echo "and return var ".$Returns." is ". $$Returns ."<br>";
				}
        }

		if ($_DEBUG){
			echo "GUI to call is ".$IDEA['Events'][$i]['GUI'];
		}
		$IDEA['Events'][$i]['GUI']();
		break;
    }
}
?>
