@@ -83,6 +83,8 @@ function implode_recursive($glue, $input, $file = 'unknown', $function = 'unknow
8383 trigger_error ("Input not array! Error originated in $ file, function $ function, line $ line. Input = " . print_r ($ input , true ));
8484 return $ input ;
8585 }
86+ elseif (is_string ($ input )) return $ input ;
87+ runDebug (__FILE__ , __FUNCTION__ , __LINE__ ,'The variable $input is of type ' . gettype ($ input ), 4 );
8688 foreach ($ input as $ index => $ element )
8789 {
8890 if (empty ($ element ))
@@ -288,15 +290,15 @@ function parse_get_tag($convoArr, $element, $parentName, $level)
288290 $ response = $ row ['value ' ];
289291 }
290292 else {
291- $ response = 'undefined ' ;
293+ $ response = 'undefined ' ;
292294 }
293- mysql_free_result ($ result );
295+ mysql_free_result ($ result );
294296 }
295297 runDebug (__FILE__ , __FUNCTION__ , __LINE__ , "The value for $ var_name is $ response. " , 4 );
296298 return $ response ;
297299 }
298300
299- function parse_set_tag ($ convoArr , $ element , $ parentName , $ level )
301+ function parse_set_tag (& $ convoArr , $ element , $ parentName , $ level )
300302 {
301303 runDebug (__FILE__ , __FUNCTION__ , __LINE__ , 'Parsing the SET tag. ' , 2 );
302304 global $ con , $ dbn , $ user_name , $ remember_up_to ;
@@ -314,8 +316,8 @@ function parse_set_tag($convoArr, $element, $parentName, $level)
314316 if ($ var_name == 'name ' )
315317 {
316318 $ user_name = $ var_value ;
317- $ sql = " UPDATE ` $ dbn `.`users` set `user_name` = ' $ var_value' where `id` = $ user_id ; " ;
318- $ sql = mysql_real_escape_string ( $ sql ) ;
319+ $ escaped_var_value = mysql_real_escape_string ( $ var_value) ;
320+ $ sql = " UPDATE ` $ dbn `.`users` set `user_name` = ' $ escaped_var_value ' where `id` = $ user_id ; " ;
319321 runDebug (__FILE__ , __FUNCTION__ , __LINE__ , "Updating user name in the DB. SQL: \n$ sql " , 3 );
320322 $ result = db_query ($ sql , $ con ) or trigger_error ('Error setting user name in ' . __FILE__ . ', function ' . __FUNCTION__ . ', line ' . __LINE__ . ' - Error message: ' . mysql_error ());
321323 $ numRows = mysql_affected_rows ();
@@ -355,11 +357,12 @@ function parse_set_tag($convoArr, $element, $parentName, $level)
355357 $ result = db_query ($ sql , $ con ) or trigger_error ('Error saving to db in ' . __FILE__ . ', function ' . __FUNCTION__ . ', line ' . __LINE__ . ' - Error message: ' . mysql_error ());
356358 $ rowCount = mysql_affected_rows ();
357359 $ response = $ var_value ;
360+ $ convoArr ['client_properties ' ][$ var_name ] = $ var_value ;
358361 runDebug (__FILE__ , __FUNCTION__ , __LINE__ , "Value for $ var_name has ben set. Returning $ var_value. " , 4 );
359362 return $ response ;
360363 }
361364
362- function parse_think_tag ($ convoArr , $ element , $ parentName , $ level )
365+ function parse_think_tag (& $ convoArr , $ element , $ parentName , $ level )
363366 {
364367 runDebug (__FILE__ , __FUNCTION__ , __LINE__ , 'I \'m considering parsing a THINK tag. ' , 2 );
365368 $ response_string = tag_to_string ($ convoArr , $ element , $ parentName , $ level , 'element ' );
@@ -467,7 +470,6 @@ function parse_condition_tag($convoArr, $element, $parentName, $level)
467470 runDebug (__FILE__ , __FUNCTION__ , __LINE__ , 'Parsing a CONDITION tag. ' , 2 );
468471 global $ error_response ;
469472 $ response = array ();
470- $ attrName = $ element ['name ' ];
471473 $ attributes = (array )$ element ->attributes ();
472474 $ attributesArray = (isset ($ attributes ['@attributes ' ])) ? $ attributes ['@attributes ' ] : array ();
473475 runDebug (__FILE__ , __FUNCTION__ , __LINE__ , 'Element attributes: ' . print_r ($ attributesArray , true ), 4 );
@@ -502,6 +504,7 @@ function parse_condition_tag($convoArr, $element, $parentName, $level)
502504 runDebug (__FILE__ , __FUNCTION__ , __LINE__ , 'Parsing a CONDITION tag with 2 attributes. ' , 4 );
503505 $ condition_name = (string )$ element ['name ' ];
504506 $ test_value = get_client_property ($ convoArr , $ condition_name );
507+ $ test_value = trim ($ test_value );
505508 switch (true )
506509 {
507510 case (isset ($ element ['value ' ])):
@@ -521,14 +524,42 @@ function parse_condition_tag($convoArr, $element, $parentName, $level)
521524 }
522525 elseif (array_key_exists ('name ' , $ attributesArray )) // this ~SHOULD~ just trigger if the NAME value is present, and ~NOT~ NAME and (VALUE|CONTAINS|EXISTS)
523526 {
524- runDebug (__FILE__ , __FUNCTION__ , __LINE__ , 'Parsing a CONDITION tag with only the NAME attribute. ' , 4 );
527+ runDebug (__FILE__ , __FUNCTION__ , __LINE__ , 'Parsing a CONDITION tag with only the NAME attribute ' , 4 );
525528 $ condition_name = (string )$ element ['name ' ];
526529 $ test_value = get_client_property ($ convoArr , $ condition_name );
527- $ path = "li[@value= \"$ test_value \"]|li[not(@*)] " ;
530+ //$path = "li[@name=*][not(@value)]|li[not(@*)]";
531+ $ path = "li[@name]|li[not(@*)] " ;
532+ //trigger_error("path = $path");
528533 runDebug (__FILE__ , __FUNCTION__ , __LINE__ , "search string = $ path " , 4 );
529534 $ choice = $ element ->xpath ($ path );
530- $ pick = $ choice [0 ];
531- runDebug (__FILE__ , __FUNCTION__ , __LINE__ , 'Found a match. Pick = ' . print_r ($ pick , true ), 4 );
535+ runDebug (__FILE__ , __FUNCTION__ , __LINE__ ,'Choices = ' . print_r ($ choice , true ), 4 );
536+ if (count ($ choice ) != 0 )
537+ {
538+ $ test_value = rtrim ($ test_value );
539+ runDebug (__FILE__ , __FUNCTION__ , __LINE__ ,'parent XML = ' . $ element ->asXML (), 4 );
540+ foreach ($ choice as $ pick )
541+ {
542+ $ testVarName = (string )$ pick ['name ' ];
543+ $ testVarValue = get_client_property ($ convoArr , $ testVarName );
544+ $ testVarValue = trim ($ testVarValue );
545+ runDebug (__FILE__ , __FUNCTION__ , __LINE__ ,"Checking to see if $ testVarValue ( $ testVarName) is equal to $ test_value. " , 4 );
546+ if (strtolower ($ testVarValue ) == strtolower ($ test_value ))
547+ {
548+ runDebug (__FILE__ , __FUNCTION__ , __LINE__ ,'Pick XML = ' . $ pick ->asXML (), 4 );
549+ break ;
550+ }
551+ }
552+ //$pick = $choice[0];
553+ runDebug (__FILE__ , __FUNCTION__ , __LINE__ , 'Found a match. Pick = ' . print_r ($ pick , true ), 4 );
554+ }
555+ else
556+ {
557+ $ path = "li[@value= \"$ test_value \"]|li[not(@*)] " ;
558+ runDebug (__FILE__ , __FUNCTION__ , __LINE__ , "search string = $ path " , 4 );
559+ $ choice = $ element ->xpath ($ path );
560+ $ pick = $ choice [0 ];
561+ runDebug (__FILE__ , __FUNCTION__ , __LINE__ , 'Found a match. Pick = ' . print_r ($ pick , true ), 4 );
562+ }
532563 }
533564 else // nothing matches
534565 {
@@ -778,7 +809,7 @@ function parse_eval_tag($convoArr, $element, $parentName, $level)
778809 * @return (string) $response_string
779810 */
780811
781- function tag_to_string ($ convoArr , $ element , $ parentName , $ level , $ type = 'element ' )
812+ function tag_to_string (& $ convoArr , $ element , $ parentName , $ level , $ type = 'element ' )
782813 {
783814 runDebug (__FILE__ , __FUNCTION__ , __LINE__ , "converting the $ parentName tag into text. " , 2 );
784815 $ response = array ();
0 commit comments