-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-dev.php
218 lines (181 loc) · 7.63 KB
/
build-dev.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
/**
* @file build-dev.php
* @brief Gallery Builder
* @details Builing database, loading images and indexing
*
* @copyright http://www.gnu.org/licenses/lgpl.txt LGPL version 3
* @author Erik Bachmann <[email protected]>
* @since 2024-11-30T07:13:29 / ErBa
* @version @include version.txt
*/
/** @brief Root for timer data */
$GLOBALS['timer'] = TRUE;
include_once( 'lib/handleJson.php');
include_once( 'lib/handleSqlite.php');
include_once( 'lib/debug.php');
include_once( 'lib/map.php');
include_once( 'lib/push.php');
// Include script specific shutdown function. BEFORE _header.php !
include_once( 'lib/'.basename(__FILE__,".php").'.shutdown.php');
//timer_set('_header');
include_once('lib/_header.php');
//timer_set('_header');
timer_set('header', 'Reading header info');
echo "
<!DOCTYPE html>
<html lang='en'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<title>".___('sigbuild_window_title')."</title>
<link rel='stylesheet' href='css/styles.css'>
<!--script src='js/display.js'></script-->
<link rel='icon' type='image/x-icon' href=\"{$GLOBALS['config']['system']['favicon']}\">
<script>
// [How to prevent form resubmission when page is refreshed (F5 / CTRL+R)](https://stackoverflow.com/a/45656609)
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
function clicked( str ) {
document.getElementById('action').value='build_sub.php?' + str;
document.getElementById('action').value+='&database_name=' + document.getElementById('database_name').value;
document.getElementById('action').value+='&source_dir=' + document.getElementById('source_dir').value.replace('/\\/g', '/');;
document.getElementById('action_frame').src=document.getElementById('action').value;
console.log( 'clicked');
} // clicked()
//----------------------------------------------------------------------
function replace_slash( str ) {
//console.log('change ' + str);
// Replace backslash
str = str.replaceAll( /\\\\/g, \"/\");
// Remove qoutes
str = str.replaceAll( /['\"]+/g, '' );
//console.log('changed ' + str);
return str;
} // replace_slash()
</script>
</head>
<body>
";
debug( $GLOBALS['browser']['language'], "session language: ");
/** @brief Dummy dir */
$releaseroot = __DIR__ . '/';
/** @brief Verbose mode on by default */
$verbose=1;
/** @brief Debug mode */
//$debug=1;
// Default path = all
if ( empty( $_REQUEST['path']) )
$_REQUEST['path'] = '.';
if ( empty( $_REQUEST['action']) )
$_REQUEST['action'] = '';
if ( empty( $_REQUEST['QUERY_STRING']) )
//$_REQUEST['QUERY_STRING'] = '';
$_REQUEST['QUERY_STRING'] = http_build_query($_REQUEST);
timer_set('header', 'end');
/** @brief Database File Name: Argument / config / hard coded default */
$database_name = $_REQUEST['db']
?? $GLOBALS['config']['database']['file_name']
?? 'database/data.db' ;
/** @brief Image Source Dir: Argument / config / hard coded default */
$source = $_REQUEST['source']
?? $GLOBALS['config']['data']['data_root']
?? 'C:/TMP/test_data/' ;
echo "<h2>".___('sigbuild_title')."</h2>";
$loc = [
'database' => ___('database'), // Database
'create_database' => ___('create_database'), // Create database
'source_dir' => ___('source_dir'), // Source dir
'update_images' => ___('update_images'), // {$loc['database']}
'delete_directories' => ___('delete_directories'), // {$loc['database']}
'submit' => ___('submit'),
'clear' => ___('clear'),
'action' => ___('action'),
'reindex' => ___('reindex'),
'test_wordclouds' => ___('test_wordclouds'),
'test_index' => ___('test_index'),
];
echo <<<EOF
<form id="build_form" action=""> <!-- Action to self -->
<table border=1>
<!-- Database -->
<tr><th>
<label for="database_name">{$loc['database']}:</label>
</th><td>
<input type="text" id="database_name" name="database_name" onchange="this.value = replace_slash(this.value);" size=50 value="{$database_name}">
</td><td>
<!-- Button: Create -->
<button type="button" onClick="clicked('action=create_database');" >🗍 {$loc['create_database']}</button>
</td></tr>
<!-- Source -->
<tr><th>
<label for="source_dir">{$loc['source_dir']}:</label>
</th><td>
<input type="text" id="source_dir" name="source_dir" size=50 onchange="this.value = replace_slash(this.value);" value="{$source}">
</td><td>
<!-- Button: Update -->
<button type="button" onClick="clicked('action=update_images');">🗘 {$loc['update_images']}</button>
<!-- Button: Delete dirs -->
<button type="button" onClick="clicked('action=delete_images');">⌦ {$loc['delete_directories']} 🖾</button>
<!-- Button: Reindex -->
<button type="button" onClick="clicked('action=reindex');">🗃 {$loc['reindex']} 🌪</button>
</td></tr>
<!-- Action -->
<tr><th>
<label for="action">{$loc['action']}:</label>
</th><td>
<input id='action' name='action' type="text" size=50 value='{$_REQUEST['action']}'>
</td><td>
<!-- Button: Test index -->
<button class="btn btn-success" onclick="window.open('index.php','_blank');return false;">🖽 {$loc['test_index']}</button>
<!-- Button: Test wordclouds -->
<button class="btn btn-success" onclick="window.open('wordclouds.php','_blank');return false;">🖽 {$loc['test_wordclouds']}</button>
</td></tr>
</table>
<p> </p>
<!-- Submit -->
<input type="submit" value="{$loc['submit']}">
<input type="button" value="{$loc['clear']}" onClick='document.getElementById("build_form").reset();'>
</form>
<!-- Progress -->
<label for="progress">progress:</label>
<progress id="progress" value="0" max="100"> 0% </progress>
<span id='progress_status'></span>
<br>
<details>
<summary>Iframe</summary>
<iframe id='action_frame' src="{$_REQUEST['action']}" title="description" width=600 height=600></iframe>
</details>
<div id='status' name='status' class='status'></div>
EOF;
echo "<script>document.getElementById( 'status' ).innerHTML = '';</script>\n";
if ( !empty( $_REQUEST['action'] ) )
{
pstate( "<div>action: {$_REQUEST['action']}</div>");
switch( $_REQUEST['action'])
{
case 'delete_action':
if ( ! empty($_REQUEST['files'] ))
{
pstate( "<div>Deleting directories: ");
foreach($_REQUEST['files'] as $dir)
{
// Get count of images in dir
$sql = sprintf( $GLOBALS['database']['sql']['select_count_source_dir'], $dir );
$count = querySqlSingleValue( $db, $sql );
// Delete by dir
$sql = sprintf( $GLOBALS['database']['sql']['delete_image_by_source'], $dir );
$db->exec( $sql );
pstate( "<div>- ⌦ $count $dir</div>");
}
pstate( "<div>done</div>");
}
else
pstate("<div>No files to delete</div>");
break;
default:
pstate( "<div>do nothing</div>" );
}
}
//----------------------------------------------------------------------
?>