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

Last change on this file since 30219 was 29634, checked in by mistic100, 10 years ago

don't change banner to last uploaded

File size: 3.9 KB
Line 
1<?php
2defined('HEADER_MANAGER_PATH') or 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  $conf['header_manager']['keep_ratio'] = isset($_POST['keep_ratio']);
17  conf_update_param('header_manager', $conf['header_manager']);
18 
19  $banner = get_banner($_POST['picture_file']);
20 
21  $img = new banner_image($banner['PATH']);
22  $img->banner_resize(
23    $banner['PATH'],
24    $_POST
25    );
26  $img->destroy();
27 
28  $img = new pwg_image($banner['PATH']);
29  $img->pwg_resize(
30    $banner['THUMB'],
31    230, 70, 80,
32    false, true, true, false
33    );
34  $img->destroy();
35 
36  $_SESSION['page_infos'][] = l10n('Banner added');
37 
38  if (!empty($_GET['redirect']))
39  {
40    redirect($_GET['redirect']);
41  }
42  else
43  {
44    redirect(HEADER_MANAGER_ADMIN);
45  }
46}
47
48// copy picture from gallery
49if (isset($_POST['upload_gallery_image']))
50{
51  $query = '
52SELECT
53    file,
54    path,
55    coi,
56    width,
57    height
58  FROM '.IMAGES_TABLE.'
59  WHERE id = '. (int)@$_POST['picture_id'] .'
60;';
61  $result = pwg_query($query);
62 
63  if (!pwg_db_num_rows($result))
64  {
65    $page['errors'][] = l10n('Unknown picture id');
66  }
67  else
68  {
69    $picture = pwg_db_fetch_assoc($result);
70    $picture['filename'] = basename($picture['path']);
71   
72    copy(PHPWG_ROOT_PATH . $picture['path'], HEADER_MANAGER_DIR . $picture['filename']);
73   
74    define('IN_CROP', true);
75  }
76}
77// upload new picture
78else if (isset($_POST['upload_new_image']))
79{
80  $file = $_FILES['new_image'];
81 
82  if ($file['error'] > 0) 
83  {
84    $page['errors'][] = l10n('Unknown upload error');
85  }
86  else if (!in_array($file['type'], array('image/jpeg','image/png','image/gif')))
87  {
88    $page['errors'][] = l10n('Incorrect file type,').' '.l10n('Allowed file types: %s.', 'jpg, png, gif');
89  }
90 
91  if (count($page['errors']) == 0)
92  {
93    $file['filename'] = date('Ymd').'-'.uniqid().'.'.get_extension($file['name']);
94    move_uploaded_file($file['tmp_name'], HEADER_MANAGER_DIR . $file['filename']);
95   
96    list($width, $height) = getimagesize(HEADER_MANAGER_DIR . $file['filename']);
97    $picture = array(
98      'file' => $file['name'],
99      'filename' => $file['filename'],
100      'width' => $width,
101      'height' => $height,
102      );
103     
104    define('IN_CROP', true);
105  }
106}
107
108// croping template
109if (defined('IN_CROP'))
110{
111  // save default size configuration
112  $conf['header_manager']['width'] = intval($_POST['width']);
113  $conf['header_manager']['height'] = intval($_POST['height']);
114  conf_update_param('header_manager', $conf['header_manager']);
115
116  $picture['banner_src'] = HEADER_MANAGER_DIR . $picture['filename'];
117 
118  $template->assign(array(
119    'IN_CROP' => true,
120    'picture' => $picture,
121    'crop' => hm_get_crop_display($picture),
122    'keep_ratio' => $conf['header_manager']['keep_ratio'],
123    ));
124}
125// upload form
126else
127{
128  include_once(PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php');
129 
130  $upload_max_filesize = min(
131    get_ini_size('upload_max_filesize'),
132    get_ini_size('post_max_size')
133    );
134   
135  $upload_max_filesize_shorthand = 
136    ($upload_max_filesize == get_ini_size('upload_max_filesize')) ?
137    get_ini_size('upload_max_filesize', false) :
138    get_ini_size('post_max_filesize', false);
139   
140  $template->assign(array(
141    'upload_max_filesize' => $upload_max_filesize,
142    'upload_max_filesize_shorthand' => $upload_max_filesize_shorthand,
143    'BANNER_WIDTH' => $conf['header_manager']['width'],
144    'BANNER_HEIGHT' => $conf['header_manager']['height'],
145    ));
146}
147
148$template->assign('F_ACTION', HEADER_MANAGER_ADMIN . '-add' .
149  (!empty($_GET['redirect']) ? '&amp;redirect='.urlencode($_GET['redirect']) : ''));
150
151$template->set_filename('header_manager', realpath(HEADER_MANAGER_PATH . 'admin/template/add.tpl'));
Note: See TracBrowser for help on using the repository browser.