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 / upload.php,v < prev   
Text File  |  2003-10-20  |  10KB  |  549 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:    upload.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 to allow an administrator to 
  69. //               upload an sql file from home and replace the associated 
  70. //               table if applicable. 
  71. // 
  72. // Copyright (c) 2003 John L. Whiteman
  73. //
  74. // Permission is herby granted, free of charge, to any person obtaining a 
  75. // copy of this software, data, and associated documentation files 
  76. // (the "Software"), to deal in the Software without restriction, 
  77. // including without limitation the rights to use, copy, modify, merge, 
  78. // publish, distribute, sublicense, and/or sell copies of Software, and to
  79. // permit persons to whom the Software is furnished to do so, subject to 
  80. // the following conditions:
  81. //
  82. // The above copyright notice and this permission notice shall be 
  83. // included in all copies or substantial portions of the Software.
  84. //
  85. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
  86. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
  87. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  88. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 
  89. // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHERE IN AN ACTION OF CONTRACT,
  90. // TORT OR OTHERWISE, ARISING IN THE SOFTWARE.  
  91. //////////////////////////////////////////////////////////////////////////////
  92. //////////////////////////////////////////////////////////////////////////////
  93. $web = new Web();
  94.  
  95. if (!$_SESSION['ADMIN']) {
  96.  
  97.     $web->redirect("login.php");
  98.  
  99.     exit;
  100. }
  101.  
  102. $indonesia = new Indonesia();
  103.  
  104. if ($_SESSION['NODUP_UPLOAD']) {
  105.  
  106.     unset($_SESSION['NODUP_UPLOAD']);
  107.  
  108.     $web->redirect("admin.php");
  109.  
  110.     exit;
  111. }
  112. ?>
  113. <html>
  114. <head>
  115. <title>Bahasa Indonesia Dictionary: Upload</title>
  116.  
  117. <link href="bahasa.css" rel="stylesheet" type="text/css">
  118.  
  119. <script type="text/javascript" src="bahasa.js"></script>
  120.  
  121. <script language="Javascript" type="text/javascript"> 
  122. <!--
  123. //////////////////////////////////////////////////////////////////////////////
  124. function get_basename(stoken) {
  125.  
  126.     if (is_white_space(stoken)) {
  127.  
  128.         return(stoken);
  129.     }
  130.  
  131.     if (stoken.lastIndexOf("\\") > 0) {
  132.  
  133.         start = stoken.lastIndexOf("\\") + 1;
  134.  
  135.         return(stoken.substring(start, stoken.length));
  136.  
  137.     } else if (stoken.lastIndexOf("/") > 0) {
  138.  
  139.         start = stoken.lastIndexOf("/") + 1;
  140.  
  141.         return(stoken.substring(start, stoken.length));
  142.     } 
  143.  
  144.     return(stoken);
  145. }
  146. //////////////////////////////////////////////////////////////////////////////
  147. function verify() {
  148.  
  149.     source = document.upload.source.value;
  150.  
  151.     source = trim(source);
  152.  
  153.     if (is_white_space(source)) {
  154.  
  155.         alert(
  156.         "You must specify a source file to upload!");
  157.  
  158.         document.upload.source.focus();
  159.  
  160.         return(false);
  161.     } 
  162.  
  163.     target = document.upload.target.value;
  164.  
  165.     target = trim(target);
  166.  
  167.     if (is_white_space(target)) {
  168.  
  169.         alert(
  170.         "You must specify a target value to replace!");
  171.  
  172.         document.upload.target.focus();
  173.  
  174.         return(false);
  175.     }
  176.  
  177.     name = document.upload.name.value;
  178.  
  179.     name = trim(name);
  180.  
  181.     if (is_white_space(name)) {
  182.  
  183.         alert(
  184.         "You must specify a name value!");
  185.  
  186.         document.upload.name.focus();
  187.  
  188.         return(false);
  189.     }
  190.  
  191.     password = document.upload.password.value;
  192.  
  193.     if (is_white_space(password)) {
  194.  
  195.         alert(
  196.         "You must specify a password value!");
  197.  
  198.         document.upload.password.focus();
  199.  
  200.         return(false);
  201.     }
  202.  
  203.     source_basename = get_basename(source);
  204.  
  205.     if (source_basename != target) {
  206.  
  207.         alert(
  208.         "Source and target names do not match!  " +
  209.         "They must be the same."); 
  210.  
  211.         document.upload.source.focus();
  212.  
  213.         return(false);
  214.     }
  215.  
  216.     return(true);
  217. }
  218. //////////////////////////////////////////////////////////////////////////////
  219. // -->
  220. </script>
  221. </head>
  222. <body>
  223. <?
  224. $web->show_logo("Upload");
  225. ?>
  226. <a href="admin.php">Administration</a>
  227. <br><br>
  228. <?
  229.  
  230. if (
  231. (isset($_POST['name'])) &&
  232. (isset($_POST['password'])) &&
  233. (isset($HTTP_POST_FILES['source'])) &&
  234. (isset($_POST['target']))) {
  235.  
  236.     $errstr = 
  237.     $indonesia->login_db_user(
  238.     $_POST['name'], $_POST['password']);
  239.  
  240.     if ($errstr != "") {
  241.  
  242.         print "<br><hr><b>${errstr}</b><hr><br>\n";
  243.  
  244.     } else {
  245.  
  246.         $backup_flag = 0;
  247.  
  248.         if ($_POST['backup'] == 1) {
  249.  
  250.             $backup_flag = 1;
  251.         }
  252.  
  253.         if ($_POST['replace'] == 1) {
  254.  
  255.             $errstr = 
  256.             $indonesia->upload_sql_file_and_replace_table(
  257.             $HTTP_POST_FILES, $_POST['target'], $backup_flag);
  258.  
  259.             if ($errstr != "") {
  260.  
  261.                 print "<br><hr><b>${errstr}</b><hr><br>\n";
  262.  
  263.             } else {
  264.  
  265.                 $_SESSION['NODUP_UPLOAD'] = 1;
  266.  
  267.                 if ($backup_flag) {
  268.  
  269.                     print
  270.                     "<br><hr><b>\n" .
  271.                     "SQL file upload and backup " .
  272.                     "and replace successful!\n" .
  273.                     "</b><hr><br>\n"; 
  274.  
  275.                 } else {
  276.  
  277.                     print
  278.                     "<br><hr><b>\n" .
  279.                     "SQL file upload and replace " .
  280.                     "successful!</b><hr><br>\n"; 
  281.                 }
  282.             }
  283.  
  284.         } else {
  285.  
  286.             $errstr = 
  287.             $indonesia->upload_sql_file(
  288.             $HTTP_POST_FILES, $_POST['target'], $backup_flag);
  289.  
  290.             if ($errstr != "") {
  291.  
  292.                 print "<br><hr><b>${errstr}</b><hr><br>\n";
  293.  
  294.             } else {
  295.  
  296.                 $_SESSION['NODUP_UPLOAD'] = 1;
  297.  
  298.                 if ($backup_flag) {
  299.  
  300.                     print
  301.                     "<br><hr><b>\n" .
  302.                     "SQL file upload and backup " .
  303.                     "successful!</b><hr><br>\n"; 
  304.  
  305.                 } else {
  306.  
  307.                     print
  308.                     "<br><hr><b>\n" .
  309.                     "SQL file upload " .
  310.                     "successful!</b><hr><br>\n"; 
  311.                 }
  312.             }
  313.         }
  314.     }
  315.  
  316. } else {
  317.  
  318.     show_upload_form($web, $indonesia);
  319.  
  320. }
  321. ?>
  322.  
  323. </body>
  324. </html>
  325.  
  326. <?
  327.  
  328.  
  329.  
  330.  
  331. //////////////////////////////////////////////////////////////////////////////
  332. function show_upload_form($web, $indonesia) {
  333.  
  334.     $admin_tables = array();
  335.  
  336.     $admin_tables = $indonesia->get_admin_tables();
  337.  
  338.     if (count($admin_tables) < 1) {
  339.  
  340.         return;
  341.     }
  342.  
  343.     $table_select = 
  344.     "<select name=\"target\">\n" .
  345.     "<option value=\"\">\n";
  346.  
  347.     foreach($admin_tables as $table) {
  348.  
  349.         $sql = $web->tohtml($table["sql"]);
  350.  
  351.         $table_select 
  352.         .= "<option value=\"${sql}\">${sql}\n"; 
  353.     }
  354.  
  355.     $table_select .= "</select>\n";
  356.  
  357.     $max_file_size = $indonesia->get_max_file_upload_size();
  358.  
  359.     print <<<EOFSU
  360.  
  361. <form name="upload" enctype="multipart/form-data" method="post" 
  362.  action="upload.php"  onSubmit='return verify()'>
  363. <table cellpadding="3" cellspacing="3" border="0">
  364. <tr>
  365. <td>Source:</td>
  366. <td>
  367. <input name="source" type="file">
  368. </td>
  369. </tr><tr>
  370. <td>Target:</td>
  371. <td>
  372. $table_select
  373. </td>
  374. </tr><tr>
  375. <td>Name:</td>
  376. <td>
  377. <input type="text" name="name">
  378. </td>
  379. </tr><tr>
  380. <td>Password:</td>
  381. <td>
  382. <input type="password" name="password">
  383. </td>
  384. </tr><tr>
  385. <td>
  386. Create Backup:
  387. </td>
  388. <td>
  389. <input type="checkbox" value="1" name="backup" checked>
  390. </td>
  391. </tr><tr>
  392. <td>
  393. Replace Table:
  394. </td>
  395. <td>
  396. <input type="checkbox" value="1" name="replace">
  397. </td>
  398. </tr><tr>
  399. <td colspan="2" align="right">
  400. <input type="reset" value="Clear form">
  401.   
  402. <input type="submit" value="Upload!">
  403. </td>
  404. </tr>
  405. </table>
  406. <input type="hidden" name="MAX_FILE_SIZE" value="${max_file_size}">
  407. </form>
  408. <script language="Javascript" type="text/javascript"> 
  409. document.upload.source.focus();
  410. </script>
  411. EOFSU;
  412. }
  413. //////////////////////////////////////////////////////////////////////////////
  414. function backup_file($web, $indonesia, $file) {
  415.  
  416.  
  417.  
  418.  
  419. }
  420. //////////////////////////////////////////////////////////////////////////////
  421. function upload_file($web, $indonesia, $source, $target) {
  422.  
  423.  
  424.     return("");
  425. }
  426. //////////////////////////////////////////////////////////////////////////////
  427. //////////////////////////////////////////////////////////////////////////////
  428. ?>
  429. @
  430.  
  431.  
  432. 1.5
  433. log
  434. @*** empty log message ***
  435. @
  436. text
  437. @d12 1
  438. a12 1
  439. // Modified:     October 17, 2003
  440. d62 2
  441. @
  442.  
  443.  
  444. 1.4
  445. log
  446. @*** empty log message ***
  447. @
  448. text
  449. @d12 1
  450. a12 1
  451. // Modified:     October 05, 2003
  452. d63 2
  453. d66 1
  454. a90 25
  455. function is_white_space(stoken) {
  456.  
  457.     if (stoken == null) return(true);
  458.  
  459.     if (stoken == '') return(true);
  460.  
  461.     if (stoken == "") return(true);
  462.  
  463.     return(false);
  464. }
  465. //////////////////////////////////////////////////////////////////////////////
  466. function trim(stoken) {
  467.  
  468.     if (is_white_space(stoken)) {
  469.  
  470.         return(stoken);
  471.     }
  472.  
  473.     stoken = stoken.replace(/^\s*/, "");
  474.  
  475.     stoken = stoken.replace(/\s*$/, "");
  476.  
  477.     return(stoken);
  478. }
  479. //////////////////////////////////////////////////////////////////////////////
  480. d163 1
  481. a163 1
  482. //////////////////////////////////////////////////////////////////////////////
  483. @
  484.  
  485.  
  486. 1.3
  487. log
  488. @*** empty log message ***
  489. @
  490. text
  491. @d12 1
  492. a12 1
  493. // Modified:     September 30, 2003
  494. d189 3
  495. a191 1
  496. <h2>Bahasa Indonesia Dictionary: Upload</h2>
  497. @
  498.  
  499.  
  500. 1.2
  501. log
  502. @*** empty log message ***
  503. @
  504. text
  505. @d12 1
  506. a12 1
  507. // Modified:     August 19, 2003
  508. d41 1
  509. a41 1
  510. if (!session_is_registered("ADMIN")) {
  511. d50 1
  512. a50 1
  513. if (session_is_registered("NODUP_UPLOAD")) {
  514. d52 1
  515. a52 1
  516.     session_unregister("NODUP_UPLOAD");
  517. d229 1
  518. a229 3
  519.                 $NODUP_UPLOAD = 1;
  520.  
  521.                 session_register("NODUP_UPLOAD");
  522. d260 1
  523. a260 3
  524.                 $NODUP_UPLOAD = 1;
  525.  
  526.                 session_register("NODUP_UPLOAD");
  527. @
  528.  
  529.  
  530. 1.1
  531. log
  532. @Initial revision
  533. @
  534. text
  535. @d5 34
  536. a38 1
  537.  
  538. a396 1
  539.  
  540. @
  541.  
  542.  
  543. 1.1.1.1
  544. log
  545. @Bahasa Indonesia Dictionary
  546. @
  547. text
  548. @@
  549.