-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
394 lines (341 loc) · 12.3 KB
/
index.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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
<?php
/*
MIT License
Copyright (c) 2023 Golovanov Grigoriy
Contact e-mail: [email protected]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
?>
<html>
<head>
<title>Tabs</title>
<link href="css/styles.css" rel="stylesheet" type="text/css">
</head>
<body>
<?php
session_start();
include "config.php";
include "db.php";
include "functions.php";
include "header.php";
if (isset($_REQUEST['frm_sort'])) {
$_SESSION['frm_sort']=$_REQUEST['frm_sort'];
} else {
$_REQUEST['frm_sort']=$_SESSION['frm_sort'];
}
$_REQUEST['frm_sort']>1 ? $sSortAction="cat_sort DESC" : $sSortAction="cat_desc";
$sQuery="
SELECT *
FROM
".PHP_TM_PDO_TABLENAME_DESC."
ORDER BY
".$sSortAction;
//print $sQuery;
try {
$oResults = $oPDO->query($sQuery);
foreach ($oResults->fetchAll() as $aRow) {
$aCatID[$aRow['id']]=$aRow['cat_id'];
$aCatDesc[$aRow['id']]=$aRow['cat_desc'];
$aCatIcon[$aRow['id']]=$aRow['cat_icon'];
$aCatColor[$aRow['id']]=$aRow['cat_color'];
$aCatType[$aRow['id']]=$aRow['cat_type'];
}
} catch(PDOException $e) {
fErrorHandler(["filename"=>__FILE__, "line"=>__LINE__, "error"=>$e->getMessage()]);
}
$sCheckBoxAddTabAutoTitle=false;
foreach($aCatID as $sID) {
if ($_REQUEST["frm_add_tab_submit_$sID"]=="Add" || $_REQUEST["frm_add_tab_submit_$sID"]=="Update") {
if ($_REQUEST["frm_add_tab_auto_title_$sID"]=="on") {
$sCheckBoxAddTabAutoTitle=true;
}
$aAddTab['title_manual']=$_REQUEST["frm_add_tab_title_$sID"];
$aAddTab['cat_id']=$sID;
$aAddTab['action']=$_REQUEST["frm_add_tab_action_$sID"];
$aAddTab['tab_id']=$_REQUEST["frm_add_tab_edit_item_id_$sID"];
$aAddTab['url']=$_REQUEST["frm_add_tab_url_$sID"];
}
}
if ($_REQUEST['frm_category_action']) {
foreach($_REQUEST as $sName=>$sVal){
$aEXP_frm_check=explode("_", $sName);
if (preg_match("/frm_check/", $sName)==true) {
$aAllRequestID[]=$aEXP_frm_check[2];
if (preg_match("/on/", $sVal)==true) {
$aChecked[]=$aEXP_frm_check[2];
isset($sIDList)? $sIDList.=",".$aEXP_frm_check[2] : $sIDList.=$aEXP_frm_check[2];
}
}
}
// Move selected tabs to another category
if ($_REQUEST['frm_action']=="move") {
$sQuery="
UPDATE
".PHP_TM_PDO_TABLENAME_DATA."
SET
tab_parent_id=".$_REQUEST['frm_category']."
WHERE
id IN (".$sIDList.")";
$sMessage="Move";
}
// Delete selected tabs
if ($_REQUEST['frm_action']=="delete") {
$sQuery="
DELETE FROM
".PHP_TM_PDO_TABLENAME_DATA."
WHERE
id IN (".$sIDList.")";
$sMessage="Delete";
}
//print $sQuery;
try {
$oResults = $oPDO->query($sQuery);
strlen($sMessage) >0 ? fMessageHandler(["message"=>$sMessage." tabs: ", "additional_message"=>" complete!"]) : "";
} catch(PDOException $e) {
fErrorHandler(["filename"=>__FILE__, "line"=>__LINE__, "error"=>$e->getMessage()]);
}
}
// Delete one selected tab
if ($_REQUEST['frm_action']=="delete_one") {
$sQuery="
DELETE FROM
".PHP_TM_PDO_TABLENAME_DATA."
WHERE
id=".$_REQUEST['frm_delete_value_id'];
//print $sQuery;
try {
$oResults = $oPDO->query($sQuery);
fMessageHandler(["message"=>"Deleted tab: ", "additional_message"=>" complete!"]);
} catch(PDOException $e) {
fErrorHandler(["filename"=>__FILE__, "line"=>__LINE__, "error"=>$e->getMessage()]);
}
}
// Update selected icon
if ($_REQUEST['frm_action']=="update_icon") {
$aResult = fParseHTML($_REQUEST['frm_update_icon_domain']);
$sIconSource = fGetIconSource($aResult);
$sQuery="
UPDATE
".PHP_TM_PDO_TABLENAME_DATA."
SET
tab_icon='".$sIconSource."'
WHERE
id=".$_REQUEST['frm_update_icon_id'];
//print $sQuery;
try {
$oResults = $oPDO->query($sQuery);
fMessageHandler(["message"=>"Icon update: ", "additional_message"=>" complete!"]);
} catch(PDOException $e) {
fErrorHandler(["filename"=>__FILE__, "line"=>__LINE__, "error"=>$e->getMessage()]);
}
}
// Update existing tab
if (($aAddTab['action']=="edit") && (strlen($aAddTab['url'])>0)) {
$sQuery="
UPDATE
".PHP_TM_PDO_TABLENAME_DATA."
SET
tab_title='".$aAddTab['title_manual']."',
tab_url='".$aAddTab['url']."'
WHERE id = ".$aAddTab['tab_id'];
//print $sQuery;
try {
$oResults = $oPDO->query($sQuery);
fMessageHandler(["message"=>"Tab update: ", "additional_message"=>" complete!"]);
} catch(PDOException $e) {
fErrorHandler(["filename"=>__FILE__, "line"=>__LINE__, "error"=>$e->getMessage()]);
}
}
// Add new tab
if (($aAddTab['action']=="add_tab") && (strlen($aAddTab['url'])>0)) {
if ($sCheckBoxAddTabAutoTitle==true) {
$aResult = fParseHTML($aAddTab['url']);
$sIconSource = fGetIconSource($aResult);
$sAddTabTitle=$aResult['title'];
} else {
$sAddTabTitle=$aAddTab['title_manual'];
}
$sQuery="
INSERT INTO
".PHP_TM_PDO_TABLENAME_DATA." (
tab_url,
tab_title,
tab_icon_url,
tab_icon,
tab_parent_id,
tab_parse_id
)
VALUES
('".$aAddTab['url']."',
'".$sAddTabTitle."',
'".$aResult['icon_url']."',
'".$sIconSource."',
".$aAddTab['cat_id'].",
-1
)";
//print $sQuery;
try {
$oResults = $oPDO->query($sQuery);
fMessageHandler(["message"=>"Add new tab: " . $sAddTabTitle, "additional_message"=>" complete!"]);
} catch(PDOException $e) {
fErrorHandler(["filename"=>__FILE__, "line"=>__LINE__, "error"=>$e->getMessage()]);
}
}
?>
<script>
function fPreparedHTML() {
aHTML[0]='selected ';
aHTML[1]='to: <select name="frm_category">'
<?php
foreach ($aCatDesc as $sID => $sCatDesc) {
?>
aHTML[1]+='<option value=<?=$aCatID[$sID]?>><?=str_replace(["\r", "\n"], "", $sCatDesc)?></option>';
<?php
}
?>
aHTML[1]+='</select>';
aHTML[2]='<input type="hidden" name="frm_action" id="frm_action" value="">';
aHTML[3]=' <input type="button" value="OK" onclick="fSubmitMainForm();">';
aHTML[4]='<select name="frm_sort" onchange="document.getElementById(\'frm_main_form\').submit();">';
aHTML[4]+='<option value="0">---</option>';
aHTML[4]+='<option value="1">auto by name</option>';
aHTML[4]+='<option value="2">user preferences</option>';
aHTML[4]+='</select>';
}
</script>
<form method="post" action="index.php" name="frm_main_form" id="frm_main_form">
<table>
<tr>
<td>
<select name="frm_category_action" id="frm_category_action" onchange="fChangeFrmSelect(this.value);">
<option value="0">---</option>
<option value="1">Move</option>
<option value="2">Delete</option>
<option value="3">Export</option>
<option value="4">Sort</option>
</select>
<td>
<td id="frm_td_select">
</td>
</tr>
</table>
<table cellpadding="1" cellspacing="1" border="0" style="width:100%">
<?php
$sExportString = "
<!DOCTYPE NETSCAPE-Bookmark-file-1>
<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks menu</H1>
<DL><p>
<DL><p>
<DT><H3 ADD_DATE=\"".time()."\" LAST_MODIFIED=\"".time()."\">bookmarks</H3>
<DL><p>
";
foreach ($aCatID as $sID => $sCatID) {
$sHexColor=$aCatColor[$sID];
?>
<tr>
<td valign="top" width="10">
<?php
$sEmptyIconFlag=false;
if ($aCatType[$sID]==1) {
!strlen($aCatIcon[$sID]) >0 ? $sEmptyIconFlag=true : "";
$sShowIcon="<img src=\"".PHP_TM_HTTP_ROOT."/tmp/icon_cache/".$aCatIcon[$sID]."\" width=\"24\" height=\"24\">";
} else {
$sShowIcon="<div style=\"background-color:".$aCatColor[$sID].";width:24px;height:24px;\"></div>";
}
// Detect color in icon URL
if (preg_match("/^#(?:[0-9a-fA-F]{3,6})$/", $aCatIcon[$sID])) {
$sShowIcon="<div style=\"background-color:".$aCatColor[$sID].";width:24px;height:24px;\"></div>";
}
// Detect empty icon
if ($sEmptyIconFlag) {
$sShowIcon="<div style=\"background-color:".$aCatColor[$sID].";width:24px;height:24px;\"></div>";
}
?>
<a href="javascript:void(0)" onclick="fCounter(<?=$sCatID?>);"><?=$sShowIcon?></a>
</td>
<td valign="top" width="1">
</td>
<td>
<a href="javascript:void(0)" onclick="fCounter(<?=$sCatID?>);">
<?=$aCatDesc[$sID]?>
</a>
<div id="z_<?=$sCatID?>" style="display:none; background-color: #f8f8f8; padding:5px; width:90%;">
<?php
// Load urls and titles by category id
fLoadTabs($sCatID);
?>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td colspan="3">
<a name="edit_tab_<?=$sCatID?>">
<form method="post" action="index.php" name="frm_add_tab_<?=$sCatID?>" id="frm_add_tab_<?=$sCatID?>">
<br>
<table border="0">
<tr>
<td>Tab Title:</td><td><input type="text" name="frm_add_tab_title_<?=$sCatID?>" id="frm_add_tab_title_<?=$sCatID?>" value="" size="50"></td>
</tr>
<tr>
<td>Tab URL:</td><td><input type="text" name="frm_add_tab_url_<?=$sCatID?>" id="frm_add_tab_url_<?=$sCatID?>" value="" size="50"></td>
</tr>
<tr>
<td colspan="2">Add title and favicon automatically:<input type="checkbox" name="frm_add_tab_auto_title_<?=$sCatID?>" id="frm_add_tab_auto_title_<?=$sCatID?>">
<input type="hidden" name="frm_add_tab_action_<?=$sCatID?>" id="frm_add_tab_action_<?=$sCatID?>" value="add_tab">
<input type="hidden" name="frm_add_tab_edit_item_id_<?=$sCatID?>" id="frm_add_tab_edit_item_id_<?=$sCatID?>" value="">
<input type="submit" name="frm_add_tab_submit_<?=$sCatID?>" id="frm_add_tab_submit_<?=$sCatID?>" value="Add">
<input type="button" name="frm_add_tab_cancel_<?=$sCatID?>" onclick="document.getElementById('frm_add_tab_action_<?=$sCatID?>').value = 'add_tab';
document.getElementById('frm_add_tab_submit_<?=$sCatID?>').value = 'Add';
document.getElementById('frm_add_tab_edit_item_id_<?=$sCatID?>').value = '';
document.getElementById('frm_add_tab_title_<?=$sCatID?>').value = '';
document.getElementById('frm_add_tab_url_<?=$sCatID?>').value = '';" value="Cancel">
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</div>
<?php
}
// Export tabs to a file
if ($_REQUEST['frm_action']=="export") {
$sExportString .=" </DL><p>
</DL><p>
</DL>";
file_put_contents(PHP_TM_PATH_TO_EXPORT_BOOKMARK_FILE, $sExportString);
fMessageHandler(["message"=>"Bookmarks export: ", "additional_message"=>" complete!"]);
}
?>
</td>
</tr>
</table>
</form>
<form method="post" action="index.php" id="frm_delete" name="frm_delete">
<input type="hidden" name="frm_delete_value_id" id="frm_delete_value_id" value="">
<input type="hidden" name="frm_action" value="delete_one">
</form>
<form method="post" action="index.php" name="frm_icon_update" id="frm_icon_update">
<input type="hidden" name="frm_update_icon_id" id="frm_update_icon_id" value="">
<input type="hidden" name="frm_update_icon_domain" id="frm_update_icon_domain" value="">
<input type="hidden" name="frm_action" value="update_icon">
</form>
<script src="js/actions.js"></script>
</body>
</html>