forked from chaosarium/lwt
-
Notifications
You must be signed in to change notification settings - Fork 20
/
edit_tags.php
352 lines (301 loc) · 13.1 KB
/
edit_tags.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<?php
/**
* Manage tags
*
* Call: edit_tags.php?....
* ... markaction=[opcode] ... do actions on marked tags
* ... allaction=[opcode] ... do actions on all tags
* ... del=[wordid] ... do delete
* ... op=Save ... do insert new
* ... op=Change ... do update
* ... new=1 ... display new tag screen
* ... chg=[wordid] ... display edit screen
* ... sort=[sortcode] ... sort
* ... page=[pageno] ... page
* ... query=[tagtextfilter] ... tag text filter
*
* PHP version 8.1
*
* @category User_Interface
* @package Lwt
*/
namespace Lwt\Interface\Edit_Tags;
require_once 'inc/session_utility.php';
$currentsort = (int) processDBParam("sort", 'currenttagsort', '1', true);
$currentpage = (int) processSessParam("page", "currenttagpage", '1', true);
$currentquery = (string) processSessParam("query", "currenttagquery", '', false);
$wh_query = convert_string_to_sqlsyntax(str_replace("*", "%", $currentquery));
$wh_query = ($currentquery != '') ? (' and (TgText like ' . $wh_query . ' or TgComment like ' . $wh_query . ')') : '';
pagestart('My Term Tags', true);
$message = '';
// MARK ACTIONS
if (isset($_REQUEST['markaction'])) {
$markaction = $_REQUEST['markaction'];
$message = "Multiple Actions: 0";
if (isset($_REQUEST['marked'])) {
if (is_array($_REQUEST['marked'])) {
$l = count($_REQUEST['marked']);
if ($l > 0) {
$list = "(" . $_REQUEST['marked'][0];
for ($i=1; $i<$l; $i++) {
$list .= "," . $_REQUEST['marked'][$i];
}
$list .= ")";
if ($markaction == 'del') {
$message = runsql(
'delete from ' . $tbpref . 'tags
where TgID in ' . $list,
"Deleted"
);
runsql(
"DELETE " . $tbpref . "wordtags FROM (
" . $tbpref . "wordtags LEFT JOIN " . $tbpref . "tags
on WtTgID = TgID
) WHERE TgID IS NULL",
''
);
adjust_autoincr('tags', 'TgID');
}
}
}
}
}
// ALL ACTIONS
if (isset($_REQUEST['allaction'])) {
$allaction = $_REQUEST['allaction'];
if ($allaction == 'delall') {
$message = runsql('delete from ' . $tbpref . 'tags where (1=1) ' . $wh_query, "Deleted");
runsql("DELETE " . $tbpref . "wordtags FROM (" . $tbpref . "wordtags LEFT JOIN " . $tbpref . "tags on WtTgID = TgID) WHERE TgID IS NULL", '');
adjust_autoincr('tags', 'TgID');
}
}
// DEL
elseif (isset($_REQUEST['del'])) {
$message = runsql('delete from ' . $tbpref . 'tags where TgID = ' . $_REQUEST['del'], "Deleted");
runsql("DELETE " . $tbpref . "wordtags FROM (" . $tbpref . "wordtags LEFT JOIN " . $tbpref . "tags on WtTgID = TgID) WHERE TgID IS NULL", '');
adjust_autoincr('tags', 'TgID');
}
// INS/UPD
elseif (isset($_REQUEST['op'])) {
// INSERT
if ($_REQUEST['op'] == 'Save') {
$message = runsql(
'insert into ' . $tbpref . 'tags (TgText, TgComment) values(' .
convert_string_to_sqlsyntax($_REQUEST["TgText"]) . ', ' .
convert_string_to_sqlsyntax_nonull($_REQUEST["TgComment"]) . ')', "Saved", $sqlerrdie = false
);
}
// UPDATE
elseif ($_REQUEST['op'] == 'Change') {
$message = runsql(
'update ' . $tbpref . 'tags set TgText = ' .
convert_string_to_sqlsyntax($_REQUEST["TgText"]) . ', TgComment = ' .
convert_string_to_sqlsyntax_nonull($_REQUEST["TgComment"]) . ' where TgID = ' . $_REQUEST["TgID"], "Updated", $sqlerrdie = false
);
}
}
// NEW
if (isset($_REQUEST['new'])) {
?>
<h2>New Tag</h2>
<script type="text/javascript" charset="utf-8">
$(document).ready(lwtFormCheck.askBeforeExit);
</script>
<form name="newtag" class="validate" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table class="tab1" cellspacing="0" cellpadding="5">
<tr>
<td class="td1 right">Tag:</td>
<td class="td1">
<input class="notempty setfocus noblanksnocomma checkoutsidebmp respinput"
type="text" name="TgText" data_info="Tag" value="" maxlength="20" size="20" />
<img src="icn/status-busy.png" title="Field must not be empty" alt="Field must not be empty" />
</td>
</tr>
<tr>
<td class="td1 right">Comment:</td>
<td class="td1">
<textarea class="textarea-noreturn checklength checkoutsidebmp respinput"
data_maxlength="200" data_info="Comment" name="TgComment" cols="40" rows="3"></textarea>
</td>
</tr>
<tr>
<td class="td1 right" colspan="2">
<input type="button" value="Cancel" onclick="{lwtFormCheck.resetDirty(); location.href='edit_tags.php';}" />
<input type="submit" name="op" value="Save" />
</td>
</tr>
</table>
</form>
<?php
} elseif (isset($_REQUEST['chg'])) {
// CHG
$sql = 'select * from ' . $tbpref . 'tags where TgID = ' . $_REQUEST['chg'];
$res = do_mysqli_query($sql);
if ($record = mysqli_fetch_assoc($res)) {
?>
<h2>Edit Tag</h2>
<script type="text/javascript" charset="utf-8">
$(document).ready(lwtFormCheck.askBeforeExit);
</script>
<form name="edittag" class="validate" action="<?php echo $_SERVER['PHP_SELF']; ?>#rec<?php echo $_REQUEST['chg']; ?>" method="post">
<input type="hidden" name="TgID" value="<?php echo $record['TgID']; ?>" />
<table class="tab1" cellspacing="0" cellpadding="5">
<tr>
<td class="td1 right">Tag:</td>
<td class="td1">
<input data_info="Tag" class="notempty setfocus noblanksnocomma checkoutsidebmp respinput"
type="text" name="TgText" value="<?php echo tohtml($record['TgText']); ?>" maxlength="20" size="20" />
<img src="icn/status-busy.png" title="Field must not be empty" alt="Field must not be empty" /></td>
</tr>
<tr>
<td class="td1 right">Comment:</td>
<td class="td1">
<textarea class="textarea-noreturn checklength checkoutsidebmp respinput"
data_maxlength="200" data_info="Comment" name="TgComment" rows="3"><?php echo tohtml($record['TgComment']); ?></textarea>
</td>
</tr>
<tr>
<td class="td1 right" colspan="2">
<input type="button" value="Cancel" onclick="{lwtFormCheck.resetDirty(); location.href='edit_tags.php#rec<?php echo $_REQUEST['chg']; ?>';}" />
<input type="submit" name="op" value="Change" /></td>
</tr>
</table>
</form>
<?php
}
mysqli_free_result($res);
} else {
// DISPLAY
if (substr($message, 0, 24) == "Error: Duplicate entry '"
&& substr($message, -18) == "' for key 'TgText'"
) {
$message = substr($message, 24);
$message = substr($message, 0, strlen($message)-18);
$message = "Error: Term Tag '" . $message .
"' already exists. Please go back and correct this!";
}
echo error_message_with_hide($message, false);
get_tags($refresh = 1); // refresh tags cache
$sql = 'select count(TgID) as value from ' . $tbpref . 'tags where (1=1) ' . $wh_query;
$recno = (int) get_first_value($sql);
if ($debug) {
echo $sql . ' ===> ' . $recno;
}
$maxperpage = (int) getSettingWithDefault('set-tags-per-page');
$pages = $recno == 0 ? 0 : (intval(($recno-1) / $maxperpage) + 1);
if ($currentpage < 1) {
$currentpage = 1;
}
if ($currentpage > $pages) {
$currentpage = $pages;
}
$limit = 'LIMIT ' . (($currentpage-1) * $maxperpage) . ',' . $maxperpage;
$sorts = array('TgText','TgComment','TgID desc','TgID asc');
$lsorts = count($sorts);
if ($currentsort < 1) { $currentsort = 1;
}
if ($currentsort > $lsorts) { $currentsort = $lsorts;
}
?>
<p><a href="<?php echo $_SERVER['PHP_SELF']; ?>?new=1"><img src="icn/plus-button.png" title="New" alt="New" /> New Term Tag ...</a></p>
<form name="form1" action="#" onsubmit="document.form1.querybutton.click(); return false;">
<table class="tab2" cellspacing="0" cellpadding="5">
<tr>
<th class="th1" colspan="4">Filter <img src="icn/funnel.png" title="Filter" alt="Filter" />
<input type="button" value="Reset All" onclick="{location.href='edit_tags.php?page=1&query=';}" /></th>
</tr>
<tr>
<td class="td1 center" colspan="4">
Tag Text or Comment:
<input type="text" name="query" value="<?php echo tohtml($currentquery); ?>" maxlength="50" size="15" />
<input type="button" name="querybutton" value="Filter" onclick="{val=document.form1.query.value; location.href='edit_tags.php?page=1&query=' + val;}" />
<input type="button" value="Clear" onclick="{location.href='edit_tags.php?page=1&query=';}" />
</td>
</tr>
<?php if($recno > 0) { ?>
<tr>
<th class="th1" colspan="1" nowrap="nowrap">
<?php echo $recno; ?> Tag<?php echo ($recno==1?'':'s'); ?>
</th><th class="th1" colspan="2" nowrap="nowrap">
<?php makePager($currentpage, $pages, 'edit_tags.php', 'form1'); ?>
</th><th class="th1" nowrap="nowrap">
Sort Order:
<select name="sort" onchange="{val=document.form1.sort.options[document.form1.sort.selectedIndex].value; location.href='edit_tags.php?page=1&sort=' + val;}"><?php echo get_tagsort_selectoptions($currentsort); ?></select>
</th></tr>
<?php
} ?>
</table>
</form>
<?php
if ($recno==0) {
?>
<p>No tags found.</p>
<?php
} else {
?>
<form name="form2" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="data" value="" />
<table class="tab2" cellspacing="0" cellpadding="5">
<tr><th class="th1 center" colspan="2">
Multi Actions <img src="icn/lightning.png" title="Multi Actions" alt="Multi Actions" />
</th></tr>
<tr><td class="td1 center" colspan="2">
<b>ALL</b> <?php echo ($recno == 1 ? '1 Tag' : $recno . ' Tags'); ?>:
<select name="allaction" onchange="allActionGo(document.form2, document.form2.allaction,<?php echo $recno; ?>);"><?php echo get_alltagsactions_selectoptions(); ?></select>
</td></tr>
<tr><td class="td1 center">
<input type="button" value="Mark All" onclick="selectToggle(true,'form2');" />
<input type="button" value="Mark None" onclick="selectToggle(false,'form2');" />
</td>
<td class="td1 center">Marked Tags:
<select name="markaction" id="markaction" disabled="disabled" onchange="multiActionGo(document.form2, document.form2.markaction);"><?php echo get_multipletagsactions_selectoptions(); ?></select>
</td></tr></table>
<table class="sortable tab2" cellspacing="0" cellpadding="5">
<tr>
<th class="th1 sorttable_nosort">Mark</th>
<th class="th1 sorttable_nosort">Actions</th>
<th class="th1 clickable">Tag Text</th>
<th class="th1 clickable">Tag Comment</th>
<th class="th1 clickable">Terms With Tag</th>
</tr>
<?php
$sql = 'select TgID, TgText, TgComment from ' . $tbpref . 'tags where (1=1) ' . $wh_query . ' order by ' . $sorts[$currentsort-1] . ' ' . $limit;
if ($debug) {
echo $sql;
}
$res = do_mysqli_query($sql);
while ($record = mysqli_fetch_assoc($res)) {
$c = get_first_value('select count(*) as value from ' . $tbpref . 'wordtags where WtTgID=' . $record['TgID']);
echo '<tr>
<td class="td1 center">
<a name="rec' . $record['TgID'] . '">
<input name="marked[]" type="checkbox" class="markcheck" value="' . $record['TgID'] . '" ' . checkTest($record['TgID'], 'marked') . ' />
</a></td>
<td class="td1 center" nowrap="nowrap"> <a href="' . $_SERVER['PHP_SELF'] . '?chg=' . $record['TgID'] . '"><img src="icn/document--pencil.png" title="Edit" alt="Edit" /></a> <a class="confirmdelete" href="' . $_SERVER['PHP_SELF'] . '?del=' . $record['TgID'] . '"><img src="icn/minus-button.png" title="Delete" alt="Delete" /></a> </td>
<td class="td1 center">' . tohtml($record['TgText']) . '</td>
<td class="td1 center">' . tohtml($record['TgComment']) . '</td>
<td class="td1 center">' . ($c > 0 ? '<a href="edit_words.php?page=1&query=&text=&status=&filterlang=&status=&tag12=0&tag2=&tag1=' . $record['TgID'] . '">' . $c . '</a>' : '0' ) . '</td>
</tr>';
}
mysqli_free_result($res);
?>
</table>
<?php if($pages > 1) { ?>
<table class="tab2" cellspacing="0" cellpadding="5">
<tr>
<th class="th1" nowrap="nowrap">
<?php echo $recno; ?> Tag<?php echo ($recno==1?'':'s'); ?>
</th>
<th class="th1" nowrap="nowrap">
<?php makePager($currentpage, $pages, 'edit_tags.php', 'form2'); ?>
</th>
</tr>
</table>
</form>
<?php
} ?>
<?php
}
}
pageend();
?>