Source for file menu.inc.php

Documentation is available at menu.inc.php

  1. <?php
  2.  
  3. /*
  4. Program E related AIML knowledgebase tools
  5. Copyright 2004, Anne Kootstra [anne@aiml.info]
  6. http://www.AIML.info
  7. Program E is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. Program E is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Program E; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21.  
  22. $settings['menuItems'] = '5';
  23.  
  24.  
  25. function getFirstWords($strFirstChar, $botid, $pid) {
  26.  
  27. global $settings;
  28.  
  29. $strSQLfirsWords = "
  30. SELECT
  31. DISTINCT SUBSTRING_INDEX(pattern, ' ', 1) AS firstWords
  32. FROM templates
  33. WHERE
  34. bot = ".$botid." AND
  35. pattern REGEXP '^".$strFirstChar."'
  36. ORDER BY
  37. firstWords ASC
  38. LIMIT ".$pid * $settings['menuItems'].",".(($pid + 1) * $settings['menuItems']).";";
  39.  
  40. debugger($strSQLfirsWords,2);
  41. $selectcode = mysql_query($strSQLfirsWords);
  42. if ($selectcode){
  43. if(!mysql_numrows($selectcode)){
  44. return "";
  45. }
  46. else{
  47. while ($q = mysql_fetch_row($selectcode)){
  48. $result[] = $q[0];
  49. }
  50. return $result;
  51. }
  52. }
  53.  
  54. return "";
  55. }
  56.  
  57.  
  58. function getNode($strPattern, $botid, $pid) {
  59.  
  60. global $settings;
  61.  
  62. $pid = $pid - 1;
  63.  
  64. $quer = "set @strPat = '1';";
  65. $que2 = "select botname from bots where id = @strPat;";
  66.  
  67. $strSQLsetVar = "
  68. SET
  69. @strPattern = TRIM(UCASE('".$strPattern."')),
  70.  
  71. @intWords = LENGTH(@strPattern) - LENGTH(REPLACE(@strPattern, ' ', '')) + 1;";
  72.  
  73. $strSQLnodes = "
  74.  
  75. SELECT
  76. SUBSTRING_INDEX(
  77. SUBSTRING_INDEX(
  78. pattern,
  79. ' ',
  80. @intWords +1
  81. ),
  82. ' ',
  83. -1
  84. ) AS word,
  85.  
  86. IF(
  87. LENGTH(pattern) - LENGTH(REPLACE(pattern, ' ', '')) = @intWords,
  88. 1,
  89. 0
  90. ) AS isend,
  91.  
  92. COUNT(pattern) AS no_nodes,
  93.  
  94. IF(
  95. LENGTH(pattern) - LENGTH(REPLACE(pattern, ' ', '')) = @intWords || COUNT(pattern) = 1,
  96. id,
  97. null
  98. ) AS template_id,
  99.  
  100. MAX(LENGTH(pattern) - LENGTH(REPLACE(pattern, ' ', ''))) + 1 AS max_words
  101. FROM
  102. templates
  103. WHERE
  104. SUBSTRING_INDEX(pattern, ' ', @intWords) like @strPattern AND
  105. pattern != @strPattern AND
  106. bot = ".$botid."
  107. GROUP BY
  108. word
  109. ORDER BY
  110. word ASC
  111. LIMIT ".$pid * $settings['menuItems'].",".(($pid + 1) * $settings['menuItems']).";";
  112. //echo "$strSQLsetVar $strSQLnodes";
  113. debugger($strSQLnodes,2);
  114. $selectcode = mysql_query($strSQLsetVar);
  115. $selectcode = mysql_query($strSQLnodes);
  116. if ($selectcode){
  117. if(!mysql_numrows($selectcode)){
  118. //die('<br/><br/><br/>Invalid query: ' . mysql_error());
  119. return "";
  120. }
  121. else{
  122. $x = 0;
  123. while ($q = mysql_fetch_array($selectcode)){
  124. $result[$x]['word'] = $q['word'];
  125. $result[$x]['isend'] = $q['isend'];
  126. $result[$x]['no_nodes'] = $q['no_nodes'];
  127. $result[$x]['template_id'] = $q['template_id'];
  128. $result[$x]['max_words'] = $q['max_words'];
  129. $x++;
  130. }
  131. return $result;
  132. }
  133. }
  134. return "";
  135.  
  136. }
  137.  
  138.  
  139.  
  140. function getBotName($botid){
  141.  
  142. $query = "select botname from bots where id=".$botid."";
  143. debugger($query,2);
  144. $selectcode = mysql_query($query);
  145. if ($selectcode){
  146. if(!mysql_numrows($selectcode)){
  147. return "";
  148. }
  149. else{
  150. while ($q = mysql_fetch_array($selectcode)){
  151. return $q[0];
  152. }
  153. }
  154. }
  155.  
  156. return "";
  157. }
  158. ?>

Documentation generated on Tue, 11 Jan 2005 18:41:07 +0100 by phpDocumentor 1.3.0RC3