<?php

include("datalayer.php");
$dl = new DataLayer();
$dl->debug false;
$dl->myconnect("tomh");

$user_id 0;
$PARAMS = (count($HTTP_POST_VARS)) ? $HTTP_POST_VARS $HTTP_GET_VARS;
foreach (
$PARAMS as $key=>$value) {
    if (
$key=='userid') {
        
$user_id $value;
    }
}

//we pull the users information out of the database...
$arr_users $dl->select("tbl_users""user_id = $user_id");
//should be one user selected, go ahead and get their information again
foreach ($arr_users as $u_row) {
    foreach (
$u_row as $name=>$val) {
        if (
$name == "pin") { 
            
$str_pins .= " ".$val
        }
        if (
$name == "title") { 
            
$title $val
        }
        if (
$name == "first_name") { 
            
$str_firstname $val
        }
        if (
$name == "last_name") { 
            
$str_lastname $val
        }
    }
}

//next select the users' feeds for the menu:
$cnt_feeds 0;
$arr_feeds $dl->select_feed_by_user($user_id);
foreach (
$arr_feeds as $f_row) {
    
$cnt_feeds++;
}
//just the count for now, tbh

//create the header, much like in authentication.vxml.php
header("Content-Type: application/voicexml+xml"); 
$vxml "";
$vxml .= "<?xml version=\"1.0\" ?>\n\t<!DOCTYPE vxml PUBLIC \"-//BeVocal Inc//VoiceXML 2.0//EN\"\n";
$vxml .= "\"http://cafe.bevocal.com/libraries/dtd/vxml2-0-bevocal.dtd\">\n";
 
$vxml .= " <vxml version=\"2.0\"\n   application=\"root_project.vxml\"\n";
$vxml .= "xmlns=\"http://www.w3.org/2001/vxml\"\n   xml:lang=\"en-US\">\n";

print 
$vxml;
?>

 
<!-- MAIN_MENU.VXML.PHP -->

<meta name="Voice_RSSProject" content="tomh@aduni.org" /> 

 <link next="main_menu.vxml.php?userid=<?=$user_id?>">
   <grammar type="application/x-nuance-gsl">
     [
       (bevocal reload)
       (dtmf-star dtmf-star dtmf-star)
     ]
   </grammar>
 </link>
 
 <noinput>
   I'm sorry.  I didn't hear anything.
   <reprompt/>
 </noinput>
 
 <nomatch>
   I didn't get that.
   <reprompt/>
 </nomatch>
 
 <property name="universals" value="all" />

 <help>
   I'm sorry. There's no help available here.
 </help>
 

<menu scope = "dialog">

    <prompt>
    Voice RSS main menu for user <?=$str_firstname?> <?=$str_lastname?>.  
    You are currently signed up for <?=$cnt_feeds?> feeds.
    <!--add other user specific information here-->
    Select from: add feeds, change pen, list feeds, or help.
    </prompt>

    <choice dtmf = "1" next = "#addfeeds">
        add feeds
    </choice>

    <choice dtmf = "2" next = "#changepin">
        change pen
    </choice>

    <choice dtmf = "3" next = "#listfeeds">
        list feeds
    </choice>
<?php
//add the feeds here, so that users can actually go to the feed that they want
$dmtf 3;
if (!empty(
$arr_feeds)) {
    foreach (
$arr_feeds as $f_row) {
        
$f_name "";
        
$legal_name "";
    
        foreach (
$f_row as $name=>$value) {
            
$dmtf++;
            if (
$name == "name") {
                
$f_name $value;
                
$legal_name str_replace(" ","",$f_name);
            }
        }
//end of looping through array of database columns
?>
    <choice dtmf = "<?=$dmtf?>" next = "#<?=$legal_name?>">
        <?=$f_name?>
    </choice>
<?php
    
}//end of looping through rows in the database
}//end of checking that it is an array
?>

    <choice dtmf = "0" next = "#help">
        help
    </choice>

</menu>

<form id = "addfeeds">
    <block>

    <if cond = "debug == 'true' ">
        <prompt>
        You selected <emphasis level = "strong"> add feeds</emphasis>.
        </prompt>
    </if>

        <prompt>
        This service is not available.  Returning to
        
        </prompt>

        <goto next = "main_menu.vxml.php?userid=<?=$user_id?>" />

    </block>
</form>


<form id = "changepin">
    <block>

    <if cond = "debug == 'true' ">
        <prompt>
        You selected <emphasis level = "strong"> change pen</emphasis>.
        </prompt>
    </if>

        <prompt>
        This service is not available.  Returning to
        
        </prompt>

        <goto next = "main_menu.vxml.php?userid=<?=$user_id?>" />

    </block>
</form>

<form id = "listfeeds">
    <block>

    <if cond = "debug == 'true' ">
        <prompt>
        You selected <emphasis level = "strong"> list feeds</emphasis>.
        </prompt>
    </if>

        <goto next = "list_feeds.vxml.php?userid=<?=$user_id?>" />

    </block>
</form>
<?php
//go through the array again, so that we can then send the user on to the next step
if (!empty($arr_feeds)) {
    foreach (
$arr_feeds as $f_row) {
        
$f_name "";
        
$legal_name "";
        
$feed_id 0;
        foreach (
$f_row as $name=>$value) {
            
$dmtf++;
            if (
$name == "name") {
                
$f_name $value;
                
$legal_name str_replace(" ","",$f_name);
            }
            if (
$name == "feed_id") {
                
$feed_id $value;
            }
        }
//end of looping through array of database columns
?>
<form id = "<?=$legal_name?>">
    <block>

    <if cond = "debug == 'true' ">
        <prompt>
        You selected <emphasis level = "strong"> <?=$f_name?></emphasis>.
        </prompt>
    </if>

        <goto next = "work_feed.vxml.php?userid=<?=$user_id?>&amp;feedid=<?=$feed_id?>" />

    </block>
</form>

<?php
    
}//end of looping through rows in the database
}//end of checking to see if it's an array
?>
<form id = "help">
    <block>

    <if cond = "debug == 'true' ">
        <prompt>
        You selected <emphasis level = "strong"> help </emphasis>.
        </prompt>
    </if>

        <prompt>
        Sorry.  There is no help available.  Returning to
        
        </prompt>

        <goto next = "main_menu.vxml.php?userid=<?=$user_id?>" />

    </block>
</form>

</vxml>