Documentation is available at backup.php
- <?php
- /*
- Program E related AIML knowledgebase tools
- Copyright 2004, Anne Kootstra [anne@aiml.info]
- http://www.AIML.info
- Program E is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- Program E is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with Program E; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
- // increasing the maximum script time from 30 seconds to 24 hours.
- set_time_limit(86400);
- /**
- * start of the timer sequence of the chatterbot. This will tell you at the
- * end how much time it took to process the log file
- */
- $t_start = array_sum(explode(' ', microtime()));
- // Required files with PHP functions
- require_once "../admin/dbprefs.php";
- require_once "include/retrieve.inc.php";
- require_once "include/common.inc.php";
- require_once "include/backup.inc.php";
- // This is the http_post/get_var
- getRequest("botid", 0);
- // Number of templates to select and process per round.
- $templatesToProcess = 3000;
- // Name of the file in which the backup will be made.
- $backupfile = "backup.aiml";
- // Setting certain needed variables to zero.
- $pid = 0;
- $categories = 0;
- // If not botid is known, present the user with a botselection page
- if(!$botid) {
- // Get an array of bot names and botid's from the database
- $botnames = getbotnames();
- // Put the names and the ID's into a selection form box
- while(list($key, $val) = each($botnames)) {
- if($botid == $key){
- $bots .= "<option value=\"$key\" selected>$val</option>";
- }else{
- $bots .= "<option value=\"$key\">$val</option>";
- }
- }
- // Assign a placeholder in the HTML template to a variable.
- $page['{{bots}}'] = $bots;
- // Select the HTML template and return the completed page to the user's browser
- echo useTemplate('botselect',$page);
- // In this case the PHP script ends processing here.
- return;
- }
- // Open and wipe an existing file or create a new one.
- $fd = fopen($backupfile, "w+");
- // write the AIML file header.
- $fout = fwrite($fd, '<?xml version="1.0" encoding="ISO-8859-1"?>');
- $fout = fwrite($fd, "\n<aiml>\n");
- // Count the number of templates in the templates database.
- $templateCount = count_IDs($botid);
- // Calculate the number of processing cycles.
- $templateCycles = ceil($templateCount/$templatesToProcess);
- // Untill the last processing cycle has been reached ...
- while($pid < $templateCycles) {
- // Get the necessary template ID's and their contents.
- $templateIDs = getTemplateIDs($botid, $pid, $templatesToProcess);
- // Process every template seperately.
- while (list($key, $val) = each($templateIDs)) {
- // Retrieve the AIML pattern (topic, pattern, that) from the pattern table.
- $category = findCategoryPattern($botid, $key);
- // Build the actual AIML category.
- $aiml_cat = makeCategory($category['topic'], $category['that'], $category['pattern'], $val);
- // Write the AIML category to the file
- $fout = fwrite($fd, $aiml_cat);
- // category counter.
- $categories++;
- }
- // Increase the Processing ID, to process the next bunch of templates.
- $pid++;
- }
- // Write the AIML file ending and close it.
- $fout = fwrite($fd, "\n</aiml>\n");
- fclose($fd);
- // calculation of the total time needed to process the script.
- $exec_time = array_sum(explode(' ', microtime())) - $t_start;
- // match the placeholders in the template to
- // a specific PHP variable.
- $page['{{bot_id}}'] = $botid;
- $page['{{templatesToProcess}}'] = $templatesToProcess;
- $page['{{categories}}'] = $categories;
- $page['{{exec_time}}'] = $exec_time;
- // Select the HTML template and return the completed page to the user's browser
- echo useTemplate('backup',$page);
- ?>
Documentation generated on Tue, 11 Jan 2005 18:40:58 +0100 by phpDocumentor 1.3.0RC3