diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..412eeda --- /dev/null +++ b/.gitattributes @@ -0,0 +1,22 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp +*.sln merge=union +*.csproj merge=union +*.vbproj merge=union +*.fsproj merge=union +*.dbproj merge=union + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8372746 --- /dev/null +++ b/.gitignore @@ -0,0 +1,180 @@ +################# +## Program O +################# + +*.log +admin/error.log +admin/skins +admin/downloads +config/global_config.php +config/error.log +config/*.txt +config/uploads/* +chatbot/debug/*.txt +test +logs/*.log +logs/*.txt + +################# +## Eclipse +################# + +*.pydevproject +.project +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.classpath +.settings/ +.loadpath + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# PDT-specific +.buildpath + + +################# +## Visual Studio +################# + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results +[Dd]ebug/ +[Rr]elease/ +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.vspscc +.builds +*.dotCover + +## TODO: If you have NuGet Package Restore enabled, uncomment this +#packages/ + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf + +# Visual Studio profiler +*.psess +*.vsp + +# ReSharper is a .NET coding add-in +_ReSharper* + +# Installshield output folder +[Ee]xpress + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish + +# Others +[Bb]in +[Oo]bj +sql +TestResults +*.Cache +ClientBin +stylecop.* +~$* +*.dbmdl +Generated_Code #added for RIA/Silverlight projects + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML + + + +############ +## Windows +############ + +# Windows image file caches +Thumbs.db + +# Folder config file +Desktop.ini + + +############# +## Python +############# + +*.py[co] + +# Packages +*.egg +*.egg-info +dist +build +eggs +parts +bin +var +sdist +develop-eggs +.installed.cfg + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox + +#Translations +*.mo + +#Mr Developer +.mr.developer.cfg + +# Mac crap +.DS_Store diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 0000000..1daba46 --- /dev/null +++ b/CHANGELOG @@ -0,0 +1,56 @@ +/*************************************** +* http://www.program-o.com +* PROGRAM O +* Version: 2.0.9 +* FILE: CHANGELOG +* AUTHOR: ELIZABETH PERREAU AND DAVE MORTON +* DATE: 01-02-2013 +* DETAILS: Describes the version changes in Program O +***************************************/ + +Version History: + +2.0.9 Feature Update + 1.) Added a function to the admin page to poll GitHub for the current release version, and notify + the botmaster if a new version is available, providing a link to the latest version. + +2.0.8 Performed the following upgrades/fixes: + 1.) Added version information to the admin page. so that botmasters can see at a glance which version + they're using. This is a prelude to a new "version check" feature that I'm working on. + 2.) Corrected a bug where changing the bot's default page format wasn't being reflected in the config + file. PLEASE NOTE that if you have several chatbots, this will affect ALL of them, but if that's + the case, you shouldn't be relying on the default chatbot page anyway. + +2.0.7 Two major changes, this time: + 1.) Removed some settings from the install script that had been causing new chatbots to + fail to respond. These settings are still available in the admin pages, but during installation + are given default values. + 2.) Added support for uploading ZIP file archives of AIML files, to make the process of adding + AIML files less faster and less tedious. the size limit for uploading files is still 2MB, + but a 2MB ZIP file can hold a LOT of AIML files. + +2.0.6 Performed the following upgrades/fixes: + 1.) Corrected typographical errors in several files, both in the admin pages, and in the config files. + 2.) Consolidated error logging, adding a /logs/ folder to the base directory. Error logs are + also named for the pages where the errors occur. (e.g. admin-error.log for the admin pages, + install-error.log, etc.) + 3.) Updated the addon checkForBan, activating it, and adding functionality to add banned users + to the list of banned IP addresses. It's still up to the botmaster to implement banning in + their AIML files. To ban a user, insert the following into the apropriate AIML template: + + For further assistance, please check out the Program O Support Forums. + +2.0.5 Fixed a bug where uploaded AIML files were not being added to the DB, even if they passed validation. + Also added the variable $default_charset to allow character encoding other than UTF-8 for both AIML + files and chatbot pages. Further, experimental support for international characters has been added. + This is far from it's "final" implementation, but we hope that it's a start. + +2.0.4 Fixed a bug in the debugging functions that caused empty debugging files to be created on non-Windows systems + +2.0.3 Added simple AIML validation to the upload script, and restyled the admin pages accordingly + +2.0.2 Unspecified Bug fixes + +2.0.1 Unspecified Bug fixes + +2.0.0 Initial Release diff --git a/README b/README index e8cccb5..5271c4c 100644 --- a/README +++ b/README @@ -1,49 +1,55 @@ -/******************************************************** -* http://www.program-o.com -* PROGRAM O -* Version: 2.0.1 -* README -********************************************************/ - -Introduction ---------------------------------------------------------- -Program O is an AIML interpretor written in PHP -The bot engine sits in the /chatbot/ directory -The admin area can be found in the /admin/ directory -Functions used by the bot and the admin area are in the /library/ directory -Any optional addons are found in the /chatbot/addons/ directory - -Configuration ---------------------------------------------------------- -v2.0.1 has support for multiple bots -Configuration of the individual bots is done from inside the admin area. -Bot specific variables are stored in the database. -Configuration of Program O itself is done in /config/global_config.php - -Using the bot ---------------------------------------------------------- -After installation you can chat to Program O in one of 3 ways --HTML form (example in /gui/plain/index.php or /gui/pretty/index.php or /gui/jquery/index.php) --HTML form using CURL (return response in XML or JSON) (example in /gui/htmltoxml/index.php) --send XML using CURL (return response in XML or JSON) (example in /gui/xml/index.php) - -Upgrade ---------------------------------------------------------- -If you are upgrading from v1 you will need to make the following changes to the db -Back up your old files then overwrite with the new ones - -Clean install ---------------------------------------------------------- -v2.0.1 has an automatic installer for clean installation. -Simply point your web browser to your freshly uploaded -Program O directory to run the install script. Then -follow the instructions on the page. The installer is -designed to only run once. -Please note that the installer script will NOT install your -bot's AIML files. Once you complete the installation -process, simply go to your new Program O admin page -(e.g. http://www.example.com/ProgramO/admin) and log -in using the admin credentials you provided during the -install process. Then select "Upload AIML" from the -navigation link on the left and upload your AIML files. +/******************************************************** +* http://www.program-o.com +* PROGRAM O +* Version: 2.0.9 +* README +********************************************************/ + +Introduction +--------------------------------------------------------- +Program O is an AIML interpretor written in PHP +The bot engine sits in the /chatbot/ directory +The admin area can be found in the /admin/ directory +Functions used by the bot and the admin area are in the /library/ directory +Any optional addons are found in the /chatbot/addons/ directory + +Configuration +--------------------------------------------------------- +v2.0.1 has support for multiple bots +Configuration of the individual bots is done from inside the admin area. +Bot specific variables are stored in the database. +Configuration of Program O itself is done in /config/global_config.php + +Using the bot +--------------------------------------------------------- +After installation you can chat to Program O in one of 3 ways +-HTML form (example in /gui/plain/index.php) +-HTML form using AJAX (example in /gui/jquery/index.php) +-send XML using CURL (return response in XML or JSON) (example in /gui/xml/index.php) + +Upgrade +--------------------------------------------------------- +If you are upgrading from v1 you will need to make the following changes to the db +Back up your old files then overwrite with the new ones + +Clean install +--------------------------------------------------------- +v2.0.1 has an automatic installer for clean installation. +Simply point your web browser to your freshly uploaded +Program O directory to run the install script. Then +follow the instructions on the page. The installer is +designed to only run once. + +Please note that the installer script will NOT create your +database for you, nor will it install your bot's AIML files. +The database, along with the username/password used to +access it, needs to be created in advance. See the file +fresh_install_README.txt for more information. + +After you create the database, and once you complete the +installation process, simply go to your new Program O +admin page (e.g. http://www.example.com/ProgramO/admin) +and log in using the admin credentials you provided during +the install process. Then select "Upload AIML" from the +navigation link on the left and upload your AIML files. Then sit back and enjoy your new bot! \ No newline at end of file diff --git a/UPGRADE_README b/UPGRADE_README new file mode 100644 index 0000000..fcc39fe --- /dev/null +++ b/UPGRADE_README @@ -0,0 +1 @@ +Coming soon. \ No newline at end of file diff --git a/admin/.htaccess b/admin/.htaccess deleted file mode 100644 index 10eda69..0000000 --- a/admin/.htaccess +++ /dev/null @@ -1,25 +0,0 @@ -ErrorDocument 400 /Program_O/test/myError.php -ErrorDocument 401 /Program_O/test/myError.php -ErrorDocument 402 /Program_O/test/myError.php -ErrorDocument 403 /Program_O/test/myError.php -ErrorDocument 404 /Program_O/test/myError.php -ErrorDocument 405 /Program_O/test/myError.php -ErrorDocument 406 /Program_O/test/myError.php -ErrorDocument 407 /Program_O/test/myError.php -ErrorDocument 408 /Program_O/test/myError.php -ErrorDocument 409 /Program_O/test/myError.php -ErrorDocument 410 /Program_O/test/myError.php -ErrorDocument 411 /Program_O/test/myError.php -ErrorDocument 412 /Program_O/test/myError.php -ErrorDocument 413 /Program_O/test/myError.php -ErrorDocument 414 /Program_O/test/myError.php -ErrorDocument 415 /Program_O/test/myError.php -ErrorDocument 416 /Program_O/test/myError.php -ErrorDocument 417 /Program_O/test/myError.php -ErrorDocument 500 /Program_O/test/myError.php -ErrorDocument 501 /Program_O/test/myError.php -ErrorDocument 502 /Program_O/test/myError.php -ErrorDocument 503 /Program_O/test/myError.php -ErrorDocument 504 /Program_O/test/myError.php -ErrorDocument 505 /Program_O/test/myError.php - diff --git a/admin/AIML_Header.dat b/admin/AIML_Header.dat index 66811a2..6ac18b0 100644 --- a/admin/AIML_Header.dat +++ b/admin/AIML_Header.dat @@ -1,34 +1,31 @@ - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/admin/SQL_Header.dat b/admin/SQL_Header.dat index 801b6f0..cd23650 100644 --- a/admin/SQL_Header.dat +++ b/admin/SQL_Header.dat @@ -1,19 +1,19 @@ --- Program O SQL Dump --- --- Host: [host] --- Generation Time: [curDate] --- PHP Version: [phpVer] --- --- Database: `[dbn]` --- --- Data for table `aiml` --- --- File: [fileName] --- --- Created for: [botmaster_name] --- --- SQL Query: [sql] - --- -------------------------------------------------------- -insert into aiml (id,bot_id,aiml,pattern,thatpattern,template,topic,filename,php_code) values - +-- Program O SQL Dump +-- +-- Host: [host] +-- Generation Time: [curDate] +-- PHP Version: [phpVer] +-- +-- Database: `[dbn]` +-- +-- Data for table `aiml` +-- +-- File: [fileName] +-- +-- Created for: [botmaster_name] +-- +-- SQL Query: [sql] + +-- -------------------------------------------------------- +insert into aiml (id,bot_id,aiml,pattern,thatpattern,template,topic,filename,php_code) values + diff --git a/admin/admin.css b/admin/admin.css deleted file mode 100644 index 3b71949..0000000 --- a/admin/admin.css +++ /dev/null @@ -1,508 +0,0 @@ -body { - background-attachment: fixed; - background-color: #a5c739; - background-image: url(http://github.com/images/repeated_header.jpg); - background-repeat: repeat-x; - height: 100%; -/*overflow: hidden;*/ - margin: 0; - padding: 0; - width: 100%; -} - -fieldset { - border: 1px solid black; - line-height: 125%; - padding: 12px; - padding-left: 5%; - padding-right: 5%; -} - -label { - cursor: pointer; - margin-right: 20px; -} - -legend { - font-size: xx-large; - font-weight: bold; - margin-left: -5px; - margin-top: -15px; -} - -p {text-indent: 1em;} - -strong { - text-align: center; - width: 100%; -} - -table {border: 6px outset orange;/**/} - -tr, td { - background-color: #EEEEEE; - border: 3px yellow inset; - border-bottom-color: #993300; - border-left-color: #FF9900; - border-right-color: #993300; - border-top-color: #FF9900; - margin: 0; - padding: 0; -} - -.bold {font-weight: bold;} - -.border {border: 1px solid black;} - -.error { - clear: left; - color: red; - text-decoration: underline; -} - -.floatRight {float: right;} - -.fullSize { - width: 99.5%;/* border: 1px solid red;*/ -} - -.halfSize {width: 50%;} - -.ll { - background-image: url(http://github.com/images/ll.png); - bottom: 0; - left: 0; -} - -.lr { - background-image: url(http://github.com/images/lr.png); - bottom: 0; - right: 0; -} - -.m10r {margin-right: 30px;} - -.m5r {margin-right: 5px;} - -.orange { - background-color: transparent; - color: orange; -} - -.pad5 {padding: 5px;} - -.red { - background-color: transparent; - color: red; - font-size: large; - font-weight: bold; -} - -.shadowBorderInset { - border-bottom: 1px solid white; - border-left: 2px solid #707070; - border-right: 1px solid white; - border-top: 2px solid #505050; -} - -.shadowBorderOutset { - border-bottom: 2px solid #505050; - border-left: 1px solid white; - border-right: 2px solid #707070; - border-top: 1px solid white; -} - -.small {font-size: x-small;} - -.spacer_left {margin-left: 20px;} - -.underline { - text-decoration: underline; -} - -div.row { - clear: both; - padding-top: 5px; -} - -div.row span.formw { - float: right; - text-align: left; - width: 49.75%; -} - -div.row span.formw input [ type = checkbox ], div.row span.formw input [ type = radio ] { - margin: 0; - width: 15px; -} - -div.row span.formw input, div.row span.formw textarea { - margin: 0; - width: 150px; -} - -div.row span.formw select { - margin: 0; - width: 155px; -} - -div.row span.formxw input [ type = checkbox ], div.row span.formxw input [ type = radio ] { - margin: 0; - margin-left: 6px; - text-align: left; - width: 15px; -} - -div.row span.formxw input, div.row span.formxw textarea { - margin: 0; - margin-left: 6px; - width: 40%; -} - -div.row span.formxw select { - margin: 0; - width: 42%; -} - -div.row span.label { - float: left; - text-align: left; - width: 49.75%; -} - -div.spacer {clear: both;} - -tr, td, .center {text-align: center;} - -#botNames {height: 20px;} - -#container{ - margin: 0 auto; - padding: 1em; - text-align: left; -} - -#container1, #container2 { - margin: 0; - margin-left: auto; - margin-right: auto; - padding: 0px; - position: relative; - width: 95%; -} - -#container2 { - background-color: #FFFF99; - border: 4px inset #a5c739; - overflow: auto; -} - -#footer { - background-color: #AFEEEE; - bottom: 15px; - color: #000; - height: 60px; - left: 5%; - margin-left: auto; - margin-right: auto; - padding: 0px; - position: absolute; - right: 5%; - width: 90%; -} - -#footer a { - color: #467AA7; - font-size: 1em; - font-weight: normal; - text-align: center; - text-decoration: none; -} - -#footer p { - color: #333; - font-family: arial; - font-size: 0.7em; - font-weight: normal; - line-height: 1.4em; - padding: 2px; - text-align: center; -} - -#formSubmit { - border: none; - float: right; - margin-right: 4%; - margin-top: 4px; - text-align: right; - width: 95%; -} - -#form_table { - margin-left: auto; - margin-right: auto; - margin-top: 20px; - padding: 12px; - width: 250px; -} - -#gcData, #lsData, #rsData { - background-color: #FFFF99; - left: 0; - margin: 0; - margin-bottom: 6px; - padding: 0; - padding-bottom: 6px; - position: relative; - top: 0; - width: 100%; -} - -#leftPanel {left: 5px;} - -#leftPanel, #midPanel, #rightPanel { - background-color: #FFFF99; - border: 4px inset #a5c739; - overflow: auto; - padding: 3px; - position: absolute; - text-align: left; - top: 5px; - width: 31%; -} - -#ll { - background-image: url(http://github.com/images/ll.png); - bottom: 3px; - left: 0; -} - -#logo { - background-image: url(http://github.com/images/bg_header.gif); - background-position: center 0; - background-repeat: no-repeat; - height: 217px; - left: 0; - position: absolute; - top: 0; - width: 100%; - z-index: 1; -} - -#lr { - background-image: url(http://github.com/images/lr.png); - bottom: 3px; - right: 0; -} - -#main {height: 450px;} - -#main { - background-color: white; - bottom: 200px; - left: 240px; - max-height: 400px; - min-height: 200px; - position: absolute; - right: 5%; - top: 60px;/**/ -} - -#midPanel {right: 34%;} - -#nav { - left: 0; - list-style: none; - position: absolute; - top: 44px; -} - -#nav .ll { - background-image: url(http://github.com/images/ll.png); - bottom: 16px; - left: 40px; -} - -#nav .lr { - background-image: url(http://github.com/images/lr.png); - bottom: 16px; - right: 0; -} - -#nav .selected { - background-color: #f7f7f2; - color: #37210c; -} - -#nav .ul { - background-image: url(http://github.com/images/ul.png); - left: 40px; - top: 16px; -} - -#nav .ur { - background-image: url(http://github.com/images/ur.png); - right: 0; - top: 16px; -} - -#nav li { - border-bottom: 1px solid #eaeada; - text-align: left; -} - -#nav ul {list-style: none;} - -#nav ul li a { - background-color: #AFEEEE; - background-image: url(http://github.com/pages/Img/bullet.gif); - background-position: left center; - background-repeat: no-repeat; - color: #666666; - display: block; - font-size: 0.8em; - font-weight: normal; - line-height: 1.7em; - margin: 0px; - padding-bottom: 6px; - padding-left: 22px; - padding-top: 6px; - text-decoration: none; - width: 165px; -} - -#navhorisontell { - background-color: transparent; - height: 50px; - margin-left: auto; - margin-right: auto; - width: 435px; -/*width: 90%;*/ -} - -#navhorisontell ul { - list-style: none; - margin: 0; -} - -#navhorisontell ul li a { - background-color: #008000; - border-right: 1px solid #fff; - color: #ecf9ff; - display: block; - font-size: 0.8em; - font-weight: normal; - line-height: 2.5em; - margin-right: 0px; - padding: 8px 14px 8px 14px; - text-decoration: none; -} - -#nocol { - font-size: 0.9em; - overflow: auto; - padding: 5px; - text-align: left; -} -/*#nocol .ul, #nocol .ll, #nocol .ur, #nocol .lr { width: 6px; height: 6px; position: absolute; background-color: transparent; z-index: 1;} - #nocol .ul { top: 60px; left: 240px; background-image: url(http://github.com/images/ul.png); } - #nocol .ll { bottom: 90px; left: 240px; background-image: url(http://github.com/images/ll.png); } - #nocol .ur { top: 60px; right: 5%; background-image: url(http://github.com/images/ur.png); } - #nocol .lr { bottom: 90px; right: 5%; background-image: url(http://github.com/images/lr.png); }*/ - -#notes { - bottom: 0; - left: 0; - position: absolute; -} - -#rightPanel {right: 5px;} - -#title { - background-color: transparent; - font-size: x-large; - font-weight: bold; - height: 30px; - left: 2.8%; - margin: 0; - padding: 0px; - position: absolute; - right: 33%; - text-align: center; - top: 206px; - width: 94%; - z-index: 2; -} - -#titlespan { - background-image: url(http://github.com/images/bg_list2.gif); - color: white; - width: 100%; - z-index: 5; -} - -#ul, #ll, #ur, #lr { - background-color: transparent; - height: 6px; - position: absolute; - width: 6px; - z-index: 4; -} - -#ul, .ul { - background-image: url(http://github.com/images/ul.png); - left: 0; - top: 0; -} - -#ur, .ur { - background-image: url(http://github.com/images/ur.png); - right: 0; - top: 0; -} - -#wrapper { - bottom: 0px; - left: 0px; - margin-top: 242px; - overflow: auto; - padding: 0; - padding-top: 0; - position: absolute; - right: 0px; - top: 0px; -} - -.floatLeft, #navhorisontell li { - float: left; -} - -.ul, .ll, .ur, .lr, #nav .ul, #nav .ll, #nav .ur, #nav .lr { - background-color: transparent; - height: 6px; - position: absolute; - width: 6px; - z-index: 1; -} - -#footer a:hover { - color: #467AA7; - font-weight: normal; - text-align: center; - text-decoration: underline; -} - -#nav li a:hover { - border-bottom: 1px solid yellow; - color: #000; -} - -#navhorisontell li a:hover, #navhorisontell ul li .selected { - background-color: #9ACD32; - color: #ecf9ff; -} - -#navhorisontell ul li .selected:hover { - background-color: #008000; - color: #ecf9ff; -} \ No newline at end of file diff --git a/admin/botpersonality.php b/admin/botpersonality.php new file mode 100644 index 0000000..e3110cb --- /dev/null +++ b/admin/botpersonality.php @@ -0,0 +1,307 @@ +getSection('TopNav'); + $leftNav = $template->getSection('LeftNav'); + $main = $template->getSection('Main'); + $topNavLinks = makeLinks('top', $topLinks, 12); + $navHeader = $template->getSection('NavHeader'); + $leftNavLinks = makeLinks('left', $leftLinks, 12); + $FooterInfo = getFooter(); + $errMsgClass = (!empty($msg)) ? "ShowError" : "HideError"; + $errMsgStyle = $template->getSection($errMsgClass); + $noLeftNav = ''; + $noTopNav = ''; + $noRightNav = $template->getSection('NoRightNav'); + $headerTitle = 'Actions:'; + $pageTitle = 'My-Program O - Bot Personality'; + #$mainContent = ($func != 'updateBot') ? $func() : ''; + $mainContent = "main content"; + #$msg = "function = $func"; + switch ($func) { + case 'updateBot': + $msg = $func(); + $mainContent = getBot(); + break; + default: + $mainContent = $func(); + #$msg = "function = $func"; + } +/* +*/ + #$mainContent = "test... func = $func"; + $mainTitle = 'Bot Personality Settings for '.$bot_name; + if ($func == 'updateBot' or $func == 'addBotPersonality') { + $msg = updateBot(); + include('main.php'); + } +function getBot() { + #die('entered function.'); + global $dbn; + $dbconn = db_open(); + $formCell = ' +'; + $blankCell ='   +'; + $startDiv = ' ' . "\n "; + $endDiv = "\n \n
\n"; + $inputs=""; + $row_class = 'row fm-opt'; + $bot_name = $_SESSION['poadmin']['bot_name']; + $bot_id = (isset($_SESSION['poadmin']['bot_id'])) ? $_SESSION['poadmin']['bot_id'] : 0; + //get the current bot's personality table from the db + $sql = "SELECT * FROM `botpersonality` where bot = $bot_id"; + #die ("SQL = $sql
db name = $dbn\n"); + $result = mysql_query($sql,$dbconn)or $msg .= SQL_Error(mysql_errno()); + if ($result) { + $rowCount = mysql_num_rows($result); + if ($rowCount > 0) { + $left = true; + $colCount = 0; + while($row = mysql_fetch_assoc($result)) { + $rid = $row['id']; + $label = $row['name']; + $value = stripslashes_deep($row['value']); + $tmpRow = str_replace('[row_class]', $row_class, $formCell); + $tmpRow = str_replace('[row_id]', $rid, $tmpRow); + $tmpRow = str_replace('[row_label]', $label, $tmpRow); + $tmpRow = str_replace('[row_value]', $value, $tmpRow); + $inputs .= $tmpRow; + $colCount++; + if ($colCount >=3) { + $inputs .= ' + '; + $colCount = 0; + } + } + $inputs .= "\n"; + if (($colCount > 0) and ($colCount < 3)) { + for ($n = 0; $n < (3 - $colCount); $n++) { + $addCell = str_replace('[cid]',"[$n]", $blankCell); + $inputs .= $addCell; + } + } + mysql_close($dbconn); + $action = 'Update Data'; + $func = 'updateBot'; + } + else { + $inputs = newForm(); + $action = 'Add New Data'; + $func = 'addBotPersonality'; + } + } + if (empty($func)) $func = 'getBot'; + $form = << + + +$inputs + + + + +
+ + + +
+ + +endForm2; + return $form; +} + +function stripslashes_deep($value) { + $newValue = stripslashes($value); + while ($newValue != $value) { + $value = $newValue; + $newValue = stripslashes($value); + } + return $newValue; +} + + +function updateBot() { + global $bot_id, $bot_name; + $botId = (isset($_POST['bot_id'])) ? $_POST['bot_id'] : $bot_id; + $dbconn = db_open(); + $msg = ""; + if (!empty($_POST['newEntryName'])) { + $newEntryNames = $_POST['newEntryName']; + $newEntryValues = $_POST['newEntryValue']; + $addSQL = "Insert into `botpersonality` (`id`, `bot`, `name`, `value`) values\n"; + $addSQLTemplate = "(null, $bot_id, '[key]', '[value]'),\n"; + foreach ($newEntryNames as $index => $key) { + $value = $newEntryValues[$index]; + if (empty($value)) continue; + $tmpSQL = str_replace('[key]', $key, $addSQLTemplate); + $tmpSQL = str_replace('[value]', $value, $tmpSQL); + $addSQL .= $tmpSQL; + } + $addSQL = rtrim($addSQL,",\n"); + $result = mysql_query($addSQL,$dbconn) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
SQL:
\n$addSQL\n
\n
\n"); + if(!$result) { + $msg = 'Error updating bot personality.'; + } + elseif($msg == "") { + $msg = 'Bot personality added.'; + } + } + + $updateSQL = "UPDATE `botpersonality` SET `value` = CASE `name` \n"; + $sql = "SELECT * FROM `botpersonality` where bot = $botId;"; + $changes = array(); + $additions = array(); + $result = mysql_query($sql, $dbconn) or $msg .= SQL_Error(mysql_errno()); + if ($result) { + while ($row = mysql_fetch_assoc($result)) { + $id = $row['id']; + $name = $row['name']; + $value = $row['value']; + $postVal = (isset($_POST[$name])) ? $_POST[$name] : ''; + if (!empty($postVal)) { + if ($postVal != $value){ + $changes[$id] = mysql_real_escape_string(stripslashes_deep($postVal)); + $additions[$id] = $name; + } + } + } + } + if (!empty($additions)) { + $changesText = implode(',', array_keys($changes)); + foreach ($changes as $id => $value) { + $name = $additions[$id]; + $updateSQL .= sprintf("WHEN '%s' THEN '%s' \n", $name, $value); + } + $updateSQL .= "END WHERE `id` IN ($changesText);"; + $saveSQL = str_replace("\n", "\r\n", $updateSQL); + $result = mysql_query($updateSQL, $dbconn) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
SQL:
\n$updateSQL\n
\n
\n"); + if (!$result) $msg = 'Error updating bot.'; + $msg = (empty($msg)) ? 'Bot personality updated.' : $msg; + } + else $msg = 'Something'; + mysql_close($dbconn); + return $msg; +} + +function addBotPersonality() { + $dbconn = db_open(); +/* + $postVars = print_r($_POST, true); + die ("Post vars:
\n$postVars\n
"); +*/ + $bot_id = $_POST['bot_id']; + $sql = "Insert into `botpersonality` (`id`, `bot`, `name`, `value`) values\n"; + $sql2 = "(null, $bot_id, '[key]', '[value]'),\n"; + $msg = ""; + $newEntryNames = (isset($_POST['newEntryName'])) ? $_POST['newEntryName'] : ''; + $newEntryValues = (isset($_POST['newEntryValue'])) ? $_POST['newEntryValue'] : ''; + if (!empty($newEntryNames)) { + foreach ($newEntryNames as $index => $key) { + $value = $newEntryValues[$index]; + if (!empty($value)) { + $tmpSQL = str_replace('[key]', $key, $sql2); + $tmpSQL = str_replace('[value]', $value, $tmpSQL); + $sql .= $tmpSQL; + } + } + } + + $skipKeys = array('bot_id', 'action', 'func', 'newEntryName', 'newEntryValue'); + foreach($_POST as $key => $value) { + if(!in_array($key, $skipKeys)) { + #if($value=="") continue; + if (is_array($value)) { + foreach ($value as $index => $fieldValue) { + $field = $key[$fieldValue]; + $fieldValue = mysql_real_escape_string(trim($fieldValue)); + $tmpSQL = str_replace('[key]', $field, $sql2); + $tmpSQL = str_replace('[value]', $fieldValue, $tmpSQL); + $sql .= $tmpSQL; + } + continue; + } + else { + $value = mysql_real_escape_string(trim($value)); + $tmpSQL = str_replace('[key]', $key, $sql2); + $tmpSQL = str_replace('[value]', $value, $tmpSQL); + $sql .= $tmpSQL; + } + } + } + $sql = rtrim($sql,",\n"); + $result = mysql_query($sql,$dbconn) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
SQL:
\n$sql\n
\n
\n"); + if(!$result) { + $msg = 'Error updating bot personality.'; + } + elseif($msg == "") { + $msg = 'Bot personality added!'; + } + mysql_close($dbconn); + return $msg; +} + + + function newForm() { + $out = ' + +'; + $rowTemplate = ' +'; + $tr = ' + +'; + $blankTD = ' +'; + + $lastBit = ' + + + + + +
 
   
+'; + + $fields = file(_CONF_PATH_ . 'default_botpersonality_fields.dat'); + $count = 0; + foreach ($fields as $field) + { + $count++; + $field = trim($field); + $tmpRow = str_replace('[field]', $field, $rowTemplate); + $tmpRow = str_replace('[uc_field]', ucfirst($field), $tmpRow); + $out .= $tmpRow; + if ($count % 3 == 0) $out .= $tr; + } + switch ($count % 3) + { + case 1: + $out .= $blankTD; + break; + case 2: + $out .= $blankTD . $blankTD; + } + $out .= $lastBit; + return $out; + + } + + +?> \ No newline at end of file diff --git a/admin/bots.php b/admin/bots.php deleted file mode 100644 index f0903a9..0000000 --- a/admin/bots.php +++ /dev/null @@ -1,305 +0,0 @@ -getSection('TopNav'); - $leftNav = $template->getSection('LeftNav'); - $main = $template->getSection('Main'); - $topNavLinks = makeLinks('top', $topLinks, 12); - $navHeader = $template->getSection('NavHeader'); - $leftNavLinks = makeLinks('left', $leftLinks, 12); - $FooterInfo = getFooter(); - $errMsgClass = (!empty($msg)) ? "ShowError" : "HideError"; - $errMsgStyle = $template->getSection($errMsgClass); - $noLeftNav = ''; - $noTopNav = ''; - $noRightNav = $template->getSection('NoRightNav'); - $headerTitle = 'Actions:'; - $pageTitle = 'My-Program O - Bot Personality'; - $mainContent = ($func != 'updateBot') ? $func() : ''; - #$mainContent = "test... func = $func"; - $mainTitle = 'Bot Personality Settings for '.$bot_name; - if ($func == 'updateBot' or $func == 'addBotPersonaity') { - $msg = updateBot(); - include('main.php'); - } -function getBot() { - #die('entered function.'); - global $dbn; - $dbconn = db_open(); - $formCell = ' -'; - $blankCell ='   -'; - $startDiv = ' ' . "\n "; - $endDiv = "\n \n
\n"; - $inputs=""; - $row_class = 'row fm-opt'; - $bot_name = $_SESSION['poadmin']['bot_name']; - $bot_id = (isset($_SESSION['poadmin']['bot_id'])) ? $_SESSION['poadmin']['bot_id'] : 0; - //get the current bot's personality table from the db - $sql = "SELECT * FROM `botpersonality` where bot = $bot_id"; - #die ("SQL = $sql
db name = $dbn\n"); - $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . '.'); - $rowCount = mysql_num_rows($result); - if ($rowCount > 0) { - $left = true; - $colCount = 0; - while($row = mysql_fetch_assoc($result)) { - $rid = $row['id']; - $label = $row['name']; - $value = stripslashes_deep($row['value']); - $tmpRow = str_replace('[row_class]', $row_class, $formCell); - $tmpRow = str_replace('[row_id]', $rid, $tmpRow); - $tmpRow = str_replace('[row_label]', $label, $tmpRow); - $tmpRow = str_replace('[row_value]', $value, $tmpRow); - $inputs .= $tmpRow; - $colCount++; - if ($colCount >=3) { - $inputs .= ' - '; - $colCount = 0; - } - } - $inputs .= "\n"; - if (($colCount > 0) and ($colCount < 3)) { - for ($n = 0; $n < (3 - $colCount); $n++) { - $addCell = str_replace('[cid]',"[$n]", $blankCell); - $inputs .= $addCell; - } - } - mysql_close($dbconn); - $action = 'Update Data'; - $func = 'updateBot'; - } - else { - $inputs = newForm(); - $action = 'Add New Data'; - $func = 'addBotPersonality'; - } - if (empty($func)) $func = 'getBot'; - $form = << - - -$inputs - - - - -
- - - -
- - -endForm2; - return $form; -} - -function stripslashes_deep($value) { - $newValue = stripslashes($value); - while ($newValue != $value) { - $value = $newValue; - $newValue = stripslashes($value); - } - return $newValue; -} - - -function updateBot() { - global $bot_id, $bot_name; - $botId = (isset($_POST['bot_id'])) ? $_POST['bot_id'] : $bot_id; - $dbconn = db_open(); - $msg = ""; -/* -$sql = "UPDATE categories SET display_order = CASE id "; -foreach ($display_order as $id => $ordinal) { - $sql .= sprintf("WHEN %d THEN %d ", $id, $ordinal); -} -$sql .= "END WHERE id IN ($ids)"; -echo $sql; -*/ - $updateSQL = "UPDATE `botpersonality` SET `value` = CASE `name` \n"; - $sql = "select `id`, `name`, `value` from `botpersonality` where `bot` = $botId;"; - $changes = array(); - $additions = array(); - $result = mysql_query($sql, $dbconn) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
SQL:
\n$sql\n
\n
\n"); - while ($row = mysql_fetch_assoc($result)) { - $id = $row['id']; - $name = $row['name']; - $value = $row['value']; - $postVal = (isset($_POST[$name])) ? $_POST[$name] : ''; - if (!empty($postVal)) { - if ($postVal != $value){ - $changes[$id] = mysql_escape_string(stripslashes_deep($postVal)); - $additions[$id] = $name; - } - } - } - $changesText = implode(',', array_keys($changes)); - foreach ($changes as $id => $value) { - $name = $additions[$id]; - $updateSQL .= sprintf("WHEN '%s' THEN '%s' \n", $name, $value); - } - $updateSQL .= "END WHERE `id` IN ($changesText);"; - #die ("
\nupdate SQL = \n$updateSQL\n

\n"); - $saveSQL = str_replace("\n", "\r\n", $updateSQL); - $x = file_put_contents('sql.txt', "$saveSQL\r\n\r\n", FILE_APPEND); - $result = mysql_query($updateSQL, $dbconn) ;#or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
SQL:
\n$updateSQL\n
\n
\n"); - #die("result = $result
\n error = |" . mysql_error($link) . "|\nSQL = $updateSQL
\n"); - if (!$result) $msg = 'Error updating bot.'; - $msg = (empty($msg)) ? 'Bot personality updated.' : $msg; - mysql_close($dbconn); - return $msg; -} -function addBotPersonality() { - $dbconn = db_open(); - $bot_id = $_POST['bot_id']; - $sql = "Insert into `botpersonality` (`id`, `bot`, `name`, `value`) values\n"; - $sql2 = "(null, $bot_id, '[key]', '[value]'),\n"; - $msg = ""; - $skipKeys = array('bot_id', 'action', 'func'); - foreach($_POST as $key => $value) { - if(!in_array($key, $skipKeys)) { - if($value=="") continue; - $value = mysql_escape_string(trim($value)); - $tmpSQL = str_replace('[key]', $key, $sql2); - $tmpSQL = str_replace('[value]', $value, $tmpSQL); - $sql .= $tmpSQL; - } - } - $sql = rtrim($sql,",\n"); - $result = mysql_query($sql,$dbconn) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
SQL:
\n$sql\n
\n
\n"); - if(!$result) { - $msg = 'Error updating bot personality.'; - } - elseif($msg == "") { - $msg = 'Bot personality added.'; - } - mysql_close($dbconn); - return $msg; -} - - function newForm() { - return << - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -endForm; - } -?> \ No newline at end of file diff --git a/admin/bugs.php b/admin/bugs.php index eb7ee4f..8276ad3 100644 --- a/admin/bugs.php +++ b/admin/bugs.php @@ -1,207 +1,207 @@ - - - -endScript; - foreach ($_POST as $key => $value) { - $$key = mysql_escape_string($value); - } - $func = (isset($_POST['func'])) ? $_POST['func'] : 'showBugForm'; -# Build page sections -# ordered here in the order that the page is constructed -# Only the variables that are different from the -# login page need be set here. - $topNav = $template->getSection('TopNav'); - $leftNav = $template->getSection('LeftNav'); - $main = $template->getSection('Main'); - $topNavLinks = makeLinks('top', $topLinks, 12); - $navHeader = $template->getSection('NavHeader'); - $leftNavLinks = makeLinks('left', $leftLinks, 12); - $FooterInfo = getFooter(); - $errMsgClass = (!empty($msg)) ? "ShowError" : "HideError"; - $errMsgStyle = $template->getSection($errMsgClass); - $noLeftNav = ''; - $noTopNav = ''; - $noRightNav = $template->getSection('NoRightNav'); - $headerTitle = 'Actions:'; - $pageTitle = 'My-Program O - Report a Bug'; - $mainContent = $func(); - $lowerScripts .= ' '; - $mainTitle = 'Send a Bug Report'; - - - function showBugForm() { - return << - - - - - - - - - - - - - - - - - - - -
- Your Name:
- -
- Your Email Address:
- -
- Subject:
- -
- Message:
- -
-

- Use this handy form to submit a bug report to Liz and Company over at the Program O website. - Please describe the problem as completely as possible, including what actions you were trying - to perform at the time that you noticed the problem. -

-
-
- -
-

- Answer the question you see in the image on the left into the text area - below. We are looking for a one word answer (no numbers). Sry, but bots are not allowed. -

- -
- -
- -endForm; - } - function sendMail() { - global $email, $name, $subject, $message, $captcha; - #print "\n"; - if ($isPresent !== false) $out = 1; - } - $content .= "\n"; - return $out; - } - - function checkBadIP () { - global $content; - $IP = $_SERVER['REMOTE_ADDR']; - $out = 0; - $excluded = array("89.28.114", "85.140.66.54"); - foreach ($excluded as $check) { - $isPresent = strpos($IP, $check); - $content .= "\n"; - if ($isPresent !== false) $out = 1; - } - $content .= "\n"; - return $out; - } + + + +endScript; + foreach ($_POST as $key => $value) { + $$key = mysql_real_escape_string($value); + } + $func = (isset($_POST['func'])) ? $_POST['func'] : 'showBugForm'; +# Build page sections +# ordered here in the order that the page is constructed +# Only the variables that are different from the +# login page need be set here. + $topNav = $template->getSection('TopNav'); + $leftNav = $template->getSection('LeftNav'); + $main = $template->getSection('Main'); + $topNavLinks = makeLinks('top', $topLinks, 12); + $navHeader = $template->getSection('NavHeader'); + $leftNavLinks = makeLinks('left', $leftLinks, 12); + $FooterInfo = getFooter(); + $errMsgClass = (!empty($msg)) ? "ShowError" : "HideError"; + $errMsgStyle = $template->getSection($errMsgClass); + $noLeftNav = ''; + $noTopNav = ''; + $noRightNav = $template->getSection('NoRightNav'); + $headerTitle = 'Actions:'; + $pageTitle = 'My-Program O - Report a Bug'; + $mainContent = $func(); + $lowerScripts .= ' '; + $mainTitle = 'Send a Bug Report'; + + + function showBugForm() { + return << + + + + + + + + + + + + + + + + + + + +
+ Your Name:
+ +
+ Your Email Address:
+ +
+ Subject:
+ +
+ Message:
+ +
+

+ Use this handy form to submit a bug report to Liz and Company over at the Program O website. + Please describe the problem as completely as possible, including what actions you were trying + to perform at the time that you noticed the problem. +

+
+
+ +
+

+ Answer the question you see in the image on the left into the text area + below. We are looking for a one word answer (no numbers). Sry, but bots are not allowed. +

+ +
+ +
+ +endForm; + } + function sendMail() { + global $email, $name, $subject, $message, $captcha; + #print "\n"; + if ($isPresent !== false) $out = 1; + } + $content .= "\n"; + return $out; + } + + function checkBadIP () { + global $content; + $IP = $_SERVER['REMOTE_ADDR']; + $out = 0; + $excluded = array("89.28.114", "85.140.66.54"); + foreach ($excluded as $check) { + $isPresent = strpos($IP, $check); + $content .= "\n"; + if ($isPresent !== false) $out = 1; + } + $content .= "\n"; + return $out; + } ?> \ No newline at end of file diff --git a/admin/captcha-fonts/BoringLesson.ttf b/admin/captcha-fonts/BoringLesson.ttf deleted file mode 100644 index 7748cef..0000000 Binary files a/admin/captcha-fonts/BoringLesson.ttf and /dev/null differ diff --git a/admin/captcha-fonts/GILLIGAN.ttf b/admin/captcha-fonts/GILLIGAN.ttf deleted file mode 100644 index b6c0a48..0000000 Binary files a/admin/captcha-fonts/GILLIGAN.ttf and /dev/null differ diff --git a/admin/captcha-fonts/NESBIT.ttf b/admin/captcha-fonts/NESBIT.ttf deleted file mode 100644 index 7b590bf..0000000 Binary files a/admin/captcha-fonts/NESBIT.ttf and /dev/null differ diff --git a/admin/captcha-fonts/comic.ttf b/admin/captcha-fonts/comic.ttf deleted file mode 100644 index d17e1be..0000000 Binary files a/admin/captcha-fonts/comic.ttf and /dev/null differ diff --git a/admin/captcha.php b/admin/captcha.php index 47505fa..01cee87 100644 --- a/admin/captcha.php +++ b/admin/captcha.php @@ -1,197 +1,197 @@ - - -The minimum size for the CAPTCHA image is 200x75, to allow for both the describing -image, and the question text. Larger image sizes are allowed, and both the font -size for the question text and the describing image should scale accordingly. - -The CAPTCHA script will randomly pick from an array of valid keywords, then generate -the image based on that word, and store the SHA1 value for that word. CAPTCHA -validation in your script then needs to compare the session variable -$_SESSION['capKey'] with the SHA1 of the submitted response from the user. A -match should allow the user access, while failure should be handled accordingly. - - - */ - $minX = 200; - $minY = 75; - $X = (isset($_GET['w'])) ? (int)$_GET['w'] : $minX; // Determine width of image - $Y = (isset($_GET['h'])) ? (int)$_GET['h'] : $minY; // Determine height of image - $X = ($X < $minX) ? $minX : $X; - $Y = ($Y < $minY) ? $minY : $Y; - $b = (isset($_GET['b'])) ? true : false; // determine whether a black background is desired - $g = (isset($_GET['g'])) ? true : false; // determine whether a gradient background is desired - $defaultAspectRatio = 200 / 75; - $aspectRatio = $X / $Y; - $fsl = 20 * floor((200 / $X) * ($aspectRatio / $defaultAspectRatio)); - $fsh = 26 * floor((200 / $X) * ($aspectRatio / $defaultAspectRatio)); - $vCenter = floor($Y / 2); - $capString = ""; // This is the 'question string' to present to the user, and is built later - $capKeys = array ('red','green','blue','man','woman','cat','dog','fish','one','two','three','four','circle','square','triangle'); - $capKeyCount = count($capKeys); - $capNum = rand(0,$capKeyCount - 1); - #$capNum = rand(0,7); - $capKey = $capKeys[$capNum]; - $objectWord = ''; - $fn = ''; - $number = ''; - switch ($capKey) { - case 'red': - case 'green': - case 'blue': - $fn = '[objectWord] [capKey]'; - $capString = "What color is this [objectWord]?"; - $objectNum = rand(1,5); - switch ($objectNum) { - case 1: - $objectWord = 'man'; - $capString = "What color is this man's shirt?"; - break; - case 2: - $objectWord = 'woman'; - $capString = "What color is this woman's blouse?"; - break; - case 3: - $objectWord = 'cat'; - break; - case 4: - $objectWord = 'dog'; - break; - case 5: - $objectWord = 'fish'; - break; - } - break; - case 'one': - case 'two': - case 'three': - case 'four': - $fn = '[capKey]'; - $capString = "How many lines do you see?"; - break; - case 'circle': - case 'square': - case 'triangle': - $fn = '[capKey]'; - $capString = "What shape do you see?"; - break; - case 'man': - case 'woman': - $fn = '[capKey] [objectWord]'; - $capString = "Is this a man or a woman?"; - $objectNum = rand(1,3); - switch ($objectNum) { - case 1: - $objectWord = 'red'; - break; - case 2: - $objectWord = 'green'; - break; - case 3: - $objectWord = 'blue'; - break; - } - break; - case 'cat': - case 'dog': - case 'fish': - $fn = '[capKey] [objectWord]'; - $capString = "What is this object?"; - $objectNum = rand(1,3); - switch ($objectNum) { - case 1: - $objectWord = 'red'; - break; - case 2: - $objectWord = 'green'; - break; - case 3: - $objectWord = 'blue'; - break; - } - break; - } - $capString = str_replace('[objectWord]',$objectWord, $capString); - #die ("capKey = $capKey.
\ncapString = $capString.
\nfilename = $fn.
\n"); - - // Set up the image - $image = imagecreatetruecolor($X, $Y); - $white = imagecolorallocate ($image, 255, 255, 255); - $black = imagecolorallocate ($image, 0, 0, 0); - $black = ($b) ? imagecolorallocate ($image, 128, 128, 128) : $black; - $bkg = ($b) ? $black : $white; - $fgc = ($b) ? $white : $black; - - // If black is the chosen background, lighten the current "black" to a medium grey - - // Fill the image with the desired background (the gradient will be handled later) - imagefill ($image, 0, 0, $bkg); - - - // Paints the gradient background, if set - if ($g) { - $lrl = 128; - $lrh = 200; - $drl = 64; - $drh = 160; - for ($c = 0; $c <= $minX; $c++) { - $l = 255 - (($c / $minX) * 255); - $color = imagecolorallocate($image, $l, $l, $l); - imageline($image, $c, 0, $c, $minY, $color); - } - } - - // get the description image - $fn = str_replace('[capKey]', $capKey, $fn); - $fn = str_replace('[objectWord]', $objectWord, $fn); - $overlay = imagecreatefrompng("./captcha-images/$fn.png"); - $trans = imagecolorallocatealpha($overlay,0,0,0,127); - imagecopy($image,$overlay,$X-64,$Y-64,0,0,64,64); - - - - // Base value for the distance between each character - imagestring($image,2,3,3,$capString,$fgc); - $_SESSION["capKey"] = sha1(strtolower($capKey)); - header ("Content-type: image/jpeg"); - imagejpeg($image,"",100); - imagedestroy($image); - // Debug - #file_put_contents('./capKey.txt', "$capKey\r\n",FILE_APPEND); + + +The minimum size for the CAPTCHA image is 200x75, to allow for both the describing +image, and the question text. Larger image sizes are allowed, and both the font +size for the question text and the describing image should scale accordingly. + +The CAPTCHA script will randomly pick from an array of valid keywords, then generate +the image based on that word, and store the SHA1 value for that word. CAPTCHA +validation in your script then needs to compare the session variable +$_SESSION['capKey'] with the SHA1 of the submitted response from the user. A +match should allow the user access, while failure should be handled accordingly. + + + */ + $minX = 200; + $minY = 75; + $X = (isset($_GET['w'])) ? (int)$_GET['w'] : $minX; // Determine width of image + $Y = (isset($_GET['h'])) ? (int)$_GET['h'] : $minY; // Determine height of image + $X = ($X < $minX) ? $minX : $X; + $Y = ($Y < $minY) ? $minY : $Y; + $b = (isset($_GET['b'])) ? true : false; // determine whether a black background is desired + $g = (isset($_GET['g'])) ? true : false; // determine whether a gradient background is desired + $defaultAspectRatio = 200 / 75; + $aspectRatio = $X / $Y; + $fsl = 20 * floor((200 / $X) * ($aspectRatio / $defaultAspectRatio)); + $fsh = 26 * floor((200 / $X) * ($aspectRatio / $defaultAspectRatio)); + $vCenter = floor($Y / 2); + $capString = ""; // This is the 'question string' to present to the user, and is built later + $capKeys = array ('red','green','blue','man','woman','cat','dog','fish','one','two','three','four','circle','square','triangle'); + $capKeyCount = count($capKeys); + $capNum = rand(0,$capKeyCount - 1); + #$capNum = rand(0,7); + $capKey = $capKeys[$capNum]; + $objectWord = ''; + $fn = ''; + $number = ''; + switch ($capKey) { + case 'red': + case 'green': + case 'blue': + $fn = '[objectWord] [capKey]'; + $capString = "What color is this [objectWord]?"; + $objectNum = rand(1,5); + switch ($objectNum) { + case 1: + $objectWord = 'man'; + $capString = "What color is this man's shirt?"; + break; + case 2: + $objectWord = 'woman'; + $capString = "What color is this woman's blouse?"; + break; + case 3: + $objectWord = 'cat'; + break; + case 4: + $objectWord = 'dog'; + break; + case 5: + $objectWord = 'fish'; + break; + } + break; + case 'one': + case 'two': + case 'three': + case 'four': + $fn = '[capKey]'; + $capString = "How many lines do you see?"; + break; + case 'circle': + case 'square': + case 'triangle': + $fn = '[capKey]'; + $capString = "What shape do you see?"; + break; + case 'man': + case 'woman': + $fn = '[capKey] [objectWord]'; + $capString = "Is this a man or a woman?"; + $objectNum = rand(1,3); + switch ($objectNum) { + case 1: + $objectWord = 'red'; + break; + case 2: + $objectWord = 'green'; + break; + case 3: + $objectWord = 'blue'; + break; + } + break; + case 'cat': + case 'dog': + case 'fish': + $fn = '[capKey] [objectWord]'; + $capString = "What is this object?"; + $objectNum = rand(1,3); + switch ($objectNum) { + case 1: + $objectWord = 'red'; + break; + case 2: + $objectWord = 'green'; + break; + case 3: + $objectWord = 'blue'; + break; + } + break; + } + $capString = str_replace('[objectWord]',$objectWord, $capString); + #die ("capKey = $capKey.
\ncapString = $capString.
\nfilename = $fn.
\n"); + + // Set up the image + $image = imagecreatetruecolor($X, $Y); + $white = imagecolorallocate ($image, 255, 255, 255); + $black = imagecolorallocate ($image, 0, 0, 0); + $black = ($b) ? imagecolorallocate ($image, 128, 128, 128) : $black; + $bkg = ($b) ? $black : $white; + $fgc = ($b) ? $white : $black; + + // If black is the chosen background, lighten the current "black" to a medium grey + + // Fill the image with the desired background (the gradient will be handled later) + imagefill ($image, 0, 0, $bkg); + + + // Paints the gradient background, if set + if ($g) { + $lrl = 128; + $lrh = 200; + $drl = 64; + $drh = 160; + for ($c = 0; $c <= $minX; $c++) { + $l = 255 - (($c / $minX) * 255); + $color = imagecolorallocate($image, $l, $l, $l); + imageline($image, $c, 0, $c, $minY, $color); + } + } + + // get the description image + $fn = str_replace('[capKey]', $capKey, $fn); + $fn = str_replace('[objectWord]', $objectWord, $fn); + $overlay = imagecreatefrompng("./captcha-images/$fn.png"); + $trans = imagecolorallocatealpha($overlay,0,0,0,127); + imagecopy($image,$overlay,$X-64,$Y-64,0,0,64,64); + + + + // Base value for the distance between each character + imagestring($image,2,3,3,$capString,$fgc); + $_SESSION["capKey"] = sha1(strtolower($capKey)); + header ("Content-type: image/jpeg"); + imagejpeg($image,"",100); + imagedestroy($image); + // Debug + #file_put_contents('./capKey.txt', "$capKey\r\n",FILE_APPEND); ?> \ No newline at end of file diff --git a/admin/clear.php b/admin/clear.php index 22701e3..28c3aba 100644 --- a/admin/clear.php +++ b/admin/clear.php @@ -1,133 +1,176 @@ -getSection('TopNav'); - $leftNav = $template->getSection('LeftNav'); - $main = $template->getSection('Main'); - $topNavLinks = makeLinks('top', $topLinks, 12); - $navHeader = $template->getSection('NavHeader'); - $leftNavLinks = makeLinks('left', $leftLinks, 12); - $FooterInfo = getFooter(); - $errMsgClass = (!empty($msg)) ? "ShowError" : "HideError"; - $errMsgStyle = $template->getSection($errMsgClass); - $noLeftNav = ''; - $noTopNav = ''; - $noRightNav = $template->getSection('NoRightNav'); - $headerTitle = 'Actions:'; - $pageTitle = 'My-Program O - Clear AIML Categories'; - $mainContent = $content; - $mainTitle = 'Clear AIML Categories'; - - function replaceTags(&$content) { - return $content; - } - - function clearAIML() { - global $dbn; - $dbconn = db_open(); - - $sql = 'truncate table aiml;'; - #return "SQL = $sql"; - $result = mysql_query($sql,$dbconn) or die(mysql_error()); - mysql_close($dbconn); - $msg = "All AIML categories cleared!
"; - return $msg; - } - - function clearAIMLByFileName($filename) { - global $dbn; - $dbconn = db_open(); - $cleanedFilename = mysql_real_escape_string($filename, $dbconn); - $sql = "delete from aiml where filename like '$cleanedFilename';"; - #return "SQL = $sql"; - $result = mysql_query($sql,$dbconn) or die(mysql_error()); - mysql_close($dbconn); - $msg = "
AIML categories cleared for file $filename!
"; - return $msg; - } - - function getSelOpts() { - global $dbn; - $out = " \n"; - $dbconn = db_open(); - $optionTemplate = " \n"; - $sql = 'SELECT DISTINCT filename FROM aiml order by filename;'; - #return "SQL = $sql"; - $result = mysql_query($sql,$dbconn) or die(mysql_error()); - while ($row = mysql_fetch_assoc($result)) { - if (empty($row['filename'])) { - $curOption = " \n"; - } - else $curOption = str_replace('[val]', $row['filename'], $optionTemplate); - $out .= $curOption; - } - mysql_close($dbconn); - $out .= " \n"; - return $out; - } - - function renderMain() { - $selectOptions = getSelOpts(); - $content = <<permanent!
- This action CANNOT be undone!
-
- - - - - - - - - - -
- - -
- -
- -
- -
-
-endForm; - - return $content; - } + + + +endScript; + + +if((isset($_POST['action']))&&($_POST['action']=="clear")) { + $content .= clearAIML(); +} +elseif((isset($_POST['clearFile']))&&($_POST['clearFile'] != "null")) { + $content .= clearAIMLByFileName($_POST['clearFile']); +} +else { +} + $content .= renderMain(); + + $topNav = $template->getSection('TopNav'); + $leftNav = $template->getSection('LeftNav'); + $main = $template->getSection('Main'); + $topNavLinks = makeLinks('top', $topLinks, 12); + $navHeader = $template->getSection('NavHeader'); + $leftNavLinks = makeLinks('left', $leftLinks, 12); + $FooterInfo = getFooter(); + $errMsgClass = (!empty($msg)) ? "ShowError" : "HideError"; + $errMsgStyle = $template->getSection($errMsgClass); + $noLeftNav = ''; + $noTopNav = ''; + $noRightNav = $template->getSection('NoRightNav'); + $headerTitle = 'Actions:'; + $pageTitle = "My-Program O - Clear AIML Categories"; + $mainContent = $content; + $mainTitle = "Clear AIML Categories for the bot named $bot_name [helpLink]"; + $showHelp = $template->getSection('ClearShowHelp'); + + $mainTitle = str_replace('[helpLink]', $template->getSection('HelpLink'), $mainTitle); + $mainContent = str_replace('[showHelp]', $showHelp, $mainContent); + $mainContent = str_replace('[upperScripts]', $upperScripts, $mainContent); + function replaceTags(&$content) { + return $content; + } + + function clearAIML() { + global $dbn, $bot_id, $bot_name; + $dbconn = db_open(); + + $sql = "DELETE FROM `aiml` WHERE `bot_id` = $bot_id;"; + #return "SQL = $sql"; + $result = mysql_query($sql,$dbconn) or die(mysql_error()); + mysql_close($dbconn); + $msg = "All AIML categories cleared for $bot_name!
"; + return $msg; + } + + function clearAIMLByFileName($filename) { + global $dbn, $bot_id; + $dbconn = db_open(); + $cleanedFilename = mysql_real_escape_string($filename, $dbconn); + $sql = "delete from `aiml` where `filename` like '$cleanedFilename' and `bot_id` = $bot_id;"; + #return "SQL = $sql"; + $result = mysql_query($sql,$dbconn) or die(mysql_error()); + mysql_close($dbconn); + $msg = "
AIML categories cleared for file $filename!
"; + return $msg; + } + + function getSelOpts() { + global $dbn, $bot_id, $msg; + $out = " \n"; + $dbconn = db_open(); + $optionTemplate = " \n"; + $sql = "SELECT DISTINCT filename FROM `aiml` where `bot_id` = $bot_id order by `filename`;"; + #return "SQL = $sql"; + $result = mysql_query($sql,$dbconn) or die(mysql_error()); + if (mysql_num_rows($result) == 0) $msg = "This bot has no AIML categories to clear."; + while ($row = mysql_fetch_assoc($result)) { + if (empty($row['filename'])) { + $curOption = " \n"; + } + else $curOption = str_replace('[val]', $row['filename'], $optionTemplate); + $out .= $curOption; + } + mysql_close($dbconn); + $out .= " \n"; + return $out; + } + + function renderMain() { + $selectOptions = getSelOpts(); + $content = <<permanent! + This action CANNOT be undone!
+
+
+ + + + + + + + + + + +
+ + + + +
+
+ +
+ +
+
+
+[showHelp] + +endForm; + + return $content; + } ?> \ No newline at end of file diff --git a/admin/date.php b/admin/date.php index d0a181e..f052e7d 100644 --- a/admin/date.php +++ b/admin/date.php @@ -1,7 +1,7 @@ -\n"; -print "The formatted hour is " . strftime('%H') . "

\n"; -require_once("global_config.php"); -print "The current time is " . date('h:i:s') . "
\n"; -print "The formatted hour is " . strftime('%H') . "
\n"; +\n"; +print "The formatted hour is " . strftime('%H') . "

\n"; +require_once("global_config.php"); +print "The current time is " . date('h:i:s') . "
\n"; +print "The formatted hour is " . strftime('%H') . "
\n"; ?> \ No newline at end of file diff --git a/admin/default.page.htm b/admin/default.page.htm index b21768e..71eacaf 100644 --- a/admin/default.page.htm +++ b/admin/default.page.htm @@ -1,769 +1,827 @@ - - - - - [pageTitle] - - [noLeftNav][noRightNav][upperScripts][errMsgStyle] - - - -[blank] - -
-
-[errMsg] -
-[logo] -[topNav] -[leftNav] -[main] -[rightNav] -[footer] -
-[lowerScripts] - - - -Individual sections are placed after this section. This comment should NEVER be visible on any page! - -[blank] - - -[blank]
-[divDecoration] -
    -[topNavLinks] -
-
- -You don't even have to place documentation within comment tags, since the sections -between the start and end section tags are the only parts of the template that are displayed. - -[blank]
-[divDecoration] -[navHeader] -
    -[leftNavLinks] -
-
- - -[blank]
-[divDecoration] -
- [mainTitle] -
-
-[mainContent] -
-
- - -[blank]
-[divDecoration] -[navHeader] -[rightNavLinks] -
- - -[blank] - - -[blank] - - -[blank]
  • - -[divDecoration] - - [linkLabel] - - -
  • - - -[blank]
    -
    -
    -
    - - -[blank]
    -
    -[divDecoration] - My Program-O -
    -
    - - -[blank] - - -[blank] - - -[blank] - - -[blank] - - -[blank]
    [errorMessage]
    - - -[blank]
    -
    - Login -
    -
    - - -
    -
    - -
    -
    -
    - -
    -
    -
    -
    - - -
    -
    -
    - - - -
    -
    -
    - - - -[blank]
    -
    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - -
    - - - -
    - - - -
    - - - -
    - - - -
    - - - -
    -
    -
    - - - - - - - - - - - - - - - - - - - - - -
    - -
    - -
    - -
    - -
    - -
    -
    - -
    - -
    -
    -
    - - -
    - - -
    - - -
    [bot_name]'s Conversation Logs
    -

    [convo]

    - - - -
    -
    -
    Add a Misspelled word and it's correction:
    -
    - - -
    -
    - - -
    -
    - -
    -
    -
    - - -
    -
    -
    Search for a Misspelled word:
    -
    - - -
    -
    -
    - - -
    -
    -
    Edit the entry for the Misspelled word [missspelling]:
    -
    - - -
    -
    - - -
    -
    - - -
    -
    -
    - - -
    -
    -
    Add an improper word and it's replacement:
    -
    - - -
    -
    - - -
    -
    - - -
    -
    -
    - - -
    -
    -
    Search for an improper word:
    -
    - - -
    -
    -
    - - -
    -
    -
    Edit the entry for the improper word [word_to_censor]:
    -
    - - -
    -
    - - -
    -
    - - -
    -
    -
    - - -[blank]
    -[teach_content] -
    -
    -[showHelp] -
    - - -[blank]
    -
    -
    - - -
    -
    - - -
    -
    - - -
    -
    - - -
    -
    For help, click the icon in the title, above.
    -
    - -
    -
    -
    - - -[blank]
    -

    Help...

    -
    Adding a 'Topic' means that the bot will only be able to access this response if a previous aiml category has set this topic as it's current topic.
    -
    The 'Previous Bot Response' means that the bot must have answered with this text in it's last response.
    -
    The 'User Input' is the the users input used to access the bots response.
    -
    The 'Bot Response' is the text the bot will output when the 'user Input' has been matched.
    -
    -

    Simple Example

    -
    User input: hello how are you
    -
    Bot Response: I am well thank you and you?
    -
    -

    Intermediate example:

    -
    Previous Bot Response: I am well thank you and you
    -
    User input: ok thanks
    -
    Bot Response: That is great to hear
    -
    -

    Advanced example:

    -
    1. First response MUST set the topic
    -
    User input: I like chatbots
    -
    Bot Response: What do you like about them?
    -
    -
    2. Second pattern can only be accessed because the topic has been set in the previous response
    -
    Topic: chatbots
    -
    User input: I just think they are cool
    -
    Bot Response: Yes chatbots are cool
    -
    --You can find alot of information on the net about writing well formed aiml.
    --If you want to learn more about writing AIML start here -
    - - -[blank]
    -

    Help...

    -
    This part is still under construction.
    -
    -
    -
    -
    -
    - - -[blank]
    -

    Help...

    -
    If your aiml file will not upload you may want to check the following.
    -
    --Make sure the folder you are trying to upload to has read/write privs on it (CHMOD 755)
    -
    --Remove any comments from the aiml
    -
    --Replace everything above the first <cattegory> with a simple <aiml> tag
    -
    --You can find alot of information on the net about writing well formed aiml. -
    --If you want to learn more about writing AIML start here -
    - - - Click to toggle help - - -

    [rssRowTitle]

    -

    [rssRowContent]

    -
    - - - - - - - - - - - -
    Talk to [bot_name] using the [format] interface:
    -
    - - -[blank]
    -

    - Here's where you add, remove or edit admin accounts. -

    -[members_list_form] -[members_content] -
    -
    -[showHelp] -
    - - -[blank]

    [action] Admin Account:

    -
    -
    -
    - - -
    -
    - - -
    -
    - - -
    -
    - - -
    -
    - - - -
    -
    -
    - - -[blank]
    -
    -
    - - - - -
    -
    -
    - - -[blank]
    -

    - This uploader can only handle aiml files of 1MB or less. - This script does not perform XML validation, but you can - validate your AIML files prior to uploading - (STRONGLY SUGGESTED) using W3School's - XML Validator. -

    -[upload_content] -
    - List of Currently Stored AIML files:
    -[AIML_List] -
    -
    -
    -[showHelp] -
    - - -[blank]
    -
    -
    - -     -     - - -
    -
    -
    - - -[blank]
    -
    -
    - - -
    -
    - - -
    -
    - - -
    -
    - - -
    -
    - - -
    -
    - TIP: Use % as a wildcard along with your search word/phrase to improve chances of - finding what you're looking for (e.g. "I % you", "%hot" or "%live%") -
    -
    - -
    -
    -
    - - -
    -
    -
    - - -
    -
    - - -
    -
    - - -
    -
    - - -
    -
    - - -
    -
    - - -
    -
    -
    - - -[blank]
    -

    [bot_name]'s Stats

    -
    - Conversations:
    - Today: [oneday]
    - Last week: [oneweek]
    - Last month: [onemonth]
    - Last six months: [sixmonths]
    - Last year: [oneyear]
    - All time: [alltime] -
    -
    - Conversation Lines:
    - Single line: [singlelines]
    - 1-25 lines: [alines]
    - 25-50 lines: [blines]
    - 51-100 lines: [clines]
    - 101+ lines: [dlines]
    - Average: [avg] -
    -
    - + + + + + [pageTitle] + + [noLeftNav][noRightNav][upperScripts][errMsgStyle] + + + +[blank] + +
    [version]
    +
    +[logo] +[topNav] +[leftNav] +[main] +[rightNav] +[footer] +
    +[lowerScripts] + + + +Individual sections are placed after this section. This comment should NEVER be visible on any page! + +[blank] + + +[blank]
    +[divDecoration] +
      +[topNavLinks] +
    +
    + +You don't even have to place documentation within comment tags, since the sections +between the start and end section tags are the only parts of the template that are displayed. + +[blank]
    +[divDecoration] +[navHeader] +
      +[leftNavLinks] +
    +
    + + +[blank]
    +
     
    +[errMsg] +
    +
    +[divDecoration] +
    + [mainTitle] +
    +
    +[mainContent] +
    +
    + + +[blank]
    +[divDecoration] +[navHeader] +[rightNavLinks] +
    + + +[blank] + + +[blank] + + +[blank]
  • + +[divDecoration] + + [linkLabel] + + +
  • + + +[blank]
    +
    +
    +
    + + +[blank]
    +
    +[divDecoration] + My Program-O +
    +
    + + +[blank] + + +[blank] + + +[blank] + + +[blank] + + +[blank]
    [errorMessage]
    + + +[blank]
    +
    + Login +
    +
    + + +
    +
    + +
    +
    +
    + +
    +
    +
    +
    + + + +
    +
    + + + +
    +
    + + + + +[blank] +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + +
    + + + +
    + + + +
    + + + +
    + + + +
    + + + +
    + + + +
    +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + +
    + +
    + +
    + + + +
    + +
    + + + +
    + +
    +
    + +
    + +
    +
    + + + +
    + + +
    + + +
    [bot_name]'s Conversation Logs
    +

    [convo]

    + + + +
    +
    +
    Add a Misspelled word and it's correction:
    +
    + + +
    +
    + + +
    +
    + +
    +
    +
    + + +
    + +
    + + +
    +
    +
    Edit the entry for the Misspelled word [missspelling]:
    +
    + + +
    +
    + + +
    +
    + + + +
    +
    +
    + + +
    +
    +
    Add an improper word and it's replacement:
    +
    + + +
    +
    + + +
    +
    + +   +
    +
    +
    + + +
    + +
    + + +
    +
    +
    Edit the entry for the improper word [word_to_censor]:
    +
    + + +
    +
    + + +
    +
    + +   + +
    +
    +
    + + +[blank]
    +[teach_content] +
    +
    +[showHelp] +
    + + +[blank]
    +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    For help, click the icon in the title, above.
    +
    + +
    +
    +
    + + +[blank]
    +

    Help...

    +
    Adding a 'Topic' means that the bot will only be able to access this response if a previous aiml category has set this topic as it's current topic.
    +
    The 'Previous Bot Response' means that the bot must have answered with this text in it's last response.
    +
    The 'User Input' is the the users input used to access the bots response.
    +
    The 'Bot Response' is the text the bot will output when the 'user Input' has been matched.
    +
    +

    Simple Example

    +
    User input: hello how are you
    +
    Bot Response: I am well thank you and you?
    +
    +

    Intermediate example:

    +
    Previous Bot Response: I am well thank you and you
    +
    User input: ok thanks
    +
    Bot Response: That is great to hear
    +
    +

    Advanced example:

    +
    1. First response MUST set the topic
    +
    User input: I like chatbots
    +
    Bot Response: What do you like about them?
    +
    +
    2. Second pattern can only be accessed because the topic has been set in the previous response
    +
    Topic: chatbots
    +
    User input: I just think they are cool
    +
    Bot Response: Yes chatbots are cool
    +
    --You can find alot of information on the net about writing well formed aiml.
    --If you want to learn more about writing AIML start here +
    + + +[blank]
    +

    Help...

    +
    This help panel is under construction.
    +
    + + +[blank]
    +

    Help...

    +
    This part is still under construction.
    +
    +
    +
    +
    +
    + + +[blank]
    +

    Help...

    +
    If your aiml file will not upload you may want to check the following.
    +
    --Make sure the folder you are trying to upload to has read/write privs on it (CHMOD 755)
    +
    --Remove any comments from the aiml
    +
    --Replace everything above the first <cattegory> with a simple <aiml> tag
    +
    --You can find alot of information on the net about writing well formed aiml. +
    --If you want to learn more about writing AIML start here +
    + + +[blank]
    +

    Help...

    +
    This help panel is under construction.
    +
    + + + Click to toggle help + + +

    [rssRowTitle]

    +

    [rssRowContent]

    +
    + + + + + + + + + + + +
    Talk to [bot_name] using the [format] interface:
    +
    + + +[blank]
    +

    + Here's where you add, remove or edit admin accounts. +

    +[members_list_form] +[members_content] +
    +
    +[showHelp] +
    + + +[blank]

    [action] Admin Account:

    +
    +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + + +
    +
    +
    + + +[blank]
    +
    +
    + + + + +
    +
    +
    + + +[blank]
    +

    + Use this uploader to add AIML categories to your chatbot's database. You have the option + to upload either individual AIML files, or ZIP archive files of up to 2MB in size. + This uploader no longer performs XML validation, so you need to validate your AIML files prior to + uploading them. It's STRONGLY SUGGESTED that you use either W3School's + XML Validator, + or the GCC AIML Validator. + There are other XML validators available, but the W3Schools validator is one of the best, + and the one at Geek Cave Creations is specifically designed to validate AIML files. +

    +[upload_content] +
    +
    + List of Currently Stored AIML files for [bot_name]:
    +[AIML_List] +
    +
    +
    +
    +[showHelp] +
    + + +[blank]
    + + + + + + + + + + + +
    + +     + +     + +
    + +     +
    + +
    +
    + + +[blank] + + +
    +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    +
    + + +[blank]
    +

    [bot_name]'s Stats

    +
    + Conversations:
    + Today: [oneday]
    + Last week: [oneweek]
    + Last month: [onemonth]
    + Last six months: [sixmonths]
    + Last year: [oneyear]
    + All time: [alltime] +
    +
    + Conversation Lines:
    + Single line: [singlelines]
    + 1-25 lines: [alines]
    + 25-50 lines: [blines]
    + 51-100 lines: [clines]
    + 101+ lines: [dlines]
    + Average: [avg] +
    +
    + diff --git a/admin/demochat.php b/admin/demochat.php index b893718..4697f21 100644 --- a/admin/demochat.php +++ b/admin/demochat.php @@ -1,52 +1,52 @@ -getSection('TopNav'); - $leftNav = $template->getSection('LeftNav'); - $main = $template->getSection('Main'); - $topNavLinks = makeLinks('top', $topLinks, 12); - $navHeader = $template->getSection('NavHeader'); - $leftNavLinks = makeLinks('left', $leftLinks, 12); - $FooterInfo = getFooter(); - $errMsgClass = (!empty($msg)) ? "ShowError" : "HideError"; - $errMsgStyle = $template->getSection($errMsgClass); - $noLeftNav = ''; - $noTopNav = ''; - $noRightNav = $template->getSection('NoRightNav'); - $headerTitle = 'Actions:'; - $pageTitle = 'My-Program O - Chat Demo'; - $mainContent = 'This will eventually be the page for the chat demo.'; - $mainContent = showChatFrame(); - $mainTitle = 'Chat Demo'; - - function showChatFrame() { - global $template, $bot_name, $bot_id; - $dbconn = db_open(); - $sql = "select `format` from `bots` where `bot_id` = $bot_id limit 1;"; - $result = mysql_query($sql, $dbconn) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
    \nSQL = $sql
    \n"); - $row = mysql_fetch_assoc($result); - $format = strtolower($row['format']); - switch ($format) { - case "html": - $url = '../gui/plain/'; - break; - case "json": - $url = '../gui/jquery/'; - break; - case "xml": - $url = '../gui/xml/'; - break; - } - $out = $template->getSection('ChatDemo'); - $out = str_replace('[pageSource]', $url, $out); - $out = str_replace('[format]', strtoupper($format), $out); - return $out; - } +getSection('TopNav'); + $leftNav = $template->getSection('LeftNav'); + $main = $template->getSection('Main'); + $topNavLinks = makeLinks('top', $topLinks, 12); + $navHeader = $template->getSection('NavHeader'); + $leftNavLinks = makeLinks('left', $leftLinks, 12); + $FooterInfo = getFooter(); + $errMsgClass = (!empty($msg)) ? "ShowError" : "HideError"; + $errMsgStyle = $template->getSection($errMsgClass); + $noLeftNav = ''; + $noTopNav = ''; + $noRightNav = $template->getSection('NoRightNav'); + $headerTitle = 'Actions:'; + $pageTitle = 'My-Program O - Chat Demo'; + $mainContent = 'This will eventually be the page for the chat demo.'; + $mainContent = showChatFrame(); + $mainTitle = 'Chat Demo'; + + function showChatFrame() { + global $template, $bot_name, $bot_id; + $dbconn = db_open(); + $sql = "select `format` from `bots` where `bot_id` = $bot_id limit 1;"; + $result = mysql_query($sql, $dbconn) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
    \nSQL = $sql
    \n"); + $row = mysql_fetch_assoc($result); + $format = strtolower($row['format']); + switch ($format) { + case "html": + $url = '../gui/plain/'; + break; + case "json": + $url = '../gui/jquery/'; + break; + case "xml": + $url = '../gui/xml/'; + break; + } + $out = $template->getSection('ChatDemo'); + $out = str_replace('[pageSource]', $url, $out); + $out = str_replace('[format]', strtoupper($format), $out); + return $out; + } ?> \ No newline at end of file diff --git a/admin/download.php b/admin/download.php index c5d1596..80ad450 100644 --- a/admin/download.php +++ b/admin/download.php @@ -1,234 +1,286 @@ - -getSection('TopNav'); - $leftNav = $template->getSection('LeftNav'); - $main = $template->getSection('Main'); - $topNavLinks = makeLinks('top', $topLinks, 12); - $navHeader = $template->getSection('NavHeader'); - $leftNavLinks = makeLinks('left', $leftLinks, 12); - $FooterInfo = getFooter(); - $errMsgClass = (!empty($msg)) ? "ShowError" : "HideError"; - $errMsgStyle = $template->getSection($errMsgClass); - $noLeftNav = ''; - $noTopNav = ''; - $noRightNav = $template->getSection('NoRightNav'); - $headerTitle = 'Actions:'; - $pageTitle = 'My-Program O - Download AIML'; - $mainContent = $content; - $mainTitle = 'Download AIML'; - - function replaceTags(&$content) { - return $content; - } - - function getAIMLByFileName($filename) { - global $dbn,$botmaster_name; - $categoryTemplate = '[pattern][that]'; - $dbconn = db_open(); - $cleanedFilename = mysql_real_escape_string($filename, $dbconn); - # Get all topics within the file - $topicArray = array(); - $curPath = dirname(__FILE__); - chdir($curPath); - $fileContent = file_get_contents('./AIML_Header.dat'); - #$x = file_put_contents('./AIML_Header_tmp.dat', $fileContent); - $fileContent = str_replace('[botmaster_name]', $botmaster_name, $fileContent); - $curDate = date('m-d-Y', time()); - $fileContent = str_replace('[curDate]', $curDate, $fileContent); - $fileContent = str_replace('[fileName]', $cleanedFilename, $fileContent); - $sql = "select distinct topic from aiml where filename like '$cleanedFilename';"; - #return "SQL = $sql"; - $result = mysql_query($sql,$dbconn) or die(mysql_error()); - while ($row = mysql_fetch_assoc($result)) { - $topicArray[] = $row['topic']; - } - foreach ($topicArray as $topic) { - if (!empty($topic)) $fileContent .= "\n"; - $sql = "select pattern, thatpattern, template from aiml where topic like '$topic' and filename like '$cleanedFilename';"; - $fileContent .= "\r\n\r\n\r\n\r\n"; - $result = mysql_query($sql,$dbconn) or die(mysql_error()); - while ($row = mysql_fetch_assoc($result)) { - $pattern = strtoupper($row['pattern']); - $template = str_replace("\r\n",'',$row['template']); - $template = str_replace("\n",'',$row['template']); - $newLine = str_replace('[pattern]',$pattern, $categoryTemplate); - $newLine = str_replace('[template]',$template,$newLine); - $that = (!empty($row['thatpattern'])) ? '' . $row['thatpattern'].'' : ''; - $newLine = str_replace('[that]',$that,$newLine); - $fileContent .= "$newLine\n"; - } - if (!empty($topic)) $fileContent .= "\n"; - } - $fileContent .= "\r\n
    \r\n"; - $outFile = ltrim($fileContent, "\n\r\n"); - $x = file_put_contents("./downloads/$cleanedFilename", trim($outFile)); - - mysql_close($dbconn); - $msg = "
    AIML file $filename successfully saved!"; - $msg = "Your file, $filename, is being prepaired. If it doesn't start, please Click Here.
    \n"; - return serveFile($filename, $msg); - } - - function getSQLByFileName($filename) { - global $dbn,$botmaster_name, $dbh; - $curPath = dirname(__FILE__); - chdir($curPath); - $dbFilename = $filename; - $filename = str_ireplace('.aiml', '.sql', $filename); // change to sql extension for clarity - $categoryTemplate = " ([id],[bot_id],'[aiml]','[pattern]','[thatpattern]','[template]','[topic]','[filename]','[php_code]'),"; - $dbconn = db_open(); - $phpVer = phpversion(); - $cleanedFilename = mysql_real_escape_string($dbFilename, $dbconn); - # Get all topics within the file - $topicArray = array(); - $sql = "select * from aiml where filename like '$cleanedFilename' order by id asc;"; - $fileContent = file_get_contents('SQL_Header.dat'); - $fileContent = str_replace('[botmaster_name]', $botmaster_name, $fileContent); - $fileContent = str_replace('[host]', $dbh, $fileContent); - $fileContent = str_replace('[dbn]', $dbn, $fileContent); - $fileContent = str_replace('[sql]', $sql, $fileContent); - $fileContent = str_replace('[phpVer]', $phpVer, $fileContent); - $curDate = date('m-d-Y h:j:s A', time()); - $fileContent = str_replace('[curDate]', $curDate, $fileContent); - $fileContent = str_replace('[fileName]', $cleanedFilename, $fileContent); - - $result = mysql_query($sql,$dbconn) or die(mysql_error()); - while ($row = mysql_fetch_assoc($result)) { - $aiml = str_replace("\r\n",'',$row['aiml']); - $aiml = str_replace("\n",'',$aiml); - $aiml = mysql_real_escape_string($aiml,$dbconn); - $template = str_replace("\r\n",'',$row['template']); - $template = str_replace("\n",'',$template); - $template = mysql_real_escape_string($template,$dbconn); - $newLine = str_replace('[id]', $row['id'], $categoryTemplate); - $newLine = str_replace('[bot_id]', $row['bot_id'], $newLine); - $newLine = str_replace('[aiml]', $aiml, $newLine); - $newLine = str_replace('[pattern]', $row['pattern'], $newLine); - $newLine = str_replace('[thatpattern]',$row['thatpattern'], $newLine); - $newLine = str_replace('[template]', $template, $newLine); - $newLine = str_replace('[topic]', $row['topic'], $newLine); - $newLine = str_replace('[filename]', $row['filename'], $newLine); - $newLine = str_replace('[php_code]', $row['php_code'], $newLine); - $fileContent .= "$newLine\r\n"; - } - $fileContent = trim($fileContent,",\r\n"); // remove the comma from the last row - $fileContent .= "\n"; - $x = file_put_contents("./downloads/$filename", trim($fileContent)); - - mysql_close($dbconn); - $msg = "Your file, $filename, is being prepaired. If it doesn't start, please Click Here.
    \n"; - return serveFile($filename, $msg); - } - - function getSelOpts() { - global $dbn; - $out = " \n"; - $dbconn = db_open(); - $optionTemplate = " \n"; - $sql = 'SELECT DISTINCT filename FROM aiml order by filename;'; - #return "SQL = $sql"; - $result = mysql_query($sql,$dbconn) or die(mysql_error()); - while ($row = mysql_fetch_assoc($result)) { - if (empty($row['filename'])) { - $curOption = " \n"; - } - else $curOption = str_replace('[val]', $row['filename'], $optionTemplate); - $out .= $curOption; - } - mysql_close($dbconn); - $out .= " \n"; - return $out; - } - - function renderMain() { - $selectOptions = getSelOpts(); - $content = << -
    - - - - - - - - - -
    - - - -
    - - - - - -
    -
    -endForm; - - return $content; - } - - function serveFile($req_file, &$msg = '') { - $fileserver_path = dirname(__FILE__) . '/downloads'; // change this to the directory your files reside - $whoami = basename(__FILE__); // you are free to rename this file - $myMsg = urlencode($msg); -/* no web spamming */ -if (!preg_match("/^[a-zA-Z0-9._-]+$/", $req_file, $matches)) { - return "I don't know what you were trying to do, nor do I care. Just stop it."; -} - -/* download any file, but not this one */ -if ($req_file == $whoami) { - return "I don't know what you were trying to do, nor do I care. Just stop it."; -} - -/* check if file exists */ -if (!file_exists("$fileserver_path/$req_file")) { - return "File $req_file doesn't exist."; -} - -if (empty($_GET['send_file'])) { - header("Refresh: 5; url=$whoami?file=$req_file&send_file=yes&msg=$myMsg"); -} -else { - header('Content-Description: File Transfer'); - header('Content-Type: application/force-download'); - header('Content-Length: ' . filesize("$fileserver_path/$req_file")); - header('Content-Disposition: attachment; filename=' . $req_file); - #readfile("$fileserver_path/$req_file"); - print file_get_contents("$fileserver_path/$req_file"); - exit; -} - return $msg; - } + + + + +endScript; + +$msg = (isset($_REQUEST['msg'])) ? $_REQUEST['msg'] : ''; +if((isset($_POST['action']))&&($_POST['action']=="AIML")) { + $status = getAIMLByFileName($_POST['getFile']); +} +elseif((isset($_POST['action']))&&($_POST['action']=="SQL")) { + $status = getSQLByFileName($_POST['getFile']); +} +elseif(isset($_GET['file'])) { + $status = serveFile($_GET['file'], $msg); +} +else { +} + $content .= renderMain(); + $showHelp = $template->getSection('DownloadShowHelp'); + + $topNav = $template->getSection('TopNav'); + $leftNav = $template->getSection('LeftNav'); + $main = $template->getSection('Main'); + $topNavLinks = makeLinks('top', $topLinks, 12); + $navHeader = $template->getSection('NavHeader'); + $leftNavLinks = makeLinks('left', $leftLinks, 12); + $FooterInfo = getFooter(); + #$msg = (empty($msg)) ? 'Test' : $msg; + $errMsgClass = (!empty($msg)) ? "ShowError" : "HideError"; + $errMsgStyle = $template->getSection($errMsgClass); + $noLeftNav = ''; + $noTopNav = ''; + $noRightNav = $template->getSection('NoRightNav'); + $headerTitle = 'Actions:'; + $pageTitle = "My-Program O - Download AIML files"; + $mainContent = $content; + $mainTitle = "Download AIML files for the bot named $bot_name [helpLink]"; + + $mainContent = str_replace('[showHelp]', $showHelp, $mainContent); + $mainContent = str_replace('[status]', $status, $mainContent); + $mainTitle = str_replace('[helpLink]', $template->getSection('HelpLink'), $mainTitle); + + function replaceTags(&$content) { + return $content; + } + + function getAIMLByFileName($filename) { + global $dbn,$botmaster_name; + $bmnLen = strlen($botmaster_name) - 2; // The "- 2" accommodates the extra 2 spaces from the year. + $bmnSearch = str_pad('[bm_name]',$bmnLen); + $categoryTemplate = '[pattern][that]'; + $dbconn = db_open(); + $cleanedFilename = mysql_real_escape_string($filename, $dbconn); + $fileNameSearch = '[fileName]'; + $cfnLen = strlen($cleanedFilename); + $fileNameSearch = str_pad($fileNameSearch, $cfnLen); + # Get all topics within the file + $topicArray = array(); + $curPath = dirname(__FILE__); + chdir($curPath); + $fileContent = file_get_contents('./AIML_Header.dat'); + $fileContent = str_replace('[year]', date('Y'), $fileContent); + $fileContent = str_replace($bmnSearch, $botmaster_name, $fileContent); + $curDate = date('m-d-Y', time()); + $cdLen = strlen($curDate); + $curDateSearch = str_pad('[curDate]',$cdLen); + $fileContent = str_replace($curDateSearch, $curDate, $fileContent); + $fileContent = str_replace($fileNameSearch, $cleanedFilename, $fileContent); + $sql = "select distinct topic from aiml where filename like '$cleanedFilename';"; + #return "SQL = $sql"; + $result = mysql_query($sql,$dbconn) or trigger_error('Cannot load the list of topics from the DB. Error = ' . mysql_error()); + while ($row = mysql_fetch_assoc($result)) { + $topicArray[] = $row['topic']; + } + foreach ($topicArray as $topic) { + if (!empty($topic)) $fileContent .= "\n"; + $sql = "select pattern, thatpattern, template from aiml where topic like '$topic' and filename like '$cleanedFilename';"; + $fileContent .= "\r\n\r\n\r\n\r\n"; + $result = mysql_query($sql,$dbconn) or trigger_error('Cannot obtain the AIML categories from the DB. Error = ' . mysql_error()); + while ($row = mysql_fetch_assoc($result)) { + $pattern = strtoupper($row['pattern']); + $template = str_replace("\r\n",'',$row['template']); + $template = str_replace("\n",'',$row['template']); + $newLine = str_replace('[pattern]',$pattern, $categoryTemplate); + $newLine = str_replace('[template]',$template,$newLine); + $that = (!empty($row['thatpattern'])) ? '' . $row['thatpattern'].'' : ''; + $newLine = str_replace('[that]',$that,$newLine); + $fileContent .= "$newLine\n"; + } + if (!empty($topic)) $fileContent .= "\n"; + } + $fileContent .= "\r\n
    \r\n"; + $outFile = ltrim($fileContent, "\n\r\n"); + $x = file_put_contents("./downloads/$cleanedFilename", trim($outFile)); + + mysql_close($dbconn); + $msg = "Your file, $filename, is being prepaired. If it doesn't start, please Click Here.
    \n"; + return serveFile($filename, $msg); + } + + function getSQLByFileName($filename) { + global $dbn,$botmaster_name, $dbh; + $curPath = dirname(__FILE__); + chdir($curPath); + $dbFilename = $filename; + $filename = str_ireplace('.aiml', '.sql', $filename); // change to sql extension for clarity + $categoryTemplate = " ([id],[bot_id],'[aiml]','[pattern]','[thatpattern]','[template]','[topic]','[filename]','[php_code]'),"; + $dbconn = db_open(); + $phpVer = phpversion(); + $cleanedFilename = mysql_real_escape_string($dbFilename, $dbconn); + # Get all topics within the file + $topicArray = array(); + $sql = "select * from aiml where filename like '$cleanedFilename' order by id asc;"; + $fileContent = file_get_contents('SQL_Header.dat'); + $fileContent = str_replace('[botmaster_name]', $botmaster_name, $fileContent); + $fileContent = str_replace('[host]', $dbh, $fileContent); + $fileContent = str_replace('[dbn]', $dbn, $fileContent); + $fileContent = str_replace('[sql]', $sql, $fileContent); + $fileContent = str_replace('[phpVer]', $phpVer, $fileContent); + $curDate = date('m-d-Y h:j:s A', time()); + $fileContent = str_replace('[curDate]', $curDate, $fileContent); + $fileContent = str_replace('[fileName]', $cleanedFilename, $fileContent); + + $result = mysql_query($sql,$dbconn) or trigger_error('Cannot load the AIML categories from the DB. Error = ' . mysql_error());; + while ($row = mysql_fetch_assoc($result)) { + $aiml = str_replace("\r\n",'',$row['aiml']); + $aiml = str_replace("\n",'',$aiml); + $aiml = mysql_real_escape_string($aiml,$dbconn); + $template = str_replace("\r\n",'',$row['template']); + $template = str_replace("\n",'',$template); + $template = mysql_real_escape_string($template,$dbconn); + $newLine = str_replace('[id]', $row['id'], $categoryTemplate); + $newLine = str_replace('[bot_id]', $row['bot_id'], $newLine); + $newLine = str_replace('[aiml]', $aiml, $newLine); + $newLine = str_replace('[pattern]', $row['pattern'], $newLine); + $newLine = str_replace('[thatpattern]',$row['thatpattern'], $newLine); + $newLine = str_replace('[template]', $template, $newLine); + $newLine = str_replace('[topic]', $row['topic'], $newLine); + $newLine = str_replace('[filename]', $row['filename'], $newLine); + $newLine = str_replace('[php_code]', $row['php_code'], $newLine); + $fileContent .= "$newLine\r\n"; + } + $fileContent = trim($fileContent,",\r\n"); // remove the comma from the last row + $fileContent .= "\n"; + $x = file_put_contents("./downloads/$filename", trim($fileContent)); + + mysql_close($dbconn); + $msg = "Your file, $filename, is being prepaired. If it doesn't start, please Click Here.
    \n"; + return serveFile($filename, $msg); + } + + function getSelOpts() { + global $dbn, $bot_id, $msg; + $out = " \n"; + $dbconn = db_open(); + $optionTemplate = " \n"; + $sql = "SELECT DISTINCT filename FROM `aiml` where `bot_id` = $bot_id order by `filename`;"; + #return "SQL = $sql"; + $result = mysql_query($sql,$dbconn) or trigger_error('Cannot load the list of filenames from the DB. Error = ' . mysql_error()); + if (mysql_num_rows($result) == 0) $msg = "This bot has no AIML categories. Please select another bot."; + while ($row = mysql_fetch_assoc($result)) { + if (empty($row['filename'])) { + $curOption = " \n"; + } + else $curOption = str_replace('[val]', $row['filename'], $optionTemplate); + $out .= $curOption; + } + mysql_close($dbconn); + $out .= " \n"; + return $out; + } + + function renderMain() { + $selectOptions = getSelOpts(); + $content = << + Please select the AIML file you wish to download from the list below.
    +
    + + + + + + + + + +
    + + + +
    + + + + + +
    +
    +
    [status]
    + +[showHelp] +endForm; + + return $content; + } + + function serveFile($req_file, &$msg = '') { + $fileserver_path = dirname(__FILE__) . '/downloads'; // change this to the directory your files reside + $whoami = basename(__FILE__); // you are free to rename this file + $myMsg = urlencode($msg); +/* no web spamming */ +if (!preg_match("/^[a-zA-Z0-9._-]+$/", $req_file, $matches)) { + return "I don't know what you were trying to do, nor do I care. Just stop it."; +} + +/* download any file, but not this one */ +if ($req_file == $whoami) { + return "I don't know what you were trying to do, nor do I care. Just stop it."; +} + +/* check if file exists */ +if (!file_exists("$fileserver_path/$req_file")) { + return "File $req_file doesn't exist."; +} + +if (empty($_GET['send_file'])) { + header("Refresh: 5; url=$whoami?file=$req_file&send_file=yes&msg=$myMsg"); +} +else { + header('Content-Description: File Transfer'); + header('Content-Type: application/force-download'); + header('Content-Length: ' . filesize("$fileserver_path/$req_file")); + header('Content-Disposition: attachment; filename=' . $req_file); + #readfile("$fileserver_path/$req_file"); + print file_get_contents("$fileserver_path/$req_file"); + exit; +} + return $msg; + } ?> \ No newline at end of file diff --git a/admin/error.log b/admin/downloads/index.html similarity index 100% rename from admin/error.log rename to admin/downloads/index.html diff --git a/admin/file.php b/admin/file.php index 74b993c..1568162 100644 --- a/admin/file.php +++ b/admin/file.php @@ -1,48 +1,48 @@ -$req_file doesn't exist."; - exit; -} - -if (empty($_GET['send_file'])) { - header("Refresh: 5; url=$whoami?file=$req_file&send_file=yes"); -} -else { - header('Content-Description: File Transfer'); - header('Content-Type: application/force-download'); - header('Content-Length: ' . filesize("$fileserver_path/$req_file")); - header('Content-Disposition: attachment; filename=' . $req_file); - #readfile("$fileserver_path/$req_file"); - print file_get_contents("$fileserver_path/$req_file"); - exit; -} -header("Location: $pageBack"); -?> - +$req_file doesn't exist."; + exit; +} + +if (empty($_GET['send_file'])) { + header("Refresh: 5; url=$whoami?file=$req_file&send_file=yes"); +} +else { + header('Content-Description: File Transfer'); + header('Content-Type: application/force-download'); + header('Content-Length: ' . filesize("$fileserver_path/$req_file")); + header('Content-Disposition: attachment; filename=' . $req_file); + #readfile("$fileserver_path/$req_file"); + print file_get_contents("$fileserver_path/$req_file"); + exit; +} +header("Location: $pageBack"); +?> + diff --git a/admin/formTest.php b/admin/formTest.php index e0412a8..51a3d36 100644 --- a/admin/formTest.php +++ b/admin/formTest.php @@ -1,144 +1,144 @@ - - - - - - - -
    -
    -
    - - - -
    -
    -
    -
    -
    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - -
    - - - -
    - - - -
    - - - -
    - - - -
    - - - -
    -
    -
    - - - - - - - - - - - - - - - - - - - - - -
    - -
    - -
    - -
    - -
    - -
    -
    - -
    - -
    -
    -
    - + + + + + + + +
    +
    +
    + + + +
    +
    +
    +
    +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + +
    + + + +
    + + + +
    + + + +
    + + + +
    + + + +
    +
    +
    + + + + + + + + + + + + + + + + + + + + + +
    + +
    + +
    + +
    + +
    + +
    +
    + +
    + +
    +
    +
    + \ No newline at end of file diff --git a/admin/images/closeButton.png b/admin/images/closeButton.png new file mode 100644 index 0000000..fae56c3 Binary files /dev/null and b/admin/images/closeButton.png differ diff --git a/admin/images/index.html b/admin/images/index.html index f9055b0..b6201a8 100644 --- a/admin/images/index.html +++ b/admin/images/index.html @@ -1,10 +1,10 @@ - - - - -My Program-O - - - - - + + + + +My Program-O + + + + + diff --git a/admin/index.php b/admin/index.php index 7982ad3..8559819 100644 --- a/admin/index.php +++ b/admin/index.php @@ -1,436 +1,492 @@ -getSection('Logo'); - $titleSpan = $template->getSection('TitleSpan'); - $main = $template->getSection('Main'); - $divDecoration = $template->getSection('DivDecoration'); - $mainContent = $template->getSection('LoginForm'); - $noLeftNav = $template->getSection('NoLeftNav'); - $noRightNav = $template->getSection('NoRightNav'); - $navHeader = $template->getSection('NavHeader'); - $footer = $template->getSection('Footer'); - $topNav = ''; - $leftNav = ''; - $rightNav = ''; - $rightNavLinks = ''; - $lowerScripts = $template->getSection('LogoLinkScript'); - $pageTitleInfo = ''; - #$topNavLinks = makeLinks('top', $topLinks, 12); - $topNavLinks = ''; - $leftNavLinks = ''; - $mediaType = ' media="screen"'; - $mainTitle = 'Program O Login'; - $FooterInfo = '

    © 2011 My Program-O
    www.program-o.com

    '; - $headerTitle = ''; - $pageTitle = 'My-Program O - Login'; - $upperScripts = ''; - - if((isset($_POST['uname']))&&(isset($_POST['pw']))) { - $_SESSION['poadmin']['display'] = $hide_logo; - $uname = mysql_escape_string(strip_tags(trim($_POST['uname']))); - $pw = mysql_escape_string(strip_tags(trim($_POST['pw']))); - $dbconn = db_open(); - $sql = "SELECT * FROM `myprogramo` WHERE uname = '".$uname."' AND pword = '".MD5($pw)."'"; - $result = mysql_query($sql,$dbconn) or die ("mySQL error:" . mysql_error($dbconn)); - $count = mysql_num_rows($result); - $msg =""; - if($count>0) { - $row=mysql_fetch_array($result); - $_SESSION['poadmin']['uid']=$row['id']; - $_SESSION['poadmin']['name']=$row['uname']; - $_SESSION['poadmin']['lip']=$row['lastip']; - $_SESSION['poadmin']['llastlogin']=date('l jS \of F Y h:i:s A', strtotime($row['lastlogin'])); - if(!empty($_SERVER['HTTP_CLIENT_IP'])) { //check ip from share internet - $ip=$_SERVER['HTTP_CLIENT_IP']; - } - elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { //to check ip is pass from proxy - $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; - } - else { - $ip=$_SERVER['REMOTE_ADDR']; - } - $sqlupdate = "UPDATE `myprogramo` SET `lastip` = '$ip', `lastlogin` = CURRENT_TIMESTAMP WHERE uname = '$uname' limit 1"; - //echo $sql; - $result = mysql_query($sqlupdate,$dbconn); - $transact = mysql_affected_rows($dbconn); - $_SESSION['poadmin']['ip']=$ip; - $_SESSION['poadmin']['lastlogin']=date('l jS \of F Y h:i:s A'); - $sql = "SELECT * FROM `bots` WHERE bot_active = '1' ORDER BY bot_id ASC LIMIT 1"; - $result = mysql_query($sql,$dbconn); - $count = mysql_num_rows($result); - $msg =""; - if($count>0) { - $row=mysql_fetch_array($result); - $_SESSION['poadmin']['bot_id']=$row['bot_id']; - $_SESSION['poadmin']['bot_name']=$row['bot_name']; - } - else { - $_SESSION['poadmin']['bot_id']=-1; - $_SESSION['poadmin']['bot_name']="unknown"; - } - } - else { - $msg = "incorrect username/password"; - } - mysql_close($dbconn); - if($msg == "") { - include ('main.php'); - } - } - elseif(isset($_GET['msg'])) { - $msg = htmlentities($_GET['msg']); - } - elseif(isset($_GET['page'])) { - $curPage = $_GET['page']; - if ($curPage == 'logout') { - if(isset($_COOKIE[session_name()])) { - setcookie(session_name(), '', time()-42000, '/'); - } - session_destroy(); - //header('location: ./'); - } - else { - $_SESSION['poadmin']['curPage'] = $curPage; - include ("$curPage.php"); - } - } - $curPage = (isset($curPage)) ? $curPage : 'main'; - $upperScripts .= ($hide_logo == 'HideLogoCSS') ? $template->getSection('HideLogoCSS') : ''; - - # Build page content from the template - $content = $template->getSection('Header'); - #$content .= "hide_logo = $hide_logo"; - $content .= $template->getSection('PageBody'); - - # Replace template labels with real data - $styleSheet = 'style.css'; - $errMsgClass = (!empty($msg)) ? "ShowError" : "HideError"; - $errMsgStyle = $template->getSection($errMsgClass); -/* These are the most common template replacement tags used. Any additional - replacement tags should be handled in the include file for the current page, - in a function named replaceTags(&$content). This function will alter the - $content variable directly, rather than change it and then return it. -*/ - $searches = array( - '[myPage]' => $curPage, - '[pageTitle]' => $pageTitle, - '[styleSheet]' => $styleSheet, - '[mediaType]' => $mediaType, - '[upperScripts]' => $upperScripts, - '[logo]' => $logo, - '[pageTitleInfo]' => $pageTitleInfo, - '[topNav]' => $topNav, - '[leftNav]' => $leftNav, - '[rightNav]' => $rightNav, - '[main]' => $main, - '[rightNav]' => $rightNav, - '[footer]' => $footer, - '[lowerScripts]' => $lowerScripts, - '[pageTitleInfo]' => $pageTitleInfo, - '[titleSpan]' => $titleSpan, - '[divDecoration]' => $divDecoration, - '[topNavLinks]' => $topNavLinks, - '[navHeader]' => $navHeader, - '[leftNavLinks]' => $leftNavLinks, - '[mainTitle]' => $mainTitle, - '[mainContent]' => $mainContent, - '[rightNavLinks]' => $rightNavLinks, - '[FooterInfo]' => $FooterInfo, - '[headerTitle]' => $headerTitle, - '[errMsg]' => $msg, - '[bot_id]' => $bot_id, - '[bot_name]' => $bot_name, - '[errMsgStyle]' => $errMsgStyle, - '[noRightNav]' => $noRightNav, - '[noLeftNav]' => $noLeftNav - ); - foreach ($searches as $search => $replace) { - $content = str_replace($search, $replace, $content); - } - $content = str_replace('[myPage]', $curPage, $content); - $content = str_replace('[divDecoration]', $divDecoration, $content); - $content = str_replace('[blank]', '', $content); - if(function_exists('replaceTags')) replaceTags($content); // Handle any extra replacement tags, as needed. - #die ('
    ' . print_r($_SESSION, true) . "

    \ndisplay = $hide_logo
    \n"); - exit($content); - - function makeLinks($section, $linkArray, $spaces = 2) { - #print "\n"; - global $template, $curPage; - $curPage = (empty($curPage)) ? 'main' : $curPage; - $botName = (isset($_SESSION['poadmin']['bot_name'])) ? $_SESSION['poadmin']['bot_name'] : 'unknown'; - $out = ''; - # [linkClass][linkHref][linkOnclick][linkAlt][linkTitle]>[linkLabel] - $linkText = $template->getSection('NavLink'); - foreach ($linkArray as $needle) { - $tmp = $linkText; - foreach ($needle as $search => $replace) { - $tmp = str_replace($search, $replace, $tmp); - } - $linkClass = $needle['[linkHref]']; - $linkClass = str_replace(' href="http://github.com/?page=', '', $linkClass); - $linkClass = str_replace('"', '', $linkClass); - #die ("linkClass = $linkClass
    \nstrstr = $sp
    \n"); - #$curClass = ($linkClass == $curPage) ? 'selected' : 'noClass'; - $curClass = ($linkClass == $curPage) ? 'selected' : 'noClass'; - if ($curPage == 'main') $curClass = (stripos($linkClass,'main') !== false) ? 'selected' : 'noClass'; -/* -*/ - $tmp = str_replace('[curClass]', $curClass, $tmp); - $out .= "$tmp\n"; - } - #print "\n"; - $out = str_replace('[curBot]', $botName, $out); - return trim($out); - } - - - function getFooter() { - $ip = $_SERVER['REMOTE_ADDR']; - $name = $_SESSION['poadmin']['name']; - $lip = $_SESSION['poadmin']['lip']; - $last = $_SESSION['poadmin']['lastlogin']; - $llast = $_SESSION['poadmin']['llastlogin']; - $admess = "You are logged in as: $name from $ip since: $last"; - $admess .= "
    You last logged in from $lip on $llast"; - $today = date("Y"); - $out = <<© $today My Program-O
    $admess

    -endFooter; - return $out; - } - - function makeTopLinks() { - $out = array( - array( - '[linkClass]' => ' class="[curClass]"', - '[linkHref]' => ' href="http://github.com/?page=main"', - '[linkOnclick]' => '', - '[linkAlt]' => ' alt="Home"', - '[linkTitle]' => ' title="Home"', - '[linkLabel]' => 'Home' - ), - array( - '[linkClass]' => ' class="[curClass]"', - '[linkHref]' => ' href="http://www.program-o.com/"', - '[linkOnclick]' => '', - '[linkAlt]' => ' alt="Get the latest news from the Program O website"', - '[linkTitle]' => ' title="Get the latest news from the Program O website"', - '[linkLabel]' => 'News' - ), - array( - '[linkClass]' => ' class="[curClass]"', - '[linkHref]' => ' href="http://www.program-o.com/ns/faq/"', - '[linkOnclick]' => '', - '[linkAlt]' => ' alt="The Program O User\'s Guide"', - '[linkTitle]' => ' title="The Program O User\'s Guide"', - '[linkLabel]' => 'Documentation' - ), - array( - '[linkClass]' => ' class="[curClass]"', - '[linkHref]' => ' href="http://github.com/?page=bugs"', - '[linkOnclick]' => '', - '[linkAlt]' => ' alt="Bug reporting"', - '[linkTitle]' => ' title="Bug reporting"', - '[linkLabel]' => 'Bug Reporting' - ), - array( - '[linkClass]' => ' class="[curClass]"', - '[linkHref]' => ' href="http://github.com/?page=stats"', - '[linkOnclick]' => '', - '[linkAlt]' => ' alt="Get bot statistics"', - '[linkTitle]' => ' title="Get bot statistics"', - '[linkLabel]' => 'Stats' - ), - array( - '[linkClass]' => ' class="[curClass]"', - '[linkHref]' => ' href="http://www.program-o.com/support/"', - '[linkOnclick]' => '', - '[linkAlt]' => ' alt="Get support for Program O"', - '[linkTitle]' => ' title="Get support for Program O"', - '[linkLabel]' => 'Support' - ), - array( - '[linkClass]' => '', - '[linkHref]' => ' href="http://github.com/?page=logout"', - '[linkOnclick]' => '', - '[linkAlt]' => ' alt="Log out"', - '[linkTitle]' => ' title="Log out"', - '[linkLabel]' => 'Log Out' - ) - ); - return $out; - } - function makeLeftLinks() { - $out = array( - array( # Change bot - '[linkClass]' => ' class="[curClass]"', - '[linkHref]' => ' href="http://github.com/?page=select_bots"', - '[linkOnclick]' => '', - '[linkAlt]' => ' alt="Change or edit the current bot"', - '[linkTitle]' => ' title="Change or edit the current bot"', - '[linkLabel]' => 'Change/Edit Bot: ([curBot])' - ), - array( - '[linkClass]' => ' class="[curClass]"', - '[linkHref]' => ' href="http://github.com/?page=bots"', - '[linkOnclick]' => '', - '[linkAlt]' => ' alt="Edit your bot\'s personality"', - '[linkTitle]' => ' title="Edit your bot\'s personality"', - '[linkLabel]' => 'Bot Personality' - ), - array( - '[linkClass]' => ' class="[curClass]"', - '[linkHref]' => ' href="http://github.com/?page=logs"', - '[linkOnclick]' => '', - '[linkAlt]' => ' alt="View the log files"', - '[linkTitle]' => ' title="View the log files"', - '[linkLabel]' => 'Logs' - ), - array( - '[linkClass]' => ' class="[curClass]"', - '[linkHref]' => ' href="http://github.com/?page=teach"', - '[linkOnclick]' => '', - '[linkAlt]' => ' alt="Train your bot"', - '[linkTitle]' => ' title="Train your bot"', - '[linkLabel]' => 'Teach' - ), - array( - '[linkClass]' => ' class="[curClass]"', - '[linkHref]' => ' href="http://github.com/?page=upload"', - '[linkOnclick]' => '', - '[linkAlt]' => ' alt="Upload AIML files"', - '[linkTitle]' => ' title="Upload AIML files"', - '[linkLabel]' => 'Upload AIML' - ), - array( - '[linkClass]' => ' class="[curClass]"', - '[linkHref]' => ' href="http://github.com/?page=download"', - '[linkOnclick]' => '', - '[linkAlt]' => ' alt="Download AIML files"', - '[linkTitle]' => ' title="Download AIML files"', - '[linkLabel]' => 'Download AIML' - ), - array( - '[linkClass]' => ' class="[curClass]"', - '[linkHref]' => ' href="http://github.com/?page=clear"', - '[linkOnclick]' => '', - '[linkAlt]' => ' alt="Clear AIML Categories"', - '[linkTitle]' => ' title="Clear AIML Categories"', - '[linkLabel]' => 'Clear AIML Categories' - ), - array( - '[linkClass]' => ' class="[curClass]"', - '[linkHref]' => ' href="http://github.com/?page=spellcheck"', - '[linkOnclick]' => '', - '[linkAlt]' => ' alt="Edit the SpellCheck entries"', - '[linkTitle]' => ' title="Edit the SpellCheck entries"', - '[linkLabel]' => 'Spell Check' - ), - array( - '[linkClass]' => ' class="[curClass]"', - '[linkHref]' => ' href="http://github.com/?page=wordcensor"', - '[linkOnclick]' => '', - '[linkAlt]' => ' alt="Edit the Word Censor entries"', - '[linkTitle]' => ' title="Edit the Word Censor entries"', - '[linkLabel]' => 'Word Censor' - ), - array( - '[linkClass]' => ' class="[curClass]"', - '[linkHref]' => ' href="http://github.com/?page=search"', - '[linkOnclick]' => '', - '[linkAlt]' => ' alt="Search and edit specific AIML categories"', - '[linkTitle]' => ' title="Search and edit specific AIML categories"', - '[linkLabel]' => 'Search/Edit AIML' - ), - array( - '[linkClass]' => ' class="[curClass]"', - '[linkHref]' => ' href="http://github.com/?page=demochat"', - '[linkOnclick]' => '', - '[linkAlt]' => ' alt="Run a demo version of your bot"', - '[linkTitle]' => ' title="Run a demo version of your bot"', - '[linkLabel]' => 'Demo Chat' - ), - array( - '[linkClass]' => '', - '[linkHref]' => ' href="http://github.com/?page=members"', - '[linkOnclick]' => '', - '[linkAlt]' => ' alt="Edit Admin Accounts"', - '[linkTitle]' => ' title="Edit Admin Accounts"', - '[linkLabel]' => 'Edit Admin Accounts' - ), - array( - '[linkClass]' => '', - '[linkHref]' => ' href="http://github.com/?page=logout"', - '[linkOnclick]' => '', - '[linkAlt]' => ' alt="Log out"', - '[linkTitle]' => ' title="Log out"', - '[linkLabel]' => 'Log Out' - ), - array( - '[linkClass]' => '', - '[linkHref]' => ' href="#"', - '[linkOnclick]' => ' onclick="toggleLogo(); return false;"', - '[linkAlt]' => ' alt="Toggle the Logo"', - '[linkTitle]' => ' title="Toggle the Logo"', - '[linkLabel]' => 'Toggle the Logo' - ) - ); - return $out; - } - -?> +\n"; + $_GET['page'] = 'logout'; + } + else { + $name = $_SESSION['poadmin']['name']; + $ip = $_SESSION['poadmin']['ip']; + $last = $_SESSION['poadmin']['lastlogin']; + $lip = $_SESSION['poadmin']['lip']; + $llast = $_SESSION['poadmin']['llastlogin']; + $bot_name = $_SESSION['poadmin']['bot_name']; + $bot_id = $_SESSION['poadmin']['bot_id']; + } + } + //load shared files + require_once(_LIB_PATH_ . 'db_functions.php'); + require_once(_LIB_PATH_ . 'error_functions.php'); + require_once(_LIB_PATH_ . 'template.class.php'); + # Load the template file + $thisPath = dirname(__FILE__); + $template = new Template("$thisPath/default.page.htm"); + $leftLinks = makeLeftLinks(); + $topLinks = makeTopLinks(); + $githubVersion = getCurrentVersion(); + $version = ($githubVersion == VERSION) ? 'Program O version ' . VERSION : 'There is a new version of Program O available. Click here to download it.'; +# set template section defaults + +# Build page sections +# ordered here in the order that the page is constructed + $logo = $template->getSection('Logo'); + $titleSpan = $template->getSection('TitleSpan'); + $main = $template->getSection('Main'); + $divDecoration = $template->getSection('DivDecoration'); + $mainContent = $template->getSection('LoginForm'); + $noLeftNav = $template->getSection('NoLeftNav'); + $noRightNav = $template->getSection('NoRightNav'); + $navHeader = $template->getSection('NavHeader'); + $footer = $template->getSection('Footer'); + $topNav = ''; + $leftNav = ''; + $rightNav = ''; + $rightNavLinks = ''; + $lowerScripts = $template->getSection('LogoLinkScript'); + $pageTitleInfo = ''; + #$topNavLinks = makeLinks('top', $topLinks, 12); + $topNavLinks = ''; + $leftNavLinks = ''; + $mediaType = ' media="screen"'; + $mainTitle = 'Program O Login'; + $FooterInfo = '

    © 2011-2012 My Program-O
    www.program-o.com

    '; + $headerTitle = ''; + $pageTitle = 'My-Program O - Login'; + $upperScripts = ''; + + if((isset($_POST['uname']))&&(isset($_POST['pw']))) { + $_SESSION['poadmin']['display'] = $hide_logo; + $dbconn = db_open(); + $uname = filter_input(INPUT_POST,'uname',FILTER_SANITIZE_STRING); + $pw = filter_input(INPUT_POST,'pw',FILTER_SANITIZE_STRING); + $sql = "SELECT * FROM `myprogramo` WHERE uname = '".$uname."' AND pword = '".MD5($pw)."'"; + $result = mysql_query($sql,$dbconn) or $msg .= SQL_Error(mysql_errno()); + if ($result) { + $count = mysql_num_rows($result); + if($count > 0) { + $row=mysql_fetch_array($result); + $_SESSION['poadmin']['uid']=$row['id']; + $_SESSION['poadmin']['name']=$row['uname']; + $_SESSION['poadmin']['lip']=$row['lastip']; + $_SESSION['poadmin']['llastlogin']=date('l jS \of F Y h:i:s A', strtotime($row['lastlogin'])); + if(!empty($_SERVER['HTTP_CLIENT_IP'])) { //check ip from share internet + $ip=$_SERVER['HTTP_CLIENT_IP']; + } + elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { //to check ip is pass from proxy + $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; + } + else { + $ip=$_SERVER['REMOTE_ADDR']; + } + $sqlupdate = "UPDATE `myprogramo` SET `lastip` = '$ip', `lastlogin` = CURRENT_TIMESTAMP WHERE uname = '$uname' limit 1"; + $result = mysql_query($sqlupdate,$dbconn); + $transact = mysql_affected_rows($dbconn); + $_SESSION['poadmin']['ip']=$ip; + $_SESSION['poadmin']['lastlogin']=date('l jS \of F Y h:i:s A'); + $sql = "SELECT * FROM `bots` WHERE bot_active = '1' ORDER BY bot_id ASC LIMIT 1"; + $result = mysql_query($sql,$dbconn); + $count = mysql_num_rows($result); + if($count > 0) { + $row=mysql_fetch_array($result); + $_SESSION['poadmin']['bot_id']=$row['bot_id']; + $_SESSION['poadmin']['bot_name']=$row['bot_name']; + } + else { + $_SESSION['poadmin']['bot_id']=-1; + $_SESSION['poadmin']['bot_name']="unknown"; + } + } + else { + $msg .= "incorrect username/password
    \n"; + } + } + mysql_close($dbconn); + if($msg == "") { + include ('main.php'); + } + } + elseif(isset($_GET['msg'])) { + $msg .= htmlentities($_GET['msg']); + } + elseif(isset($_GET['page'])) { + $curPage = $_GET['page']; + if ($curPage == 'logout') { + if(isset($_COOKIE[session_name()])) { + setcookie(session_name(), '', time()-42000, '/'); + } + session_destroy(); + //header('location: ./'); + } + else { + $_SESSION['poadmin']['curPage'] = $curPage; + include ("$curPage.php"); + } + } + $curPage = (isset($curPage)) ? $curPage : 'main'; + $upperScripts .= ($hide_logo == 'HideLogoCSS') ? $template->getSection('HideLogoCSS') : ''; + + # Build page content from the template + $content = $template->getSection('Header'); + #$content .= "hide_logo = $hide_logo"; + $content .= $template->getSection('PageBody'); + + # Replace template labels with real data + $styleSheet = 'style.css'; + $errMsgClass = (!empty($msg)) ? "ShowError" : "HideError"; + $errMsgStyle = $template->getSection($errMsgClass); +/* These are the most common template replacement tags used. Any additional + replacement tags should be handled in the include file for the current page, + in a function named replaceTags(&$content). This function will alter the + $content variable directly, rather than change it and then return it. +*/ + $searches = array( + '[myPage]' => $curPage, + '[pageTitle]' => $pageTitle, + '[styleSheet]' => $styleSheet, + '[mediaType]' => $mediaType, + '[upperScripts]' => $upperScripts, + '[logo]' => $logo, + '[pageTitleInfo]' => $pageTitleInfo, + '[topNav]' => $topNav, + '[leftNav]' => $leftNav, + '[rightNav]' => $rightNav, + '[main]' => $main, + '[rightNav]' => $rightNav, + '[footer]' => $footer, + '[lowerScripts]' => $lowerScripts, + '[pageTitleInfo]' => $pageTitleInfo, + '[titleSpan]' => $titleSpan, + '[divDecoration]' => $divDecoration, + '[topNavLinks]' => $topNavLinks, + '[navHeader]' => $navHeader, + '[leftNavLinks]' => $leftNavLinks, + '[mainTitle]' => $mainTitle, + '[mainContent]' => $mainContent, + '[rightNavLinks]' => $rightNavLinks, + '[FooterInfo]' => $FooterInfo, + '[headerTitle]' => $headerTitle, + '[errMsg]' => $msg, + '[bot_id]' => $bot_id, + '[bot_name]' => $bot_name, + '[errMsgStyle]' => $errMsgStyle, + '[noRightNav]' => $noRightNav, + '[noLeftNav]' => $noLeftNav, + '[version]' => $version, + ); + foreach ($searches as $search => $replace) { + $content = str_replace($search, $replace, $content); + } + $content = str_replace('[myPage]', $curPage, $content); + $content = str_replace('[divDecoration]', $divDecoration, $content); + $content = str_replace('[blank]', '', $content); + if(function_exists('replaceTags')) replaceTags($content); // Handle any extra replacement tags, as needed. + #die ('
    ' . print_r($_SESSION, true) . "

    \ndisplay = $hide_logo
    \n"); + exit($content); + + function makeLinks($section, $linkArray, $spaces = 2) { + #print "\n"; + global $template, $curPage; + $curPage = (empty($curPage)) ? 'main' : $curPage; + $botName = (isset($_SESSION['poadmin']['bot_name'])) ? $_SESSION['poadmin']['bot_name'] : 'unknown'; + $out = ''; + # [linkClass][linkHref][linkOnclick][linkAlt][linkTitle]>[linkLabel] + $linkText = $template->getSection('NavLink'); + foreach ($linkArray as $needle) { + $tmp = $linkText; + foreach ($needle as $search => $replace) { + $tmp = str_replace($search, $replace, $tmp); + } + $linkClass = $needle['[linkHref]']; + $linkClass = str_replace(' href="http://github.com/?page=', '', $linkClass); + $linkClass = str_replace('"', '', $linkClass); + #die ("linkClass = $linkClass
    \nstrstr = $sp
    \n"); + #$curClass = ($linkClass == $curPage) ? 'selected' : 'noClass'; + $curClass = ($linkClass == $curPage) ? 'selected' : 'noClass'; + if ($curPage == 'main') $curClass = (stripos($linkClass,'main') !== false) ? 'selected' : 'noClass'; +/* +*/ + $tmp = str_replace('[curClass]', $curClass, $tmp); + $out .= "$tmp\n"; + } + #print "\n"; + $out = str_replace('[curBot]', $botName, $out); + return trim($out); + } + + + function getFooter() { + $ip = $_SERVER['REMOTE_ADDR']; + $name = $_SESSION['poadmin']['name']; + $lip = $_SESSION['poadmin']['lip']; + $last = $_SESSION['poadmin']['lastlogin']; + $llast = $_SESSION['poadmin']['llastlogin']; + $admess = "You are logged in as: $name from $ip since: $last"; + $admess .= "
    You last logged in from $lip on $llast"; + $today = date("Y"); + $out = <<© $today My Program-O
    $admess

    +endFooter; + return $out; + } + + function makeTopLinks() { + $out = array( + array( + '[linkClass]' => ' class="[curClass]"', + '[linkHref]' => ' href="http://github.com/?page=main"', + '[linkOnclick]' => '', + '[linkAlt]' => ' alt="Home"', + '[linkTitle]' => ' title="Home"', + '[linkLabel]' => 'Home' + ), + array( + '[linkClass]' => ' class="[curClass]"', + '[linkHref]' => ' href="'.NEWS_URL.'"', + '[linkOnclick]' => '', + '[linkAlt]' => ' alt="Get the latest news from the Program O website"', + '[linkTitle]' => ' title="Get the latest news from the Program O website"', + '[linkLabel]' => 'News' + ), + array( + '[linkClass]' => ' class="[curClass]"', + '[linkHref]' => ' href="'.FAQ_URL.'"', + '[linkOnclick]' => '', + '[linkAlt]' => ' alt="The Program O User\'s Guide"', + '[linkTitle]' => ' title="The Program O User\'s Guide"', + '[linkLabel]' => 'Documentation' + ), + array( + '[linkClass]' => ' class="[curClass]"', + '[linkHref]' => ' href="http://github.com/?page=bugs"', + '[linkOnclick]' => '', + '[linkAlt]' => ' alt="Bug reporting"', + '[linkTitle]' => ' title="Bug reporting"', + '[linkLabel]' => 'Bug Reporting' + ), + array( + '[linkClass]' => ' class="[curClass]"', + '[linkHref]' => ' href="http://github.com/?page=stats"', + '[linkOnclick]' => '', + '[linkAlt]' => ' alt="Get bot statistics"', + '[linkTitle]' => ' title="Get bot statistics"', + '[linkLabel]' => 'Stats' + ), + array( + '[linkClass]' => ' class="[curClass]"', + '[linkHref]' => ' href="http://github.com/?page=support"', + '[linkOnclick]' => '', + '[linkAlt]' => ' alt="Get support for Program O"', + '[linkTitle]' => ' title="Get support for Program O"', + '[linkLabel]' => 'Support' + ), + array( + '[linkClass]' => '', + '[linkHref]' => ' href="http://github.com/?page=logout"', + '[linkOnclick]' => '', + '[linkAlt]' => ' alt="Log out"', + '[linkTitle]' => ' title="Log out"', + '[linkLabel]' => 'Log Out' + ) + ); + return $out; + } + function makeLeftLinks() { + $out = array( + array( # Change bot + '[linkClass]' => ' class="[curClass]"', + '[linkHref]' => ' href="http://github.com/?page=select_bots"', + '[linkOnclick]' => '', + '[linkAlt]' => ' alt="Change or edit the current bot"', + '[linkTitle]' => ' title="Change or edit the current bot"', + '[linkLabel]' => 'Change/Edit Bot: ([curBot])' + ), + array( + '[linkClass]' => ' class="[curClass]"', + '[linkHref]' => ' href="http://github.com/?page=botpersonality"', + '[linkOnclick]' => '', + '[linkAlt]' => ' alt="Edit your bot\'s personality"', + '[linkTitle]' => ' title="Edit your bot\'s personality"', + '[linkLabel]' => 'Bot Personality' + ), + array( + '[linkClass]' => ' class="[curClass]"', + '[linkHref]' => ' href="http://github.com/?page=logs"', + '[linkOnclick]' => '', + '[linkAlt]' => ' alt="View the log files"', + '[linkTitle]' => ' title="View the log files"', + '[linkLabel]' => 'Logs' + ), + array( + '[linkClass]' => ' class="[curClass]"', + '[linkHref]' => ' href="http://github.com/?page=teach"', + '[linkOnclick]' => '', + '[linkAlt]' => ' alt="Train your bot"', + '[linkTitle]' => ' title="Train your bot"', + '[linkLabel]' => 'Teach' + ), + array( + '[linkClass]' => ' class="[curClass]"', + '[linkHref]' => ' href="http://github.com/?page=upload"', + '[linkOnclick]' => '', + '[linkAlt]' => ' alt="Upload AIML files"', + '[linkTitle]' => ' title="Upload AIML files"', + '[linkLabel]' => 'Upload AIML' + ), + array( + '[linkClass]' => ' class="[curClass]"', + '[linkHref]' => ' href="http://github.com/?page=download"', + '[linkOnclick]' => '', + '[linkAlt]' => ' alt="Download AIML files"', + '[linkTitle]' => ' title="Download AIML files"', + '[linkLabel]' => 'Download AIML' + ), + array( + '[linkClass]' => ' class="[curClass]"', + '[linkHref]' => ' href="http://github.com/?page=clear"', + '[linkOnclick]' => '', + '[linkAlt]' => ' alt="Clear AIML Categories"', + '[linkTitle]' => ' title="Clear AIML Categories"', + '[linkLabel]' => 'Clear AIML Categories' + ), + array( + '[linkClass]' => ' class="[curClass]"', + '[linkHref]' => ' href="http://github.com/?page=spellcheck"', + '[linkOnclick]' => '', + '[linkAlt]' => ' alt="Edit the SpellCheck entries"', + '[linkTitle]' => ' title="Edit the SpellCheck entries"', + '[linkLabel]' => 'Spell Check' + ), + array( + '[linkClass]' => ' class="[curClass]"', + '[linkHref]' => ' href="http://github.com/?page=wordcensor"', + '[linkOnclick]' => '', + '[linkAlt]' => ' alt="Edit the Word Censor entries"', + '[linkTitle]' => ' title="Edit the Word Censor entries"', + '[linkLabel]' => 'Word Censor' + ), + array( + '[linkClass]' => ' class="[curClass]"', + '[linkHref]' => ' href="http://github.com/?page=search"', + '[linkOnclick]' => '', + '[linkAlt]' => ' alt="Search and edit specific AIML categories"', + '[linkTitle]' => ' title="Search and edit specific AIML categories"', + '[linkLabel]' => 'Search/Edit AIML' + ), + array( + '[linkClass]' => ' class="[curClass]"', + '[linkHref]' => ' href="http://github.com/?page=demochat"', + '[linkOnclick]' => '', + '[linkAlt]' => ' alt="Run a demo version of your bot"', + '[linkTitle]' => ' title="Run a demo version of your bot"', + '[linkLabel]' => 'Test Your Bot' + ), + array( + '[linkClass]' => '', + '[linkHref]' => ' href="http://github.com/?page=members"', + '[linkOnclick]' => '', + '[linkAlt]' => ' alt="Edit Admin Accounts"', + '[linkTitle]' => ' title="Edit Admin Accounts"', + '[linkLabel]' => 'Edit Admin Accounts' + ), + array( + '[linkClass]' => '', + '[linkHref]' => ' href="http://github.com/?page=logout"', + '[linkOnclick]' => '', + '[linkAlt]' => ' alt="Log out"', + '[linkTitle]' => ' title="Log out"', + '[linkLabel]' => 'Log Out' + ), + array( + '[linkClass]' => '', + '[linkHref]' => ' href="#"', + '[linkOnclick]' => ' onclick="toggleLogo(); return false;"', + '[linkAlt]' => ' alt="Toggle the Logo"', + '[linkTitle]' => ' title="Toggle the Logo"', + '[linkLabel]' => 'Toggle the Logo' + ) + ); + return $out; + } + + function getRSS($feed = 'RSS') { + global $template; + switch ($feed) { + case 'support': + $feedURL = SUP_URL; + break; + default: + $feedURL = RSS_URL; + } + $out = ''; + if (function_exists('curl_init')) { + $ch = curl_init($feedURL); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HEADER, 0); + $data = curl_exec($ch); + curl_close($ch); + if (false === $data) return 'The RSS Feed is not currently available. We apologise for the inconvenience.'; + $rss = new SimpleXmlElement($data, LIBXML_NOCDATA); + if($rss) { + $items = $rss->channel->item; + foreach ($items as $item) { + $title = $item->title; + $link = $item->link; + $published_on = $item->pubDate; + $description = $item->description; + $out .= "

    $title

    \n"; + $out .= "

    $description

    "; + } + } + } + else $out = 'RSS Feed not available'; + return $out; + } + + function getCurrentVersion() + { + $url = 'https://api.github.com/repos/Program-O/Program-O/contents/version.txt'; + $out = false; + if (function_exists('curl_init')) + { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $out = curl_exec($ch); + if (false === $out) trigger_error('Not sure what it is, but there\'s a problem with checking the current version on GitHub. Maybe this will help: "' . curl_error($ch) . '"'); + curl_close($ch); + $repoArray = json_decode($out, true); + $versionB64 = $repoArray['content']; + $version = base64_decode($versionB64); + $out = $version; + } + return $out; + } + +?> diff --git a/admin/logs.php b/admin/logs.php index 0e40182..7c4433e 100644 --- a/admin/logs.php +++ b/admin/logs.php @@ -1,241 +1,241 @@ - - - -endScript; - - $topNav = $template->getSection('TopNav'); - $leftNav = $template->getSection('LeftNav'); - $main = $template->getSection('Main'); - $topNavLinks = makeLinks('top', $topLinks, 12); - $leftNavLinks = makeLinks('left', $leftLinks, 12); - $FooterInfo = getFooter(); - $errMsgClass = (!empty($msg)) ? "ShowError" : "HideError"; - $errMsgStyle = $template->getSection($errMsgClass); - $rightNav = $template->getSection('RightNav'); - $navHeader = $template->getSection('NavHeader'); - $noLeftNav = ''; - $noTopNav = ''; - $noRightNav = ''; - $headerTitle = 'Actions:'; - $pageTitle = 'My-Program O - Chat Logs'; - $mainContent = $template->getSection('ConversationLogs1'); - $mainTitle = 'Chat Logs'; - - $rightNav = str_replace('[rightNavLinks]', $show_this . $user_list, $rightNav); - $rightNav = str_replace('[navHeader]', $navHeader, $rightNav); - $rightNav = str_replace('[headerTitle]', 'Log Actions:', $rightNav); - $mainContent = str_replace('[show_this]', '', $mainContent); - $mainContent = str_replace('[convo]', $convo, $mainContent); - $mainContent = str_replace('[bot_name]', $bot_name, $mainContent); - -function getUserNames() { - $dbconn = db_open(); - $sql = "select `id`, `name` from `users` where 1;"; - $result = mysql_query($sql,$dbconn); - $nameList = array(); - while ($row = mysql_fetch_assoc($result)) { - $nameList[$row['id']] = $row['name']; - } - mysql_close($dbconn); - return $nameList; -} - -function getuserList($showing) { - //db globals - global $template, $adm_dbn; - $nameList = getUserNames(); - $curUserid = (isset($_GET['id'])) ? $_GET['id'] : -1; - #die ("user names:
    \n" . print_r($nameList, true) . "\n
    \n"); - $dbconn = db_open(); - $bot_id = $_SESSION['poadmin']['bot_id']; - $linkTag = $template->getSection('NavLink'); - $sql = "SELECT DISTINCT(`userid`),COUNT(`userid`) AS TOT FROM `conversation_log` WHERE bot_id = '$bot_id' AND DATE(`timestamp`) = '[repl_date]' GROUP BY `userid` ORDER BY ABS(`userid`) ASC"; - $showarray = array("last 20","previous week","previous 2 weeks","previous month","last 6 months","this year","previous year","all years"); - switch ($showing) { - case "today": - $repl_date = date("Y-m-d"); - break; - case "previous week": - $repl_date = strtotime("-1 week"); - break; - case "previous 2 weeks": - $repl_date = strtotime("-2 week"); - break; - case "previous month": - $repl_date = strtotime("-1 month"); - break; - case "previous 6 months": - $repl_date = strtotime("-6 month"); - break; - case "past 12 months": - $repl_date = strtotime("-1 year"); - break; - case "all time": - $sql = "SELECT DISTINCT(`userid`),COUNT(`userid`) AS TOT FROM `conversation_log` WHERE bot_id = '$bot_id' GROUP BY `userid` ORDER BY ABS(`userid`) ASC"; - $repl_date = time(); - break; - default: - $sql = "SELECT DISTINCT(`userid`),COUNT(`userid`) AS TOT FROM `conversation_log` WHERE bot_id = '$bot_id' GROUP BY `userid` ORDER BY ABS(`userid`) ASC"; - $repl_date = time(); - } - $sql = str_replace('[repl_date]', $repl_date, $sql); - $list =<< -
      - -endList; - $result = mysql_query($sql,$dbconn) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
      \nSQL = $sql
      \n"); - while($row = mysql_fetch_array($result)) { - $userid = $row['userid']; - $linkClass = ($userid == $curUserid) ? 'selected' : 'noClass'; - $userName = @$nameList[$userid]; - $TOT = $row['TOT']; - $tmpLink = str_replace('[linkClass]'," class=\"$linkClass\"", $linkTag); - $tmpLink = str_replace('[linkOnclick]','', $tmpLink); - $tmpLink = str_replace('[linkHref]',"href=\"./?page=logs&showing=$showing&id=$userid#$userid\" name=\"$userid\"", $tmpLink); - $tmpLink = str_replace('[linkTitle]'," title=\"Show entries for user $userName\"", $tmpLink); - $tmpLink = str_replace('[linkLabel]',"USER:$userName($TOT)", $tmpLink); - $anchor = " \n"; - $anchor = ''; - $list .= "$tmpLink\n$anchor"; - } - $list .="\n \n"; - mysql_close($dbconn); - return $list; -} - -function showThis($showing="last 20") { - $showarray = array("last 20","today","previous week","previous 2 weeks","previous month","last 6 months","past 12 months","all time"); - $options = ""; - foreach($showarray as $index => $value) { - if($value == $showing) { - $sel = " SELECTED=SELECTED"; - } - else { - $sel = ""; - } - $options .= " \n"; - } - - $form = << - - - -endForm; - return $form; -} - -function getuserConvo($id, $showing) { - $bot_name= (isset($_SESSION['poadmin']['bot_name'])) ? $_SESSION['poadmin']['bot_name'] : 'Bot'; - $bot_id = (isset($_SESSION['poadmin']['bot_id'])) ? $_SESSION['poadmin']['bot_id'] : 0; - $nameList = getUserNames(); - $user_name = $nameList[$id]; - switch ($showing) { - case "today": - $sqladd = "AND DATE(`timestamp`) = '".date('Y-m-d')."'"; - $title = "Today's "; - break; - case "previous week": - $lastweek = strtotime("-1 week"); - $sqladd = "AND DATE(`timestamp`) >= '".$lastweek."'"; - $title = "Last week's "; - break; - case "previous 2 weeks": - $lasttwoweek = strtotime("-2 week"); - $sqladd = "AND DATE(`timestamp`) >= '".$lasttwoweek ."'"; - $title = "Last two week's "; - break; - case "previous month": - $lastmonth = strtotime("-1 month"); - $sqladd = "AND DATE(`timestamp`) >= '".$lastmonth ."'"; - $title = "Last month's "; - break; - case "previous 6 months": - $lastsixmonth = strtotime("-6 month"); - $sqladd = "AND DATE(`timestamp`) >= '".$lastsixmonth ."'"; - $title = "Last six month's "; - break; - case "past 12 months": - $lastyear = strtotime("-1 year"); - $sqladd = "AND DATE(`timestamp`) >= '".$lastyear ."'"; - $title = "Last twelve month's "; - break; - case "all time": - $sql = ""; - $title = "All "; - break; - default: - $sqladd = ""; - $title = "Last "; - } - $lasttimestamp = ""; - $i = 1; - $dbconn = db_open(); - //get undefined defaults from the db - $sql = "SELECT * FROM `conversation_log` WHERE `bot_id` = '$bot_id' AND `userid` = $id $sqladd ORDER BY `id` ASC"; - $list = "

      $title conversations for user: $id

      "; - $list .="
      "; - $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
      \nSQL = $sql\n"); - while($row = mysql_fetch_array($result)) { - $thisdate = date("Y-m-d",strtotime($row['timestamp'])); - if($thisdate!=$lasttimestamp) { - if($i>1) { - if($showing == "last 20") { - break; - } - } - $date = date("Y-m-d"); - $list .= "

      Conversation#$i $thisdate

      "; - $i++; - } - $list .= "
      $user_name: ".$row['input'].""; - $list .= "
      $bot_name: ".$row['response'].""; - $lasttimestamp = $thisdate; - } - $list .="
      "; - mysql_close($dbconn); - $list = str_ireplace(' + + + +endScript; + + $topNav = $template->getSection('TopNav'); + $leftNav = $template->getSection('LeftNav'); + $main = $template->getSection('Main'); + $topNavLinks = makeLinks('top', $topLinks, 12); + $leftNavLinks = makeLinks('left', $leftLinks, 12); + $FooterInfo = getFooter(); + $errMsgClass = (!empty($msg)) ? "ShowError" : "HideError"; + $errMsgStyle = $template->getSection($errMsgClass); + $rightNav = $template->getSection('RightNav'); + $navHeader = $template->getSection('NavHeader'); + $noLeftNav = ''; + $noTopNav = ''; + $noRightNav = ''; + $headerTitle = 'Actions:'; + $pageTitle = 'My-Program O - Chat Logs'; + $mainContent = $template->getSection('ConversationLogs1'); + $mainTitle = 'Chat Logs'; + + $rightNav = str_replace('[rightNavLinks]', $show_this . $user_list, $rightNav); + $rightNav = str_replace('[navHeader]', $navHeader, $rightNav); + $rightNav = str_replace('[headerTitle]', 'Log Actions:', $rightNav); + $mainContent = str_replace('[show_this]', '', $mainContent); + $mainContent = str_replace('[convo]', $convo, $mainContent); + $mainContent = str_replace('[bot_name]', $bot_name, $mainContent); + +function getUserNames() { + $dbconn = db_open(); + $sql = "select `id`, `name` from `users` where 1;"; + $result = mysql_query($sql,$dbconn); + $nameList = array(); + while ($row = mysql_fetch_assoc($result)) { + $nameList[$row['id']] = $row['name']; + } + mysql_close($dbconn); + return $nameList; +} + +function getuserList($showing) { + //db globals + global $template; + $nameList = getUserNames(); + $curUserid = (isset($_GET['id'])) ? $_GET['id'] : -1; + #die ("user names:
      \n" . print_r($nameList, true) . "\n
      \n"); + $dbconn = db_open(); + $bot_id = $_SESSION['poadmin']['bot_id']; + $linkTag = $template->getSection('NavLink'); + $sql = "SELECT DISTINCT(`userid`),COUNT(`userid`) AS TOT FROM `conversation_log` WHERE bot_id = '$bot_id' AND DATE(`timestamp`) = '[repl_date]' GROUP BY `userid` ORDER BY ABS(`userid`) ASC"; + $showarray = array("last 20","previous week","previous 2 weeks","previous month","last 6 months","this year","previous year","all years"); + switch ($showing) { + case "today": + $repl_date = date("Y-m-d"); + break; + case "previous week": + $repl_date = strtotime("-1 week"); + break; + case "previous 2 weeks": + $repl_date = strtotime("-2 week"); + break; + case "previous month": + $repl_date = strtotime("-1 month"); + break; + case "previous 6 months": + $repl_date = strtotime("-6 month"); + break; + case "past 12 months": + $repl_date = strtotime("-1 year"); + break; + case "all time": + $sql = "SELECT DISTINCT(`userid`),COUNT(`userid`) AS TOT FROM `conversation_log` WHERE bot_id = '$bot_id' GROUP BY `userid` ORDER BY ABS(`userid`) ASC"; + $repl_date = time(); + break; + default: + $sql = "SELECT DISTINCT(`userid`),COUNT(`userid`) AS TOT FROM `conversation_log` WHERE bot_id = '$bot_id' GROUP BY `userid` ORDER BY ABS(`userid`) ASC"; + $repl_date = time(); + } + $sql = str_replace('[repl_date]', $repl_date, $sql); + $list =<< +
        + +endList; + $result = mysql_query($sql,$dbconn) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); + while($row = mysql_fetch_array($result)) { + $userid = $row['userid']; + $linkClass = ($userid == $curUserid) ? 'selected' : 'noClass'; + $userName = @$nameList[$userid]; + $TOT = $row['TOT']; + $tmpLink = str_replace('[linkClass]'," class=\"$linkClass\"", $linkTag); + $tmpLink = str_replace('[linkOnclick]','', $tmpLink); + $tmpLink = str_replace('[linkHref]',"href=\"./?page=logs&showing=$showing&id=$userid#$userid\" name=\"$userid\"", $tmpLink); + $tmpLink = str_replace('[linkTitle]'," title=\"Show entries for user $userName\"", $tmpLink); + $tmpLink = str_replace('[linkLabel]',"USER:$userName($TOT)", $tmpLink); + $anchor = "
        \n"; + $anchor = ''; + $list .= "$tmpLink\n$anchor"; + } + $list .="\n \n"; + mysql_close($dbconn); + return $list; +} + +function showThis($showing="last 20") { + $showarray = array("last 20","today","previous week","previous 2 weeks","previous month","last 6 months","past 12 months","all time"); + $options = ""; + foreach($showarray as $index => $value) { + if($value == $showing) { + $sel = " SELECTED=SELECTED"; + } + else { + $sel = ""; + } + $options .= " \n"; + } + + $form = << + + + +endForm; + return $form; +} + +function getuserConvo($id, $showing) { + $bot_name= (isset($_SESSION['poadmin']['bot_name'])) ? $_SESSION['poadmin']['bot_name'] : 'Bot'; + $bot_id = (isset($_SESSION['poadmin']['bot_id'])) ? $_SESSION['poadmin']['bot_id'] : 0; + $nameList = getUserNames(); + $user_name = $nameList[$id]; + switch ($showing) { + case "today": + $sqladd = "AND DATE(`timestamp`) = '".date('Y-m-d')."'"; + $title = "Today's "; + break; + case "previous week": + $lastweek = strtotime("-1 week"); + $sqladd = "AND DATE(`timestamp`) >= '".$lastweek."'"; + $title = "Last week's "; + break; + case "previous 2 weeks": + $lasttwoweek = strtotime("-2 week"); + $sqladd = "AND DATE(`timestamp`) >= '".$lasttwoweek ."'"; + $title = "Last two week's "; + break; + case "previous month": + $lastmonth = strtotime("-1 month"); + $sqladd = "AND DATE(`timestamp`) >= '".$lastmonth ."'"; + $title = "Last month's "; + break; + case "previous 6 months": + $lastsixmonth = strtotime("-6 month"); + $sqladd = "AND DATE(`timestamp`) >= '".$lastsixmonth ."'"; + $title = "Last six month's "; + break; + case "past 12 months": + $lastyear = strtotime("-1 year"); + $sqladd = "AND DATE(`timestamp`) >= '".$lastyear ."'"; + $title = "Last twelve month's "; + break; + case "all time": + $sql = ""; + $title = "All "; + break; + default: + $sqladd = ""; + $title = "Last "; + } + $lasttimestamp = ""; + $i = 1; + $dbconn = db_open(); + //get undefined defaults from the db + $sql = "SELECT * FROM `conversation_log` WHERE `bot_id` = '$bot_id' AND `userid` = $id $sqladd ORDER BY `id` ASC"; + $list = "

        $title conversations for user: $id

        "; + $list .="
        "; + $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql\n"); + while($row = mysql_fetch_array($result)) { + $thisdate = date("Y-m-d",strtotime($row['timestamp'])); + if($thisdate!=$lasttimestamp) { + if($i>1) { + if($showing == "last 20") { + break; + } + } + $date = date("Y-m-d"); + $list .= "

        Conversation#$i $thisdate

        "; + $i++; + } + $list .= "
        $user_name: ".$row['input'].""; + $list .= "
        $bot_name: ".$row['response'].""; + $lasttimestamp = $thisdate; + } + $list .="
        "; + mysql_close($dbconn); + $list = str_ireplace(' diff --git a/admin/main.php b/admin/main.php index 796aa83..9adc4a7 100644 --- a/admin/main.php +++ b/admin/main.php @@ -1,98 +1,48 @@ -getSection('NoRightNav'); - $logo = $template->getSection('Logo'); - $topNav = $template->getSection('TopNav'); - $leftNav = $template->getSection('LeftNav'); - $main = $template->getSection('Main'); - $rightNav = ''; - $footer = trim($template->getSection('Footer')); - #$lowerScripts = ''; - #$pageTitleInfo = ''; - $divDecoration = $template->getSection('DivDecoration'); - $topNavLinks = makeLinks('top', $topLinks, 12); - $navHeader = $template->getSection('NavHeader'); - $leftNavLinks = makeLinks('left', $leftLinks, 12); - $mainTitle = 'Home'; - $rightNavLinks = ''; - $FooterInfo = getFooter(); - $titleSpan = $template->getSection('TitleSpan'); - $errMsgStyle = (!empty($msg)) ? "ShowError" : "HideError"; - $errMsgStyle = $template->getSection($errMsgStyle); - $mediaType = ' media="screen"'; - $upperScripts = ''; - $noLeftNav = ''; - $noTopNav = ''; - $pageTitle = 'My-Program O - Main Page'; - $headerTitle = 'Actions:'; - $mainContent = << - Welcome to 'My Program-O', the Program-O chatbot admin area. Please - use the links above or to the left to perform administrative tasks, - as needed. -

        -
        -
        Latest News from Program-O.com
        -
        [rssOutput]
        -
        -endMain; - - $mainContent = str_replace('[rssOutput]', getRSS(), $mainContent); - - function getRSS() { - global $template; - $out = ''; - $itemTemplate = $template->getSection('RSSItemTemplate'); - $url = 'http://www.program-o.com/ns/feed/rss/'; - $xml = simplexml_load_file($url); //loading the document - $title = $xml->channel->title; //gets the title of the document. - $rss = simplexml_load_file($url); - if($rss) { - $items = $rss->channel->item; - foreach($items as $item) { - $title = $item->title; - $link = $item->link; - $published_on = $item->pubDate; - $description = $item->description; - $out .= "

        $title

        \n"; - $out .= "

        $description

        "; - } - } - return $out; - } - - function getXML_section($file, $tagName, $count = 1) { - $startTagSearch = "<$tagName>"; - $endTagSearch = ""; - $atomicTagSearch = "<$tagName />"; - $alternateAtomicTagSearch = "<$tagName/>"; - $foundPositions = array(-1); - $pos = 0; - $n = 0; - while ($pos !== false) { - switch (true) { - case ($newPos = stripos($file, $startTagSearch, $pos)): - case ($newPos = stripos($file, $atomicTagSearch, $pos)): - case ($newPos = stripos($file, $alternateAtomicTagSearch, $pos)): - $foundPositions[] = $newPos; - break; - default: - $pos = $newPos; - } - $n++; - if ($n > 50) break; - } - $startPos = $foundPositions[$count]; - $endPos = stripos($file, $endTagSearch, $startPos); - $len = $endPos - $startPos; - return substr($file, $startPos, $len); - } - +getSection('NoRightNav'); + $logo = $template->getSection('Logo'); + $topNav = $template->getSection('TopNav'); + $leftNav = $template->getSection('LeftNav'); + $main = $template->getSection('Main'); + $rightNav = ''; + $footer = trim($template->getSection('Footer')); + #$lowerScripts = ''; + #$pageTitleInfo = ''; + $divDecoration = $template->getSection('DivDecoration'); + $topNavLinks = makeLinks('top', $topLinks, 12); + $navHeader = $template->getSection('NavHeader'); + $leftNavLinks = makeLinks('left', $leftLinks, 12); + $mainTitle = 'Home'; + $rightNavLinks = ''; + $FooterInfo = getFooter(); + $titleSpan = $template->getSection('TitleSpan'); + $errMsgStyle = (!empty($msg)) ? "ShowError" : "HideError"; + $errMsgStyle = $template->getSection($errMsgStyle); + $mediaType = ' media="screen"'; + $upperScripts = ''; + $noLeftNav = ''; + $noTopNav = ''; + $pageTitle = 'My-Program O - Main Page'; + $headerTitle = 'Actions:'; + $mainContent = << + Welcome to 'My Program-O', the Program-O chatbot admin area. Please + use the links above or to the left to perform administrative tasks, + as needed. +

        +
        +
        Latest News from Program-O.com
        +
        [rssOutput]
        +
        +endMain; + $mainContent = str_replace('[rssOutput]', getRSS(), $mainContent); + ?> \ No newline at end of file diff --git a/admin/members.php b/admin/members.php index d35ad20..0a773d4 100644 --- a/admin/members.php +++ b/admin/members.php @@ -1,180 +1,196 @@ -$myPost"; - #if (!empty($_POST)) die ("
        \n Post Vars:\n$myPost\n
        \n"); - - $uname = ''; - $action = (isset($_POST['action'])) ? ucfirst(strtolower($_POST['action'])) : 'Add'; - if (!empty($_POST)) { - $msg = save($action); - $action = 'Add'; - } - $id = (isset($_POST['id'])) ? $_POST['id'] : getNextID(); - $id = ($id <= 0) ? getNextID() : $id; - if (isset($_POST['memberSelect'])) { - $id = $_POST['memberSelect']; - getMemberData($_POST['memberSelect']); - } - $upperScripts = << - - -endScript; - - $XmlEntities = array( - '&' => '&', - '<' => '<', - '>' => '>', - ''' => '\'', - '"' => '"', - ); - - $AdminsOpts = getAdminsOpts(); - - $membersForm = $template->getSection('MembersForm'); - $members_list_form = $template->getSection('MembersListForm'); - $showHelp = $template->getSection('MembersShowHelp'); - - $topNav = $template->getSection('TopNav'); - $leftNav = $template->getSection('LeftNav'); - $main = $template->getSection('Main'); - $topNavLinks = makeLinks('top', $topLinks, 12); - $navHeader = $template->getSection('NavHeader'); - $leftNavLinks = makeLinks('left', $leftLinks, 12); - $FooterInfo = getFooter(); - $errMsgClass = (!empty($msg)) ? "ShowError" : "HideError"; - $errMsgStyle = $template->getSection($errMsgClass); - $noLeftNav = ''; - $noTopNav = ''; - $noRightNav = $template->getSection('NoRightNav'); - $headerTitle = 'Actions:'; - $pageTitle = 'My-Program O - Admin Accounts'; - $mainContent = $template->getSection('MembersMain'); - $mainTitle = "Modify Admin Account Data [helpLink]"; - - $members_list_form = str_replace('[adminList]', $AdminsOpts, $members_list_form); - $mainContent = str_replace('[members_content]', $membersForm, $mainContent); - $mainContent = str_replace('[showHelp]', $showHelp, $mainContent); - $mainContent = str_replace('[members_list_form]', $members_list_form, $mainContent); - $mainContent = str_replace('[uname]', $uname, $mainContent); - $mainContent = str_replace('[action]', $action, $mainContent); - $mainContent = str_replace('[id]', $id, $mainContent); - $mainTitle = str_replace('[helpLink]', $template->getSection('HelpLink'), $mainTitle); - - - function updateDB($sql) { - $dbconn = db_open(); - $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL =
        $sql

        \n"); - $commit = mysql_affected_rows($dbconn); - return $commit; - } - - function save($action) { - if (!isset($_POST['uname']) or !isset($_POST['pword']) or !isset($_POST['pwordConfirm'])) return 'You left something out!'; - $id = $_POST['id']; - $uname = $_POST['uname']; - $pword1 = $_POST['pword']; - $pword2 = $_POST['pwordConfirm']; - if ($action != 'Delete' and ($pword1 != $pword2)) return 'The passwords don\'t match!'; - $pword = md5($pword1); - switch ($action) { - case 'Add': - $sql = "insert into myprogramo (id, uname, pword, lastip, lastlogin) values (null, '$uname', '$pword','', CURRENT_TIMESTAMP);"; - $out = "Account for $uname successfully added!"; - break; - case 'Delete': - $sql = "DELETE FROM `pgov2_db1`.`myprogramo` WHERE `myprogramo`.`id` = $id LIMIT 1"; - $out = "Account for $uname successfully deleted!"; - break; - default: - $sql = "update myprogramo set uname = '$uname', pword = '$pword' where id = $id;"; - $out = "Account for $uname successfully updated!"; - } - $x = updateDB($sql); - #return "action = $action
        \n SQL = $sql"; - return $out; - } - - - - function getAdminsOpts() { - global $dbn; - $out = " \n"; - $dbconn = db_open(); - $optionTemplate = " \n"; - $sql = 'SELECT id, uname FROM myprogramo order by uname;'; - $result = mysql_query($sql,$dbconn) or die(mysql_error()); - while ($row = mysql_fetch_assoc($result)) { - $uname = $row['uname']; - $id = $row['id']; - $curOption = str_replace('[key]', $row['uname'], $optionTemplate); - $curOption = str_replace('[val]', $row['id'], $curOption); - $out .= $curOption; - } - mysql_close($dbconn); - $out .= " \n"; - return $out; - } - - function getMemberData($id) { - if ($id <= 0) return false; - global $dbn, $uname, $id; - $sql = "select id, uname from myprogramo where id = $id limit 1;"; - $dbconn = db_open(); - $result = mysql_query($sql,$dbconn) or die(mysql_error()); - $row = mysql_fetch_assoc($result); - $uname = $row['uname']; - $id = $row['id']; - mysql_close($dbconn); - } - - function getNextID() { - global $dbn, $uname; - $sql = "select id from myprogramo order by id desc limit 1;"; - $dbconn = db_open(); - $result = mysql_query($sql,$dbconn) or die(mysql_error()); - $row = mysql_fetch_assoc($result); - $id = $row['id']; - mysql_close($dbconn); - return $id + 1; - } - +$myPost
        \n"; + #if (!empty($_POST)) die ("
        \n Post Vars:\n$myPost\n
        \n"); + + $uname = ''; + $action = (isset($_POST['action'])) ? ucfirst(strtolower($_POST['action'])) : 'Add'; + if (!empty($_POST)) { + $msg = save($action); + #$action = ($action == 'editfromlist') ? 'Edit' : $action; + } + + $id = (isset($_POST['id']) and $action != 'Add') ? $_POST['id'] : getNextID(); + $id = ($id <= 0) ? getNextID() : $id; + if (isset($_POST['memberSelect'])) { + $id = $_POST['memberSelect']; + getMemberData($_POST['memberSelect']); + } + $upperScripts = << + + +endScript; + + $XmlEntities = array( + '&' => '&', + '<' => '<', + '>' => '>', + ''' => '\'', + '"' => '"', + ); + + $AdminsOpts = getAdminsOpts(); + + $membersForm = $template->getSection('MembersForm'); + $members_list_form = $template->getSection('MembersListForm'); + $showHelp = $template->getSection('MembersShowHelp'); + + $topNav = $template->getSection('TopNav'); + $leftNav = $template->getSection('LeftNav'); + $main = $template->getSection('Main'); + $topNavLinks = makeLinks('top', $topLinks, 12); + $navHeader = $template->getSection('NavHeader'); + $leftNavLinks = makeLinks('left', $leftLinks, 12); + $FooterInfo = getFooter(); + $errMsgClass = (!empty($msg)) ? "ShowError" : "HideError"; + $errMsgStyle = $template->getSection($errMsgClass); + $noLeftNav = ''; + $noTopNav = ''; + $noRightNav = $template->getSection('NoRightNav'); + $headerTitle = 'Actions:'; + $pageTitle = 'My-Program O - Admin Accounts'; + $mainContent = $template->getSection('MembersMain'); + $mainTitle = "Modify Admin Account Data [helpLink]"; + + $members_list_form = str_replace('[adminList]', $AdminsOpts, $members_list_form); + $mainContent = str_replace('[members_content]', $membersForm, $mainContent); + $mainContent = str_replace('[showHelp]', $showHelp, $mainContent); + $mainContent = str_replace('[members_list_form]', $members_list_form, $mainContent); + $mainContent = str_replace('[uname]', $uname, $mainContent); + $mainContent = str_replace('[action]', $action, $mainContent); + $mainContent = str_replace('[id]', $id, $mainContent); + $mainTitle = str_replace('[helpLink]', $template->getSection('HelpLink'), $mainTitle); + + + function updateDB($sql) { + $dbconn = db_open(); + $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL =
        $sql

        \n"); + $commit = mysql_affected_rows($dbconn); + return $commit; + } + + function save($action) { + global $dbn, $action; + #return 'action = ' . $action; + if (isset($_POST['memberSelect'])) { + $id = $_POST['memberSelect']; + } + else { + if (!isset($_POST['uname']) or !isset($_POST['pword']) or !isset($_POST['pwordConfirm'])) return 'You left something out!'; + $id = $_POST['id']; + $uname = $_POST['uname']; + $pword1 = $_POST['pword']; + $pword2 = $_POST['pwordConfirm']; + $pword = md5($pword1); + if ($action != 'Delete' and ($pword1 != $pword2)) return 'The passwords don\'t match!'; + } + switch ($action) { + case 'Add': + $ip = $_SERVER['REMOTE_HOST']; + $sql = "insert into myprogramo (id, uname, pword, lastip, lastlogin) values (null, '$uname', '$pword','$ip', CURRENT_TIMESTAMP);"; + $out = "Account for $uname successfully added!"; + break; + case 'Delete': + $action = 'Add'; + $sql = "DELETE FROM `$dbn`.`myprogramo` WHERE `myprogramo`.`id` = $id LIMIT 1"; + $out = "Account for $uname successfully deleted!"; + break; + case 'Edit': + $action = 'Add'; + $sql = "update myprogramo set uname = '$uname', pword = '$pword' where id = $id;"; + $out = "Account for $uname successfully updated!"; + break; + default: + $action = 'Edit'; + $sql = ''; + $out = ''; + } + $x = (!empty($sql)) ? updateDB($sql) : ''; + #return "action = $action
        \n SQL = $sql"; + return $out; + } + + + + function getAdminsOpts() { + global $dbn; + $out = " \n"; + $dbconn = db_open(); + $optionTemplate = " \n"; + $sql = 'SELECT id, uname FROM myprogramo order by uname;'; + $result = mysql_query($sql,$dbconn) or die(mysql_error()); + while ($row = mysql_fetch_assoc($result)) { + $uname = $row['uname']; + $id = $row['id']; + $curOption = str_replace('[key]', $row['uname'], $optionTemplate); + $curOption = str_replace('[val]', $row['id'], $curOption); + $out .= $curOption; + } + mysql_close($dbconn); + $out .= " \n"; + return $out; + } + + function getMemberData($id) { + if ($id <= 0) return false; + global $dbn, $uname, $id; + $sql = "select id, uname from myprogramo where id = $id limit 1;"; + $dbconn = db_open(); + $result = mysql_query($sql,$dbconn) or die(mysql_error()); + $row = mysql_fetch_assoc($result); + $uname = $row['uname']; + $id = $row['id']; + mysql_close($dbconn); + } + + function getNextID() { + global $dbn, $uname; + $sql = "select id from myprogramo order by id desc limit 1;"; + $dbconn = db_open(); + $result = mysql_query($sql,$dbconn) or die(mysql_error()); + $row = mysql_fetch_assoc($result); + $id = $row['id']; + mysql_close($dbconn); + return $id + 1; + } + ?> \ No newline at end of file diff --git a/admin/scripts/dtree.js b/admin/scripts/dtree.js index beac994..2144d3a 100644 --- a/admin/scripts/dtree.js +++ b/admin/scripts/dtree.js @@ -1,693 +1,693 @@ -/*--------------------------------------------------| - -| dTree 2.05 | www.destroydrop.com/javascript/tree/ | - -|---------------------------------------------------| - -| Copyright (c) 2002-2003 Geir Landr� | - -| | - -| This script can be used freely as long as all | - -| copyright messages are intact. | - -| | - -| Updated: 17.04.2003 | - -|--------------------------------------------------*/ - - - -// Node object - -function Node(id, pid, name, url, title, target, icon, iconOpen, open) { - - this.id = id; - - this.pid = pid; - - this.name = name; - - this.url = url; - - this.title = title; - - this.target = target; - - this.icon = icon; - - this.iconOpen = iconOpen; - - this._io = open || false; - - this._is = false; - - this._ls = false; - - this._hc = false; - - this._ai = 0; - - this._p; - -}; - - - -// Tree object - -function dTree(objName) { - - this.config = { - - target : null, - - folderLinks : true, - - useSelection : true, - - useCookies : true, - - useLines : true, - - useIcons : true, - - useStatusText : false, - - closeSameLevel : false, - - inOrder : false - - } - - this.icon = { - - root : 'img/base.gif', - - folder : 'img/folder.gif', - - folderOpen : 'img/folderopen.gif', - - node : 'img/page.gif', - - empty : 'img/empty.gif', - - line : 'img/line.gif', - - join : 'img/join.gif', - - joinBottom : 'img/joinbottom.gif', - - plus : 'img/plus.gif', - - plusBottom : 'img/plusbottom.gif', - - minus : 'img/minus.gif', - - minusBottom : 'img/minusbottom.gif', - - nlPlus : 'img/nolines_plus.gif', - - nlMinus : 'img/nolines_minus.gif' - - }; - - this.obj = objName; - - this.aNodes = []; - - this.aIndent = []; - - this.root = new Node(-1); - - this.selectedNode = null; - - this.selectedFound = false; - - this.completed = false; - -}; - - - -// Adds a new node to the node array - -dTree.prototype.add = function(id, pid, name, url, title, target, icon, iconOpen, open) { - - this.aNodes[this.aNodes.length] = new Node(id, pid, name, url, title, target, icon, iconOpen, open); - -}; - - - -// Open/close all nodes - -dTree.prototype.openAll = function() { - - this.oAll(true); - -}; - -dTree.prototype.closeAll = function() { - - this.oAll(false); - -}; - - - -// Outputs the tree to the page - -dTree.prototype.toString = function() { - - var str = '
        \n'; - - if (document.getElementById) { - - if (this.config.useCookies) this.selectedNode = this.getSelected(); - - str += this.addNode(this.root); - - } else str += 'Browser not supported.'; - - str += '
        '; - - if (!this.selectedFound) this.selectedNode = null; - - this.completed = true; - - return str; - -}; - - - -// Creates the tree structure - -dTree.prototype.addNode = function(pNode) { - - var str = ''; - - var n=0; - - if (this.config.inOrder) n = pNode._ai; - - for (n; n'; - - } - - if (node.url) { - - str += ''; - - str += node.name; - - if (node.url || ((!this.config.folderLinks || !node.url) && node._hc)) str += ''; - - str += ''; - - if (node._hc) { - - str += '
        '; - - str += this.addNode(node); - - str += '
        '; - - } - - this.aIndent.pop(); - - return str; - -}; - - - -// Adds the empty and line icons - -dTree.prototype.indent = function(node, nodeId) { - - var str = ''; - - if (this.root.id != node.pid) { - - for (var n=0; n'; - - (node._ls) ? this.aIndent.push(0) : this.aIndent.push(1); - - if (node._hc) { - - str += ''; - - } else str += ''; - - } - - return str; - -}; - - - -// Checks if a node has any children and if it is the last sibling - -dTree.prototype.setCS = function(node) { - - var lastId; - - for (var n=0; n'; + + } + + if (node.url) { + + str += ''; + + str += node.name; + + if (node.url || ((!this.config.folderLinks || !node.url) && node._hc)) str += ''; + + str += ''; + + if (node._hc) { + + str += '
        '; + + str += this.addNode(node); + + str += '
        '; + + } + + this.aIndent.pop(); + + return str; + +}; + + + +// Adds the empty and line icons + +dTree.prototype.indent = function(node, nodeId) { + + var str = ''; + + if (this.root.id != node.pid) { + + for (var n=0; n'; + + (node._ls) ? this.aIndent.push(0) : this.aIndent.push(1); + + if (node._hc) { + + str += ''; + + } else str += ''; + + } + + return str; + +}; + + + +// Checks if a node has any children and if it is the last sibling + +dTree.prototype.setCS = function(node) { + + var lastId; + + for (var n=0; n 1){ - rowLength = rowLength + (rowArr[0][c].getAttribute(fdTableSort.colspan) - 1); - }; - }; - - workArr = new Array(rowArr.length); - for(c = rowArr.length;c--;){ workArr[c]= new Array(rowLength); }; - - for(c = 0;c < workArr.length;c++){ - celCount = 0; - for(i = 0;i < rowLength;i++){ - if(!workArr[c][i]){ - cel = rowArr[c][celCount]; - colspan = (cel.getAttribute(fdTableSort.colspan) > 1) ? cel.getAttribute(fdTableSort.colspan):1; - rowspan = (cel.getAttribute(fdTableSort.rowspan) > 1) ? cel.getAttribute(fdTableSort.rowspan):1; - for(var t = 0;((t < colspan)&&((i+t) < rowLength));t++){ - for(var n = 0;((n < rowspan)&&((c+n) < workArr.length));n++) { - workArr[(c+n)][(i+t)] = cel; - }; - }; - if(++celCount == rowArr[c].length) break; - }; - }; - }; - - for(c = 0;c < workArr.length;c++) { - for(i = 0;i < workArr[c].length;i++){ - - if(workArr[c][i].className.search("fd-column-") == -1 && workArr[c][i].className.search("sortable") != -1) workArr[c][i].className = workArr[c][i].className + " fd-column-" + i; - - if(workArr[c][i].className.match('sortable')) { - workArr[c][i].className = workArr[c][i].className.replace(/forwardSort|reverseSort/, ""); - - if(i in columnNumSortObj) { - columnNumSortObj[i]["thNode"] = workArr[c][i]; - columnNumSortObj["active"] = true; - }; - - thtext = fdTableSort.getInnerText(workArr[c][i], true); - - for(var cn = workArr[c][i].childNodes.length; cn--;) { - // Skip image nodes and links created by the filter script. - if(workArr[c][i].childNodes[cn].nodeType == 1 && (workArr[c][i].childNodes[cn].className == "fdFilterTrigger" || /img/i.test(workArr[c][i].childNodes[cn].nodeName))) { - continue; - }; - if(workArr[c][i].childNodes[cn].nodeType == 1 && /^a$/i.test(workArr[c][i].childNodes[cn].nodeName)) { - workArr[c][i].childNodes[cn].onclick = workArr[c][i].childNodes[cn].onkeydown = null; - }; - workArr[c][i].removeChild(workArr[c][i].childNodes[cn]); - }; - - aclone = a.cloneNode(true); - //aclone.appendChild(document.createTextNode(thtext)); - aclone.innerHTML = thtext; - aclone.title = "Sort on \u201c" + thtext.replace('
        ', '') + "\u201d"; - aclone.onclick = aclone.onkeydown = workArr[c][i].onclick = fdTableSort.initWrapper; - workArr[c][i].appendChild(aclone); - if(showArrow) workArr[c][i].appendChild(span.cloneNode(false)); - workArr[c][i].className = workArr[c][i].className.replace(/fd-identical|fd-not-identical/, ""); - fdTableSort.disableSelection(workArr[c][i]); - aclone = null; - }; - }; - }; - - fdTableSort.tmpCache[tbl.id] = {cols:rowLength, headers:workArr}; - - workArr = null; - multi = 0; - - if("active" in columnNumSortObj) { - fdTableSort.tableId = tbl.id; - fdTableSort.prepareTableData(document.getElementById(fdTableSort.tableId)); - - delete columnNumSortObj["active"]; - - for(col in columnNumSortObj) { - obj = columnNumSortObj[col]; - if(!("thNode" in obj)) { continue; }; - fdTableSort.multi = true; - - len = obj.reverse ? 2 : 1; - - for(ii = 0; ii < len; ii++) { - fdTableSort.thNode = obj.thNode; - if(!showOnly) { - fdTableSort.initSort(false, true); - } else { - fdTableSort.addThNode(); - }; - }; - - if(showOnly) { - fdTableSort.removeClass(obj.thNode, "(forwardSort|reverseSort)"); - fdTableSort.addClass(obj.thNode, obj.reverse ? "reverseSort" : "forwardSort"); - if(showArrow) { - span = fdTableSort.thNode.getElementsByTagName('span')[0]; - if(span.firstChild) { span.removeChild(span.firstChild); }; - span.appendChild(document.createTextNode(len == 1 ? " \u2193" : " \u2191")); - }; - }; - }; - if(showOnly && (fdTableSort.tableCache[tbl.id].colStyle || fdTableSort.tableCache[tbl.id].rowStyle)) { - fdTableSort.redraw(tbl.id, false); - }; - } else if(tbl.className.search(/onload-zebra/) != -1) { - fdTableSort.tableId = tbl.id; - fdTableSort.prepareTableData(tbl); - if(fdTableSort.tableCache[tbl.id].rowStyle) { fdTableSort.redraw(tbl.id, false); }; - }; - }; - - fdTableSort.thNode = aclone = a = span = columnNumSortObj = thNode = tbl = allRowArr = rowArr = null; - }, - initWrapper: function(e) { - e = e || window.event; - var kc = e.type == "keydown" ? e.keyCode != null ? e.keyCode : e.charCode : -1; - if(fdTableSort.thNode == null && (e.type == "click" || kc == 13)) { - var targ = this; - while(targ.tagName.toLowerCase() != "th") { targ = targ.parentNode; }; - fdTableSort.thNode = targ; - while(targ.tagName.toLowerCase() != "table") { targ = targ.parentNode; }; - fdTableSort.tableId = targ.id; - fdTableSort.multi = e.shiftKey; - fdTableSort.addSortActiveClass(); - setTimeout(fdTableSort.initSort,5,false); - return fdTableSort.stopEvent(e); - }; - return kc != -1 ? true : fdTableSort.stopEvent(e); - }, - jsWrapper: function(tableid, colNums) { - if(!(tableid in fdTableSort.tmpCache)) { return false; }; - if(!(tableid in fdTableSort.tableCache)) { fdTableSort.prepareTableData(document.getElementById(tableid)); }; - if(!(colNums instanceof Array)) { colNums = [colNums]; }; - - fdTableSort.tableId = tableid; - var len = colNums.length, colNum; - - if(fdTableSort.tableCache[tableid].thList.length == colNums.length) { - var identical = true; - var th; - for(var i = 0; i < len; i++) { - colNum = colNums[i]; - th = fdTableSort.tmpCache[tableid].headers[0][colNum]; - if(th != fdTableSort.tableCache[tableid].thList[i]) { - identical = false; - break; - }; - }; - if(identical) { - fdTableSort.thNode = th; - fdTableSort.initSort(true); - return; - }; - }; - - fdTableSort.addSortActiveClass(); - - for(var i = 0; i < len; i++) { - fdTableSort.multi = i; - colNum = colNums[i]; - fdTableSort.thNode = fdTableSort.tmpCache[tableid].headers[0][colNum]; - fdTableSort.initSort(true); - }; - }, - addSortActiveClass: function() { - if(fdTableSort.thNode == null) { return; }; - fdTableSort.addClass(fdTableSort.thNode, fdTableSort.sortActiveClass); - fdTableSort.addClass(document.getElementsByTagName('body')[0], fdTableSort.sortActiveClass); - }, - removeSortActiveClass: function() { - if(fdTableSort.thNode == null) return; - fdTableSort.removeClass(fdTableSort.thNode, fdTableSort.sortActiveClass); - fdTableSort.removeClass(document.getElementsByTagName('body')[0], fdTableSort.sortActiveClass); - }, - doCallback: function(init) { - if(!fdTableSort.tableId || !(fdTableSort.tableId in fdTableSort.tableCache)) { return; }; - fdTableSort.callback(fdTableSort.tableId, init ? fdTableSort.tableCache[fdTableSort.tableId].initiatedCallback : fdTableSort.tableCache[fdTableSort.tableId].completeCallback); - }, - addClass: function(e,c) { - if(new RegExp("(^|\\s)" + c + "(\\s|$)").test(e.className)) { return; }; - e.className += ( e.className ? " " : "" ) + c; - }, - /*@cc_on - /*@if (@_win32) - removeClass: function(e,c) { - e.className = !c ? "" : e.className.replace(new RegExp("(^|\\s)" + c + "(\\s|$)"), " ").replace(/^\s*((?:[\S\s]*\S)?)\s*$/, '$1'); - }, - @else @*/ - removeClass: function(e,c) { - e.className = !c ? "" : e.className.replace(new RegExp("(^|\\s)" + c + "(\\s|$)"), " ").replace(/^\s\s*/, '').replace(/\s\s*$/, ''); - }, - /*@end - @*/ - callback: function(tblId, cb) { - var func, parts; - try { - if(cb.indexOf(".") != -1) { - parts = cb.split('.'); - obj = window; - for (var x = 0, part; part = obj[parts[x]]; x++) { - if(part instanceof Function) { - (function() { - var method = part; - func = function (data) { method.apply(obj, [data]) }; - })(); - } else { - obj = part; - }; - }; - } else if(cb + tblId in window) { - func = window[cb + tblId]; - } else if(cb in window) { - func = window[cb]; - } else { - func = null; - }; - } catch(err) {}; - - if(!(func instanceof Function)) return; - func(tblId, fdTableSort.tableCache[tblId].thList); - }, - prepareTableData: function(table) { - var data = []; - - var start = table.getElementsByTagName('tbody'); - start = start.length ? start[0] : table; - - var trs = start.rows; - var ths = table.getElementsByTagName('th'); - - var numberOfRows = trs.length; - var numberOfCols = fdTableSort.tmpCache[table.id].cols; - - var data = []; - var identical = new Array(numberOfCols); - var identVal = new Array(numberOfCols); - - for(var tmp = 0; tmp < numberOfCols; tmp++) identical[tmp] = true; - - var tr, td, th, txt, tds, col, row; - - var re = new RegExp(/fd-column-([0-9]+)/); - var rowCnt = 0; - - var sortableColumnNumbers = []; - - for(var tmp = 0, th; th = ths[tmp]; tmp++) { - if(th.className.search(re) == -1) continue; - sortableColumnNumbers[sortableColumnNumbers.length] = th; - }; - - for(row = 0; row < numberOfRows; row++) { - - tr = trs[row]; - if(tr.parentNode != start || tr.getElementsByTagName("th").length || (tr.parentNode && tr.parentNode.tagName.toLowerCase().search(/thead|tfoot/) != -1)) continue; - data[rowCnt] = []; - tds = tr.cells; - - for(var tmp = 0, th; th = sortableColumnNumbers[tmp]; tmp++) { - col = th.className.match(re)[1]; - - td = tds[col]; - txt = fdTableSort.getInnerText(td) + " "; - txt = txt.replace(/^\s+/,'').replace(/\s+$/,''); - - if(th.className.search(/sortable-date/) != -1) { - txt = fdTableSort.dateFormat(txt, th.className.search(/sortable-date-dmy/) != -1); - } else if(th.className.search(/sortable-numeric|sortable-currency/) != -1) { - txt = parseFloat(txt.replace(/[^0-9\.\-]/g,'')); - if(isNaN(txt)) txt = ""; - } else if(th.className.search(/sortable-text/) != -1) { - txt = txt.toLowerCase(); - } else if (th.className.search(/sortable-keep/) != -1) { - txt = rowCnt; - } else if(th.className.search(/sortable-([a-zA-Z\_]+)/) != -1) { - if((th.className.match(/sortable-([a-zA-Z\_]+)/)[1] + "PrepareData") in window) { - txt = window[th.className.match(/sortable-([a-zA-Z\_]+)/)[1] + "PrepareData"](td, txt); - }; - } else if(txt != "") { - fdTableSort.removeClass(th, "sortable"); - if(fdTableSort.dateFormat(txt) != 0) { - fdTableSort.addClass(th, "sortable-date"); - txt = fdTableSort.dateFormat(txt); - } else if(txt.search(fdTableSort.regExp_Number) != -1 || txt.search(fdTableSort.regExp_Currency) != -1) { - fdTableSort.addClass(th, "sortable-numeric"); - txt = parseFloat(txt.replace(/[^0-9\.\-]/g,'')); - if(isNaN(txt)) txt = ""; - } else { - fdTableSort.addClass(th, "sortable-text"); - txt = txt.toLowerCase(); - }; - }; - - if(rowCnt > 0 && identical[col] && identVal[col] != txt) { identical[col] = false; }; - - identVal[col] = txt; - data[rowCnt][col] = txt; - }; - data[rowCnt][numberOfCols] = tr; - rowCnt++; - }; - - var colStyle = table.className.search(/colstyle-([\S]+)/) != -1 ? table.className.match(/colstyle-([\S]+)/)[1] : false; - var rowStyle = table.className.search(/rowstyle-([\S]+)/) != -1 ? table.className.match(/rowstyle-([\S]+)/)[1] : false; - var iCBack = table.className.search(/sortinitiatedcallback-([\S-]+)/) == -1 ? "sortInitiatedCallback" : table.className.match(/sortinitiatedcallback-([\S]+)/)[1]; - var cCBack = table.className.search(/sortcompletecallback-([\S-]+)/) == -1 ? "sortCompleteCallback" : table.className.match(/sortcompletecallback-([\S]+)/)[1]; - iCBack = iCBack.replace("-", "."); - cCBack = cCBack.replace("-", "."); - fdTableSort.tableCache[table.id] = { hook:start, initiatedCallback:iCBack, completeCallback:cCBack, thList:[], colOrder:{}, data:data, identical:identical, colStyle:colStyle, rowStyle:rowStyle, noArrow:table.className.search(/no-arrow/) != -1 }; - sortableColumnNumbers = data = tr = td = th = trs = identical = identVal = null; - }, - onUnload: function() { - for(tbl in fdTableSort.tableCache) { fdTableSort.removeTableCache(tbl); }; - for(tbl in fdTableSort.tmpCache) { fdTableSort.removeTmpCache(tbl); }; - fdTableSort.removeEvent(window, "load", fdTableSort.initEvt); - fdTableSort.removeEvent(window, "unload", fdTableSort.onUnload); - fdTableSort.tmpCache = fdTableSort.tableCache = null; - }, - addThNode: function() { - var dataObj = fdTableSort.tableCache[fdTableSort.tableId]; - var pos = fdTableSort.thNode.className.match(/fd-column-([0-9]+)/)[1]; - var alt = false; - - if(!fdTableSort.multi) { - if(dataObj.colStyle) { - var len = dataObj.thList.length; - for(var i = 0; i < len; i++) { - dataObj.colOrder[dataObj.thList[i].className.match(/fd-column-([0-9]+)/)[1]] = false; - }; - }; - if(dataObj.thList.length && dataObj.thList[0] == fdTableSort.thNode) alt = true; - dataObj.thList = []; - }; - - var found = false; - var l = dataObj.thList.length; - - for(var i = 0, n; n = dataObj.thList[i]; i++) { - if(n == fdTableSort.thNode) { - found = true; - break; - }; - }; - - if(!found) { - dataObj.thList.push(fdTableSort.thNode); - if(dataObj.colStyle) { dataObj.colOrder[pos] = true; }; - }; - - var ths = document.getElementById(fdTableSort.tableId).getElementsByTagName("th"); - for(var i = 0, th; th = ths[i]; i++) { - found = false; - for(var z = 0, n; n = dataObj.thList[z]; z++) { - if(n == th) { - found = true; - break; - }; - }; - if(!found) { - fdTableSort.removeClass(th, "(forwardSort|reverseSort)"); - if(!dataObj.noArrow) { - span = th.getElementsByTagName('span'); - if(span.length) { - span = span[0]; - while(span.firstChild) span.removeChild(span.firstChild); - }; - }; - }; - }; - - if(dataObj.thList.length > 1) { - classToAdd = fdTableSort.thNode.className.search(/forwardSort/) != -1 ? "reverseSort" : "forwardSort"; - fdTableSort.removeClass(fdTableSort.thNode, "(forwardSort|reverseSort)"); - fdTableSort.addClass(fdTableSort.thNode, classToAdd); - dataObj.pos = -1 - } else if(alt) { dataObj.pos = fdTableSort.thNode }; - }, - initSort: function(noCallback, ident) { - var thNode = fdTableSort.thNode; - var tableElem = document.getElementById(fdTableSort.tableId); - - if(!(fdTableSort.tableId in fdTableSort.tableCache)) { fdTableSort.prepareTableData(document.getElementById(fdTableSort.tableId)); }; - - fdTableSort.addThNode(); - - if(!noCallback) { fdTableSort.doCallback(true); }; - - fdTableSort.pos = thNode.className.match(/fd-column-([0-9]+)/)[1]; - var dataObj = fdTableSort.tableCache[tableElem.id]; - var lastPos = dataObj.pos && dataObj.pos.className ? dataObj.pos.className.match(/fd-column-([0-9]+)/)[1] : -1; - var len1 = dataObj.data.length; - var len2 = dataObj.data.length > 0 ? dataObj.data[0].length - 1 : 0; - var identical = dataObj.identical[fdTableSort.pos]; - var classToAdd = "forwardSort"; - - if(dataObj.thList.length > 1) { - var js = "var sortWrapper = function(a,b) {\n"; - var l = dataObj.thList.length; - var cnt = 0; - var e,d,th,p,f; - - for(var i=0; i < l; i++) { - th = dataObj.thList[i]; - p = th.className.match(/fd-column-([0-9]+)/)[1]; - if(dataObj.identical[p]) { continue; }; - cnt++; - - if(th.className.match(/sortable-(numeric|currency|date|keep)/)) { - f = "fdTableSort.sortNumeric"; - } else if(th.className.match('sortable-text')) { - f = "fdTableSort.sortText"; - } else if(th.className.search(/sortable-([a-zA-Z\_]+)/) != -1 && th.className.match(/sortable-([a-zA-Z\_]+)/)[1] in window) { - f = "window['" + th.className.match(/sortable-([a-zA-Z\_]+)/)[1] + "']"; - } else f = "fdTableSort.sortText"; - - e = "e" + i; - d = th.className.search('forwardSort') != -1 ? "a,b" : "b,a"; - js += "fdTableSort.pos = " + p + ";\n"; - js += "var " + e + " = "+f+"(" + d +");\n"; - js += "if(" + e + ") return " + e + ";\n"; - js += "else { \n"; - }; - - js += "return 0;\n"; - - for(var i=0; i < cnt; i++) { - js += "};\n"; - }; - - if(cnt) js += "return 0;\n"; - js += "};\n"; - - eval(js); - dataObj.data.sort(sortWrapper); - identical = false; - } else if((lastPos == fdTableSort.pos && !identical) || (thNode.className.search(/sortable-keep/) != -1 && lastPos == -1)) { - dataObj.data.reverse(); - classToAdd = thNode.className.search(/reverseSort/) != -1 ? "forwardSort" : "reverseSort"; - if(thNode.className.search(/sortable-keep/) != -1 && lastPos == -1) fdTableSort.tableCache[tableElem.id].pos = thNode; - } else { - fdTableSort.tableCache[tableElem.id].pos = thNode; - classToAdd = thNode.className.search(/forwardSort/) != -1 ? "reverseSort" : "forwardSort"; - if(!identical) { - if(thNode.className.match(/sortable-(numeric|currency|date|keep)/)) { - dataObj.data.sort(fdTableSort.sortNumeric); - } else if(thNode.className.match('sortable-text')) { - dataObj.data.sort(fdTableSort.sortText); - } else if(thNode.className.search(/sortable-([a-zA-Z\_]+)/) != -1 && thNode.className.match(/sortable-([a-zA-Z\_]+)/)[1] in window) { - dataObj.data.sort(window[thNode.className.match(/sortable-([a-zA-Z\_]+)/)[1]]); - }; - - if(thNode.className.search(/(^|\s)favour-reverse($|\s)/) != -1) { - classToAdd = classToAdd == "forwardSort" ? "reverseSort" : "forwardSort"; - dataObj.data.reverse(); - }; - }; - }; - if(ident) { identical = false; }; - if(dataObj.thList.length == 1) { - fdTableSort.removeClass(thNode, "(forwardSort|reverseSort)"); - fdTableSort.addClass(thNode, classToAdd); - }; - if(!dataObj.noArrow) { - var span = fdTableSort.thNode.getElementsByTagName('span')[0]; - if(span.firstChild) span.removeChild(span.firstChild); - span.appendChild(document.createTextNode(fdTableSort.thNode.className.search(/forwardSort/) != -1 ? " \u2193" : " \u2191")); - }; - if(!dataObj.rowStyle && !dataObj.colStyle && identical) { - fdTableSort.removeSortActiveClass(); - if(!noCallback) { fdTableSort.doCallback(false); }; - fdTableSort.thNode = null; - return; - }; - if("tablePaginater" in window && tablePaginater.tableIsPaginated(fdTableSort.tableId)) { - tablePaginater.redraw(fdTableSort.tableId, identical); - } else { - fdTableSort.redraw(fdTableSort.tableId, identical); - }; - fdTableSort.removeSortActiveClass(); - if(!noCallback) { fdTableSort.doCallback(false); }; - fdTableSort.thNode = null; - }, - redraw: function(tableid, identical) { - if(!tableid || !(tableid in fdTableSort.tableCache)) { return; }; - var dataObj = fdTableSort.tableCache[tableid]; - var data = dataObj.data; - var len1 = data.length; - var len2 = len1 ? data[0].length - 1 : 0; - var hook = dataObj.hook; - var colStyle = dataObj.colStyle; - var rowStyle = dataObj.rowStyle; - var colOrder = dataObj.colOrder; - var highLight = 0; - var reg = /(^|\s)invisibleRow(\s|$)/; - var tr, tds; - - for(var i = 0; i < len1; i++) { - tr = data[i][len2]; - if(colStyle) { - tds = tr.cells; - for(thPos in colOrder) { - if(!colOrder[thPos]) fdTableSort.removeClass(tds[thPos], colStyle); - else fdTableSort.addClass(tds[thPos], colStyle); - }; - }; - if(!identical) { - if(rowStyle && tr.className.search(reg) == -1) { - if(highLight++ & 1) fdTableSort.addClass(tr, rowStyle); - else fdTableSort.removeClass(tr, rowStyle); - }; - - // Netscape 8.1.2 requires the removeChild call or it freaks out, so add the line if you want to support this browser - // hook.removeChild(tr); - hook.appendChild(tr); - }; - }; - tr = tds = hook = null; - }, - getInnerText: function(el, allowBrTags) { - if (typeof el == "string" || typeof el == "undefined") return el; - if(el.innerText) return el.innerText; - var txt = '', i; - for(i = el.firstChild; i; i = i.nextSibling) { - if(allowBrTags && i.nodeName && i.nodeName == "BR") txt += "
        "; - else if(i.nodeType == 3) txt += i.nodeValue; - else if(i.nodeType == 1) txt += fdTableSort.getInnerText(i); - }; - return txt; - }, - dateFormat: function(dateIn, favourDMY) { - var dateTest = [ - { regExp:/^(0?[1-9]|1[012])([- \/.])(0?[1-9]|[12][0-9]|3[01])([- \/.])((\d\d)?\d\d)$/, d:3, m:1, y:5 }, // mdy - { regExp:/^(0?[1-9]|[12][0-9]|3[01])([- \/.])(0?[1-9]|1[012])([- \/.])((\d\d)?\d\d)$/, d:1, m:3, y:5 }, // dmy - { regExp:/^(\d\d\d\d)([- \/.])(0?[1-9]|1[012])([- \/.])(0?[1-9]|[12][0-9]|3[01])$/, d:5, m:3, y:1 } // ymd - ]; - var start, cnt = 0, numFormats = dateTest.length; - while(cnt < numFormats) { - start = (cnt + (favourDMY ? numFormats + 1 : numFormats)) % numFormats; - if(dateIn.match(dateTest[start].regExp)) { - res = dateIn.match(dateTest[start].regExp); - y = res[dateTest[start].y]; - m = res[dateTest[start].m]; - d = res[dateTest[start].d]; - if(m.length == 1) m = "0" + String(m); - if(d.length == 1) d = "0" + String(d); - if(y.length != 4) y = (parseInt(y) < 50) ? "20" + String(y) : "19" + String(y); - - return y+String(m)+d; - }; - cnt++; - }; - return 0; - }, - sortNumeric:function(a,b) { - var aa = a[fdTableSort.pos]; - var bb = b[fdTableSort.pos]; - if(aa == bb) return 0; - if(aa === "" && !isNaN(bb)) return -1; - if(bb === "" && !isNaN(aa)) return 1; - return aa - bb; - }, - sortText:function(a,b) { - var aa = a[fdTableSort.pos]; - var bb = b[fdTableSort.pos]; - if(aa == bb) return 0; - if(aa < bb) return -1; - return 1; - } -}; -})(); -fdTableSort.addEvent(window, "load", fdTableSort.initEvt); +/* + TableSort revisited v5.0 by frequency-decoder.com + + Released under a creative commons Attribution-ShareAlike 2.5 license (http://creativecommons.org/licenses/by-sa/2.5/) + + Please credit frequency decoder in any derivative work - thanks + + You are free: + + * to copy, distribute, display, and perform the work + * to make derivative works + * to make commercial use of the work + + Under the following conditions: + + by Attribution. + -------------- + You must attribute the work in the manner specified by the author or licensor. + + sa + -- + Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one. + + * For any reuse or distribution, you must make clear to others the license terms of this work. + * Any of these conditions can be waived if you get permission from the copyright holder. +*/ + +(function() { +fdTableSort = { + regExp_Currency: /^[£$€¥¤]/, + regExp_Number: /^(\-)?[0-9]+(\.[0-9]*)?$/, + pos: -1, + uniqueHash: 1, + thNode: null, + tableId: null, + tableCache: {}, + tmpCache: {}, + sortActiveClass: "sort-active", + /*@cc_on + /*@if (@_win32) + colspan: "colSpan", + rowspan: "rowSpan", + @else @*/ + colspan: "colspan", + rowspan: "rowspan", + /*@end + @*/ + + addEvent: function(obj, type, fn, tmp) { + tmp || (tmp = true); + if( obj.attachEvent ) { + obj["e"+type+fn] = fn; + obj[type+fn] = function(){obj["e"+type+fn]( window.event );}; + obj.attachEvent( "on"+type, obj[type+fn] ); + } else { + obj.addEventListener( type, fn, true ); + }; + }, + removeEvent: function(obj, type, fn, tmp) { + tmp || (tmp = true); + try { + if( obj.detachEvent ) { + obj.detachEvent( "on"+type, obj[type+fn] ); + obj[type+fn] = null; + } else { + obj.removeEventListener( type, fn, true ); + }; + } catch(err) {}; + }, + stopEvent: function(e) { + e = e || window.event; + + if(e.stopPropagation) { + e.stopPropagation(); + e.preventDefault(); + }; + + /*@cc_on@*/ + /*@if(@_win32) + e.cancelBubble = true; + e.returnValue = false; + /*@end@*/ + return false; + }, + parseClassName: function(head, tbl) { + var colMatch = tbl.className.match(new RegExp(head + "((-[\\d]+([r]){0,1})+)")); + return colMatch && colMatch.length ? colMatch[0].replace(head, "").split("-") : []; + }, + disableSelection: function(element) { + element.onselectstart = function() { + return false; + }; + element.unselectable = "on"; + element.style.MozUserSelect = "none"; + }, + removeTableCache: function(tableId) { + if(!(tableId in fdTableSort.tableCache)) return; + + fdTableSort.tableCache[tableId] = null; + delete fdTableSort.tableCache[tableId]; + + var tbl = document.getElementById(tableId); + if(!tbl) return; + var ths = tbl.getElementsByTagName("th"); + var a; + for(var i = 0, th; th = ths[i]; i++) { + a = th.getElementsByTagName("a"); + if(a.length) a[0].onkeydown = a[0].onclick = null; + th.onclick = th.onselectstart = th = a = null; + }; + }, + removeTmpCache: function(tableId) { + if(!(tableId in fdTableSort.tmpCache)) return; + var headers = fdTableSort.tmpCache[tableId].headers; + var a; + for(var i = 0, row; row = headers[i]; i++) { + for(var j = 0, th; th = row[j]; j++) { + a = th.getElementsByTagName("a"); + if(a.length) a[0].onkeydown = a[0].onclick = null; + th.onclick = th.onselectstart = th = a = null; + }; + }; + fdTableSort.tmpCache[tableId] = null; + delete fdTableSort.tmpCache[tableId]; + }, + initEvt: function(e) { + fdTableSort.init(false); + }, + init: function(tableId) { + if (!document.getElementsByTagName || !document.createElement || !document.getElementById) return; + + var tables = tableId && document.getElementById(tableId) ? [document.getElementById(tableId)] : document.getElementsByTagName("table"); + var c, ii, len, colMatch, showOnly, match, showArrow, columnNumSortObj, obj, workArr, headers, thtext, aclone, multi, colCnt, cel, allRowArr, rowArr, sortableTable, celCount, colspan, rowspan, rowLength; + + var a = document.createElement("a"); + a.href = "#"; + a.className = "fdTableSortTrigger"; + + var span = document.createElement("span"); + + for(var k = 0, tbl; tbl = tables[k]; k++) { + + if(tbl.id) { + fdTableSort.removeTableCache(tbl.id); + fdTableSort.removeTmpCache(tbl.id); + }; + + allRowArr = tbl.getElementsByTagName('thead').length ? tbl.getElementsByTagName('thead')[0].getElementsByTagName('tr') : tbl.getElementsByTagName('tr'); + rowArr = []; + sortableTable = false; + + for(var i = 0, tr; tr = allRowArr[i]; i++) { + if(tr.getElementsByTagName('td').length || !tr.getElementsByTagName('th').length) { continue; }; + rowArr[rowArr.length] = tr.getElementsByTagName('th'); + for(var j = 0, th; th = rowArr[rowArr.length - 1][j]; j++) { + if(th.className.search(/sortable/) != -1) { sortableTable = true; }; + }; + }; + + if(!sortableTable) continue; + + if(!tbl.id) { tbl.id = "fd-table-" + fdTableSort.uniqueHash++; }; + + showArrow = tbl.className.search("no-arrow") == -1; + showOnly = tbl.className.search("sortable-onload-show") != -1; + + columnNumSortObj = {}; + colMatch = fdTableSort.parseClassName(showOnly ? "sortable-onload-show" : "sortable-onload", tbl); + for(match = 1; match < colMatch.length; match++) { + columnNumSortObj[parseInt(colMatch[match], 10)] = { "reverse":colMatch[match].search("r") != -1 }; + }; + + rowLength = rowArr[0].length; + + for(c = 0;c < rowArr[0].length;c++){ + if(rowArr[0][c].getAttribute(fdTableSort.colspan) && rowArr[0][c].getAttribute(fdTableSort.colspan) > 1){ + rowLength = rowLength + (rowArr[0][c].getAttribute(fdTableSort.colspan) - 1); + }; + }; + + workArr = new Array(rowArr.length); + for(c = rowArr.length;c--;){ workArr[c]= new Array(rowLength); }; + + for(c = 0;c < workArr.length;c++){ + celCount = 0; + for(i = 0;i < rowLength;i++){ + if(!workArr[c][i]){ + cel = rowArr[c][celCount]; + colspan = (cel.getAttribute(fdTableSort.colspan) > 1) ? cel.getAttribute(fdTableSort.colspan):1; + rowspan = (cel.getAttribute(fdTableSort.rowspan) > 1) ? cel.getAttribute(fdTableSort.rowspan):1; + for(var t = 0;((t < colspan)&&((i+t) < rowLength));t++){ + for(var n = 0;((n < rowspan)&&((c+n) < workArr.length));n++) { + workArr[(c+n)][(i+t)] = cel; + }; + }; + if(++celCount == rowArr[c].length) break; + }; + }; + }; + + for(c = 0;c < workArr.length;c++) { + for(i = 0;i < workArr[c].length;i++){ + + if(workArr[c][i].className.search("fd-column-") == -1 && workArr[c][i].className.search("sortable") != -1) workArr[c][i].className = workArr[c][i].className + " fd-column-" + i; + + if(workArr[c][i].className.match('sortable')) { + workArr[c][i].className = workArr[c][i].className.replace(/forwardSort|reverseSort/, ""); + + if(i in columnNumSortObj) { + columnNumSortObj[i]["thNode"] = workArr[c][i]; + columnNumSortObj["active"] = true; + }; + + thtext = fdTableSort.getInnerText(workArr[c][i], true); + + for(var cn = workArr[c][i].childNodes.length; cn--;) { + // Skip image nodes and links created by the filter script. + if(workArr[c][i].childNodes[cn].nodeType == 1 && (workArr[c][i].childNodes[cn].className == "fdFilterTrigger" || /img/i.test(workArr[c][i].childNodes[cn].nodeName))) { + continue; + }; + if(workArr[c][i].childNodes[cn].nodeType == 1 && /^a$/i.test(workArr[c][i].childNodes[cn].nodeName)) { + workArr[c][i].childNodes[cn].onclick = workArr[c][i].childNodes[cn].onkeydown = null; + }; + workArr[c][i].removeChild(workArr[c][i].childNodes[cn]); + }; + + aclone = a.cloneNode(true); + //aclone.appendChild(document.createTextNode(thtext)); + aclone.innerHTML = thtext; + aclone.title = "Sort on \u201c" + thtext.replace('
        ', '') + "\u201d"; + aclone.onclick = aclone.onkeydown = workArr[c][i].onclick = fdTableSort.initWrapper; + workArr[c][i].appendChild(aclone); + if(showArrow) workArr[c][i].appendChild(span.cloneNode(false)); + workArr[c][i].className = workArr[c][i].className.replace(/fd-identical|fd-not-identical/, ""); + fdTableSort.disableSelection(workArr[c][i]); + aclone = null; + }; + }; + }; + + fdTableSort.tmpCache[tbl.id] = {cols:rowLength, headers:workArr}; + + workArr = null; + multi = 0; + + if("active" in columnNumSortObj) { + fdTableSort.tableId = tbl.id; + fdTableSort.prepareTableData(document.getElementById(fdTableSort.tableId)); + + delete columnNumSortObj["active"]; + + for(col in columnNumSortObj) { + obj = columnNumSortObj[col]; + if(!("thNode" in obj)) { continue; }; + fdTableSort.multi = true; + + len = obj.reverse ? 2 : 1; + + for(ii = 0; ii < len; ii++) { + fdTableSort.thNode = obj.thNode; + if(!showOnly) { + fdTableSort.initSort(false, true); + } else { + fdTableSort.addThNode(); + }; + }; + + if(showOnly) { + fdTableSort.removeClass(obj.thNode, "(forwardSort|reverseSort)"); + fdTableSort.addClass(obj.thNode, obj.reverse ? "reverseSort" : "forwardSort"); + if(showArrow) { + span = fdTableSort.thNode.getElementsByTagName('span')[0]; + if(span.firstChild) { span.removeChild(span.firstChild); }; + span.appendChild(document.createTextNode(len == 1 ? " \u2193" : " \u2191")); + }; + }; + }; + if(showOnly && (fdTableSort.tableCache[tbl.id].colStyle || fdTableSort.tableCache[tbl.id].rowStyle)) { + fdTableSort.redraw(tbl.id, false); + }; + } else if(tbl.className.search(/onload-zebra/) != -1) { + fdTableSort.tableId = tbl.id; + fdTableSort.prepareTableData(tbl); + if(fdTableSort.tableCache[tbl.id].rowStyle) { fdTableSort.redraw(tbl.id, false); }; + }; + }; + + fdTableSort.thNode = aclone = a = span = columnNumSortObj = thNode = tbl = allRowArr = rowArr = null; + }, + initWrapper: function(e) { + e = e || window.event; + var kc = e.type == "keydown" ? e.keyCode != null ? e.keyCode : e.charCode : -1; + if(fdTableSort.thNode == null && (e.type == "click" || kc == 13)) { + var targ = this; + while(targ.tagName.toLowerCase() != "th") { targ = targ.parentNode; }; + fdTableSort.thNode = targ; + while(targ.tagName.toLowerCase() != "table") { targ = targ.parentNode; }; + fdTableSort.tableId = targ.id; + fdTableSort.multi = e.shiftKey; + fdTableSort.addSortActiveClass(); + setTimeout(fdTableSort.initSort,5,false); + return fdTableSort.stopEvent(e); + }; + return kc != -1 ? true : fdTableSort.stopEvent(e); + }, + jsWrapper: function(tableid, colNums) { + if(!(tableid in fdTableSort.tmpCache)) { return false; }; + if(!(tableid in fdTableSort.tableCache)) { fdTableSort.prepareTableData(document.getElementById(tableid)); }; + if(!(colNums instanceof Array)) { colNums = [colNums]; }; + + fdTableSort.tableId = tableid; + var len = colNums.length, colNum; + + if(fdTableSort.tableCache[tableid].thList.length == colNums.length) { + var identical = true; + var th; + for(var i = 0; i < len; i++) { + colNum = colNums[i]; + th = fdTableSort.tmpCache[tableid].headers[0][colNum]; + if(th != fdTableSort.tableCache[tableid].thList[i]) { + identical = false; + break; + }; + }; + if(identical) { + fdTableSort.thNode = th; + fdTableSort.initSort(true); + return; + }; + }; + + fdTableSort.addSortActiveClass(); + + for(var i = 0; i < len; i++) { + fdTableSort.multi = i; + colNum = colNums[i]; + fdTableSort.thNode = fdTableSort.tmpCache[tableid].headers[0][colNum]; + fdTableSort.initSort(true); + }; + }, + addSortActiveClass: function() { + if(fdTableSort.thNode == null) { return; }; + fdTableSort.addClass(fdTableSort.thNode, fdTableSort.sortActiveClass); + fdTableSort.addClass(document.getElementsByTagName('body')[0], fdTableSort.sortActiveClass); + }, + removeSortActiveClass: function() { + if(fdTableSort.thNode == null) return; + fdTableSort.removeClass(fdTableSort.thNode, fdTableSort.sortActiveClass); + fdTableSort.removeClass(document.getElementsByTagName('body')[0], fdTableSort.sortActiveClass); + }, + doCallback: function(init) { + if(!fdTableSort.tableId || !(fdTableSort.tableId in fdTableSort.tableCache)) { return; }; + fdTableSort.callback(fdTableSort.tableId, init ? fdTableSort.tableCache[fdTableSort.tableId].initiatedCallback : fdTableSort.tableCache[fdTableSort.tableId].completeCallback); + }, + addClass: function(e,c) { + if(new RegExp("(^|\\s)" + c + "(\\s|$)").test(e.className)) { return; }; + e.className += ( e.className ? " " : "" ) + c; + }, + /*@cc_on + /*@if (@_win32) + removeClass: function(e,c) { + e.className = !c ? "" : e.className.replace(new RegExp("(^|\\s)" + c + "(\\s|$)"), " ").replace(/^\s*((?:[\S\s]*\S)?)\s*$/, '$1'); + }, + @else @*/ + removeClass: function(e,c) { + e.className = !c ? "" : e.className.replace(new RegExp("(^|\\s)" + c + "(\\s|$)"), " ").replace(/^\s\s*/, '').replace(/\s\s*$/, ''); + }, + /*@end + @*/ + callback: function(tblId, cb) { + var func, parts; + try { + if(cb.indexOf(".") != -1) { + parts = cb.split('.'); + obj = window; + for (var x = 0, part; part = obj[parts[x]]; x++) { + if(part instanceof Function) { + (function() { + var method = part; + func = function (data) { method.apply(obj, [data]) }; + })(); + } else { + obj = part; + }; + }; + } else if(cb + tblId in window) { + func = window[cb + tblId]; + } else if(cb in window) { + func = window[cb]; + } else { + func = null; + }; + } catch(err) {}; + + if(!(func instanceof Function)) return; + func(tblId, fdTableSort.tableCache[tblId].thList); + }, + prepareTableData: function(table) { + var data = []; + + var start = table.getElementsByTagName('tbody'); + start = start.length ? start[0] : table; + + var trs = start.rows; + var ths = table.getElementsByTagName('th'); + + var numberOfRows = trs.length; + var numberOfCols = fdTableSort.tmpCache[table.id].cols; + + var data = []; + var identical = new Array(numberOfCols); + var identVal = new Array(numberOfCols); + + for(var tmp = 0; tmp < numberOfCols; tmp++) identical[tmp] = true; + + var tr, td, th, txt, tds, col, row; + + var re = new RegExp(/fd-column-([0-9]+)/); + var rowCnt = 0; + + var sortableColumnNumbers = []; + + for(var tmp = 0, th; th = ths[tmp]; tmp++) { + if(th.className.search(re) == -1) continue; + sortableColumnNumbers[sortableColumnNumbers.length] = th; + }; + + for(row = 0; row < numberOfRows; row++) { + + tr = trs[row]; + if(tr.parentNode != start || tr.getElementsByTagName("th").length || (tr.parentNode && tr.parentNode.tagName.toLowerCase().search(/thead|tfoot/) != -1)) continue; + data[rowCnt] = []; + tds = tr.cells; + + for(var tmp = 0, th; th = sortableColumnNumbers[tmp]; tmp++) { + col = th.className.match(re)[1]; + + td = tds[col]; + txt = fdTableSort.getInnerText(td) + " "; + txt = txt.replace(/^\s+/,'').replace(/\s+$/,''); + + if(th.className.search(/sortable-date/) != -1) { + txt = fdTableSort.dateFormat(txt, th.className.search(/sortable-date-dmy/) != -1); + } else if(th.className.search(/sortable-numeric|sortable-currency/) != -1) { + txt = parseFloat(txt.replace(/[^0-9\.\-]/g,'')); + if(isNaN(txt)) txt = ""; + } else if(th.className.search(/sortable-text/) != -1) { + txt = txt.toLowerCase(); + } else if (th.className.search(/sortable-keep/) != -1) { + txt = rowCnt; + } else if(th.className.search(/sortable-([a-zA-Z\_]+)/) != -1) { + if((th.className.match(/sortable-([a-zA-Z\_]+)/)[1] + "PrepareData") in window) { + txt = window[th.className.match(/sortable-([a-zA-Z\_]+)/)[1] + "PrepareData"](td, txt); + }; + } else if(txt != "") { + fdTableSort.removeClass(th, "sortable"); + if(fdTableSort.dateFormat(txt) != 0) { + fdTableSort.addClass(th, "sortable-date"); + txt = fdTableSort.dateFormat(txt); + } else if(txt.search(fdTableSort.regExp_Number) != -1 || txt.search(fdTableSort.regExp_Currency) != -1) { + fdTableSort.addClass(th, "sortable-numeric"); + txt = parseFloat(txt.replace(/[^0-9\.\-]/g,'')); + if(isNaN(txt)) txt = ""; + } else { + fdTableSort.addClass(th, "sortable-text"); + txt = txt.toLowerCase(); + }; + }; + + if(rowCnt > 0 && identical[col] && identVal[col] != txt) { identical[col] = false; }; + + identVal[col] = txt; + data[rowCnt][col] = txt; + }; + data[rowCnt][numberOfCols] = tr; + rowCnt++; + }; + + var colStyle = table.className.search(/colstyle-([\S]+)/) != -1 ? table.className.match(/colstyle-([\S]+)/)[1] : false; + var rowStyle = table.className.search(/rowstyle-([\S]+)/) != -1 ? table.className.match(/rowstyle-([\S]+)/)[1] : false; + var iCBack = table.className.search(/sortinitiatedcallback-([\S-]+)/) == -1 ? "sortInitiatedCallback" : table.className.match(/sortinitiatedcallback-([\S]+)/)[1]; + var cCBack = table.className.search(/sortcompletecallback-([\S-]+)/) == -1 ? "sortCompleteCallback" : table.className.match(/sortcompletecallback-([\S]+)/)[1]; + iCBack = iCBack.replace("-", "."); + cCBack = cCBack.replace("-", "."); + fdTableSort.tableCache[table.id] = { hook:start, initiatedCallback:iCBack, completeCallback:cCBack, thList:[], colOrder:{}, data:data, identical:identical, colStyle:colStyle, rowStyle:rowStyle, noArrow:table.className.search(/no-arrow/) != -1 }; + sortableColumnNumbers = data = tr = td = th = trs = identical = identVal = null; + }, + onUnload: function() { + for(tbl in fdTableSort.tableCache) { fdTableSort.removeTableCache(tbl); }; + for(tbl in fdTableSort.tmpCache) { fdTableSort.removeTmpCache(tbl); }; + fdTableSort.removeEvent(window, "load", fdTableSort.initEvt); + fdTableSort.removeEvent(window, "unload", fdTableSort.onUnload); + fdTableSort.tmpCache = fdTableSort.tableCache = null; + }, + addThNode: function() { + var dataObj = fdTableSort.tableCache[fdTableSort.tableId]; + var pos = fdTableSort.thNode.className.match(/fd-column-([0-9]+)/)[1]; + var alt = false; + + if(!fdTableSort.multi) { + if(dataObj.colStyle) { + var len = dataObj.thList.length; + for(var i = 0; i < len; i++) { + dataObj.colOrder[dataObj.thList[i].className.match(/fd-column-([0-9]+)/)[1]] = false; + }; + }; + if(dataObj.thList.length && dataObj.thList[0] == fdTableSort.thNode) alt = true; + dataObj.thList = []; + }; + + var found = false; + var l = dataObj.thList.length; + + for(var i = 0, n; n = dataObj.thList[i]; i++) { + if(n == fdTableSort.thNode) { + found = true; + break; + }; + }; + + if(!found) { + dataObj.thList.push(fdTableSort.thNode); + if(dataObj.colStyle) { dataObj.colOrder[pos] = true; }; + }; + + var ths = document.getElementById(fdTableSort.tableId).getElementsByTagName("th"); + for(var i = 0, th; th = ths[i]; i++) { + found = false; + for(var z = 0, n; n = dataObj.thList[z]; z++) { + if(n == th) { + found = true; + break; + }; + }; + if(!found) { + fdTableSort.removeClass(th, "(forwardSort|reverseSort)"); + if(!dataObj.noArrow) { + span = th.getElementsByTagName('span'); + if(span.length) { + span = span[0]; + while(span.firstChild) span.removeChild(span.firstChild); + }; + }; + }; + }; + + if(dataObj.thList.length > 1) { + classToAdd = fdTableSort.thNode.className.search(/forwardSort/) != -1 ? "reverseSort" : "forwardSort"; + fdTableSort.removeClass(fdTableSort.thNode, "(forwardSort|reverseSort)"); + fdTableSort.addClass(fdTableSort.thNode, classToAdd); + dataObj.pos = -1 + } else if(alt) { dataObj.pos = fdTableSort.thNode }; + }, + initSort: function(noCallback, ident) { + var thNode = fdTableSort.thNode; + var tableElem = document.getElementById(fdTableSort.tableId); + + if(!(fdTableSort.tableId in fdTableSort.tableCache)) { fdTableSort.prepareTableData(document.getElementById(fdTableSort.tableId)); }; + + fdTableSort.addThNode(); + + if(!noCallback) { fdTableSort.doCallback(true); }; + + fdTableSort.pos = thNode.className.match(/fd-column-([0-9]+)/)[1]; + var dataObj = fdTableSort.tableCache[tableElem.id]; + var lastPos = dataObj.pos && dataObj.pos.className ? dataObj.pos.className.match(/fd-column-([0-9]+)/)[1] : -1; + var len1 = dataObj.data.length; + var len2 = dataObj.data.length > 0 ? dataObj.data[0].length - 1 : 0; + var identical = dataObj.identical[fdTableSort.pos]; + var classToAdd = "forwardSort"; + + if(dataObj.thList.length > 1) { + var js = "var sortWrapper = function(a,b) {\n"; + var l = dataObj.thList.length; + var cnt = 0; + var e,d,th,p,f; + + for(var i=0; i < l; i++) { + th = dataObj.thList[i]; + p = th.className.match(/fd-column-([0-9]+)/)[1]; + if(dataObj.identical[p]) { continue; }; + cnt++; + + if(th.className.match(/sortable-(numeric|currency|date|keep)/)) { + f = "fdTableSort.sortNumeric"; + } else if(th.className.match('sortable-text')) { + f = "fdTableSort.sortText"; + } else if(th.className.search(/sortable-([a-zA-Z\_]+)/) != -1 && th.className.match(/sortable-([a-zA-Z\_]+)/)[1] in window) { + f = "window['" + th.className.match(/sortable-([a-zA-Z\_]+)/)[1] + "']"; + } else f = "fdTableSort.sortText"; + + e = "e" + i; + d = th.className.search('forwardSort') != -1 ? "a,b" : "b,a"; + js += "fdTableSort.pos = " + p + ";\n"; + js += "var " + e + " = "+f+"(" + d +");\n"; + js += "if(" + e + ") return " + e + ";\n"; + js += "else { \n"; + }; + + js += "return 0;\n"; + + for(var i=0; i < cnt; i++) { + js += "};\n"; + }; + + if(cnt) js += "return 0;\n"; + js += "};\n"; + + eval(js); + dataObj.data.sort(sortWrapper); + identical = false; + } else if((lastPos == fdTableSort.pos && !identical) || (thNode.className.search(/sortable-keep/) != -1 && lastPos == -1)) { + dataObj.data.reverse(); + classToAdd = thNode.className.search(/reverseSort/) != -1 ? "forwardSort" : "reverseSort"; + if(thNode.className.search(/sortable-keep/) != -1 && lastPos == -1) fdTableSort.tableCache[tableElem.id].pos = thNode; + } else { + fdTableSort.tableCache[tableElem.id].pos = thNode; + classToAdd = thNode.className.search(/forwardSort/) != -1 ? "reverseSort" : "forwardSort"; + if(!identical) { + if(thNode.className.match(/sortable-(numeric|currency|date|keep)/)) { + dataObj.data.sort(fdTableSort.sortNumeric); + } else if(thNode.className.match('sortable-text')) { + dataObj.data.sort(fdTableSort.sortText); + } else if(thNode.className.search(/sortable-([a-zA-Z\_]+)/) != -1 && thNode.className.match(/sortable-([a-zA-Z\_]+)/)[1] in window) { + dataObj.data.sort(window[thNode.className.match(/sortable-([a-zA-Z\_]+)/)[1]]); + }; + + if(thNode.className.search(/(^|\s)favour-reverse($|\s)/) != -1) { + classToAdd = classToAdd == "forwardSort" ? "reverseSort" : "forwardSort"; + dataObj.data.reverse(); + }; + }; + }; + if(ident) { identical = false; }; + if(dataObj.thList.length == 1) { + fdTableSort.removeClass(thNode, "(forwardSort|reverseSort)"); + fdTableSort.addClass(thNode, classToAdd); + }; + if(!dataObj.noArrow) { + var span = fdTableSort.thNode.getElementsByTagName('span')[0]; + if(span.firstChild) span.removeChild(span.firstChild); + span.appendChild(document.createTextNode(fdTableSort.thNode.className.search(/forwardSort/) != -1 ? " \u2193" : " \u2191")); + }; + if(!dataObj.rowStyle && !dataObj.colStyle && identical) { + fdTableSort.removeSortActiveClass(); + if(!noCallback) { fdTableSort.doCallback(false); }; + fdTableSort.thNode = null; + return; + }; + if("tablePaginater" in window && tablePaginater.tableIsPaginated(fdTableSort.tableId)) { + tablePaginater.redraw(fdTableSort.tableId, identical); + } else { + fdTableSort.redraw(fdTableSort.tableId, identical); + }; + fdTableSort.removeSortActiveClass(); + if(!noCallback) { fdTableSort.doCallback(false); }; + fdTableSort.thNode = null; + }, + redraw: function(tableid, identical) { + if(!tableid || !(tableid in fdTableSort.tableCache)) { return; }; + var dataObj = fdTableSort.tableCache[tableid]; + var data = dataObj.data; + var len1 = data.length; + var len2 = len1 ? data[0].length - 1 : 0; + var hook = dataObj.hook; + var colStyle = dataObj.colStyle; + var rowStyle = dataObj.rowStyle; + var colOrder = dataObj.colOrder; + var highLight = 0; + var reg = /(^|\s)invisibleRow(\s|$)/; + var tr, tds; + + for(var i = 0; i < len1; i++) { + tr = data[i][len2]; + if(colStyle) { + tds = tr.cells; + for(thPos in colOrder) { + if(!colOrder[thPos]) fdTableSort.removeClass(tds[thPos], colStyle); + else fdTableSort.addClass(tds[thPos], colStyle); + }; + }; + if(!identical) { + if(rowStyle && tr.className.search(reg) == -1) { + if(highLight++ & 1) fdTableSort.addClass(tr, rowStyle); + else fdTableSort.removeClass(tr, rowStyle); + }; + + // Netscape 8.1.2 requires the removeChild call or it freaks out, so add the line if you want to support this browser + // hook.removeChild(tr); + hook.appendChild(tr); + }; + }; + tr = tds = hook = null; + }, + getInnerText: function(el, allowBrTags) { + if (typeof el == "string" || typeof el == "undefined") return el; + if(el.innerText) return el.innerText; + var txt = '', i; + for(i = el.firstChild; i; i = i.nextSibling) { + if(allowBrTags && i.nodeName && i.nodeName == "BR") txt += "
        "; + else if(i.nodeType == 3) txt += i.nodeValue; + else if(i.nodeType == 1) txt += fdTableSort.getInnerText(i); + }; + return txt; + }, + dateFormat: function(dateIn, favourDMY) { + var dateTest = [ + { regExp:/^(0?[1-9]|1[012])([- \/.])(0?[1-9]|[12][0-9]|3[01])([- \/.])((\d\d)?\d\d)$/, d:3, m:1, y:5 }, // mdy + { regExp:/^(0?[1-9]|[12][0-9]|3[01])([- \/.])(0?[1-9]|1[012])([- \/.])((\d\d)?\d\d)$/, d:1, m:3, y:5 }, // dmy + { regExp:/^(\d\d\d\d)([- \/.])(0?[1-9]|1[012])([- \/.])(0?[1-9]|[12][0-9]|3[01])$/, d:5, m:3, y:1 } // ymd + ]; + var start, cnt = 0, numFormats = dateTest.length; + while(cnt < numFormats) { + start = (cnt + (favourDMY ? numFormats + 1 : numFormats)) % numFormats; + if(dateIn.match(dateTest[start].regExp)) { + res = dateIn.match(dateTest[start].regExp); + y = res[dateTest[start].y]; + m = res[dateTest[start].m]; + d = res[dateTest[start].d]; + if(m.length == 1) m = "0" + String(m); + if(d.length == 1) d = "0" + String(d); + if(y.length != 4) y = (parseInt(y) < 50) ? "20" + String(y) : "19" + String(y); + + return y+String(m)+d; + }; + cnt++; + }; + return 0; + }, + sortNumeric:function(a,b) { + var aa = a[fdTableSort.pos]; + var bb = b[fdTableSort.pos]; + if(aa == bb) return 0; + if(aa === "" && !isNaN(bb)) return -1; + if(bb === "" && !isNaN(aa)) return 1; + return aa - bb; + }, + sortText:function(a,b) { + var aa = a[fdTableSort.pos]; + var bb = b[fdTableSort.pos]; + if(aa == bb) return 0; + if(aa < bb) return -1; + return 1; + } +}; +})(); +fdTableSort.addEvent(window, "load", fdTableSort.initEvt); fdTableSort.addEvent(window, "unload", fdTableSort.onUnload); \ No newline at end of file diff --git a/admin/search.php b/admin/search.php index 51ee0e2..ecb8d3e 100644 --- a/admin/search.php +++ b/admin/search.php @@ -1,206 +1,206 @@ -getSection('SearchAIMLForm'); - $mainContent .= runSearch(); - } - elseif((isset($_POST['action']))&&($_POST['action']=="update")) { - $mainContent = $template->getSection('SearchAIMLForm'); - $mainContent .= updateAIML(); - } - elseif((isset($_GET['action']))&&($_GET['action']=="del")&&(isset($_GET['id']))&&($_GET['id']!="")) { - $mainContent = $template->getSection('SearchAIMLForm'); - $mainContent .= delAIML($_GET['id']); - } - elseif((isset($_GET['action']))&&($_GET['action']=="edit")&&(isset($_GET['id']))&&($_GET['id']!="")) { - $mainContent = $template->getSection('SearchAIMLForm'); - $mainContent .= editAIMLForm($_GET['id']); - } - else { - $mainContent = $template->getSection('SearchAIMLForm'); - } - - $upperScripts = ''."\n"; - $topNav = $template->getSection('TopNav'); - $leftNav = $template->getSection('LeftNav'); - $main = $template->getSection('Main'); - $topNavLinks = makeLinks('top', $topLinks, 12); - $navHeader = $template->getSection('NavHeader'); - $leftNavLinks = makeLinks('left', $leftLinks, 12); - $FooterInfo = getFooter(); - $errMsgClass = (!empty($msg)) ? "ShowError" : "HideError"; - $errMsgStyle = $template->getSection($errMsgClass); - $noLeftNav = ''; - $noTopNav = ''; - $noRightNav = $template->getSection('NoRightNav'); - $headerTitle = 'Actions:'; - $pageTitle = 'My-Program O - Search/Edit AIML'; - #$mainContent = 'This will eventually be the page for searching and/or editing AIML categories.'; - $mainTitle = 'Search/Edit AIML'; - - function delAIML($id) { - - $dbconn = db_open(); - if($id!="") { - $sql = "DELETE FROM `aiml` WHERE `id` = '$id' LIMIT 1"; - $result = mysql_query($sql,$dbconn) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); - if(!$result) { - $msg = 'Error AIML couldn\'t be deleted - no changes made.'; - } - else { - $msg = 'AIML has been deleted.'; - } - } - else { - $msg = 'Error AIML couldn\'t be deleted - no changes made.'; - } - mysql_close($dbconn); - return $msg; - } - - - function runSearch() { - global $bot_id, $bot_name; - $dbconn = db_open(); - $i=0; - $searchTermsTemplate = " like '[value]' or\n "; - $searchTerms = ''; - $search_topic = mysql_escape_string(trim($_POST['search_topic'])); - $search_filename = mysql_escape_string(trim($_POST['search_filename'])); - $search_pattern = mysql_escape_string(trim($_POST['search_pattern'])); - $search_template = mysql_escape_string(trim($_POST['search_template'])); - $search_that = mysql_escape_string(trim($_POST['search_that'])); - if(!empty($search_topic) or !empty($search_filename) or !empty($search_pattern) or !empty($search_template) or !empty($search_that)) { - $sql = "SELECT * FROM `aiml` WHERE `bot_id` = '$bot_id' AND (\n [searchTerms]\n) LIMIT 50;"; - $searchTerms .= (!empty($search_topic)) ? '`topic`' . str_replace('[value]', $search_topic, $searchTermsTemplate) : ''; - $searchTerms .= (!empty($search_filename)) ? '`filename`' . str_replace('[value]', $search_filename, $searchTermsTemplate) : ''; - $searchTerms .= (!empty($search_pattern)) ? '`pattern`' . str_replace('[value]', $search_pattern, $searchTermsTemplate) : ''; - $searchTerms .= (!empty($search_template)) ? '`template`' . str_replace('[value]', $search_template, $searchTermsTemplate) : ''; - $searchTerms .= (!empty($search_that)) ? '`thatpattern`' . str_replace('[value]', $search_that, $searchTermsTemplate) : ''; - $searchTerms = rtrim($searchTerms, " or\n "); - $sql = str_replace('[searchTerms]', $searchTerms, $sql); - #die ("SQL =
        \n$sql\n
        \n"); - $result = mysql_query($sql,$dbconn) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); - $htmltbl = << - - - Topic - Previous Bot Response - User Input - Bot Response - Filename - Action - - - -endtHead; - while($row=mysql_fetch_array($result)) { - $i++; - $topic = $row['topic']; - $pattern = $row['pattern']; - $thatpattern = $row['thatpattern']; - $template = htmlentities($row['template']); - $filename = $row['filename']; - $id = $row['id']; - $action = << - - - - - -endLink; - - $htmltbl .= << - $topic - $thatpattern - $pattern - $template - $filename - $action - -endRow; - } - mysql_close($dbconn); - $htmltbl .= " \n "; - if($i == 50) { - $msg = "Found more than 50 results for your specified search terms. please refine your search further"; - } - elseif($i == 0) { - $msg = "Found 0 results for your specified search terms. please try again"; - $htmltbl=""; - } - else { - $msg = "Found $i results for your specified search terms."; - } - $htmlresults = "
        $msg
        ".$htmltbl; - } - else { - $htmlresults = 'Please enter a search term in any one of the available search boxes.'; - } - return $htmlresults; - } - - - function editAIMLForm($id) { - //db globals - global $template; - $dbconn = db_open(); - $sql = "SELECT * FROM `aiml` WHERE `id` = '$id' LIMIT 1"; - $result = mysql_query($sql,$dbconn) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); - $row=mysql_fetch_array($result); - $topic = $row['topic']; - $pattern = $row['pattern']; - $thatpattern = $row['thatpattern']; - $row_template = htmlentities($row['template']); - $filename = $row['filename']; - $id = $row['id']; - $form = $template->getSection('EditAIMLForm'); - $form = str_replace('[id]', $id, $form); - $form = str_replace('[topic]', $topic, $form); - $form = str_replace('[pattern]', $pattern, $form); - $form = str_replace('[thatpattern]', $thatpattern, $form); - $form = str_replace('[template]', $row_template, $form); - $form = str_replace('[filename]', $filename, $form); - mysql_close($dbconn); - return $form; - } - - function updateAIML() { - //db globals - $dbconn = db_open(); - $template = mysql_escape_string(trim($_POST['template'])); - $filename = mysql_escape_string(trim($_POST['filename'])); - $pattern = strtoupper(mysql_escape_string(trim($_POST['pattern']))); - $thatpattern = strtoupper(mysql_escape_string(trim($_POST['thatpattern']))); - $topic = strtoupper(mysql_escape_string(trim($_POST['topic']))); - $id = trim($_POST['id']); - if(($template == "")||($pattern== "")||($id=="")) { - $msg = 'Please make sure you have entered a user input and bot response '; - } - else { - $sql = "UPDATE `aiml` SET `pattern` = '$pattern',`thatpattern`='$thatpattern',`template`='$template',`topic`='$topic',`filename`='$filename' WHERE `id`='$id' LIMIT 1"; - $result = mysql_query($sql,$dbconn) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); - if($result) { - $msg = 'AIML Updated.'; - } - else { - $msg = 'There was an error updating the AIML - no changes made.'; - } - } - mysql_close($dbconn); - return $msg; - } - +getSection('SearchAIMLForm'); + $mainContent .= runSearch(); + } + elseif((isset($_POST['action']))&&($_POST['action']=="update")) { + $mainContent = $template->getSection('SearchAIMLForm'); + $mainContent .= updateAIML(); + } + elseif((isset($_GET['action']))&&($_GET['action']=="del")&&(isset($_GET['id']))&&($_GET['id']!="")) { + $mainContent = $template->getSection('SearchAIMLForm'); + $mainContent .= delAIML($_GET['id']); + } + elseif((isset($_GET['action']))&&($_GET['action']=="edit")&&(isset($_GET['id']))&&($_GET['id']!="")) { + $mainContent = $template->getSection('SearchAIMLForm'); + $mainContent .= editAIMLForm($_GET['id']); + } + else { + $mainContent = $template->getSection('SearchAIMLForm'); + } + + $upperScripts = ''."\n"; + $topNav = $template->getSection('TopNav'); + $leftNav = $template->getSection('LeftNav'); + $main = $template->getSection('Main'); + $topNavLinks = makeLinks('top', $topLinks, 12); + $navHeader = $template->getSection('NavHeader'); + $leftNavLinks = makeLinks('left', $leftLinks, 12); + $FooterInfo = getFooter(); + $errMsgClass = (!empty($msg)) ? "ShowError" : "HideError"; + $errMsgStyle = $template->getSection($errMsgClass); + $noLeftNav = ''; + $noTopNav = ''; + $noRightNav = $template->getSection('NoRightNav'); + $headerTitle = 'Actions:'; + $pageTitle = 'My-Program O - Search/Edit AIML'; + #$mainContent = 'This will eventually be the page for searching and/or editing AIML categories.'; + $mainTitle = 'Search/Edit AIML'; + + function delAIML($id) { + + $dbconn = db_open(); + if($id!="") { + $sql = "DELETE FROM `aiml` WHERE `id` = '$id' LIMIT 1"; + $result = mysql_query($sql,$dbconn) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); + if(!$result) { + $msg = 'Error AIML couldn\'t be deleted - no changes made.'; + } + else { + $msg = 'AIML has been deleted.'; + } + } + else { + $msg = 'Error AIML couldn\'t be deleted - no changes made.'; + } + mysql_close($dbconn); + return $msg; + } + + + function runSearch() { + global $bot_id, $bot_name; + $dbconn = db_open(); + $i=0; + $searchTermsTemplate = " like '[value]' or\n "; + $searchTerms = ''; + $search_topic = mysql_real_escape_string(trim($_POST['search_topic'])); + $search_filename = mysql_real_escape_string(trim($_POST['search_filename'])); + $search_pattern = mysql_real_escape_string(trim($_POST['search_pattern'])); + $search_template = mysql_real_escape_string(trim($_POST['search_template'])); + $search_that = mysql_real_escape_string(trim($_POST['search_that'])); + if(!empty($search_topic) or !empty($search_filename) or !empty($search_pattern) or !empty($search_template) or !empty($search_that)) { + $sql = "SELECT * FROM `aiml` WHERE `bot_id` = '$bot_id' AND (\n [searchTerms]\n) LIMIT 50;"; + $searchTerms .= (!empty($search_topic)) ? '`topic`' . str_replace('[value]', $search_topic, $searchTermsTemplate) : ''; + $searchTerms .= (!empty($search_filename)) ? '`filename`' . str_replace('[value]', $search_filename, $searchTermsTemplate) : ''; + $searchTerms .= (!empty($search_pattern)) ? '`pattern`' . str_replace('[value]', $search_pattern, $searchTermsTemplate) : ''; + $searchTerms .= (!empty($search_template)) ? '`template`' . str_replace('[value]', $search_template, $searchTermsTemplate) : ''; + $searchTerms .= (!empty($search_that)) ? '`thatpattern`' . str_replace('[value]', $search_that, $searchTermsTemplate) : ''; + $searchTerms = rtrim($searchTerms, " or\n "); + $sql = str_replace('[searchTerms]', $searchTerms, $sql); + #die ("SQL =
        \n$sql\n
        \n"); + $result = mysql_query($sql,$dbconn) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); + $htmltbl = << + + + Topic + Previous Bot Response + User Input + Bot Response + Filename + Action + + + +endtHead; + while($row=mysql_fetch_array($result)) { + $i++; + $topic = $row['topic']; + $pattern = $row['pattern']; + $thatpattern = $row['thatpattern']; + $template = htmlentities($row['template']); + $filename = $row['filename']; + $id = $row['id']; + $action = << + Edit this entry + + + Delete this entry + +endLink; + + $htmltbl .= << + $topic + $thatpattern + $pattern + $template + $filename + $action + +endRow; + } + mysql_close($dbconn); + $htmltbl .= " \n "; + if($i == 50) { + $msg = "Found more than 50 results for your specified search terms. please refine your search further"; + } + elseif($i == 0) { + $msg = "Found 0 results for your specified search terms. please try again"; + $htmltbl=""; + } + else { + $msg = "Found $i results for your specified search terms."; + } + $htmlresults = "
        $msg
        ".$htmltbl; + } + else { + $htmlresults = 'Please enter a search term in any one of the available search boxes.'; + } + return $htmlresults; + } + + + function editAIMLForm($id) { + //db globals + global $template; + $dbconn = db_open(); + $sql = "SELECT * FROM `aiml` WHERE `id` = '$id' LIMIT 1"; + $result = mysql_query($sql,$dbconn) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); + $row=mysql_fetch_array($result); + $topic = $row['topic']; + $pattern = $row['pattern']; + $thatpattern = $row['thatpattern']; + $row_template = htmlentities($row['template']); + $filename = $row['filename']; + $id = $row['id']; + $form = $template->getSection('EditAIMLForm'); + $form = str_replace('[id]', $id, $form); + $form = str_replace('[topic]', $topic, $form); + $form = str_replace('[pattern]', $pattern, $form); + $form = str_replace('[thatpattern]', $thatpattern, $form); + $form = str_replace('[template]', $row_template, $form); + $form = str_replace('[filename]', $filename, $form); + mysql_close($dbconn); + return $form; + } + + function updateAIML() { + //db globals + $dbconn = db_open(); + $template = mysql_real_escape_string(trim($_POST['template'])); + $filename = mysql_real_escape_string(trim($_POST['filename'])); + $pattern = strtoupper(mysql_real_escape_string(trim($_POST['pattern']))); + $thatpattern = strtoupper(mysql_real_escape_string(trim($_POST['thatpattern']))); + $topic = strtoupper(mysql_real_escape_string(trim($_POST['topic']))); + $id = trim($_POST['id']); + if(($template == "")||($pattern== "")||($id=="")) { + $msg = 'Please make sure you have entered a user input and bot response '; + } + else { + $sql = "UPDATE `aiml` SET `pattern` = '$pattern',`thatpattern`='$thatpattern',`template`='$template',`topic`='$topic',`filename`='$filename' WHERE `id`='$id' LIMIT 1"; + $result = mysql_query($sql,$dbconn) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); + if($result) { + $msg = 'AIML Updated.'; + } + else { + $msg = 'There was an error updating the AIML - no changes made.'; + } + } + mysql_close($dbconn); + return $msg; + } + ?> \ No newline at end of file diff --git a/admin/select_bots.php b/admin/select_bots.php index d05b68b..14ec46f 100644 --- a/admin/select_bots.php +++ b/admin/select_bots.php @@ -1,385 +1,437 @@ -getSection('TopNav'); - $leftNav = $template->getSection('LeftNav'); - $main = $template->getSection('Main'); - $topNavLinks = makeLinks('top', $topLinks, 12); - $navHeader = $template->getSection('NavHeader'); - $leftNavLinks = makeLinks('left', $leftLinks, 12); - $FooterInfo = getFooter(); - $errMsgClass = (!empty($msg)) ? "ShowError" : "HideError"; - $errMsgStyle = $template->getSection($errMsgClass); - $noLeftNav = ''; - $noTopNav = ''; - $noRightNav = $template->getSection('NoRightNav'); - $headerTitle = 'Actions:'; - $pageTitle = 'My-Program O - Select or Edit a Bot'; - $mainContent = $selectBot; - $mainTitle = 'Choose/Edit a Bot'; - - function replaceTags(&$selectBot) { - - } - -function getBotParentList($current_parent,$dbconn) { - //db globals - $dbconn = db_open(); - //get active bots from the db - if(empty($current_parent)) $current_parent = 0; - $sql = "SELECT * FROM `bots` where bot_active = '1'"; - $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . '.');; - - $options = ' '; - - while($row = mysql_fetch_array($result)) { - if($current_parent==$row['bot_id']) { - $sel = "SELECTED=SELECTED"; - } - else { - $sel = ""; - } - $options .= ' '; - } - - return $options; -} - - -function getSelectedBot() { - global $template; - $dbconn = db_open(); - $inputs=""; - $form = $template->getSection('SelectBotForm'); - $sel_session = ""; - $sel_db = ""; - $sel_html = ""; - $sel_xml = ""; - $sel_json = ""; - $sel_yes = ""; - $sel_no = ""; - $sel_fyes = ""; - $sel_fno = ""; - $ds_ = ""; - $ds_i = ""; - $ds_ii = ""; - $ds_iii = ""; - $dm_ = ""; - $dm_i = ""; - $dm_ii = ""; - $dm_iii = ""; - if($_SESSION['poadmin']['bot_id']!="new") { - $bot_id = $_SESSION['poadmin']['bot_id']; - //get data for all of the bots from the db - $sql = "SELECT * FROM `bots` where bot_id = '$bot_id';"; - $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . '.'); - while($row = mysql_fetch_assoc($result)) { - foreach ($row as $key => $value) { - if (strstr($key,'bot_') != false){ - $tmp = ''; - $$key = $value; - } - else { - $tmp = "bot_$key"; - $$tmp = $value; - } - } - if($bot_active=="1") { - $sel_yes = " SELECTED=SELECTED"; - } - else { - $sel_no = " SELECTED=SELECTED"; - } - if($bot_save_state=="database") { - $sel_db = " SELECTED=SELECTED"; - } - else { - $sel_session = " SELECTED=SELECTED"; - } - if($bot_format=="html") { - $sel_html = " SELECTED=SELECTED"; - } - elseif($bot_format=="xml") { - $sel_xml = " SELECTED=SELECTED"; - } - elseif($bot_format=="json") { - $sel_json = " SELECTED=SELECTED"; - } - if($bot_update_aiml_code=="1") { - $sel_fyes = " SELECTED=SELECTED"; - } - elseif($bot_update_aiml_code=="0") { - $sel_fno = " SELECTED=SELECTED"; - } - if($bot_debugshow=="0") { - $ds_ = " SELECTED=SELECTED"; - } - elseif($bot_debugshow=="1") { - $ds_i = " SELECTED=SELECTED"; - } - elseif($bot_debugshow=="2") { - $ds_ii = " SELECTED=SELECTED"; - } - elseif($bot_debugshow=="3") { - $ds_iii = " SELECTED=SELECTED"; - } - if($bot_debugmode=="0") { - $dm_ = " SELECTED=SELECTED"; - } - elseif($bot_debugshow=="1") { - $dm_i = " SELECTED=SELECTED"; - } - elseif($bot_debugshow=="2") { - $dm_ii = " SELECTED=SELECTED"; - } - elseif($bot_debugshow=="3") { - $dm_iii = " SELECTED=SELECTED"; - } - $action = "update"; - } - mysql_close($dbconn); - } - else { - $bot_id = ""; - $bot_parent_id = 0; - $bot_name = ""; - $bot_desc = ""; - $bot_active = ""; - $action = "add"; - $bot_format = ""; - $bot_update_aiml_code = ""; - $bot_conversation_lines = ""; - $bot_remember_up_to = ""; - $bot_debugemail = ""; - $bot_debugshow = ""; - $bot_debugmode = ""; - } - $parent_options = getBotParentList($bot_parent_id,$dbconn); - $searches = array( - '[bot_id]','[bot_name]','[bot_desc]','[parent_options]','[sel_yes]','[sel_no]', - '[sel_html]','[sel_xml]','[sel_json]','[sel_session]','[sel_db]','[sel_fyes]', - '[sel_fno]','[bot_conversation_lines]','[bot_remember_up_to]','[bot_debugemail]', - '[dm_]','[dm_i]','[dm_ii]','[dm_iii]','[ds_]','[ds_i]','[ds_ii]','[ds_iii]','[action]' - ); - foreach ($searches as $search) { - $replace = str_replace('[', '', $search); - $replace = str_replace(']', '', $replace); - $form = str_replace($search, $$replace, $form); - } - return $form; -} - -function updateBotSelection() { - //db globals - global $msg; - $dbconn = db_open(); - $sql = ""; - $msg = ""; - foreach($_POST as $key => $value) { - if(($key!="bot_id")||($key!="action")) { - $value = mysql_escape_string(trim(stripslashes($value))); - if(($key != "bot_id")&&($key != "action")&&($value!="")) { - $sql = "UPDATE `bots` SET `$key` ='$value' where `bot_id` = '".$_POST['bot_id']."' limit 1; "; - $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . '.'); - if(!$result) { - $msg = 'Error updating bot details.'; - break; - } - } - } - } - if($msg == "") { - $msg = 'Bot details updated.'; - } - - mysql_close($dbconn); - return $msg; - -} - - -function addBot() { - //db globals - global $msg; - foreach ($_POST as $key => $value) { - $$key = mysql_escape_string(trim($value)); - } - $dbconn = db_open(); - $sql = <<0) { - $row=mysql_fetch_array($result); - $_SESSION['poadmin']['bot_id']=$row['bot_id']; - $_SESSION['poadmin']['bot_name']=$row['bot_name']; - } - else { - $_SESSION['poadmin']['bot_id']="new"; - $_SESSION['poadmin']['bot_name']=""; - } - } - else { - $_SESSION['poadmin']['bot_name']=""; - $_SESSION['poadmin']['bot_id']="new"; - } - mysql_close($dbconn); -} - - -function getChangeList() { - //db globals - global $template; - $dbconn = db_open(); - $inputs=""; - //get bot names from the db - $sql = "SELECT * FROM `bots` ORDER BY bot_name"; - $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . '.'); - $options = '' . "\n"; - while($row = mysql_fetch_array($result)) { - if($_SESSION['poadmin']['bot_id']==$row['bot_id']) { - $sel = " SELECTED=SELECTED"; - } - else { - $sel= ""; - } - $bot_id = $row['bot_id']; - $bot_name = $row['bot_name']; - $options .= " \n"; - } - $options = rtrim($options); - mysql_close($dbconn); - $form = $template->getSection('ChangeBot'); - $form = str_replace('[options]', $options, $form); - return $form; -} - +getSection('TopNav'); + $leftNav = $template->getSection('LeftNav'); + $main = $template->getSection('Main'); + $topNavLinks = makeLinks('top', $topLinks, 12); + $navHeader = $template->getSection('NavHeader'); + $leftNavLinks = makeLinks('left', $leftLinks, 12); + $FooterInfo = getFooter(); + $errMsgClass = (!empty($msg)) ? "ShowError" : "HideError"; + $errMsgStyle = $template->getSection($errMsgClass); + $noLeftNav = ''; + $noTopNav = ''; + $noRightNav = $template->getSection('NoRightNav'); + $headerTitle = 'Actions:'; + $pageTitle = 'My-Program O - Select or Edit a Bot'; + $mainContent = $selectBot; + $mainTitle = 'Choose/Edit a Bot'; + + function replaceTags(&$selectBot) { + + } + +function getBotParentList($current_parent,$dbconn) { + //db globals + $dbconn = db_open(); + //get active bots from the db + if(empty($current_parent)) $current_parent = 0; + $sql = "SELECT * FROM `bots` where bot_active = '1'"; + $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . '.');; + + $options = ' '; + + while($row = mysql_fetch_array($result)) { + if ($row['bot_id'] == 0) $options = str_replace('[noBot]', 'selected="selected"', $options); + if($current_parent==$row['bot_id']) { + $sel = "selected=\"selected\""; + } + else { + $sel = ""; + } + $options .= ' '; + } + $options = str_replace('[noBot]', 'selected="selected"', $options); + + return $options; +} + + +function getSelectedBot() { + global $template, $default_pattern, $default_remember_up_to, $default_conversation_lines, $default_error_response; + $bot_conversation_lines = $default_conversation_lines; + $bot_remember_up_to = $default_remember_up_to; + $bot_default_aiml_pattern = $default_pattern; + $bot_error_response = $default_error_response; + $dbconn = db_open(); + $inputs=""; + $form = $template->getSection('SelectBotForm'); + $sel_session = ""; + $sel_db = ""; + $sel_html = ""; + $sel_xml = ""; + $sel_json = ""; + $sel_yes = ""; + $sel_no = ""; + $sel_fyes = ""; + $sel_fno = ""; + $sel_fuyes = ""; + $sel_funo = ""; + $ds_ = ""; + $ds_i = ""; + $ds_ii = ""; + $ds_iii = ""; + $ds_iv = ""; + $dm_ = ""; + $dm_i = ""; + $dm_ii = ""; + $dm_iii = ""; + $dm_iv = ""; + if($_SESSION['poadmin']['bot_id']!="new") { + $bot_id = $_SESSION['poadmin']['bot_id']; + //get data for all of the bots from the db + $sql = "SELECT * FROM `bots` where bot_id = '$bot_id';"; + $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . '.'); + while($row = mysql_fetch_assoc($result)) { + foreach ($row as $key => $value) { + if (strstr($key,'bot_') != false){ + $tmp = ''; + $$key = $value; + } + else { + $tmp = "bot_$key"; + $$tmp = $value; + } + } + if($bot_active=="1") { + $sel_yes = ' selected="selected"'; + } + else { + $sel_no = ' selected="selected"'; + } + if($bot_save_state=="database") { + $sel_db = ' selected="selected"'; + } + else { + $sel_session = ' selected="selected"'; + } + if($bot_format=="html") { + $sel_html = ' selected="selected"'; + } + elseif($bot_format=="xml") { + $sel_xml = ' selected="selected"'; + } + elseif($bot_format=="json") { + $sel_json = ' selected="selected"'; + } + if($bot_use_aiml_code=="1") { + $sel_fuyes = ' selected="selected"'; + } + elseif($bot_use_aiml_code=="0") { + $sel_funo = ' selected="selected"'; + } + if($bot_update_aiml_code=="1") { + $sel_fyes = ' selected="selected"'; + } + elseif($bot_update_aiml_code=="0") { + $sel_fno = ' selected="selected"'; + } + if($bot_debugshow=="0") { + $ds_ = ' selected="selected"'; + } + elseif($bot_debugshow=="1") { + $ds_i = ' selected="selected"'; + } + elseif($bot_debugshow=="2") { + $ds_ii = ' selected="selected"'; + } + elseif($bot_debugshow=="3") { + $ds_iii = ' selected="selected"'; + } + elseif($bot_debugshow=="4") { + $ds_iv = ' selected="selected"'; + } + if($bot_debugmode=="0") { + $dm_ = ' selected="selected"'; + } + elseif($bot_debugmode=="1") { + $dm_i = ' selected="selected"'; + } + elseif($bot_debugmode=="2") { + $dm_ii = ' selected="selected"'; + } + elseif($bot_debugmode=="3") { + $dm_iii = ' selected="selected"'; + } + elseif($bot_debugmode=="4") { + $dm_iv = ' selected="selected"'; + } + $action = "update"; + } + mysql_close($dbconn); + } + else { + $bot_id = ""; + $bot_parent_id = 0; + $bot_name = ""; + $bot_desc = ""; + $bot_active = ""; + $action = "add"; + $bot_format = ""; + $bot_use_aiml_code = ""; + $bot_update_aiml_code = ""; + $bot_conversation_lines = $default_conversation_lines; + $bot_remember_up_to = $default_remember_up_to; + $bot_default_aiml_pattern = $default_pattern; + $bot_error_response = $default_error_response; + $bot_debugemail = ""; + $debugemail = ""; + $bot_debugshow = ""; + $bot_debugmode = ""; + + } + $parent_options = getBotParentList($bot_parent_id,$dbconn); + $searches = array( + '[bot_id]','[bot_name]','[bot_desc]','[parent_options]','[sel_yes]','[sel_no]', + '[sel_html]','[sel_xml]','[sel_json]','[sel_session]','[sel_db]','[sel_fyes]', + '[sel_fno]','[sel_fuyes]','[sel_funo]','[bot_conversation_lines]','[bot_remember_up_to]', + '[bot_debugemail]','[dm_]','[dm_i]','[dm_ii]','[dm_iii]','[ds_]','[ds_i]','[ds_ii]', + '[ds_iii]','[ds_iv]','[action]', '[bot_default_aiml_pattern]', '[bot_error_response]', + ); + foreach ($searches as $search) { + $replace = str_replace('[', '', $search); + $replace = str_replace(']', '', $replace); + $form = str_replace($search, $$replace, $form); + } + return $form; +} + +function updateBotSelection() { + //db globals + global $msg, $default_format; + $logFile = _LOG_URL_ . 'error.log'; + $dbconn = db_open(); + $sql = ""; + $msg = ""; + foreach($_POST as $key => $value) { + if(($key!="bot_id")||($key!="action")) { + $value = mysql_real_escape_string(trim(stripslashes($value))); + if(($key != "bot_id")&&($key != "action")&&($value!="")) { + $sql = "UPDATE `bots` SET `$key` ='$value' where `bot_id` = '".$_POST['bot_id']."' limit 1; "; + $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . '.'); + if(!$result) { + $msg = "Error updating bot details. See the error log for details.
        "; + trigger_error("There was a problem adding '$key' to the database. The value was '$value'."); + break; + } + } + } + } + + $format = filter_input(INPUT_POST,'format'); + + if ($format !== $default_format) + { + $cfn = _CONF_PATH_ . 'global_config.php'; + $configFile = file(_CONF_PATH_ . 'global_config.php',FILE_IGNORE_NEW_LINES); + $search = ' $default_format = \'' . $default_format . '\';'; + $replace = ' $default_format = \'' . $format . '\';'; + $index = array_search($search, $configFile); + if (false === $index) + { + $msg .= "Error updating the config file. See the error log for details.
        "; + trigger_error("There was a problem with updating the default format in the config file. Please edit the value manually and submit a bug report."); + } + else + { + $configFile[$index] = $replace; + $configContent = implode("\n", $configFile); + $x = file_put_contents(_CONF_PATH_ . 'global_config.php', $configContent); + } + } + if($msg == "") { + $msg = 'Bot details updated.'; + } + + mysql_close($dbconn); + return $msg; + +} + + +function addBot() { + //db globals + global $msg; + foreach ($_POST as $key => $value) { + $$key = mysql_real_escape_string(trim($value)); + } + $dbconn = db_open(); + $sql = <<0) { + $row=mysql_fetch_array($result); + $_SESSION['poadmin']['bot_id']=$row['bot_id']; + $_SESSION['poadmin']['bot_name']=$row['bot_name']; + } + else { + $_SESSION['poadmin']['bot_id']="new"; + $_SESSION['poadmin']['bot_name']=""; + } + } + else { + $_SESSION['poadmin']['bot_name']=""; + $_SESSION['poadmin']['bot_id']="new"; + } + mysql_close($dbconn); +} + + +function getChangeList() { + //db globals + global $template; + $dbconn = db_open(); + $inputs=""; + //get bot names from the db + $sql = "SELECT * FROM `bots` ORDER BY bot_name"; + $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . '.'); + $options = '' . "\n"; + while($row = mysql_fetch_array($result)) { + if($_SESSION['poadmin']['bot_id']==$row['bot_id']) { + $sel = ' selected="selected"'; + } + else { + $sel= ""; + } + $bot_id = $row['bot_id']; + $bot_name = $row['bot_name']; + $options .= " \n"; + } + $options = rtrim($options); + mysql_close($dbconn); + $form = $template->getSection('ChangeBot'); + $form = str_replace('[options]', $options, $form); + return $form; +} + ?> \ No newline at end of file diff --git a/admin/serveFile.php b/admin/serveFile.php index 5fcb879..bf1c86d 100644 --- a/admin/serveFile.php +++ b/admin/serveFile.php @@ -1,35 +1,35 @@ -Download here +Download here ?> \ No newline at end of file diff --git a/admin/spellcheck.php b/admin/spellcheck.php index 887ca23..8b23b26 100644 --- a/admin/spellcheck.php +++ b/admin/spellcheck.php @@ -1,302 +1,304 @@ - - -endScript; - - $group = (isset($_GET['group'])) ? $_GET['group'] : 1; - $content = $template->getSection('SearchSpellForm'); - if (isset($_REQUEST['action'])) { - switch($_REQUEST['action']) { - case 'search': - $content .= runSpellSearch(); - $content .= spellCheckForm(); - break; - case 'update': - $x = updateSpell(); - $content .= spellCheckForm(); - break; - case 'del': - $content .= (isset($_GET['id']))&&($_GET['id']!="") ? delSpell($_GET['id']) . spellCheckForm() : spellCheckForm(); - break; - case 'edit': - $content .= (isset($_GET['id']))&&($_GET['id']!="") ? editSpellForm($_GET['id']) : spellCheckForm(); - break; - case 'add': - $x = insertSpell(); - $content .= spellCheckForm(); - break; - default: - $content .= spellCheckForm(); - } - } - else { - $content .= spellCheckForm(); - } - $content = str_replace('[group]', $group, $content); - - $topNav = $template->getSection('TopNav'); - $leftNav = $template->getSection('LeftNav'); - $main = $template->getSection('Main'); - $topNavLinks = makeLinks('top', $topLinks, 12); - $navHeader = $template->getSection('NavHeader'); - $rightNav = $template->getSection('RightNav'); - $leftNavLinks = makeLinks('left', $leftLinks, 12); - $rightNavLinks = getMisspelledWords(); - $FooterInfo = getFooter(); - $errMsgClass = (!empty($msg)) ? "ShowError" : "HideError"; - $errMsgStyle = $template->getSection($errMsgClass); - $noLeftNav = ''; - $noTopNav = ''; - $noRightNav = ''; - $headerTitle = 'Actions:'; - $pageTitle = 'My-Program O - Spellcheck Editor'; - $mainContent = $content; - $mainTitle = 'Spellcheck Editor'; - - $mainContent = str_replace('[spellCheckForm]', spellCheckForm(), $mainContent); - $rightNav = str_replace('[rightNavLinks]', $rightNavLinks, $rightNav); - $rightNav = str_replace('[navHeader]', $navHeader, $rightNav); - $rightNav = str_replace('[headerTitle]', paginate(), $rightNav); - - function paginate() { - $dbConn = db_open(); - $sql = "select count(*) from `spellcheck` where 1"; - $result = mysql_query($sql) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); - $row = mysql_fetch_array($result); - $rowCount = $row[0]; - mysql_close($dbConn); - $lastPage = intval($rowCount / 50); - $remainder = ($rowCount / 50) - $lastPage; - if ($remainder > 0) $lastPage++; - #die ("Session values:
        \n" . print_r($_SESSION, true) . "
        \nCount = $count
        \n"); - $out = "Missspelled Words
        \n50 words per page:
        \n"; - $link=" - [label]"; - $curStart = (isset($_GET['group'])) ? $_GET['group'] : 1; - $firstPage = 1; - $prev = ($curStart > ($firstPage + 1)) ? $curStart - 1 : -1; - $next = ($lastPage > ($curStart + 1)) ? $curStart + 1 : -1; - $firstLink = ($firstPage != $curStart) ? str_replace('[group]', '1', $link) : ''; - $prevLink = ($prev > 0) ? str_replace('[group]', $prev, $link) : ''; - $curLink = "- $curStart "; - if (empty($firstLink) and empty($prevLink)) $curLink = $curStart; - $nextLink = ($next > 0) ? str_replace('[group]', $next, $link) : ''; - $lastLink = ($lastPage > $curStart) ? str_replace('[group]', $lastPage, $link) : ''; - $firstLink = str_replace('[label]', 'first', $firstLink); - $prevLink = str_replace('[label]', '<<', $prevLink); - $nextLink = str_replace('[label]', '>>', $nextLink); - $lastLink = str_replace('[label]', 'last', $lastLink); - $out .= ltrim("$firstLink\n$prevLink\n$curLink\n$nextLink\n$lastLink", " - "); - return $out; - } - - function getMisspelledWords() { - global $template; - # pagination variables - $group = (isset($_GET['group'])) ? $_GET['group'] : 1; - $_SESSION['poadmin']['group'] = $group; - $startEntry = ($group - 1) * 50; - $end = $group + 50; - $_SESSION['poadmin']['page_start'] = $group; - $dbconn = db_open(); - $curID = (isset($_GET['id'])) ? $_GET['id'] : -1; - $sql = "select `id`,`missspelling` from `spellcheck` where 1 order by abs(`id`) asc limit $startEntry, 50;"; - #die ("SQL = $sql
        \n"); - $baseLink = $template->getSection('NavLink'); - $links = '
        ' . "\n"; - $result = mysql_query($sql, $dbconn) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); - $count = 0; - while ($row = mysql_fetch_assoc($result)) { - $linkId = $row['id']; - $linkClass = ($linkId == $curID) ? 'selected' : 'noClass'; - $missspelling = $row['missspelling']; - $tmpLink = str_replace('[linkClass]', " class=\"$linkClass\"", $baseLink); - $linkHref = " href=\"./?page=spellcheck&action=edit&id=$linkId&group=$group#$linkId\" name=\"$linkId\""; - $tmpLink = str_replace('[linkHref]', $linkHref, $tmpLink); - $tmpLink = str_replace('[linkOnclick]', '', $tmpLink); - $tmpLink = str_replace('[linkTitle]', " title=\"Edit spelling correction for the word '$missspelling'\"", $tmpLink); - $tmpLink = str_replace('[linkLabel]', $missspelling, $tmpLink); - $links .= "$tmpLink\n"; - $count++; - } - $page_count = intval($count / 50); - $_SESSION['poadmin']['page_count'] = $page_count + (($count / 50) > $page_count) ? 1 : 0; - $links .= "\n
        \n"; - return $links; - } - -function spellCheckForm() { - global $template; - $out = $template->getSection('SpellcheckForm'); - $group = (isset($_GET['group'])) ? $_GET['group'] : 1; - $out = str_replace('[group]', $group, $out); - return $out; -} - -function insertSpell() { - //global vars - global $template, $msg; - $dbconn = db_open(); - - $correction = mysql_escape_string(trim($_POST['correction'])); - $missspell = mysql_escape_string(trim($_POST['missspell'])); - - if(($correction == "") || ($missspell == "")) { - $msg = '
        You must enter a spelling mistake and the correction.
        ' . "\n"; - } - else { - $sql = "INSERT INTO `spellcheck` VALUES (NULL,'$missspell','$correction')"; - $result = mysql_query($sql,$dbconn) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); - - if($result) { - $msg = '
        Correction added.
        '; - } - else { - $msg = '
        There was a problem editing the correction - no changes made.
        '; - } - } - mysql_close($dbconn); - - return $msg; -} - -function delSpell($id) { - global $template, $msg; - $dbconn = db_open(); - if($id=="") { - $msg = '
        There was a problem editing the correction - no changes made.
        '; - } - else { - $sql = "DELETE FROM `spellcheck` WHERE `id` = '$id' LIMIT 1"; - $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); - if($result) { - $msg = '
        Correction deleted.
        '; - } - else { - $msg = '
        There was a problem editing the correction - no changes made.
        '; - } - } - mysql_close($dbconn); -} - - -function runSpellSearch() { - //global vars - global $template; - $dbconn = db_open(); - $i=0; - $search = mysql_escape_string(trim($_POST['search'])); - $sql = "SELECT * FROM `spellcheck` WHERE `missspelling` LIKE '%$search%' OR `correction` LIKE '%$search%' LIMIT 50"; - $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); - $htmltbl = ' - - - - - - - - '; - while($row=mysql_fetch_array($result)) { - $i++; - $misspell = strtoupper($row['missspelling']); - $correction = strtoupper($row['correction']); - $id = $row['id']; - $group = round(($id / 50)); - $action = " - "; - $htmltbl .= " - - - - "; - } - $htmltbl .= "
        missspellingCorrectionAction
        $misspell$correction$action
        "; - - if($i >= 50) { - $msg = "Found more than 50 results for '$search', please refine your search further"; - } - elseif($i == 0) { - $msg = "Found 0 results for '$search'. You can use the form below to add that entry."; - $htmltbl=""; - } - else { - $msg = "Found $i results for '$search'"; - } - $htmlresults = "
        $msg
        ".$htmltbl; - mysql_close($dbconn); - return $htmlresults; -} - -function editSpellForm($id) { - //global vars - global $template; - $group = (isset($_GET['group'])) ? $_GET['group'] : 1; - $form = $template->getSection('EditSpellForm'); - $dbconn = db_open(); - $sql = "SELECT * FROM `spellcheck` WHERE `id` = '$id' LIMIT 1"; - $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); - $row = mysql_fetch_array($result); - $form = str_replace('[id]', $row['id'], $form); - $form = str_replace('[missspelling]', strtoupper($row['missspelling']), $form); - $form = str_replace('[correction]', strtoupper($row['correction']), $form); - $form = str_replace('[group]', $group, $form); - mysql_close($dbconn); - return $form; -} - -function updateSpell() { - //global vars - global $template, $msg; - $dbconn = db_open(); - $missspelling = mysql_escape_string(trim($_POST['missspelling'])); - $correction = mysql_escape_string(trim($_POST['correction'])); - $id = trim($_POST['id']); - if(($id=="")||($missspelling=="")||($correction=="")) { - $msg = '
        There was a problem editing the correction - no changes made.
        '; - } - else { - $sql = "UPDATE `spellcheck` SET `missspelling` = '$missspelling',`correction`='$correction' WHERE `id`='$id' LIMIT 1"; - $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); - if($result) { - $msg = '
        Correction edited.
        '; - } - else { - $msg = '
        There was a problem editing the correction - no changes made.
        '; - } - } -} - + + +endScript; + + $group = (isset($_GET['group'])) ? $_GET['group'] : 1; + $content = $template->getSection('SearchSpellForm'); + $sc_action = isset($_REQUEST['action']) ? strtolower($_REQUEST['action']) : ''; + $sc_id = isset($_REQUEST['id']) ? $_REQUEST['id'] : -1; + if (!empty($sc_action)) { + switch($sc_action) { + case 'search': + $content .= runSpellSearch(); + $content .= spellCheckForm(); + break; + case 'update': + $x = updateSpell(); + $content .= spellCheckForm(); + break; + case 'delete': + $content .= ($sc_id >= 0) ? delSpell($sc_id) . spellCheckForm() : spellCheckForm(); + break; + case 'edit': + $content .= ($sc_id >= 0) ? editSpellForm($sc_id) : spellCheckForm(); + break; + case 'add': + $x = insertSpell(); + $content .= spellCheckForm(); + break; + default: + $content .= spellCheckForm(); + } + } + else { + $content .= spellCheckForm(); + } + $content = str_replace('[group]', $group, $content); + + $topNav = $template->getSection('TopNav'); + $leftNav = $template->getSection('LeftNav'); + $main = $template->getSection('Main'); + $topNavLinks = makeLinks('top', $topLinks, 12); + $navHeader = $template->getSection('NavHeader'); + $rightNav = $template->getSection('RightNav'); + $leftNavLinks = makeLinks('left', $leftLinks, 12); + $rightNavLinks = getMisspelledWords(); + $FooterInfo = getFooter(); + $errMsgClass = (!empty($msg)) ? "ShowError" : "HideError"; + $errMsgStyle = $template->getSection($errMsgClass); + $noLeftNav = ''; + $noTopNav = ''; + $noRightNav = ''; + $headerTitle = 'Actions:'; + $pageTitle = 'My-Program O - Spellcheck Editor'; + $mainContent = $content; + $mainTitle = 'Spellcheck Editor'; + + $mainContent = str_replace('[spellCheckForm]', spellCheckForm(), $mainContent); + $rightNav = str_replace('[rightNavLinks]', $rightNavLinks, $rightNav); + $rightNav = str_replace('[navHeader]', $navHeader, $rightNav); + $rightNav = str_replace('[headerTitle]', paginate(), $rightNav); + + function paginate() { + $dbConn = db_open(); + $sql = "select count(*) from `spellcheck` where 1"; + $result = mysql_query($sql) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); + $row = mysql_fetch_array($result); + $rowCount = $row[0]; + mysql_close($dbConn); + $lastPage = intval($rowCount / 50); + $remainder = ($rowCount / 50) - $lastPage; + if ($remainder > 0) $lastPage++; + #die ("Session values:
        \n" . print_r($_SESSION, true) . "
        \nCount = $count
        \n"); + $out = "Missspelled Words
        \n50 words per page:
        \n"; + $link=" - [label]"; + $curStart = (isset($_GET['group'])) ? $_GET['group'] : 1; + $firstPage = 1; + $prev = ($curStart > ($firstPage + 1)) ? $curStart - 1 : -1; + $next = ($lastPage > ($curStart + 1)) ? $curStart + 1 : -1; + $firstLink = ($firstPage != $curStart) ? str_replace('[group]', '1', $link) : ''; + $prevLink = ($prev > 0) ? str_replace('[group]', $prev, $link) : ''; + $curLink = "- $curStart "; + if (empty($firstLink) and empty($prevLink)) $curLink = $curStart; + $nextLink = ($next > 0) ? str_replace('[group]', $next, $link) : ''; + $lastLink = ($lastPage > $curStart) ? str_replace('[group]', $lastPage, $link) : ''; + $firstLink = str_replace('[label]', 'first', $firstLink); + $prevLink = str_replace('[label]', '<<', $prevLink); + $nextLink = str_replace('[label]', '>>', $nextLink); + $lastLink = str_replace('[label]', 'last', $lastLink); + $out .= ltrim("$firstLink\n$prevLink\n$curLink\n$nextLink\n$lastLink", " - "); + return $out; + } + + function getMisspelledWords() { + global $template; + # pagination variables + $group = (isset($_GET['group'])) ? $_GET['group'] : 1; + $_SESSION['poadmin']['group'] = $group; + $startEntry = ($group - 1) * 50; + $end = $group + 50; + $_SESSION['poadmin']['page_start'] = $group; + $dbconn = db_open(); + $curID = (isset($_GET['id'])) ? $_GET['id'] : -1; + $sql = "select `id`,`missspelling` from `spellcheck` where 1 order by abs(`id`) asc limit $startEntry, 50;"; + #die ("SQL = $sql
        \n"); + $baseLink = $template->getSection('NavLink'); + $links = '
        ' . "\n"; + $result = mysql_query($sql, $dbconn) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); + $count = 0; + while ($row = mysql_fetch_assoc($result)) { + $linkId = $row['id']; + $linkClass = ($linkId == $curID) ? 'selected' : 'noClass'; + $missspelling = $row['missspelling']; + $tmpLink = str_replace('[linkClass]', " class=\"$linkClass\"", $baseLink); + $linkHref = " href=\"./?page=spellcheck&action=edit&id=$linkId&group=$group#$linkId\" name=\"$linkId\""; + $tmpLink = str_replace('[linkHref]', $linkHref, $tmpLink); + $tmpLink = str_replace('[linkOnclick]', '', $tmpLink); + $tmpLink = str_replace('[linkTitle]', " title=\"Edit spelling correction for the word '$missspelling'\"", $tmpLink); + $tmpLink = str_replace('[linkLabel]', $missspelling, $tmpLink); + $links .= "$tmpLink\n"; + $count++; + } + $page_count = intval($count / 50); + $_SESSION['poadmin']['page_count'] = $page_count + (($count / 50) > $page_count) ? 1 : 0; + $links .= "\n
        \n"; + return $links; + } + +function spellCheckForm() { + global $template; + $out = $template->getSection('SpellcheckForm'); + $group = (isset($_GET['group'])) ? $_GET['group'] : 1; + $out = str_replace('[group]', $group, $out); + return $out; +} + +function insertSpell() { + //global vars + global $template, $msg; + $dbconn = db_open(); + + $correction = mysql_real_escape_string(trim($_POST['correction'])); + $missspell = mysql_real_escape_string(trim($_POST['missspell'])); + + if(($correction == "") || ($missspell == "")) { + $msg = '
        You must enter a spelling mistake and the correction.
        ' . "\n"; + } + else { + $sql = "INSERT INTO `spellcheck` VALUES (NULL,'$missspell','$correction')"; + $result = mysql_query($sql,$dbconn) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); + + if($result) { + $msg = '
        Correction added.
        '; + } + else { + $msg = '
        There was a problem editing the correction - no changes made.
        '; + } + } + mysql_close($dbconn); + + return $msg; +} + +function delSpell($id) { + global $template, $msg; + $dbconn = db_open(); + if($id=="") { + $msg = '
        There was a problem editing the correction - no changes made.
        '; + } + else { + $sql = "DELETE FROM `spellcheck` WHERE `id` = '$id' LIMIT 1"; + $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); + if($result) { + $msg = '
        Correction deleted.
        '; + } + else { + $msg = '
        There was a problem editing the correction - no changes made.
        '; + } + } + mysql_close($dbconn); +} + + +function runSpellSearch() { + //global vars + global $template; + $dbconn = db_open(); + $i=0; + $search = mysql_real_escape_string(trim($_POST['search'])); + $sql = "SELECT * FROM `spellcheck` WHERE `missspelling` LIKE '%$search%' OR `correction` LIKE '%$search%' LIMIT 50"; + $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); + $htmltbl = ' + + + + + + + + '; + while($row=mysql_fetch_array($result)) { + $i++; + $misspell = strtoupper($row['missspelling']); + $correction = strtoupper($row['correction']); + $id = $row['id']; + $group = round(($id / 50)); + $action = "\"Edit + \"Edit"; + $htmltbl .= " + + + + "; + } + $htmltbl .= "
        missspellingCorrectionAction
        $misspell$correction$action
        "; + + if($i >= 50) { + $msg = "Found more than 50 results for '$search', please refine your search further"; + } + elseif($i == 0) { + $msg = "Found 0 results for '$search'. You can use the form below to add that entry."; + $htmltbl=""; + } + else { + $msg = "Found $i results for '$search'"; + } + $htmlresults = "
        $msg
        ".$htmltbl; + mysql_close($dbconn); + return $htmlresults; +} + +function editSpellForm($id) { + //global vars + global $template; + $group = (isset($_GET['group'])) ? $_GET['group'] : 1; + $form = $template->getSection('EditSpellForm'); + $dbconn = db_open(); + $sql = "SELECT * FROM `spellcheck` WHERE `id` = '$id' LIMIT 1"; + $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); + $row = mysql_fetch_array($result); + $form = str_replace('[id]', $row['id'], $form); + $form = str_replace('[missspelling]', strtoupper($row['missspelling']), $form); + $form = str_replace('[correction]', strtoupper($row['correction']), $form); + $form = str_replace('[group]', $group, $form); + mysql_close($dbconn); + return $form; +} + +function updateSpell() { + //global vars + global $template, $msg; + $dbconn = db_open(); + $missspelling = mysql_real_escape_string(trim($_POST['missspelling'])); + $correction = mysql_real_escape_string(trim($_POST['correction'])); + $id = trim($_POST['id']); + if(($id=="")||($missspelling=="")||($correction=="")) { + $msg = '
        There was a problem editing the correction - no changes made.
        '; + } + else { + $sql = "UPDATE `spellcheck` SET `missspelling` = '$missspelling',`correction`='$correction' WHERE `id`='$id' LIMIT 1"; + $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); + if($result) { + $msg = '
        Correction edited.
        '; + } + else { + $msg = '
        There was a problem editing the correction - no changes made.
        '; + } + } +} + ?> \ No newline at end of file diff --git a/admin/stats.php b/admin/stats.php index 30e15a7..8d115a9 100644 --- a/admin/stats.php +++ b/admin/stats.php @@ -1,108 +1,108 @@ -getSection('TopNav'); - $leftNav = $template->getSection('LeftNav'); - $main = $template->getSection('Main'); - $topNavLinks = makeLinks('top', $topLinks, 12); - $navHeader = $template->getSection('NavHeader'); - $leftNavLinks = makeLinks('left', $leftLinks, 12); - $FooterInfo = getFooter(); - $errMsgClass = (!empty($msg)) ? "ShowError" : "HideError"; - $errMsgStyle = $template->getSection($errMsgClass); - $noLeftNav = ''; - $noTopNav = ''; - $noRightNav = $template->getSection('NoRightNav'); - $headerTitle = 'Actions:'; - $pageTitle = 'My-Program O - Bot Stats'; - $mainContent = $template->getSection('StatsPage'); - $mainTitle = 'Bot Statistics for ' . $bot_name; - - $mainContent = str_replace('[oneday]', $oneday, $mainContent); - $mainContent = str_replace('[oneweek]', $oneweek, $mainContent); - $mainContent = str_replace('[onemonth]', $onemonth, $mainContent); - $mainContent = str_replace('[sixmonths]', $sixmonths, $mainContent); - $mainContent = str_replace('[oneyear]', $oneyear, $mainContent); - $mainContent = str_replace('[alltime]', $alltime, $mainContent); - $mainContent = str_replace('[singlelines]', $singlelines, $mainContent); - $mainContent = str_replace('[alines]', $alines, $mainContent); - $mainContent = str_replace('[blines]', $blines, $mainContent); - $mainContent = str_replace('[clines]', $clines, $mainContent); - $mainContent = str_replace('[dlines]', $dlines, $mainContent); - $mainContent = str_replace('[avg]', $avg, $mainContent); - -function getStats($interval) { - global $bot_id; - $dbconn = db_open(); - if($interval!="all") { - $intervaldate = date("Y-m-d", strtotime($interval)); - $sqladd = " AND date(timestamp) >= '$intervaldate'"; - } - else { - $sqladd =""; - } - //get undefined defaults from the db - $sql = "SELECT count(distinct(`userid`)) AS TOT FROM `conversation_log` WHERE bot_id = '$bot_id' $sqladd"; - $result = mysql_query($sql,$dbconn) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); - $row = mysql_fetch_assoc($result); - $res = $row['TOT']; - return $res; -} - -function getChatLines($i,$j) { - global $bot_id; - $dbconn = db_open(); - $sql = <<\nSQL = $sql
        \n"); - $row = mysql_fetch_assoc($result); - $res = $row['TOT']; - return $res; -} - - - - - - - - - - - +getSection('TopNav'); + $leftNav = $template->getSection('LeftNav'); + $main = $template->getSection('Main'); + $topNavLinks = makeLinks('top', $topLinks, 12); + $navHeader = $template->getSection('NavHeader'); + $leftNavLinks = makeLinks('left', $leftLinks, 12); + $FooterInfo = getFooter(); + $errMsgClass = (!empty($msg)) ? "ShowError" : "HideError"; + $errMsgStyle = $template->getSection($errMsgClass); + $noLeftNav = ''; + $noTopNav = ''; + $noRightNav = $template->getSection('NoRightNav'); + $headerTitle = 'Actions:'; + $pageTitle = 'My-Program O - Bot Stats'; + $mainContent = $template->getSection('StatsPage'); + $mainTitle = 'Bot Statistics for ' . $bot_name; + + $mainContent = str_replace('[oneday]', $oneday, $mainContent); + $mainContent = str_replace('[oneweek]', $oneweek, $mainContent); + $mainContent = str_replace('[onemonth]', $onemonth, $mainContent); + $mainContent = str_replace('[sixmonths]', $sixmonths, $mainContent); + $mainContent = str_replace('[oneyear]', $oneyear, $mainContent); + $mainContent = str_replace('[alltime]', $alltime, $mainContent); + $mainContent = str_replace('[singlelines]', $singlelines, $mainContent); + $mainContent = str_replace('[alines]', $alines, $mainContent); + $mainContent = str_replace('[blines]', $blines, $mainContent); + $mainContent = str_replace('[clines]', $clines, $mainContent); + $mainContent = str_replace('[dlines]', $dlines, $mainContent); + $mainContent = str_replace('[avg]', $avg, $mainContent); + +function getStats($interval) { + global $bot_id; + $dbconn = db_open(); + if($interval!="all") { + $intervaldate = date("Y-m-d", strtotime($interval)); + $sqladd = " AND date(timestamp) >= '$intervaldate'"; + } + else { + $sqladd =""; + } + //get undefined defaults from the db + $sql = "SELECT count(distinct(`userid`)) AS TOT FROM `conversation_log` WHERE bot_id = '$bot_id' $sqladd"; + $result = mysql_query($sql,$dbconn) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); + $row = mysql_fetch_assoc($result); + $res = $row['TOT']; + return $res; +} + +function getChatLines($i,$j) { + global $bot_id; + $dbconn = db_open(); + $sql = <<\nSQL = $sql
        \n"); + $row = mysql_fetch_assoc($result); + $res = $row['TOT']; + return $res; +} + + + + + + + + + + + ?> \ No newline at end of file diff --git a/admin/style.css b/admin/style.css index 40cbea6..645ced9 100644 --- a/admin/style.css +++ b/admin/style.css @@ -1,669 +1,754 @@ -/* -My Program-O Version 2.0.1 -Program-O chatbot admin area -Written by Elizabeth Perreau and Dave Morton -Aug 2011 -for more information and support please visit www.program-o.com -*/ -html, body { - height: 100%; -} -body { - background-color: #9FC03A; - /*background-color: white;*/ - background-image: url(http://github.com/images/CompRule.png); - background-repeat: repeat; - background-image: url(http://github.com/images/repeated_header2.jpg); - background-repeat: repeat-x; - color: #000000; - margin: 0; - padding: 0; - width: 99.5%; - height: 99.5%; - overflow: hidden; -} -table td {vertical-align: top;} -fieldset { border: 1px solid black; padding: 12px; padding-left: 5px; padding-right: 5px; line-height: 125%;} -legend { font-weight: bold; font-size: xx-large; margin-left: -5px; margin-top: -15px; } -label { cursor: pointer; margin-right: 20px; } -div.row { clear: both; padding-top: 8px; border: none; width: 95%; margin-left: auto; margin-right: auto; min-height: 2em;} -label { cursor: pointer; margin-right: 20px; } -.leftHalf table tr td, .rightHalf table tr td {vertical-align: top;} -div.row span.label {float: left; width: 49.5%; text-align: left; padding-left: 3px; background-color: #DDFFFF; border: 1px outset #999; padding-top: 3px; padding-bottom: 3px;} -div.row span.label:hover, div.row span.formw:hover {background-color: #EEE;} -td span.label {float:left;width: 99%; text-align: left; padding-left: 3px; background-color: #DDFFFF; border: 1px outset #999; padding-top: 3px; padding-bottom: 3px; vertical-align: top;} -td span.label:hover, div.row span.formw:hover {background-color: #EEE;} -td span.formw {float:right;width: 99%; text-align: left; background-color: #DDFFFF; border: 1px outset #999; padding-top: 2px; padding-bottom: 2px;} -td span.formw input, div.row span.formw textarea { width: 150px; margin: 0; } -td span.formw input[type="radio"] { width: auto; margin-right: 5px; } -div.row span.formw {float: right; clear: none; width: 49.5%; text-align: left; background-color: #DDFFFF; border: 1px outset #999; padding-top: 2px; padding-bottom: 2px;} -div.row span.formw input, div.row span.formw textarea { width: 150px; margin: 0; } -div.row span.formxw input, div.row span.formxw textarea { width: 80%; margin: 0; margin-left: 6px; margin-right: 2px; } -div.row span.formw select { width: 155px; margin: 0; } -div.row span.formxw select { width: 42%; margin: 0; } -div.row span.formw input.wide { width: 99.1%; margin: 0; } -div.row span.formw input[type=checkbox], div.row span.formw input[type=radio] { width: 15px; margin: 0; } -div.row span.formxw input[type=checkbox], div.row span.formxw input[type=radio] { width: 15px; margin: 0; text-align: left; margin-left: 6px; } -.leftHalf { width: 49%; float: left; } -.rightHalf { width: 49%; float: right; } -.leftHalf, .rightHalf { - border-right: 1px solid #666; - border-bottom: 2px solid #000; - padding-bottom: 2px; -} -.indent { text-indent: 1em; } -.fullWidth { width: 100%;} -.eightyPercent { width: 80%; } -span.eightyPercent input.wide { width: 67%; margin: 0; float: right; } -.twentyPercent { width: 20%; } -.noBorder { border: none; } -.testBorder { border: 1px solid red; } -.center { text-align: center; } -.bold { font-weight: bold; } -.narrow { padding-left: 0; float: left;width: 25%;text-align: left; border: 1px dashed blue;} -.errMsg { - position: absolute; - top: 25px; - left: 25px; - width: 250px; - background-color: #FFF45A; - background-color: transparent; - color: black; - vertical-align: middle; - text-align: center; - padding: 0; - margin: 0; - display: none; - overflow: auto; -} -.ul, .ll, .ur, .lr { - width: 6px; - height: 6px; - position: absolute; - background-color: transparent; - background-repeat: no-repeat; - z-index: 1; -} -.ul { top: 0; left: 0; background-image: url(http://github.com/images/ul.png); } -.ll { bottom: 0; left: 0; background-image: url(http://github.com/images/ll.png); } -.ur { top: 0; right: 0; background-image: url(http://github.com/images/ur.png); } -.lr { bottom: 0; right: 0; background-image: url(http://github.com/images/lr.png); } -.nav_header { - text-align: center; - padding-bottom: 3px; - border-bottom: 1px solid black; - width: 100%; -} -.red { - background-color: transparent; - color: red; - font-size: large; - font-weight: bold; -} -.orange { background-color: transparent; color: orange } -.validCSS { float: right; margin-top: 10px; } -.validXHTML { float: left; margin-top: 10px; margin-left: 5px; } -.userlist { - height: 80%; - overflow: auto; - padding-left: 5px; -} -.paginate { font-size: 0.8em; } -#form_table { width: 300px; margin-left: auto; margin-right: auto; margin-top: 20px; padding: 12px; height: 100px; } -#fm-form div label { float: left; } -#fm-form div input { float: right; margin-right: 10px; } -#title { - text-align: center; - font-size: x-large; - font-weight: bold; - position: absolute; - top: 125px; - left: 25px; - right: 25px; - /*width: 94%;*/ - height: 30px; - z-index: 100; - background-color: transparent; - background-image: url(http://github.com/images/bg_list.gif); - background-position: bottom; - background-repeat: repeat-x; - margin: 0; - padding: 0px; -} -#titlespan { - background-repeat: no-repeat; - background-position: center; - background-color: transparent; - color: white; - z-index: 50; - width: 100%; -} -#logo { - background-image: url(http://github.com/images/bg_header2.jpg); - background-repeat: no-repeat; - background-position: center 0; - /*background-color: white;*/ - width: 100%; - height: 140px; - border: none; - margin: 0; - padding: 0; - float: none; -} -#top_nav { - background-color: transparent; - height: 25px; - padding: 6px; - padding-top: 0; - text-align: center; - position: absolute; - top: 130px; - left: 25px; - right: 25px; -} -#top_nav ul { - list-style: none; - margin: 0; - padding:0; -} -#top_nav ul li { - display: inline; -} - -#top_nav ul li div { - width: 120px; - height: 25px; - position: relative; - background-color: #39A3C6; - display: inline-block; - vertical-align: middle; - padding: 0; - margin: 0; -} - -#top_nav ul li div a { - position: absolute; - left: 0; - top: 0; - right: 0; - bottom: 0; - background-color: transparent; - color: white; - line-height:1em; - margin: 0; - padding-top: 4px; - font-weight:normal; - font-size: 0.995em; - text-decoration: none; - vertical-align: middle; - width: 100%; - height: 100%; - border: 1px solid white; - border: none; -} -#top_nav ul li div:hover { - background-color: #FFF45A; -} -#top_nav ul li div a:hover { - color: black; -} -#top_nav ul li div.selected { - background-color: #FFF45A; - color: black; -} -#top_nav ul li div.selected:hover { - background-color: #FFF45A; -} -#top_nav ul li div.selected a { - color: black; -} - -#top_nav ul li div.ul, #top_nav ul li div.ll, #top_nav ul li div.ur, #top_nav ul li div.lr { - width: 6px; - height: 6px; - position: absolute; - background-color: transparent; - background-repeat: no-repeat; - z-index: 1; - border: none -} - -#left_nav { - background-color: #FFFFCC; - float: left; - position: absolute; - top: 160px; - left: 25px; - bottom: 70px; - width: 172px; - min-height: 25%; - overflow: auto; - margin: 0; - padding: 0; -} - -#left_nav ul { - margin: 0; - padding: 0; - margin-top: 5px; - /*border: 1px solid red;*/ -} -#left_nav ul li a { - text-align: left; - list-style: none; - background-image: url(http://github.com/images/bullet.gif); - background-repeat:no-repeat; - background-position:left center; - background-color: transparent; - display: block; - line-height:1.4em; - height:1.3em; - margin: 0px; - padding-top:6px; - padding-bottom:6px; - padding-left: 22px; - color: black; - font-weight:normal; - font-size: 0.8em; - text-decoration: none; - vertical-align: middle; -} -/* -*/ -#left_nav ul li a:hover { - background-image: url(http://github.com/images/bullet_hover.gif); - color: black; - background-color: #EEE8AA; -} - -#left_nav ul li a.selected:hover { - cursor: default; -} - -#right_nav { - background-color: #FFFFCC; - float: left; - position: absolute; - top: 160px; - right: 25px; - bottom: 70px; - width: 170px; - min-height: 25%; - overflow: hidden; - margin: 0; - padding: 0; -} - -#right_nav ul { - margin: 0; - padding: 0; - margin-top: 5px; - /*border: 1px solid red;*/ -} - -#right_nav ul li a { - text-align: right; - list-style: none; - background-image: url(http://github.com/images/bullet_right.gif); - background-repeat:no-repeat; - background-position:right center; - background-color: transparent; - display: block; - line-height:1.4em; - height:1.4em; - margin: 0px; - padding-top:6px; - padding-bottom:6px; - padding-right: 22px; - color: black; - font-weight:normal; - font-size: 0.8em; - text-decoration: none; - vertical-align: middle; -} -/* -*/ -#right_nav ul li a:hover { - background-image: url(http://github.com/images/bullet_right_hover.gif); - color: black; - background-color: #EEE8AA; -} - -#right_nav .selected, #left_nav .selected, #top_nav ul li a.selected { - color: black; - background-color: #E1D66C; -} - -#right_nav .selected:hover, #left_nav .selected:hover, #top_nav ul li a.selected:hover { - color: black; - background-color: #F2EDBD; - cursor: default; -} - -#wrapper { - width: 90%; - height: 90%; - margin: auto; - padding: 0; - /*background: url(http://github.com/images/red_trans.png) repeat; - border: 1px solid blue;*/ - overflow: hidden; -} -#main { - position: absolute; - top: 160px; - bottom: 70px; - left: 205px; - right: 205px; - background-color: transparent; - background-color: #FFFFCC; - overflow: hidden; - min-height: 25%; -} -#main_title { - text-align: center; - width: 99%; - height: 50px; - margin: 0; - font-size: xx-large; - font-weight: bold; - font-variant: small-caps; -} -#main_content { - position: absolute; - top: 50px; - bottom: 25px; - left: 5px; - right: 5px; - text-indent: 1em; - overflow: auto; - width: 99%; -} - -#rssContainer { - width: 98.5%; - min-height: 300px; - position: absolute; - top: 40px; - left: 0; - right: 0; - bottom: 0; - border: none; - overflow: hidden; -} -#rssTitle { - width: 100%; - height: 35px; - position: absolute; - left: 0; - top: 0; - text-align: center; - font-weight: bold; - font-size: larger; -} -#rssOutput { - position: absolute; - left: 0; - right: 0; - top: 35px; - bottom: 0; - overflow: auto; - padding: 5px; -} - -#col1 { -float:left; -width:410px; -margin-right:0px; -margin-top:20px; -background-color:inherit; -text-align:left; -font-size:0.9em; -padding:5px; -} - -#nocol { -float:left; -width:98%; -margin-right:0px; -margin-top:20px; -text-align:left; -font-size:0.9em; -padding:5px; -} - -#col1 h1 { -display:block; -font-size:0.9em; -width:50px; -font-family: arial; -text-align:left; -font-weight:bold; -color:#403f3b; -font-family:arial; -font-weight:bold; -padding:5px; -margin-top:5px; -margin-left:12px; -} - -#col1 p { -font: normal 0.9em Arial, Verdana, Helvetica, sans-serif; -font-size:0.9em; -color: #000000; -padding:10px; -text-align:left; -} - -#col2 { -float:right; -background-color:#ffffff; -width:272px; -margin-top:20px; -padding:8px 0 8px 8px; -text-align:left; -font-size:0.9em; -} - - -#col2 p { -font: bold 0.9em Arial, Verdana, Helvetica, sans-serif; -font-size:0.8em; -color: #000000; -padding:10px; -text-align:left; -} - -#col2 .imagecol2 { -padding-left:0px; -padding-top:0px; -border:none; -} - -#help { - overflow: hidden; - position: absolute; - top: 5px; - left: 5px; - bottom: 5px; - right: 5px; - z-index: 5; - background-color: #FFFFCC; -} -#showHelp { - position: absolute; - top: 0; - left: 0; - bottom: 0; - right: 0; - background-color: #FFFFCC; - padding: 5px; - display: none; - overflow: auto; - border: 1px solid black; -} - -#teachForm, #uploadForm, #downloadForm, #membersForm { - position: absolute; - top: 0; - left: 0; - bottom: 0; - right: 20%; - z-index: 10; - display: block; -} - -#teachForm fieldset { border: none; } - -#demoChatContainer { - position: absolute; - left: 5px; - top: 35px; - bottom: 5px; - right: 5px; - overflow: hidden; -} -#demoChatTitle { - position: absolute; - left: 0; - top: 0; - width: 100%; - height: 40px; - margin: 0; - font-size: larger; - font-weight: bold; -} -#demoChat { - position: absolute; - left: 0; - top: 0; - bottom: 0; - right: 0; - width: 95%; - height: 90%; - padding: 5px; - margin: 0; -} -#footer { - position: absolute; - left: 25px; - right: 25px; - bottom: 10px; - height: 50px; - padding: 0; - background-color: #FFFFCC; -} - -#footer_content { - position: absolute; - left: 5%; - right: 5%; - top: 5%; - bottom: 5%; - text-align: center; - margin: 0; - padding: 0; -} - -#footer_content p { - font-size:0.8em; - font-weight:normal; - line-height: 1.1em; - color:#000; - margin: 0; - padding: 0; - /*padding-top: 3px;*/ - text-align:center; -} - -#footer_content a { - font-size:1em; - text-decoration:none; - font-weight:normal; - color:#467AA7; - text-align:center; -} - -#footer_content a:hover { - text-decoration:underline; - font-weight:normal; - color:#467AA7; - text-align:center; -} - -#container{ - margin: 0 auto; - padding: 1em; - text-align: left; - background-color: white; - overflow: auto; - position: absolute; - top: 160px; - left: 25px; - right: 25px; - bottom: 25px; -} -.helpButton { - background:url(http://github.com/images/help_small.png) no-repeat 0 0; - width: 18px; - height: 18px; -} - -div#AIML_List { - border: 2px inset #9FC03A; - margin-left: 22px; - padding: 12px; - text-align: left; - text-indent: 0; - width: 250px; - height: 300px; - overflow: auto; -} - -[disabled="disabled"] { /* Text and background colour, medium red on light yellow */ - color:#500; - background-color:#EDD; -} - -.floatRight { -/* float: right; - clear: none;*/ - width: 48%; -} -.floatLeft { -/* float: left; - clear: none;*/ - width: 48%; -} -table.botForm { - width: 99.5%; -} - -table.botForm span.label, table.botForm span.formw { - width: 48.5%; -} -table.botForm span.formw { - text-align: right; -} -table.botForm span.formw input { - width: 97%; -} -table.botForm td { - vertical-align: top; -} - -table td#notes { - text-align: left; background-color: #DDFFFF; border: 1px outset #999; padding-top: 2px; padding-bottom: 2px; - vertical-align: top; -} - - -.floatRight { - float: right; - clear: none; - } - -span.formw label { - white-space: nowrap; -} - +/* +My Program-O Version 2.0.9 +Program-O chatbot admin area +Written by Elizabeth Perreau and Dave Morton +Aug 2011 +for more information and support please visit www.program-o.com +*/ +html, body { + height: 100%; +} +body { + background-color: #9FC03A; + /*background-color: white;*/ + background-image: url(http://github.com/images/CompRule.png); + background-repeat: repeat; + background-image: url(http://github.com/images/repeated_header2.jpg); + background-repeat: repeat-x; + color: #000000; + margin: 0; + padding: 0; + width: 99.5%; + height: 99.5%; + overflow: hidden; +} +table td {vertical-align: top;} +fieldset { border: 1px solid orange; padding: 12px; padding-left: 5px; padding-right: 5px; line-height: 125%;} +legend { font-weight: bold; font-size: xx-large; margin-left: -5px; margin-top: -15px; } +label { cursor: pointer; margin-right: 20px; } +div.row { clear: both; padding-top: 8px; border: none; width: 95%; margin-left: auto; margin-right: auto; min-height: 2em;} +label { cursor: pointer; margin-right: 20px; } +.leftHalf table tr td, .rightHalf table tr td {vertical-align: top;} +div.row span.label {float: left; width: 49.5%; text-align: left; padding-left: 3px; background-color: #DDFFFF; border: 1px outset #999; padding-top: 3px; padding-bottom: 3px;} +div.row span.label:hover, div.row span.formw:hover {background-color: #EEE;} +td.label {text-align: left; padding-left: 3px; background-color: #DDFFFF; border: 1px outset #999; padding-top: 3px; padding-bottom: 3px; vertical-align: top;} +td.label:hover, div.row span.formw:hover {background-color: #EEE;} +td.label label {float: left; width: 100%; margin: 0; background-color: transparent;} +td.label span {float: right;} +td.label span.required {float: right;} +td.formw {text-align: left; background-color: #DDFFFF; border: 1px outset #999; padding-top: 2px; padding-bottom: 2px;} +td.formw input, div.row span.formw textarea { width: 94%; margin: 0 1%; } +td.formw input[type="radio"] { width: auto; margin-right: 5px; } +td.formw input[type="checkbox"], td.formw select { width: 95%; margin: 0; float: left; text-align: left; } +td.underline {border: 2px outset #666;border-top: 1px outset #666; border-left: 1px outset #666;} +div.row span.formw {float: right; clear: none; width: 49.5%; text-align: left; background-color: #DDFFFF; border: 1px outset #999; padding-top: 2px; padding-bottom: 2px;} +div.row span.formw input, div.row span.formw textarea { width: 150px; margin: 0; } +div.row span.formxw input, div.row span.formxw textarea { width: 80%; margin: 0; margin-left: 6px; margin-right: 2px; } +div.row span.formw select { width: 155px; margin: 0; } +div.row span.formxw select { width: 42%; margin: 0; } +div.row span.formw input.wide { width: 99.1%; margin: 0; } +div.row span.formw input[type=checkbox], div.row span.formw input[type=radio] { width: 15px; margin: 0; } +div.row span.formxw input[type=checkbox], div.row span.formxw input[type=radio] { width: 15px; margin: 0; text-align: left; margin-left: 6px; } +.leftHalf { width: 49%; float: left; } +.rightHalf { width: 49%; float: right; } +.leftHalf, .rightHalf { + border-right: 1px solid #666; + border-bottom: 2px solid #000; + padding-bottom: 2px; +} +.indent { text-indent: 1em; } +.fullWidth { width: 100%;} +.eightyPercent { width: 80%; } +span.eightyPercent input.wide { width: 67%; margin: 0; float: right; } +.twentyPercent { width: 20%; } +.noBorder { border: none; } +.testBorder { border: 1px solid red; } +.center { text-align: center; } +.bold { font-weight: bold; } +.big { font-size: larger; } +.narrow { padding-left: 0; float: left;width: 25%;text-align: left; border: 1px dashed blue;} +.closeButton { + position: absolute; + top: 3px; + right: 3px; + width: 32px; + height: 32px; + background: url(http://github.com/images/closeButton.png) no-repeat; + cursor: pointer; +} +.errMsg { + min-width: 250px; + max-width: 95%; + min-height: 32px; + max-height: 95%; + width: auto; + background-color: #FFF45A; + background-color: #FCC; /*transparent;*/ + color: black; + vertical-align: middle; + text-align: center; + padding: 5px; + margin: 0 auto; + display: none; + overflow: auto; + border: 6px outset #933; + position: absolute; + top: 15px; + right: 15px; + z-index: 99; + padding-right: 40px; + overflow: auto; +} +.errMsgContent { + overflow: auto; + width: 100%; + height: 100%; + position: absolute; + top: 0; + left: 0; +} + +.ul, .ll, .ur, .lr { + width: 6px; + height: 6px; + position: absolute; + background-color: transparent; + background-repeat: no-repeat; + z-index: 1; +} +.ul { top: 0; left: 0; background-image: url(http://github.com/images/ul.png); } +.ll { bottom: 0; left: 0; background-image: url(http://github.com/images/ll.png); } +.ur { top: 0; right: 0; background-image: url(http://github.com/images/ur.png); } +.lr { bottom: 0; right: 0; background-image: url(http://github.com/images/lr.png); } +.nav_header { + text-align: center; + padding-bottom: 3px; + border-bottom: 1px solid black; + width: 100%; +} +.red { + background-color: transparent; + color: red; + /*font-size: large; + font-weight: bold;*/ +} +.orange { background-color: transparent; color: orange } +.small { + font-size: smaller; +} +.validCSS { float: right; margin-top: 10px; } +.validXHTML { float: left; margin-top: 10px; margin-left: 5px; } +.userlist { + height: 80%; + overflow: auto; + padding-left: 5px; +} +.paginate { font-size: 0.8em; } +#form_table { width: 300px; margin-left: auto; margin-right: auto; margin-top: 20px; padding: 12px; height: 100px; } +#fm-form div label { float: left; } +#fm-form div input { float: right; margin-right: 10px; } +#title { + text-align: center; + font-size: x-large; + font-weight: bold; + position: absolute; + top: 125px; + left: 25px; + right: 25px; + /*width: 94%;*/ + height: 30px; + z-index: 100; + background-color: transparent; + background-image: url(http://github.com/images/bg_list.gif); + background-position: bottom; + background-repeat: repeat-x; + margin: 0; + padding: 0px; +} +#titlespan { + background-repeat: no-repeat; + background-position: center; + background-color: transparent; + color: white; + z-index: 50; + width: 100%; +} +#logo { + background-image: url(http://github.com/images/bg_header2.jpg); + background-repeat: no-repeat; + background-position: center 0; + /*background-color: white;*/ + width: 100%; + height: 140px; + border: none; + margin: 0; + padding: 0; + float: none; +} +#top_nav { + background-color: transparent; + height: 25px; + padding: 6px; + padding-top: 0; + text-align: center; + position: absolute; + top: 130px; + left: 25px; + right: 25px; +} +#top_nav ul { + list-style: none; + margin: 0; + padding:0; +} +#top_nav ul li { + display: inline; +} + +#top_nav ul li div { + width: 120px; + height: 25px; + position: relative; + background-color: #39A3C6; + display: inline-block; + vertical-align: middle; + padding: 0; + margin: 0; +} + +#top_nav ul li div a { + position: absolute; + left: 0; + top: 0; + right: 0; + bottom: 0; + background-color: transparent; + color: white; + line-height:1em; + margin: 0; + padding-top: 4px; + font-weight:normal; + font-size: 0.995em; + text-decoration: none; + vertical-align: middle; + width: 100%; + height: 100%; + border: 1px solid white; + border: none; +} +#top_nav ul li div:hover { + background-color: #FFF45A; +} +#top_nav ul li div a:hover { + color: black; +} +#top_nav ul li div.selected { + background-color: #FFF45A; + color: black; +} +#top_nav ul li div.selected:hover { + background-color: #FFF45A; +} +#top_nav ul li div.selected a { + color: black; +} + +#top_nav ul li div.ul, #top_nav ul li div.ll, #top_nav ul li div.ur, #top_nav ul li div.lr { + width: 6px; + height: 6px; + position: absolute; + background-color: transparent; + background-repeat: no-repeat; + z-index: 1; + border: none +} + +#left_nav { + background-color: #FFFFCC; + float: left; + position: absolute; + top: 160px; + left: 25px; + bottom: 70px; + width: 172px; + min-height: 25%; + overflow: auto; + margin: 0; + padding: 0; +} + +#left_nav ul { + margin: 0; + padding: 0; + margin-top: 5px; + /*border: 1px solid red;*/ +} +#left_nav ul li a { + text-align: left; + list-style: none; + background-image: url(http://github.com/images/bullet.gif); + background-repeat:no-repeat; + background-position:left center; + background-color: transparent; + display: block; + line-height:1.4em; + height:1.3em; + margin: 0px; + padding-top:6px; + padding-bottom:6px; + padding-left: 22px; + color: black; + font-weight:normal; + font-size: 0.8em; + text-decoration: none; + vertical-align: middle; +} +/* +*/ +#left_nav ul li a:hover { + background-image: url(http://github.com/images/bullet_hover.gif); + color: black; + background-color: #EEE8AA; +} + +#left_nav ul li a.selected:hover { + cursor: default; +} + +#right_nav { + background-color: #FFFFCC; + float: left; + position: absolute; + top: 160px; + right: 25px; + bottom: 70px; + width: 170px; + min-height: 25%; + overflow: hidden; + margin: 0; + padding: 0; +} + +#right_nav ul { + margin: 0; + padding: 0; + margin-top: 5px; + /*border: 1px solid red;*/ +} + +#right_nav ul li a { + text-align: right; + list-style: none; + background-image: url(http://github.com/images/bullet_right.gif); + background-repeat:no-repeat; + background-position:right center; + background-color: transparent; + display: block; + line-height:1.4em; + height:1.4em; + margin: 0px; + padding-top:6px; + padding-bottom:6px; + padding-right: 22px; + color: black; + font-weight:normal; + font-size: 0.8em; + text-decoration: none; + vertical-align: middle; +} +/* +*/ +#right_nav ul li a:hover { + background-image: url(http://github.com/images/bullet_right_hover.gif); + color: black; + background-color: #EEE8AA; +} + +#right_nav .selected, #left_nav .selected, #top_nav ul li a.selected { + color: black; + background-color: #E1D66C; +} + +#right_nav .selected:hover, #left_nav .selected:hover, #top_nav ul li a.selected:hover { + color: black; + background-color: #F2EDBD; + cursor: default; +} + +#wrapper { + width: 90%; + height: 90%; + margin: auto; + padding: 0; + /*background: url(http://github.com/images/red_trans.png) repeat; + border: 1px solid blue;*/ + overflow: hidden; +} +#main { + position: absolute; + top: 160px; + bottom: 70px; + left: 205px; + right: 205px; + background-color: transparent; + background-color: #FFFFCC; + overflow: hidden; + min-height: 25%; +} +#main_title { + text-align: center; + width: 99%; + height: 50px; + margin: 0; + font-size: large; + font-weight: bold; + font-variant: small-caps; +} +#main_content { + position: absolute; + top: 55px; + bottom: 5px; + left: 0; + right: 0; + text-indent: 1em; + overflow: auto; + padding-top: 5px; + padding-left: 5px; + background-color: pink; + background-color: #FFFFCC; + z-index: 3; +/* + width: 99%; +*/ +} + +#rssContainer { + width: 98.5%; + min-height: 300px; + position: absolute; + top: 40px; + left: 0; + right: 0; + bottom: 0; + border: none; + overflow: hidden; +} +#rssTitle { + width: 100%; + height: 35px; + position: absolute; + left: 0; + top: 0; + text-align: center; + font-weight: bold; + font-size: larger; +} +#rssOutput { + position: absolute; + left: 0; + right: 0; + top: 35px; + bottom: 0; + overflow: auto; + padding: 5px; +} + +#col1 { +float:left; +width:410px; +margin-right:0px; +margin-top:20px; +background-color:inherit; +text-align:left; +font-size:0.9em; +padding:5px; +} + +#nocol { +float:left; +width:98%; +margin-right:0px; +margin-top:20px; +text-align:left; +font-size:0.9em; +padding:5px; +} + +#col1 h1 { +display:block; +font-size:0.9em; +width:50px; +font-family: arial; +text-align:left; +font-weight:bold; +color:#403f3b; +font-family:arial; +font-weight:bold; +padding:5px; +margin-top:5px; +margin-left:12px; +} + +#col1 p { +font: normal 0.9em Arial, Verdana, Helvetica, sans-serif; +font-size:0.9em; +color: #000000; +padding:10px; +text-align:left; +} + +#col2 { +float:right; +background-color:#ffffff; +width:272px; +margin-top:20px; +padding:8px 0 8px 8px; +text-align:left; +font-size:0.9em; +} + + +#col2 p { +font: bold 0.9em Arial, Verdana, Helvetica, sans-serif; +font-size:0.8em; +color: #000000; +padding:10px; +text-align:left; +} + +#col2 .imagecol2 { +padding-left:0px; +padding-top:0px; +border:none; +} + +#help { + top: 5px; + overflow: hidden; + position: absolute; + top: 5px; + left: 5px; + bottom: 5px; + right: 5px; +/* +*/ + z-index: 5; + background-color: transparent; + background-color: #FFFFCC; +} +#showHelp { + position: absolute; + top: 5px; + left: 0; + bottom: 5px; + right: 0; + background-color: #FFFFCC; + padding: 5px; + display: none; + overflow: auto; + border: none; +} + +#teachForm, #uploadForm, #downloadForm, #membersForm { + position: absolute; + top: 0; + left: 0; + bottom: 0; + right: 20%; + z-index: 10; + display: block; + /*background-color: red;*/ + overflow: auto; +} + +#teachForm p, #uploadForm p, #downloadForm p, #membersForm p { + padding: 5px; +} + +#teachForm fieldset { border: none; } + +#demoChatContainer { + position: absolute; + left: 5px; + top: 35px; + bottom: 5px; + right: 5px; + overflow: hidden; +} +#demoChatTitle { + position: absolute; + left: 0; + top: 0; + width: 100%; + height: 40px; + margin: 0; + font-size: larger; + font-weight: bold; +} +#demoChat { + position: absolute; + left: 0; + top: 0; + bottom: 0; + right: 0; + width: 95%; + height: 90%; + padding: 5px; + margin: 0; +} +#footer { + position: absolute; + left: 25px; + right: 25px; + bottom: 10px; + height: 50px; + padding: 0; + background-color: #FFFFCC; +} + +#footer_content { + position: absolute; + left: 5%; + right: 5%; + top: 5%; + bottom: 5%; + text-align: center; + margin: 0; + padding: 0; +} + +#footer_content p { + font-size:0.8em; + font-weight:normal; + line-height: 1.1em; + color:#000; + margin: 0; + padding: 0; + /*padding-top: 3px;*/ + text-align:center; +} + +#footer_content a { + font-size:1em; + text-decoration:none; + font-weight:normal; + color:#467AA7; + text-align:center; +} + +#footer_content a:hover { + text-decoration:underline; + font-weight:normal; + color:#467AA7; + text-align:center; +} + +#container{ + margin: 0 auto; + padding: 1em; + text-align: left; + background-color: white; + overflow: auto; + position: absolute; + top: 160px; + left: 25px; + right: 25px; + bottom: 25px; +} +.helpButton { + background:url(http://github.com/images/help_small.png) no-repeat 0 0; + width: 18px; + height: 18px; + padding: 0; + margin: 0; +} + +div#AIML_List { + border: 2px inset #9FC03A; + border: none; + margin: 10px auto; + padding: 12px; + text-align: left; + text-indent: 0; + width: auto%; + max-height: 300px; + overflow: auto; +} + +[disabled="disabled"] { /* Text and background colour, medium red on light yellow */ + color:#500; + background-color:#EDD; +} + +.floatRight { +/* float: right; + clear: none;*/ + width: 48%; +} +.floatLeft { +/* float: left; + clear: none;*/ + width: 48%; +} +table.botForm { + width: 99.5%; +} + +table.botForm span.label, table.botForm span.formw { + width: 48.5%; +} +table.botForm span.formw { + text-align: right; +} +table.botForm span.formw input { + width: 97%; +} +table.botForm td { + vertical-align: top; +} + +table td#notes { + text-align: left; background-color: #DDFFFF; border: 1px outset #999; padding-top: 2px; padding-bottom: 2px; + vertical-align: top; +} + +#notes { + text-align: left; background-color: pink; border: none; height: 80px; +} + +#notes div {background-color: transparent; border: none; height: 20px; margin: 3px; padding: 2px;} + +.floatRight { + float: right; + clear: none; + } + +#helpLink1 {float: left; margin-bottom: 10px;} +td input, td select { + width: 95%; + margin: 0 auto; +} +.formTable { + border: 1px solid orange; + border: none; + width: 98%; + margin: 10px auto; + padding: 5px; +} +.formTable td { + padding: 3px; + border: 1px solid green; + border: none; + margin: 2px; + padding: 2px; +} +.formTable td select { width: 96.2%; margin: 0 auto; } +.formTable td textarea, .formTable td input[type=text] { width: 95%; margin: 0 auto; } +.formTable td textarea { height: 45px; } +.formTable td input[type=submit] { width: auto; } +.formTable td span { width: 100%; text-align: left; margin: 0 auto; padding: 0; } + +select#bot_id { width: auto; min-width: 30%; } + +#script_version{position: absolute;top: 5px;left: 5px;} + diff --git a/admin/support.php b/admin/support.php new file mode 100644 index 0000000..b01e7ef --- /dev/null +++ b/admin/support.php @@ -0,0 +1,47 @@ +getSection('NoRightNav'); + $logo = $template->getSection('Logo'); + $topNav = $template->getSection('TopNav'); + $leftNav = $template->getSection('LeftNav'); + $main = $template->getSection('Main'); + $rightNav = ''; + $footer = trim($template->getSection('Footer')); + #$lowerScripts = ''; + #$pageTitleInfo = ''; + $divDecoration = $template->getSection('DivDecoration'); + $topNavLinks = makeLinks('top', $topLinks, 12); + $navHeader = $template->getSection('NavHeader'); + $leftNavLinks = makeLinks('left', $leftLinks, 12); + $mainTitle = 'Program O Support'; + $rightNavLinks = ''; + $FooterInfo = getFooter(); + $titleSpan = $template->getSection('TitleSpan'); + $errMsgStyle = (!empty($msg)) ? "ShowError" : "HideError"; + $errMsgStyle = $template->getSection($errMsgStyle); + $mediaType = ' media="screen"'; + $upperScripts = ''; + $noLeftNav = ''; + $noTopNav = ''; + $pageTitle = 'My-Program O - Support Page'; + $headerTitle = 'Actions:'; + $forumURL = FORUM_URL; + $mainContent = << +
        + For specific support questions, please use the Program O Forums and post your question.
        + Below are the most recent forum posts: +
        +
        [rssOutput]
        + +endMain; + $mainContent = str_replace('[rssOutput]', getRSS('support'), $mainContent); + +?> \ No newline at end of file diff --git a/admin/teach.php b/admin/teach.php index a6a5d7d..59db589 100644 --- a/admin/teach.php +++ b/admin/teach.php @@ -1,107 +1,110 @@ - - - -endScript; - - $msg = ''; - if((isset($_POST['action']))&&($_POST['action']=="teach")) { - $msg = insertAIML(); - } - $teachContent = $template->getSection('TeachBotForm'); - $showHelp = $template->getSection('TeachShowHelp'); - #$teachContent = ''; - #$showHelp = ''; - - $topNav = $template->getSection('TopNav'); - $leftNav = $template->getSection('LeftNav'); - $main = $template->getSection('Main'); - $topNavLinks = makeLinks('top', $topLinks, 12); - $navHeader = $template->getSection('NavHeader'); - $leftNavLinks = makeLinks('left', $leftLinks, 12); - $FooterInfo = getFooter(); - $errMsgClass = (!empty($msg)) ? "ShowError" : "HideError"; - $errMsgStyle = $template->getSection($errMsgClass); - $noLeftNav = ''; - $noTopNav = ''; - $noRightNav = $template->getSection('NoRightNav'); - $headerTitle = 'Actions:'; - $pageTitle = 'My-Program O - Teaching Interface'; - $mainContent = $template->getSection('TeachMain'); - #die ("main content =
        |$mainContent|

        \n"); - #$mainContent = 'Hello!'; - $mainTitle = "Chatbot Teaching Interface for $bot_name [helpLink]"; - - $mainContent = str_replace('[bot_name]', $bot_name, $mainContent); - $mainContent = str_replace('[teach_content]', $teachContent, $mainContent); - $mainContent = str_replace('[showHelp]', $showHelp, $mainContent); - $mainTitle = str_replace('[helpLink]', $template->getSection('HelpLink'), $mainTitle); - - -function insertAIML() { - //db globals - global $template, $msg; - $dbconn = db_open(); - - $template = mysql_escape_string(trim($_POST['template'])); - $pattern = strtoupper(mysql_escape_string(trim($_POST['pattern']))); - $thatpattern = strtoupper(mysql_escape_string(trim($_POST['thatpattern']))); - $topic = strtoupper(mysql_escape_string(trim($_POST['topic']))); - $bot_id = (isset($_SESSION['poadmin']['bot_id'])) ? $_SESSION['poadmin']['bot_id'] : 0; - if(($pattern=="") || ($template=="")) { - $msg = 'You must enter a user input and bot response.'; - } - else { - $sql = "INSERT INTO `aiml` (`id`,`bot_id`, `pattern`,`thatpattern`,`template`,`topic`,`filename`) VALUES (NULL,'$bot_id','$pattern','$thatpattern','$template','$topic','ADMIN ADDED')"; - $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); - - if($result) { - $msg = "AIML added."; - } - else { - $msg = "There was a problem adding the AIML - no changes made."; - } - } - mysql_close($dbconn); - - return $msg; -} - + + + +endScript; + + $msg = ''; + if((isset($_POST['action']))&&($_POST['action']=="teach")) { + $msg = insertAIML(); + } + $teachContent = $template->getSection('TeachBotForm'); + $showHelp = $template->getSection('TeachShowHelp'); + #$teachContent = ''; + #$showHelp = ''; + + $topNav = $template->getSection('TopNav'); + $leftNav = $template->getSection('LeftNav'); + $main = $template->getSection('Main'); + $topNavLinks = makeLinks('top', $topLinks, 12); + $navHeader = $template->getSection('NavHeader'); + $leftNavLinks = makeLinks('left', $leftLinks, 12); + $FooterInfo = getFooter(); + $errMsgClass = (!empty($msg)) ? "ShowError" : "HideError"; + $errMsgStyle = $template->getSection($errMsgClass); + $noLeftNav = ''; + $noTopNav = ''; + $noRightNav = $template->getSection('NoRightNav'); + $headerTitle = 'Actions:'; + $pageTitle = 'My-Program O - Teaching Interface'; + $mainContent = $template->getSection('TeachMain'); + #die ("main content =
        |$mainContent|

        \n"); + #$mainContent = 'Hello!'; + $mainTitle = "Chatbot Teaching Interface for $bot_name [helpLink]"; + + $mainContent = str_replace('[bot_name]', $bot_name, $mainContent); + $mainContent = str_replace('[teach_content]', $teachContent, $mainContent); + $mainContent = str_replace('[showHelp]', $showHelp, $mainContent); + $mainTitle = str_replace('[helpLink]', $template->getSection('HelpLink'), $mainTitle); + + +function insertAIML() { + //db globals + global $template, $msg; + $dbconn = db_open(); + $aiml = "[pattern][thatpattern]"; + $aimltemplate = mysql_real_escape_string(trim($_POST['template'])); + $pattern = strtoupper(mysql_real_escape_string(trim($_POST['pattern']))); + $thatpattern = strtoupper(mysql_real_escape_string(trim($_POST['thatpattern']))); + $aiml = str_replace('[pattern]', $pattern, $aiml); + $aiml = (empty($thatpattern)) ? str_replace('[thatpattern]', "$thatpattern", $aiml) : $aiml; + $aiml = str_replace('[template]', $aimltemplate, $aiml); + $topic = strtoupper(mysql_real_escape_string(trim($_POST['topic']))); + $bot_id = (isset($_SESSION['poadmin']['bot_id'])) ? $_SESSION['poadmin']['bot_id'] : 1; + if(($pattern=="") || ($template=="")) { + $msg = 'You must enter a user input and bot response.'; + } + else { + $sql = "INSERT INTO `aiml` (`id`,`bot_id`, `aiml`, `pattern`,`thatpattern`,`template`,`topic`,`filename`, `php_code`) VALUES (NULL,'$bot_id', '$aiml','$pattern','$thatpattern','$aimltemplate','$topic','admin_added.aiml', '')"; + $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); + + if($result) { + $msg = "AIML added."; + } + else { + $msg = "There was a problem adding the AIML - no changes made."; + } + } + mysql_close($dbconn); + + return $msg; +} + ?> \ No newline at end of file diff --git a/admin/upload.php b/admin/upload.php index ce98207..84d31b9 100644 --- a/admin/upload.php +++ b/admin/upload.php @@ -1,231 +1,390 @@ - - - -endScript; - - $XmlEntities = array( - '&' => '&', - '<' => '<', - '>' => '>', - ''' => '\'', - '"' => '"', - ); - - $g_tagName = null; - $aiml_sql = ""; - $pattern_sql = ""; - $that_sql = ""; - $template_sql = ""; - $insert_sql = ""; - $file = ""; - $full_path = ""; - $cat_counter = 0; - $AIML_List = getAIML_List(); - $uploadContent = $template->getSection('UploadAIMLForm'); - $showHelp = $template->getSection('UploadShowHelp'); - - $topNav = $template->getSection('TopNav'); - $leftNav = $template->getSection('LeftNav'); - $main = $template->getSection('Main'); - $topNavLinks = makeLinks('top', $topLinks, 12); - $navHeader = $template->getSection('NavHeader'); - $leftNavLinks = makeLinks('left', $leftLinks, 12); - $FooterInfo = getFooter(); - $errMsgClass = (!empty($msg)) ? "ShowError" : "HideError"; - $errMsgStyle = $template->getSection($errMsgClass); - $noLeftNav = ''; - $noTopNav = ''; - $noRightNav = $template->getSection('NoRightNav'); - $headerTitle = 'Actions:'; - $pageTitle = 'My-Program O - Upload AIML'; - $mainContent = $template->getSection('UploadMain'); - $mainTitle = "Upload AIML to use for the bot named $bot_name [helpLink]"; - - $mainContent = str_replace('[bot_name]', $bot_name, $mainContent); - $mainContent = str_replace('[upload_content]', $uploadContent, $mainContent); - $mainContent = str_replace('[showHelp]', $showHelp, $mainContent); - $mainContent = str_replace('[AIML_List]', $AIML_List, $mainContent); - $mainTitle = str_replace('[helpLink]', $template->getSection('HelpLink'), $mainTitle); - - function parseAIML ($file) { - if (empty($file)) return ""; - global $debugmode, $bot_id; - $fileName = basename($file); - $success = false; - $dbconn = db_open(); - #Clear the database of the old entries - $sql = "DELETE FROM `aiml` WHERE `filename` = '$fileName' AND bot_id = '$bot_id'"; - if(isset($_POST['clearDB'])) { - $x = updateDB($sql); - } - # Read new file into the XML parser - $fileName = basename($file); - $sql_start = "insert into `aiml` (`id`, `bot_id`, `aiml`, `pattern`, `thatpattern`, `template`, `topic`, `filename`, `php_code`) values\n"; - $sql = $sql_start; - $sql_template = "(NULL, $bot_id, '[aiml_add]', '[pattern]', '[that]', '[template]', '[topic]', '$fileName', ''),\n"; - $aimlFile = file_get_contents($file); - $aiml = new SimpleXMLElement($aimlFile); - $rowCount = 0; - if (!empty($aiml->topic)) { - foreach ($aiml->topic as $topicXML) { # handle any topic tag(s) in the file - $topicAttributes = $topicXML->attributes(); - $topic = $topicAttributes['name']; - #$topicName = $topicXML->getName(); - foreach ($topicXML->category as $category) { - $fullCategory = $category->asXML(); - $pattern = $category->pattern; - $that = $category->that; - $template = $category->template->asXML(); - $template = str_replace('', '', $template); - $aiml_add = str_replace("\r\n", '', $fullCategory); # Strip CRLF from category (windows) - $aiml_add = str_replace("\n", '', $aiml_add); # Strip LF from category (mac/*nix) - $sql_add = str_replace('[aiml_add]', mysql_escape_string($aiml_add), $sql_template); - $sql_add = str_replace('[pattern]', $pattern, $sql_add); - $sql_add = str_replace('[that]', $that, $sql_add); - $sql_add = str_replace('[template]', mysql_escape_string($template), $sql_add); - $sql_add = str_replace('[topic]', $topic, $sql_add); - $sql .= "$sql_add"; - $rowCount++; - if ($rowCount >= 100) { - $rowCount = 0; - $sql = rtrim($sql, ",\n") . ';'; - $success = (updateDB($sql) >=0) ? true : false; - $sql = $sql_start; - } - } - } - } - if (!empty($aiml->category)) { - foreach ($aiml->category as $category) { - $fullCategory = $category->asXML(); - $pattern = $category->pattern; - $that = $category->that; - $template = $category->template->asXML(); - $template = str_replace('', '', $template); - $aiml_add = str_replace("\r\n", '', $fullCategory); # Strip CRLF from category (windows) - $aiml_add = str_replace("\n", '', $aiml_add); # Strip LF from category (mac/*nix) - $sql_add = str_replace('[aiml_add]', mysql_escape_string($aiml_add), $sql_template); - $sql_add = str_replace('[pattern]', $pattern, $sql_add); - $sql_add = str_replace('[that]', $that, $sql_add); - $sql_add = str_replace('[template]', mysql_escape_string($template), $sql_add); - $sql_add = str_replace('[topic]', '', $sql_add); - $sql .= "$sql_add"; - $rowCount++; - if ($rowCount >= 100) { - $rowCount = 0; - $sql = rtrim($sql, ",\n") . ';'; - $success = (updateDB($sql) >=0) ? true : false; - $sql = $sql_start; - } - } - } - if ($sql != $sql_start) { - $sql = rtrim($sql, ",\n") . ';'; - $success = (updateDB($sql) >=0) ? true : false; - } - $msg = "There was a problem adding file $fileName to the database."; - if ($success) $msg = "Successfully added $fileName to the database."; - return $msg; - } - - function updateDB($sql) { - $dbconn = db_open(); - $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL =
        $sql

        \n"); - $commit = mysql_affected_rows($dbconn); - return $commit; - } - - - function processUpload() { - global $msg; - // Validate the uploaded file - if($_FILES['aimlfile']['size'] === 0 or empty($_FILES['aimlfile']['tmp_name'])) { - $msg = 'No file was selected.'; - } - elseif($_FILES['aimlfile']['size'] > 2000000) { - $msg = 'The file was too large.'; - } - else if($_FILES['aimlfile']['error'] !== UPLOAD_ERR_OK) { - // There was a PHP error - $msg = 'There was an error uploading.'; - } - else { - // Create uploads directory if necessary - if(!file_exists('uploads')) mkdir('uploads'); - // Move the file - $file = './uploads/' . $_FILES['aimlfile']['name']; - if(move_uploaded_file($_FILES['aimlfile']['tmp_name'], $file)) { - return $file; - } - else { - $msg = 'There was an error moving the file.'; - } - } - die($msg); - } - - function getAIML_List() { - global $dbn; - $out = " \n"; - $dbconn = db_open(); - $sql = 'SELECT DISTINCT filename FROM aiml order by filename;'; - $result = mysql_query($sql,$dbconn) or die(mysql_error()); - while ($row = mysql_fetch_assoc($result)) { - if (empty($row['filename'])) { - $curOption = " No Filename entry
        \n"; - } - else $out .= $row['filename'] . "
        \n"; - } - mysql_close($dbconn); - $out .= " \n"; - return $out; - } - - - + + + +endScript; + + $XmlEntities = array('&' => '&', '<' => '<', '>' => '>', ''' => '\'', '"' => '"',); + $g_tagName = null; + $aiml_sql = ""; + $pattern_sql = ""; + $that_sql = ""; + $template_sql = ""; + $insert_sql = ""; + $file = ""; + $full_path = ""; + $cat_counter = 0; + $AIML_List = getAIML_List(); + $all_bots = getBotList(); + $uploadContent = $template->getSection('UploadAIMLForm'); + $showHelp = $template->getSection('UploadShowHelp'); + $topNav = $template->getSection('TopNav'); + $leftNav = $template->getSection('LeftNav'); + $main = $template->getSection('Main'); + $topNavLinks = makeLinks('top', $topLinks, 12); + $navHeader = $template->getSection('NavHeader'); + $leftNavLinks = makeLinks('left', $leftLinks, 12); + $FooterInfo = getFooter(); + $errMsgClass = (!empty ($msg)) ? "ShowError" : "HideError"; + $errMsgStyle = $template->getSection($errMsgClass); + $noLeftNav = ''; + $noTopNav = ''; + $noRightNav = $template->getSection('NoRightNav'); + $headerTitle = 'Actions:'; + $pageTitle = 'My-Program O - Upload AIML'; + $mainContent = $template->getSection('UploadMain'); + $mainTitle = "Upload AIML to use for the bot named $bot_name [helpLink]"; + #$msg = (empty($msg)) ? 'Test' : $msg; + $mainContent = str_replace('[bot_name]', $bot_name, $mainContent); + $mainContent = str_replace('[mainTitle]', $mainTitle, $mainContent); + $mainContent = str_replace('[upload_content]', $uploadContent, $mainContent); + $mainContent = str_replace('[showHelp]', $showHelp, $mainContent); + $mainContent = str_replace('[AIML_List]', $AIML_List, $mainContent); + $mainContent = str_replace('[all_bots]', $all_bots, $mainContent); + $mainTitle = str_replace('[helpLink]', $template->getSection('HelpLink'), $mainTitle); + $mainTitle = str_replace('[errMsg]', $msg, $mainTitle); + + function parseAIML($fn,$aimlContent) + { + if (empty ($aimlContent)) + return "File $fn was empty!"; + global $debugmode, $bot_id, $default_charset; + $fileName = basename($fn); + $success = false; + $dbconn = db_open(); + #Clear the database of the old entries + $sql = "DELETE FROM `aiml` WHERE `filename` = '$fileName' AND bot_id = '$bot_id'"; + if (isset ($_POST['clearDB'])) + { + $x = updateDB($sql); + } + $myBot_id = (isset ($_POST['bot_id'])) ? $_POST['bot_id'] : $bot_id; + # Read new file into the XML parser + $sql_start = "insert into `aiml` (`id`, `bot_id`, `aiml`, `pattern`, `thatpattern`, `template`, `topic`, `filename`, `php_code`) values\n"; + $sql = $sql_start; + $sql_template = "(NULL, $myBot_id, '[aiml_add]', '[pattern]', '[that]', '[template]', '[topic]', '$fileName', ''),\n"; + # Validate the incoming document + + /*******************************************************/ + /* Set up for validation from a common DTD */ + /* This will involve removing the XML and */ + /* AIML tags from the beginning of the file */ + /* and replacing them with our own tags */ + /*******************************************************/ + $validAIMLHeader = ' + +'; + $validAIMLHeader = str_replace('[charset]', $default_charset, $validAIMLHeader); + $aimlTagStart = stripos($aimlContent, '', $aimlTagStart) + 1; + $aimlFile = $validAIMLHeader . substr($aimlContent, $aimlTagEnd); + //die('
        ' . htmlentities("File contents:
        \n$aimlFile")); + try + { + libxml_use_internal_errors(true); + $xml = new DOMDocument(); + $xml->loadXML($aimlFile); + //$xml->validate(); + $aiml = new SimpleXMLElement($xml->saveXML()); + $rowCount = 0; + if (!empty ($aiml->topic)) + { + foreach ($aiml->topic as $topicXML) + { + # handle any topic tag(s) in the file + $topicAttributes = $topicXML->attributes(); + $topic = $topicAttributes['name']; + foreach ($topicXML->category as $category) + { + $fullCategory = $category->asXML(); + $pattern = $category->pattern; + $pattern = str_replace("'", ' ', $pattern); + $that = $category->that; + $template = $category->template->asXML(); + $template = str_replace('', '', $template); + $aiml_add = str_replace("\r\n", '', $fullCategory); + # Strip CRLF from category (windows) + $aiml_add = str_replace("\n", '', $aiml_add); + # Strip LF from category (mac/*nix) + $sql_add = str_replace('[aiml_add]', mysql_real_escape_string($aiml_add), $sql_template); + $sql_add = str_replace('[pattern]', $pattern, $sql_add); + $sql_add = str_replace('[that]', $that, $sql_add); + $sql_add = str_replace('[template]', mysql_real_escape_string($template), $sql_add); + $sql_add = str_replace('[topic]', $topic, $sql_add); + $sql .= "$sql_add"; + $rowCount++; + if ($rowCount >= 100) + { + $rowCount = 0; + $sql = rtrim($sql, ",\n") . ';'; + $success = (updateDB($sql) >= 0) ? true : false; + $sql = $sql_start; + } + } + } + } + if (!empty ($aiml->category)) + { + foreach ($aiml->category as $category) + { + $fullCategory = $category->asXML(); + $pattern = $category->pattern; + $pattern = str_replace("'", ' ', $pattern); + $that = $category->that; + $template = $category->template->asXML(); + $template = str_replace('', '', $template); + $aiml_add = str_replace("\r\n", '', $fullCategory); + # Strip CRLF from category (windows) + $aiml_add = str_replace("\n", '', $aiml_add); + # Strip LF from category (mac/*nix) + $sql_add = str_replace('[aiml_add]', mysql_real_escape_string($aiml_add), $sql_template); + $sql_add = str_replace('[pattern]', $pattern, $sql_add); + $sql_add = str_replace('[that]', $that, $sql_add); + $sql_add = str_replace('[template]', mysql_real_escape_string($template), $sql_add); + $sql_add = str_replace('[topic]', '', $sql_add); + $sql .= "$sql_add"; + $rowCount++; + if ($rowCount >= 100) + { + $rowCount = 0; + $sql = rtrim($sql, ",\n") . ';'; + $success = (updateDB($sql) >= 0) ? true : false; + $sql = $sql_start; + } + } + } + if ($sql != $sql_start) + { + $sql = rtrim($sql, ",\n") . ';'; + $success = (updateDB($sql) >= 0) ? true : false; + } + $msg = "Successfully added $fileName to the database.
        \n"; + } + catch (Exception $e) + { + $success = false; + $msg = "There was a problem adding file $fileName to the database. Please validate the file and try again.
        \n"; + $msg = libxml_display_errors($msg); + } + return $msg; + } + + function updateDB($sql) + { + $dbconn = db_open(); + $result = mysql_query($sql, $dbconn) or die('You have a SQL error on line ' . __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL =
        " . htmlentities($sql) . "

        \n"); + $commit = mysql_affected_rows($dbconn); + return $commit; + } + + function processUpload() + { + global $msg; + // Validate the uploaded file + if ($_FILES['aimlfile']['size'] === 0 or empty ($_FILES['aimlfile']['tmp_name'])) + { + $msg = 'No file was selected.'; + } + elseif ($_FILES['aimlfile']['size'] > 2000000) + { + $msg = 'The file was too large.'; + } + else + if ($_FILES['aimlfile']['error'] !== UPLOAD_ERR_OK) + { + // There was a PHP error + $msg = 'There was an error uploading.'; + } + else + { + // Create uploads directory if necessary + if (!file_exists('uploads')) + mkdir('uploads'); + // Move the file + $file = './uploads/' . $_FILES['aimlfile']['name']; + if (move_uploaded_file($_FILES['aimlfile']['tmp_name'], $file)) + { + if ($_FILES['aimlfile']['type'] == 'application/zip') return processZip($file); + else return parseAIML($file,file_get_contents($file)); + } + else + { + $msg = 'There was an error moving the file.'; + } + } + //die($msg); + $_SESSION['errorMessage'] = $msg; + } + + function getAIML_List() + { + global $dbn, $bot_id; + $out = " \n"; + $dbconn = db_open(); + $sql = "SELECT DISTINCT filename FROM `aiml` where `bot_id` = $bot_id order by `filename`;"; + $result = mysql_query($sql, $dbconn) or die(mysql_error()); + while ($row = mysql_fetch_assoc($result)) + { + if (empty ($row['filename'])) + { + $curOption = " No Filename entry
        \n"; + } + else + $out .= $row['filename'] . "
        \n"; + } + mysql_close($dbconn); + $out .= " \n"; + return $out; + } + + function getBotList() + { + global $dbn, $bot_id; + $botOptions = ''; + $dbconn = db_open(); + $sql = 'SELECT `bot_name`, `bot_id` FROM `bots` order by `bot_id`;'; + $result = mysql_query($sql, $dbconn) or die(mysql_error()); + while ($row = mysql_fetch_assoc($result)) + { + $bn = $row['bot_name']; + $bi = $row['bot_id']; + $sel = ($bot_id == $bi) ? ' selected="selected"' : ''; + $botOptions .= " $bn\n"; + } + mysql_close($dbconn); + return $botOptions; + } + + function libxml_display_errors($msg) + { + $errors = libxml_get_errors(); + //die ('Errors = ' . print_r($errors)); + foreach ($errors as $error) + { + $msg .= libxml_display_error($error) . "
        \n"; + } + libxml_clear_errors(); + return $msg; + } + + function libxml_display_error($error) + { + $out = "
        \n"; + switch ($error->level) + { + case LIBXML_ERR_WARNING : + $out .= "Warning $error->code: "; + break; + case LIBXML_ERR_ERROR : + $out .= "Error $error->code: "; + break; + case LIBXML_ERR_FATAL : + $out .= "Fatal Error $error->code: "; + break; + } + $out .= trim($error->message); + if ($error->file) + { + $out .= " in $error->file"; + } + $out .= " on line $error->line\n"; + return $out; + } + + function processZip($fileName) + { + $out = ''; + $zipName = basename($fileName); + $zip = new ZipArchive; + $res = $zip->open($fileName); + if ($res === TRUE) { + $numFiles = $zip->numFiles; + for ($loop = 0; $loop < $numFiles-1; $loop++) + { + $curName = $zip->getNameIndex($loop); + if (strstr($curName, '/') !== false) + { + $endPos = strrpos($curName, '/') + 1; + $curName = substr($curName, $endPos); + } + if (empty($curName)) continue; + $fp = $zip->getStream($zip->getNameIndex($loop)); + if(!$fp) + { + $out .= "Processing for $curName failed.
        \n"; + } + else + { + $curText = ''; + while (!feof($fp)) + { + $curText .= fread($fp, 8192); + } + fclose($fp); + $out .= "Processing file $curName
        \n"; + if (!stristr($curName, '.aiml')) + { + $out .= "file $curName is not an AIML file - Ignoring.
        \n"; + continue; + } + $out .= parseAIML($curName, $curText); + } + } + $zip->close(); + $out .= "Upload complete. $numFiles files were processed.
        \n"; + } + else + { + $out = "Upload failed. $fileName was either corrupted, or not a zip file." ; + } + return $out; + } + ?> \ No newline at end of file diff --git a/admin/wordcensor.php b/admin/wordcensor.php index 6b160ae..b9079f6 100644 --- a/admin/wordcensor.php +++ b/admin/wordcensor.php @@ -1,303 +1,307 @@ - - -endScript; - - $group = (isset($_GET['group'])) ? $_GET['group'] : 1; - $content = $template->getSection('SearchWordCensorForm'); - if (isset($_REQUEST['action'])) { - switch($_REQUEST['action']) { - case 'search': - $content .= runWordCensorSearch(); - $content .= wordCensorForm(); - break; - case 'update': - $x = updateWordCensor(); - $content .= wordCensorForm(); - break; - case 'del': - $content .= (isset($_GET['id']))&&($_GET['id']!="") ? delWordCensor($_GET['id']) . wordCensorForm() : wordCensorForm(); - break; - case 'edit': - $content .= (isset($_GET['id']))&&($_GET['id']!="") ? editWordCensorForm($_GET['id']) : wordCensorForm(); - break; - case 'add': - $x = insertWordCensor(); - $content .= wordCensorForm(); - break; - default: - $content .= wordCensorForm(); - } - } - else { - $content .= wordCensorForm(); - } - $content = str_replace('[group]', $group, $content); - - $topNav = $template->getSection('TopNav'); - $leftNav = $template->getSection('LeftNav'); - $main = $template->getSection('Main'); - $topNavLinks = makeLinks('top', $topLinks, 12); - $navHeader = $template->getSection('NavHeader'); - $rightNav = $template->getSection('RightNav'); - $leftNavLinks = makeLinks('left', $leftLinks, 12); - $rightNavLinks = getWordCensorWords(); - $FooterInfo = getFooter(); - $errMsgClass = (!empty($msg)) ? "ShowError" : "HideError"; - $errMsgStyle = $template->getSection($errMsgClass); - $noLeftNav = ''; - $noTopNav = ''; - $noRightNav = ''; - $headerTitle = 'Actions:'; - $pageTitle = 'My-Program O - Word Censor Editor'; - $mainContent = $content; - $mainTitle = 'Word Censor Editor'; - - $mainContent = str_replace('[wordCensorForm]', wordCensorForm(), $mainContent); - $rightNav = str_replace('[rightNavLinks]', $rightNavLinks, $rightNav); - $rightNav = str_replace('[navHeader]', $navHeader, $rightNav); - $rightNav = str_replace('[headerTitle]', paginate(), $rightNav); - - function paginate() { - $dbConn = db_open(); - $sql = "select count(*) from `wordcensor` where 1"; - $result = mysql_query($sql) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); - $row = mysql_fetch_array($result); - $rowCount = $row[0]; - mysql_close($dbConn); - $lastPage = intval($rowCount / 50); - $remainder = ($rowCount / 50) - $lastPage; - if ($remainder > 0) $lastPage++; - #die ("Session values:
        \n" . print_r($_SESSION, true) . "
        \nCount = $count
        \n"); - $out = "Censored Words
        \n50 words per page:
        \n"; - $link=" - [label]"; - $curStart = (isset($_GET['group'])) ? $_GET['group'] : 1; - $firstPage = 1; - $prev = ($curStart > ($firstPage + 1)) ? $curStart - 1 : -1; - $next = ($lastPage > ($curStart + 1)) ? $curStart + 1 : -1; - $firstLink = ($firstPage != $curStart) ? str_replace('[group]', '1', $link) : ''; - $prevLink = ($prev > 0) ? str_replace('[group]', $prev, $link) : ''; - $curLink = "- $curStart "; - if (empty($firstLink) and empty($prevLink)) $curLink = $curStart; - $nextLink = ($next > 0) ? str_replace('[group]', $next, $link) : ''; - $lastLink = ($lastPage > $curStart) ? str_replace('[group]', $lastPage, $link) : ''; - $firstLink = str_replace('[label]', 'first', $firstLink); - $prevLink = str_replace('[label]', '<<', $prevLink); - $nextLink = str_replace('[label]', '>>', $nextLink); - $lastLink = str_replace('[label]', 'last', $lastLink); - $out .= ltrim("$firstLink\n$prevLink\n$curLink\n$nextLink\n$lastLink", " - "); - return $out; - } - - function getWordCensorWords() { - global $template; - # pagination variables - $group = (isset($_GET['group'])) ? $_GET['group'] : 1; - $_SESSION['poadmin']['group'] = $group; - $startEntry = ($group - 1) * 50; - $startEntry = ($startEntry < 0) ? 0 : $startEntry; - $end = $group + 50; - $_SESSION['poadmin']['page_start'] = $group; - $dbconn = db_open(); - $curID = (isset($_GET['id'])) ? $_GET['id'] : -1; - $sql = "select `censor_id`,`word_to_censor` from `wordcensor` where 1 order by abs(`censor_id`) asc limit $startEntry, 50;"; - #die ("SQL = $sql
        \n"); - $baseLink = $template->getSection('NavLink'); - $links = '
        ' . "\n"; - $result = mysql_query($sql, $dbconn) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); - $count = 0; - while ($row = mysql_fetch_assoc($result)) { - $linkId = $row['censor_id']; - $linkClass = ($linkId == $curID) ? 'selected' : 'noClass'; - $word_to_censor = $row['word_to_censor']; - $tmpLink = str_replace('[linkClass]', " class=\"$linkClass\"", $baseLink); - $linkHref = " href=\"./?page=wordcensor&action=edit&id=$linkId&group=$group#$linkId\" name=\"$linkId\""; - $tmpLink = str_replace('[linkHref]', $linkHref, $tmpLink); - $tmpLink = str_replace('[linkOnclick]', '', $tmpLink); - $tmpLink = str_replace('[linkTitle]', " title=\"Edit spelling replace_with for the word '$word_to_censor'\"", $tmpLink); - $tmpLink = str_replace('[linkLabel]', $word_to_censor, $tmpLink); - $links .= "$tmpLink\n"; - $count++; - } - $page_count = intval($count / 50); - $_SESSION['poadmin']['page_count'] = $page_count + (($count / 50) > $page_count) ? 1 : 0; - $links .= "\n
        \n"; - return $links; - } - -function wordCensorForm() { - global $template; - $out = $template->getSection('WordCensorForm'); - $group = (isset($_GET['group'])) ? $_GET['group'] : 1; - $out = str_replace('[group]', $group, $out); - return $out; -} - -function insertWordCensor() { - //global vars - global $template, $msg; - $dbconn = db_open(); - - $replace_with = mysql_escape_string(trim($_POST['replace_with'])); - $word_to_censor = mysql_escape_string(trim($_POST['word_to_censor'])); - - if(($replace_with == "") || ($word_to_censor == "")) { - $msg = '
        You must enter a spelling mistake and the replace_with.
        ' . "\n"; - } - else { - $sql = "INSERT INTO `wordcensor` VALUES (NULL,'$word_to_censor','$replace_with')"; - $result = mysql_query($sql,$dbconn) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); - - if($result) { - $msg = '
        Correction added.
        '; - } - else { - $msg = '
        There was a problem editing the replace_with - no changes made.
        '; - } - } - mysql_close($dbconn); - - return $msg; -} - -function delWordCensor($id) { - global $template, $msg; - $dbconn = db_open(); - if($id=="") { - $msg = '
        There was a problem editing the replace_with - no changes made.
        '; - } - else { - $sql = "DELETE FROM `wordcensor` WHERE `censor_id` = '$id' LIMIT 1"; - $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); - if($result) { - $msg = '
        Correction deleted.
        '; - } - else { - $msg = '
        There was a problem editing the replace_with - no changes made.
        '; - } - } - mysql_close($dbconn); -} - - -function runWordCensorSearch() { - //global vars - global $template; - $dbconn = db_open(); - $i=0; - $search = mysql_escape_string(trim($_POST['search'])); - $sql = "SELECT * FROM `wordcensor` WHERE `word_to_censor` LIKE '%$search%' OR `replace_with` LIKE '%$search%' LIMIT 50"; - $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); - $htmltbl = ' - - - - - - - - '; - while($row=mysql_fetch_array($result)) { - $i++; - $word_to_censor = strtoupper($row['word_to_censor']); - $replace_with = strtoupper($row['replace_with']); - $id = $row['censor_id']; - $group = round(($id / 50)); - $action = " - "; - $htmltbl .= " - - - - "; - } - $htmltbl .= "
        word_to_censorCorrectionAction
        $word_to_censor$replace_with$action
        "; - - if($i >= 50) { - $msg = "Found more than 50 results for '$search', please refine your search further"; - } - elseif($i == 0) { - $msg = "Found 0 results for '$search'. You can use the form below to add that entry."; - $htmltbl=""; - } - else { - $msg = "Found $i results for '$search'"; - } - $htmlresults = "
        $msg
        ".$htmltbl; - mysql_close($dbconn); - return $htmlresults; -} - -function editWordCensorForm($id) { - //global vars - global $template; - $group = (isset($_GET['group'])) ? $_GET['group'] : 1; - $form = $template->getSection('EditWordCensorForm'); - $dbconn = db_open(); - $sql = "SELECT * FROM `wordcensor` WHERE `censor_id` = '$id' LIMIT 1"; - $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); - $row = mysql_fetch_array($result); - $form = str_replace('[censor_id]', $row['censor_id'], $form); - $form = str_replace('[word_to_censor]', strtoupper($row['word_to_censor']), $form); - $form = str_replace('[replace_with]', strtoupper($row['replace_with']), $form); - $form = str_replace('[group]', $group, $form); - mysql_close($dbconn); - return $form; -} - -function updateWordCensor() { - //global vars - global $template, $msg; - $dbconn = db_open(); - $word_to_censor = mysql_escape_string(trim($_POST['word_to_censor'])); - $replace_with = mysql_escape_string(trim($_POST['replace_with'])); - $id = trim($_POST['id']); - if(($id=="")||($word_to_censor=="")||($replace_with=="")) { - $msg = '
        There was a problem editing the replace_with - no changes made.
        '; - } - else { - $sql = "UPDATE `wordcensor` SET `word_to_censor` = '$word_to_censor',`replace_with`='$replace_with' WHERE `censor_id`='$id' LIMIT 1"; - $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); - if($result) { - $msg = '
        Correction edited.
        '; - } - else { - $msg = '
        There was a problem editing the replace_with - no changes made.
        '; - } - } -} - + + +endScript; + $form = print_r($_REQUEST, true); + #die("
        \nRequest vars:\n\n$form\n
        \n"); + $group = (isset($_REQUEST['group'])) ? $_REQUEST['group'] : 1; + $content = $template->getSection('SearchWordCensorForm'); + $wc_action = isset($_REQUEST['action']) ? strtolower($_REQUEST['action']) : ''; + $wc_id = isset($_REQUEST['censor_id']) ? $_REQUEST['censor_id'] : -1; + if (!empty($wc_action)) { + switch($wc_action) { + case 'search': + $content .= runWordCensorSearch(); + $content .= wordCensorForm(); + break; + case 'update': + $x = updateWordCensor(); + $content .= wordCensorForm(); + break; + case 'delete': + #die("Delete called! id = $wc_id"); + $content .= ($wc_id >= 0) ? delWordCensor($wc_id) . wordCensorForm() : wordCensorForm(); + break; + case 'edit': + $content .= ($wc_id >= 0) ? editWordCensorForm($wc_id) : wordCensorForm(); + break; + case 'add': + $x = insertWordCensor(); + $content .= wordCensorForm(); + break; + default: + $content .= wordCensorForm(); + } + } + else { + $content .= wordCensorForm(); + } + $content = str_replace('[group]', $group, $content); + + $topNav = $template->getSection('TopNav'); + $leftNav = $template->getSection('LeftNav'); + $main = $template->getSection('Main'); + $topNavLinks = makeLinks('top', $topLinks, 12); + $navHeader = $template->getSection('NavHeader'); + $rightNav = $template->getSection('RightNav'); + $leftNavLinks = makeLinks('left', $leftLinks, 12); + $rightNavLinks = getWordCensorWords(); + $FooterInfo = getFooter(); + $errMsgClass = (!empty($msg)) ? "ShowError" : "HideError"; + $errMsgStyle = $template->getSection($errMsgClass); + $noLeftNav = ''; + $noTopNav = ''; + $noRightNav = ''; + $headerTitle = 'Actions:'; + $pageTitle = 'My-Program O - Word Censor Editor'; + $mainContent = $content; + $mainTitle = 'Word Censor Editor'; + + $mainContent = str_replace('[wordCensorForm]', wordCensorForm(), $mainContent); + $rightNav = str_replace('[rightNavLinks]', $rightNavLinks, $rightNav); + $rightNav = str_replace('[navHeader]', $navHeader, $rightNav); + $rightNav = str_replace('[headerTitle]', paginate(), $rightNav); + + function paginate() { + $dbConn = db_open(); + $sql = "select count(*) from `wordcensor` where 1"; + $result = mysql_query($sql) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); + $row = mysql_fetch_array($result); + $rowCount = $row[0]; + mysql_close($dbConn); + $lastPage = intval($rowCount / 50); + $remainder = ($rowCount / 50) - $lastPage; + if ($remainder > 0) $lastPage++; + #die ("Session values:
        \n" . print_r($_SESSION, true) . "
        \nCount = $count
        \n"); + $out = "Censored Words
        \n50 words per page:
        \n"; + $link=" - [label]"; + $curStart = (isset($_GET['group'])) ? $_GET['group'] : 1; + $firstPage = 1; + $prev = ($curStart > ($firstPage + 1)) ? $curStart - 1 : -1; + $next = ($lastPage > ($curStart + 1)) ? $curStart + 1 : -1; + $firstLink = ($firstPage != $curStart) ? str_replace('[group]', '1', $link) : ''; + $prevLink = ($prev > 0) ? str_replace('[group]', $prev, $link) : ''; + $curLink = "- $curStart "; + if (empty($firstLink) and empty($prevLink)) $curLink = $curStart; + $nextLink = ($next > 0) ? str_replace('[group]', $next, $link) : ''; + $lastLink = ($lastPage > $curStart) ? str_replace('[group]', $lastPage, $link) : ''; + $firstLink = str_replace('[label]', 'first', $firstLink); + $prevLink = str_replace('[label]', '<<', $prevLink); + $nextLink = str_replace('[label]', '>>', $nextLink); + $lastLink = str_replace('[label]', 'last', $lastLink); + $out .= ltrim("$firstLink\n$prevLink\n$curLink\n$nextLink\n$lastLink", " - "); + return $out; + } + + function getWordCensorWords() { + global $template; + # pagination variables + $group = (isset($_GET['group'])) ? $_GET['group'] : 1; + $_SESSION['poadmin']['group'] = $group; + $startEntry = ($group - 1) * 50; + $startEntry = ($startEntry < 0) ? 0 : $startEntry; + $end = $group + 50; + $_SESSION['poadmin']['page_start'] = $group; + $dbconn = db_open(); + $curID = (isset($_GET['id'])) ? $_GET['id'] : -1; + $sql = "select `censor_id`,`word_to_censor` from `wordcensor` where 1 order by abs(`censor_id`) asc limit $startEntry, 50;"; + #die ("SQL = $sql
        \n"); + $baseLink = $template->getSection('NavLink'); + $links = '
        ' . "\n"; + $result = mysql_query($sql, $dbconn) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); + $count = 0; + while ($row = mysql_fetch_assoc($result)) { + $linkId = $row['censor_id']; + $linkClass = ($linkId == $curID) ? 'selected' : 'noClass'; + $word_to_censor = $row['word_to_censor']; + $tmpLink = str_replace('[linkClass]', " class=\"$linkClass\"", $baseLink); + $linkHref = " href=\"./?page=wordcensor&action=edit&censor_id=$linkId&group=$group#$linkId\" name=\"$linkId\""; + $tmpLink = str_replace('[linkHref]', $linkHref, $tmpLink); + $tmpLink = str_replace('[linkOnclick]', '', $tmpLink); + $tmpLink = str_replace('[linkTitle]', " title=\"Edit spelling replace_with for the word '$word_to_censor'\"", $tmpLink); + $tmpLink = str_replace('[linkLabel]', $word_to_censor, $tmpLink); + $links .= "$tmpLink\n"; + $count++; + } + $page_count = intval($count / 50); + $_SESSION['poadmin']['page_count'] = $page_count + (($count / 50) > $page_count) ? 1 : 0; + $links .= "\n
        \n"; + return $links; + } + +function wordCensorForm() { + global $template; + $out = $template->getSection('WordCensorForm'); + $group = (isset($_GET['group'])) ? $_GET['group'] : 1; + $out = str_replace('[group]', $group, $out); + return $out; +} + +function insertWordCensor() { + //global vars + global $template, $msg; + $dbconn = db_open(); + + $replace_with = mysql_real_escape_string(trim($_POST['replace_with'])); + $word_to_censor = mysql_real_escape_string(trim($_POST['word_to_censor'])); + + if(($replace_with == "") || ($word_to_censor == "")) { + $msg = '
        You must enter a spelling mistake and the replace_with.
        ' . "\n"; + } + else { + $sql = "INSERT INTO `wordcensor` (`censor_id`, `word_to_censor`, `replace_with`, `bot_exclude`) VALUES (NULL,'$word_to_censor','$replace_with', '')"; + $result = mysql_query($sql,$dbconn) or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); + + if($result) { + $msg = '
        Correction added.
        '; + } + else { + $msg = '
        There was a problem editing the replace_with - no changes made.
        '; + } + } + mysql_close($dbconn); + + return $msg; +} + +function delWordCensor($id) { + global $template, $msg; + $dbconn = db_open(); + if($id=="") { + $msg = '
        There was a problem editing the replace_with - no changes made.
        '; + } + else { + $sql = "DELETE FROM `wordcensor` WHERE `censor_id` = '$id' LIMIT 1"; + $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); + if($result) { + $msg = '
        Correction deleted.
        '; + } + else { + $msg = '
        There was a problem editing the replace_with - no changes made.
        '; + } + } + mysql_close($dbconn); +} + + +function runWordCensorSearch() { + //global vars + global $template; + $dbconn = db_open(); + $i=0; + $search = mysql_real_escape_string(trim($_POST['search'])); + $sql = "SELECT * FROM `wordcensor` WHERE `word_to_censor` LIKE '%$search%' OR `replace_with` LIKE '%$search%' LIMIT 50"; + $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); + $htmltbl = ' + + + + + + + + '; + while($row=mysql_fetch_array($result)) { + $i++; + $word_to_censor = strtoupper($row['word_to_censor']); + $replace_with = strtoupper($row['replace_with']); + $id = $row['censor_id']; + $group = round(($id / 50)); + $action = "\"Edit + \"Delete"; + $htmltbl .= " + + + + "; + } + $htmltbl .= "
        word_to_censorCorrectionAction
        $word_to_censor$replace_with$action
        "; + + if($i >= 50) { + $msg = "Found more than 50 results for '$search', please refine your search further"; + } + elseif($i == 0) { + $msg = "Found 0 results for '$search'. You can use the form below to add that entry."; + $htmltbl=""; + } + else { + $msg = "Found $i results for '$search'"; + } + $htmlresults = "
        $msg
        ".$htmltbl; + mysql_close($dbconn); + return $htmlresults; +} + +function editWordCensorForm($id) { + //global vars + global $template; + $group = (isset($_GET['group'])) ? $_GET['group'] : 1; + $form = $template->getSection('EditWordCensorForm'); + $dbconn = db_open(); + $sql = "SELECT * FROM `wordcensor` WHERE `censor_id` = '$id' LIMIT 1"; + $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); + $row = mysql_fetch_array($result); + $form = str_replace('[censor_id]', $row['censor_id'], $form); + $form = str_replace('[word_to_censor]', strtoupper($row['word_to_censor']), $form); + $form = str_replace('[replace_with]', strtoupper($row['replace_with']), $form); + $form = str_replace('[group]', $group, $form); + mysql_close($dbconn); + return $form; +} + +function updateWordCensor() { + //global vars + global $template, $msg; + $dbconn = db_open(); + $word_to_censor = mysql_real_escape_string(trim($_POST['word_to_censor'])); + $replace_with = mysql_real_escape_string(trim($_POST['replace_with'])); + $id = trim($_POST['id']); + if(($id=="")||($word_to_censor=="")||($replace_with=="")) { + $msg = '
        There was a problem editing the replace_with - no changes made.
        '; + } + else { + $sql = "UPDATE `wordcensor` SET `word_to_censor` = '$word_to_censor',`replace_with`='$replace_with' WHERE `censor_id`='$id' LIMIT 1"; + $result = mysql_query($sql,$dbconn)or die('You have a SQL error on line '. __LINE__ . ' of ' . __FILE__ . '. Error message is: ' . mysql_error() . ".
        \nSQL = $sql
        \n"); + if($result) { + $msg = '
        Correction edited.
        '; + } + else { + $msg = '
        There was a problem editing the replace_with - no changes made.
        '; + } + } +} + ?> \ No newline at end of file diff --git a/aiml tag list.txt b/aiml tag list.txt new file mode 100644 index 0000000..2e7bee5 --- /dev/null +++ b/aiml tag list.txt @@ -0,0 +1,37 @@ + + + + + (pattern-side - no index) + (template-side - with index) +