source: extensions/header_manager/admin/add.php @ 15854

Last change on this file since 15854 was 15854, checked in by mistic100, 12 years ago

initial release

File size: 3.6 KB
Line 
1<?php
2if (!defined('HEADER_MANAGER_PATH')) die('Hacking attempt!');
3
4// cancel crop
5if (isset($_POST['cancel_crop']))
6{
7  $banner = get_banner($_POST['picture_file']);
8  @unlink($banner['PATH']);
9  @unlink($banner['THUMB']);
10}
11// apply crop and redirect
12else if (isset($_POST['submit_crop']))
13{
14  include_once(HEADER_MANAGER_PATH . 'include/banner.class.php');
15 
16  $banner = get_banner($_POST['picture_file']);
17  $img = new banner_image($banner['PATH']);
18  $crop = get_crop_display(array('width'=>$img->get_width(), 'height'=>$img->get_height()));
19 
20  $img->banner_resize(
21    $banner['PATH'],
22    $_POST['x'],
23    $_POST['y'], 
24    $_POST['x2'],
25    $_POST['y2'],
26    $crop['display_width'],
27    $crop['display_height']
28    );
29  $img->destroy();
30 
31  $img = new banner_image($banner['PATH']);
32  $img->pwg_resize(
33    $banner['THUMB'],
34    230, 70, 80,
35    false, true, true, false
36    );
37  $img->destroy();
38 
39  $_SESSION['page_infos'][] = l10n('Banner added');
40  pwg_set_session_var('added_banner', $_POST['picture_file']);
41 
42  redirect(HEADER_MANAGER_ADMIN);
43}
44
45// copy picture from gallery
46if (isset($_POST['upload_gallery_image']))
47{
48  $query = '
49SELECT
50    file,
51    path,
52    coi,
53    width,
54    height
55  FROM '.IMAGES_TABLE.'
56  WHERE id = '. (int)@$_POST['picture_id'] .'
57;';
58  $result = pwg_query($query);
59 
60  if (!pwg_db_num_rows($result))
61  {
62    array_push($page['errors'], l10n('Unknown picture id'));
63  }
64  else
65  {
66    $picture = pwg_db_fetch_assoc($result);
67   
68    copy(PHPWG_ROOT_PATH . $picture['path'], HEADER_MANAGER_DIR . $picture['file']);
69   
70    define('IN_CROP', true);
71  }
72}
73// upload new picture
74else if (isset($_POST['upload_new_image']))
75{
76  $file = $_FILES['new_image'];
77 
78  if ($file['error'] > 0) 
79  {
80    array_push($page['errors'], l10n('Unknown upload error'));
81  }
82  else if ( !in_array($file['type'], array('image/jpeg','image/png','image/gif')) )
83  {
84    array_push($page['errors'], l10n('Incorrect file type,').' '.sprintf(l10n('Allowed file types: %s.'), 'jpg, png, gif'));
85  }
86 
87  if (count($page['errors']) == 0)
88  {
89    move_uploaded_file($file['tmp_name'], HEADER_MANAGER_DIR . $file['name']);
90   
91    list($width, $height) = getimagesize(HEADER_MANAGER_DIR . $file['name']);
92    $picture = array(
93      'file' => $file['name'],
94      'width' => $width,
95      'height' => $height,
96      );
97     
98    define('IN_CROP', true);
99  }
100}
101
102// croping template
103if (defined('IN_CROP'))
104{
105  // save default size configuration
106  $conf['header_manager']['width'] = intval($_POST['width']);
107  $conf['header_manager']['height'] = intval($_POST['height']);
108  conf_update_param('header_manager', serialize($conf['header_manager']));
109   
110  $picture['banner_src'] = HEADER_MANAGER_DIR . $picture['file'];
111 
112  $template->assign(array(
113    'IN_CROP' => true,
114    'picture' => $picture,
115    'crop' => get_crop_display($picture),
116    ));
117}
118// upload form
119else
120{
121  include_once(PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php');
122 
123  $upload_max_filesize = min(
124    get_ini_size('upload_max_filesize'),
125    get_ini_size('post_max_size')
126    );
127   
128  $upload_max_filesize_shorthand = 
129    ($upload_max_filesize == get_ini_size('upload_max_filesize')) ?
130    get_ini_size('upload_max_filesize', false) :
131    get_ini_size('post_max_filesize', false);
132   
133  $template->assign(array(
134    'upload_max_filesize' => $upload_max_filesize,
135    'upload_max_filesize_shorthand' => $upload_max_filesize_shorthand,
136    'BANNER_WIDTH' => $conf['header_manager']['width'],
137    'BANNER_HEIGHT' => $conf['header_manager']['height'],
138    ));
139}
140
141$template->set_filename('header_manager', dirname(__FILE__).'/template/add.tpl');
142
143?>
Note: See TracBrowser for help on using the repository browser.