-
Notifications
You must be signed in to change notification settings - Fork 0
/
index_edit.php
339 lines (323 loc) · 12.9 KB
/
index_edit.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
<?php
// Change the blocks on "My page" and "Home page"
//
// webtrees: Web based Family History software
// Copyright (C) 2012 webtrees development team.
//
// Derived from PhpGedView
// Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// $Id$
define('WT_SCRIPT_NAME', 'index_edit.php');
require './includes/session.php';
$controller=new WT_Controller_Ajax();
// Only one of $user_id and $gedcom_id should be set
$user_id=safe_REQUEST($_REQUEST, 'user_id');
if ($user_id) {
$gedcom_id=null;
} else {
$gedcom_id=safe_REQUEST($_REQUEST, 'gedcom_id');
}
// Only an admin can edit the "default" page
// Only managers can edit the "home page"
// Only a user or an admin can edit a user's "my page"
if (
$gedcom_id<0 && !WT_USER_IS_ADMIN ||
$gedcom_id>0 && !userGedcomAdmin(WT_USER_ID, $gedcom_id) ||
$user_id && WT_USER_ID!=$user_id && !WT_USER_IS_ADMIN
) {
$controller->pageHeader();
$controller->addInlineJavascript('window.location.reload();');
exit;
}
$action=safe_GET('action');
if (isset($_REQUEST['main'])) {
$main=$_REQUEST['main'];
} else {
$main=array();
}
if (isset($_REQUEST['right'])) {
$right=$_REQUEST['right'];
} else {
$right=array();
}
// Define all the icons we're going to use
$IconUarrow = 'icon-uarrow';
$IconDarrow = 'icon-darrow';
if($TEXT_DIRECTION=='ltr') {
$IconRarrow = 'icon-rarrow';
$IconLarrow = 'icon-larrow';
$IconRDarrow = 'icon-rdarrow';
$IconLDarrow = 'icon-ldarrow';
} else {
$IconRarrow = 'icon-larrow';
$IconLarrow = 'icon-rarrow';
$IconRDarrow = 'icon-ldarrow';
$IconLDarrow = 'icon-rdarrow';
}
$all_blocks=array();
foreach (WT_Module::getActiveBlocks() as $name=>$block) {
if ($user_id && $block->isUserBlock() || $gedcom_id && $block->isGedcomBlock()) {
$all_blocks[$name]=$block;
}
}
if ($user_id) {
$blocks=get_user_blocks($user_id);
} elseif ($gedcom_id) {
$blocks=get_gedcom_blocks($gedcom_id);
}
if ($action=='update') {
foreach (array('main', 'side') as $location) {
if ($location=='main') {
$new_blocks=$main;
} else {
$new_blocks=$right;
}
foreach ($new_blocks as $order=>$block_name) {
if (is_numeric($block_name)) {
// existing block
WT_DB::prepare("UPDATE `##block` SET block_order=? WHERE block_id=?")->execute(array($order, $block_name));
// existing block moved location
WT_DB::prepare("UPDATE `##block` SET location=? WHERE block_id=?")->execute(array($location, $block_name));
} else {
// new block
if ($user_id) {
WT_DB::prepare("INSERT INTO `##block` (user_id, location, block_order, module_name) VALUES (?, ?, ?, ?)")->execute(array($user_id, $location, $order, $block_name));
} else {
WT_DB::prepare("INSERT INTO `##block` (gedcom_id, location, block_order, module_name) VALUES (?, ?, ?, ?)")->execute(array($gedcom_id, $location, $order, $block_name));
}
}
}
// deleted blocks
foreach ($blocks[$location] as $block_id=>$block_name) {
if (!in_array($block_id, $main) && !in_array($block_id, $right)) {
WT_DB::prepare("DELETE FROM `##block_setting` WHERE block_id=?")->execute(array($block_id));
WT_DB::prepare("DELETE FROM `##block` WHERE block_id=?")->execute(array($block_id));
}
}
}
exit;
}
$controller
->pageHeader()
->addInlineJavascript('
/**
* Move Up Block Javascript function
*
* This function moves the selected option up in the given select list
* @param String section_name the name of the select to move the options
*/
function move_up_block(section_name) {
section_select = document.getElementById(section_name);
if (section_select) {
if (section_select.selectedIndex <= 0) return false;
index = section_select.selectedIndex;
temp = new Option(section_select.options[index-1].text, section_select.options[index-1].value);
section_select.options[index-1] = new Option(section_select.options[index].text, section_select.options[index].value);
section_select.options[index] = temp;
section_select.selectedIndex = index-1;
}
}
/**
* Move Down Block Javascript function
*
* This function moves the selected option down in the given select list
* @param String section_name the name of the select to move the options
*/
function move_down_block(section_name) {
section_select = document.getElementById(section_name);
if (section_select) {
if (section_select.selectedIndex < 0) return false;
if (section_select.selectedIndex >= section_select.length-1) return false;
index = section_select.selectedIndex;
temp = new Option(section_select.options[index+1].text, section_select.options[index+1].value);
section_select.options[index+1] = new Option(section_select.options[index].text, section_select.options[index].value);
section_select.options[index] = temp;
section_select.selectedIndex = index+1;
}
}
/**
* Move Block from one column to the other Javascript function
*
* This function moves the selected option down in the given select list
* @author KosherJava
* @param String from_column the name of the select to move the option from
* @param String to_column the name of the select to remove the option to
*/
function move_left_right_block(from_column, to_column) {
to_select = document.getElementById(to_column);
from_select = document.getElementById(from_column);
instruct = document.getElementById("instructions");
if ((to_select) && (from_select)) {
add_option = from_select.options[from_select.selectedIndex];
if (to_column != "available_select") {
to_select.options[to_select.length] = new Option(add_option.text, add_option.value);
}
if (from_column != "available_select") {
from_select.options[from_select.selectedIndex] = null; //remove from list
}
}
}
/**
* Select Options Javascript function
*
* This function selects all the options in the multiple select lists
*/
function select_options() {
section_select = document.getElementById("main_select");
if (section_select) {
for (i=0; i<section_select.length; i++) {
section_select.options[i].selected=true;
}
}
section_select = document.getElementById("right_select");
if (section_select) {
for (i=0; i<section_select.length; i++) {
section_select.options[i].selected=true;
}
}
return true;
}
/**
* Show Block Description Javascript function
*
* This function shows a description for the selected option
* @param String list_name the name of the select to get the option from
*/
function show_description(list_name) {
list_select = document.getElementById(list_name);
instruct = document.getElementById("instructions");
if (block_descr[list_select.options[list_select.selectedIndex].value] && instruct) {
instruct.innerHTML = block_descr[list_select.options[list_select.selectedIndex].value];
} else {
instruct.innerHTML = block_descr["advice1"];
}
list1 = document.getElementById("main_select");
list2 = document.getElementById("available_select");
list3 = document.getElementById("right_select");
if (list_name=="main_select") {
list2.selectedIndex = -1;
list3.selectedIndex = -1;
}
if (list_name=="available_select") {
list1.selectedIndex = -1;
list3.selectedIndex = -1;
}
if (list_name=="right_select") {
list1.selectedIndex = -1;
list2.selectedIndex = -1;
}
}
var block_descr = new Array();
');
// Load Block Description array for use by javascript
foreach ($all_blocks as $block_name=>$block) {
$controller->addInlineJavascript(
'block_descr["'.$block_name.'"] = "'.addslashes($block->getDescription()).'";'
);
}
$controller->addInlineJavascript(
'block_descr["advice1"] = "'.WT_I18N::translate('Highlight a block name and then click on one of the arrow icons to move that highlighted block in the indicated direction.').'";'
);
?>
<form name="config_setup" method="post" action="index_edit.php?action=update" onsubmit="select_options(); return modalDialogSubmitAjax(this);" >
<input type="hidden" name="user_id" value="<?php echo $user_id; ?>">
<input type="hidden" name="gedcom_id" value="<?php echo $gedcom_id; ?>">
<table border="1" id="change_blocks">
<?php
// NOTE: Row 1: Column legends
echo '<tr>';
echo '<td class="descriptionbox center vmiddle" colspan="2">';
echo '<b>', WT_I18N::translate('Main Section Blocks'), '</b>';
echo '</td>';
echo '<td class="descriptionbox center vmiddle" colspan="3">';
echo '<b>', WT_I18N::translate('Available Blocks'), '</b>';
echo '</td>';
echo '<td class="descriptionbox center vmiddle" colspan="2">';
echo '<b>', WT_I18N::translate('Right Section Blocks'), '</b>';
echo '</td>';
echo '</tr>';
echo '<tr>';
// NOTE: Row 2 column 1: Up/Down buttons for left (main) block list
echo '<td class="optionbox center vmiddle">';
echo '<a onclick="move_up_block(\'main_select\');" title="', WT_I18N::translate('Move up'), '"class="', $IconUarrow, '"></a>';
echo '<br>';
echo '<a onclick="move_down_block(\'main_select\');" title="', WT_I18N::translate('Move down'), '"class="', $IconDarrow, '"></a>';
echo '<br><br>';
echo help_link('block_move_up');
echo '</td>';
// NOTE: Row 2 column 2: Left (Main) block list
echo '<td class="optionbox center">';
echo '<select multiple="multiple" id="main_select" name="main[]" size="10" onchange="show_description(\'main_select\');">';
foreach ($blocks['main'] as $block_id=>$block_name) {
echo '<option value="', $block_id, '">', $all_blocks[$block_name]->getTitle(), '</option>';
}
echo '</select>';
echo '</td>';
// NOTE: Row 2 column 3: Left/Right buttons for left (main) block list
echo '<td class="optionbox center vmiddle">';
echo '<a onclick="move_left_right_block(\'main_select\', \'right_select\');" title="', WT_I18N::translate('Move Right'), '"class="', $IconRDarrow, '"></a>';
echo '<br>';
echo '<a onclick="move_left_right_block(\'main_select\', \'available_select\');" title="', WT_I18N::translate('Remove'), '"class="', $IconRarrow, '"></a>';
echo '<br>';
echo '<a onclick="move_left_right_block(\'available_select\', \'main_select\');" title="', WT_I18N::translate('Add'), '"class="', $IconLarrow, '"></a>';
echo '<br><br>';
echo help_link('block_move_right');
echo '</td>';
// Row 2 column 4: Middle (Available) block list
echo '<td class="optionbox center">';
echo '<select id="available_select" name="available[]" size="10" onchange="show_description(\'available_select\');">';
foreach ($all_blocks as $block_name=>$block) {
echo '<option value="', $block_name, '">', $block->getTitle(), '</option>';
}
echo '</select>';
echo '</td>';
// NOTE: Row 2 column 5: Left/Right buttons for right block list
echo '<td class="optionbox center vmiddle">';
echo '<a onclick="move_left_right_block(\'right_select\', \'main_select\');" title="', WT_I18N::translate('Move Left'), '"class="', $IconLDarrow, '"></a>';
echo '<br>';
echo '<a onclick="move_left_right_block(\'right_select\', \'available_select\');" title="', WT_I18N::translate('Remove'), '"class="', $IconLarrow, '"></a>';
echo '<br>';
echo '<a onclick="move_left_right_block(\'available_select\', \'right_select\');" title="', WT_I18N::translate('Add'), '"class="', $IconRarrow, '"></a>';
echo '<br><br>';
echo help_link('block_move_right');
echo '</td>';
// NOTE: Row 2 column 6: Right block list
echo '<td class="optionbox center">';
echo '<select multiple="multiple" id="right_select" name="right[]" size="10" onchange="show_description(\'right_select\');">';
foreach ($blocks['side'] as $block_id=>$block_name) {
echo '<option value="', $block_id, '">', $all_blocks[$block_name]->getTitle(), '</option>';
}
echo '</select>';
echo '</td>';
// NOTE: Row 2 column 7: Up/Down buttons for right block list
echo '<td class="optionbox center vmiddle">';
echo '<a onclick="move_up_block(\'right_select\');" title="', WT_I18N::translate('Move up'), '"class="', $IconUarrow, '"></a>';
echo '<br>';
echo '<a onclick="move_down_block(\'right_select\');" title="', WT_I18N::translate('Move down'), '"class="', $IconDarrow, '"></a>';
echo '<br><br>';
echo help_link('block_move_up');
echo '</td>';
echo '</tr>';
// NOTE: Row 3 columns 1-7: Summary description of currently selected block
echo '<tr><td class="descriptionbox wrap" colspan="7"><div id="instructions">';
echo WT_I18N::translate('Highlight a block name and then click on one of the arrow icons to move that highlighted block in the indicated direction.');
echo '</div></td></tr>';
echo '<tr><td class="topbottombar" colspan="7">';
echo '<input type="submit" value="', WT_I18N::translate('save'), '">';
echo '</td></tr></table>';
echo '</form>';