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

Last change on this file since 24010 was 24010, checked in by mistic100, 11 years ago

"Add banner" in album page make the user redirected to the same page after cropping

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