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 / backup.php,v < prev    next >
Text File  |  2003-10-20  |  12KB  |  707 lines

  1. head    1.9;
  2. access;
  3. symbols
  4.     Initial:1.1.1.1 bule:1.1.1;
  5. locks; strict;
  6. comment    @# @;
  7.  
  8.  
  9. 1.9
  10. date    2003.10.20.00.21.45;    author bule;    state Exp;
  11. branches;
  12. next    1.8;
  13.  
  14. 1.8
  15. date    2003.10.18.00.33.41;    author bule;    state Exp;
  16. branches;
  17. next    1.7;
  18.  
  19. 1.7
  20. date    2003.10.06.00.39.26;    author bule;    state Exp;
  21. branches;
  22. next    1.6;
  23.  
  24. 1.6
  25. date    2003.10.01.06.51.29;    author bule;    state Exp;
  26. branches;
  27. next    1.5;
  28.  
  29. 1.5
  30. date    2003.09.11.05.28.22;    author bule;    state Exp;
  31. branches;
  32. next    1.4;
  33.  
  34. 1.4
  35. date    2003.09.05.06.42.30;    author bule;    state Exp;
  36. branches;
  37. next    1.3;
  38.  
  39. 1.3
  40. date    2003.09.04.07.26.59;    author bule;    state Exp;
  41. branches;
  42. next    1.2;
  43.  
  44. 1.2
  45. date    2003.08.19.06.42.07;    author bule;    state Exp;
  46. branches;
  47. next    1.1;
  48.  
  49. 1.1
  50. date    2003.08.12.19.18.23;    author bule;    state Exp;
  51. branches
  52.     1.1.1.1;
  53. next    ;
  54.  
  55. 1.1.1.1
  56. date    2003.08.12.19.18.23;    author bule;    state Exp;
  57. branches;
  58. next    ;
  59.  
  60.  
  61. desc
  62. @@
  63.  
  64.  
  65. 1.9
  66. log
  67. @*** empty log message ***
  68. @
  69. text
  70. @<?
  71. session_start();
  72. require_once("../php/Indonesia.php");
  73. require_once("../php/Web.php");
  74. //////////////////////////////////////////////////////////////////////////////
  75. //////////////////////////////////////////////////////////////////////////////
  76. // Project Name: Bahasa Indonesia Dictionary
  77. // Directory:    bahasa/web
  78. // File Name:    backup.php
  79. // Author(s):    John L. Whiteman
  80. // Created:      June 23, 2003  
  81. // Modified:     October 19, 2003
  82. // Description:  The purpose of this restricted access PHP web client 
  83. //               page is provide backup capabilities for various 
  84. //               tables in the database. 
  85. // 
  86. // Copyright (c) 2003 John L. Whiteman
  87. //
  88. // Permission is herby granted, free of charge, to any person obtaining a 
  89. // copy of this software, data, and associated documentation files 
  90. // (the "Software"), to deal in the Software without restriction, 
  91. // including without limitation the rights to use, copy, modify, merge, 
  92. // publish, distribute, sublicense, and/or sell copies of Software, and to
  93. // permit persons to whom the Software is furnished to do so, subject to 
  94. // the following conditions:
  95. //
  96. // The above copyright notice and this permission notice shall be 
  97. // included in all copies or substantial portions of the Software.
  98. //
  99. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
  100. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
  101. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  102. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 
  103. // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHERE IN AN ACTION OF CONTRACT,
  104. // TORT OR OTHERWISE, ARISING IN THE SOFTWARE.  
  105. //////////////////////////////////////////////////////////////////////////////
  106. //////////////////////////////////////////////////////////////////////////////
  107. $web = new Web();
  108.  
  109. if (!$_SESSION['ADMIN']) {
  110.  
  111.     $web->redirect("login.php");
  112.  
  113.     exit;
  114. }
  115.  
  116. $indonesia = new Indonesia();
  117.  
  118. $status = $indonesia->get_dictionary_status();
  119.  
  120. if ($status["status"] == 1 || $status["status"] == 2) {
  121.  
  122.     $web->redirect("admin.php");
  123.  
  124.     exit;
  125. }
  126.  
  127. ?>
  128. <html>
  129. <head>
  130. <title>Bahasa Indonesia Dictionary: Backup Tables</title>
  131.  
  132. <link href="bahasa.css" rel="stylesheet" type="text/css">
  133.  
  134. <script type="text/javascript" src="bahasa.js"></script>
  135.  
  136. <script language="Javascript" type="text/javascript"> 
  137. <!-- 
  138. //////////////////////////////////////////////////////////////////////////////
  139. function verify() {
  140.  
  141.     password = document.backups.password.value;
  142.  
  143.     if (is_white_space(password)) {
  144.  
  145.         alert("You must enter a password value.");
  146.  
  147.         document.backups.password.focus();
  148.  
  149.         return(false);
  150.     }
  151.  
  152.     return(true);
  153. }
  154. //////////////////////////////////////////////////////////////////////////////
  155. // -->
  156. </script>
  157. </head>
  158. <body>
  159. <?
  160. $web->show_logo("Backup Tables");
  161. ?>
  162. <a href="admin.php">Administration</a>
  163. <br>
  164. <?
  165. if (
  166. ($_SESSION['NODUP_BACKUPS']) &&
  167. (isset($_POST['id'])) &&
  168. ($_SESSION['NODUP_BACKUPS'] == $_POST['id'])) {
  169.  
  170.         //Do nothing...prevents refresh duplication of last action
  171.  
  172. } else if (
  173. (isset($_POST['backup_tables'])) &&
  174. (isset($_POST['id'])) &&
  175. (isset($_POST['password']))) {
  176.  
  177.     $total_tables = count($_POST['backup_tables']);
  178.  
  179.     $all_flag = 0;
  180.  
  181.     $fail_flag = 0;
  182.  
  183.     foreach($_POST['backup_tables'] as $table) {
  184.  
  185.         $table = $web->strip($table);
  186.  
  187.         if ($total_tables > 1 && $table == "all") {
  188.  
  189.             print 
  190.             "<hr><b>You can't select ALL TABLES " .
  191.             "and one or more individual tables.  " .
  192.             "Select one or the other only.</b><hr>\n";
  193.  
  194.             $fail_flag = 1;
  195.  
  196.             break;
  197.  
  198.         } else if ($table == "all") {
  199.  
  200.             $all_flag = 1;
  201.         }
  202.     }
  203.  
  204.     if (!$fail_flag) {
  205.  
  206.         if ($_SESSION['NODUP_BACKUPS']) {
  207.  
  208.             unset($_SESSION['NODUP_BACKUPS']);
  209.         }
  210.  
  211.         $errstr = 
  212.         $indonesia->login($_SESSION['ADMIN'], $_POST['password']);
  213.  
  214.         if ($errstr != "") {
  215.  
  216.             print "<hr><b>Permission denied!</b><hr>\n";
  217.  
  218.         } else if ($all_flag == 1) {
  219.  
  220.             $errstr = $indonesia->backup();
  221.  
  222.             if ($errstr != "") {
  223.  
  224.                 print 
  225.                 "<hr><b>${errstr}</b><hr>\n";
  226.  
  227.             } else {
  228.  
  229.                 print 
  230.                 "<hr><b>Successful backup for " .
  231.                 "all tables.</b><hr>\n";
  232.  
  233.                 $_SESSION['NODUP_BACKUPS'] = $_POST['id'];
  234.             }
  235.  
  236.         } else {
  237.  
  238.             $backed_up_tables = 0;
  239.  
  240.             $fail_flag = 0;
  241.  
  242.             foreach($_POST['backup_tables'] as $table) {
  243.  
  244.                 $table = $web->strip($table);
  245.  
  246.                 $errstr = $indonesia->create_backup($table);
  247.  
  248.                 if ($errstr != "") {
  249.  
  250.                     print "<hr><b>${errstr}</b><hr>\n";
  251.  
  252.                     $fail_flag = 1;
  253.  
  254.                     break;
  255.                 } else {
  256.  
  257.                     $table_uc = ucfirst($table);
  258.  
  259.                     $table_uc = 
  260.                     preg_replace("/_/", " ", $table_uc);
  261.  
  262.                     print 
  263.                     "<hr><b>Successful backup " .
  264.                     "for table: ${table_uc}</b><hr>\n";
  265.  
  266.                     $backed_up_tables++;
  267.                 }
  268.  
  269.                 if ($backed_up_tables == 1) {
  270.  
  271.                     $_SESSION['NODUP_BACKUPS'] = 
  272.                         $_POST['id'];
  273.                 }
  274.             }
  275.  
  276.             if ((!$fail_flag) && ($backed_up_tables == 0)) {
  277.  
  278.                 print
  279.                 "<hr><b>You must select at least " .
  280.                 "one table or ALL TABLES.</b><hr>\n"; 
  281.             }
  282.         }
  283.     }
  284.  
  285. } else if ( 
  286. (isset($_POST['id'])) &&
  287. (isset($_POST['password']))) {
  288.  
  289.     if ($_SESSION['NODUP_BACKUPS']) {
  290.  
  291.         unset($_SESSION['NODUP_BACKUPS']);
  292.     }
  293.  
  294.     print 
  295.     "<hr><b>You must select at least one table or ALL TABLES.</b><hr>\n";
  296. }
  297.  
  298. show_tables($web, $indonesia);
  299.  
  300. ?>
  301. </body>
  302. </html>
  303.  
  304. <?
  305. //////////////////////////////////////////////////////////////////////////////
  306. function show_tables($web, $indonesia) {
  307.  
  308.     $sql_files = array();
  309.  
  310.     $id = uniqid(rand(), true);
  311.  
  312.     $errstr = $indonesia->get_sql_data_files($sql_files);
  313.  
  314.     if ($errstr != "") {
  315.  
  316.         print "<br><hr><b>${errstr}</b><hr><br>\n";
  317.  
  318.         return;
  319.     }
  320.  
  321.     $total_tables = count($sql_files) + 1;
  322.  
  323.     $table_select =
  324.     "\n<select multiple size=\"${total_tables}\" " .
  325.     "name=\"backup_tables[]\">\n" .
  326.     "<option value=\"all\">ALL TABLES\n";
  327.  
  328.     foreach($sql_files as $table => $path) {
  329.  
  330.         $table = $web->tohtml($table);
  331.  
  332.         $table_uc = ucfirst($table);
  333.  
  334.         $table_uc = preg_replace("/_/", " ", $table_uc);
  335.  
  336.         $table_select .= "<option value=\"${table}\">${table_uc}\n";
  337.     }
  338.  
  339.     $table_select .= "</select>\n";    
  340.  
  341.     print <<<EOFST
  342. <form name="backups" method="post" onsubmit='return verify()'>
  343. <table width="50%" cellpadding="3" cellspacing="3" border="1">
  344. <tr>
  345. <td wrap>
  346. <b>Select one or more<br>
  347. tables or ALL TABLES:</b>
  348. </td>
  349. <td colspan="2">${table_select}</td>
  350. </tr><tr>
  351. <td colspan="3"> </td>
  352. </tr><tr>
  353. <td>
  354. <input type="submit" value="Backup!">
  355. </td>
  356. <td>
  357. <b>Password:</b>
  358. </td>
  359. <td align="center">
  360. <input type="password" name="password">
  361. </td>
  362. </tr>
  363. </tr><tr>
  364. <td wrap colspan="3">
  365. <i>Note: Some tables may require up to a few minutes to do a complete 
  366. backup.  Please wait for backup to complete before doing something else.</i> 
  367. </td>
  368. </tr>
  369. </table>
  370. <input type="hidden" name="id" value="${id}">
  371. </form>
  372. <script language="Javascript" type="text/javascript"> 
  373. </script>
  374. EOFST;
  375.  
  376.     return;
  377. }
  378. //////////////////////////////////////////////////////////////////////////////
  379. //////////////////////////////////////////////////////////////////////////////
  380. ?>
  381. @
  382.  
  383.  
  384. 1.8
  385. log
  386. @*** empty log message ***
  387. @
  388. text
  389. @d12 1
  390. a12 1
  391. // Modified:     October 17, 2003
  392. d62 2
  393. @
  394.  
  395.  
  396. 1.7
  397. log
  398. @*** empty log message ***
  399. @
  400. text
  401. @d12 1
  402. a12 1
  403. // Modified:     October 05, 2003
  404. d63 2
  405. d66 1
  406. a66 25
  407. //////////////////////////////////////////////////////////////////////////////
  408. function is_white_space(stoken) {
  409.  
  410.     if (stoken == null) return(true);
  411.  
  412.     if (stoken == '') return(true);
  413.  
  414.     if (stoken == "") return(true);
  415.  
  416.     return(false);
  417. }
  418. //////////////////////////////////////////////////////////////////////////////
  419. function trim(stoken) {
  420.  
  421.     if (is_white_space(stoken)) {
  422.  
  423.         return(stoken);
  424.     }
  425.  
  426.     stoken = stoken.replace(/^\s*/, "");
  427.  
  428.     stoken = stoken.replace(/\s*$/, "");
  429.  
  430.     return(stoken);
  431. }
  432. d84 1
  433. a84 1
  434. //////////////////////////////////////////////////////////////////////////////
  435. @
  436.  
  437.  
  438. 1.6
  439. log
  440. @*** empty log message ***
  441. @
  442. text
  443. @d12 1
  444. a12 1
  445. // Modified:     September 30, 2003
  446. d110 3
  447. a112 1
  448. <h2>Bahasa Indonesia Dictionary: Backup Tables</h2>
  449. @
  450.  
  451.  
  452. 1.5
  453. log
  454. @*** empty log message ***
  455. @
  456. text
  457. @d12 1
  458. a12 1
  459. // Modified:     September 08, 2003
  460. d40 1
  461. a40 1
  462. if (!session_is_registered("ADMIN")) {
  463. d115 1
  464. a115 1
  465. (session_is_registered("NODUP_BACKUPS")) &&
  466. d155 1
  467. a155 1
  468.         if (session_is_registered("NODUP_BACKUPS")) {
  469. d157 1
  470. a157 1
  471.             session_unregister("NODUP_BACKUPS");
  472. d182 1
  473. a182 3
  474.                 $NODUP_BACKUPS = $_POST['id'];
  475.  
  476.                 session_register("NODUP_BACKUPS");
  477. d220 2
  478. a221 3
  479.                     $NODUP_BACKUPS = $_POST['id'];
  480.  
  481.                     session_register("NODUP_BACKUPS");
  482. d238 1
  483. a238 1
  484.     if (session_is_registered("NODUP_BACKUPS")) {
  485. d240 1
  486. a240 1
  487.         session_unregister("NODUP_BACKUPS");
  488. d292 1
  489. a292 1
  490. <table cellpadding="3" cellspacing="3" border="1">
  491. d308 1
  492. a308 1
  493. <td bgcolor="black">
  494. d310 6
  495. @
  496.  
  497.  
  498. 1.4
  499. log
  500. @*** empty log message ***
  501. @
  502. text
  503. @d12 1
  504. a12 1
  505. // Modified:     September 04, 2003
  506. d109 1
  507. a109 1
  508. <body bgcolor="#CCCC99">
  509. @
  510.  
  511.  
  512. 1.3
  513. log
  514. @*** empty log message ***
  515. @
  516. text
  517. @d12 1
  518. a12 1
  519. // Modified:     September 03, 2003
  520. a91 13
  521.     //name = document.backups.backup_tables[].value;
  522.  
  523.     //if (is_white_space(name)) {
  524.  
  525.     //    alert(
  526.     //    "You must select one or more tables " + 
  527.     //    "to backup or ALL tables.");
  528.  
  529.     //    document.backups.backup_tables.focus();
  530.  
  531.     //    return(false);
  532.     //}
  533.  
  534. d109 1
  535. a109 1
  536. <body>
  537. d236 12
  538. d298 2
  539. a299 2
  540. Select one or more<br>
  541. tables or ALL TABLES:
  542. d309 1
  543. a309 1
  544. Password:
  545. d311 1
  546. a311 1
  547. <td>
  548. @
  549.  
  550.  
  551. 1.2
  552. log
  553. @*** empty log message ***
  554. @
  555. text
  556. @d12 1
  557. a12 1
  558. // Modified:     August 18, 2003
  559. a46 9
  560. if (session_is_registered("NODUP_BACKUP_TABLE")) {
  561.  
  562.     session_unregister("NODUP_BACKUP_TABLE");
  563.  
  564.     $web->redirect("admin.php");
  565.  
  566.     exit;
  567. }
  568.  
  569. d61 1
  570. a61 1
  571. <title>Bahasa Indonesia Dictionary: Backup</title>
  572. d92 1
  573. a92 1
  574.     name = document.backup.backup_table.value;
  575. d94 1
  576. a94 1
  577.     if (is_white_space(name)) {
  578. d96 3
  579. a98 1
  580.         alert("You must select a table to backup or ALL tables.");
  581. d100 1
  582. a100 1
  583.         document.backup.backup_table.focus();
  584. d102 2
  585. a103 2
  586.         return(false);
  587.     }
  588. d105 1
  589. a105 1
  590.     password = document.backup.password.value;
  591. d111 1
  592. a111 1
  593.         document.backup.password.focus();
  594. d123 1
  595. a123 1
  596. <h2>Bahasa Indonesia Dictionary: Backup</h2>
  597. d125 1
  598. a125 1
  599. <br><br>
  600. d127 40
  601. a166 1
  602. if (isset($_POST['backup_table']) && isset($_POST['password'])) {
  603. d168 1
  604. a168 1
  605.     $errstr = $indonesia->login($_SESSION['ADMIN'], $_POST['password']);
  606. d170 5
  607. a174 1
  608.     if ($errstr != "") {
  609. d176 1
  610. a176 1
  611.         print "<br><hr><b>Permission denied!</b><hr><br>\n";
  612. d178 1
  613. a178 1
  614.     } else { 
  615. d180 1
  616. a180 1
  617.         if ($_POST['backup_table'] == "all") {
  618. d187 1
  619. a187 1
  620.                 "<br><hr><b>${errstr}</b><hr><br>\n";
  621. d192 2
  622. a193 2
  623.                 "<br><hr><b>Successful backup operation " .
  624.                 "for all tables.</b><hr><br>\n";
  625. d195 1
  626. a195 1
  627.                 $NODUP_BACKUP_TABLE = 1;
  628. d197 1
  629. a197 1
  630.                 session_register("NODUP_BACKUP_TABLE");
  631. d200 22
  632. a221 1
  633.         } else { 
  634. d223 2
  635. a224 2
  636.             $errstr = 
  637.             $indonesia->create_backup($_POST['backup_table']);
  638. d226 6
  639. a231 1
  640.             if ($errstr != "") {
  641. d233 1
  642. a233 2
  643.                 print 
  644.                 "<br><hr><b>${errstr}</b><hr><br>\n";
  645. d235 1
  646. a235 1
  647.             } else {
  648. d237 3
  649. a239 6
  650.                 print 
  651.                 "<br><hr><b>Successful backup operation " .
  652.                 "for " .
  653.                 $_POST['backup_table'] . 
  654.                 " table." . 
  655.                 "</b><hr><br>\n";
  656. d241 1
  657. a241 1
  658.                 $NODUP_BACKUP_TABLE = 1;
  659. d243 3
  660. a245 1
  661.                 session_register("NODUP_BACKUP_TABLE");
  662. d249 1
  663. d251 1
  664. a251 1
  665. } else {
  666. a252 2
  667.     show_tables($web, $indonesia);
  668. }
  669. d263 2
  670. d274 2
  671. d277 2
  672. a278 2
  673.     "\n<select name=\"backup_table\">\n" .
  674.     "<option value=\"\">\n" .
  675. d283 2
  676. d295 1
  677. a295 1
  678. <form name="backup" method="post" onsubmit='return verify()'>
  679. d298 4
  680. a301 1
  681. <td>Select a Table:</td>
  682. d317 1
  683. a319 1
  684. document.backup.backup_table.focus();
  685. @
  686.  
  687.  
  688. 1.1
  689. log
  690. @Initial revision
  691. @
  692. text
  693. @d5 33
  694. a37 1
  695.  
  696. a259 1
  697.  
  698. @
  699.  
  700.  
  701. 1.1.1.1
  702. log
  703. @Bahasa Indonesia Dictionary
  704. @
  705. text
  706. @@
  707.