1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* PHPPgAdmin v6.0.0-beta.48 |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace PHPPgAdmin\Controller; |
8
|
|
|
|
9
|
|
|
use PHPPgAdmin\Decorators\Decorator; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Base controller class. |
13
|
|
|
* |
14
|
|
|
* @package PHPPgAdmin |
15
|
|
|
*/ |
16
|
|
|
class FulltextController extends BaseController |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
public $controller_title = 'strschemas'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Default method to render the controller according to the action parameter. |
22
|
|
|
*/ |
23
|
|
|
public function render() |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
if ('tree' == $this->action) { |
26
|
|
|
return $this->doTree(); |
27
|
|
|
} |
28
|
|
|
if ('subtree' == $this->action) { |
29
|
|
|
return $this->doSubTree($_REQUEST['what']); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
$this->printHeader(); |
33
|
|
|
$this->printBody(); |
34
|
|
|
|
35
|
|
|
if (isset($_POST['cancel'])) { |
36
|
|
|
if (isset($_POST['prev_action'])) { |
37
|
|
|
$this->action = $_POST['prev_action']; |
38
|
|
|
} else { |
39
|
|
|
$this->action = ''; |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
switch ($this->action) { |
44
|
|
|
case 'createconfig': |
45
|
|
|
if (isset($_POST['create'])) { |
46
|
|
|
$this->doSaveCreateConfig(); |
47
|
|
|
} else { |
48
|
|
|
$this->doCreateConfig(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
break; |
52
|
|
|
case 'alterconfig': |
53
|
|
|
if (isset($_POST['alter'])) { |
54
|
|
|
$this->doSaveAlterConfig(); |
55
|
|
|
} else { |
56
|
|
|
$this->doAlterConfig(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
break; |
60
|
|
|
case 'dropconfig': |
61
|
|
|
if (isset($_POST['drop'])) { |
62
|
|
|
$this->doDropConfig(false); |
63
|
|
|
} else { |
64
|
|
|
$this->doDropConfig(true); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
break; |
68
|
|
|
case 'viewconfig': |
69
|
|
|
$this->doViewConfig($_REQUEST['ftscfg']); |
70
|
|
|
|
71
|
|
|
break; |
72
|
|
|
case 'viewparsers': |
73
|
|
|
$this->doViewParsers(); |
74
|
|
|
|
75
|
|
|
break; |
76
|
|
|
case 'viewdicts': |
77
|
|
|
$this->doViewDicts(); |
78
|
|
|
|
79
|
|
|
break; |
80
|
|
|
case 'createdict': |
81
|
|
|
if (isset($_POST['create'])) { |
82
|
|
|
$this->doSaveCreateDict(); |
83
|
|
|
} else { |
84
|
|
|
$this->doCreateDict(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
break; |
88
|
|
|
case 'alterdict': |
89
|
|
|
if (isset($_POST['alter'])) { |
90
|
|
|
$this->doSaveAlterDict(); |
91
|
|
|
} else { |
92
|
|
|
$this->doAlterDict(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
break; |
96
|
|
|
case 'dropdict': |
97
|
|
|
if (isset($_POST['drop'])) { |
98
|
|
|
$this->doDropDict(false); |
99
|
|
|
} else { |
100
|
|
|
$this->doDropDict(true); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
break; |
104
|
|
|
case 'dropmapping': |
105
|
|
|
if (isset($_POST['drop'])) { |
106
|
|
|
$this->doDropMapping(false); |
107
|
|
|
} else { |
108
|
|
|
$this->doDropMapping(true); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
break; |
112
|
|
|
case 'altermapping': |
113
|
|
|
if (isset($_POST['alter'])) { |
114
|
|
|
$this->doSaveAlterMapping(); |
115
|
|
|
} else { |
116
|
|
|
$this->doAlterMapping(); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
break; |
120
|
|
|
case 'addmapping': |
121
|
|
|
if (isset($_POST['add'])) { |
122
|
|
|
$this->doSaveAddMapping(); |
123
|
|
|
} else { |
124
|
|
|
$this->doAddMapping(); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
break; |
128
|
|
|
default: |
129
|
|
|
$this->doDefault(); |
130
|
|
|
|
131
|
|
|
break; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
return $this->printFooter(); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function doDefault($msg = '') |
138
|
|
|
{ |
139
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
140
|
|
|
|
141
|
|
|
$this->printTrail('schema'); |
|
|
|
|
142
|
|
|
$this->printTabs('schema', 'fulltext'); |
143
|
|
|
$this->printTabs('fulltext', 'ftsconfigs'); |
144
|
|
|
$this->printMsg($msg); |
145
|
|
|
|
146
|
|
|
$cfgs = $data->getFtsConfigurations(false); |
147
|
|
|
|
148
|
|
|
$columns = [ |
149
|
|
|
'configuration' => [ |
150
|
|
|
'title' => $this->lang['strftsconfig'], |
151
|
|
|
'field' => Decorator::field('name'), |
152
|
|
|
'url' => "fulltext?action=viewconfig&{$this->misc->href}&", |
153
|
|
|
'vars' => ['ftscfg' => 'name'], |
154
|
|
|
], |
155
|
|
|
'schema' => [ |
156
|
|
|
'title' => $this->lang['strschema'], |
157
|
|
|
'field' => Decorator::field('schema'), |
158
|
|
|
], |
159
|
|
|
'actions' => [ |
160
|
|
|
'title' => $this->lang['stractions'], |
161
|
|
|
], |
162
|
|
|
'comment' => [ |
163
|
|
|
'title' => $this->lang['strcomment'], |
164
|
|
|
'field' => Decorator::field('comment'), |
165
|
|
|
], |
166
|
|
|
]; |
167
|
|
|
|
168
|
|
|
$actions = [ |
169
|
|
|
'drop' => [ |
170
|
|
|
'content' => $this->lang['strdrop'], |
171
|
|
|
'attr' => [ |
172
|
|
|
'href' => [ |
173
|
|
|
'url' => 'fulltext', |
174
|
|
|
'urlvars' => [ |
175
|
|
|
'action' => 'dropconfig', |
176
|
|
|
'ftscfg' => Decorator::field('name'), |
177
|
|
|
], |
178
|
|
|
], |
179
|
|
|
], |
180
|
|
|
], |
181
|
|
|
'alter' => [ |
182
|
|
|
'content' => $this->lang['stralter'], |
183
|
|
|
'attr' => [ |
184
|
|
|
'href' => [ |
185
|
|
|
'url' => 'fulltext', |
186
|
|
|
'urlvars' => [ |
187
|
|
|
'action' => 'alterconfig', |
188
|
|
|
'ftscfg' => Decorator::field('name'), |
189
|
|
|
], |
190
|
|
|
], |
191
|
|
|
], |
192
|
|
|
], |
193
|
|
|
]; |
194
|
|
|
|
195
|
|
|
echo $this->printTable($cfgs, $columns, $actions, 'fulltext-fulltext', $this->lang['strftsnoconfigs']); |
196
|
|
|
|
197
|
|
|
$navlinks = [ |
198
|
|
|
'createconf' => [ |
199
|
|
|
'attr' => [ |
200
|
|
|
'href' => [ |
201
|
|
|
'url' => 'fulltext', |
202
|
|
|
'urlvars' => [ |
203
|
|
|
'action' => 'createconfig', |
204
|
|
|
'server' => $_REQUEST['server'], |
205
|
|
|
'database' => $_REQUEST['database'], |
206
|
|
|
'schema' => $_REQUEST['schema'], |
207
|
|
|
], |
208
|
|
|
], |
209
|
|
|
], |
210
|
|
|
'content' => $this->lang['strftscreateconfig'], |
211
|
|
|
], |
212
|
|
|
]; |
213
|
|
|
|
214
|
|
|
$this->printNavLinks($navlinks, 'fulltext-fulltext', get_defined_vars()); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Generate XML for the browser tree. |
219
|
|
|
*/ |
220
|
|
|
public function doTree() |
221
|
|
|
{ |
222
|
|
|
$tabs = $this->misc->getNavTabs('fulltext'); |
223
|
|
|
$items = $this->adjustTabsForTree($tabs); |
224
|
|
|
|
225
|
|
|
$reqvars = $this->misc->getRequestVars('ftscfg'); |
226
|
|
|
|
227
|
|
|
$attrs = [ |
228
|
|
|
'text' => Decorator::field('title'), |
229
|
|
|
'icon' => Decorator::field('icon'), |
230
|
|
|
'action' => Decorator::actionurl( |
231
|
|
|
'fulltext', |
232
|
|
|
$reqvars, |
233
|
|
|
Decorator::field('urlvars') |
234
|
|
|
), |
235
|
|
|
'branch' => Decorator::url( |
236
|
|
|
'fulltext', |
237
|
|
|
$reqvars, |
238
|
|
|
[ |
239
|
|
|
'action' => 'subtree', |
240
|
|
|
'what' => Decorator::field('icon'), // IZ: yeah, it's ugly, but I do not want to change navigation tabs arrays |
241
|
|
|
] |
242
|
|
|
), |
243
|
|
|
]; |
244
|
|
|
|
245
|
|
|
return $this->printTree($items, $attrs, 'fts'); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
public function doSubTree($what) |
249
|
|
|
{ |
250
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
251
|
|
|
|
252
|
|
|
switch ($what) { |
253
|
|
|
case 'FtsCfg': |
254
|
|
|
$items = $data->getFtsConfigurations(false); |
255
|
|
|
$urlvars = ['action' => 'viewconfig', 'ftscfg' => Decorator::field('name')]; |
256
|
|
|
|
257
|
|
|
break; |
258
|
|
|
case 'FtsDict': |
259
|
|
|
$items = $data->getFtsDictionaries(false); |
260
|
|
|
$urlvars = ['action' => 'viewdicts']; |
261
|
|
|
|
262
|
|
|
break; |
263
|
|
|
case 'FtsParser': |
264
|
|
|
$items = $data->getFtsParsers(false); |
265
|
|
|
$urlvars = ['action' => 'viewparsers']; |
266
|
|
|
|
267
|
|
|
break; |
268
|
|
|
default: |
269
|
|
|
return; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
$reqvars = $this->misc->getRequestVars('ftscfg'); |
273
|
|
|
|
274
|
|
|
$attrs = [ |
275
|
|
|
'text' => Decorator::field('name'), |
276
|
|
|
'icon' => $what, |
277
|
|
|
'toolTip' => Decorator::field('comment'), |
278
|
|
|
'action' => Decorator::actionurl( |
279
|
|
|
'fulltext', |
280
|
|
|
$reqvars, |
281
|
|
|
$urlvars |
282
|
|
|
), |
283
|
|
|
'branch' => Decorator::ifempty( |
284
|
|
|
Decorator::field('branch'), |
285
|
|
|
'', |
286
|
|
|
Decorator::url( |
287
|
|
|
'fulltext', |
288
|
|
|
$reqvars, |
289
|
|
|
[ |
290
|
|
|
'action' => 'subtree', |
291
|
|
|
'ftscfg' => Decorator::field('name'), |
292
|
|
|
] |
293
|
|
|
) |
294
|
|
|
), |
295
|
|
|
]; |
296
|
|
|
|
297
|
|
|
return $this->printTree($items, $attrs, strtolower($what)); |
298
|
|
|
} |
299
|
|
|
|
300
|
|
View Code Duplication |
public function doDropConfig($confirm) |
|
|
|
|
301
|
|
|
{ |
302
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
303
|
|
|
|
304
|
|
|
if ($confirm) { |
305
|
|
|
$this->printTrail('ftscfg'); |
|
|
|
|
306
|
|
|
$this->printTitle($this->lang['strdrop'], 'pg.ftscfg.drop'); |
307
|
|
|
|
308
|
|
|
echo '<p>', sprintf($this->lang['strconfdropftsconfig'], $this->misc->printVal($_REQUEST['ftscfg'])), '</p>'.PHP_EOL; |
309
|
|
|
|
310
|
|
|
echo '<form action="'.\SUBFOLDER.'/src/views/fulltext" method="post">'.PHP_EOL; |
311
|
|
|
echo "<p><input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /> <label for=\"cascade\">{$this->lang['strcascade']}</label></p>".PHP_EOL; |
312
|
|
|
echo '<p><input type="hidden" name="action" value="dropconfig" />'.PHP_EOL; |
313
|
|
|
echo '<input type="hidden" name="database" value="', htmlspecialchars($_REQUEST['database']), '" />'.PHP_EOL; |
314
|
|
|
echo '<input type="hidden" name="ftscfg" value="', htmlspecialchars($_REQUEST['ftscfg']), '" />'.PHP_EOL; |
315
|
|
|
echo $this->misc->form; |
316
|
|
|
echo "<input type=\"submit\" name=\"drop\" value=\"{$this->lang['strdrop']}\" />".PHP_EOL; |
317
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>".PHP_EOL; |
318
|
|
|
echo '</form>'.PHP_EOL; |
319
|
|
|
} else { |
320
|
|
|
$status = $data->dropFtsConfiguration($_POST['ftscfg'], isset($_POST['cascade'])); |
321
|
|
|
if (0 == $status) { |
322
|
|
|
$this->misc->setReloadBrowser(true); |
323
|
|
|
$this->doDefault($this->lang['strftsconfigdropped']); |
324
|
|
|
} else { |
325
|
|
|
$this->doDefault($this->lang['strftsconfigdroppedbad']); |
326
|
|
|
} |
327
|
|
|
} |
328
|
|
|
} |
329
|
|
|
|
330
|
|
View Code Duplication |
public function doDropDict($confirm) |
|
|
|
|
331
|
|
|
{ |
332
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
333
|
|
|
|
334
|
|
|
if ($confirm) { |
335
|
|
|
$this->printTrail('ftscfg'); // TODO: change to smth related to dictionary |
|
|
|
|
336
|
|
|
$this->printTitle($this->lang['strdrop'], 'pg.ftsdict.drop'); |
337
|
|
|
|
338
|
|
|
echo '<p>', sprintf($this->lang['strconfdropftsdict'], $this->misc->printVal($_REQUEST['ftsdict'])), '</p>'.PHP_EOL; |
339
|
|
|
|
340
|
|
|
echo '<form action="'.\SUBFOLDER.'/src/views/fulltext" method="post">'.PHP_EOL; |
341
|
|
|
echo "<p><input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /> <label for=\"cascade\">{$this->lang['strcascade']}</label></p>".PHP_EOL; |
342
|
|
|
echo '<p><input type="hidden" name="action" value="dropdict" />'.PHP_EOL; |
343
|
|
|
echo '<input type="hidden" name="database" value="', htmlspecialchars($_REQUEST['database']), '" />'.PHP_EOL; |
344
|
|
|
echo '<input type="hidden" name="ftsdict" value="', htmlspecialchars($_REQUEST['ftsdict']), '" />'.PHP_EOL; |
345
|
|
|
//echo "<input type=\"hidden\" name=\"ftscfg\" value=\"", htmlspecialchars($_REQUEST['ftscfg']), "\" />".PHP_EOL; |
346
|
|
|
echo '<input type="hidden" name="prev_action" value="viewdicts" /></p>'.PHP_EOL; |
347
|
|
|
echo $this->misc->form; |
348
|
|
|
echo "<input type=\"submit\" name=\"drop\" value=\"{$this->lang['strdrop']}\" />".PHP_EOL; |
349
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>".PHP_EOL; |
350
|
|
|
echo '</form>'.PHP_EOL; |
351
|
|
|
} else { |
352
|
|
|
$status = $data->dropFtsDictionary($_POST['ftsdict'], isset($_POST['cascade'])); |
353
|
|
|
if (0 == $status) { |
354
|
|
|
$this->misc->setReloadBrowser(true); |
355
|
|
|
$this->doViewDicts($this->lang['strftsdictdropped']); |
356
|
|
|
} else { |
357
|
|
|
$this->doViewDicts($this->lang['strftsdictdroppedbad']); |
358
|
|
|
} |
359
|
|
|
} |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
/** |
363
|
|
|
* Displays a screen where one can enter a new FTS configuration. |
364
|
|
|
* |
365
|
|
|
* @param mixed $msg |
366
|
|
|
*/ |
367
|
|
|
public function doCreateConfig($msg = '') |
368
|
|
|
{ |
369
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
370
|
|
|
|
371
|
|
|
$this->coalesceArr($_POST, 'formName', ''); |
372
|
|
|
|
373
|
|
|
$this->coalesceArr($_POST, 'formParser', ''); |
374
|
|
|
|
375
|
|
|
$this->coalesceArr($_POST, 'formTemplate', ''); |
376
|
|
|
|
377
|
|
|
$this->coalesceArr($_POST, 'formWithMap', ''); |
378
|
|
|
|
379
|
|
|
$this->coalesceArr($_POST, 'formComment', ''); |
380
|
|
|
|
381
|
|
|
// Fetch all FTS configurations from the database |
382
|
|
|
$ftscfgs = $data->getFtsConfigurations(); |
383
|
|
|
// Fetch all FTS parsers from the database |
384
|
|
|
$ftsparsers = $data->getFtsParsers(); |
385
|
|
|
|
386
|
|
|
$this->printTrail('schema'); |
|
|
|
|
387
|
|
|
$this->printTitle($this->lang['strftscreateconfig'], 'pg.ftscfg.create'); |
388
|
|
|
$this->printMsg($msg); |
389
|
|
|
|
390
|
|
|
echo '<form action="'.\SUBFOLDER.'/src/views/fulltext" method="post">'.PHP_EOL; |
391
|
|
|
echo '<table>'.PHP_EOL; |
392
|
|
|
// conf name |
393
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left required\">{$this->lang['strname']}</th>".PHP_EOL; |
394
|
|
|
echo "\t\t<td class=\"data1\"><input name=\"formName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
395
|
|
|
htmlspecialchars($_POST['formName']), "\" /></td>\n\t</tr>".PHP_EOL; |
396
|
|
|
|
397
|
|
|
// Template |
398
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strftstemplate']}</th>".PHP_EOL; |
399
|
|
|
echo "\t\t<td class=\"data1\">"; |
400
|
|
|
|
401
|
|
|
$tpls = []; |
402
|
|
|
$tplsel = ''; |
403
|
|
View Code Duplication |
while (!$ftscfgs->EOF) { |
|
|
|
|
404
|
|
|
$data->fieldClean($ftscfgs->fields['schema']); |
405
|
|
|
$data->fieldClean($ftscfgs->fields['name']); |
406
|
|
|
$tplname = $ftscfgs->fields['schema'].'.'.$ftscfgs->fields['name']; |
407
|
|
|
$tpls[$tplname] = serialize([ |
408
|
|
|
'name' => $ftscfgs->fields['name'], |
409
|
|
|
'schema' => $ftscfgs->fields['schema'], |
410
|
|
|
]); |
411
|
|
|
if ($_POST['formTemplate'] == $tpls[$tplname]) { |
412
|
|
|
$tplsel = htmlspecialchars($tpls[$tplname]); |
413
|
|
|
} |
414
|
|
|
$ftscfgs->moveNext(); |
415
|
|
|
} |
416
|
|
|
echo \PHPPgAdmin\XHtml\HTMLController::printCombo($tpls, 'formTemplate', true, $tplsel, false); |
417
|
|
|
echo "\n\t\t</td>\n\t</tr>".PHP_EOL; |
418
|
|
|
|
419
|
|
|
// Parser |
420
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strftsparser']}</th>".PHP_EOL; |
421
|
|
|
echo "\t\t<td class=\"data1\">".PHP_EOL; |
422
|
|
|
$ftsparsers_ = []; |
423
|
|
|
$ftsparsel = ''; |
424
|
|
View Code Duplication |
while (!$ftsparsers->EOF) { |
|
|
|
|
425
|
|
|
$data->fieldClean($ftsparsers->fields['schema']); |
426
|
|
|
$data->fieldClean($ftsparsers->fields['name']); |
427
|
|
|
$parsername = $ftsparsers->fields['schema'].'.'.$ftsparsers->fields['name']; |
428
|
|
|
|
429
|
|
|
$ftsparsers_[$parsername] = serialize([ |
430
|
|
|
'parser' => $ftsparsers->fields['name'], |
431
|
|
|
'schema' => $ftsparsers->fields['schema'], |
432
|
|
|
]); |
433
|
|
|
if ($_POST['formParser'] == $ftsparsers_[$parsername]) { |
434
|
|
|
$ftsparsel = htmlspecialchars($ftsparsers_[$parsername]); |
435
|
|
|
} |
436
|
|
|
$ftsparsers->moveNext(); |
437
|
|
|
} |
438
|
|
|
echo \PHPPgAdmin\XHtml\HTMLController::printCombo($ftsparsers_, 'formParser', true, $ftsparsel, false); |
439
|
|
|
echo "\n\t\t</td>\n\t</tr>".PHP_EOL; |
440
|
|
|
|
441
|
|
|
// Comment |
442
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strcomment']}</th>".PHP_EOL; |
443
|
|
|
echo "\t\t<td class=\"data1\"><textarea name=\"formComment\" rows=\"3\" cols=\"32\">", |
444
|
|
|
htmlspecialchars($_POST['formComment']), "</textarea></td>\n\t</tr>".PHP_EOL; |
445
|
|
|
|
446
|
|
|
echo '</table>'.PHP_EOL; |
447
|
|
|
echo '<p>'.PHP_EOL; |
448
|
|
|
echo '<input type="hidden" name="action" value="createconfig" />'.PHP_EOL; |
449
|
|
|
echo '<input type="hidden" name="database" value="', htmlspecialchars($_REQUEST['database']), '" />'.PHP_EOL; |
450
|
|
|
echo $this->misc->form; |
451
|
|
|
echo "<input type=\"submit\" name=\"create\" value=\"{$this->lang['strcreate']}\" />".PHP_EOL; |
452
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" />".PHP_EOL; |
453
|
|
|
echo '</p>'.PHP_EOL; |
454
|
|
|
echo '</form>'.PHP_EOL; |
455
|
|
|
} |
456
|
|
|
|
457
|
|
|
/** |
458
|
|
|
* Actually creates the new FTS configuration in the database. |
459
|
|
|
*/ |
460
|
|
|
public function doSaveCreateConfig() |
461
|
|
|
{ |
462
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
463
|
|
|
|
464
|
|
|
$err = ''; |
465
|
|
|
// Check that they've given a name |
466
|
|
|
if ('' == $_POST['formName']) { |
467
|
|
|
$err .= "{$this->lang['strftsconfigneedsname']}<br />"; |
468
|
|
|
} |
469
|
|
|
|
470
|
|
|
if (('' != $_POST['formParser']) && ('' != $_POST['formTemplate'])) { |
471
|
|
|
$err .= "{$this->lang['strftscantparsercopy']}<br />"; |
472
|
|
|
} |
473
|
|
|
|
474
|
|
|
if ($err !== '') { |
475
|
|
|
return $this->doCreateConfig($err); |
476
|
|
|
} |
477
|
|
|
|
478
|
|
|
if ('' != $_POST['formParser']) { |
479
|
|
|
$formParser = unserialize($_POST['formParser']); |
480
|
|
|
} else { |
481
|
|
|
$formParser = ''; |
482
|
|
|
} |
483
|
|
|
|
484
|
|
View Code Duplication |
if ('' != $_POST['formTemplate']) { |
|
|
|
|
485
|
|
|
$formTemplate = unserialize($_POST['formTemplate']); |
486
|
|
|
} else { |
487
|
|
|
$formTemplate = ''; |
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
$status = $data->createFtsConfiguration($_POST['formName'], $formParser, $formTemplate, $_POST['formComment']); |
491
|
|
|
if (0 == $status) { |
492
|
|
|
$this->misc->setReloadBrowser(true); |
493
|
|
|
$this->doDefault($this->lang['strftsconfigcreated']); |
494
|
|
|
} else { |
495
|
|
|
$this->doCreateConfig($this->lang['strftsconfigcreatedbad']); |
496
|
|
|
} |
497
|
|
|
} |
498
|
|
|
|
499
|
|
|
/** |
500
|
|
|
* Display a form to permit editing FTS configuration properies. |
501
|
|
|
* |
502
|
|
|
* @param mixed $msg |
503
|
|
|
*/ |
504
|
|
|
public function doAlterConfig($msg = '') |
505
|
|
|
{ |
506
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
507
|
|
|
|
508
|
|
|
$this->printTrail('ftscfg'); |
|
|
|
|
509
|
|
|
$this->printTitle($this->lang['stralter'], 'pg.ftscfg.alter'); |
510
|
|
|
$this->printMsg($msg); |
511
|
|
|
|
512
|
|
|
$ftscfg = $data->getFtsConfigurationByName($_REQUEST['ftscfg']); |
513
|
|
|
if ($ftscfg->recordCount() > 0) { |
514
|
|
|
$this->coalesceArr($_POST, 'formComment', $ftscfg->fields['comment']); |
515
|
|
|
|
516
|
|
|
$this->coalesceArr($_POST, 'ftscfg', $_REQUEST['ftscfg']); |
517
|
|
|
|
518
|
|
|
$this->coalesceArr($_POST, 'formName', $_REQUEST['ftscfg']); |
519
|
|
|
|
520
|
|
|
$this->coalesceArr($_POST, 'formParser', ''); |
521
|
|
|
|
522
|
|
|
// Fetch all FTS parsers from the database |
523
|
|
|
$ftsparsers = $data->getFtsParsers(); |
|
|
|
|
524
|
|
|
|
525
|
|
|
echo '<form action="'.\SUBFOLDER.'/src/views/fulltext" method="post">'.PHP_EOL; |
526
|
|
|
echo '<table>'.PHP_EOL; |
527
|
|
|
|
528
|
|
|
echo "\t<tr>".PHP_EOL; |
529
|
|
|
echo "\t\t<th class=\"data left required\">{$this->lang['strname']}</th>".PHP_EOL; |
530
|
|
|
echo "\t\t<td class=\"data1\">"; |
531
|
|
|
echo "\t\t\t<input name=\"formName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
532
|
|
|
htmlspecialchars($_POST['formName']), '" />'.PHP_EOL; |
533
|
|
|
echo "\t\t</td>".PHP_EOL; |
534
|
|
|
echo "\t</tr>".PHP_EOL; |
535
|
|
|
|
536
|
|
|
// Comment |
537
|
|
|
echo "\t<tr>".PHP_EOL; |
538
|
|
|
echo "\t\t<th class=\"data\">{$this->lang['strcomment']}</th>".PHP_EOL; |
539
|
|
|
echo "\t\t<td class=\"data1\"><textarea cols=\"32\" rows=\"3\"name=\"formComment\">", htmlspecialchars($_POST['formComment']), '</textarea></td>'.PHP_EOL; |
540
|
|
|
echo "\t</tr>".PHP_EOL; |
541
|
|
|
echo '</table>'.PHP_EOL; |
542
|
|
|
echo '<p><input type="hidden" name="action" value="alterconfig" />'.PHP_EOL; |
543
|
|
|
echo '<input type="hidden" name="ftscfg" value="', htmlspecialchars($_POST['ftscfg']), '" />'.PHP_EOL; |
544
|
|
|
echo $this->misc->form; |
545
|
|
|
echo "<input type=\"submit\" name=\"alter\" value=\"{$this->lang['stralter']}\" />".PHP_EOL; |
546
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>".PHP_EOL; |
547
|
|
|
echo '</form>'.PHP_EOL; |
548
|
|
|
} else { |
549
|
|
|
echo "<p>{$this->lang['strnodata']}</p>".PHP_EOL; |
550
|
|
|
} |
551
|
|
|
} |
552
|
|
|
|
553
|
|
|
/** |
554
|
|
|
* Save the form submission containing changes to a FTS configuration. |
555
|
|
|
*/ |
556
|
|
|
public function doSaveAlterConfig() |
557
|
|
|
{ |
558
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
559
|
|
|
$status = $data->updateFtsConfiguration($_POST['ftscfg'], $_POST['formComment'], $_POST['formName']); |
560
|
|
|
if (0 == $status) { |
561
|
|
|
$this->doDefault($this->lang['strftsconfigaltered']); |
562
|
|
|
} else { |
563
|
|
|
$this->doAlterConfig($this->lang['strftsconfigalteredbad']); |
564
|
|
|
} |
565
|
|
|
} |
566
|
|
|
|
567
|
|
|
/** |
568
|
|
|
* View list of FTS parsers. |
569
|
|
|
* |
570
|
|
|
* @param mixed $msg |
571
|
|
|
*/ |
572
|
|
View Code Duplication |
public function doViewParsers($msg = '') |
|
|
|
|
573
|
|
|
{ |
574
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
575
|
|
|
|
576
|
|
|
$this->printTrail('schema'); |
|
|
|
|
577
|
|
|
$this->printTabs('schema', 'fulltext'); |
578
|
|
|
$this->printTabs('fulltext', 'ftsparsers'); |
579
|
|
|
$this->printMsg($msg); |
580
|
|
|
|
581
|
|
|
$parsers = $data->getFtsParsers(false); |
582
|
|
|
|
583
|
|
|
$columns = [ |
584
|
|
|
'schema' => [ |
585
|
|
|
'title' => $this->lang['strschema'], |
586
|
|
|
'field' => Decorator::field('schema'), |
587
|
|
|
], |
588
|
|
|
'name' => [ |
589
|
|
|
'title' => $this->lang['strname'], |
590
|
|
|
'field' => Decorator::field('name'), |
591
|
|
|
], |
592
|
|
|
'comment' => [ |
593
|
|
|
'title' => $this->lang['strcomment'], |
594
|
|
|
'field' => Decorator::field('comment'), |
595
|
|
|
], |
596
|
|
|
]; |
597
|
|
|
|
598
|
|
|
$actions = []; |
599
|
|
|
|
600
|
|
|
echo $this->printTable($parsers, $columns, $actions, 'fulltext-viewparsers', $this->lang['strftsnoparsers']); |
601
|
|
|
|
602
|
|
|
//TODO: navlink to "create parser" |
603
|
|
|
} |
604
|
|
|
|
605
|
|
|
/** |
606
|
|
|
* View list of FTS dictionaries. |
607
|
|
|
* |
608
|
|
|
* @param mixed $msg |
609
|
|
|
*/ |
610
|
|
|
public function doViewDicts($msg = '') |
611
|
|
|
{ |
612
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
613
|
|
|
|
614
|
|
|
$this->printTrail('schema'); |
|
|
|
|
615
|
|
|
$this->printTabs('schema', 'fulltext'); |
616
|
|
|
$this->printTabs('fulltext', 'ftsdicts'); |
617
|
|
|
$this->printMsg($msg); |
618
|
|
|
|
619
|
|
|
$dicts = $data->getFtsDictionaries(false); |
620
|
|
|
|
621
|
|
|
$columns = [ |
622
|
|
|
'schema' => [ |
623
|
|
|
'title' => $this->lang['strschema'], |
624
|
|
|
'field' => Decorator::field('schema'), |
625
|
|
|
], |
626
|
|
|
'name' => [ |
627
|
|
|
'title' => $this->lang['strname'], |
628
|
|
|
'field' => Decorator::field('name'), |
629
|
|
|
], |
630
|
|
|
'actions' => [ |
631
|
|
|
'title' => $this->lang['stractions'], |
632
|
|
|
], |
633
|
|
|
'comment' => [ |
634
|
|
|
'title' => $this->lang['strcomment'], |
635
|
|
|
'field' => Decorator::field('comment'), |
636
|
|
|
], |
637
|
|
|
]; |
638
|
|
|
|
639
|
|
|
$actions = [ |
640
|
|
|
'drop' => [ |
641
|
|
|
'content' => $this->lang['strdrop'], |
642
|
|
|
'attr' => [ |
643
|
|
|
'href' => [ |
644
|
|
|
'url' => 'fulltext', |
645
|
|
|
'urlvars' => [ |
646
|
|
|
'action' => 'dropdict', |
647
|
|
|
'ftsdict' => Decorator::field('name'), |
648
|
|
|
], |
649
|
|
|
], |
650
|
|
|
], |
651
|
|
|
], |
652
|
|
|
'alter' => [ |
653
|
|
|
'content' => $this->lang['stralter'], |
654
|
|
|
'attr' => [ |
655
|
|
|
'href' => [ |
656
|
|
|
'url' => 'fulltext', |
657
|
|
|
'urlvars' => [ |
658
|
|
|
'action' => 'alterdict', |
659
|
|
|
'ftsdict' => Decorator::field('name'), |
660
|
|
|
], |
661
|
|
|
], |
662
|
|
|
], |
663
|
|
|
], |
664
|
|
|
]; |
665
|
|
|
|
666
|
|
|
echo $this->printTable($dicts, $columns, $actions, 'fulltext-viewdicts', $this->lang['strftsnodicts']); |
667
|
|
|
|
668
|
|
|
$navlinks = [ |
669
|
|
|
'createdict' => [ |
670
|
|
|
'attr' => [ |
671
|
|
|
'href' => [ |
672
|
|
|
'url' => 'fulltext', |
673
|
|
|
'urlvars' => [ |
674
|
|
|
'action' => 'createdict', |
675
|
|
|
'server' => $_REQUEST['server'], |
676
|
|
|
'database' => $_REQUEST['database'], |
677
|
|
|
'schema' => $_REQUEST['schema'], |
678
|
|
|
], |
679
|
|
|
], |
680
|
|
|
], |
681
|
|
|
'content' => $this->lang['strftscreatedict'], |
682
|
|
|
], |
683
|
|
|
]; |
684
|
|
|
|
685
|
|
|
$this->printNavLinks($navlinks, 'fulltext-viewdicts', get_defined_vars()); |
686
|
|
|
} |
687
|
|
|
|
688
|
|
|
/** |
689
|
|
|
* View details of FTS configuration given. |
690
|
|
|
* |
691
|
|
|
* @param mixed $ftscfg |
692
|
|
|
* @param mixed $msg |
693
|
|
|
*/ |
694
|
|
|
public function doViewConfig($ftscfg, $msg = '') |
695
|
|
|
{ |
696
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
697
|
|
|
|
698
|
|
|
$this->printTrail('ftscfg'); |
|
|
|
|
699
|
|
|
$this->printTabs('schema', 'fulltext'); |
700
|
|
|
$this->printTabs('fulltext', 'ftsconfigs'); |
701
|
|
|
$this->printMsg($msg); |
702
|
|
|
|
703
|
|
|
echo "<h3>{$this->lang['strftsconfigmap']}</h3>".PHP_EOL; |
704
|
|
|
|
705
|
|
|
$map = $data->getFtsConfigurationMap($ftscfg); |
706
|
|
|
|
707
|
|
|
$columns = [ |
708
|
|
|
'name' => [ |
709
|
|
|
'title' => $this->lang['strftsmapping'], |
710
|
|
|
'field' => Decorator::field('name'), |
711
|
|
|
], |
712
|
|
|
'dictionaries' => [ |
713
|
|
|
'title' => $this->lang['strftsdicts'], |
714
|
|
|
'field' => Decorator::field('dictionaries'), |
715
|
|
|
], |
716
|
|
|
'actions' => [ |
717
|
|
|
'title' => $this->lang['stractions'], |
718
|
|
|
], |
719
|
|
|
'comment' => [ |
720
|
|
|
'title' => $this->lang['strcomment'], |
721
|
|
|
'field' => Decorator::field('description'), |
722
|
|
|
], |
723
|
|
|
]; |
724
|
|
|
|
725
|
|
|
$actions = [ |
726
|
|
|
'drop' => [ |
727
|
|
|
'multiaction' => 'dropmapping', |
728
|
|
|
'content' => $this->lang['strdrop'], |
729
|
|
|
'attr' => [ |
730
|
|
|
'href' => [ |
731
|
|
|
'url' => 'fulltext', |
732
|
|
|
'urlvars' => [ |
733
|
|
|
'action' => 'dropmapping', |
734
|
|
|
'mapping' => Decorator::field('name'), |
735
|
|
|
'ftscfg' => Decorator::field('cfgname'), |
736
|
|
|
], |
737
|
|
|
], |
738
|
|
|
], |
739
|
|
|
], |
740
|
|
|
'alter' => [ |
741
|
|
|
'content' => $this->lang['stralter'], |
742
|
|
|
'attr' => [ |
743
|
|
|
'href' => [ |
744
|
|
|
'url' => 'fulltext', |
745
|
|
|
'urlvars' => [ |
746
|
|
|
'action' => 'altermapping', |
747
|
|
|
'mapping' => Decorator::field('name'), |
748
|
|
|
'ftscfg' => Decorator::field('cfgname'), |
749
|
|
|
], |
750
|
|
|
], |
751
|
|
|
], |
752
|
|
|
], |
753
|
|
|
'multiactions' => [ |
754
|
|
|
'keycols' => ['mapping' => 'name'], |
755
|
|
|
'url' => 'fulltext', |
756
|
|
|
'default' => null, |
757
|
|
|
'vars' => ['ftscfg' => $ftscfg], |
758
|
|
|
], |
759
|
|
|
]; |
760
|
|
|
|
761
|
|
|
echo $this->printTable($map, $columns, $actions, 'fulltext-viewconfig', $this->lang['strftsemptymap']); |
762
|
|
|
|
763
|
|
|
$navlinks = [ |
764
|
|
|
'addmapping' => [ |
765
|
|
|
'attr' => [ |
766
|
|
|
'href' => [ |
767
|
|
|
'url' => 'fulltext', |
768
|
|
|
'urlvars' => [ |
769
|
|
|
'action' => 'addmapping', |
770
|
|
|
'server' => $_REQUEST['server'], |
771
|
|
|
'database' => $_REQUEST['database'], |
772
|
|
|
'schema' => $_REQUEST['schema'], |
773
|
|
|
'ftscfg' => $ftscfg, |
774
|
|
|
], |
775
|
|
|
], |
776
|
|
|
], |
777
|
|
|
'content' => $this->lang['strftsaddmapping'], |
778
|
|
|
], |
779
|
|
|
]; |
780
|
|
|
|
781
|
|
|
$this->printNavLinks($navlinks, 'fulltext-viewconfig', get_defined_vars()); |
782
|
|
|
} |
783
|
|
|
|
784
|
|
|
/** |
785
|
|
|
* Displays a screen where one can enter a details of a new FTS dictionary. |
786
|
|
|
* |
787
|
|
|
* @param mixed $msg |
788
|
|
|
*/ |
789
|
|
|
public function doCreateDict($msg = '') |
790
|
|
|
{ |
791
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
792
|
|
|
|
793
|
|
|
$this->coalesceArr($_POST, 'formName', ''); |
794
|
|
|
|
795
|
|
|
$this->coalesceArr($_POST, 'formIsTemplate', false); |
796
|
|
|
|
797
|
|
|
$this->coalesceArr($_POST, 'formTemplate', ''); |
798
|
|
|
|
799
|
|
|
$this->coalesceArr($_POST, 'formLexize', ''); |
800
|
|
|
|
801
|
|
|
$this->coalesceArr($_POST, 'formInit', ''); |
802
|
|
|
|
803
|
|
|
$this->coalesceArr($_POST, 'formOption', ''); |
804
|
|
|
|
805
|
|
|
$this->coalesceArr($_POST, 'formComment', ''); |
806
|
|
|
|
807
|
|
|
// Fetch all FTS dictionaries from the database |
808
|
|
|
$ftstpls = $data->getFtsDictionaryTemplates(); |
809
|
|
|
|
810
|
|
|
$this->printTrail('schema'); |
|
|
|
|
811
|
|
|
// TODO: create doc links |
812
|
|
|
$this->printTitle($this->lang['strftscreatedict'], 'pg.ftsdict.create'); |
813
|
|
|
$this->printMsg($msg); |
814
|
|
|
|
815
|
|
|
echo '<form action="'.\SUBFOLDER.'/src/views/fulltext" method="post">'.PHP_EOL; |
816
|
|
|
echo '<table>'.PHP_EOL; |
817
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left required\">{$this->lang['strname']}</th>".PHP_EOL; |
818
|
|
|
echo "\t\t<td class=\"data1\"><input name=\"formName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
819
|
|
|
htmlspecialchars($_POST['formName']), '" /> ', |
820
|
|
|
'<input type="checkbox" name="formIsTemplate" id="formIsTemplate"', $_POST['formIsTemplate'] ? ' checked="checked" ' : '', " />\n", |
821
|
|
|
"<label for=\"formIsTemplate\">{$this->lang['strftscreatedicttemplate']}</label></td>\n\t</tr>".PHP_EOL; |
822
|
|
|
|
823
|
|
|
// Template |
824
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strftstemplate']}</th>".PHP_EOL; |
825
|
|
|
echo "\t\t<td class=\"data1\">"; |
826
|
|
|
$tpls = []; |
827
|
|
|
$tplsel = ''; |
828
|
|
View Code Duplication |
while (!$ftstpls->EOF) { |
|
|
|
|
829
|
|
|
$data->fieldClean($ftstpls->fields['schema']); |
830
|
|
|
$data->fieldClean($ftstpls->fields['name']); |
831
|
|
|
$tplname = $ftstpls->fields['schema'].'.'.$ftstpls->fields['name']; |
832
|
|
|
$tpls[$tplname] = serialize([ |
833
|
|
|
'name' => $ftstpls->fields['name'], |
834
|
|
|
'schema' => $ftstpls->fields['schema'], |
835
|
|
|
]); |
836
|
|
|
if ($_POST['formTemplate'] == $tpls[$tplname]) { |
837
|
|
|
$tplsel = htmlspecialchars($tpls[$tplname]); |
838
|
|
|
} |
839
|
|
|
$ftstpls->moveNext(); |
840
|
|
|
} |
841
|
|
|
echo \PHPPgAdmin\XHtml\HTMLController::printCombo($tpls, 'formTemplate', true, $tplsel, false); |
842
|
|
|
echo "\n\t\t</td>\n\t</tr>".PHP_EOL; |
843
|
|
|
|
844
|
|
|
// TODO: what about maxlengths? |
845
|
|
|
// Lexize |
846
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strftslexize']}</th>".PHP_EOL; |
847
|
|
|
echo "\t\t<td class=\"data1\"><input name=\"formLexize\" size=\"32\" maxlength=\"1000\" value=\"", |
848
|
|
|
htmlspecialchars($_POST['formLexize']), '" ', isset($_POST['formIsTemplate']) ? '' : ' disabled="disabled" ', |
849
|
|
|
"/></td>\n\t</tr>".PHP_EOL; |
850
|
|
|
|
851
|
|
|
// Init |
852
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strftsinit']}</th>".PHP_EOL; |
853
|
|
|
echo "\t\t<td class=\"data1\"><input name=\"formInit\" size=\"32\" maxlength=\"1000\" value=\"", |
854
|
|
|
htmlspecialchars($_POST['formInit']), '"', @$_POST['formIsTemplate'] ? '' : ' disabled="disabled" ', |
855
|
|
|
"/></td>\n\t</tr>".PHP_EOL; |
856
|
|
|
|
857
|
|
|
// Option |
858
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strftsoptionsvalues']}</th>".PHP_EOL; |
859
|
|
|
echo "\t\t<td class=\"data1\"><input name=\"formOption\" size=\"32\" maxlength=\"1000\" value=\"", |
860
|
|
|
htmlspecialchars($_POST['formOption']), "\" /></td>\n\t</tr>".PHP_EOL; |
861
|
|
|
|
862
|
|
|
// Comment |
863
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strcomment']}</th>".PHP_EOL; |
864
|
|
|
echo "\t\t<td class=\"data1\"><textarea name=\"formComment\" rows=\"3\" cols=\"32\">", |
865
|
|
|
htmlspecialchars($_POST['formComment']), "</textarea></td>\n\t</tr>".PHP_EOL; |
866
|
|
|
|
867
|
|
|
echo '</table>'.PHP_EOL; |
868
|
|
|
echo '<p>'.PHP_EOL; |
869
|
|
|
echo '<input type="hidden" name="action" value="createdict" />'.PHP_EOL; |
870
|
|
|
echo '<input type="hidden" name="database" value="', htmlspecialchars($_REQUEST['database']), '" />'.PHP_EOL; |
871
|
|
|
echo $this->misc->form; |
872
|
|
|
echo "<input type=\"submit\" name=\"create\" value=\"{$this->lang['strcreate']}\" />".PHP_EOL; |
873
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" />".PHP_EOL; |
874
|
|
|
echo '</p>'.PHP_EOL; |
875
|
|
|
echo "</form>\n", |
876
|
|
|
"<script type=\"text/javascript\"> |
877
|
|
|
function templateOpts() { |
878
|
|
|
isTpl = document.getElementsByName('formIsTemplate')[0].checked; |
879
|
|
|
document.getElementsByName('formTemplate')[0].disabled = isTpl; |
880
|
|
|
document.getElementsByName('formOption')[0].disabled = isTpl; |
881
|
|
|
document.getElementsByName('formLexize')[0].disabled = !isTpl; |
882
|
|
|
document.getElementsByName('formInit')[0].disabled = !isTpl; |
883
|
|
|
} |
884
|
|
|
|
885
|
|
|
document.getElementsByName('formIsTemplate')[0].onchange = templateOpts; |
886
|
|
|
|
887
|
|
|
templateOpts(); |
888
|
|
|
</script>".PHP_EOL; |
889
|
|
|
} |
890
|
|
|
|
891
|
|
|
/** |
892
|
|
|
* Actually creates the new FTS dictionary in the database. |
893
|
|
|
*/ |
894
|
|
|
public function doSaveCreateDict() |
895
|
|
|
{ |
896
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
897
|
|
|
|
898
|
|
|
// Check that they've given a name |
899
|
|
|
if ('' == $_POST['formName']) { |
900
|
|
|
$this->doCreateDict($this->lang['strftsdictneedsname']); |
901
|
|
|
} else { |
902
|
|
|
$this->coalesceArr($_POST, 'formIsTemplate', false); |
903
|
|
|
|
904
|
|
View Code Duplication |
if (isset($_POST['formTemplate'])) { |
|
|
|
|
905
|
|
|
$formTemplate = unserialize($_POST['formTemplate']); |
906
|
|
|
} else { |
907
|
|
|
$formTemplate = ''; |
908
|
|
|
} |
909
|
|
|
|
910
|
|
|
$this->coalesceArr($_POST, 'formLexize', ''); |
911
|
|
|
|
912
|
|
|
$this->coalesceArr($_POST, 'formInit', ''); |
913
|
|
|
|
914
|
|
|
$this->coalesceArr($_POST, 'formOption', ''); |
915
|
|
|
|
916
|
|
|
$status = $data->createFtsDictionary( |
917
|
|
|
$_POST['formName'], |
918
|
|
|
$_POST['formIsTemplate'], |
919
|
|
|
$formTemplate, |
920
|
|
|
$_POST['formLexize'], |
921
|
|
|
$_POST['formInit'], |
922
|
|
|
$_POST['formOption'], |
923
|
|
|
$_POST['formComment'] |
924
|
|
|
); |
925
|
|
|
|
926
|
|
|
if (0 == $status) { |
927
|
|
|
$this->misc->setReloadBrowser(true); |
928
|
|
|
$this->doViewDicts($this->lang['strftsdictcreated']); |
929
|
|
|
} else { |
930
|
|
|
$this->doCreateDict($this->lang['strftsdictcreatedbad']); |
931
|
|
|
} |
932
|
|
|
} |
933
|
|
|
} |
934
|
|
|
|
935
|
|
|
/** |
936
|
|
|
* Display a form to permit editing FTS dictionary properies. |
937
|
|
|
* |
938
|
|
|
* @param mixed $msg |
939
|
|
|
*/ |
940
|
|
|
public function doAlterDict($msg = '') |
941
|
|
|
{ |
942
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
943
|
|
|
|
944
|
|
|
$this->printTrail('ftscfg'); // TODO: change to smth related to dictionary |
|
|
|
|
945
|
|
|
$this->printTitle($this->lang['stralter'], 'pg.ftsdict.alter'); |
946
|
|
|
$this->printMsg($msg); |
947
|
|
|
|
948
|
|
|
$ftsdict = $data->getFtsDictionaryByName($_REQUEST['ftsdict']); |
949
|
|
|
if ($ftsdict->recordCount() > 0) { |
950
|
|
|
$this->coalesceArr($_POST, 'formComment', $ftsdict->fields['comment']); |
951
|
|
|
|
952
|
|
|
$this->coalesceArr($_POST, 'ftsdict', $_REQUEST['ftsdict']); |
953
|
|
|
|
954
|
|
|
$this->coalesceArr($_POST, 'formName', $_REQUEST['ftsdict']); |
955
|
|
|
|
956
|
|
|
echo '<form action="'.\SUBFOLDER.'/src/views/fulltext" method="post">'.PHP_EOL; |
957
|
|
|
echo '<table>'.PHP_EOL; |
958
|
|
|
|
959
|
|
|
echo "\t<tr>".PHP_EOL; |
960
|
|
|
echo "\t\t<th class=\"data left required\">{$this->lang['strname']}</th>".PHP_EOL; |
961
|
|
|
echo "\t\t<td class=\"data1\">"; |
962
|
|
|
echo "\t\t\t<input name=\"formName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
963
|
|
|
htmlspecialchars($_POST['formName']), '" />'.PHP_EOL; |
964
|
|
|
echo "\t\t</td>".PHP_EOL; |
965
|
|
|
echo "\t</tr>".PHP_EOL; |
966
|
|
|
|
967
|
|
|
// Comment |
968
|
|
|
echo "\t<tr>".PHP_EOL; |
969
|
|
|
echo "\t\t<th class=\"data\">{$this->lang['strcomment']}</th>".PHP_EOL; |
970
|
|
|
echo "\t\t<td class=\"data1\"><textarea cols=\"32\" rows=\"3\"name=\"formComment\">", htmlspecialchars($_POST['formComment']), '</textarea></td>'.PHP_EOL; |
971
|
|
|
echo "\t</tr>".PHP_EOL; |
972
|
|
|
echo '</table>'.PHP_EOL; |
973
|
|
|
echo '<p><input type="hidden" name="action" value="alterdict" />'.PHP_EOL; |
974
|
|
|
echo '<input type="hidden" name="ftsdict" value="', htmlspecialchars($_POST['ftsdict']), '" />'.PHP_EOL; |
975
|
|
|
echo '<input type="hidden" name="prev_action" value="viewdicts" /></p>'.PHP_EOL; |
976
|
|
|
echo $this->misc->form; |
977
|
|
|
echo "<input type=\"submit\" name=\"alter\" value=\"{$this->lang['stralter']}\" />".PHP_EOL; |
978
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>".PHP_EOL; |
979
|
|
|
echo '</form>'.PHP_EOL; |
980
|
|
|
} else { |
981
|
|
|
echo "<p>{$this->lang['strnodata']}</p>".PHP_EOL; |
982
|
|
|
} |
983
|
|
|
} |
984
|
|
|
|
985
|
|
|
/** |
986
|
|
|
* Save the form submission containing changes to a FTS dictionary. |
987
|
|
|
*/ |
988
|
|
|
public function doSaveAlterDict() |
989
|
|
|
{ |
990
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
991
|
|
|
|
992
|
|
|
$status = $data->updateFtsDictionary($_POST['ftsdict'], $_POST['formComment'], $_POST['formName']); |
993
|
|
|
if (0 == $status) { |
994
|
|
|
$this->doViewDicts($this->lang['strftsdictaltered']); |
995
|
|
|
} else { |
996
|
|
|
$this->doAlterDict($this->lang['strftsdictalteredbad']); |
997
|
|
|
} |
998
|
|
|
} |
999
|
|
|
|
1000
|
|
|
/** |
1001
|
|
|
* Show confirmation of drop and perform actual drop of FTS mapping. |
1002
|
|
|
* |
1003
|
|
|
* @param mixed $confirm |
1004
|
|
|
*/ |
1005
|
|
|
public function doDropMapping($confirm) |
1006
|
|
|
{ |
1007
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
1008
|
|
|
|
1009
|
|
|
if (empty($_REQUEST['mapping']) && empty($_REQUEST['ma'])) { |
1010
|
|
|
$this->doDefault($this->lang['strftsspecifymappingtodrop']); |
1011
|
|
|
|
1012
|
|
|
return; |
1013
|
|
|
} |
1014
|
|
|
|
1015
|
|
|
if (empty($_REQUEST['ftscfg'])) { |
1016
|
|
|
$this->doDefault($this->lang['strftsspecifyconfigtoalter']); |
1017
|
|
|
|
1018
|
|
|
return; |
1019
|
|
|
} |
1020
|
|
|
|
1021
|
|
|
if ($confirm) { |
1022
|
|
|
$this->printTrail('ftscfg'); // TODO: proper breadcrumbs |
|
|
|
|
1023
|
|
|
$this->printTitle($this->lang['strdrop'], 'pg.ftscfg.alter'); |
1024
|
|
|
|
1025
|
|
|
echo '<form action="'.\SUBFOLDER.'/src/views/fulltext" method="post">'.PHP_EOL; |
1026
|
|
|
|
1027
|
|
|
// Case of multiaction drop |
1028
|
|
|
if (isset($_REQUEST['ma'])) { |
1029
|
|
|
foreach ($_REQUEST['ma'] as $v) { |
1030
|
|
|
$a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES)); |
1031
|
|
|
echo '<p>', sprintf($this->lang['strconfdropftsmapping'], $this->misc->printVal($a['mapping']), $this->misc->printVal($_REQUEST['ftscfg'])), '</p>'.PHP_EOL; |
1032
|
|
|
printf('<input type="hidden" name="mapping[]" value="%s" />', htmlspecialchars($a['mapping'])); |
1033
|
|
|
} |
1034
|
|
|
} else { |
1035
|
|
|
echo '<p>', sprintf($this->lang['strconfdropftsmapping'], $this->misc->printVal($_REQUEST['mapping']), $this->misc->printVal($_REQUEST['ftscfg'])), '</p>'.PHP_EOL; |
1036
|
|
|
echo '<input type="hidden" name="mapping" value="', htmlspecialchars($_REQUEST['mapping']), '" />'.PHP_EOL; |
1037
|
|
|
} |
1038
|
|
|
|
1039
|
|
|
echo "<input type=\"hidden\" name=\"ftscfg\" value=\"{$_REQUEST['ftscfg']}\" />".PHP_EOL; |
1040
|
|
|
echo '<input type="hidden" name="action" value="dropmapping" />'.PHP_EOL; |
1041
|
|
|
echo '<input type="hidden" name="prev_action" value="viewconfig" /></p>'.PHP_EOL; |
1042
|
|
|
echo $this->misc->form; |
1043
|
|
|
echo "<input type=\"submit\" name=\"drop\" value=\"{$this->lang['strdrop']}\" />".PHP_EOL; |
1044
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" />".PHP_EOL; |
1045
|
|
|
echo '</form>'.PHP_EOL; |
1046
|
|
|
} else { |
1047
|
|
|
// Case of multiaction drop |
1048
|
|
|
if (is_array($_REQUEST['mapping'])) { |
1049
|
|
|
$status = $data->changeFtsMapping($_REQUEST['ftscfg'], $_REQUEST['mapping'], 'drop'); |
1050
|
|
|
if (0 != $status) { |
1051
|
|
|
$this->doViewConfig($_REQUEST['ftscfg'], $this->lang['strftsmappingdroppedbad']); |
1052
|
|
|
|
1053
|
|
|
return; |
1054
|
|
|
} |
1055
|
|
|
$this->doViewConfig($_REQUEST['ftscfg'], $this->lang['strftsmappingdropped']); |
1056
|
|
|
} else { |
1057
|
|
|
$status = $data->changeFtsMapping($_REQUEST['ftscfg'], [$_REQUEST['mapping']], 'drop'); |
1058
|
|
|
if (0 == $status) { |
1059
|
|
|
$this->doViewConfig($_REQUEST['ftscfg'], $this->lang['strftsmappingdropped']); |
1060
|
|
|
} else { |
1061
|
|
|
$this->doViewConfig($_REQUEST['ftscfg'], $this->lang['strftsmappingdroppedbad']); |
1062
|
|
|
} |
1063
|
|
|
} |
1064
|
|
|
} |
1065
|
|
|
} |
1066
|
|
|
|
1067
|
|
|
public function doAlterMapping($msg = '') |
1068
|
|
|
{ |
1069
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
1070
|
|
|
$this->printTrail('ftscfg'); |
|
|
|
|
1071
|
|
|
$this->printTitle($this->lang['stralter'], 'pg.ftscfg.alter'); |
1072
|
|
|
$this->printMsg($msg); |
1073
|
|
|
|
1074
|
|
|
$ftsdicts = $data->getFtsDictionaries(); |
1075
|
|
|
if ($ftsdicts->recordCount() > 0) { |
1076
|
|
|
$this->coalesceArr($_POST, 'formMapping', @$_REQUEST['mapping']); |
1077
|
|
|
|
1078
|
|
|
$this->coalesceArr($_POST, 'formDictionary', ''); |
1079
|
|
|
|
1080
|
|
|
$this->coalesceArr($_POST, 'ftscfg', $_REQUEST['ftscfg']); |
1081
|
|
|
|
1082
|
|
|
echo '<form action="'.\SUBFOLDER.'/src/views/fulltext" method="post">'.PHP_EOL; |
1083
|
|
|
|
1084
|
|
|
echo '<table>'.PHP_EOL; |
1085
|
|
|
echo "\t<tr>".PHP_EOL; |
1086
|
|
|
echo "\t\t<th class=\"data left required\">{$this->lang['strftsmapping']}</th>".PHP_EOL; |
1087
|
|
|
echo "\t\t<td class=\"data1\">"; |
1088
|
|
|
|
1089
|
|
|
$ma_mappings = []; |
1090
|
|
|
// Case of multiaction drop |
1091
|
|
|
if (isset($_REQUEST['ma'])) { |
1092
|
|
|
$ma_mappings_names = []; |
1093
|
|
|
foreach ($_REQUEST['ma'] as $v) { |
1094
|
|
|
$a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES)); |
1095
|
|
|
printf('<input type="hidden" name="formMapping[]" value="%s" />', htmlspecialchars($a['mapping'])); |
1096
|
|
|
$ma_mappings[] = $data->getFtsMappingByName($_POST['ftscfg'], $a['mapping']); |
1097
|
|
|
$ma_mappings_names[] = $a['mapping']; |
1098
|
|
|
} |
1099
|
|
|
echo implode(', ', $ma_mappings_names); |
1100
|
|
|
} else { |
1101
|
|
|
$mapping = $data->getFtsMappingByName($_POST['ftscfg'], $_POST['formMapping']); |
1102
|
|
|
echo $mapping->fields['name']; |
1103
|
|
|
echo '<input type="hidden" name="formMapping" value="', htmlspecialchars($_POST['formMapping']), '" />'.PHP_EOL; |
1104
|
|
|
} |
1105
|
|
|
|
1106
|
|
|
echo "\t\t</td>".PHP_EOL; |
1107
|
|
|
echo "\t</tr>".PHP_EOL; |
1108
|
|
|
|
1109
|
|
|
// Dictionary |
1110
|
|
|
echo "\t<tr>".PHP_EOL; |
1111
|
|
|
echo "\t\t<th class=\"data left required\">{$this->lang['strftsdict']}</th>".PHP_EOL; |
1112
|
|
|
echo "\t\t<td class=\"data1\">"; |
1113
|
|
|
echo "\t\t\t<select name=\"formDictionary\">".PHP_EOL; |
1114
|
|
|
while (!$ftsdicts->EOF) { |
1115
|
|
|
$ftsdict = htmlspecialchars($ftsdicts->fields['name']); |
1116
|
|
|
echo "\t\t\t\t<option value=\"{$ftsdict}\"", |
1117
|
|
|
( |
1118
|
|
|
$ftsdict == $_POST['formDictionary'] |
1119
|
|
|
|| $ftsdict == @$mapping->fields['dictionaries'] |
|
|
|
|
1120
|
|
|
|| $ftsdict == @$ma_mappings[0]->fields['dictionaries'] |
1121
|
|
|
) ? ' selected="selected"' : '', ">{$ftsdict}</option>".PHP_EOL; |
1122
|
|
|
$ftsdicts->moveNext(); |
1123
|
|
|
} |
1124
|
|
|
|
1125
|
|
|
echo "\t\t</td>".PHP_EOL; |
1126
|
|
|
echo "\t</tr>".PHP_EOL; |
1127
|
|
|
|
1128
|
|
|
echo '</table>'.PHP_EOL; |
1129
|
|
|
echo '<p><input type="hidden" name="action" value="altermapping" />'.PHP_EOL; |
1130
|
|
|
echo '<input type="hidden" name="ftscfg" value="', htmlspecialchars($_POST['ftscfg']), '" />'.PHP_EOL; |
1131
|
|
|
echo '<input type="hidden" name="prev_action" value="viewconfig" /></p>'.PHP_EOL; |
1132
|
|
|
|
1133
|
|
|
echo $this->misc->form; |
1134
|
|
|
echo "<input type=\"submit\" name=\"alter\" value=\"{$this->lang['stralter']}\" />".PHP_EOL; |
1135
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>".PHP_EOL; |
1136
|
|
|
echo '</form>'.PHP_EOL; |
1137
|
|
|
} else { |
1138
|
|
|
echo "<p>{$this->lang['strftsnodictionaries']}</p>".PHP_EOL; |
1139
|
|
|
} |
1140
|
|
|
} |
1141
|
|
|
|
1142
|
|
|
/** |
1143
|
|
|
* Save the form submission containing changes to a FTS mapping. |
1144
|
|
|
*/ |
1145
|
|
View Code Duplication |
public function doSaveAlterMapping() |
|
|
|
|
1146
|
|
|
{ |
1147
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
1148
|
|
|
|
1149
|
|
|
$mappingArray = (is_array($_POST['formMapping']) ? $_POST['formMapping'] : [$_POST['formMapping']]); |
1150
|
|
|
$status = $data->changeFtsMapping($_POST['ftscfg'], $mappingArray, 'alter', $_POST['formDictionary']); |
1151
|
|
|
if (0 == $status) { |
1152
|
|
|
$this->doViewConfig($_POST['ftscfg'], $this->lang['strftsmappingaltered']); |
1153
|
|
|
} else { |
1154
|
|
|
$this->doAlterMapping($this->lang['strftsmappingalteredbad']); |
1155
|
|
|
} |
1156
|
|
|
} |
1157
|
|
|
|
1158
|
|
|
/** |
1159
|
|
|
* Show the form to enter parameters of a new FTS mapping. |
1160
|
|
|
* |
1161
|
|
|
* @param mixed $msg |
1162
|
|
|
*/ |
1163
|
|
|
public function doAddMapping($msg = '') |
1164
|
|
|
{ |
1165
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
1166
|
|
|
|
1167
|
|
|
$this->printTrail('ftscfg'); |
|
|
|
|
1168
|
|
|
$this->printTitle($this->lang['stralter'], 'pg.ftscfg.alter'); |
1169
|
|
|
$this->printMsg($msg); |
1170
|
|
|
|
1171
|
|
|
$ftsdicts = $data->getFtsDictionaries(); |
1172
|
|
|
if ($ftsdicts->recordCount() > 0) { |
1173
|
|
|
$this->coalesceArr($_POST, 'formMapping', ''); |
1174
|
|
|
|
1175
|
|
|
$this->coalesceArr($_POST, 'formDictionary', ''); |
1176
|
|
|
|
1177
|
|
|
$this->coalesceArr($_POST, 'ftscfg', $_REQUEST['ftscfg']); |
1178
|
|
|
|
1179
|
|
|
$mappings = $data->getFtsMappings($_POST['ftscfg']); |
1180
|
|
|
|
1181
|
|
|
echo '<form action="'.\SUBFOLDER.'/src/views/fulltext" method="post">'.PHP_EOL; |
1182
|
|
|
echo '<table>'.PHP_EOL; |
1183
|
|
|
echo "\t<tr>".PHP_EOL; |
1184
|
|
|
echo "\t\t<th class=\"data left required\">{$this->lang['strftsmapping']}</th>".PHP_EOL; |
1185
|
|
|
echo "\t\t<td class=\"data1\">"; |
1186
|
|
|
echo "\t\t\t<select name=\"formMapping\">".PHP_EOL; |
1187
|
|
|
while (!$mappings->EOF) { |
1188
|
|
|
$mapping = htmlspecialchars($mappings->fields['name']); |
1189
|
|
|
$mapping_desc = htmlspecialchars($mappings->fields['description']); |
1190
|
|
|
echo "\t\t\t\t<option value=\"{$mapping}\"", |
1191
|
|
|
$mapping == $_POST['formMapping'] ? ' selected="selected"' : '', ">{$mapping}", $mapping_desc ? " - {$mapping_desc}" : '', '</option>'.PHP_EOL; |
1192
|
|
|
$mappings->moveNext(); |
1193
|
|
|
} |
1194
|
|
|
echo "\t\t</td>".PHP_EOL; |
1195
|
|
|
echo "\t</tr>".PHP_EOL; |
1196
|
|
|
|
1197
|
|
|
// Dictionary |
1198
|
|
|
echo "\t<tr>".PHP_EOL; |
1199
|
|
|
echo "\t\t<th class=\"data left required\">{$this->lang['strftsdict']}</th>".PHP_EOL; |
1200
|
|
|
echo "\t\t<td class=\"data1\">"; |
1201
|
|
|
echo "\t\t\t<select name=\"formDictionary\">".PHP_EOL; |
1202
|
|
|
while (!$ftsdicts->EOF) { |
1203
|
|
|
$ftsdict = htmlspecialchars($ftsdicts->fields['name']); |
1204
|
|
|
echo "\t\t\t\t<option value=\"{$ftsdict}\"", |
1205
|
|
|
$ftsdict == $_POST['formDictionary'] ? ' selected="selected"' : '', ">{$ftsdict}</option>".PHP_EOL; |
1206
|
|
|
$ftsdicts->moveNext(); |
1207
|
|
|
} |
1208
|
|
|
|
1209
|
|
|
echo "\t\t</td>".PHP_EOL; |
1210
|
|
|
echo "\t</tr>".PHP_EOL; |
1211
|
|
|
|
1212
|
|
|
echo '</table>'.PHP_EOL; |
1213
|
|
|
echo '<p><input type="hidden" name="action" value="addmapping" />'.PHP_EOL; |
1214
|
|
|
echo '<input type="hidden" name="ftscfg" value="', htmlspecialchars($_POST['ftscfg']), '" />'.PHP_EOL; |
1215
|
|
|
echo '<input type="hidden" name="prev_action" value="viewconfig" /></p>'.PHP_EOL; |
1216
|
|
|
echo $this->misc->form; |
1217
|
|
|
echo "<input type=\"submit\" name=\"add\" value=\"{$this->lang['stradd']}\" />".PHP_EOL; |
1218
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>".PHP_EOL; |
1219
|
|
|
echo '</form>'.PHP_EOL; |
1220
|
|
|
} else { |
1221
|
|
|
echo "<p>{$this->lang['strftsnodictionaries']}</p>".PHP_EOL; |
1222
|
|
|
} |
1223
|
|
|
} |
1224
|
|
|
|
1225
|
|
|
/** |
1226
|
|
|
* Save the form submission containing parameters of a new FTS mapping. |
1227
|
|
|
*/ |
1228
|
|
View Code Duplication |
public function doSaveAddMapping() |
|
|
|
|
1229
|
|
|
{ |
1230
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
1231
|
|
|
|
1232
|
|
|
$mappingArray = (is_array($_POST['formMapping']) ? $_POST['formMapping'] : [$_POST['formMapping']]); |
1233
|
|
|
$status = $data->changeFtsMapping($_POST['ftscfg'], $mappingArray, 'add', $_POST['formDictionary']); |
1234
|
|
|
if (0 == $status) { |
1235
|
|
|
$this->doViewConfig($_POST['ftscfg'], $this->lang['strftsmappingadded']); |
1236
|
|
|
} else { |
1237
|
|
|
$this->doAddMapping($this->lang['strftsmappingaddedbad']); |
1238
|
|
|
} |
1239
|
|
|
} |
1240
|
|
|
} |
1241
|
|
|
|
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString
.