Source for file backup.php

Documentation is available at backup.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. // increasing the maximum script time from 30 seconds to 24 hours.
  23. set_time_limit(86400);
  24.  
  25.  
  26. /**
  27. * start of the timer sequence of the chatterbot. This will tell you at the
  28. * end how much time it took to process the log file
  29. */
  30. $t_start = array_sum(explode(' ', microtime()));
  31.  
  32. // Required files with PHP functions
  33. require_once "../admin/dbprefs.php";
  34. require_once "include/retrieve.inc.php";
  35. require_once "include/common.inc.php";
  36. require_once "include/backup.inc.php";
  37.  
  38. // This is the http_post/get_var
  39. getRequest("botid", 0);
  40.  
  41. // Number of templates to select and process per round.
  42. $templatesToProcess = 3000;
  43.  
  44. // Name of the file in which the backup will be made.
  45. $backupfile = "backup.aiml";
  46.  
  47. // Setting certain needed variables to zero.
  48. $pid = 0;
  49. $categories = 0;
  50.  
  51.  
  52. // If not botid is known, present the user with a botselection page
  53. if(!$botid) {
  54. // Get an array of bot names and botid's from the database
  55. $botnames = getbotnames();
  56. // Put the names and the ID's into a selection form box
  57. while(list($key, $val) = each($botnames)) {
  58. if($botid == $key){
  59. $bots .= "<option value=\"$key\" selected>$val</option>";
  60. }else{
  61. $bots .= "<option value=\"$key\">$val</option>";
  62. }
  63. }
  64. // Assign a placeholder in the HTML template to a variable.
  65. $page['{{bots}}'] = $bots;
  66. // Select the HTML template and return the completed page to the user's browser
  67. echo useTemplate('botselect',$page);
  68.  
  69. // In this case the PHP script ends processing here.
  70. return;
  71.  
  72. }
  73.  
  74. // Open and wipe an existing file or create a new one.
  75. $fd = fopen($backupfile, "w+");
  76.  
  77. // write the AIML file header.
  78. $fout = fwrite($fd, '<?xml version="1.0" encoding="ISO-8859-1"?>');
  79. $fout = fwrite($fd, "\n<aiml>\n");
  80.  
  81. // Count the number of templates in the templates database.
  82. $templateCount = count_IDs($botid);
  83.  
  84. // Calculate the number of processing cycles.
  85. $templateCycles = ceil($templateCount/$templatesToProcess);
  86.  
  87. // Untill the last processing cycle has been reached ...
  88. while($pid < $templateCycles) {
  89.  
  90. // Get the necessary template ID's and their contents.
  91. $templateIDs = getTemplateIDs($botid, $pid, $templatesToProcess);
  92.  
  93. // Process every template seperately.
  94. while (list($key, $val) = each($templateIDs)) {
  95. // Retrieve the AIML pattern (topic, pattern, that) from the pattern table.
  96. $category = findCategoryPattern($botid, $key);
  97. // Build the actual AIML category.
  98. $aiml_cat = makeCategory($category['topic'], $category['that'], $category['pattern'], $val);
  99. // Write the AIML category to the file
  100. $fout = fwrite($fd, $aiml_cat);
  101. // category counter.
  102. $categories++;
  103.  
  104. }
  105. // Increase the Processing ID, to process the next bunch of templates.
  106. $pid++;
  107. }
  108.  
  109. // Write the AIML file ending and close it.
  110. $fout = fwrite($fd, "\n</aiml>\n");
  111. fclose($fd);
  112.  
  113. // calculation of the total time needed to process the script.
  114. $exec_time = array_sum(explode(' ', microtime())) - $t_start;
  115.  
  116. // match the placeholders in the template to
  117. // a specific PHP variable.
  118.  
  119. $page['{{bot_id}}'] = $botid;
  120. $page['{{templatesToProcess}}'] = $templatesToProcess;
  121. $page['{{categories}}'] = $categories;
  122. $page['{{exec_time}}'] = $exec_time;
  123.  
  124.  
  125. // Select the HTML template and return the completed page to the user's browser
  126. echo useTemplate('backup',$page);
  127. ?>

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