Location: PHPKode > projects > Program E > docs/developer/__filesource/fsource_Interpreter_Responder_talk.php.html
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
		<head>
			<!-- template designed by Marco Von Ballmoos  -->
			<title>File Source for talk.php</title>
			<link rel="stylesheet" href="../media/stylesheet.css" />
											</head>
		<body>
						
<h1>Source for file talk.php</h1>
<p>Documentation is available at <a href="../Interpreter/Responder/_talk_php.html">talk.php</a></p>
<div class="src-code">
<pre><ol><li><a name="a1"></a><span class="src-php">&lt;?php</span></li>
<li><a name="a2"></a>&nbsp;</li>
<li><a name="a3"></a><span class="src-comm">/*</span></li>
<li><a name="a4"></a><span class="src-comm">    Program E</span></li>
<li><a name="a5"></a><span class="src-comm">    Copyright 2002, Paul Rydell</span></li>
<li><a name="a6"></a>&nbsp;</li>
<li><a name="a7"></a><span class="src-comm">    This file is part of Program E.</span></li>
<li><a name="a8"></a>    </li>
<li><a name="a9"></a><span class="src-comm">    Program E is free software; you can redistribute it and/or modify</span></li>
<li><a name="a10"></a><span class="src-comm">    it under the terms of the GNU General Public License as published by</span></li>
<li><a name="a11"></a><span class="src-comm">    the Free Software Foundation; either version 2 of the License, or</span></li>
<li><a name="a12"></a><span class="src-comm">    (at your option) any later version.</span></li>
<li><a name="a13"></a>&nbsp;</li>
<li><a name="a14"></a><span class="src-comm">    Program E is distributed in the hope that it will be useful,</span></li>
<li><a name="a15"></a><span class="src-comm">    but WITHOUT ANY WARRANTY; without even the implied warranty of</span></li>
<li><a name="a16"></a><span class="src-comm">    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span></li>
<li><a name="a17"></a><span class="src-comm">    GNU General Public License for more details.</span></li>
<li><a name="a18"></a>&nbsp;</li>
<li><a name="a19"></a><span class="src-comm">    You should have received a copy of the GNU General Public License</span></li>
<li><a name="a20"></a><span class="src-comm">    along with Program E; if not, write to the Free Software</span></li>
<li><a name="a21"></a><span class="src-comm">    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span></li>
<li><a name="a22"></a><span class="src-comm">*/</span></li>
<li><a name="a23"></a>&nbsp;</li>
<li><a name="a24"></a><span class="src-doc">/**</span></li>
<li><a name="a25"></a><span class="src-doc"> * HTML chat interface</span></li>
<li><a name="a26"></a><span class="src-doc"> * </span></li>
<li><a name="a27"></a><span class="src-doc"> * Contains the script that outputs the HTML interface for chatting</span></li>
<li><a name="a28"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@author</span><span class="src-doc"> Paul Rydell</span></li>
<li><a name="a29"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@copyright</span><span class="src-doc"> 2002</span></li>
<li><a name="a30"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@version</span><span class="src-doc"> 0.0.8</span></li>
<li><a name="a31"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@package</span><span class="src-doc"> Interpreter</span></li>
<li><a name="a32"></a><span class="src-doc"> * </span><span class="src-doc-coretag">@subpackage</span><span class="src-doc"> Responder</span></li>
<li><a name="a33"></a><span class="src-doc"> */</span></li>
<li><a name="a34"></a>&nbsp;</li>
<li><a name="a35"></a>&nbsp;</li>
<li><a name="a36"></a><span class="src-doc">/**</span></li>
<li><a name="a37"></a><span class="src-doc">* Include the guts of the program.</span></li>
<li><a name="a38"></a><span class="src-doc">*/</span></li>
<li><a name="a39"></a><span class="src-inc">include </span><span class="src-str">&quot;respond.php&quot;</span><span class="src-sym">;</span></li>
<li><a name="a40"></a>&nbsp;</li>
<li><a name="a41"></a><span class="src-key">if </span><span class="src-sym">(</span>isset<span class="src-sym">(</span><span class="src-var">$HTTP_POST_VARS</span><span class="src-sym">[</span><span class="src-str">'input'</span><span class="src-sym">]</span><span class="src-sym">))</span><span class="src-sym">{</span></li>
<li><a name="a42"></a>&nbsp;</li>
<li><a name="a43"></a>    <span class="src-var">$numselects</span>=<span class="src-num">0</span><span class="src-sym">;</span></li>
<li><a name="a44"></a>&nbsp;</li>
<li><a name="a45"></a>    <span class="src-comm">// Start the session or get the existing session.</span></li>
<li><a name="a46"></a>    <a href="http://www.php.net/session_start">session_start</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a47"></a>    <span class="src-var">$myuniqueid</span>=<a href="http://www.php.net/session_id">session_id</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a48"></a>&nbsp;</li>
<li><a name="a49"></a>    <span class="src-comm">// Here is where we get the reply.</span></li>
<li><a name="a50"></a>    <span class="src-var">$botresponse</span>=<a href="../Interpreter/_respond_php.html#functionreplybotname">replybotname</a><span class="src-sym">(</span><span class="src-var">$HTTP_POST_VARS</span><span class="src-sym">[</span><span class="src-str">'input'</span><span class="src-sym">]</span><span class="src-sym">,</span><span class="src-var">$myuniqueid</span><span class="src-sym">,</span><span class="src-var">$HTTP_POST_VARS</span><span class="src-sym">[</span><span class="src-str">'botname'</span><span class="src-sym">]</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a51"></a>&nbsp;</li>
<li><a name="a52"></a>    <span class="src-comm">// Print the results.</span></li>
<li><a name="a53"></a>    print <span class="src-str">&quot;&lt;B&gt;RESPONSE: &quot; </span>. <span class="src-var">$botresponse</span><span class="src-sym">-&gt;</span><span class="src-id">response </span>. <span class="src-str">&quot;&lt;BR&gt;&lt;/b&gt;&quot;</span><span class="src-sym">;</span></li>
<li><a name="a54"></a>    print <span class="src-str">&quot;&lt;BR&gt;&lt;BR&gt;execution time: &quot; </span>. <span class="src-var">$botresponse</span><span class="src-sym">-&gt;</span><span class="src-id">timer</span><span class="src-sym">;</span></li>
<li><a name="a55"></a>    print <span class="src-str">&quot;</span>&lt;<span class="src-id">BR</span>&gt;<span class="src-id">numselects</span>= <span class="src-var">$numselects</span><span class="src-str">&quot;</span><span class="src-sym">;</span></li>
<li><a name="a56"></a>&nbsp;</li>
<li><a name="a57"></a>    <span class="src-comm">//print_r($botresponse-&gt;inputs);</span></li>
<li><a name="a58"></a><span class="src-comm">//print_r($botresponse-&gt;patternsmatched);</span></li>
<li><a name="a59"></a>&nbsp;</li>
<li><a name="a60"></a>    <span class="src-comm">// Include a form so they can say more. Note the hidden part for people that do not have trans sid on but want non-cookie users to be able to use the system.</span></li>
<li><a name="a61"></a>&nbsp;</li>
<li><a name="a60"></a>    </li>
<li><a name="a61"></a>&nbsp;</li>
<li><a name="a62"></a>    <span class="src-php">?&gt;</span></li>
<li><a name="a63"></a>&nbsp;</li>
<li><a name="a64"></a>    &lt;html&gt;</li>
<li><a name="a65"></a>    &lt;head&gt;</li>
<li><a name="a66"></a>    &lt;title&gt;Sample talk to Program E page&lt;/title&gt;</li>
<li><a name="a67"></a>    &lt;/head&gt;</li>
<li><a name="a68"></a>    &lt;body&gt;</li>
<li><a name="a69"></a>    &lt;form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;talk.php&quot;&gt;</li>
<li><a name="a70"></a>    &lt;input type=&quot;hidden&quot; name=&quot;<span class="src-php">&lt;?=</span><a href="http://www.php.net/session_name">session_name</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-php">?&gt;</span>&quot; value=&quot;<span class="src-php">&lt;?=</span><span class="src-var">$uid</span><span class="src-php">?&gt;</span>&quot;&gt;</li>
<li><a name="a71"></a>    &lt;input type=&quot;hidden&quot; name=&quot;botname&quot; value=&quot;<span class="src-php">&lt;?=</span><span class="src-var">$HTTP_POST_VARS</span><span class="src-sym">[</span><span class="src-str">'botname'</span><span class="src-sym">]</span><span class="src-php">?&gt;</span>&quot;&gt;</li>
<li><a name="a72"></a>      Input: &lt;input type=&quot;text&quot; name=&quot;input&quot; size=&quot;55&quot;&gt;</li>
<li><a name="a73"></a>&nbsp;</li>
<li><a name="a74"></a>      &lt;input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot;&gt;</li>
<li><a name="a75"></a>    &lt;/form&gt;</li>
<li><a name="a76"></a>    &lt;/body&gt;</li>
<li><a name="a77"></a>    &lt;/html&gt;</li>
<li><a name="a78"></a>&nbsp;</li>
<li><a name="a79"></a><span class="src-php">&lt;?</span></li>
<li><a name="a80"></a><span class="src-sym">}</span></li>
<li><a name="a81"></a><span class="src-key">else </span><span class="src-sym">{</span></li>
<li><a name="a82"></a>&nbsp;</li>
<li><a name="a83"></a>    <span class="src-var">$availbots</span>=<span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a84"></a>&nbsp;</li>
<li><a name="a85"></a>    <span class="src-comm">// Get all the names of our bots.</span></li>
<li><a name="a86"></a>    <span class="src-var">$query</span>=<span class="src-str">&quot;select botname from bots&quot;</span><span class="src-sym">;</span></li>
<li><a name="a87"></a>&nbsp;</li>
<li><a name="a88"></a>    <span class="src-var">$selectcode </span>= <a href="http://www.php.net/mysql_query">mysql_query</a><span class="src-sym">(</span><span class="src-var">$query</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a89"></a>&nbsp;</li>
<li><a name="a90"></a>    <span class="src-key">if </span><span class="src-sym">(</span><span class="src-var">$selectcode</span><span class="src-sym">)</span><span class="src-sym">{</span></li>
<li><a name="a91"></a>        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">!</span><a href="http://www.php.net/mysql_numrows">mysql_numrows</a><span class="src-sym">(</span><span class="src-var">$selectcode</span><span class="src-sym">))</span><span class="src-sym">{</span></li>
<li><a name="a92"></a>        <span class="src-sym">}</span></li>
<li><a name="a93"></a>        <span class="src-key">else</span><span class="src-sym">{</span></li>
<li><a name="a94"></a>            <span class="src-key">while </span><span class="src-sym">(</span><span class="src-var">$q </span>= <a href="http://www.php.net/mysql_fetch_array">mysql_fetch_array</a><span class="src-sym">(</span><span class="src-var">$selectcode</span><span class="src-sym">))</span><span class="src-sym">{</span></li>
<li><a name="a95"></a>                <span class="src-var">$availbots</span><span class="src-sym">[</span><span class="src-sym">]</span>=<span class="src-var">$q</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a96"></a>            <span class="src-sym">}</span></li>
<li><a name="a97"></a>        <span class="src-sym">}</span></li>
<li><a name="a98"></a>    <span class="src-sym">}</span></li>
<li><a name="a99"></a>&nbsp;</li>
<li><a name="a100"></a>    <span class="src-php">?&gt;</span></li>
<li><a name="a101"></a>&nbsp;</li>
<li><a name="a102"></a>    &lt;html&gt;</li>
<li><a name="a103"></a>    &lt;head&gt;</li>
<li><a name="a104"></a>    &lt;title&gt;Program E Tester&lt;/title&gt;</li>
<li><a name="a105"></a>    &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;&gt;</li>
<li><a name="a106"></a>    &lt;/head&gt;</li>
<li><a name="a107"></a>&nbsp;</li>
<li><a name="a108"></a>    &lt;body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;&gt;</li>
<li><a name="a109"></a>    &lt;form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;talk.php&quot;&gt;</li>
<li><a name="a110"></a>&nbsp;</li>
<li><a name="a111"></a>    Talk to: &lt;select name=&quot;botname&quot;&gt;</li>
<li><a name="a112"></a>    <span class="src-php">&lt;? </span></li>
<li><a name="a113"></a>    <span class="src-key">foreach </span><span class="src-sym">(</span><span class="src-var">$availbots </span><span class="src-key">as </span><span class="src-var">$onebot</span><span class="src-sym">)</span><span class="src-sym">{</span></li>
<li><a name="a114"></a>        print <span class="src-str">&quot;</span>&lt;<span class="src-id">option value</span>=\&quot;<span class="src-var">$onebot</span>\&quot;&gt;<span class="src-var">$onebot</span>&lt;/<span class="src-id">option</span>&gt;<span class="src-str">&quot;</span><span class="src-sym">;</span></li>
<li><a name="a115"></a>    <span class="src-sym">}</span></li>
<li><a name="a116"></a>    <span class="src-php">?&gt;</span></li>
<li><a name="a117"></a>    &lt;/select&gt;&lt;BR&gt;</li>
<li><a name="a118"></a>&nbsp;</li>
<li><a name="a119"></a>      Input: &lt;input type=&quot;text&quot; name=&quot;input&quot; size=&quot;55&quot;&gt;</li>
<li><a name="a120"></a>&nbsp;</li>
<li><a name="a121"></a>      &lt;input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot;&gt;</li>
<li><a name="a122"></a>    &lt;/form&gt;</li>
<li><a name="a123"></a>      </li>
<li><a name="a124"></a>    &lt;/body&gt;</li>
<li><a name="a125"></a>    &lt;/html&gt;</li>
<li><a name="a126"></a>&nbsp;</li>
<li><a name="a127"></a>    <span class="src-php">&lt;?</span></li>
<li><a name="a128"></a>&nbsp;</li>
<li><a name="a129"></a><span class="src-sym">}</span></li>
<li><a name="a130"></a>&nbsp;</li>
<li><a name="a131"></a><span class="src-php">?&gt;</span></li>
</ol></pre>
</div>
	<p class="notes" id="credit">
		Documentation generated on Wed, 12 Jan 2005 12:24:49 +0100 by <a href="http://www.phpdoc.org" target="_blank">phpDocumentor 1.3.0RC3</a>
	</p>
	</body>
</html>
Return current item: Program E