source: extensions/upload_form/upload.php @ 4806

Last change on this file since 4806 was 4806, checked in by plg, 14 years ago

feature 1407: don't display the privacy level id in the form

File size: 5.8 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2010      Pierrick LE GALL             http://piwigo.org |
6// +-----------------------------------------------------------------------+
7// | This program is free software; you can redistribute it and/or modify  |
8// | it under the terms of the GNU General Public License as published by  |
9// | the Free Software Foundation                                          |
10// |                                                                       |
11// | This program is distributed in the hope that it will be useful, but   |
12// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
13// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
14// | General Public License for more details.                              |
15// |                                                                       |
16// | You should have received a copy of the GNU General Public License     |
17// | along with this program; if not, write to the Free Software           |
18// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
19// | USA.                                                                  |
20// +-----------------------------------------------------------------------+
21
22if( !defined("PHPWG_ROOT_PATH") )
23{
24  die ("Hacking attempt!");
25}
26
27include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
28include_once(UPLOAD_FORM_PATH.'include/functions_upload.inc.php');
29load_language('plugin.lang', UPLOAD_FORM_PATH);
30
31$admin_base_url = get_root_url().'admin.php?page=plugin&section=upload_form%2Fupload.php';
32
33// +-----------------------------------------------------------------------+
34// | Check Access and exit when user status is not ok                      |
35// +-----------------------------------------------------------------------+
36check_status(ACCESS_ADMINISTRATOR);
37
38// +-----------------------------------------------------------------------+
39// |                             process form                              |
40// +-----------------------------------------------------------------------+
41
42if (isset($_POST['submit_upload']))
43{
44  $category_id = null;
45  if ('existing' == $_POST['category_type'])
46  {
47    $category_id = $_POST['category'];
48  }
49  elseif ('new' == $_POST['category_type'])
50  {
51    $output_create = create_virtual_category(
52      $_POST['category_name'],
53      (0 == $_POST['category_parent'] ? null : $_POST['category_parent'])
54      );
55
56    if (isset($output_create['error']))
57    {
58      array_push($page['errors'], $output_create['error']);
59    }
60    else
61    {
62      // information
63      array_push(
64        $page['infos'],
65        sprintf(
66          l10n('Category "%s" has been added'),
67          '<em>'.get_cat_display_name_from_id($output_create['id']).'</em>'
68          )
69        );
70    }
71
72    $category_id = $output_create['id'];
73  }
74 
75  $starttime = get_moment();
76 
77  foreach ($_FILES['image_upload']['error'] as $idx => $error)
78  {
79    if (UPLOAD_ERR_OK == $error)
80    {
81      $source_filepath = $_FILES['image_upload']['tmp_name'][$idx];
82      $original_filename = $_FILES['image_upload']['name'][$idx];
83      add_uploaded_file($source_filepath, $original_filename, array($category_id), $_POST['level']);
84    }
85  }
86 
87  $endtime = get_moment();
88  $elapsed = ($endtime - $starttime) * 1000;
89  // printf('%.2f ms', $elapsed);
90}
91
92// +-----------------------------------------------------------------------+
93// |                             template init                             |
94// +-----------------------------------------------------------------------+
95
96$template->set_filenames(
97  array(
98    'plugin_admin_content' => dirname(__FILE__).'/upload.tpl'
99    )
100  );
101
102$template->assign(
103    array(
104      'F_ADD_ACTION'=> $admin_base_url,
105      'plugin_path' => UPLOAD_FORM_PATH,
106    )
107  );
108
109$query = '
110SELECT id,name,uppercats,global_rank
111  FROM '.CATEGORIES_TABLE.'
112;';
113
114display_select_cat_wrapper(
115  $query,
116  array(),
117  'category_options'
118  );
119
120// image level options
121$tpl_options = array();
122foreach ($conf['available_permission_levels'] as $level)
123{
124  $tpl_options[$level] = l10n( sprintf('Level %d', $level) );
125}
126$selected_level = isset($_POST['level']) ? $_POST['level'] : 0;
127$template->assign(
128    array(
129      'level_options'=> $tpl_options,
130      'level_options_selected' => array($selected_level)
131    )
132  );
133
134
135// +-----------------------------------------------------------------------+
136// |                             setup errors                              |
137// +-----------------------------------------------------------------------+
138
139$setup_errors = array();
140
141$upload_base_dir = 'upload';
142$upload_dir = PHPWG_ROOT_PATH.$upload_base_dir;
143
144if (!is_dir($upload_dir))
145{
146  if (!is_writable(PHPWG_ROOT_PATH))
147  {
148    array_push(
149      $setup_errors,
150      sprintf(
151        l10n('Create the "%s" directory at the root of your Piwigo installation'),
152        $upload_base_dir
153        )
154      );
155  }
156}
157else
158{
159  if (!is_writable($upload_dir))
160  {
161    @chmod($upload_dir, 0777);
162
163    if (!is_writable($upload_dir))
164    {
165      array_push(
166        $setup_errors,
167        sprintf(
168          l10n('Give write access (chmod 777) to "%s" directory at the root of your Piwigo installation'),
169          $upload_base_dir
170          )
171        );
172    }
173  }
174}
175
176$template->assign(
177    array(
178      'setup_errors'=> $setup_errors,
179    )
180  );
181
182// +-----------------------------------------------------------------------+
183// |                           sending html code                           |
184// +-----------------------------------------------------------------------+
185
186$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
187?>
Note: See TracBrowser for help on using the repository browser.