-
Notifications
You must be signed in to change notification settings - Fork 87
/
edit_texttags.php
309 lines (252 loc) · 11.6 KB
/
edit_texttags.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
<?php
/**************************************************************
"Learning with Texts" (LWT) is released into the Public Domain.
This applies worldwide.
In case this is not legally possible, any entity is granted the
right to use this work for any purpose, without any conditions,
unless such conditions are required by law.
Developed by J. Pierre in 2011.
***************************************************************/
/**************************************************************
Call: edit_texttags.php?....
... markaction=[opcode] ... do actions on marked text tags
... allaction=[opcode] ... do actions on all text tags
... del=[wordid] ... do delete
... op=Save ... do insert new
... op=Change ... do update
... new=1 ... display new text tag screen
... chg=[wordid] ... display edit screen
... sort=[sortcode] ... sort
... page=[pageno] ... page
... query=[tagtextfilter] ... tag text filter
Manage tags
***************************************************************/
include "connect.inc.php";
include "settings.inc.php";
include "utilities.inc.php";
$currentsort = processDBParam("sort",'currenttexttagsort','1',1);
$currentpage = processSessParam("page","currenttexttagpage",'1',1);
$currentquery = processSessParam("query","currenttexttagquery",'',0);
$wh_query = convert_string_to_sqlsyntax(str_replace("*","%",$currentquery));
$wh_query = ($currentquery != '') ? (' and (T2Text like ' . $wh_query . ' or T2Comment like ' . $wh_query . ')') : '';
pagestart('My Text 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 tags2 where T2ID in ' . $list, "Deleted");
runsql("DELETE texttags FROM (texttags LEFT JOIN tags2 on TtT2ID = T2ID) WHERE T2ID IS NULL",'');
runsql("DELETE archtexttags FROM (archtexttags LEFT JOIN tags2 on AgT2ID = T2ID) WHERE T2ID IS NULL",'');
adjust_autoincr('tags2','T2ID');
}
}
}
}
}
// ALL ACTIONS
if (isset($_REQUEST['allaction'])) {
$allaction = $_REQUEST['allaction'];
if ($allaction == 'delall') {
$message = runsql('delete from tags2 where (1=1) ' . $wh_query, "Deleted");
runsql("DELETE texttags FROM (texttags LEFT JOIN tags2 on TtT2ID = T2ID) WHERE T2ID IS NULL",'');
runsql("DELETE archtexttags FROM (archtexttags LEFT JOIN tags2 on AgT2ID = T2ID) WHERE T2ID IS NULL",'');
adjust_autoincr('tags2','T2ID');
}
}
// DEL
elseif (isset($_REQUEST['del'])) {
$message = runsql('delete from tags2 where T2ID = ' . $_REQUEST['del'], "Deleted");
runsql("DELETE texttags FROM (texttags LEFT JOIN tags2 on TtT2ID = T2ID) WHERE T2ID IS NULL",'');
runsql("DELETE archtexttags FROM (archtexttags LEFT JOIN tags2 on AgT2ID = T2ID) WHERE T2ID IS NULL",'');
adjust_autoincr('tags2','T2ID');
}
// INS/UPD
elseif (isset($_REQUEST['op'])) {
// INSERT
if ($_REQUEST['op'] == 'Save') {
$message = runsql('insert into tags2 (T2Text, T2Comment) values(' .
convert_string_to_sqlsyntax($_REQUEST["T2Text"]) . ', ' .
convert_string_to_sqlsyntax_nonull($_REQUEST["T2Comment"]) . ')', "Saved");
}
// UPDATE
elseif ($_REQUEST['op'] == 'Change') {
$message = runsql('update tags2 set T2Text = ' .
convert_string_to_sqlsyntax($_REQUEST["T2Text"]) . ', T2Comment = ' .
convert_string_to_sqlsyntax_nonull($_REQUEST["T2Comment"]) . ' where T2ID = ' . $_REQUEST["T2ID"], "Updated");
}
}
// NEW
if (isset($_REQUEST['new'])) {
?>
<h4>New Tag</h4>
<form name="newtag" class="validate" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table class="tab3" cellspacing="0" cellpadding="5">
<tr>
<td class="td1 right">Tag:</td>
<td class="td1"><input class="notempty setfocus noblanksnocomma" type="text" name="T2Text" 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" data_maxlength="200" data_info="Comment" name="T2Comment" cols="40" rows="3"></textarea></td>
</tr>
<tr>
<td class="td1 right" colspan="2">
<input type="button" value="Cancel" onclick="location.href='edit_texttags.php';" />
<input type="submit" name="op" value="Save" /></td>
</tr>
</table>
</form>
<?php
}
// CHG
elseif (isset($_REQUEST['chg'])) {
$sql = 'select * from tags2 where T2ID = ' . $_REQUEST['chg'];
$res = mysql_query($sql);
if ($res == FALSE) die("Invalid Query: $sql");
if ($record = mysql_fetch_assoc($res)) {
?>
<h4>Edit Tag</h4>
<form name="edittag" class="validate" action="<?php echo $_SERVER['PHP_SELF']; ?>#rec<?php echo $_REQUEST['chg']; ?>" method="post">
<input type="hidden" name="T2ID" value="<?php echo $record['T2ID']; ?>" />
<table class="tab3" cellspacing="0" cellpadding="5">
<tr>
<td class="td1 right">Tag:</td>
<td class="td1"><input data_info="Tag" class="notempty setfocus noblanksnocomma" type="text" name="T2Text" value="<?php echo tohtml($record['T2Text']); ?>" 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" data_maxlength="200" data_info="Comment" name="T2Comment" cols="40" rows="3"><?php echo tohtml($record['T2Comment']); ?></textarea></td>
</tr>
<tr>
<td class="td1 right" colspan="2">
<input type="button" value="Cancel" onclick="location.href='edit_texttags.php#rec<?php echo $_REQUEST['chg']; ?>';" />
<input type="submit" name="op" value="Change" /></td>
</tr>
</table>
</form>
<?php
}
mysql_free_result($res);
}
// DISPLAY
else {
echo error_message_with_hide($message,0);
get_texttags(1); // refresh tags cache
$sql = 'select count(T2ID) as value from tags2 where (1=1) ' . $wh_query;
$recno = get_first_value($sql);
if ($debug) echo $sql . ' ===> ' . $recno;
$maxperpage = 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('T2Text','T2Comment','T2ID desc');
$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 Text Tag ...</a></p>
<form name="form1" action="#" onsubmit="document.form1.querybutton.click(); return false;">
<table class="tab1" 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_texttags.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_texttags.php?page=1&query=' + val;}" />
<input type="button" value="Clear" onclick="{location.href='edit_texttags.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_texttags.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_texttags.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="tab1" 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 tab1" 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">Texts<br />With Tag</th>
<th class="th1 clickable">Arch.Texts<br />With Tag</th>
</tr>
<?php
$sql = 'select T2ID, T2Text, T2Comment from tags2 where (1=1) ' . $wh_query . ' order by ' . $sorts[$currentsort-1] . ' ' . $limit;
if ($debug) echo $sql;
$res = mysql_query($sql);
if ($res == FALSE) die("Invalid Query: $sql");
while ($record = mysql_fetch_assoc($res)) {
$c = get_first_value('select count(*) as value from texttags where TtT2ID=' . $record['T2ID']);
$ca = get_first_value('select count(*) as value from archtexttags where AgT2ID=' . $record['T2ID']);
echo '<tr>';
echo '<td class="td1 center"><a name="rec' . $record['T2ID'] . '"><input name="marked[]" type="checkbox" class="markcheck" value="' . $record['T2ID'] . '" ' . checkTest($record['T2ID'], 'marked') . ' /></a></td>';
echo '<td class="td1 center" nowrap="nowrap"> <a href="' . $_SERVER['PHP_SELF'] . '?chg=' . $record['T2ID'] . '"><img src="icn/document--pencil.png" title="Edit" alt="Edit" /></a> <a href="' . $_SERVER['PHP_SELF'] . '?del=' . $record['T2ID'] . '"><img src="icn/minus-button.png" title="Delete" alt="Delete" /></a> </td>';
echo '<td class="td1 center">' . tohtml($record['T2Text']) . '</td>';
echo '<td class="td1 center">' . tohtml($record['T2Comment']) . '</td>';
echo '<td class="td1 center">' . ($c > 0 ? '<a href="edit_texts.php?page=1&query=&tag12=0&tag2=&tag1=' . $record['T2ID'] . '">' . $c . '</a>' : '0' ) . '</td>';
echo '<td class="td1 center">' . ($ca > 0 ? '<a href="edit_archivedtexts.php?page=1&query=&tag12=0&tag2=&tag1=' . $record['T2ID'] . '">' . $ca . '</a>' : '0' ) . '</td>';
echo '</tr>';
}
mysql_free_result($res);
?>
</table>
</form>
<?php if( $pages > 1) { ?>
<table class="tab1" 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_texttags.php', 'form1'); ?>
</th></tr></table>
<?php } ?>
<?php
}
}
pageend();
?>