|
11 | 11 |
|
12 | 12 | // RESTORE DEMO |
13 | 13 |
|
14 | | -if (isset($_REQUEST['install'])) { |
15 | | - $file = getcwd() . '/install_demo_db.sql.gz'; |
| 14 | +/** |
| 15 | + * Restore demo database from file. |
| 16 | + * |
| 17 | + * @return string Status message |
| 18 | + */ |
| 19 | +function restore_demo_db() |
| 20 | +{ |
| 21 | + $file = getcwd() . '/install_demo_db.sql'; |
16 | 22 | if (file_exists($file) ) { |
17 | | - $handle = gzopen($file, "r"); |
| 23 | + $handle = fopen($file, "r"); |
18 | 24 | if ($handle === false) { |
19 | | - $message = "Error: File ' . $file . ' could not be opened"; |
20 | | - } // $handle not OK |
21 | | - else { // $handle OK |
22 | | - $message = restore_file($handle, "Demo Database"); |
| 25 | + return "Error: File ' . $file . ' could not be opened"; |
| 26 | + // $handle not OK |
| 27 | + } else { |
| 28 | + // $handle OK |
| 29 | + return restore_file($handle, "Demo Database"); |
23 | 30 | } // $handle OK |
24 | | - } // restore file specified |
25 | | - else { |
26 | | - $message = "Error: File ' . $file . ' does not exist"; |
| 31 | + } else { |
| 32 | + // restore file specified |
| 33 | + return "Error: File ' . $file . ' does not exist"; |
27 | 34 | } |
| 35 | +} |
| 36 | + |
| 37 | +if (isset($_REQUEST['install'])) { |
| 38 | + $message = restore_demo_db(); |
28 | 39 | } |
29 | 40 |
|
30 | 41 | pagestart('Install LWT Demo Database', true); |
31 | 42 |
|
32 | 43 | echo error_message_with_hide($message, 1); |
33 | 44 |
|
34 | | -$langcnt = get_first_value('select count(*) as value from ' . $tbpref . 'languages'); |
| 45 | +$langcnt = get_first_value("SELECT COUNT(*) AS value FROM {$tbpref}languages"); |
35 | 46 |
|
36 | 47 | if ($tbpref == '') { |
37 | 48 | $prefinfo = "(Default Table Set)"; |
38 | | -} |
39 | | -else { |
| 49 | +} else { |
40 | 50 | $prefinfo = "(Table Set: <i>" . tohtml(substr($tbpref, 0, -1)) . "</i>)"; |
41 | 51 | } |
42 | 52 |
|
43 | 53 | ?> |
44 | 54 | <form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" onsubmit="return confirm('Are you sure?');"> |
45 | 55 | <table class="tab3" cellspacing="0" cellpadding="5"> |
46 | | -<tr> |
47 | | -<th class="th1 center">Install Demo</th> |
48 | | -<td class="td1"> |
49 | | -<p class="smallgray2"> |
50 | | -The database <i><?php echo tohtml($dbname); ?></i> <?php echo $prefinfo; ?> will be <b>replaced</b> by the LWT demo database. |
51 | | - |
52 | | -<?php |
53 | | -if ($langcnt > 0 ) { |
54 | | - ?> |
55 | | - <br />The existent database will be <b>overwritten!</b> |
56 | | - <?php |
57 | | -} |
58 | | -?> |
| 56 | + <tr> |
| 57 | + <th class="th1 center">Install Demo</th> |
| 58 | + <td class="td1"> |
| 59 | + <p class="smallgray2"> |
| 60 | + The database <i><?php echo tohtml($dbname); ?></i> |
| 61 | + <?php echo $prefinfo; ?> will be <b>replaced</b> by the LWT |
| 62 | + demo database. |
| 63 | + <?php |
| 64 | + if ($langcnt > 0) { |
| 65 | + ?> |
| 66 | + <br />The existent database will be <b>overwritten!</b> |
| 67 | + <?php |
| 68 | + } |
| 69 | + ?> |
59 | 70 |
|
60 | | -</p> |
61 | | -<p class="right"> <br /><span class="red2">YOU MAY LOSE DATA - BE CAREFUL: </span> |
62 | | -<input type="submit" name="install" value="Install LWT demo database" /></p> |
63 | | -</td> |
64 | | -</tr> |
65 | | -<tr> |
66 | | -<td class="td1 right" colspan="2"> |
67 | | -<input type="button" value="<< Back to LWT Main Menu" onclick="location.href='index.php';" /></td> |
68 | | -</tr> |
| 71 | + </p> |
| 72 | + <p class="right"> |
| 73 | + <br /><span class="red2"> |
| 74 | + YOU MAY LOSE DATA - BE CAREFUL: |
| 75 | + </span> |
| 76 | + <input type="submit" name="install" value="Install LWT demo database" /></p> |
| 77 | + </td> |
| 78 | + </tr> |
| 79 | + <tr> |
| 80 | + <td class="td1 right" colspan="2"> |
| 81 | + <input type="button" value="<< Back to LWT Main Menu" onclick="location.href='index.php';" /> |
| 82 | + </td> |
| 83 | + </tr> |
69 | 84 | </table> |
70 | 85 | </form> |
71 | 86 |
|
|
0 commit comments