Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         pages
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2011, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version         $Id: sections.php 1475 2011-07-12 23:07:10Z Luisehahne $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/pages/sections.php $
15
 * @lastmodified    $Date: 2011-07-13 01:07:10 +0200 (Wed, 13 Jul 2011) $
16
 *
17
 */
18

    
19
// Include config file
20
require('../../config.php');
21

    
22
// Make sure people are allowed to access this page
23
if(MANAGE_SECTIONS != 'enabled')
24
{
25
	header('Location: '.ADMIN_URL.'/pages/index.php');
26
	exit(0);
27
}
28
/* */
29
$debug = false; // to show position and section_id
30
If(!defined('DEBUG')) { define('DEBUG',$debug);}
31
// Include the WB functions file
32
require_once(WB_PATH.'/framework/functions.php');
33
// Create new admin object
34
require_once(WB_PATH.'/framework/class.admin.php');
35
$admin = new admin('Pages', 'pages_modify', false);
36

    
37
$action = 'show';
38
// Get page id
39
$requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
40
$page_id = intval((isset(${$requestMethod}['page_id'])) ? ${$requestMethod}['page_id'] : 0);
41
$action = ($page_id ? 'show' : $action);
42
// Get section id if there is one
43
$requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
44
$section_id = ((isset(${$requestMethod}['section_id'])) ? ${$requestMethod}['section_id']  : 0);
45
$action = ($section_id ? 'delete' : $action);
46
// Get module if there is one
47
$requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
48
$module = ((isset(${$requestMethod}['module'])) ? ${$requestMethod}['module']  : 0);
49
$action = ($module != '' ? 'add' : $action);
50
$admin_header = true;
51
$backlink = ADMIN_URL.'/pages/sections.php?page_id='.(int)$page_id;
52

    
53
switch ($action):
54
	case 'delete' :
55

    
56
		if( ( !($section_id = intval($admin->checkIDKEY('section_id', 0, $_SERVER['REQUEST_METHOD'])) )) )
57
		{
58
			if($admin_header) { $admin->print_header(); }
59
			$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$backlink);
60
		}
61

    
62
		$action = 'show';
63
	    $sql  = 'SELECT `module` FROM `'.TABLE_PREFIX.'sections` ';
64
	    $sql .= 'WHERE `section_id` ='.$section_id;
65
        if( ( ($modulname = $database->get_one($sql)) == $module) && ($section_id > 0 ) ) {
66
			// Include the modules delete file if it exists
67
			if(file_exists(WB_PATH.'/modules/'.$modulname.'/delete.php'))
68
		    {
69
				require(WB_PATH.'/modules/'.$modulname.'/delete.php');
70
			}
71
		    $sql  = 'DELETE FROM `'.TABLE_PREFIX.'sections` ';
72
		    $sql .= 'WHERE `section_id` ='.(int)$section_id.' LIMIT 1';
73
			if( !$database->query($sql) ) {
74
				if($admin_header) { $admin->print_header(); }
75
				$admin->print_error($database->get_error(),$backlink);
76
			}  else {
77
				require_once(WB_PATH.'/framework/class.order.php');
78
				$order = new order(TABLE_PREFIX.'sections', 'position', 'section_id', 'page_id');
79
				$order->clean($page_id);
80
				$format = $TEXT['SECTION'].' %d  %s %s '.strtolower( $TEXT['DELETED']);
81
				$message = sprintf ($format,$section_id,strtoupper($modulname),strtolower($TEXT['SUCCESS']));
82
				if($admin_header) { $admin->print_header(); }
83
				$admin_header = false;
84
				unset($_POST);
85
				$admin->print_success($message, $backlink );
86
			}
87
        } else {
88
			if($admin_header) { $admin->print_header(); }
89
			$admin->print_error($module.' '.strtolower($TEXT['NOT_FOUND']),$backlink);
90
        }
91

    
92
		break;
93
	case 'add' :
94

    
95
		if (!$admin->checkFTAN())
96
		{
97
			$admin->print_header();
98
			$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$backlink);
99
		}
100
		$action = 'show';
101
		$module = preg_replace('/\W/', '', $module );  // fix secunia 2010-91-4
102
		require_once(WB_PATH.'/framework/class.order.php');
103
		// Get new order
104
		$order = new order(TABLE_PREFIX.'sections', 'position', 'section_id', 'page_id');
105
		$position = $order->get_new($page_id);
106
		// Insert module into DB
107
	    $sql  = 'INSERT INTO `'.TABLE_PREFIX.'sections` SET ';
108
	    $sql .= '`page_id` = '.(int)$page_id.', ';
109
	    $sql .= '`module` = \''.$module.'\', ';
110
	    $sql .= '`position` = '.(int)$position.', ';
111
	    $sql .= '`block` = 1';
112
        if($database->query($sql)) {
113
			// Get the section id
114
			$section_id = $database->get_one("SELECT LAST_INSERT_ID()");
115
			// Include the selected modules add file if it exists
116
			if(file_exists(WB_PATH.'/modules/'.$module.'/add.php'))
117
		    {
118
				require(WB_PATH.'/modules/'.$module.'/add.php');
119
			}
120
        } elseif ($database->is_error())  {
121
			if($admin_header) { $admin->print_header(); }
122
			$admin->print_error($database->get_error());
123
		}
124
		break;
125
	default:
126
		break;
127
endswitch;
128

    
129
switch ($action):
130
	default:
131

    
132
		if($admin_header) { $admin->print_header(); }
133
		// Get perms
134
		$sql  = 'SELECT `admin_groups`,`admin_users` FROM `'.TABLE_PREFIX.'pages` ';
135
		$sql .= 'WHERE `page_id` = '.$page_id;
136
		$results = $database->query($sql);
137

    
138
		$results_array = $results->fetchRow();
139
		$old_admin_groups = explode(',', $results_array['admin_groups']);
140
		$old_admin_users = explode(',', $results_array['admin_users']);
141
		$in_old_group = FALSE;
142
		foreach($admin->get_groups_id() as $cur_gid)
143
		{
144
			if (in_array($cur_gid, $old_admin_groups))
145
		    {
146
				$in_old_group = TRUE;
147
			}
148
		}
149
		if((!$in_old_group) && !is_numeric(array_search($admin->get_user_id(), $old_admin_users)))
150
		{
151
			$admin->print_header();
152
			$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
153
		}
154

    
155
		// Get page details
156
		$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'pages` ';
157
		$sql .= 'WHERE `page_id` = '.$page_id;
158
		$results = $database->query($sql);
159

    
160
		if($database->is_error())
161
		{
162
			// $admin->print_header();
163
			$admin->print_error($database->get_error());
164
		}
165
		if($results->numRows() == 0)
166
		{
167
			// $admin->print_header();
168
			$admin->print_error($MESSAGE['PAGES']['NOT_FOUND']);
169
		}
170
		$results_array = $results->fetchRow();
171

    
172
		// Set module permissions
173
		$module_permissions = $_SESSION['MODULE_PERMISSIONS'];
174

    
175
		// Unset block var
176
		unset($block);
177
		// Include template info file (if it exists)
178
		if($results_array['template'] != '')
179
		{
180
			$template_location = WB_PATH.'/templates/'.$results_array['template'].'/info.php';
181
		} else {
182
			$template_location = WB_PATH.'/templates/'.DEFAULT_TEMPLATE.'/info.php';
183
		}
184
		if(file_exists($template_location))
185
		{
186
			require($template_location);
187
		}
188
		// Check if $menu is set
189
		if(!isset($block[1]) || $block[1] == '')
190
		{
191
			// Make our own menu list
192
			$block[1] = $TEXT['MAIN'];
193
		}
194

    
195
		/*-- load css files with jquery --*/
196
		// include jscalendar-setup
197
		$jscal_use_time = true; // whether to use a clock, too
198
		require_once(WB_PATH."/include/jscalendar/wb-setup.php");
199

    
200
		// Setup template object
201
		$tpl = new Template(THEME_PATH.'/templates');
202
		$tpl->set_file('page', 'pages_sections.htt');
203
		$tpl->set_block('page', 'main_block', 'main');
204
		$tpl->set_block('main_block', 'module_block', 'module_list');
205
		$tpl->set_block('main_block', 'section_block', 'section_list');
206
		$tpl->set_block('section_block', 'block_block', 'block_list');
207
		$tpl->set_block('main_block', 'calendar_block', 'calendar_list');
208
		$tpl->set_var('FTAN', $admin->getFTAN());
209

    
210
		// set first defaults and messages
211
		$tpl->set_var(array(
212
						'PAGE_ID' => $results_array['page_id'],
213
						// 'PAGE_IDKEY' => $admin->getIDKEY($results_array['page_id']),
214
						'PAGE_IDKEY' => $results_array['page_id'],
215
						'TEXT_PAGE' => $TEXT['PAGE'],
216
						'PAGE_TITLE' => ($results_array['page_title']),
217
						'MENU_TITLE' => ($results_array['menu_title']),
218
						'TEXT_CURRENT_PAGE' => $TEXT['CURRENT_PAGE'],
219
						'HEADING_MANAGE_SECTIONS' => $HEADING['MANAGE_SECTIONS'],
220
						'HEADING_MODIFY_PAGE' => $HEADING['MODIFY_PAGE'],
221
						'TEXT_CHANGE_SETTINGS' => $TEXT['CHANGE_SETTINGS'],
222
						'TEXT_ADD_SECTION' => $TEXT['ADD_SECTION'],
223
						'TEXT_ID' => 'ID',
224
						'TEXT_TYPE' => $TEXT['TYPE'],
225
						'TEXT_BLOCK' => $TEXT['BLOCK'],
226
						'TEXT_PUBL_START_DATE' => $TEXT{'PUBL_START_DATE'},
227
						'TEXT_PUBL_END_DATE' => $TEXT['PUBL_END_DATE'],
228
						'TEXT_ACTIONS' => $TEXT['ACTIONS'],
229
						'ADMIN_URL' => ADMIN_URL,
230
						'WB_URL' => WB_URL,
231
						'THEME_URL' => THEME_URL
232
						)
233
					);
234

    
235
		// Insert variables
236
		$tpl->set_var(array(
237
						'PAGE_ID' => $results_array['page_id'],
238
						// 'PAGE_IDKEY' => $admin->getIDKEY($results_array['page_id']),
239
						'PAGE_IDKEY' => $results_array['page_id'],
240
						'VAR_PAGE_TITLE' => $results_array['page_title'],
241
						'SETTINGS_LINK' => ADMIN_URL.'/pages/settings.php?page_id='.$results_array['page_id'],
242
						'MODIFY_LINK' => ADMIN_URL.'/pages/modify.php?page_id='.$results_array['page_id']
243
						)
244
					);
245

    
246
		$sql  = 'SELECT `section_id`,`module`,`position`,`block`,`publ_start`,`publ_end` ';
247
		$sql .= 'FROM `'.TABLE_PREFIX.'sections` ';
248
		$sql .= 'WHERE `page_id` = '.$page_id.' ';
249
		$sql .= 'ORDER BY `position` ASC';
250
		$query_sections = $database->query($sql);
251

    
252
		if($query_sections->numRows() > 0)
253
		{
254
			$num_sections = $query_sections->numRows();
255
			while($section = $query_sections->fetchRow())
256
		    {
257
				if(!is_numeric(array_search($section['module'], $module_permissions)))
258
		        {
259
					// Get the modules real name
260
		            $sql = 'SELECT `name` FROM `'.TABLE_PREFIX.'addons` ';
261
		            $sql .= 'WHERE `directory` = "'.$section['module'].'"';
262
		            if(!$database->get_one($sql) || !file_exists(WB_PATH.'/modules/'.$section['module']))
263
					{
264
						$edit_page = '<span class="module_disabled">'.$section['module'].'</span>';
265
					}else
266
					{
267
						$edit_page = '';
268
					}
269
					$edit_page_0 = '<a id="sid'.$section['section_id'].'" href="'.ADMIN_URL.'/pages/modify.php?page_id='.$results_array['page_id'];
270
					$edit_page_1 = $section['section_id'].'">'.$section['module'].'</a>';
271
					if(SECTION_BLOCKS)
272
		            {
273
						if($edit_page == '')
274
						{
275
							if(defined('EDIT_ONE_SECTION') && EDIT_ONE_SECTION)
276
							{
277
								$edit_page = $edit_page_0.'&amp;wysiwyg='.$edit_page_1;
278
							} else {
279
								$edit_page = $edit_page_0.'#wb_'.$edit_page_1;
280
							}
281
						}
282
						$input_attribute = 'input_normal';
283
						$tpl->set_var(array(
284
								'STYLE_DISPLAY_SECTION_BLOCK' => ' style="visibility:visible;"',
285
								'NAME_SIZE' => 300,
286
								'INPUT_ATTRIBUTE' => $input_attribute,
287
								'VAR_SECTION_ID' => $section['section_id'],
288
								'VAR_SECTION_IDKEY' => $admin->getIDKEY($section['section_id']),
289
								// 'VAR_SECTION_IDKEY' => $section['section_id'],
290
								'VAR_POSITION' => $section['position'],
291
								'LINK_MODIFY_URL_VAR_MODUL_NAME' => $edit_page,
292
								'SELECT' => '',
293
								'SET_NONE_DISPLAY_OPTION' => ''
294
								)
295
							);
296
						// Add block options to the section_list
297
						$tpl->clear_var('block_list');
298
						foreach($block AS $number => $name)
299
		                {
300
							$tpl->set_var('NAME', htmlentities(strip_tags($name)));
301
							$tpl->set_var('VALUE', $number);
302
							$tpl->set_var('SIZE', 1);
303
							if($section['block'] == $number)
304
		                    {
305
								$tpl->set_var('SELECTED', ' selected="selected"');
306
							} else {
307
								$tpl->set_var('SELECTED', '');
308
							}
309
							$tpl->parse('block_list', 'block_block', true);
310
						}
311
					} else {
312
						if($edit_page == '')
313
						{
314
							$edit_page = $edit_page_0.'#wb_'.$edit_page_1;
315
						}
316
						$input_attribute = 'input_normal';
317
						$tpl->set_var(array(
318
								'STYLE_DISPLAY_SECTION_BLOCK' => ' style="visibility:hidden;"',
319
								'NAME_SIZE' => 300,
320
								'INPUT_ATTRIBUTE' => $input_attribute,
321
								'VAR_SECTION_ID' => $section['section_id'],
322
								'VAR_SECTION_IDKEY' => $admin->getIDKEY($section['section_id']),
323
								// 'VAR_SECTION_IDKEY' => $section['section_id'],
324
								'VAR_POSITION' => $section['position'],
325
								'LINK_MODIFY_URL_VAR_MODUL_NAME' => $edit_page,
326
								'NAME' => htmlentities(strip_tags($block[1])),
327
								'VALUE' => 1,
328
								'SET_NONE_DISPLAY_OPTION' => ''
329
								)
330
							);
331
					}
332
					// Insert icon and images
333
					$tpl->set_var(array(
334
								'CLOCK_16_PNG' => 'clock_16.png',
335
								'CLOCK_DEL_16_PNG' => 'clock_del_16.png',
336
								'DELETE_16_PNG' => 'delete_16.png'
337
								)
338
							);
339
					// set calendar start values
340
					if($section['publ_start']==0)
341
		            {
342
						$tpl->set_var('VALUE_PUBL_START', '');
343
					} else {
344
						$tpl->set_var('VALUE_PUBL_START', date($jscal_format, $section['publ_start']));
345
					}
346
					// set calendar start values
347
					if($section['publ_end']==0)
348
		            {
349
						$tpl->set_var('VALUE_PUBL_END', '');
350
					} else {
351
						$tpl->set_var('VALUE_PUBL_END', date($jscal_format, $section['publ_end']));
352
					}
353
					// Insert icons up and down
354
					if($section['position'] != 1 )
355
		            {
356
						$tpl->set_var(
357
									'VAR_MOVE_UP_URL',
358
									'<a href="'.ADMIN_URL.'/pages/move_up.php?page_id='.$page_id.'&amp;section_id='.$section['section_id'].'">
359
									<img src="'.THEME_URL.'/images/up_16.png" alt="{TEXT_MOVE_UP}" />
360
									</a>' );
361
					} else {
362
						$tpl->set_var(array(
363
									'VAR_MOVE_UP_URL' => ''
364
									)
365
								);
366
					}
367
					if($section['position'] != $num_sections ) {
368
						$tpl->set_var(
369
									'VAR_MOVE_DOWN_URL',
370
									'<a href="'.ADMIN_URL.'/pages/move_down.php?page_id='.$page_id.'&amp;section_id='.$section['section_id'].'">
371
									<img src="'.THEME_URL.'/images/down_16.png" alt="{TEXT_MOVE_DOWN}" />
372
									</a>' );
373
					} else {
374
						$tpl->set_var(array(
375
									'VAR_MOVE_DOWN_URL' => ''
376
									)
377
								);
378
					}
379
				} else {
380
				  continue;
381
				}
382

    
383
					$tpl->set_var(array(
384
									'DISPLAY_DEBUG' => ' style="visibility="visible;"',
385
									'TEXT_SID' => 'SID',
386
									'DEBUG_COLSPAN_SIZE' => 9
387
									)
388
								);
389
				if($debug)
390
		        {
391
					$tpl->set_var(array(
392
									'DISPLAY_DEBUG' => ' style="visibility="visible;"',
393
									'TEXT_PID' => 'PID',
394
									'TEXT_SID' => 'SID',
395
									'POSITION' => $section['position']
396
									)
397
								);
398
				} else {
399
					$tpl->set_var(array(
400
									'DISPLAY_DEBUG' => ' style="display:none;"',
401
									'TEXT_PID' => '',
402
									'POSITION' => ''
403
									)
404
								);
405
				}
406
				$tpl->parse('section_list', 'section_block', true);
407
			}
408
		}
409

    
410
		// now add the calendars -- remember to to set the range to [1970, 2037] if the date is used as timestamp!
411
		// the loop is simply a copy from above.
412
		$sql  = 'SELECT `section_id`,`module` FROM `'.TABLE_PREFIX.'sections` ';
413
		$sql .= 'WHERE page_id = '.$page_id.' ';
414
		$sql .= 'ORDER BY `position` ASC';
415
		$query_sections = $database->query($sql);
416

    
417
		if($query_sections->numRows() > 0)
418
		{
419
			$num_sections = $query_sections->numRows();
420
			while($section = $query_sections->fetchRow())
421
		    {
422
				// Get the modules real name
423
		        $sql  = 'SELECT `name` FROM `'.TABLE_PREFIX.'addons` ';
424
		        $sql .= 'WHERE `directory` = "'.$section['module'].'"';
425
		        $module_name = $database->get_one($sql);
426

    
427
				if(!is_numeric(array_search($section['module'], $module_permissions)))
428
		        {
429
					$tpl->set_var(array(
430
								'jscal_ifformat' => $jscal_ifformat,
431
								'jscal_firstday' => $jscal_firstday,
432
								'jscal_today' => $jscal_today,
433
								'start_date' => 'start_date'.$section['section_id'],
434
								'end_date' => 'end_date'.$section['section_id'],
435
								'trigger_start' => 'trigger_start'.$section['section_id'],
436
								'trigger_end' => 'trigger_stop'.$section['section_id']
437
								)
438
							);
439
					if(isset($jscal_use_time) && $jscal_use_time==TRUE) {
440
						$tpl->set_var(array(
441
								'showsTime' => "true",
442
								'timeFormat' => "24"
443
								)
444
							);
445
					}  else {
446
						$tpl->set_var(array(
447
								'showsTime' => "false",
448
								'timeFormat' => "24"
449
								)
450
							);
451
					}
452
				}
453
				$tpl->parse('calendar_list', 'calendar_block', true);
454
			}
455
		}
456

    
457
		// Work-out if we should show the "Add Section" form
458
		$sql  = 'SELECT `section_id` FROM `'.TABLE_PREFIX.'sections` ';
459
		$sql .= 'WHERE `page_id` = '.$page_id.' AND `module` = "menu_link"';
460
		$query_sections = $database->query($sql);
461
		if($query_sections->numRows() == 0)
462
		{
463
			// Modules list
464
		    $sql  = 'SELECT `name`,`directory`,`type` FROM `'.TABLE_PREFIX.'addons` ';
465
		    $sql .= 'WHERE `type` = "module" AND `function` = "page" AND `directory` != "menu_link" ';
466
		    $sql .= 'ORDER BY `name`';
467
		    $result = $database->query($sql);
468
		// if(DEBUG && $database->is_error()) { $admin->print_error($database->get_error()); }
469

    
470
			if($result->numRows() > 0)
471
		    {
472
				while ($module = $result->fetchRow())
473
		        {
474
					// Check if user is allowed to use this module   echo  $module['directory'],'<br />';
475
					if(!is_numeric(array_search($module['directory'], $module_permissions)))
476
		            {
477
						$tpl->set_var('VALUE', $module['directory']);
478
						$tpl->set_var('NAME', $module['name']);
479
						if($module['directory'] == 'wysiwyg')
480
		                {
481
							$tpl->set_var('SELECTED', ' selected="selected"');
482
						} else {
483
							$tpl->set_var('SELECTED', '');
484
						}
485
						$tpl->parse('module_list', 'module_block', true);
486
					} else {
487
					  continue;
488
					}
489
				}
490
			}
491
		}
492
		// Insert language text and messages
493
		$tpl->set_var(array(
494
							'TEXT_MANAGE_SECTIONS' => $HEADING['MANAGE_SECTIONS'],
495
							'TEXT_ARE_YOU_SURE' => url_encode($TEXT['ARE_YOU_SURE']),
496
							'TEXT_TYPE' => $TEXT['TYPE'],
497
							'TEXT_ADD' => $TEXT['ADD'],
498
							'TEXT_SAVE' =>  $TEXT['SAVE'],
499
							'TEXTLINK_MODIFY_PAGE' => $HEADING['MODIFY_PAGE'],
500
							'TEXT_CALENDAR' => $TEXT['CALENDAR'],
501
							'TEXT_DELETE_DATE' => $TEXT['DELETE_DATE'],
502
							'TEXT_ADD_SECTION' => $TEXT['ADD_SECTION'],
503
							'TEXT_MOVE_UP' => $TEXT['MOVE_UP'],
504
							'TEXT_MOVE_DOWN' => $TEXT['MOVE_DOWN']
505
							)
506
						);
507
		$tpl->parse('main', 'main_block', false);
508
		$tpl->pparse('output', 'page');
509
		// include the required file for Javascript admin
510
		if(file_exists(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php'))
511
		{
512
			include(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php');
513
		}
514
		break;
515
endswitch;
516

    
517
// Print admin footer
518
$admin->print_footer();
(17-17/21)