source: extensions/upload_form/upload.php @ 4802

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

feature 1406 added: Upload Form is able to create a category "on the fly".

Note: needs a better display when switching from "existing" to "new" category.

File size: 5.4 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));
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// +-----------------------------------------------------------------------+
121// |                             setup errors                              |
122// +-----------------------------------------------------------------------+
123
124$setup_errors = array();
125
126$upload_base_dir = 'upload';
127$upload_dir = PHPWG_ROOT_PATH.$upload_base_dir;
128
129if (!is_dir($upload_dir))
130{
131  if (!is_writable(PHPWG_ROOT_PATH))
132  {
133    array_push(
134      $setup_errors,
135      sprintf(
136        l10n('Create the "%s" directory at the root of your Piwigo installation'),
137        $upload_base_dir
138        )
139      );
140  }
141}
142else
143{
144  if (!is_writable($upload_dir))
145  {
146    @chmod($upload_dir, 0777);
147
148    if (!is_writable($upload_dir))
149    {
150      array_push(
151        $setup_errors,
152        sprintf(
153          l10n('Give write access (chmod 777) to "%s" directory at the root of your Piwigo installation'),
154          $upload_base_dir
155          )
156        );
157    }
158  }
159}
160
161$template->assign(
162    array(
163      'setup_errors'=> $setup_errors,
164    )
165  );
166
167// +-----------------------------------------------------------------------+
168// |                           sending html code                           |
169// +-----------------------------------------------------------------------+
170
171$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
172?>
Note: See TracBrowser for help on using the repository browser.