Exemplo n.º 1
0
function _wppa_page_import()
{
    global $wppa_revno;
    global $wpdb;
    global $wppa_supported_photo_extensions;
    global $wppa_supported_video_extensions;
    global $wppa_supported_audio_extensions;
    global $wppa_session;
    if (wppa('ajax')) {
        ob_start();
    }
    // Suppress output if ajax operation
    // Init
    $ngg_opts = get_option('ngg_options', false);
    $user = wppa_get_user();
    // Check database
    wppa_check_database(true);
    // Update watermark settings for the user if new values supplied
    if (wppa_switch('watermark_on') && (wppa_switch('watermark_user') || current_user_can('wppa_settings'))) {
        // File
        if (isset($_POST['wppa-watermark-file'])) {
            // Sanitize input
            $watermark_file = $_POST['wppa-watermark-file'];
            if (stripos($watermark_file, '.png') !== false) {
                $watermark_file = sanitize_file_name($watermark_file);
            } else {
                if (!in_array($watermark_file, array('--- none ---', '---name---', '---filename---', '---description---', '---predef---'))) {
                    $watermark_file = 'nil';
                }
            }
            // Update setting
            update_option('wppa_watermark_file_' . $user, $watermark_file);
        }
        // Position
        if (isset($_POST['wppa-watermark-pos'])) {
            // Sanitize input
            $watermark_pos = $_POST['wppa-watermark-pos'];
            if (!in_array($watermark_pos, array('toplft', 'topcen', 'toprht', 'cenlft', 'cencen', 'cenrht', 'botlft', 'botcen', 'botrht'))) {
                $watermark_pos = 'nil';
            }
            // Update setting
            update_option('wppa_watermark_pos_' . $user, $watermark_pos);
        }
    }
    // Update last used albums
    if (isset($_POST['wppa-photo-album'])) {
        update_option('wppa-photo-album-import-' . wppa_get_user(), strval(intval($_POST['wppa-photo-album'])));
    }
    if (isset($_POST['wppa-video-album'])) {
        update_option('wppa-video-album-import-' . wppa_get_user(), strval(intval($_POST['wppa-video-album'])));
    }
    if (isset($_POST['wppa-audio-album'])) {
        update_option('wppa-audio-album-import-' . wppa_get_user(), strval(intval($_POST['wppa-audio-album'])));
    }
    // Verify last albums still exist
    $alb = get_option('wppa-photo-album-import-' . wppa_get_user(), '0');
    if ($alb) {
        $exists = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_ALBUMS . "` WHERE `id` = %s", $alb));
        if (!$exists) {
            update_option('wppa-photo-album-import-' . wppa_get_user(), '0');
        }
    }
    $alb = get_option('wppa-video-album-import-' . wppa_get_user(), '0');
    if ($alb) {
        $exists = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_ALBUMS . "` WHERE `id` = %s", $alb));
        if (!$exists) {
            update_option('wppa-video-album-import-' . wppa_get_user(), '0');
        }
    }
    $alb = get_option('wppa-audio-album-import-' . wppa_get_user(), '0');
    if ($alb) {
        $exists = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_ALBUMS . "` WHERE `id` = %s", $alb));
        if (!$exists) {
            update_option('wppa-audio-album-import-' . wppa_get_user(), '0');
        }
    }
    // Extract zip
    if (isset($_GET['zip'])) {
        wppa_extract($_GET['zip'], true);
    }
    // Set local / remote
    if (isset($_POST['wppa-local-remote']) && in_array($_POST['wppa-local-remote'], array('local', 'remote'))) {
        check_admin_referer('$wppa_nonce', WPPA_NONCE);
        update_option('wppa_import_source_type_' . $user, $_POST['wppa-local-remote']);
    }
    // Set import source dir ( when local )
    if (isset($_POST['wppa-import-set-source-dir']) && is_dir($_POST['wppa-source'])) {
        check_admin_referer('$wppa_nonce', WPPA_NONCE);
        if (isset($_POST['wppa-source'])) {
            update_option('wppa_import_source_' . $user, $_POST['wppa-source']);
        }
    }
    // Set import source url ( when remote )
    if (isset($_POST['wppa-import-set-source-url'])) {
        check_admin_referer('$wppa_nonce', WPPA_NONCE);
        if (isset($_POST['wppa-source-remote'])) {
            update_option('wppa_import_source_url_' . $user, esc_url($_POST['wppa-source-remote']));
            update_option('wppa_import_source_url_found_' . $user, false);
            update_option('wppa_import_remote_max_' . $user, strval(intval($_POST['wppa-import-remote-max'])));
        }
    }
    // Hit the submit button
    if (isset($_POST['wppa-import-submit'])) {
        if (wppa('ajax')) {
            if (!wp_verify_nonce($_POST['wppa-update-check'], '$wppa_nonce')) {
                echo $_POST['wppa-update-check'] . ' Security check failure';
                wppa_exit();
            }
        } else {
            check_admin_referer('$wppa_nonce', WPPA_NONCE);
        }
        $delp = isset($_POST['del-after-p']);
        $delf = isset($_POST['del-after-f']);
        $dela = isset($_POST['del-after-a']);
        $delz = isset($_POST['del-after-z']);
        $delv = isset($_POST['del-after-v']);
        $delu = isset($_POST['del-after-u']);
        $delc = isset($_POST['del-after-c']);
        wppa_import_photos($delp, $dela, $delz, $delv, $delu, $delc, $delf);
    } elseif (isset($_GET['continue'])) {
        if (wp_verify_nonce($_GET['nonce'], 'dirimport')) {
            wppa_import_photos();
        }
    }
    // If we did this by ajax, setup reporting results for it
    if (wppa('ajax')) {
        ob_end_clean();
        if (wppa('ajax_import_files_done')) {
            echo '<span style="color:green" >' . wppa('ajax_import_files') . ' ' . __('Done!', 'wp-photo-album-plus') . '</span>';
        } elseif (wppa('ajax_import_files_error')) {
            echo '<span style="color:red" >' . wppa('ajax_import_files') . ' ' . wppa('ajax_import_files_error') . '</span>';
        } else {
            echo '<span style="color:red" >' . wppa('ajax_import_files') . ' ' . __('Failed!', 'wp-photo-album-plus') . '</span>';
        }
        wppa_exit();
    }
    // Open the Form
    echo '<div class="wrap">' . '<h2>' . __('Import Photos', 'wp-photo-album-plus') . '</h2>';
    // See if remote is possible
    $can_remote = ini_get('allow_url_fopen') && function_exists('curl_init');
    if (!$can_remote) {
        update_option('wppa_import_source_type_' . $user, 'local');
    }
    // Get this users current source type setting ( local/remote )
    $source_type = get_option('wppa_import_source_type_' . $user, 'local');
    // Local. Find data we will going to need
    if ($source_type == 'local') {
        // Get curren local dir setting
        $source = get_option('wppa_import_source_' . $user, WPPA_DEPOT_PATH);
        if (!$source || !is_dir($source)) {
            $source = WPPA_DEPOT_PATH;
            update_option('wppa_import_source_' . $user, WPPA_DEPOT_PATH);
        }
        // See if the current source is the 'home' directory
        $is_depot = $source == WPPA_DEPOT_PATH;
        // See if the current source is a subdir of my depot
        $is_sub_depot = substr($source, 0, strlen(WPPA_DEPOT_PATH)) == WPPA_DEPOT_PATH;
        // Sanitize system, removes illegal files
        if ($is_sub_depot) {
            wppa_sanitize_files();
        }
        // See what's in there
        $files = wppa_get_import_files();
        $zipcount = wppa_get_zipcount($files);
        $albumcount = wppa_get_albumcount($files);
        $photocount = wppa_get_photocount($files);
        $videocount = wppa_get_video_count($files);
        $audiocount = wppa_get_audio_count($files);
        $dircount = $is_depot ? wppa_get_dircount($files) : '0';
        $csvcount = $is_depot ? wppa_get_csvcount($files) : '0';
        if ($ngg_opts) {
            $is_ngg = strpos($source, $ngg_opts['gallerypath']) !== false;
            // this is false for the ngg root !!
        } else {
            $is_ngg = false;
        }
    }
    // Remote. Find data we will going to need
    if ($source_type == 'remote') {
        wppa('is_remote', true);
        $source = get_option('wppa_import_source_url_' . $user, 'http://');
        $source_path = $source;
        $source_url = $source;
        $is_depot = false;
        $is_sub_depot = false;
        $files = wppa_get_import_files();
        $zipcount = '0';
        $albumcount = '0';
        $photocount = $files ? count($files) : '0';
        $videocount = '0';
        $audiocount = '0';
        $dircount = '0';
        $csvcount = '0';
        $is_ngg = false;
        $remote_max = get_option('wppa_import_remote_max_' . $user, '10');
    }
    // The form
    echo '<form' . ' action="' . wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_import_photos') . '"' . ' method="post"' . ' >';
    // Admin and superuser can change import source, other users only if change source not is restricted
    if (wppa_user_is('administrator') || !wppa_switch('chgsrc_is_restricted')) {
        // Local / Remote
        echo '<div style="border:1px solid gray; padding:4px; margin: 3px 0;" >' . wp_nonce_field('$wppa_nonce', WPPA_NONCE, true, false) . __('Select Local or Remote', 'wp-photo-album-plus') . ($disabled = $can_remote ? '' : 'disabled="disabled"') . '<select name="wppa-local-remote" >' . '<option value="local" ' . ($source_type == 'local' ? 'selected="selected"' : '') . '>' . __('Local', 'wp-photo-album-plus') . '</option>' . '<option value="remote" ' . $disabled . ($source_type == 'remote' ? 'selected="selected"' : '') . '>' . __('Remote', 'wp-photo-album-plus') . '</option>' . '</select>';
        if ($can_remote) {
            echo '<input' . ' type="submit"' . ' class="button-secundary"' . ' name="wppa-import-set-source"' . ' value="' . __('Set Local/Remote', 'wp-photo-album-plus') . '"' . '/>';
        } else {
            if (!ini_get('allow_url_fopen')) {
                _e('The server does not allow you to import from remote locations. ( The php directive allow_url_fopen is not set to 1 )', 'wp-photo-album-plus');
            }
            if (!function_exists('curl_init')) {
                _e('The server does not allow you to import from remote locations. ( The curl functions are not set up )', 'wp-photo-album-plus');
            }
        }
        echo '</div>';
        // Source dir / url
        echo '<div style="border:1px solid gray; padding:4px; margin: 3px 0;" >' . wp_nonce_field('$wppa_nonce', WPPA_NONCE, true, false) . __('Import photos from:', 'wp-photo-album-plus');
        // Local: dir
        if ($source_type == 'local') {
            echo '<select name="wppa-source" >' . wppa_abs_walktree(wppa_opt('import_root'), $source) . '</select>' . '<input' . ' type="submit"' . ' class="button-secundary"' . ' name="wppa-import-set-source-dir"' . ' value="' . __('Set source directory', 'wp-photo-album-plus') . '"' . ' />';
        } else {
            echo '<input' . ' type="text"' . ' style="width:50%"' . ' name="wppa-source-remote"' . ' value="' . $source . '"' . ' />' . __('Max:', 'wp-photo-album-plus') . '<input' . ' type="text"' . ' style="width:50px;"' . ' name="wppa-import-remote-max"' . ' value="' . $remote_max . '"' . ' />' . '<input' . ' type="submit"' . ' onclick="jQuery( \'#rem-rem\' ).css( \'display\',\'inline\' ); return true;"' . ' class="button-secundary"' . ' name="wppa-import-set-source-url"' . ' value="' . __('Find remote photos', 'wp-photo-album-plus') . '"' . ' />' . '<span id="rem-rem" style="display:none;" >' . __('Working, please wait...', 'wp-photo-album-plus') . '</span>' . '<br />' . __('You can enter either a web page address like <i>http://mysite.com/mypage/</i> or a full url to an image file like <i>http://mysite.com/wp-content/uploads/wppa/4711.jpg</i>', 'wp-photo-album-plus');
        }
        echo '</div>';
    }
    echo '</form>';
    // check if albums exist or will be made before allowing upload
    if (!wppa_has_albums() && !$albumcount && !$dircount && !$csvcount) {
        $url = wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_admin_menu');
        echo '<p>' . __('No albums exist. You must', 'wp-photo-album-plus') . ' ' . '<a href="' . $url . '" >' . __('create one', 'wp-photo-album-plus') . ' ' . '</a> ' . __('beofre you can upload your photos.', 'wp-photo-album-plus') . '</p>';
        return;
    }
    // Something to import?
    if ($photocount || $albumcount || $zipcount || $dircount || $videocount || $audiocount || $csvcount) {
        // Open the form
        echo '<form' . ' action="' . wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_import_photos') . '"' . ' method="post"' . ' >' . wp_nonce_field('$wppa_nonce', WPPA_NONCE, true, false);
        // Display the zips
        if (PHP_VERSION_ID >= 50207 && $zipcount > '0') {
            echo '<div style="border:1px solid gray; padding:4px; margin: 3px 0;" >' . '<p><b>' . sprintf(_n('There is %d zipfile in the depot', 'There are %d zipfiles in the depot', $zipcount, 'wp-photo-album-plus'), $zipcount) . '</b></p>' . '<table class="form-table wppa-table widefat" style="margin-bottom:0;" >' . '<thead>' . '<tr>' . '<td>' . '<input' . ' type="checkbox"' . ' id="all-zip"' . ' checked="checked"' . ' onchange="checkAll( \'all-zip\', \'.wppa-zip\' )"' . ' />' . '<b>&nbsp;&nbsp;' . __('Check/uncheck all', 'wp-photo-album-plus') . '</b>' . '</td>';
            if ($is_sub_depot) {
                echo '<td>' . '<input' . ' type="checkbox"' . ' id="del-after-z"' . ' name="del-after-z"' . ' checked="checked"' . ' />' . '<b>&nbsp;&nbsp;' . __('Delete after successful extraction.', 'wp-photo-album-plus') . '</b>' . '</td>';
            }
            echo '</tr>' . '</thead>' . '</table>' . '<table' . ' class="form-table wppa-table widefat"' . ' style="margin-top:0;"' . ' >' . '<tr>';
            $ct = 0;
            $idx = '0';
            foreach ($files as $file) {
                $ext = wppa_get_ext($file);
                if ($ext == 'zip') {
                    echo '<td>' . '<input' . ' type="checkbox"' . ' id="file-' . $idx . '"' . ' name="file-' . $idx . '"' . ' class="wppa-zip"' . ' checked="checked"' . ' />&nbsp;&nbsp;' . wppa_sanitize_file_name(basename($file)) . '</td>';
                    if ($ct == 3) {
                        echo '</tr><tr>';
                        $ct = 0;
                    } else {
                        $ct++;
                    }
                }
                $idx++;
            }
            echo '</tr>' . '</table>' . '</div>';
        }
        // Dispay the albums ( .amf files )
        if ($albumcount) {
            echo '<div style="border:1px solid gray; padding:4px; margin: 3px 0;" >' . '<p><b>' . sprintf(_n('There is %d albumdefinition in the depot', 'There are %d albumdefinitions in the depot', $albumcount, 'wp-photo-album-plus'), $albumcount) . '</b></p>' . '<table class="form-table wppa-table widefat" style="margin-bottom:0;" >' . '<thead>' . '<tr>' . '<td>' . '<input' . ' type="checkbox"' . ' id="all-amf"' . ' checked="checked"' . ' onchange="checkAll( \'all-amf\', \'.wppa-amf\' )"' . ' />' . '<b>&nbsp;&nbsp;' . __('Check/uncheck all', 'wp-photo-album-plus') . '</b>' . '</td>';
            if ($is_sub_depot) {
                echo '<td>' . '<input' . ' type="checkbox"' . ' id="del-after-a"' . ' name="del-after-a"' . ' checked="checked"' . ' />' . '<b>&nbsp;&nbsp;' . __('Remove from depot after successful import, or if the album already exists.', 'wp-photo-album-plus') . '</b>' . '</td>';
            }
            echo '</tr>' . '</thead>' . '</table>' . '<table' . ' class="form-table wppa-table widefat"' . ' style="margin-top:0;"' . ' >' . '<tr>';
            $ct = 0;
            $idx = '0';
            foreach ($files as $file) {
                $ext = wppa_get_ext($file);
                if ($ext == 'amf') {
                    echo '<td>' . '<input' . ' type="checkbox"' . ' id="file-' . $idx . '"' . ' name="file-' . $idx . '"' . ' class="wppa-amf"' . ' checked="checked"' . ' />' . '&nbsp;&nbsp;' . basename($file) . '&nbsp;' . stripslashes(wppa_get_meta_name($file, '( ')) . '</td>';
                    if ($ct == 3) {
                        echo '</tr><tr>';
                        $ct = 0;
                    } else {
                        $ct++;
                    }
                }
                $idx++;
            }
            echo '</tr>' . '</table>' . '</div>';
        }
        // Display the single photos
        if ($photocount) {
            echo '<div style="border:1px solid gray; padding:4px; margin: 3px 0;" >';
            // Display the number of photos
            '<p><b>';
            // Local
            if ($source_type == 'local') {
                if ($is_ngg) {
                    printf(_n('There is %d photo in the ngg gallery', 'There are %d photos in the ngg gallery', $photocount, 'wp-photo-album-plus'), $photocount);
                } else {
                    printf(_n('There is %d photo in the depot', 'There are %d photos in the depot', $photocount, 'wp-photo-album-plus'), $photocount);
                }
            } else {
                printf(_n('There is %d possible photo found remote', 'There are %d possible photos found remote', $photocount, 'wp-photo-album-plus'), $photocount);
            }
            // Tell if downsize on
            if (wppa_switch('resize_on_upload')) {
                echo ' ' . __('Photos will be downsized during import.', 'wp-photo-album-plus');
            }
            echo '</b></p>';
            // The album selection
            echo '<p class="hideifupdate" >' . __('Default album for import:', 'wp-photo-album-plus') . '<select name="wppa-photo-album" id="wppa-photo-album" >' . wppa_album_select_a(array('path' => wppa_switch('hier_albsel'), 'selected' => get_option('wppa-photo-album-import-' . wppa_get_user(), '0'), 'addpleaseselect' => true, 'checkowner' => true, 'checkupload' => true)) . '</select>' . __('Photos that have (<em>name</em>)[<em>album</em>] will be imported by that <em>name</em> in that <em>album</em>.', 'wp-photo-album-plus') . '</p>';
            // Watermark
            if (wppa_switch('watermark_on') && (wppa_switch('watermark_user') || current_user_can('wppa_settings'))) {
                echo '<p>' . __('Apply watermark file:', 'wp-photo-album-plus') . '<select name="wppa-watermark-file" id="wppa-watermark-file" >' . wppa_watermark_file_select() . '</select>' . __('Position:', 'wp-photo-album-plus') . '<select name="wppa-watermark-pos" id="wppa-watermark-pos" >' . wppa_watermark_pos_select() . '</select>' . '</p>';
            }
            // Header of photo list
            echo '<table class="form-table wppa-table widefat" style="margin-bottom:0;" >' . '<thead>' . '<tr>' . '<td>' . '<input' . ' type="checkbox"' . ' id="all-pho"' . ($is_sub_depot ? 'checked="checked"' : '') . ' onchange="checkAll( \'all-pho\', \'.wppa-pho\' )"' . ' />' . '<b>' . '&nbsp;&nbsp;' . __('Check/uncheck all', 'wp-photo-album-plus') . '</b>' . '</td>';
            // Depot specific switches
            if ($is_sub_depot) {
                echo '<td>' . '<input' . ' type="checkbox"' . ' id="del-after-p"' . ' name="del-after-p"' . ' checked="checked"' . ' />' . '<b>' . '&nbsp;&nbsp;' . __('Remove from depot after successful import.', 'wp-photo-album-plus') . '</b>' . '</td>' . '<td>' . '<input' . ' type="checkbox"' . ' id="del-after-f"' . ' name="del-after-f"' . ' />' . '<b>' . '&nbsp;&nbsp;' . __('Remove from depot after failed import.', 'wp-photo-album-plus') . '</b>' . '</td>';
            }
            // Nextgen import specific switches
            if ($is_ngg) {
                echo '<td>' . '<input' . ' type="checkbox"' . ' id="cre-album"' . ' name="cre-album"' . ' checked="checked"' . ' value="' . esc_attr(basename($source)) . '"' . ' />' . '<b>' . '&nbsp;&nbsp;' . __('Import into album', 'wp-photo-album-plus') . ' ' . basename($source) . '</b>' . '<small>' . __('The album will be created if it does not exist', 'wp-photo-album-plus') . '</small>' . '</td>' . '<td>' . '<input' . ' type="checkbox"' . ' id="use-backup"' . ' name="use-backup"' . ' checked="checked"' . ' />' . '<b>' . '&nbsp;&nbsp;' . __('Use backup if available', 'wp-photo-album-plus') . '</b>' . '</td>';
            }
            // Update existing switch
            echo '<td>' . '<input' . ' type="checkbox"' . ' id="wppa-update"' . ' onchange="impUpd( this, \'#submit\' )"' . ' name="wppa-update"' . ' />' . '<b>' . '&nbsp;&nbsp;' . __('Update existing photos', 'wp-photo-album-plus') . '</b>' . '</td>';
            // Void dups switch
            echo '<td>';
            if (wppa_switch('void_dups')) {
                echo '<input' . ' type="hidden"' . ' id="wppa-nodups"' . ' name="wppa-nodups"' . ' value="true"' . ' />';
            } else {
                echo '<input' . ' type="checkbox"' . ' id="wppa-nodups"' . ' name="wppa-nodups"' . ' checked="checked"' . ' />' . '<b>' . '&nbsp;&nbsp;' . __('Do not create duplicates', 'wp-photo-album-plus') . '</b>';
            }
            echo '</td>';
            // Import preview zoomable switch
            if (wppa_switch('import_preview')) {
                echo '<td>' . '<input' . ' type="checkbox"' . ' id="wppa-zoom"' . ' onclick="wppa_setCookie(\'zoompreview\', this.checked, \'365\')"' . ' />' . '<b>' . '&nbsp;&nbsp;' . __('Zoom previews', 'wp-photo-album-plus') . '</b>' . '<script type="text/javascript">if ( wppa_getCookie(\'zoompreview\') == true ) { jQuery(\'#wppa-zoom\').attr(\'checked\', \'checked\') }</script>' . '</td>';
            }
            echo '</tr>' . '</thead>' . '</table>';
            // Photo list
            echo '<table class="form-table wppa-table widefat" style="margin-top:0;" >' . '<tr>';
            $ct = 0;
            $idx = '0';
            if (is_array($files)) {
                foreach ($files as $file) {
                    $ext = wppa_get_ext($file);
                    $meta = wppa_strip_ext($file) . '.PMF';
                    if (!is_file($meta)) {
                        $meta = wppa_strip_ext($file) . '.pmf';
                    }
                    if (!is_file($meta)) {
                        $meta = false;
                    }
                    if (in_array(strtolower($ext), $wppa_supported_photo_extensions)) {
                        echo '<td id="td-file-' . $idx . '" >' . '<input' . ' type="checkbox"' . ' id="file-' . $idx . '"' . ' name="file-' . $idx . '"' . ' title="' . esc_attr($file) . '"' . ' class="wppa-pho"' . ($is_sub_depot ? 'checked="checked"' : '') . '/ >' . '<span' . ' id="name-file-' . $idx . '"' . ' >' . '&nbsp;&nbsp;';
                        if (wppa('is_wppa_tree')) {
                            $t = explode('uploads/wppa/', $file);
                            echo $t[1];
                        } else {
                            echo wppa_sanitize_file_name(basename($file));
                        }
                        if ($meta) {
                            echo '&nbsp;' . stripslashes(wppa_get_meta_name($meta, '( ')) . stripslashes(wppa_get_meta_album($meta, '['));
                        }
                        echo '</span>';
                        if (wppa_switch('import_preview')) {
                            if (wppa('is_remote')) {
                                if (strpos($file, '//res.cloudinary.com/') !== false) {
                                    $img_url = dirname($file) . '/h_144/' . basename($file);
                                } else {
                                    $img_url = $file;
                                }
                            } else {
                                $img_url = str_replace(ABSPATH, home_url() . '/', $file);
                            }
                            echo '<img src="' . $img_url . '"' . ' alt="N.A."' . ' style="max-height:48px;"' . ' onmouseover="if (jQuery(\'#wppa-zoom\').attr(\'checked\')) jQuery(this).css(\'max-height\', \'144px\')"' . ' onmouseout="if (jQuery(\'#wppa-zoom\').attr(\'checked\')) jQuery(this).css(\'max-height\', \'48px\')"' . ' />';
                        }
                        echo '</td>';
                        if ($ct == 3) {
                            echo '</tr><tr>';
                            $ct = 0;
                        } else {
                            $ct++;
                        }
                    }
                    $idx++;
                }
            }
            echo '</tr>' . '</table>' . '</div>';
        }
        // Display the videos
        if ($videocount && wppa_switch('enable_video')) {
            echo '<div style="border:1px solid gray; padding:4px; margin: 3px 0;" >';
            // Display available files
            echo '<p><b>' . sprintf(_n('There is %d video in the depot', 'There are %d videos in the depot', $videocount, 'wp-photo-album-plus'), $videocount) . '</b></p>';
            // Album to import to
            echo '<p class="hideifupdate" >' . __('Album to import to:', 'wp-photo-album-plus') . '<select name="wppa-video-album" id="wppa-video-album">' . wppa_album_select_a(array('path' => wppa_switch('hier_albsel'), 'selected' => get_option('wppa-video-album-import-' . wppa_get_user(), '0'), 'addpleaseselect' => true, 'checkowner' => true, 'checkupload' => true)) . '</select>' . '</p>';
            // Header of video list
            echo '<table class="form-table wppa-table widefat" style="margin-bottom:0;" >' . '<thead>' . '<tr>' . '<td>' . '<input' . ' type="checkbox"' . ' id="all-video"' . ' checked="checked"' . ' onchange="checkAll( \'all-video\', \'.wppa-video\' )"' . ' />' . '<b>' . '&nbsp;&nbsp;' . __('Check/uncheck all', 'wp-photo-album-plus') . '</b>' . '</td>';
            if ($is_sub_depot) {
                echo '<td>' . '<input' . ' type="checkbox"' . ' id="del-after-v"' . ' name="del-after-v"' . ' checked="checked"' . ' />' . '<b>' . '&nbsp;&nbsp;' . __('Remove from depot after successful import.', 'wp-photo-album-plus') . ' <small>' . __('Files larger than 64MB will always be removed after successful import.', 'wp-photo-album-plus') . '</small>' . '</b>' . '</td>';
            }
            echo '</tr>' . '</thead>' . '</table>';
            // Video list
            echo '<table class="form-table wppa-table widefat" style="margin-top:0;" >' . '<tr>';
            $ct = 0;
            $idx = '0';
            if (is_array($files)) {
                foreach ($files as $file) {
                    $ext = strtolower(substr(strrchr($file, "."), 1));
                    if (in_array(strtolower($ext), $wppa_supported_video_extensions)) {
                        echo '<td>' . '<input' . ' type="checkbox"' . ' id="file-' . $idx . '"' . ' name="file-' . $idx . '"' . ' title="' . $file . '"' . ' class="wppa-video"' . ' checked="checked"' . ' />' . '<span' . ' id="name-file-' . $idx . '"' . ' >' . '&nbsp;&nbsp;' . wppa_sanitize_file_name(basename($file)) . '</span>' . '</td>';
                        if ($ct == 3) {
                            echo '</tr><tr>';
                            $ct = 0;
                        } else {
                            $ct++;
                        }
                    }
                    $idx++;
                }
            }
            echo '</tr>' . '</table>' . '</div>';
        }
        // Display the audios
        if ($audiocount && wppa_switch('enable_audio')) {
            echo '<div style="border:1px solid gray; padding:4px; margin: 3px 0;" >';
            // Display available files
            echo '<p><b>' . sprintf(_n('There is %d audio in the depot', 'There are %d audios in the depot', $audiocount, 'wp-photo-album-plus'), $audiocount) . '</b></p>';
            // Album to import to
            echo '<p class="hideifupdate" >' . __('Album to import to:', 'wp-photo-album-plus') . '<select name="wppa-audio-album" id="wppa-audio-album" >' . wppa_album_select_a(array('path' => wppa_switch('hier_albsel'), 'selected' => get_option('wppa-audio-album-import-' . wppa_get_user(), '0'), 'addpleaseselect' => true, 'checkowner' => true, 'checkupload' => true)) . '</select>' . '</p>';
            // Header of audio list
            echo '<table class="form-table wppa-table widefat" style="margin-bottom:0;" >' . '<thead>' . '<tr>' . '<td>' . '<input' . ' type="checkbox"' . ' id="all-audio"' . ' checked="checked"' . ' onchange="checkAll( \'all-audio\', \'.wppa-audio\' )"' . ' />' . '<b>' . '&nbsp;&nbsp;' . __('Check/uncheck all', 'wp-photo-album-plus') . '</b>' . '</td>';
            // The remove box
            if ($is_sub_depot) {
                echo '<td>' . '<input' . ' type="checkbox"' . ' id="del-after-u"' . ' name="del-after-u"' . ' checked="checked"' . ' />' . '<b>' . '&nbsp;&nbsp;' . __('Remove from depot after successful import.', 'wp-photo-album-plus') . '</b>' . '</td>';
            }
            echo '</tr>' . '</thead>' . '</table>';
            // Audio list
            echo '<table class="form-table wppa-table widefat" style="margin-top:0;" >' . '<tr>';
            $ct = 0;
            $idx = '0';
            if (is_array($files)) {
                foreach ($files as $file) {
                    $ext = strtolower(substr(strrchr($file, "."), 1));
                    if (in_array(strtolower($ext), $wppa_supported_audio_extensions)) {
                        echo '<td>' . '<input' . ' type="checkbox"' . ' id="file-' . $idx . '"' . ' name="file-' . $idx . '"' . ' title="' . $file . '"' . ' class="wppa-audio"' . ' checked="checked"' . ' />' . '<span' . ' id="name-file-' . $idx . '"' . ' >' . '&nbsp;&nbsp;' . wppa_sanitize_file_name(basename($file)) . '</span>' . '</td>';
                        if ($ct == 3) {
                            echo '</tr><tr>';
                            $ct = 0;
                        } else {
                            $ct++;
                        }
                    }
                    $idx++;
                }
            }
            echo '</tr>' . '</table>' . '</div>';
        }
        // Display the directories to be imported as albums. Do this in the depot only!!
        if ($is_depot && $dircount) {
            echo '<div style="border:1px solid gray; padding:4px; margin: 3px 0;" >';
            // Display number of dirs
            echo '<p><b>' . sprintf(_n('There is %d albumdirectory in the depot', 'There are %d albumdirectories in the depot', $dircount, 'wp-photo-album-plus'), $dircount) . '</b></p>';
            // Header of dirlist
            echo '<table class="form-table wppa-table widefat" style="margin-bottom:0;" >' . '<thead>' . '<tr>' . '<td>' . '<input' . ' type="checkbox"' . ' id="all-dir"' . ' checked="checked"' . ' onchange="checkAll( \'all-dir\', \'.wppa-dir\' )"' . ' />' . '<b>' . '&nbsp;&nbsp;' . __('Check/uncheck all', 'wp-photo-album-plus') . '</b>' . '</td>' . '</tr>' . '</thead>' . '</table>';
            // Dirlist
            echo '<table class="form-table wppa-table widefat" style="margin-top:0;" >';
            $ct = 0;
            $idx = '0';
            foreach ($files as $dir) {
                if (basename($dir) == '.') {
                } elseif (basename($dir) == '..') {
                } elseif (is_dir($dir)) {
                    echo '<tr>' . '<td>' . '<input' . ' type="checkbox"' . ' id="file-' . $idx . '"' . ' name="file-' . $idx . '"' . ' class= "wppa-dir"' . ' checked="checked"' . ' />' . '&nbsp;&nbsp;' . '<b>' . wppa_sanitize_file_name(basename($dir)) . '</b>';
                    $subfiles = glob($dir . '/*');
                    $subdircount = '0';
                    if ($subfiles) {
                        foreach ($subfiles as $subfile) {
                            if (is_dir($subfile) && basename($subfile) != '.' && basename($subfile) != '..') {
                                $subdircount++;
                            }
                        }
                    }
                    $sfcount = empty($subfiles) ? '0' : wppa_get_photocount($subfiles);
                    echo ' ' . sprintf(_n('Contains %d file', 'Contains %d files', $sfcount, 'wp-photo-album-plus'), $sfcount);
                    if ($subdircount) {
                        echo ' ' . sprintf(_n('and %d subdirectory', 'and %d subdirectories', $subdircount, 'wp-photo-album-plus'), $subdircount);
                    }
                    '</td>' . '</tr>';
                }
                $idx++;
            }
            echo '</table>' . '</div>';
        }
        // Display the csv files
        if ($is_depot && $csvcount) {
            echo '<div style="border:1px solid gray; padding:4px; margin: 3px 0;" >';
            // Display number of files
            echo '<p><b>' . sprintf(_n('There is %d .csv file in the depot', 'There are %d .csv files in the depot', $csvcount, 'wp-photo-album-plus'), $csvcount) . '</b></p>';
            // Header of .csv file list
            echo '<table class="form-table wppa-table widefat" style="margin-bottom:0;" >' . '<thead>' . '<tr>' . '<td>' . '<input' . ' type="checkbox"' . ' id="all-csv"' . ' checked="checked"' . ' onchange="checkAll( \'all-csv\', \'.wppa-csv\' )"' . ' />' . '<b>' . '&nbsp;&nbsp;' . __('Check/uncheck all', 'wp-photo-album-plus') . '</b>' . '</td>' . '<td>' . '<input' . ' type="checkbox"' . ' id="del-after-c"' . ' name="del-after-c"' . ' checked="checked"' . ' disabled="disabled"' . ' />' . '<b>' . '&nbsp;&nbsp;' . __('Remove from depot after successful import.', 'wp-photo-album-plus') . '</b>' . '</td>' . '</tr>' . '</thead>' . '</table>';
            // CSV file list
            echo '<table class="form-table wppa-table widefat" style="margin-top:0;" >';
            $ct = 0;
            $idx = '0';
            foreach ($files as $csv) {
                if (is_file($csv) && strtolower(wppa_get_ext($csv)) == 'csv') {
                    echo '<tr>' . '<td>' . '<input' . ' type="checkbox"' . ' id="file-' . $idx . '"' . ' name="file-' . $idx . '"' . ' class="wppa-csv"' . ' checked="checked"' . ' />' . '&nbsp;&nbsp;' . '<b>' . wppa_sanitize_file_name(basename($csv)) . ' (' . sprintf('%5.1f', filesize($csv) / 1024) . ' kb)' . '</b>' . '</td>' . '</tr>';
                }
                $idx++;
            }
            echo '</table>' . '</div>';
        }
        // The submit button
        ?>
			<p>
				<script type="text/javascript">
					function wppaVfyAlbum() {
						var csvs = jQuery( '.wppa-csv' );
						if ( jQuery( '#wppa-update' ).attr( 'checked' ) != 'checked' ) {
							if ( 	! parseInt( jQuery( '#wppa-photo-album' ).attr( 'value' ) ) &&
									! parseInt( jQuery( '#wppa-video-album' ).attr( 'value' ) ) &&
									! parseInt( jQuery( '#wppa-audio-album' ).attr( 'value' ) ) &&
									csvs.length == 0
								) {
								alert( 'Please select an album first' );
								return false;
							}
						}
						return true;
					}
					function wppaCheckInputVars() {
						var checks = jQuery( ':checked' );
						var nChecks = checks.length;
						var nMax = <?php 
        echo ini_get('max_input_vars');
        ?>
;
						if ( nMax == 0 ) nMax = 100;
						if ( nChecks > nMax ) {
							alert ( 'There are '+nChecks+' boxes checked or selected, that is more than the maximum allowed number of '+nMax );
							return false;
						}
						var dirs = jQuery( '.wppa-dir' );
						var nDirsChecked = 0;
						if ( dirs.length > 0 ) {
							var i = 0;
							while ( i < dirs.length ) {
								if ( jQuery( dirs[i] ).attr( 'checked' ) == 'checked' ) {
									nDirsChecked++;
								}
								i++;
							}
						}
						var zips = jQuery( '.wppa-zip' );
						var nZipsChecked = 0;
						if ( zips.length > 0 ) {
							var i = 0;
							while ( i < zips.length ) {
								if ( jQuery( zips[i] ).attr( 'checked' ) == 'checked' ) {
									nZipsChecked++;
								}
								i++;
							}
						}
						// If no dirs to import checked, there must be an album selected
						if ( 0 == nDirsChecked && 0 == nZipsChecked && ! wppaVfyAlbum() ) return false;
						return true;
					}
				</script>
				<input type="submit" onclick="return wppaCheckInputVars()" class="button-primary" id="submit" name="wppa-import-submit" value="<?php 
        _e('Import', 'wp-photo-album-plus');
        ?>
" />
				<script type="text/javascript" >
					var wppaImportRuns = false;
					function wppaDoAjaxImport() {
						wppaImportRuns = true;
						var data = '';
						data += 'wppa-update-check='+jQuery( '#wppa-update-check' ).attr( 'value' );
						data += '&wppa-photo-album='+jQuery( '#wppa-photo-album' ).attr( 'value' );
						data += '&wppa-video-album='+jQuery( '#wppa-video-album' ).attr( 'value' );
						data += '&wppa-audio-album='+jQuery( '#wppa-audio-album' ).attr( 'value' );
						data += '&wppa-watermark-file='+jQuery( '#wppa-watermark-file' ).attr( 'value' );
						data += '&wppa-watermark-pos='+jQuery( '#wppa-watermark-pos' ).attr( 'value' );
						if ( jQuery( '#cre-album' ).attr( 'checked' ) ) data += '&cre-album='+jQuery( '#cre-album' ).attr( 'value' );
						if ( jQuery( '#use-backup' ).attr( 'checked' ) ) data += '&use-backup=on'; //+jQuery( '#use-backup' ).attr( 'value' );
						if ( jQuery( '#wppa-update' ).attr( 'checked' ) ) data += '&wppa-update=on'; //+jQuery( '#wppa-update' ).attr( 'value' );
						if ( jQuery( '#wppa-nodups' ).attr( 'checked' ) ) data += '&wppa-nodups=on'; //+jQuery( '#wppa-nudups' ).attr( 'value' );
						if ( jQuery( '#del-after-p' ).attr( 'checked' ) ) data += '&del-after-p=on';
						if ( jQuery( '#del-after-f' ).attr( 'checked' ) ) data += '&del-after-f=on';
						if ( jQuery( '#del-after-v' ).attr( 'checked' ) ) data += '&del-after-v=on';
						if ( jQuery( '#del-after-u' ).attr( 'checked' ) ) data += '&del-after-u=on';
						data += '&wppa-import-submit=ajax';

						var files = jQuery( ':checked' );
						var found = false;
						var i=0;
						var elm;
						var fulldata;
						for ( i=0; i<files.length; i++ ) {
							found = false;	// assume done
							elm = files[i];
							// Is it a file checkbox?
							var temp = elm.id.split( '-' );
							if ( temp[0] != 'file' ) continue;	// no
							fulldata = data+'&import-ajax-file='+elm.title;
							found = true;
							break;
						}
						//	alert( data );
						if ( ! found ) {
							wppaStopAjaxImport();
							return;	// nothing left
						}
						// found one, do it
						var oldhtml=jQuery( '#name-'+elm.id ).html();
						var xmlhttp = wppaGetXmlHttp();
						xmlhttp.onreadystatechange = function() {
							if ( xmlhttp.readyState == 4 ) {
								if ( xmlhttp.status!=404 ) {
									var resp = xmlhttp.responseText;
									//
									if ( resp.length == 0 ) {
										jQuery( '#name-'+elm.id ).html('<span style="color:red" >Timeout</span>' );
										wppaStopAjaxImport();
										return;
									}
									//
									if ( resp.indexOf( 'Server' ) != -1 && resp.indexOf( 'Error' ) != -1 ) {
										resp = '<span style="color:red" >Server error</span>';
									}
									jQuery( '#name-'+elm.id ).html( '&nbsp;&nbsp;<b>'+resp+'</b>' );
									elm.checked = '';
									if ( jQuery( '#del-after-p' ).attr( 'checked' ) ||
										 jQuery( '#del-after-f' ).attr( 'checked' ) ) {
										elm.disabled = 'disabled';
										elm.title = '';
									}
									if ( wppaImportRuns ) {
										setTimeout( 'wppaDoAjaxImport()', 100 );
									}
								}
								else {
									jQuery( '#name-'+elm.id ).html( '&nbsp;&nbsp;<b>Not found</b>' );
								}
							}
						}
						var url = wppaAjaxUrl+'?action=wppa&wppa-action=import';
						xmlhttp.open( 'POST',url,true );
						xmlhttp.setRequestHeader( "Content-type","application/x-www-form-urlencoded" );
						xmlhttp.send( fulldata );
						jQuery( '#name-'+elm.id ).html( '&nbsp;&nbsp;<b style="color:blue" >' + '<?php 
        _e('Working...', 'wp-photo-album-plus');
        ?>
' + '</b>' );
						jQuery( '#wppa-start-ajax' ).css( 'display', 'none' );
						jQuery( '#wppa-stop-ajax' ).css( 'display', 'inline' );
					}
					function wppaStopAjaxImport() {
						wppaImportRuns = false;
						jQuery( '#wppa-start-ajax' ).css( 'display', 'inline' );
						jQuery( '#wppa-stop-ajax' ).css( 'display', 'none' );
					}
				</script>
				<?php 
        if (($photocount || $videocount || $audiocount) && !$albumcount && !$dircount && !$zipcount) {
            ?>
				<input id="wppa-start-ajax" type="button" onclick="if ( wppaVfyAlbum() ) { wppaDoAjaxImport() }" class="button-secundary" value="<?php 
            esc_attr(_e('Start Ajax Import', 'wp-photo-album-plus'));
            ?>
" />
				<input id="wppa-stop-ajax" style="display:none;" type="button" onclick="wppaStopAjaxImport()" class="button-secundary" value="<?php 
            esc_attr(_e('Stop Ajax Import', 'wp-photo-album-plus'));
            ?>
" />
				<?php 
        }
        ?>
			</p>
			</form>

		<?php 
    } else {
        if ($source_type == 'local') {
            wppa_ok_message(__('There are no importable files found in directory:', 'wp-photo-album-plus') . ' ' . $source);
        } else {
            wppa_ok_message(__('There are no photos found or left to process at url:', 'wp-photo-album-plus') . ' ' . $source_url);
        }
    }
    echo '<br /><b>';
    _e('You can import the following file types:', 'wp-photo-album-plus');
    echo '</b><br />';
    if (PHP_VERSION_ID >= 50207) {
        echo '<br />';
        _e('Compressed file types: .zip', 'wp-photo-album-plus');
    }
    if (true) {
        echo '<br />';
        _e('Photo file types:', 'wp-photo-album-plus');
        foreach ($wppa_supported_photo_extensions as $ext) {
            echo ' .' . $ext;
        }
    }
    if (wppa_switch('enable_video')) {
        echo '<br />';
        _e('Video file types:', 'wp-photo-album-plus');
        foreach ($wppa_supported_video_extensions as $ext) {
            echo ' .' . $ext;
        }
    }
    if (wppa_switch('enable_audio')) {
        echo '<br />';
        _e('Audio file types:', 'wp-photo-album-plus');
        foreach ($wppa_supported_audio_extensions as $ext) {
            echo ' .' . $ext;
        }
    }
    echo '<br />';
    _e('WPPA+ file types: .amf .pmf', 'wp-photo-album-plus');
    echo '<br />';
    _e('Directories with optional subdirs containig photos', 'wp-photo-album-plus');
    echo '<br />';
    _e('Custom data files of type .csv', 'wp-photo-album-plus');
    echo '<br /><br />';
    _e('Your depot directory is:', 'wp-photo-album-plus');
    echo '<b> .../' . WPPA_DEPOT . '/</b>';
    if (wppa('continue')) {
        wppa_warning_message(__('Trying to continue...', 'wp-photo-album-plus'));
        echo '<script type="text/javascript">document.location=\'' . get_admin_url() . 'admin.php?page=wppa_import_photos&continue&nonce=' . wp_create_nonce('dirimport') . '\';</script>';
    }
    echo '<br /><br />';
    wppa_album_admin_footer();
    echo '</div><!-- .wrap -->';
}
Exemplo n.º 2
0
function _wppa_page_import()
{
    global $wppa_revno;
    global $wppa;
    global $wpdb;
    global $wppa_supported_photo_extensions;
    global $wppa_supported_video_extensions;
    global $wppa_supported_audio_extensions;
    if ($wppa['ajax']) {
        ob_start();
    }
    // Suppress output if ajax operation
    // Init
    $ngg_opts = get_option('ngg_options', false);
    $user = wppa_get_user();
    // Check database
    wppa_check_database(true);
    // Sanitize system
    $count = wppa_sanitize_files();
    if ($count) {
        wppa_error_message($count . ' ' . __('illegal files deleted.', 'wppa'));
    }
    // Update watermark settings
    if (wppa_switch('wppa_watermark_on') && (wppa_switch('wppa_watermark_user') || current_user_can('wppa_settings'))) {
        if (isset($_POST['wppa-watermark-file'])) {
            update_option('wppa_watermark_file_' . $user, $_POST['wppa-watermark-file']);
        }
        if (isset($_POST['wppa-watermark-pos'])) {
            update_option('wppa_watermark_pos_' . $user, $_POST['wppa-watermark-pos']);
        }
    }
    // Update last used albums
    if (isset($_POST['wppa-photo-album'])) {
        update_option('wppa-photo-album-import-' . wppa_get_user(), $_POST['wppa-photo-album']);
        // nog in form verwerken
    }
    if (isset($_POST['wppa-video-album'])) {
        update_option('wppa-video-album-import-' . wppa_get_user(), $_POST['wppa-video-album']);
    }
    if (isset($_POST['wppa-audio-album'])) {
        update_option('wppa-audio-album-import-' . wppa_get_user(), $_POST['wppa-audio-album']);
    }
    // Verify last albums still exist
    $alb = strval(intval(get_option('wppa-photo-album-import-' . wppa_get_user(), '0')));
    if ($alb) {
        $exists = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_ALBUMS . "`  WHERE `id` = " . $alb);
        if (!$exists) {
            update_option('wppa-photo-album-import-' . wppa_get_user(), '0');
        }
    }
    $alb = get_option('wppa-video-album-import-' . wppa_get_user(), '0');
    if ($alb) {
        $exists = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_ALBUMS . "`  WHERE `id` = " . $alb);
        if (!$exists) {
            update_option('wppa-video-album-import-' . wppa_get_user(), '0');
        }
    }
    $alb = get_option('wppa-audio-album-import-' . wppa_get_user(), '0');
    if ($alb) {
        $exists = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_ALBUMS . "`  WHERE `id` = " . $alb);
        if (!$exists) {
            update_option('wppa-audio-album-import-' . wppa_get_user(), '0');
        }
    }
    // Extract zip
    if (isset($_GET['zip'])) {
        wppa_extract($_GET['zip'], true);
    }
    // Set local / remote
    if (isset($_POST['wppa-local-remote'])) {
        check_admin_referer('$wppa_nonce', WPPA_NONCE);
        update_option('wppa_import_source_type_' . $user, $_POST['wppa-local-remote']);
    }
    // Set import source dir ( when local )
    if (isset($_POST['wppa-import-set-source-dir'])) {
        check_admin_referer('$wppa_nonce', WPPA_NONCE);
        if (isset($_POST['wppa-source'])) {
            update_option('wppa_import_source_' . $user, $_POST['wppa-source']);
        }
    }
    // Set import source url ( when remote )
    if (isset($_POST['wppa-import-set-source-url'])) {
        check_admin_referer('$wppa_nonce', WPPA_NONCE);
        if (isset($_POST['wppa-source-remote'])) {
            update_option('wppa_import_source_url_' . $user, $_POST['wppa-source-remote']);
            update_option('wppa_import_source_url_found_' . $user, false);
            update_option('wppa_import_remote_max_' . $user, strval(intval($_POST['wppa-import-remote-max'])));
        }
    }
    // Hit the submit button
    if (isset($_POST['wppa-import-submit'])) {
        if ($wppa['ajax']) {
            if (!wp_verify_nonce($_POST['wppa-update-check'], '$wppa_nonce')) {
                echo $_POST['wppa-update-check'] . ' Security check failure';
                exit;
            }
        } else {
            check_admin_referer('$wppa_nonce', WPPA_NONCE);
        }
        if (isset($_POST['del-after-p'])) {
            $delp = true;
        } else {
            $delp = false;
        }
        if (isset($_POST['del-after-a'])) {
            $dela = true;
        } else {
            $dela = false;
        }
        if (isset($_POST['del-after-z'])) {
            $delz = true;
        } else {
            $delz = false;
        }
        if (isset($_POST['del-after-v'])) {
            $delv = true;
        } else {
            $delv = false;
        }
        if (isset($_POST['del-after-u'])) {
            $delu = true;
        } else {
            $delu = false;
        }
        if (isset($_POST['del-after-c'])) {
            $delc = true;
        } else {
            $delc = false;
        }
        wppa_import_photos($delp, $dela, $delz, $delv, $delu, $delc);
    } elseif (isset($_GET['continue'])) {
        if (wp_verify_nonce($_GET['nonce'], 'dirimport')) {
            wppa_import_photos();
        }
    }
    // If we did this by ajax, setup reporting results for it
    if ($wppa['ajax']) {
        ob_end_clean();
        if ($wppa['ajax_import_files_done']) {
            echo '<span style="color:green" >' . $wppa['ajax_import_files'] . ' ' . __('Done!', 'wppa') . '</span>';
        } elseif ($wppa['ajax_import_files_error']) {
            echo '<span style="color:red" >' . $wppa['ajax_import_files'] . ' ' . $wppa['ajax_import_files_error'] . '</span>';
        } else {
            echo '<span style="color:red" >' . $wppa['ajax_import_files'] . ' ' . __('Failed!', 'wppa') . '</span>';
        }
        exit;
    }
    // Sanitize again
    $count = wppa_sanitize_files();
    if ($count) {
        wppa_error_message($count . ' ' . __('illegal files deleted.', 'wppa'));
    }
    ?>
	
	<div class="wrap">
		<?php 
    $iconurl = WPPA_URL . '/images/camera32.png';
    ?>
		<div id="icon-camera" class="icon32" style="background: transparent url( <?php 
    echo $iconurl;
    ?>
 ) no-repeat"></div>
		<?php 
    $iconurl = WPPA_URL . '/images/arrow32.png';
    ?>
		<div id="icon-arrow" class="icon32" style="background: transparent url( <?php 
    echo $iconurl;
    ?>
 ) no-repeat"></div>
		<?php 
    $iconurl = WPPA_URL . '/images/album32.png';
    ?>
		<div id="icon-album" class="icon32" style="background: transparent url( <?php 
    echo $iconurl;
    ?>
 ) no-repeat"><br /></div>
		
		<h2><?php 
    _e('Import Photos', 'wppa');
    ?>
</h2><br />
		<?php 
    // Get this users current source directory setting
    $can_remote = ini_get('allow_url_fopen') && function_exists('curl_init');
    // $can_remote = false; // Debug
    if (!$can_remote) {
        update_option('wppa_import_source_type_' . $user, 'local');
    }
    $source_type = get_option('wppa_import_source_type_' . $user, 'local');
    if ($source_type == 'local') {
        $source = get_option('wppa_import_source_' . $user, WPPA_DEPOT);
        if (!$source || !is_dir(WPPA_ABSPATH . $source)) {
            $source = WPPA_DEPOT;
            update_option('wppa_import_source_' . $user, WPPA_DEPOT);
        }
        $source_path = WPPA_ABSPATH . $source;
        $source_url = get_bloginfo('url') . '/' . $source;
        // See if the current source is the 'home' directory
        $is_depot = $source == WPPA_DEPOT;
        // See if the current souce is a wp upload location or a wppa+ sourcefile location ( if so: no delete checkbox )
        $is_sub_depot = substr($source, 0, strlen(WPPA_DEPOT)) == WPPA_DEPOT && substr(WPPA_ABSPATH . $source, 0, strlen(wppa_opt('wppa_source_dir'))) != wppa_opt('wppa_source_dir');
        // See what's in there
        $files = wppa_get_import_files();
        $zipcount = wppa_get_zipcount($files);
        $albumcount = wppa_get_albumcount($files);
        $photocount = wppa_get_photocount($files);
        $videocount = wppa_get_video_count($files);
        $audiocount = wppa_get_audio_count($files);
        $dircount = $is_depot ? wppa_get_dircount($files) : '0';
        $csvcount = $is_depot ? wppa_get_csvcount($files) : '0';
        // echo 'zips:'.$zipcount,' albs:'.$albumcount.' pho:'.$photocount.' dirs:'.$dircount;
        if ($ngg_opts) {
            $is_ngg = strpos($source, $ngg_opts['gallerypath']) !== false;
            // this is false for the ngg root !!
        } else {
            $is_ngg = false;
        }
    }
    if ($source_type == 'remote') {
        $wppa['is_remote'] = true;
        $source = get_option('wppa_import_source_url_' . $user, 'http://');
        $source_path = $source;
        $source_url = $source;
        $is_depot = false;
        $is_sub_depot = false;
        $files = wppa_get_import_files();
        $zipcount = '0';
        $albumcount = '0';
        $photocount = $files ? count($files) : '0';
        $videocount = '0';
        $audiocount = '0';
        $dircount = '0';
        $csvcount = '0';
        $is_ngg = false;
        $remote_max = get_option('wppa_import_remote_max_' . $user, '10');
    }
    ?>
		
	<form action="<?php 
    echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_import_photos');
    ?>
" method="post">
		<?php 
    if (current_user_can('administrator') || !wppa_switch('wppa_chgsrc_is_restricted')) {
        ?>

		<div style="border:1px solid gray; padding:4px; margin: 3px 0;" >
			<?php 
        wp_nonce_field('$wppa_nonce', WPPA_NONCE);
        _e('Select Local or Remote', 'wppa');
        $disabled = $can_remote ? '' : 'disabled="disabled"';
        ?>
			<select name="wppa-local-remote" >
				<option value="local" <?php 
        if ($source_type == 'local') {
            echo 'selected="selected"';
        }
        ?>
><?php 
        _e('Local', 'wppa');
        ?>
</option>
				<option value="remote" <?php 
        echo $disabled;
        if ($source_type == 'remote') {
            echo 'selected="selected"';
        }
        ?>
><?php 
        _e('Remote', 'wppa');
        ?>
</option>
			</select>
			<?php 
        if ($can_remote) {
            ?>
				<input type="submit" class="button-secundary" name="wppa-import-set-source" value="<?php 
            _e('Set Local/Remote', 'wppa');
            ?>
" />
			<?php 
        } else {
            if (!ini_get('allow_url_fopen')) {
                _e('The server does not allow you to import from remote locations. ( The php directive allow_url_fopen is not set to 1 )', 'wppa');
            }
            if (!function_exists('curl_init')) {
                _e('The server does not allow you to import from remote locations. ( The curl functions are not set up )', 'wppa');
            }
        }
        ?>
		</div>
		<div style="border:1px solid gray; padding:4px; margin: 3px 0;" >
			<?php 
        wp_nonce_field('$wppa_nonce', WPPA_NONCE);
        ?>
			<?php 
        _e('Import photos from:', 'wppa');
        ?>
			<?php 
        if ($source_type == 'local') {
            ?>
			<select name="wppa-source">
				<option value="<?php 
            echo WPPA_DEPOT;
            ?>
" <?php 
            if ($is_depot) {
                echo 'selected="selected"';
            }
            ?>
><?php 
            _e('--- My depot ---', 'wppa');
            ?>
</option>
				<?php 
            wppa_walktree(WPPA_DEPOT, $source, true, true);
            // Allow the name 'wppa', exclude topdir
            if ($ngg_opts) {
                $nextgen_root = trim($ngg_opts['gallerypath'], '/');
                wppa_walktree($nextgen_root, $source, true, true, false);
                // Allow the name 'wppa', exclude topdir, do not allow 'thumbs' */
            }
            wppa_walktree(WPPA_UPLOAD, $source, false, false);
            // Do NOT allow the name 'wppa', include topdir
            ?>
			</select>
			<input type="submit" class="button-secundary" name="wppa-import-set-source-dir" value="<?php 
            _e('Set source directory', 'wppa');
            ?>
" />
			<?php 
        } else {
            ?>
			<input type="text" style="width:50%" name="wppa-source-remote" value="<?php 
            echo $source;
            ?>
" />
			<?php 
            _e('Max:', 'wppa');
            ?>
			<input type="text" style="width:50px;" name="wppa-import-remote-max" value="<?php 
            echo $remote_max;
            ?>
" />
			<input type="submit" onclick="jQuery( '#rem-rem' ).css( 'display','inline' ); return true;" class="button-secundary" name="wppa-import-set-source-url" value="<?php 
            _e('Find remote photos', 'wppa');
            ?>
" />
			<span id="rem-rem" style="display:none;"><?php 
            _e('Working, please wait...', 'wppa');
            ?>
</span>
			<?php 
            _e('<br />You can enter either a web page address like <i>http://mysite.com/mypage/</i> or a full url to an image file like <i>http://mysite.com/wp-content/uploads/wppa/4711.jpg</i>', 'wppa');
            ?>
			<?php 
        }
        ?>
		</div>
		
		<?php 
    }
    ?>
	</form>

<?php 
    // check if albums exist or will be made before allowing upload
    if (wppa_has_albums() || $albumcount > '0' || $zipcount > '0' || $dircount > '0' || $videocount > '0' || $audiocount > '0' || $csvcount > '0') {
        if ($photocount > '0' || $albumcount > '0' || $zipcount > '0' || $dircount > '0' || $videocount > '0' || $audiocount > '0' || $csvcount > '0') {
            ?>
			
				<form action="<?php 
            echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_import_photos');
            ?>
" method="post">
				<?php 
            wp_nonce_field('$wppa_nonce', WPPA_NONCE);
            // Display the zips
            if (PHP_VERSION_ID >= 50207 && $zipcount > '0') {
                ?>
	
					<div style="border:1px solid gray; padding:4px; margin: 3px 0;" >
						<p><b>
							<?php 
                _e('There are', 'wppa');
                echo ' ' . $zipcount . ' ';
                _e('zipfiles in the depot.', 'wppa');
                ?>
<br/>
						</b></p>
						<table class="form-table wppa-table widefat" style="margin-bottom:0;" >
							<thead>
								<tr>
									<td>
										<input type="checkbox" id="all-zip" checked="checked" onchange="checkAll( 'all-zip', '.wppa-zip' )" /><b>&nbsp;&nbsp;<?php 
                _e('Check/uncheck all', 'wppa');
                ?>
</b>
									</td>
									<?php 
                if ($is_sub_depot) {
                    ?>
										<td>
											<input type="checkbox" id="del-after-z" name="del-after-z" checked="checked" /><b>&nbsp;&nbsp;<?php 
                    _e('Delete after successful extraction.', 'wppa');
                    ?>
</b>
										</td>
									<?php 
                }
                ?>
								</tr>
							</thead>
						</table>
						<table class="form-table wppa-table widefat" style="margin-top:0;" >
							<tr>
								<?php 
                $ct = 0;
                $idx = '0';
                foreach ($files as $file) {
                    $ext = strtolower(substr(strrchr($file, "."), 1));
                    if ($ext == 'zip') {
                        ?>
										<td>
											<input type="checkbox" id="file-<?php 
                        echo $idx;
                        ?>
" name="file-<?php 
                        echo $idx;
                        ?>
" class="wppa-zip" checked="checked" />&nbsp;&nbsp;<?php 
                        echo wppa_sanitize_file_name(basename($file));
                        ?>
										</td>
										<?php 
                        if ($ct == 3) {
                            echo '</tr><tr>';
                            $ct = 0;
                        } else {
                            $ct++;
                        }
                    }
                    $idx++;
                }
                ?>
							</tr>
						</table>
					</div>
				<?php 
            }
            // Dispay the albums ( .amf files )
            if ($albumcount > '0') {
                ?>
					<div style="border:1px solid gray; padding:4px; margin: 3px 0;" >
						<p><b>
							<?php 
                _e('There are', 'wppa');
                echo ' ' . $albumcount . ' ';
                _e('albumdefinitions in the depot.', 'wppa');
                ?>
<br/>
						</b></p>
						<table class="form-table wppa-table widefat" style="margin-bottom:0;" >
							<thead>
								<tr>
									<td>
										<input type="checkbox" id="all-amf" checked="checked" onchange="checkAll( 'all-amf', '.wppa-amf' )" /><b>&nbsp;&nbsp;<?php 
                _e('Check/uncheck all', 'wppa');
                ?>
</b>
									</td>
									<?php 
                if ($is_sub_depot) {
                    ?>
										<td>
											<input type="checkbox" id="del-after-a" name="del-after-a" checked="checked" /><b>&nbsp;&nbsp;<?php 
                    _e('Remove from depot after successful import, or if the album already exists.', 'wppa');
                    ?>
</b>
										</td>
									<?php 
                }
                ?>
								</tr>
							</thead>
						</table>
						<table class="form-table wppa-table widefat"  style="margin-top:0;" >
							<tr>
								<?php 
                $ct = 0;
                $idx = '0';
                foreach ($files as $file) {
                    $ext = strtolower(substr(strrchr($file, "."), 1));
                    if ($ext == 'amf') {
                        ?>
										<td>
											<input type="checkbox" id="file-<?php 
                        echo $idx;
                        ?>
" name="file-<?php 
                        echo $idx;
                        ?>
" class="wppa-amf" checked="checked" />&nbsp;&nbsp;<?php 
                        echo basename($file);
                        ?>
&nbsp;<?php 
                        echo stripslashes(wppa_get_meta_name($file, '( '));
                        ?>
										</td>
										<?php 
                        if ($ct == 3) {
                            echo '</tr><tr>';
                            $ct = 0;
                        } else {
                            $ct++;
                        }
                    }
                    $idx++;
                }
                ?>
							</tr>
						</table>
					</div>
				<?php 
            }
            // Display the single photos
            if ($photocount > '0') {
                ?>
					<div style="border:1px solid gray; padding:4px; margin: 3px 0;" >
						<p><b>
							<?php 
                _e('There are', 'wppa');
                echo ' ' . $photocount . ' ';
                if ($source_type == 'local') {
                    if ($is_ngg) {
                        _e('photos in the ngg gallery.', 'wppa');
                    } else {
                        _e('photos in the depot.', 'wppa');
                    }
                } else {
                    _e('possible photos found remote.', 'wppa');
                }
                if (wppa_switch('wppa_resize_on_upload')) {
                    echo ' ';
                    _e('Photos will be downsized during import.', 'wppa');
                }
                ?>
<br/>
						</b></p>
						<p class="hideifupdate" >
							<?php 
                _e('Default album for import:', 'wppa');
                ?>
							<select name="wppa-photo-album" id="wppa-photo-album">
								<?php 
                echo wppa_album_select_a(array('path' => wppa_switch('wppa_hier_albsel'), 'selected' => get_option('wppa-photo-album-import-' . wppa_get_user(), '0'), 'addpleaseselect' => true, 'checkowner' => true, 'checkupload' => true));
                ?>
							</select>
							<?php 
                _e('Photos that have (<em>name</em>)[<em>album</em>] will be imported by that <em>name</em> in that <em>album</em>.', 'wppa');
                ?>
						</p>
						<?php 
                if (wppa_switch('wppa_watermark_on') && (wppa_switch('wppa_watermark_user') || current_user_can('wppa_settings'))) {
                    ?>
							<p>
								<?php 
                    _e('Apply watermark file:', 'wppa');
                    ?>
								<select name="wppa-watermark-file" id="wppa-watermark-file">
									<?php 
                    echo wppa_watermark_file_select();
                    ?>
								</select>
								<?php 
                    _e('Position:', 'wppa');
                    ?>
								<select name="wppa-watermark-pos" id="wppa-watermark-pos">
									<?php 
                    echo wppa_watermark_pos_select();
                    ?>
								</select>
							</p>
						<?php 
                }
                ?>
						<table class="form-table wppa-table widefat" style="margin-bottom:0;" >
							<thead>
								<tr>
									<td>
										<input type="checkbox" id="all-pho" <?php 
                if ($is_sub_depot) {
                    echo 'checked="checked"';
                }
                ?>
 onchange="checkAll( 'all-pho', '.wppa-pho' )" /><b>&nbsp;&nbsp;<?php 
                _e('Check/uncheck all', 'wppa');
                ?>
</b>
									</td>
									<?php 
                if ($is_sub_depot) {
                    ?>
										<td>
											<input type="checkbox" id="del-after-p" name="del-after-p" checked="checked" /><b>&nbsp;&nbsp;<?php 
                    _e('Remove from depot after successful import.', 'wppa');
                    ?>
</b>
										</td>
									<?php 
                }
                ?>
									<?php 
                if ($is_ngg) {
                    ?>
										<td>
											<input type="checkbox" id="cre-album" name="cre-album" checked="checked" value="<?php 
                    echo esc_attr(basename($source));
                    ?>
" /><b>&nbsp;&nbsp;<?php 
                    echo sprintf(__('Import into album <i>%s</i>.', 'wppa'), basename($source));
                    ?>
</b>
											<br /><small><?php 
                    _e('The album will be created if it does not exist', 'wppa');
                    ?>
</small>
										</td>
										<td>
											<input type="checkbox" id="use-backup" name="use-backup" checked="checked" /><b>&nbsp;&nbsp;<?php 
                    _e('Use backup if available', 'wppa');
                    ?>
</b>
										</td>
									<?php 
                }
                ?>
									<td>
										<input type="checkbox" id="wppa-update" onchange="impUpd( this, '#submit' )" name="wppa-update"><b>&nbsp;&nbsp;<?php 
                _e('Update existing photos', 'wppa');
                ?>
</b>
									</td>
									<td>
									<?php 
                if (wppa_switch('wppa_void_dups')) {
                    ?>
										<input type="hidden" id="wppa-nodups" name="wppa-nodups" value="true" />
									<?php 
                } else {
                    ?>
										<input type="checkbox" id="wppa-nodups" name="wppa-nodups" checked="checked" ><b>&nbsp;&nbsp;<?php 
                    _e('Do not create duplicates', 'wppa');
                    ?>
</b>
									<?php 
                }
                ?>
									</td>
									<?php 
                if (wppa_switch('wppa_import_preview')) {
                    ?>
										<td>
											<input type="checkbox" id="wppa-zoom" onclick="wppa_setCookie('zoompreview', this.checked, '365')" ><b>&nbsp;&nbsp;<?php 
                    _e('Zoom previews', 'wppa');
                    ?>
</b>
											<script type="text/javascript">if ( wppa_getCookie('zoompreview') == true ) { jQuery('#wppa-zoom').attr('checked', 'checked') }</script>
										</td>
									<?php 
                }
                ?>
								</tr>
							</thead>
						</table>				
						<table class="form-table wppa-table widefat" style="margin-top:0;" >
							<tr> 
								<?php 
                $ct = 0;
                $idx = '0';
                if (is_array($files)) {
                    foreach ($files as $file) {
                        $ext = strtolower(substr(strrchr($file, "."), 1));
                        $meta = wppa_strip_ext($file) . 'pmf';
                        if (in_array($ext, $wppa_supported_photo_extensions)) {
                            ?>
										<td id="td-file-<?php 
                            echo $idx;
                            ?>
" >
											<input type="checkbox" id="file-<?php 
                            echo $idx;
                            ?>
" name="file-<?php 
                            echo $idx;
                            ?>
" title="<?php 
                            echo $file;
                            ?>
" class= "wppa-pho" <?php 
                            if ($is_sub_depot) {
                                echo 'checked="checked"';
                            }
                            ?>
 /><span id="name-file-<?php 
                            echo $idx;
                            ?>
" >&nbsp;&nbsp;<?php 
                            echo wppa_sanitize_file_name(basename($file));
                            ?>
&nbsp;<?php 
                            echo stripslashes(wppa_get_meta_name($meta, '( '));
                            echo stripslashes(wppa_get_meta_album($meta, '['));
                            ?>
</span>
											<?php 
                            if (wppa_switch('wppa_import_preview')) {
                                if ($wppa['is_remote']) {
                                    if (strpos($file, '//res.cloudinary.com/') !== false) {
                                        $img_url = dirname($file) . '/h_144/' . basename($file);
                                    } else {
                                        $img_url = $file;
                                    }
                                } else {
                                    $img_url = str_replace(ABSPATH, home_url() . '/', $file);
                                }
                                ?>
											<img src="<?php 
                                echo $img_url;
                                ?>
" alt="N.A." style="max-height:48px;" onmouseover="if (jQuery('#wppa-zoom').attr('checked')) jQuery(this).css('max-height', '144px')" onmouseout="if (jQuery('#wppa-zoom').attr('checked')) jQuery(this).css('max-height', '48px')" />
											<?php 
                            }
                            ?>
										</td>
										<?php 
                            if ($ct == 3) {
                                echo '</tr><tr>';
                                $ct = 0;
                            } else {
                                $ct++;
                            }
                        }
                        $idx++;
                    }
                }
                ?>
							</tr>
						</table>
					</div>
				<?php 
            }
            // Display the videos
            if ($videocount > '0' && wppa_switch('enable_video')) {
                ?>
					<div style="border:1px solid gray; padding:4px; margin: 3px 0;" >
						<p><b>
							<?php 
                _e('There are', 'wppa');
                echo ' ' . $videocount . ' ';
                _e('videos in the depot.', 'wppa');
                ?>
<br/>
						</b></p>
						<p class="hideifupdate" >
							<?php 
                _e('Album to import to:', 'wppa');
                ?>
							<select name="wppa-video-album" id="wppa-video-album">
								<?php 
                echo wppa_album_select_a(array('path' => wppa_switch('wppa_hier_albsel'), 'selected' => get_option('wppa-video-album-import-' . wppa_get_user(), '0'), 'addpleaseselect' => true, 'checkowner' => true, 'checkupload' => true));
                ?>
							</select>
						</p>
						<table class="form-table wppa-table widefat" style="margin-bottom:0;" >
							<thead>
								<tr>
									<td>
										<input type="checkbox" id="all-video" checked="checked" onchange="checkAll( 'all-video', '.wppa-video' )" /><b>&nbsp;&nbsp;<?php 
                _e('Check/uncheck all', 'wppa');
                ?>
</b>
									</td>
									<?php 
                if ($is_sub_depot) {
                    ?>
										<td>
											<input type="checkbox" id="del-after-v" name="del-after-v" checked="checked" /><b>&nbsp;&nbsp;<?php 
                    _e('Remove from depot after successful import.', 'wppa');
                    ?>
</b>
										</td>
									<?php 
                }
                ?>
								</tr>
							</thead>
						</table>
						<table class="form-table wppa-table widefat" style="margin-top:0;" >
							<tr>
								<?php 
                $ct = 0;
                $idx = '0';
                if (is_array($files)) {
                    foreach ($files as $file) {
                        $ext = strtolower(substr(strrchr($file, "."), 1));
                        if (in_array($ext, $wppa_supported_video_extensions)) {
                            ?>
										<td>
											<input type="checkbox" id="file-<?php 
                            echo $idx;
                            ?>
" name="file-<?php 
                            echo $idx;
                            ?>
" title="<?php 
                            echo $file;
                            ?>
" class="wppa-video" checked="checked" /><span id="name-file-<?php 
                            echo $idx;
                            ?>
" >&nbsp;&nbsp;<?php 
                            echo wppa_sanitize_file_name(basename($file));
                            ?>
</span>
										</td>
										<?php 
                            if ($ct == 3) {
                                echo '</tr><tr>';
                                $ct = 0;
                            } else {
                                $ct++;
                            }
                        }
                        $idx++;
                    }
                }
                ?>
							</tr>
						</table>
					</div>
				<?php 
            }
            // Display the audios
            if ($audiocount > '0' && wppa_switch('enable_audio')) {
                ?>
					<div style="border:1px solid gray; padding:4px; margin: 3px 0;" >
						<p><b>
							<?php 
                _e('There are', 'wppa');
                echo ' ' . $audiocount . ' ';
                _e('audios in the depot.', 'wppa');
                ?>
<br/>
						</b></p>
						<p class="hideifupdate" >
							<?php 
                _e('Album to import to:', 'wppa');
                ?>
							<select name="wppa-audio-album" id="wppa-audio-album">
								<?php 
                echo wppa_album_select_a(array('path' => wppa_switch('wppa_hier_albsel'), 'selected' => get_option('wppa-audio-album-import-' . wppa_get_user(), '0'), 'addpleaseselect' => true, 'checkowner' => true, 'checkupload' => true));
                ?>
							</select>
						</p>
						<table class="form-table wppa-table widefat" style="margin-bottom:0;" >
							<thead>
								<tr>
									<td>
										<input type="checkbox" id="all-audio" checked="checked" onchange="checkAll( 'all-audio', '.wppa-audio' )" /><b>&nbsp;&nbsp;<?php 
                _e('Check/uncheck all', 'wppa');
                ?>
</b>
									</td>
									<?php 
                if ($is_sub_depot) {
                    ?>
										<td>
											<input type="checkbox" id="del-after-u" name="del-after-u" checked="checked" /><b>&nbsp;&nbsp;<?php 
                    _e('Remove from depot after successful import.', 'wppa');
                    ?>
</b>
										</td>
									<?php 
                }
                ?>
								</tr>
							</thead>
						</table>
						<table class="form-table wppa-table widefat" style="margin-top:0;" >
							<tr>
								<?php 
                $ct = 0;
                $idx = '0';
                if (is_array($files)) {
                    foreach ($files as $file) {
                        $ext = strtolower(substr(strrchr($file, "."), 1));
                        if (in_array($ext, $wppa_supported_audio_extensions)) {
                            ?>
										<td>
											<input type="checkbox" id="file-<?php 
                            echo $idx;
                            ?>
" name="file-<?php 
                            echo $idx;
                            ?>
" title="<?php 
                            echo $file;
                            ?>
" class="wppa-audio" checked="checked" /><span id="name-file-<?php 
                            echo $idx;
                            ?>
" >&nbsp;&nbsp;<?php 
                            echo wppa_sanitize_file_name(basename($file));
                            ?>
</span>
										</td>
										<?php 
                            if ($ct == 3) {
                                echo '</tr><tr>';
                                $ct = 0;
                            } else {
                                $ct++;
                            }
                        }
                        $idx++;
                    }
                }
                ?>
							</tr>
						</table>
					</div>
				<?php 
            }
            // Display the directories to be imported as albums. Do this in the depot only!!
            if ($is_depot && $dircount > '0') {
                ?>
					<div style="border:1px solid gray; padding:4px; margin: 3px 0;" >
						<p><b>
							<?php 
                _e('There are', 'wppa');
                echo ' ' . $dircount . ' ';
                _e('albumdirectories in the depot.', 'wppa');
                ?>
<br/>
						</b></p>
						<table class="form-table wppa-table widefat" style="margin-bottom:0;" >
							<thead>
								<tr>
									<td>
										<input type="checkbox" id="all-dir" checked="checked" onchange="checkAll( 'all-dir', '.wppa-dir' )" /><b>&nbsp;&nbsp;<?php 
                _e('Check/uncheck all', 'wppa');
                ?>
</b>
									</td>
								</tr>
							</thead>
						</table>				
						<table class="form-table wppa-table widefat" style="margin-top:0;" >
							<?php 
                $ct = 0;
                $idx = '0';
                foreach ($files as $dir) {
                    if (basename($dir) == '.') {
                    } elseif (basename($dir) == '..') {
                    } elseif (is_dir($dir)) {
                        ?>
										<tr>
											<td>
												<input type="checkbox" id="file-<?php 
                        echo $idx;
                        ?>
" name="file-<?php 
                        echo $idx;
                        ?>
" class= "wppa-dir" checked="checked" />&nbsp;&nbsp;<b><?php 
                        echo wppa_sanitize_file_name(basename($dir));
                        ?>
</b>
												<?php 
                        $subfiles = glob($dir . '/*');
                        $subdircount = '0';
                        if ($subfiles) {
                            foreach ($subfiles as $subfile) {
                                if (is_dir($subfile) && basename($subfile) != '.' && basename($subfile) != '..') {
                                    $subdircount++;
                                }
                            }
                        }
                        $sfcount = empty($subfiles) ? '0' : wppa_get_photocount($subfiles);
                        echo ' Contains ' . $sfcount . ' files';
                        if ($subdircount) {
                            echo ' and ' . $subdircount . ' sub directories.';
                        }
                        ?>
											</td>
										</tr>
									<?php 
                    }
                    $idx++;
                }
                ?>
						</table>
					</div>				
				<?php 
            }
            ?>
				<?php 
            // Display the csv files
            if ($is_depot && $csvcount > '0') {
                ?>
					<div style="border:1px solid gray; padding:4px; margin: 3px 0;" >
						<p><b>
							<?php 
                _e('There are', 'wppa');
                echo ' ' . $csvcount . ' ';
                _e('csv files in the depot.', 'wppa');
                ?>
<br/>
						</b></p>
						<table class="form-table wppa-table widefat" style="margin-bottom:0;" >
							<thead>
								<tr>
									<td>
										<input type="checkbox" id="all-csv" checked="checked" onchange="checkAll( 'all-csv', '.wppa-csv' )" /><b>&nbsp;&nbsp;<?php 
                _e('Check/uncheck all', 'wppa');
                ?>
</b>
									</td>
									<td>
										<input type="checkbox" id="del-after-c" name="del-after-c" checked="checked" disabled="disabled" /><b>&nbsp;&nbsp;<?php 
                _e('Remove from depot after successful import.', 'wppa');
                ?>
</b>
									</td>
								</tr>
							</thead>
						</table>				
						<table class="form-table wppa-table widefat" style="margin-top:0;" >
							<?php 
                $ct = 0;
                $idx = '0';
                foreach ($files as $csv) {
                    if (is_file($csv) && strtolower(wppa_get_ext($csv) == 'csv')) {
                        ?>
										<tr>
											<td>
												<input type="checkbox" id="file-<?php 
                        echo $idx;
                        ?>
" name="file-<?php 
                        echo $idx;
                        ?>
" class= "wppa-csv" checked="checked" />&nbsp;&nbsp;<b><?php 
                        echo wppa_sanitize_file_name(basename($csv)) . ' (' . sprintf('%5.1f', filesize($csv) / 1024) . ' kb)';
                        ?>
</b>
											</td>
										</tr>
									<?php 
                    }
                    $idx++;
                }
                ?>
						</table>
					</div>				
				
				<?php 
            }
            ?>
				<?php 
            // The submit button
            ?>
				<p>
					<script type="text/javascript">
						function wppaVfyAlbum() {
							var csvs = jQuery( '.wppa-csv' );
							if ( jQuery( '#wppa-update' ).attr( 'checked' ) != 'checked' ) {
								if ( 	! parseInt( jQuery( '#wppa-photo-album' ).attr( 'value' ) ) && 
										! parseInt( jQuery( '#wppa-video-album' ).attr( 'value' ) ) && 
										! parseInt( jQuery( '#wppa-audio-album' ).attr( 'value' ) ) &&
										csvs.length == 0
									) {
									alert( 'Please select an album first' );
									return false;
								}
							}
							return true;
						}
						function wppaCheckInputVars() {
							var checks = jQuery( ':checked' );
							var nChecks = checks.length;
							var nMax = <?php 
            echo ini_get('max_input_vars');
            ?>
;
							if ( nMax == 0 ) nMax = 100;
							if ( nChecks > nMax ) { 
								alert ( 'There are '+nChecks+' boxes checked or selected, that is more than the maximum allowed number of '+nMax );
								return false;
							}
							var dirs = jQuery( '.wppa-dir' );
							var nDirsChecked = 0;
							if ( dirs.length > 0 ) {
								var i = 0;
								while ( i < dirs.length ) {
									if ( jQuery( dirs[i] ).attr( 'checked' ) == 'checked' ) {
										nDirsChecked++;
									}
									i++;
								}
							}
							var zips = jQuery( '.wppa-zip' );
							var nZipsChecked = 0;
							if ( zips.length > 0 ) {
								var i = 0;
								while ( i < zips.length ) {
									if ( jQuery( zips[i] ).attr( 'checked' ) == 'checked' ) {
										nZipsChecked++;
									}
									i++;
								}
							}
							// If no dirs to import checked, there must be an album selected
							if ( 0 == nDirsChecked && 0 == nZipsChecked && ! wppaVfyAlbum() ) return false;
							return true;
						}
					</script>
					<input type="submit" onclick="return wppaCheckInputVars()" class="button-primary" id="submit" name="wppa-import-submit" value="<?php 
            _e('Import', 'wppa');
            ?>
" />
					<script type="text/javascript" >
						var wppaImportRuns = false;
						function wppaDoAjaxImport() {
							wppaImportRuns = true;
							var data = '';
							data += 'wppa-update-check='+jQuery( '#wppa-update-check' ).attr( 'value' );
							data += '&wppa-photo-album='+jQuery( '#wppa-photo-album' ).attr( 'value' );
							data += '&wppa-video-album='+jQuery( '#wppa-video-album' ).attr( 'value' );
							data += '&wppa-audio-album='+jQuery( '#wppa-audio-album' ).attr( 'value' );
							data += '&wppa-watermark-file='+jQuery( '#wppa-watermark-file' ).attr( 'value' );
							data += '&wppa-watermark-pos='+jQuery( '#wppa-watermark-pos' ).attr( 'value' );
							if ( jQuery( '#cre-album' ).attr( 'checked' ) ) data += '&cre-album='+jQuery( '#cre-album' ).attr( 'value' );
							if ( jQuery( '#use-backup' ).attr( 'checked' ) ) data += '&use-backup=on'; //+jQuery( '#use-backup' ).attr( 'value' );
							if ( jQuery( '#wppa-update' ).attr( 'checked' ) ) data += '&wppa-update=on'; //+jQuery( '#wppa-update' ).attr( 'value' );
							if ( jQuery( '#wppa-nodups' ).attr( 'checked' ) ) data += '&wppa-nodups=on'; //+jQuery( '#wppa-nudups' ).attr( 'value' );
							if ( jQuery( '#del-after-p' ).attr( 'checked' ) ) data += '&del-after-p=on';
							if ( jQuery( '#del-after-v' ).attr( 'checked' ) ) data += '&del-after-v=on';
							if ( jQuery( '#del-after-u' ).attr( 'checked' ) ) data += '&del-after-u=on';
							data += '&wppa-import-submit=ajax';
							
							var files = jQuery( ':checked' );
							var found = false;
							var i=0;
							var elm;
							var fulldata;
							for ( i=0; i<files.length; i++ ) {
								found = false;	// assume done
								elm = files[i];
								// Is it a file checkbox?
								var temp = elm.id.split( '-' );
								if ( temp[0] != 'file' ) continue;	// no
								fulldata = data+'&import-ajax-file='+elm.title;
								found = true;
								break;
							}
							//	alert( data );
							if ( ! found ) {
								wppaStopAjaxImport();
								return;	// nothing left
							}
							// found one, do it
							var oldhtml=jQuery( '#name-'+elm.id ).html();
							var xmlhttp = wppaGetXmlHttp();
							xmlhttp.onreadystatechange = function() {
								if ( xmlhttp.readyState == 4 ) {
									if ( xmlhttp.status!=404 ) {
										if ( jQuery( '#del-after-p' ).attr( 'checked' ) ) {
											elm.checked = '';
											elm.disabled = 'disabled';
											elm.title = '';
											jQuery( '#name-'+elm.id ).html( '&nbsp;&nbsp;<b>'+xmlhttp.responseText+'</b>' );
										}
										else {
											elm.checked = '';
											
											jQuery( '#name-'+elm.id ).html( '&nbsp;&nbsp;<b>'+xmlhttp.responseText+'</b>' );
										}
										if ( wppaImportRuns ) {
											setTimeout( 'wppaDoAjaxImport()', 100 );
										}
									}
									else {
										jQuery( '#name-'+elm.id ).html( '&nbsp;&nbsp;<b>Not found</b>' );
									}
								}
							}
							var url = wppaAjaxUrl+'?action=wppa&wppa-action=import';
							xmlhttp.open( 'POST',url,true );
							xmlhttp.setRequestHeader( "Content-type","application/x-www-form-urlencoded" );
							xmlhttp.send( fulldata );
							jQuery( '#name-'+elm.id ).html( '&nbsp;&nbsp;<b style="color:blue" >Working...</b>' );
							jQuery( '#wppa-start-ajax' ).css( 'display', 'none' );
							jQuery( '#wppa-stop-ajax' ).css( 'display', 'inline' );
						}
						function wppaStopAjaxImport() {
							wppaImportRuns = false;
							jQuery( '#wppa-start-ajax' ).css( 'display', 'inline' );
							jQuery( '#wppa-stop-ajax' ).css( 'display', 'none' );
						}
					</script>
					<?php 
            if (($photocount || $videocount || $audiocount) && !$albumcount && !$dircount && !$zipcount) {
                ?>
					<input id="wppa-start-ajax" type="button" onclick="if ( wppaVfyAlbum() ) { wppaDoAjaxImport() }" class="button-secundary" value="Start Ajax" />
					<input id="wppa-stop-ajax" style="display:none;" type="button" onclick="wppaStopAjaxImport()" class="button-secundary" value="Stop Ajax" />
					<?php 
            }
            ?>
				</p>
				</form>

		<?php 
        } else {
            if ($source_type == 'local') {
                wppa_ok_message(__('There are no importable files found in directory:', 'wppa') . ' ' . $source_url);
            } else {
                wppa_ok_message(__('There are no photos found or left to process at url:', 'wppa') . ' ' . $source_url);
            }
        }
        echo '<br /><b>';
        _e('You can import the following file types:', 'wppa');
        echo '</b><br />';
        if (PHP_VERSION_ID >= 50207) {
            echo '<br />';
            _e('Compressed file types: .zip', 'wppa');
        }
        if (true) {
            echo '<br />';
            _e('Photo file types:', 'wppa');
            foreach ($wppa_supported_photo_extensions as $ext) {
                echo ' .' . $ext;
            }
        }
        if (wppa_switch('enable_video')) {
            echo '<br />';
            _e('Video file types:', 'wppa');
            foreach ($wppa_supported_video_extensions as $ext) {
                echo ' .' . $ext;
            }
        }
        if (wppa_switch('enable_audio')) {
            echo '<br />';
            _e('Audio file types:', 'wppa');
            foreach ($wppa_supported_audio_extensions as $ext) {
                echo ' .' . $ext;
            }
        }
        echo '<br />';
        _e('WPPA+ file types: .amf .pmf', 'wppa');
        echo '<br />';
        _e('Directories with optional subdirs containig photos', 'wppa');
        echo '<br />';
        _e('Custom data files of type .csv', 'wppa');
        echo '<br /><br />';
        _e('Your depot directory is:', 'wppa');
        echo '<b> .../' . WPPA_DEPOT . '/</b>';
    } else {
        ?>
		<?php 
        $url = wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_admin_menu');
        ?>
		<p><?php 
        _e('No albums exist. You must', 'wppa');
        ?>
 <a href="<?php 
        echo $url;
        ?>
"><?php 
        _e('create one', 'wppa');
        ?>
</a> <?php 
        _e('beofre you can upload your photos.', 'wppa');
        ?>
</p><?php 
    }
    if ($wppa['continue']) {
        wppa_warning_message(__('Trying to continue...', 'wppa'));
        echo '<script type="text/javascript">document.location=\'' . get_admin_url() . 'admin.php?page=wppa_import_photos&continue&nonce=' . wp_create_nonce('dirimport') . '\';</script>';
    }
    ?>
	</div>
<?php 
}