home *** CD-ROM | disk | FTP | other *** search
/ ftp.ee.pdx.edu / 2014.02.ftp.ee.pdx.edu.tar / ftp.ee.pdx.edu / oss / cvs-2004 / bahasa / web / sql.php,v < prev    next >
Text File  |  2003-10-20  |  8KB  |  472 lines

  1. head    1.6;
  2. access;
  3. symbols
  4.     Initial:1.1.1.1 bule:1.1.1;
  5. locks; strict;
  6. comment    @# @;
  7.  
  8.  
  9. 1.6
  10. date    2003.10.20.00.21.46;    author bule;    state Exp;
  11. branches;
  12. next    1.5;
  13.  
  14. 1.5
  15. date    2003.10.18.00.33.42;    author bule;    state Exp;
  16. branches;
  17. next    1.4;
  18.  
  19. 1.4
  20. date    2003.10.06.00.39.27;    author bule;    state Exp;
  21. branches;
  22. next    1.3;
  23.  
  24. 1.3
  25. date    2003.10.01.06.51.30;    author bule;    state Exp;
  26. branches;
  27. next    1.2;
  28.  
  29. 1.2
  30. date    2003.08.19.19.24.21;    author bule;    state Exp;
  31. branches;
  32. next    1.1;
  33.  
  34. 1.1
  35. date    2003.08.12.19.18.23;    author bule;    state Exp;
  36. branches
  37.     1.1.1.1;
  38. next    ;
  39.  
  40. 1.1.1.1
  41. date    2003.08.12.19.18.23;    author bule;    state Exp;
  42. branches;
  43. next    ;
  44.  
  45.  
  46. desc
  47. @@
  48.  
  49.  
  50. 1.6
  51. log
  52. @*** empty log message ***
  53. @
  54. text
  55. @<?
  56. session_start();
  57. require_once("../php/Indonesia.php");
  58. require_once("../php/Web.php");
  59. //////////////////////////////////////////////////////////////////////////////
  60. //////////////////////////////////////////////////////////////////////////////
  61. // Project Name: Bahasa Indonesia Dictionary
  62. // Directory:    bahasa/web
  63. // File Name:    sql.php
  64. // Author(s):    John L. Whiteman
  65. // Created:      June 23, 2003  
  66. // Modified:     October 19, 2003
  67. // Description:  The purpose of this restricted access PHP web 
  68. //               client page is allow an administrator to run
  69. //               custom SQL commands against the database. 
  70. // 
  71. // Copyright (c) 2003 John L. Whiteman
  72. //
  73. // Permission is herby granted, free of charge, to any person obtaining a 
  74. // copy of this software, data, and associated documentation files 
  75. // (the "Software"), to deal in the Software without restriction, 
  76. // including without limitation the rights to use, copy, modify, merge, 
  77. // publish, distribute, sublicense, and/or sell copies of Software, and to
  78. // permit persons to whom the Software is furnished to do so, subject to 
  79. // the following conditions:
  80. //
  81. // The above copyright notice and this permission notice shall be 
  82. // included in all copies or substantial portions of the Software.
  83. //
  84. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
  85. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
  86. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  87. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 
  88. // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHERE IN AN ACTION OF CONTRACT,
  89. // TORT OR OTHERWISE, ARISING IN THE SOFTWARE.  
  90. //////////////////////////////////////////////////////////////////////////////
  91. //////////////////////////////////////////////////////////////////////////////
  92. $web = new Web();
  93.  
  94. if (!$_SESSION['ADMIN']) {
  95.  
  96.     $web->redirect("login.php");
  97.  
  98.     exit;
  99. }
  100.  
  101. if ($_SESSION['NODUP_SQL']) {
  102.  
  103.     unset($_SESSION['NODUP_SQL']);
  104.  
  105.     $web->redirect("admin.php");
  106.  
  107.     exit;
  108. }
  109.  
  110. $indonesia = new Indonesia();
  111.  
  112. $status = $indonesia->get_dictionary_status();
  113.  
  114. if ($status["status"] == 1 || $status["status"] == 2) {
  115.  
  116.     $web->redirect("admin.php");
  117.  
  118.     exit;
  119. }
  120.  
  121. ?>
  122. <html>
  123. <head>
  124. <title>Bahasa Indonesia Dictionary: SQL</title>
  125.  
  126. <link href="bahasa.css" rel="stylesheet" type="text/css">
  127.  
  128. <script type="text/javascript" src="bahasa.js"></script>
  129.  
  130. <script language="Javascript" type="text/javascript"> 
  131. <!--
  132. //////////////////////////////////////////////////////////////////////////////
  133. function verify() {
  134.  
  135.     statement = document.sql.statement.value;
  136.  
  137.     statement = trim(statement);
  138.  
  139.     if (is_white_space(statement)) {
  140.  
  141.         alert("You must enter a SQL value!");
  142.  
  143.         document.sql.statement.focus();
  144.  
  145.         return(false);
  146.     }
  147.  
  148.     name = document.sql.name.value;
  149.  
  150.     name = trim(name);
  151.  
  152.     if (is_white_space(name)) {
  153.  
  154.         alert("You must enter a name value!");
  155.  
  156.         document.sql.name.focus();
  157.  
  158.         return(false);
  159.     }
  160.  
  161.     password = document.sql.password.value;
  162.  
  163.     if (is_white_space(password)) {
  164.  
  165.         alert("You must enter a password value!");
  166.  
  167.         document.sql.password.focus();
  168.  
  169.         return(false);
  170.     }
  171.  
  172.     return(true);
  173. }
  174. //////////////////////////////////////////////////////////////////////////////
  175. // -->
  176. </script>
  177. </head>
  178. <body>
  179. <?
  180. $web->show_logo("SQL");
  181. ?>
  182. <a href="admin.php">Administration</a>
  183. <br><br>
  184. <?
  185. show_sql_form($web, $indonesia);
  186.  
  187. if (
  188. (isset($_POST['statement'])) &&
  189. (isset($_POST['name'])) &&
  190. (isset($_POST['password']))) {
  191.  
  192.     run_sql(
  193.     $web, $indonesia, $_POST['statement'], 
  194.     $_POST['name'], $_POST['password']);
  195. }
  196. ?>
  197. </body>
  198. </html>
  199.  
  200. <?
  201. //////////////////////////////////////////////////////////////////////////////
  202. function run_sql($web, $indonesia, $statement, $name, $password) {
  203.  
  204.     $results = array();
  205.  
  206.     $name = trim($name);
  207.  
  208.     if ($name == "") {
  209.  
  210.         print 
  211.         "<br><hr><b>You must provide a name value!</b><hr><br>\n";
  212.  
  213.         return;
  214.     }
  215.  
  216.     $password = trim($password);
  217.  
  218.     if ($password == "") {
  219.  
  220.         print 
  221.         "<br><hr><b>You must provide a password value!</b><hr><br>\n";
  222.  
  223.         return;
  224.     }
  225.  
  226.     $statement = trim($statement);
  227.  
  228.     if ($statement == "") {
  229.  
  230.         print 
  231.         "<br><hr><b>You must provide an SQL value!</b><hr><br>\n";
  232.  
  233.         return;
  234.     }
  235.  
  236.     $errstr = 
  237.     $indonesia->login_db_user($name, $password);
  238.  
  239.     if ($errstr != "") {
  240.  
  241.         print "<br><hr><b>${errstr}</b><hr><br>\n";
  242.  
  243.         return;
  244.     }
  245.  
  246.     $errstr = $indonesia->open_dictionary();
  247.  
  248.     if ($errstr != "") {
  249.  
  250.         print "<br><hr><b>${errstr}</b><hr><br>\n";
  251.  
  252.         return;
  253.     }
  254.  
  255.     $statement = stripslashes($statement);
  256.  
  257.     $rows = mysql_query($statement);
  258.  
  259.     $errstr = mysql_error();
  260.  
  261.     if ($errstr != "") {
  262.  
  263.         print "<br><hr><b>${errstr}</b><hr><br>\n";
  264.  
  265.         return;
  266.     }
  267.  
  268.     if (preg_match("/delete/i", "$statement")) {
  269.  
  270.         $arows = mysql_affected_rows();
  271.  
  272.         print 
  273.         "<br><hr><b>Affected Deleted Rows: ${arows}</b><hr><br>\n";
  274.  
  275.         return;
  276.     }
  277.  
  278.     if (preg_match("/update/i", "$statement")) {
  279.  
  280.         $arows = mysql_affected_rows();
  281.  
  282.         print 
  283.         "<br><hr><b>Affected Updated Rows: ${arows}</b><hr><br>\n";
  284.  
  285.         return;
  286.     }
  287.  
  288.  
  289.     $nrows = mysql_num_rows($rows);
  290.  
  291.     if (!$nrows) {
  292.  
  293.         return;
  294.     }
  295.  
  296.     $count = mysql_num_fields($rows);
  297.  
  298.     $table =
  299.     "<table cellpadding=\"3\" cellspacing=\"3\" border=\"1\">\n";
  300.  
  301.     for($i = 0; $i < $count; $i++) {
  302.  
  303.         $col = mysql_field_name($rows, $i);
  304.  
  305.         $table .= "<th>${col}</th>\n";
  306.     }
  307.  
  308.     while($row = mysql_fetch_row($rows)) {
  309.  
  310.         $table .= "<tr>\n";
  311.  
  312.         foreach($row as $value) {
  313.  
  314.             $table .= "<td>${value} </td>\n";
  315.         }
  316.  
  317.         $table .= "</tr>\n";
  318.     }
  319.  
  320.     $table .= "</table>";
  321.     
  322.     $indonesia->close_dictionary();
  323.  
  324.     print "$table";
  325.  
  326.     return;
  327. }
  328. //////////////////////////////////////////////////////////////////////////////
  329. function show_sql_form($web, $indonesia) {
  330.  
  331.     print <<<EOFSSF
  332. <form name="sql" method="post" onsubmit='return verify()'>
  333. <table cellpadding="3" cellspacing="3" border="0">
  334. <tr>
  335. <td>SQL:</td>
  336. </tr><tr>
  337. <td>
  338. <textarea name="statement" rows="7" cols="65" wrap="soft"></textarea>
  339. </td>
  340. </tr><tr>
  341. <td align="right">
  342. <input type="submit" value="Run SQL!">
  343.   
  344. Name: 
  345. <input type="text" name="name">
  346.   
  347. Password: 
  348. <input type="password" name="password">
  349. </td>
  350. </tr>
  351. </table>
  352. </form>
  353. <script language="Javascript" type="text/javascript"> 
  354. document.sql.statement.focus();
  355. </script>
  356. EOFSSF;
  357.  
  358.     return;
  359. }
  360. //////////////////////////////////////////////////////////////////////////////
  361. //////////////////////////////////////////////////////////////////////////////
  362. ?>
  363. @
  364.  
  365.  
  366. 1.5
  367. log
  368. @*** empty log message ***
  369. @
  370. text
  371. @d12 1
  372. a12 1
  373. // Modified:     October 17, 2003
  374. d71 2
  375. @
  376.  
  377.  
  378. 1.4
  379. log
  380. @*** empty log message ***
  381. @
  382. text
  383. @d12 1
  384. a12 1
  385. // Modified:     October 05, 2003
  386. d72 2
  387. d75 2
  388. a76 26
  389.  
  390. function is_white_space(stoken) {
  391.  
  392.     if (stoken == null) return(true);
  393.  
  394.     if (stoken == '') return(true);
  395.  
  396.     if (stoken == "") return(true);
  397.  
  398.     return(false);
  399. }
  400.  
  401. function trim(stoken) {
  402.  
  403.     if (is_white_space(stoken)) {
  404.  
  405.         return(stoken);
  406.     }
  407.  
  408.     stoken = stoken.replace(/^\s*/, "");
  409.  
  410.     stoken = stoken.replace(/\s*$/, "");
  411.  
  412.     return(stoken);
  413. }
  414.  
  415. d118 2
  416. @
  417.  
  418.  
  419. 1.3
  420. log
  421. @*** empty log message ***
  422. @
  423. text
  424. @d12 1
  425. a12 1
  426. // Modified:     September 30, 2003
  427. d143 3
  428. a145 1
  429. <h2>Bahasa Indonesia Dictionary: SQL</h2>
  430. @
  431.  
  432.  
  433. 1.2
  434. log
  435. @*** empty log message ***
  436. @
  437. text
  438. @d12 1
  439. a12 1
  440. // Modified:     August 19, 2003
  441. d40 1
  442. a40 1
  443. if (!session_is_registered("ADMIN")) {
  444. d47 1
  445. a47 1
  446. if (session_is_registered("NODUP_SQL")) {
  447. d49 1
  448. a49 1
  449.     session_unregister("NODUP_SQL");
  450. @
  451.  
  452.  
  453. 1.1
  454. log
  455. @Initial revision
  456. @
  457. text
  458. @d5 33
  459. a37 1
  460.  
  461. a324 1
  462.  
  463. @
  464.  
  465.  
  466. 1.1.1.1
  467. log
  468. @Bahasa Indonesia Dictionary
  469. @
  470. text
  471. @@
  472.