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 1349 2010-12-19 19:04:59Z Luisehahne $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/pages/sections.php $
15
 * @lastmodified    $Date: 2010-12-19 20:04:59 +0100 (Sun, 19 Dec 2010) $
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
// Get page id
30
if(!isset($_GET['page_id']) OR !is_numeric($_GET['page_id']))
31
{
32
	header("Location: index.php");
33
	exit(0);
34
} else {
35
	$page_id = $_GET['page_id'];
36
}
37

    
38
$debug = false; // to show position and section_id
39
If(!defined('DEBUG')) { define('DEBUG',$debug);}
40
// Create new admin object
41
require_once(WB_PATH.'/framework/class.admin.php');
42
$admin = new admin('Pages', 'pages_modify');
43

    
44
// Check if we are supposed to add or delete a section
45
if(isset($_GET['section_id']) AND is_numeric($_GET['section_id']))
46
{
47
	// Get more information about this section
48
	$section_id = $_GET['section_id'];
49
    $sql  = 'SELECT `module` FROM `'.TABLE_PREFIX.'sections` ';
50
    $sql .= 'WHERE `section_id` ='.$section_id;
51
    $query_section = $database->query($sql);
52

    
53
	if($query_section->numRows() == 0)
54
    {
55
		$admin->print_error('Section not found');
56
	}
57
	$section = $query_section->fetchRow();
58
	// Include the modules delete file if it exists
59
	if(file_exists(WB_PATH.'/modules/'.$section['module'].'/delete.php'))
60
    {
61
		require(WB_PATH.'/modules/'.$section['module'].'/delete.php');
62
	}
63
    $sql  = 'DELETE FROM `'.TABLE_PREFIX.'sections` ';
64
    $sql .= 'WHERE `section_id` ='.$section_id.' LIMIT 1';
65
    $query_section = $database->query($sql);
66

    
67
	if($database->is_error())
68
    {
69
		$admin->print_error($database->get_error());
70
	} else {
71
		require(WB_PATH.'/framework/class.order.php');
72
		$order = new order(TABLE_PREFIX.'sections', 'position', 'section_id', 'page_id');
73
		$order->clean($page_id);
74
		$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/sections.php?page_id='.$page_id);
75
		$admin->print_footer();
76
		exit();
77
	}
78
} elseif(isset($_POST['module']) && $_POST['module'] != '')
79
{
80
	// Get section info
81
	$module = $admin->add_slashes($_POST['module']);
82
	// Include the ordering class
83
	require(WB_PATH.'/framework/class.order.php');
84
	// Get new order
85
	$order = new order(TABLE_PREFIX.'sections', 'position', 'section_id', 'page_id');
86
	$position = $order->get_new($page_id);	
87
	// Insert module into DB
88
    $sql  = 'INSERT INTO `'.TABLE_PREFIX.'sections` SET ';
89
    $sql .= '`page_id` = '.$page_id.', ';
90
    $sql .= '`module` = "'.$module.'", ';
91
    $sql .= '`position` = '.$position.', ';
92
    $sql .= '`block`=1';
93
    $database->query($sql);
94
	// Get the section id
95
	$section_id = $database->get_one("SELECT LAST_INSERT_ID()");	
96
	// Include the selected modules add file if it exists
97
	if(file_exists(WB_PATH.'/modules/'.$module.'/add.php'))
98
    {
99
		require(WB_PATH.'/modules/'.$module.'/add.php');
100
	}
101
}
102

    
103
// Get perms
104
// $database = new database();
105
$sql  = 'SELECT `admin_groups`,`admin_users` FROM `'.TABLE_PREFIX.'pages` ';
106
$sql .= 'WHERE `page_id` = '.$page_id;
107
$results = $database->query($sql);
108

    
109
$results_array = $results->fetchRow();
110
$old_admin_groups = explode(',', $results_array['admin_groups']);
111
$old_admin_users = explode(',', $results_array['admin_users']);
112
$in_old_group = FALSE;
113
foreach($admin->get_groups_id() as $cur_gid)
114
{
115
	if (in_array($cur_gid, $old_admin_groups))
116
    {
117
		$in_old_group = TRUE;
118
	}
119
}
120
if((!$in_old_group) && !is_numeric(array_search($admin->get_user_id(), $old_admin_users)))
121
{
122
	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
123
}
124

    
125
// Get page details
126
// $database = new database();
127
$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'pages` ';
128
$sql .= 'WHERE `page_id` = '.$page_id;
129
$results = $database->query($sql);
130

    
131
if($database->is_error())
132
{
133
	// $admin->print_header();
134
	$admin->print_error($database->get_error());
135
}
136
if($results->numRows() == 0)
137
{
138
	// $admin->print_header();
139
	$admin->print_error($MESSAGE['PAGES']['NOT_FOUND']);
140
}
141
$results_array = $results->fetchRow();
142

    
143
// Set module permissions
144
$module_permissions = $_SESSION['MODULE_PERMISSIONS'];
145

    
146
// Unset block var
147
unset($block);
148
// Include template info file (if it exists)
149
if($results_array['template'] != '')
150
{
151
	$template_location = WB_PATH.'/templates/'.$results_array['template'].'/info.php';
152
} else {
153
	$template_location = WB_PATH.'/templates/'.DEFAULT_TEMPLATE.'/info.php';
154
}
155
if(file_exists($template_location))
156
{
157
	require($template_location);
158
}
159
// Check if $menu is set
160
if(!isset($block[1]) OR $block[1] == '')
161
{
162
	// Make our own menu list
163
	$block[1] = $TEXT['MAIN'];
164
}
165

    
166
/*-- load css files with jquery --*/
167
// include jscalendar-setup
168
$jscal_use_time = true; // whether to use a clock, too
169
require_once(WB_PATH."/include/jscalendar/wb-setup.php");
170

    
171
// Setup template object
172
$template = new Template(THEME_PATH.'/templates');
173
$template->set_file('page', 'pages_sections.htt');
174
$template->set_block('page', 'main_block', 'main');
175
$template->set_block('main_block', 'module_block', 'module_list');
176
$template->set_block('main_block', 'section_block', 'section_list');
177
$template->set_block('section_block', 'block_block', 'block_list');
178
$template->set_block('main_block', 'calendar_block', 'calendar_list');
179

    
180
// set first defaults and messages
181
$template->set_var(array(
182
				'PAGE_ID' => $results_array['page_id'],
183
				'PAGE_TITLE' => ($results_array['page_title']),
184
				'MENU_TITLE' => ($results_array['menu_title']),
185
				'TEXT_CURRENT_PAGE' => $TEXT['CURRENT_PAGE'],
186
				'HEADING_MANAGE_SECTIONS' => $HEADING['MANAGE_SECTIONS'],
187
				'HEADING_MODIFY_PAGE' => $HEADING['MODIFY_PAGE'],
188
				'TEXT_CHANGE_SETTINGS' => $TEXT['CHANGE_SETTINGS'],
189
				'TEXT_ADD_SECTION' => $TEXT['ADD_SECTION'],
190
				'TEXT_ID' => 'ID',
191
				'TEXT_TYPE' => $TEXT['TYPE'],
192
				'TEXT_BLOCK' => $TEXT['BLOCK'],
193
				'TEXT_PUBL_START_DATE' => $TEXT{'PUBL_START_DATE'},
194
				'TEXT_PUBL_END_DATE' => $TEXT['PUBL_END_DATE'],
195
				'TEXT_ACTIONS' => $TEXT['ACTIONS'],
196
				'ADMIN_URL' => ADMIN_URL,
197
				'WB_URL' => WB_URL,
198
				'WB_PATH' => WB_PATH,
199
				'THEME_URL' => THEME_URL
200
				) 
201
			);
202

    
203
// Insert variables
204
$template->set_var(array(
205
				'VAR_PAGE_ID' => $results_array['page_id'],
206
				'VAR_PAGE_TITLE' => $results_array['page_title'],
207
				'SETTINGS_LINK' => ADMIN_URL.'/pages/settings.php?page_id='.$results_array['page_id'],
208
				'MODIFY_LINK' => ADMIN_URL.'/pages/modify.php?page_id='.$results_array['page_id']
209
				) 
210
			);
211

    
212
$sql  = 'SELECT `section_id`,`module`,`position`,`block`,`publ_start`,`publ_end` ';
213
$sql .= 'FROM `'.TABLE_PREFIX.'sections` ';
214
$sql .= 'WHERE `page_id` = '.$page_id.' ';
215
$sql .= 'ORDER BY `position` ASC';
216
$query_sections = $database->query($sql);
217

    
218
if($query_sections->numRows() > 0)
219
{
220
	$num_sections = $query_sections->numRows();
221
	while($section = $query_sections->fetchRow())
222
    {
223
		if(!is_numeric(array_search($section['module'], $module_permissions)))
224
        {
225
			// Get the modules real name
226
            $sql = 'SELECT `name` FROM `'.TABLE_PREFIX.'addons` ';
227
            $sql .= 'WHERE `directory` = "'.$section['module'].'"';
228
            $module_name = $database->get_one($sql);
229
            // if(DEBUG && $database->is_error()) { $admin->print_error($database->get_error()); }
230
            $module_tmp = ( trim($module_name) == '' ) ? $section['module'] : $module_name;
231

    
232

    
233
			if(SECTION_BLOCKS)
234
            {
235
                if(defined('EDIT_ONE_SECTION') && EDIT_ONE_SECTION)
236
                {
237
				    $edit_page ='<a name="'.$section['section_id'].'" href="'.ADMIN_URL.'/pages/modify.php?page_id='.$page_id.'&amp;wysiwyg='.$section['section_id'] .'">'.$module_tmp.'</a>';
238
                } else {
239
				    $edit_page ='<a name="'.$section['section_id'].'" href="'.ADMIN_URL.'/pages/modify.php?page_id='.$page_id.'#wb'.$section['section_id'].'">'.$module_tmp.'</a>';
240
                }
241
                $edit_page = ( trim($module_name) == '' ) ? '<span class="module_disabled">'.$section['module'].'</span>' : $edit_page;
242
				$input_attribute = 'input_normal';
243
				$template->set_var(array(
244
						'STYLE_DISPLAY_SECTION_BLOCK' => ' style="visibility:visible;"',
245
						'NAME_SIZE' => 180,
246
						'INPUT_ATTRIBUTE' => $input_attribute,
247
						'VAR_SECTION_ID' => $section['section_id'],
248
						'VAR_POSITION' => $section['position'],
249
						'LINK_MODIFY_URL_VAR_MODUL_NAME' => $edit_page,
250
						'SELECT' => '',
251
						'SET_NONE_DISPLAY_OPTION' => ''
252
						)
253
					);
254
				// Add block options to the section_list
255
				$template->clear_var('block_list');
256
				foreach($block AS $number => $name)
257
                {
258
					$template->set_var('NAME', htmlentities(strip_tags($name)));
259
					$template->set_var('VALUE', $number);
260
					$template->set_var('SIZE', 1);
261
					if($section['block'] == $number)
262
                    {
263
						$template->set_var('SELECTED', ' selected="selected"');
264
					} else {
265
						$template->set_var('SELECTED', '');
266
					}
267
					$template->parse('block_list', 'block_block', true);
268
				}
269
			} else {
270
				$edit_page ='<a name="'.$section['section_id'].'" href="'.ADMIN_URL.'/pages/modify.php?page_id='.$page_id.'#'.$section['section_id'].'">'.$module_tmp.'</a>';
271
                $edit_page = ( trim($module_name) == '' ) ? '<span class="module_disabled">'.$section['module'].'</span>' : $edit_page;
272
				$input_attribute = 'input_small';
273
				$template->set_var(array(
274
						'STYLE_DISPLAY_SECTION_BLOCK' => ' style="display:none;"',
275
						'NAME_SIZE' => 270,
276
						'INPUT_ATTRIBUTE' => $input_attribute,
277
						'VAR_SECTION_ID' => $section['section_id'],
278
						'VAR_POSITION' => $section['position'],
279
						'LINK_MODIFY_URL_VAR_MODUL_NAME' => $edit_page,
280
						'NAME' => htmlentities(strip_tags($block[1])),
281
						'VALUE' => 1,
282
						'SET_NONE_DISPLAY_OPTION' => ''
283
						)
284
					);
285
			}
286
			// Insert icon and images
287
			$template->set_var(array(
288
						'CLOCK_16_PNG' => 'clock_16.png',
289
						'CLOCK_DEL_16_PNG' => 'clock_del_16.png',
290
						'DELETE_16_PNG' => 'delete_16.png'
291
						) 
292
					);
293
			// set calendar start values
294
			if($section['publ_start']==0)
295
            {
296
				$template->set_var('VALUE_PUBL_START', '');
297
			} else {
298
				$template->set_var('VALUE_PUBL_START', date($jscal_format, $section['publ_start']));
299
			}
300
			// set calendar start values
301
			if($section['publ_end']==0)
302
            {
303
				$template->set_var('VALUE_PUBL_END', '');
304
			} else {
305
				$template->set_var('VALUE_PUBL_END', date($jscal_format, $section['publ_end']));
306
			}
307
			// Insert icons up and down
308
			if($section['position'] != 1 )
309
            {
310
				$template->set_var(
311
							'VAR_MOVE_UP_URL',
312
							'<a href="'.ADMIN_URL.'/pages/move_up.php?page_id='.$page_id.'&amp;section_id='.$section['section_id'].'">
313
							<img src="'.THEME_URL.'/images/up_16.png" alt="{TEXT_MOVE_UP}" />
314
							</a>' );
315
			} else {
316
				$template->set_var(array(
317
							'VAR_MOVE_UP_URL' => ''
318
							) 
319
						);
320
			}
321
			if($section['position'] != $num_sections ) {
322
				$template->set_var(
323
							'VAR_MOVE_DOWN_URL',
324
							'<a href="'.ADMIN_URL.'/pages/move_down.php?page_id='.$page_id.'&amp;section_id='.$section['section_id'].'">
325
							<img src="'.THEME_URL.'/images/down_16.png" alt="{TEXT_MOVE_DOWN}" />
326
							</a>' );
327
			} else {
328
				$template->set_var(array(
329
							'VAR_MOVE_DOWN_URL' => ''
330
							) 
331
						);
332
			}
333
		} else {
334
		  continue;
335
		}
336

    
337
			$template->set_var(array(
338
							'DISPLAY_DEBUG' => ' style="visibility="visible;"',
339
							'TEXT_SID' => 'SID',
340
							'DEBUG_COLSPAN_SIZE' => 9
341
							) 
342
						);
343
		if($debug)
344
        {
345
			$template->set_var(array(
346
							'DISPLAY_DEBUG' => ' style="visibility="visible;"',
347
							'TEXT_PID' => 'PID',
348
							'TEXT_SID' => 'SID',
349
							'POSITION' => $section['position']
350
							) 
351
						);
352
		} else {
353
			$template->set_var(array(
354
							'DISPLAY_DEBUG' => ' style="display:none;"',
355
							'TEXT_PID' => '',
356
							'POSITION' => ''
357
							) 
358
						);
359
		}
360
		$template->parse('section_list', 'section_block', true);
361
	}
362
}
363

    
364
// now add the calendars -- remember to to set the range to [1970, 2037] if the date is used as timestamp!
365
// the loop is simply a copy from above.
366
$sql  = 'SELECT `section_id`,`module` FROM `'.TABLE_PREFIX.'sections` ';
367
$sql .= 'WHERE page_id = '.$page_id.' ';
368
$sql .= 'ORDER BY `position` ASC';
369
$query_sections = $database->query($sql);
370

    
371
if($query_sections->numRows() > 0)
372
{
373
	$num_sections = $query_sections->numRows();
374
	while($section = $query_sections->fetchRow())
375
    {
376
		// Get the modules real name
377
        $sql  = 'SELECT `name` FROM `'.TABLE_PREFIX.'addons` ';
378
        $sql .= 'WHERE `directory` = "'.$section['module'].'"';
379
        $module_name = $database->get_one($sql);
380

    
381
		if(!is_numeric(array_search($section['module'], $module_permissions)))
382
        {
383
			$template->set_var(array(
384
						'jscal_ifformat' => $jscal_ifformat,
385
						'jscal_firstday' => $jscal_firstday,
386
						'jscal_today' => $jscal_today,
387
						'start_date' => 'start_date'.$section['section_id'],
388
						'end_date' => 'end_date'.$section['section_id'],
389
						'trigger_start' => 'trigger_start'.$section['section_id'],
390
						'trigger_end' => 'trigger_stop'.$section['section_id']
391
						) 
392
					);
393
			if(isset($jscal_use_time) && $jscal_use_time==TRUE) {
394
				$template->set_var(array(
395
						'showsTime' => "true",
396
						'timeFormat' => "24"
397
						) 
398
					);
399
			}  else {
400
				$template->set_var(array(
401
						'showsTime' => "false",
402
						'timeFormat' => "24"
403
						) 
404
					);
405
			}
406
		}
407
		$template->parse('calendar_list', 'calendar_block', true);
408
	}
409
}
410

    
411
// Work-out if we should show the "Add Section" form
412
$sql  = 'SELECT `section_id` FROM `'.TABLE_PREFIX.'sections` ';
413
$sql .= 'WHERE `page_id` = '.$page_id.' AND `module` = "menu_link"';
414
$query_sections = $database->query($sql);
415
if($query_sections->numRows() == 0)
416
{
417
	// Modules list
418
    $sql  = 'SELECT `name`,`directory`,`type` FROM `'.TABLE_PREFIX.'addons` ';
419
    $sql .= 'WHERE `type` = "module" AND `function` = "page" AND `directory` != "menu_link" ';
420
    $sql .= 'ORDER BY `name`';
421
    $result = $database->query($sql);
422
// if(DEBUG && $database->is_error()) { $admin->print_error($database->get_error()); }
423

    
424
	if($result->numRows() > 0)
425
    {
426
		while ($module = $result->fetchRow())
427
        {
428
			// Check if user is allowed to use this module   echo  $module['directory'],'<br />';
429
			if(!is_numeric(array_search($module['directory'], $module_permissions)))
430
            {
431
				$template->set_var('VALUE', $module['directory']);
432
				$template->set_var('NAME', $module['name']);
433
				if($module['directory'] == 'wysiwyg')
434
                {
435
					$template->set_var('SELECTED', ' selected="selected"');
436
				} else {
437
					$template->set_var('SELECTED', '');
438
				}
439
				$template->parse('module_list', 'module_block', true);
440
			} else {
441
			  continue;
442
			}
443
		}
444
	}
445
}
446
// Insert language text and messages
447
$template->set_var(array(
448
					'TEXT_MANAGE_SECTIONS' => $HEADING['MANAGE_SECTIONS'],
449
					'TEXT_ARE_YOU_SURE' => $TEXT['ARE_YOU_SURE'],
450
					'TEXT_TYPE' => $TEXT['TYPE'],
451
					'TEXT_ADD' => $TEXT['ADD'],
452
					'TEXT_SAVE' =>  $TEXT['SAVE'],
453
					'TEXTLINK_MODIFY_PAGE' => $HEADING['MODIFY_PAGE'],
454
					'TEXT_CALENDAR' => $TEXT['CALENDAR'],
455
					'TEXT_DELETE_DATE' => $TEXT['DELETE_DATE'],
456
					'TEXT_ADD_SECTION' => $TEXT['ADD_SECTION'],
457
					'TEXT_MOVE_UP' => $TEXT['MOVE_UP'],
458
					'TEXT_MOVE_DOWN' => $TEXT['MOVE_DOWN']
459
					)
460
				);
461
$template->parse('main', 'main_block', false);
462
$template->pparse('output', 'page');
463

    
464
// Print admin footer
465
$admin->print_footer();
466

    
467
?>
(17-17/21)