Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        modules
5
 * @package         news
6
 * @author          WebsiteBaker Project
7
 * @copyright       2009-2011, Website Baker Org. e.V.
8
 * @link			http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11
 * @requirements    PHP 5.2.2 and higher
12
 * @version         $Id: save_group.php 1538 2011-12-10 15:06:15Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/news/save_group.php $
14
 * @lastmodified    $Date: 2011-12-10 16:06:15 +0100 (Sat, 10 Dec 2011) $
15
 *
16
 */
17

    
18
require('../../config.php');
19

    
20
// Get id
21
if(!isset($_POST['group_id']) OR !is_numeric($_POST['group_id']))
22
{
23
	header("Location: ".ADMIN_URL."/pages/index.php");
24
	exit( 0 );
25
}
26
else
27
{
28
	$group_id = $_POST['group_id'];
29
}
30

    
31
$admin_header = false;
32
// Tells script to update when this page was last updated
33
$update_when_modified = true;
34
// Include WB admin wrapper script
35
require(WB_PATH.'/modules/admin.php');
36

    
37
if (!$admin->checkFTAN())
38
{
39
	$admin->print_header();
40
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
41
}
42
$admin->print_header();
43

    
44
// Include WB functions file
45
require(WB_PATH.'/framework/functions.php');
46

    
47
// Validate all fields
48
if($admin->get_post('title') == '')
49
{
50
	$admin->print_error($MESSAGE['GENERIC']['FILL_IN_ALL'], WB_URL.'/modules/news/modify_group.php?page_id='.$page_id.'&section_id='.$section_id.'&group_id='.$admin->getIDKEY($group_id));
51
}
52
else
53
{
54
	$title = $admin->get_post_escaped('title');
55
	$active = $admin->get_post_escaped('active');
56
}
57

    
58
// Update row
59
$database->query("UPDATE ".TABLE_PREFIX."mod_news_groups SET title = '$title', active = '$active' WHERE group_id = '$group_id'");
60

    
61
// Check if the user uploaded an image or wants to delete one
62
if(isset($_FILES['image']['tmp_name']) AND $_FILES['image']['tmp_name'] != '') {
63
	// Get real filename and set new filename
64
	$filename = $_FILES['image']['name'];
65
	$file_image_type = $_FILES['image']['type'];
66
	$new_filename = WB_PATH.MEDIA_DIRECTORY.'/.news/image'.$group_id.'.jpg';
67
	// Make sure the image is a jpg file
68
	$file4=substr($filename, -4, 4);
69

    
70
	switch ($file_image_type) :
71
		case 'image/jpeg' :
72
		case 'image/pjpeg' :
73
		case 'image/png' :
74
		case 'image/x-png' :
75
		break;
76
		default:
77
			$admin->print_error($MESSAGE['GENERIC']['FILE_TYPE'].' JPG (JPEG) or PNG',ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
78
		break;
79
	endswitch;
80

    
81
/*
82
	if(($file4 != '.jpg')and($file4 != '.JPG')and($file4 != '.png')and($file4 != '.PNG') and ($file4 !='jpeg') and ($file4 != 'JPEG'))
83
    {
84
		$admin->print_error($MESSAGE['GENERIC']['FILE_TYPE'].' JPG (JPEG) or PNG',ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
85
	} elseif(
86
	(($_FILES['image']['type']) != 'image/jpeg' AND mime_content_type($_FILES['image']['tmp_name']) != 'image/jpg')
87
	and
88
	(($_FILES['image']['type']) != 'image/png' AND mime_content_type($_FILES['image']['tmp_name']) != 'image/png')
89
	){
90
		$admin->print_error($MESSAGE['GENERIC']['FILE_TYPE'].' JPG (JPEG) or PNG',ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
91
	}
92
*/
93

    
94
	// Make sure the target directory exists
95
	make_dir(WB_PATH.MEDIA_DIRECTORY.'/.news');
96
	// Upload image
97
	move_uploaded_file($_FILES['image']['tmp_name'], $new_filename);
98
	// Check if we need to create a thumb
99
	$query_settings = $database->query("SELECT resize FROM ".TABLE_PREFIX."mod_news_settings WHERE section_id = '$section_id'");
100
	$fetch_settings = $query_settings->fetchRow();
101
	$resize = $fetch_settings['resize'];
102
	if($resize != 0)
103
    {
104
		// Resize the image
105
		$thumb_location = WB_PATH.MEDIA_DIRECTORY.'/.news/thumb'.$group_id.'.jpg';
106
		if(make_thumb($new_filename, $thumb_location, $resize))
107
        {
108
			// Delete the actual image and replace with the resized version
109
			unlink($new_filename);
110
			rename($thumb_location, $new_filename);
111
		}
112
	}
113
}
114
if(isset($_POST['delete_image']) AND $_POST['delete_image'] != '')
115
{
116
	// Try unlinking image
117
	if(file_exists(WB_PATH.MEDIA_DIRECTORY.'/.news/image'.$group_id.'.jpg'))
118
    {
119
		unlink(WB_PATH.MEDIA_DIRECTORY.'/.news/image'.$group_id.'.jpg');
120
	}
121
}
122

    
123
// Check if there is a db error, otherwise say successful
124
if($database->is_error()) {
125
	$admin->print_error($database->get_error(), WB_URL.'/modules/news/modify_group.php?page_id='.$page_id.'&section_id='.$section_id.'&group_id='.$admin->getIDKEY($group_id));
126
} else {
127
	$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
128
}
129

    
130
// Print admin footer
131
$admin->print_footer();
(26-26/33)