$user['id'], 'element_id' => $image_id, ) ); } mass_inserts( CADDIE_TABLE, array_keys($inserts[0]), $inserts ); redirect(get_root_url().'admin.php?page=element_set&cat=caddie'); } // +-----------------------------------------------------------------------+ // | process form | // +-----------------------------------------------------------------------+ if (isset($_POST['submit_upload'])) { $category_id = null; if ('existing' == $_POST['category_type']) { $category_id = $_POST['category']; } elseif ('new' == $_POST['category_type']) { $output_create = create_virtual_category( $_POST['category_name'], (0 == $_POST['category_parent'] ? null : $_POST['category_parent']) ); $category_id = $output_create['id']; if (isset($output_create['error'])) { array_push($page['errors'], $output_create['error']); } else { $category_name = get_cat_display_name_from_id($category_id, 'admin.php?page=cat_modify&cat_id='); // information array_push( $page['infos'], sprintf( l10n('Category "%s" has been added'), ''.$category_name.'' ) ); // TODO: add the onclick="window.open(this.href); return false;" // attribute with jQuery on upload.tpl side for href containing // "cat_modify" } } $image_ids = array(); $page['thumbnails'] = array(); $starttime = get_moment(); foreach ($_FILES['image_upload']['error'] as $idx => $error) { if (UPLOAD_ERR_OK == $error) { $source_filepath = $_FILES['image_upload']['tmp_name'][$idx]; $original_filename = $_FILES['image_upload']['name'][$idx]; $image_id = add_uploaded_file( $source_filepath, $original_filename, array($category_id), $_POST['level'] ); array_push($image_ids, $image_id); // TODO: if $image_id is not an integer, something went wrong // we could return the list of properties from the add_uploaded_file // function, but I like the "double check". And it costs nothing // compared to the upload process. $thumbnail = array(); $query = ' SELECT file, path, tn_ext FROM '.IMAGES_TABLE.' WHERE id = '.$image_id.' ;'; $image_infos = mysql_fetch_assoc(pwg_query($query)); $thumbnail['file'] = $image_infos['file']; $thumbnail['src'] = get_thumbnail_location( array( 'path' => $image_infos['path'], 'tn_ext' => $image_infos['tn_ext'], ) ); // TODO: when implementing this plugin in Piwigo core, we should have // a function get_image_name($name, $file) (if name is null, then // compute a temporary name from filename) that would be also used in // picture.php. UPDATE: in fact, "get_name_from_file($file)" already // exists and is used twice (element_set_unit + comments, but not in // picture.php I don't know why) with the same pattern if // (empty($name)) {$name = get_name_from_file($file)}, a clean // function get_image_name($name, $file) would be better $thumbnail['title'] = get_name_from_file($image_infos['file']); $thumbnail['link'] = PHPWG_ROOT_PATH.'admin.php?page=picture_modify' .'&image_id='.$image_id .'&cat_id='.$category_id ; array_push($page['thumbnails'], $thumbnail); } } $endtime = get_moment(); $elapsed = ($endtime - $starttime) * 1000; // printf('%.2f ms', $elapsed); if (!empty($page['thumbnails'])) { array_push( $page['infos'], sprintf( l10n('%d photos uploaded'), count($page['thumbnails']) ) ); if (0 != $_POST['level']) { array_push( $page['infos'], sprintf( l10n('Privacy level set to "%s"'), l10n( sprintf('Level %d', $_POST['level']) ) ) ); } if ('existing' == $_POST['category_type']) { $query = ' SELECT COUNT(*) FROM '.IMAGE_CATEGORY_TABLE.' WHERE category_id = '.$category_id.' ;'; list($count) = mysql_fetch_row(pwg_query($query)); $category_name = get_cat_display_name_from_id($category_id, 'admin.php?page=cat_modify&cat_id='); // information array_push( $page['infos'], sprintf( l10n('Category "%s" now contains %d photos'), ''.$category_name.'', $count ) ); } $page['batch_link'] = $admin_base_url.'&batch='.implode(',', $image_ids); } } // +-----------------------------------------------------------------------+ // | template init | // +-----------------------------------------------------------------------+ $template->set_filenames( array( 'plugin_admin_content' => dirname(__FILE__).'/upload.tpl' ) ); $template->assign( array( 'F_ADD_ACTION'=> $admin_base_url, 'plugin_path' => UPLOAD_FORM_PATH, ) ); if (isset($page['thumbnails'])) { $template->assign( array( 'thumbnails' => $page['thumbnails'], ) ); // only display the batch link if we have more than 1 photo if (count($page['thumbnails']) > 1) { $template->assign( array( 'batch_link' => $page['batch_link'], 'batch_label' => sprintf( l10n('Manage this set of %d photos'), count($page['thumbnails']) ), ) ); } } $query = ' SELECT id,name,uppercats,global_rank FROM '.CATEGORIES_TABLE.' ;'; display_select_cat_wrapper( $query, array(), 'category_options' ); // image level options $tpl_options = array(); foreach ($conf['available_permission_levels'] as $level) { $tpl_options[$level] = l10n( sprintf('Level %d', $level) ); } $selected_level = isset($_POST['level']) ? $_POST['level'] : 0; $template->assign( array( 'level_options'=> $tpl_options, 'level_options_selected' => array($selected_level) ) ); // +-----------------------------------------------------------------------+ // | setup errors | // +-----------------------------------------------------------------------+ $setup_errors = array(); $upload_base_dir = 'upload'; $upload_dir = PHPWG_ROOT_PATH.$upload_base_dir; if (!is_dir($upload_dir)) { if (!is_writable(PHPWG_ROOT_PATH)) { array_push( $setup_errors, sprintf( l10n('Create the "%s" directory at the root of your Piwigo installation'), $upload_base_dir ) ); } } else { if (!is_writable($upload_dir)) { @chmod($upload_dir, 0777); if (!is_writable($upload_dir)) { array_push( $setup_errors, sprintf( l10n('Give write access (chmod 777) to "%s" directory at the root of your Piwigo installation'), $upload_base_dir ) ); } } } $template->assign( array( 'setup_errors'=> $setup_errors, ) ); // +-----------------------------------------------------------------------+ // | sending html code | // +-----------------------------------------------------------------------+ $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); ?>