<?php
define
('MAGPIE_DIR''magpie/');
require_once(
MAGPIE_DIR.'rss_fetch.inc');
require_once(
'array_change_key_case.php');

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

$user_id 0;
$feed_id 0;
$f_name "slashdot";
$f_url "http://slashdot.org/index.rss";//default url chosen so that magpie won't barf
$u_email "";
$PARAMS = (count($HTTP_POST_VARS)) ? $HTTP_POST_VARS $HTTP_GET_VARS;
//pull the user and feed ids from the p-reg split of two ids
foreach ($PARAMS as $key=>$value) {
    if (
$key=='userid') {
        
$user_id=$value;
    }
    if (
$key=='feedid') {
        
$feed_id=$value;
    }
}

//hit the database to find out which user and which feed we are talking about
$arr_users $dl->select("tbl_users""user_id = $user_id");
$arr_feed $dl->select("tbl_feeds""feed_id = $feed_id");

if (!empty(
$arr_feed)) {//better not be empty though
    
foreach ($arr_feed as $f_row) {
        foreach (
$f_row as $name=>$val) {
            if (
$name == "name") {
                
$f_name $val;
                
$legal_name str_replace(" ","",$f_name);
            }
            if (
$name == "url") {
                
$f_url $val;
            }
        }
    }
}

if (!empty(
$arr_users)) {
    foreach (
$arr_users as $u_row) {
        foreach (
$u_row as $name=>$val) {
            if (
$name == "email") {
                
$u_email $val;
            }
            if (
$name == "title") { 
                
$u_title $val
            }
            if (
$name == "first_name") { 
                
$str_firstname $val
            }
            if (
$name == "last_name") { 
                
$str_lastname $val
            }
        }
    }
}
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;
?>

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

 <link next="work_feed.vxml.php?userid=<?=$user_id?>&amp;feedid=<?=$feed_id?>">
   <grammar type="application/x-nuance-gsl">
     [
       (bevocal reload)
       (dtmf-star dtmf-star dtmf-star)
       (menu)
     ]
   </grammar>
 </link>

 <link next="main_menu.vxml.php?userid=<?=$user_id?>">
   <grammar type="application/x-nuance-gsl">
     [
       (back)
     ]
   </grammar>
 </link>

  <property name="universals" value="all" />

  <form scope="dialog">
    <!--do this next, tbh-->
    <grammar type="application/x-nuance-gsl"> 
      <![CDATA[
      Request ([mail {<mail true>} 
                describe {<describe true>}] 
                Option 
                ?and ?Option 
                ?and ?Option
                ?and ?Option
                ?and ?Option
                ?and ?Option
                ?and ?Option
                ?and ?Option
                ?and ?Option
                ?and ?Option)
      Option ([one {<one true>}
               two {<two true>}
               three {<three true>}
               four {<four true>}
               five {<five true>}
               six {<six true>}
               seven {<seven true>}
               eight {<eight true>}
               nine {<nine true>}
               ten {<ten true>}
              ])
        ]]>
      </grammar>
      <help>
        Please say 'mail' or 'describe' and one of the numbers of the article.  For
        example, 'mail one' or 'describe three'.
      </help>

    <initial>
      <prompt>
        You selected the <?=$f_name?> feed.
        Please say 'mail' or 'describe' and pick one of the next article numbers in your feed:
        <?php
            $rss 
fetch_rss($f_url);
            
$items array_slice($rss->items010);
            
$cnt_items 0;
            if (!empty(
$items)) {
                foreach (
$items as $item) {
                    
$title $item['title'];
                    
$cnt_items++;
                    print 
"$cnt_items.  $title.  <break size=\"medium\"/>";
                }
//end of foreach
            
}//end of check for empty
        
?>
    
      </prompt>
     </initial>

     <field name="mail" type="boolean"> </field>
     <field name="describe" type="boolean"> </field>
     <field name="one" type="boolean"> </field>
     <field name="two" type="boolean"> </field>
     <field name="three" type="boolean"> </field>
     <field name="four" type="boolean"> </field>
     <field name="five" type="boolean"> </field>
     <field name="six" type="boolean"> </field>
     <field name="seven" type="boolean"> </field>
     <field name="eight" type="boolean"> </field>
     <field name="nine" type="boolean"> </field>
     <field name="ten" type="boolean"> </field>
            <!-- if the user gave a valid response, the filled block
           is executed. -->
      <filled mode="any">
        <if cond="mail">
            
            <if cond="one">
                <goto next="goto_mail_feed.vxml.php?userid=<?=$user_id?>&amp;feedid=<?=$feed_id?>&amp;feednum=0"/>
                
            </if>
            <if cond="two">
                <goto next="goto_mail_feed.vxml.php?userid=<?=$user_id?>&amp;feedid=<?=$feed_id?>&amp;feednum=1"/>
            </if>
            <if cond="three">
                <goto next="goto_mail_feed.vxml.php?userid=<?=$user_id?>&amp;feedid=<?=$feed_id?>&amp;feednum=2"/>
            </if>
            <if cond="four">
                <goto next="goto_mail_feed.vxml.php?userid=<?=$user_id?>&amp;feedid=<?=$feed_id?>&amp;feednum=3"/>
            </if>
            <if cond="five">
                <goto next="goto_mail_feed.vxml.php?userid=<?=$user_id?>&amp;feedid=<?=$feed_id?>&amp;feednum=4"/>
            </if>
            <if cond="six">
                <goto next="goto_mail_feed.vxml.php?userid=<?=$user_id?>&amp;feedid=<?=$feed_id?>&amp;feednum=5"/>
            </if>
            <if cond="seven">
                <goto next="goto_mail_feed.vxml.php?userid=<?=$user_id?>&amp;feedid=<?=$feed_id?>&amp;feednum=6"/>
            </if>
            <if cond="eight">
                <goto next="goto_mail_feed.vxml.php?userid=<?=$user_id?>&amp;feedid=<?=$feed_id?>&amp;feednum=7"/>
            </if>
            <if cond="nine">
                <goto next="goto_mail_feed.vxml.php?userid=<?=$user_id?>&amp;feedid=<?=$feed_id?>&amp;feednum=8"/>
            </if>
            <if cond="ten">
                <goto next="goto_mail_feed.vxml.php?userid=<?=$user_id?>&amp;feedid=<?=$feed_id?>&amp;feednum=9"/>
            </if>
            
        </if>

        <if cond="describe">
            
            <if cond="one">
                <goto next="goto_desc_feed.vxml.php?userid=<?=$user_id?>&amp;feedid=<?=$feed_id?>&amp;feednum=0"/>
            <elseif cond="two"/>
                <goto next="goto_desc_feed.vxml.php?userid=<?=$user_id?>&amp;feedid=<?=$feed_id?>&amp;feednum=1"/>    
            <elseif cond="three"/>
                <goto next="goto_desc_feed.vxml.php?userid=<?=$user_id?>&amp;feedid=<?=$feed_id?>&amp;feednum=2"/>
            <elseif cond="four"/>
                <goto next="goto_desc_feed.vxml.php?userid=<?=$user_id?>&amp;feedid=<?=$feed_id?>&amp;feednum=3"/>
            <elseif cond="five"/>
                <goto next="goto_desc_feed.vxml.php?userid=<?=$user_id?>&amp;feedid=<?=$feed_id?>&amp;feednum=4"/>
            <elseif cond="six"/>
                <goto next="goto_desc_feed.vxml.php?userid=<?=$user_id?>&amp;feedid=<?=$feed_id?>&amp;feednum=5"/>
            <elseif cond="seven"/>
                <goto next="goto_desc_feed.vxml.php?userid=<?=$user_id?>&amp;feedid=<?=$feed_id?>&amp;feednum=6"/>
            <elseif cond="eight"/>
                <goto next="goto_desc_feed.vxml.php?userid=<?=$user_id?>&amp;feedid=<?=$feed_id?>&amp;feednum=7"/>
            <elseif cond="nine"/>
                <goto next="goto_desc_feed.vxml.php?userid=<?=$user_id?>&amp;feedid=<?=$feed_id?>&amp;feednum=8"/>
            <elseif cond="ten"/>
                <goto next="goto_desc_feed.vxml.php?userid=<?=$user_id?>&amp;feedid=<?=$feed_id?>&amp;feednum=9"/>
            </if>
            
        </if>

      </filled>

      <nomatch>
        I'm sorry, I didn't understand what you said.
        <reprompt/>
      </nomatch>
      
      <noinput>
        I'm sorry, I didn't hear you.
        <reprompt/>
      </noinput>
 
  </form>
  
 


 </vxml>