function wppa_insert_photo($file = '', $alb = '', $name = '', $desc = '', $porder = '0', $id = '0', $linkurl = '', $linktitle = '')
{
    global $wpdb;
    global $warning_given_small;
    $album = wppa_cache_album($alb);
    if (!wppa_allow_uploads($alb)) {
        if (is_admin() && !wppa('ajax')) {
            wppa_error_message(sprintf(__('Album %s is full', 'wp-photo-album-plus'), wppa_get_album_name($alb)));
        } else {
            wppa_alert(sprintf(__('Album %s is full', 'wp-photo-album-plus'), wppa_get_album_name($alb)));
        }
        return false;
    }
    if ($file != '' && $alb != '') {
        // Get the name if not given
        if ($name == '') {
            $name = basename($file);
        }
        // Sanitize name
        $filename = wppa_sanitize_file_name($name);
        $name = wppa_sanitize_photo_name($name);
        // If not dups allowed and its already here, quit
        if (isset($_POST['wppa-nodups']) || wppa_switch('void_dups')) {
            $exists = wppa_file_is_in_album($filename, $alb);
            if ($exists) {
                if (isset($_POST['del-after-p'])) {
                    unlink($file);
                    $msg = __('Photo %s already exists in album number %s. Removed from depot.', 'wp-photo-album-plus');
                } else {
                    $msg = __('Photo %s already exists in album number %s.', 'wp-photo-album-plus');
                }
                wppa_warning_message(sprintf($msg, $name, $alb));
                return false;
            }
        }
        // Verify file exists
        if (!wppa('is_remote') && !file_exists($file)) {
            if (!is_dir(dirname($file))) {
                wppa_error_message('Error: Directory ' . dirname($file) . ' does not exist.');
                return false;
            }
            if (!is_writable(dirname($file))) {
                wppa_error_message('Error: Directory ' . dirname($file) . ' is not writable.');
                return false;
            }
            wppa_error_message('Error: File ' . $file . ' does not exist.');
            return false;
        }
        //		else {
        //			wppa_ok_message( 'Good: File '.$file.' exists.' );
        //		}
        // Get and verify the size
        $img_size = getimagesize($file);
        if ($img_size) {
            if (wppa_check_memory_limit('', $img_size['0'], $img_size['1']) === false) {
                wppa_error_message(sprintf(__('ERROR: Attempt to upload a photo that is too large to process (%s).', 'wp-photo-album-plus'), $name) . wppa_check_memory_limit());
                wppa('ajax_import_files_error', __('Too big', 'wp-photo-album-plus'));
                return false;
            }
            if (!$warning_given_small && ($img_size['0'] < wppa_get_minisize() && $img_size['1'] < wppa_get_minisize())) {
                wppa_warning_message(__('WARNING: You are uploading photos that are too small. Photos must be larger than the thumbnail size and larger than the coverphotosize.', 'wp-photo-album-plus'));
                wppa('ajax_import_files_error', __('Too small', 'wp-photo-album-plus'));
                $warning_given_small = true;
            }
        } else {
            wppa_error_message(__('ERROR: Unable to retrieve image size of', 'wp-photo-album-plus') . ' ' . $name . ' ' . __('Are you sure it is a photo?', 'wp-photo-album-plus'));
            wppa('ajax_import_files_error', __('No imagesize', 'wp-photo-album-plus'));
            return false;
        }
        // Get ext based on mimetype, regardless of ext
        switch ($img_size[2]) {
            // mime type
            case 1:
                $ext = 'gif';
                break;
            case 2:
                $ext = 'jpg';
                break;
            case 3:
                $ext = 'png';
                break;
            default:
                wppa_error_message(__('Unsupported mime type encountered:', 'wp-photo-album-plus') . ' ' . $img_size[2] . '.');
                return false;
        }
        // Get an id if not yet there
        if ($id == '0') {
            $id = wppa_nextkey(WPPA_PHOTOS);
        }
        // Get opt deflt desc if empty
        if ($desc == '' && wppa_switch('apply_newphoto_desc')) {
            $desc = stripslashes(wppa_opt('newphoto_description'));
        }
        // Reset rating
        $mrat = '0';
        // Find ( new ) owner
        $owner = wppa_get_user();
        // Validate album
        if (!is_numeric($alb) || $alb < '1') {
            wppa_error_message(__('Album not known while trying to add a photo', 'wp-photo-album-plus'));
            return false;
        }
        if (!wppa_have_access($alb)) {
            wppa_error_message(sprintf(__('Album %s does not exist or is not accessable while trying to add a photo', 'wp-photo-album-plus'), $alb));
            return false;
        }
        $status = wppa_switch('upload_moderate') && !current_user_can('wppa_admin') ? 'pending' : 'publish';
        // Add photo to db
        $id = wppa_create_photo_entry(array('id' => $id, 'album' => $alb, 'ext' => $ext, 'name' => $name, 'p_order' => $porder, 'description' => $desc, 'linkurl' => $linkurl, 'linktitle' => $linktitle, 'owner' => $owner, 'status' => $status, 'filename' => $filename));
        if (!$id) {
            wppa_error_message(__('Could not insert photo.', 'wp-photo-album-plus'));
        } else {
            // Save the source
            wppa_save_source($file, $filename, $alb);
            wppa_flush_treecounts($alb);
            wppa_update_album(array('id' => $alb, 'modified' => time()));
            wppa_flush_upldr_cache('photoid', $id);
        }
        // Make the photo files
        if (wppa_make_the_photo_files($file, $id, $ext)) {
            // Repair photoname if not supplied and not standard
            wppa_set_default_name($id, $name);
            // Tags
            wppa_set_default_tags($id);
            // Index
            wppa_index_add('photo', $id);
            // and add watermark ( optionally ) to fullsize image only
            wppa_add_watermark($id);
            // also to thumbnail?
            if (wppa_switch('watermark_thumbs')) {
                wppa_create_thumbnail($id);
            }
            // Is it a default coverimage?
            wppa_check_coverimage($id);
            return $id;
        }
    } else {
        wppa_error_message(__('ERROR: Unknown file or album.', 'wp-photo-album-plus'));
        return false;
    }
}
function wppa_do_frontend_file_upload($file, $alb)
{
    global $wpdb;
    // Log upload attempt
    wppa_log('Upl', 'FE Upload attempt of file ' . $file['name'] . ', size=' . filesize($file['tmp_name']));
    $album = wppa_cache_album($alb);
    if (!wppa_allow_uploads($alb) || !wppa_allow_user_uploads()) {
        wppa_alert(__('Max uploads reached', 'wp-photo-album-plus'));
        return false;
    }
    if ($file['error'] != '0') {
        wppa_alert(__('Error during upload', 'wp-photo-album-plus'));
        return false;
    }
    $imgsize = getimagesize($file['tmp_name']);
    if (!is_array($imgsize)) {
        wppa_alert(__('Uploaded file is not an image', 'wp-photo-album-plus'));
        return false;
    }
    if ($imgsize[2] < 1 || $imgsize[2] > 3) {
        wppa_alert(sprintf(__('Only gif, jpg and png image files are supported. Returned filetype = %d.', 'wp-photo-album-plus'), $imagesize[2]));
        return false;
    }
    $ms = wppa_opt('upload_fronend_maxsize');
    if ($ms) {
        // Max size configured
        if ($imgsize[0] > $ms || $imgsize[0] > $ms) {
            wppa_alert(sprintf(__('Uploaded file is larger than the allowed maximum of %d x %d pixels.', 'wp-photo-album-plus'), $ms, $ms));
            return false;
        }
    }
    if (wppa_switch('void_dups')) {
        // Check for already exists
        if (wppa_file_is_in_album(wppa_sanitize_file_name($file['name']), $alb)) {
            wppa_alert(sprintf(__('Uploaded file %s already exists in this album.', 'wp-photo-album-plus'), wppa_sanitize_file_name($file['name'])));
            return false;
        }
    }
    $mayupload = wppa_check_memory_limit('', $imgsize[0], $imgsize[1]);
    if ($mayupload === false) {
        $maxsize = wppa_check_memory_limit(false);
        if (is_array($maxsize)) {
            wppa_alert(sprintf(__('The image is too big. Max photo size: %d x %d (%2.1f MegaPixel)', 'wp-photo-album-plus'), $maxsize['maxx'], $maxsize['maxy'], $maxsize['maxp'] / (1024 * 1024)));
            return false;
        }
    }
    switch ($imgsize[2]) {
        // mime type
        case 1:
            $ext = 'gif';
            break;
        case 2:
            $ext = 'jpg';
            break;
        case 3:
            $ext = 'png';
            break;
    }
    if (wppa_get_post('user-name')) {
        $name = wppa_get_post('user-name');
    } else {
        $name = $file['name'];
    }
    $name = wppa_sanitize_photo_name($name);
    $desc = balanceTags(wppa_get_post('user-desc'), true);
    $linktarget = '_self';
    $status = wppa_switch('upload_moderate') && !current_user_can('wppa_admin') ? 'pending' : 'publish';
    $filename = wppa_sanitize_file_name($file['name']);
    $id = wppa_create_photo_entry(array('album' => $alb, 'ext' => $ext, 'name' => $name, 'description' => $desc, 'status' => $status, 'filename' => $filename));
    if (!$id) {
        wppa_alert(__('Could not insert photo into db.', 'wp-photo-album-plus'));
        return false;
    } else {
        wppa_save_source($file['tmp_name'], $filename, $alb);
        wppa_update_album(array('id' => $alb, 'modified' => time()));
        wppa_flush_treecounts($alb);
        wppa_flush_upldr_cache('photoid', $id);
    }
    if (wppa_make_the_photo_files($file['tmp_name'], $id, $ext)) {
        // Repair photoname if not standard
        if (!wppa_get_post('user-name')) {
            wppa_set_default_name($id, $file['name']);
        }
        // Custom data
        if (wppa_switch('fe_custom_fields')) {
            $custom_data = array('', '', '', '', '', '', '', '', '', '');
            for ($i = '0'; $i < '10'; $i++) {
                if (isset($_POST['wppa-user-custom-' . $i])) {
                    $custom_data[$i] = strip_tags($_POST['wppa-user-custom-' . $i]);
                }
            }
            wppa_update_photo(array('id' => $id, 'custom' => serialize($custom_data)));
        }
        // Default tags
        wppa_set_default_tags($id);
        // Custom tags
        $tags = wppa_get_photo_item($id, 'tags');
        $oldt = $tags;
        for ($i = '1'; $i < '4'; $i++) {
            if (isset($_POST['wppa-user-tags-' . $i])) {
                // Existing tags
                $tags .= ',' . implode(',', $_POST['wppa-user-tags-' . $i]);
            }
        }
        if (isset($_POST['wppa-new-tags'])) {
            // New tags
            $newt = $_POST['wppa-new-tags'];
            $tags .= ',' . $newt;
        } else {
            $newt = '';
        }
        $tags = wppa_sanitize_tags(str_replace(array('\'', '"'), ',', wppa_filter_iptc(wppa_filter_exif($tags, $id), $id)));
        if ($tags != $oldt) {
            // Added tag(s)
            wppa_update_photo(array('id' => $id, 'tags' => $tags));
        }
        // Index
        wppa_index_add('photo', $id);
        // Tags
        if ($tags) {
            wppa_clear_taglist();
            // Forces recreation
        }
        // and add watermark ( optionally ) to fullsize image only
        wppa_add_watermark($id);
        // Also to thumbnail?
        if (wppa_switch('watermark_thumbs')) {
            wppa_create_thumbnail($id);
            // create new thumb
        }
        // Is it a default coverimage?
        wppa_check_coverimage($id);
        // Mail
        if (wppa_switch('upload_notify')) {
            $to = get_bloginfo('admin_email');
            $subj = sprintf(__('New photo uploaded: %s', 'wp-photo-album-plus'), $name);
            $cont['0'] = sprintf(__('User %1$s uploaded photo %2$s into album %3$s', 'wp-photo-album-plus'), wppa_get_user(), $id, wppa_get_album_name($alb));
            if (wppa_switch('upload_moderate') && !current_user_can('wppa_admin')) {
                $cont['1'] = __('This upload requires moderation', 'wp-photo-album-plus');
                $cont['2'] = '<a href="' . get_admin_url() . 'admin.php?page=wppa_admin_menu&tab=pmod&photo=' . $id . '" >' . __('Moderate manage photo', 'wp-photo-album-plus') . '</a>';
            } else {
                $cont['1'] = __('Details:', 'wp-photo-album-plus');
                $cont['1'] .= ' <a href="' . get_admin_url() . 'admin.php?page=wppa_admin_menu&tab=pmod&photo=' . $id . '" >' . __('Manage photo', 'wp-photo-album-plus') . '</a>';
            }
            wppa_send_mail($to, $subj, $cont, $id);
        }
        return true;
    } else {
        return false;
    }
}
function wppa_album_select_a($args)
{
    global $wpdb;
    $args = wp_parse_args($args, array('exclude' => '', 'selected' => '', 'disabled' => '', 'addpleaseselect' => false, 'addnone' => false, 'addall' => false, 'addgeneric' => false, 'addblank' => false, 'addselected' => false, 'addseparate' => false, 'addselbox' => false, 'disableancestors' => false, 'checkaccess' => false, 'checkowner' => false, 'checkupload' => false, 'addmultiple' => false, 'addnumbers' => false, 'path' => false, 'root' => false, 'content' => false, 'sort' => true));
    // Provide default selection if no selected given
    if ($args['selected'] === '') {
        $args['selected'] = wppa_get_last_album();
    }
    // See if selection is valid
    if ($args['selected'] == $args['exclude'] || $args['checkupload'] && !wppa_allow_uploads($args['selected']) || $args['disableancestors'] && wppa_is_ancestor($args['exclude'], $args['selected'])) {
        $args['selected'] = '0';
    }
    $albums = $wpdb->get_results("SELECT * FROM `" . WPPA_ALBUMS . "` " . wppa_get_album_order($args['root']), ARRAY_A);
    // Add to secondary cache
    if ($albums) {
        wppa_cache_album('add', $albums);
    }
    if ($albums) {
        // Filter for root
        if ($args['root']) {
            $root = $args['root'];
            switch ($root) {
                // case '0': all, will be skipped as it returns false in 'if ( $args['root'] )'
                case '-2':
                    // Generic only
                    foreach (array_keys($albums) as $albidx) {
                        if (wppa_is_separate($albums[$albidx]['id'])) {
                            unset($albums[$albidx]);
                        }
                    }
                    break;
                case '-1':
                    // Separate only
                    foreach (array_keys($albums) as $albidx) {
                        if (!wppa_is_separate($albums[$albidx]['id'])) {
                            unset($albums[$albidx]);
                        }
                    }
                    break;
                default:
                    foreach (array_keys($albums) as $albidx) {
                        if (!wppa_is_ancestor($root, $albums[$albidx]['id'])) {
                            unset($albums[$albidx]);
                        }
                    }
                    break;
            }
        }
        // Filter for must have content
        if ($args['content']) {
            foreach (array_keys($albums) as $albidx) {
                if (wppa_get_photo_count($albums[$albidx]['id']) <= wppa_get_mincount()) {
                    unset($albums[$albidx]);
                }
            }
        }
        // Add paths
        if ($args['path']) {
            $albums = wppa_add_paths($albums);
        } else {
            foreach (array_keys($albums) as $index) {
                $albums[$index]['name'] = __(stripslashes($albums[$index]['name']));
            }
        }
        // Sort
        if ($args['sort']) {
            $albums = wppa_array_sort($albums, 'name');
        }
    }
    // Output
    $result = '';
    $selected = $args['selected'] == '0' ? ' selected="selected"' : '';
    if ($args['addpleaseselect']) {
        $result .= '<option value="0" disabled="disabled" ' . $selected . ' >' . (is_admin() ? __('- select an album -', 'wppa') : __a('- select an album -')) . '</option>';
    }
    $selected = $args['selected'] == '0' ? ' selected="selected"' : '';
    if ($args['addnone']) {
        $result .= '<option value="0"' . $selected . ' >' . (is_admin() ? __('--- none ---', 'wppa') : __a('--- none ---')) . '</option>';
    }
    $selected = $args['selected'] == '0' ? ' selected="selected"' : '';
    if ($args['addall']) {
        $result .= '<option value="0"' . $selected . ' >' . (is_admin() ? __('--- all ---', 'wppa') : __a('--- all ---')) . '</option>';
    }
    $selected = $args['selected'] == '-2' ? ' selected="selected"' : '';
    if ($args['addall']) {
        $result .= '<option value="-2"' . $selected . ' >' . (is_admin() ? __('--- generic ---', 'wppa') : __a('--- generic ---')) . '</option>';
    }
    $selected = $args['selected'] == '0' ? ' selected="selected"' : '';
    if ($args['addblank']) {
        $result .= '<option value="0"' . $selected . ' >' . '</option>';
    }
    $selected = $args['selected'] == '-99' ? ' selected="selected"' : '';
    if ($args['addmultiple']) {
        $result .= '<option value="-99"' . $selected . ' >' . (is_admin() ? __('--- multiple see below ---', 'wppa') : __a('--- multiple see below ---')) . '</option>';
    }
    $selected = $args['selected'] == '0' ? ' selected="selected"' : '';
    if ($args['addselbox']) {
        $result .= '<option value="0"' . $selected . ' >' . (is_admin() ? __('--- a selection box ---', 'wppa') : __a('--- a selection box ---')) . '</option>';
    }
    if ($albums) {
        foreach ($albums as $album) {
            if ($args['disabled'] == $album['id'] || $args['exclude'] == $album['id'] || $args['checkupload'] && !wppa_allow_uploads($album['id']) || $args['disableancestors'] && wppa_is_ancestor($args['exclude'], $album['id'])) {
                $disabled = ' disabled="disabled"';
            } else {
                $disabled = '';
            }
            if ($args['selected'] == $album['id'] && !$disabled) {
                $selected = ' selected="selected"';
            } else {
                $selected = '';
            }
            $ok = true;
            // Assume this will be in the list
            if ($args['checkaccess'] && !wppa_have_access($album['id'])) {
                $ok = false;
            }
            if ($args['checkowner'] && wppa_switch('upload_owner_only')) {
                // Need to check
                if ($album['owner'] != wppa_get_user() && $album['owner'] != '--- public ---') {
                    // Not 'mine'
                    if (!wppa_user_is('administrator')) {
                        // No admin
                        $ok = false;
                    }
                }
            }
            if ($selected && $args['addselected']) {
                $ok = true;
            }
            if ($ok) {
                if ($args['addnumbers']) {
                    $number = ' ( ' . $album['id'] . ' )';
                } else {
                    $number = '';
                }
                $result .= '<option value="' . $album['id'] . '" ' . $selected . $disabled . '>' . $album['name'] . $number . '</option>';
            }
        }
    }
    $selected = $args['selected'] == '-1' ? ' selected="selected"' : '';
    if ($args['addseparate']) {
        $result .= '<option value="-1"' . $selected . '>' . (is_admin() ? __('--- separate ---', 'wppa') : __a('--- separate ---')) . '</option>';
    }
    return $result;
}
예제 #4
0
function wppa_get_user_upload_html($alb, $width, $where = '', $mcr = false)
{
    static $seqno;
    // Init
    $result = '';
    $mocc = wppa('mocc');
    $occur = wppa('occur');
    // Using seqno to distinguish from different places within one occurrence because
    // the album no is not known when there is a selection box.
    if ($seqno) {
        $seqno++;
    } else {
        $seqno = '1';
    }
    // Feature enabled?
    if (!wppa_switch('user_upload_on')) {
        return '';
    }
    // Login required?
    if (wppa_switch('user_upload_login')) {
        if (!is_user_logged_in()) {
            return '';
        }
    }
    // I should have access to this album ( $alb > 0 ).
    if ($alb > '0') {
        $album_owner = wppa_get_album_item($alb, 'owner');
        if ($album_owner != wppa_get_user() && $album_owner != '--- public ---' && !wppa_have_access($alb)) {
            return '';
        }
    } else {
        if (!wppa_have_access()) {
            return '';
        }
    }
    // Find max files for the user
    $allow_me = wppa_allow_user_uploads();
    if (!$allow_me) {
        if (wppa_switch('show_album_full')) {
            $result .= '<div style="clear:both"></div>' . '<span style="color:red">' . __('Max uploads reached', 'wp-photo-album-plus') . wppa_time_to_wait_html('0', true) . '</span>';
        }
        return $result;
    }
    // Find max files for the album
    $allow_alb = wppa_allow_uploads($alb);
    if (!$allow_alb) {
        if (wppa_switch('show_album_full')) {
            $result .= '<div style="clear:both"></div>' . '<span style="color:red">' . __('Max uploads reached', 'wp-photo-album-plus') . wppa_time_to_wait_html($alb) . '</span>';
        }
        return $result;
    }
    if (wppa_is_user_blacklisted()) {
        return '';
    }
    // Find max files for the system
    $allow_sys = ini_get('max_file_uploads');
    // THE max
    if ($allow_me == '-1') {
        $allow_me = $allow_sys;
    }
    if ($allow_alb == '-1') {
        $allow_alb = $allow_sys;
    }
    $max = min($allow_me, $allow_alb, $allow_sys);
    // In a widget or multi column responsive?
    $small = wppa_in_widget() == 'upload' || $mcr;
    // Ajax upload?
    $ajax_upload = wppa_switch('ajax_upload') && wppa_browser_can_html5();
    //					&&
    // WINDOWS 10 / Edge bug
    //					! strpos( $_SERVER["HTTP_USER_AGENT"], 'Edge' ) &&
    //					! strpos( $_SERVER["HTTP_USER_AGENT"], 'Windows NT 10.0' );
    // Create the return url
    if ($ajax_upload) {
        $returnurl = wppa_switch('ajax_non_admin') ? WPPA_URL . '/wppa-ajax-front.php' : admin_url('admin-ajax.php');
        $returnurl .= '?action=wppa&amp;wppa-action=do-fe-upload';
    } else {
        $returnurl = wppa_get_permalink();
        if ($where == 'cover') {
            $returnurl .= 'wppa-album=' . $alb . '&amp;wppa-cover=0&amp;wppa-occur=' . $occur;
        } elseif ($where == 'thumb') {
            $returnurl .= 'wppa-album=' . $alb . '&amp;wppa-cover=0&amp;wppa-occur=' . $occur;
        } elseif ($where == 'widget' || $where == 'uploadbox') {
        }
        if (wppa('page')) {
            $returnurl .= '&amp;wppa-page=' . wppa('page');
        }
        $returnurl = trim($returnurl, '?');
        $returnurl = wppa_trim_wppa_($returnurl);
    }
    // Make the HTML
    $t = $mcr ? 'mcr-' : '';
    $result .= '<div style="clear:both"></div>' . '<a' . ' id="wppa-up-' . $alb . '-' . $mocc . '"' . ' class="wppa-upload-' . $where . '"' . ' onclick="' . 'jQuery( \'#wppa-file-' . $t . $alb . '-' . $mocc . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#wppa-up-' . $alb . '-' . $mocc . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#wppa-cr-' . $alb . '-' . $mocc . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#wppa-ea-' . $alb . '-' . $mocc . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#wppa-cats-' . $alb . '-' . $mocc . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#_wppa-up-' . $alb . '-' . $mocc . '\' ).css( \'display\',\'block\' );' . '_wppaDoAutocol( ' . $mocc . ' )' . '"' . ' style="float:left; cursor:pointer;' . '" >' . __('Upload Photo', 'wp-photo-album-plus') . '</a>' . '<a' . ' id="_wppa-up-' . $alb . '-' . $mocc . '"' . ' class="wppa-upload-' . $where . '"' . ' onclick="' . 'jQuery( \'#wppa-file-' . $t . $alb . '-' . $mocc . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#wppa-cr-' . $alb . '-' . $mocc . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#wppa-up-' . $alb . '-' . $mocc . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#wppa-ea-' . $alb . '-' . $mocc . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#wppa-cats-' . $alb . '-' . $mocc . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#_wppa-up-' . $alb . '-' . $mocc . '\' ).css( \'display\',\'none\' );' . '_wppaDoAutocol( ' . $mocc . ' )' . '"' . ' style="float:right; cursor:pointer;display:none;' . '" >' . __(wppa_opt('close_text'), 'wp-photo-album-plus') . '</a>' . '<div' . ' id="wppa-file-' . $t . $alb . '-' . $mocc . '"' . ' class="wppa-file-' . $t . $mocc . '"' . ' style="width:' . $width . 'px;text-align:center;display:none; clear:both;"' . ' >' . '<form' . ' id="wppa-uplform-' . $alb . '-' . $mocc . '"' . ' action="' . $returnurl . '"' . ' method="post"' . ' enctype="multipart/form-data"' . ' >' . wppa_nonce_field('wppa-check', 'wppa-nonce', false, false, $alb);
    // If no album given: select one
    if (!$alb) {
        $result .= '<select' . ' id="wppa-upload-album-' . $mocc . '-' . $seqno . '"' . ' name="wppa-upload-album"' . ' style="float:left; max-width: ' . $width . 'px;"' . ' onchange="jQuery( \'#wppa-sel-' . $alb . '-' . $mocc . '\' ).trigger( \'onchange\' )"' . ' >' . wppa_album_select_a(array('addpleaseselect' => true, 'checkowner' => true, 'checkupload' => true, 'path' => wppa_switch('hier_albsel'))) . '</select>' . '<br />';
    } else {
        $result .= '<input' . ' type="hidden"' . ' id="wppa-upload-album-' . $mocc . '-' . $seqno . '"' . ' name="wppa-upload-album"' . ' value="' . $alb . '"' . ' />';
    }
    // One only ?
    if (wppa_switch('upload_one_only') && !current_user_can('administrator')) {
        $result .= '<input' . ' type="file"' . ' accept="image/*"' . (wppa_switch('camera_connect') ? ' capture="capture"' : '') . ' class="wppa-user-file"' . ' style="' . 'width:auto;' . 'max-width:' . $width . ';' . 'margin:6px 0;' . 'float:left;' . __wcs('wppa-box-text') . '"' . ' id="wppa-user-upload-' . $alb . '-' . $mocc . '"' . ' name="wppa-user-upload-' . $alb . '-' . $mocc . '[]"' . ' onchange="jQuery( \'#wppa-user-submit-' . $alb . '-' . $mocc . '\' ).css( \'display\', \'block\' )"' . ' />';
    } else {
        $result .= '<input' . ' type="file"' . ' accept="image/*"' . (wppa_switch('camera_connect') ? ' capture="capture"' : '') . ' multiple="multiple"' . ' class="wppa-user-file"' . ' style="' . 'width:auto;' . 'max-width:' . $width . ';' . 'margin:6px 0;' . 'float:left;' . __wcs('wppa-box-text') . '"' . ' id="wppa-user-upload-' . $alb . '-' . $mocc . '"' . ' name="wppa-user-upload-' . $alb . '-' . $mocc . '[]"' . ' onchange="jQuery( \'#wppa-user-submit-' . $alb . '-' . $mocc . '\' ).css( \'display\', \'block\' )"' . ' />';
    }
    // Explanation
    if (!wppa_switch('upload_one_only') && !current_user_can('administrator')) {
        if ($max) {
            $result .= '<span style="font-size:10px;" >' . sprintf(_n('You may upload %d photo', 'You may upload up to %d photos at once if your browser supports HTML-5 multiple file upload', $max, 'wp-photo-album-plus'), $max) . '</span>';
            $maxsize = wppa_check_memory_limit(false);
            if (is_array($maxsize)) {
                $result .= '<br />' . '<span style="font-size:10px;" >' . sprintf(__('Max photo size: %d x %d (%2.1f MegaPixel)', 'wp-photo-album-plus'), $maxsize['maxx'], $maxsize['maxy'], $maxsize['maxp'] / (1024 * 1024)) . '</span>';
            }
        }
    }
    // Copyright notice
    if (wppa_switch('copyright_on')) {
        $result .= '<div style="clear:both;" >' . __(wppa_opt('copyright_notice'), 'wp-photo-album-plus') . '</div>';
    }
    // Watermark
    if (wppa_switch('watermark_on') && wppa_switch('watermark_user')) {
        $result .= '<table' . ' class="wppa-watermark wppa-box-text"' . ' style="margin:0; border:0; ' . __wcs('wppa-box-text') . '"' . ' >' . '<tbody>' . '<tr valign="top" style="border: 0 none; " >' . '<td' . ' class="wppa-box-text wppa-td"' . ' style="' . __wcs('wppa-box-text') . __wcs('wppa-td') . '"' . ' >' . __('Apply watermark file:', 'wp-photo-album-plus') . '</td>' . '</tr>' . '<tr>' . '<td' . ' class="wppa-box-text wppa-td"' . ' style="width: ' . $width . ';' . __wcs('wppa-box-text') . __wcs('wppa-td') . '"' . ' >' . '<select' . ' style="margin:0; padding:0; text-align:left; width:auto; "' . ' name="wppa-watermark-file"' . ' id="wppa-watermark-file"' . ' >' . wppa_watermark_file_select() . '</select>' . '</td>' . '</tr>' . '<tr valign="top" style="border: 0 none; " >' . '<td' . ' class="wppa-box-text wppa-td"' . ' style="width: ' . $width . ';' . __wcs('wppa-box-text') . __wcs('wppa-td') . '"' . ' >' . __('Position:', 'wp-photo-album-plus') . '</td>' . ($small ? '</tr><tr>' : '') . '<td' . ' class="wppa-box-text wppa-td"' . ' style="width: ' . $width . ';' . __wcs('wppa-box-text') . __wcs('wppa-td') . '"' . ' >' . '<select' . ' style="margin:0; padding:0; text-align:left; width:auto; "' . ' name="wppa-watermark-pos"' . ' id="wppa-watermark-pos"' . ' >' . wppa_watermark_pos_select() . '</select>' . '</td>' . '</tr>' . '</tbody>' . '</table>';
    }
    // Name
    if (wppa_switch('name_user')) {
        switch (wppa_opt('newphoto_name_method')) {
            case 'none':
                $expl = '';
                break;
            case '2#005':
                $expl = __('If you leave this blank, iptc tag 005 (Graphic name) will be used as photoname if available, else the original filename will be used as photo name.', 'wp-photo-album-plus');
                break;
            case '2#120':
                $expl = __('If you leave this blank, iptc tag 120 (Caption) will be used as photoname if available, else the original filename will be used as photo name.', 'wp-photo-album-plus');
                break;
            default:
                $expl = __('If you leave this blank, the original filename will be used as photo name.', 'wp-photo-album-plus');
        }
        $result .= '<div' . ' class="wppa-box-text wppa-td"' . ' style="' . 'clear:both;' . 'float:left;' . 'text-align:left;' . __wcs('wppa-box-text') . __wcs('wppa-td') . '"' . ' >' . __('Enter photo name', 'wp-photo-album-plus') . '&nbsp;' . '<span style="font-size:10px;" >' . $expl . '</span>' . '</div>' . '<input' . ' type="text"' . ' class="wppa-box-text wppa-file-' . $t . $mocc . '"' . ' style="padding:0; width:' . ($width - 6) . 'px; ' . __wcs('wppa-box-text') . '"' . ' name="wppa-user-name"' . ' />';
    }
    // Description user fillable ?
    if (wppa_switch('desc_user')) {
        $desc = wppa_switch('apply_newphoto_desc_user') ? stripslashes(wppa_opt('newphoto_description')) : '';
        $result .= '<div' . ' class="wppa-box-text wppa-td"' . ' style="clear:both; float:left; text-align:left; ' . __wcs('wppa-box-text') . __wcs('wppa-td') . '"' . ' >' . __('Enter/modify photo description', 'wp-photo-album-plus') . '</div>' . '<textarea' . ' class="wppa-user-textarea wppa-box-text wppa-file-' . $t . $mocc . '"' . ' style="height:120px; width:' . ($width - 6) . 'px; ' . __wcs('wppa-box-text') . '"' . ' name="wppa-user-desc"' . ' >' . $desc . '</textarea>';
    } elseif (wppa_switch('apply_newphoto_desc_user')) {
        $result .= '<input' . ' type="hidden"' . ' value="' . esc_attr(wppa_opt('newphoto_description')) . '"' . ' name="wppa-user-desc"' . ' />';
    }
    // Custom fields
    if (wppa_switch('fe_custom_fields')) {
        for ($i = '0'; $i < '10'; $i++) {
            if (wppa_opt('custom_caption_' . $i)) {
                $result .= '<div' . ' class="wppa-box-text wppa-td"' . ' style="clear:both; float:left; text-align:left; ' . __wcs('wppa-box-text') . __wcs('wppa-td') . '"' . ' >' . __(wppa_opt('custom_caption_' . $i), 'wp-photo-album-plus') . ': ' . (wppa_switch('custom_visible_' . $i) ? '' : '&nbsp;<small><i>(&nbsp;' . __('hidden', 'wp-photo-album-plus') . '&nbsp;)</i></small>') . '</div>' . '<input' . ' type="text"' . ' class="wppa-box-text wppa-file-' . $t . $mocc . '"' . ' style="padding:0; width:' . ($width - 6) . 'px; ' . __wcs('wppa-box-text') . '"' . ' name="wppa-user-custom-' . $i . '"' . ' />';
            }
        }
    }
    // Tags
    if (wppa_switch('fe_upload_tags')) {
        // Prepare onclick action
        $onc = 'wppaPrevTags(\'wppa-sel-' . $alb . '-' . $mocc . '\', \'wppa-inp-' . $alb . '-' . $mocc . '\', \'wppa-upload-album-' . $mocc . '-' . $seqno . '\', \'wppa-prev-' . $alb . '-' . $mocc . '\')';
        // Open the tag enter area
        $result .= '<div class="wppa-box-text wppa-td" style="clear:both; float:left; text-align:left; ' . __wcs('wppa-box-text') . __wcs('wppa-td') . '" >';
        // Selection boxes 1..3
        for ($i = '1'; $i < '4'; $i++) {
            if (wppa_switch('up_tagselbox_on_' . $i)) {
                $result .= '<div style="float:left; margin-right:4px;" >' . '<small>' . __(wppa_opt('up_tagselbox_title_' . $i), 'wp-photo-album-plus') . '</small><br />' . '<select' . ' id="wppa-sel-' . $alb . '-' . $mocc . '-' . $i . '"' . ' style="float:left; margin-right: 4px;"' . ' name="wppa-user-tags-' . $i . '[]"' . (wppa_switch('up_tagselbox_multi_' . $i) ? ' multiple' : '') . ' onchange="' . $onc . '"' . ' >';
                if (wppa_opt('up_tagselbox_content_' . $i)) {
                    // List of tags supplied
                    $tags = explode(',', wppa_opt('up_tagselbox_content_' . $i));
                    $result .= '<option value="" >&nbsp;</option>';
                    if (is_array($tags)) {
                        foreach ($tags as $tag) {
                            $result .= '<option class="wppa-sel-' . $alb . '-' . $mocc . '" value="' . $tag . '">' . $tag . '</option>';
                        }
                    }
                } else {
                    // All existing tags
                    $tags = wppa_get_taglist();
                    $result .= '<option value="" >&nbsp;</option>';
                    if (is_array($tags)) {
                        foreach ($tags as $tag) {
                            $result .= '<option class="wppa-sel-' . $alb . '-' . $mocc . '" value="' . $tag['tag'] . '">' . $tag['tag'] . '</option>';
                        }
                    }
                }
                $result .= '</select>' . '</div>';
            }
        }
        // New tags
        if (wppa_switch('up_tag_input_on')) {
            $result .= '<div style="float:left; margin-right:4px;" >' . '<small>' . __(wppa_opt('up_tag_input_title'), 'wp-photo-album-plus') . '</small><br />' . '<input' . ' id="wppa-inp-' . $alb . '-' . $mocc . '"' . ' type="text"' . ' class="wppa-box-text"' . ' style="padding:0; width:150px; ' . __wcs('wppa-box-text') . '"' . ' name="wppa-new-tags"' . ' onchange="' . $onc . '"' . ' />' . '</div>';
        }
        // Preview area
        if (wppa_switch('up_tag_preview')) {
            $result .= '<div style="margin:0; clear:both;" >' . __('Preview tags:', 'wp-photo-album-plus') . ' <small id="wppa-prev-' . $alb . '-' . $mocc . '"></small>' . '</div>' . '<script type="text/javascript" >jQuery( document ).ready(function() {' . $onc . '})</script>';
        }
        // Close tag enter area
        $result .= '</div>';
    }
    /* start submit section */
    // Onclick submit verify album is known
    if (!$alb) {
        $onclick = ' onclick="if ( document.getElementById( \'wppa-upload-album-' . $mocc . '-' . $seqno . '\' ).value == 0 )' . ' {alert( \'' . esc_js(__('Please select an album and try again', 'wp-photo-album-plus')) . '\' );return false;}"';
    } else {
        $onclick = '';
    }
    // The submit button
    $result .= '<input' . ' type="submit"' . ' id="wppa-user-submit-' . $alb . '-' . $mocc . '"' . $onclick . ' style="display:none; margin: 6px 0; float:right; ' . __wcs('wppa-box-text') . '"' . ' class="wppa-user-submit"' . ' name="wppa-user-submit-' . $alb . '-' . $mocc . '" value="' . __('Upload photo', 'wp-photo-album-plus') . '"' . ' />' . '<div style="clear:both"></div>';
    // if ajax: progression bar
    if ($ajax_upload) {
        $result .= '<div' . ' id="progress-' . $alb . '-' . $mocc . '"' . ' class="wppa-progress"' . ' style="border-color:' . wppa_opt('bcolor_upload') . '"' . ' >' . '<div id="bar-' . $alb . '-' . $mocc . '" class="wppa-bar" ></div>' . '<div id="percent-' . $alb . '-' . $mocc . '" class="wppa-percent" >0%</div >' . '</div>' . '<div id="message-' . $alb . '-' . $mocc . '" class="wppa-message" ></div>';
    }
    /* End submit section */
    // Done
    $result .= '</form></div>';
    // Ajax upload script
    if ($ajax_upload) {
        $result .= '<script>' . 'jQuery(document).ready(function() {

					var options = {
						beforeSend: function() {
							jQuery("#progress-' . $alb . '-' . $mocc . '").show();
							//clear everything
							jQuery("#bar-' . $alb . '-' . $mocc . '").width(\'0%\');
							jQuery("#message-' . $alb . '-' . $mocc . '").html("");
							jQuery("#percent-' . $alb . '-' . $mocc . '").html("");
						},
						uploadProgress: function(event, position, total, percentComplete) {
							jQuery("#bar-' . $alb . '-' . $mocc . '").width(percentComplete+\'%\');
							if ( percentComplete < 95 ) {
								jQuery("#percent-' . $alb . '-' . $mocc . '").html(percentComplete+\'%\');
							}
							else {
								jQuery("#percent-' . $alb . '-' . $mocc . '").html(\'Processing...\');
							}
						},
						success: function() {
							jQuery("#bar-' . $alb . '-' . $mocc . '").width(\'100%\');
							jQuery("#percent-' . $alb . '-' . $mocc . '").html(\'Done!\');
						},
						complete: function(response) {
							jQuery("#message-' . $alb . '-' . $mocc . '").html( \'<span style="font-size: 10px;" >\'+response.responseText+\'</span>\' );' . ($where == 'thumb' ? 'document.location.reload(true)' : '') . '
						},
						error: function() {
							jQuery("#message-' . $alb . '-' . $mocc . '").html( \'<span style="color: red;" >' . __('ERROR: unable to upload files.', 'wp-photo-album-plus') . '</span>\' );
						}
					};

					jQuery("#wppa-uplform-' . $alb . '-' . $mocc . '").ajaxForm(options);
				});
			</script>';
    }
    return $result;
}
function wppa_do_frontend_file_upload($file, $alb)
{
    global $wpdb;
    global $wppa_supported_video_extensions;
    global $wppa_supported_audio_extensions;
    // Log upload attempt
    wppa_log('Upl', 'FE Upload attempt of file ' . $file['name'] . ', size=' . filesize($file['tmp_name']));
    $album = wppa_cache_album($alb);
    // Legal here?
    if (!wppa_allow_uploads($alb) || !wppa_allow_user_uploads()) {
        wppa_alert(__('Max uploads reached', 'wp-photo-album-plus'));
        return false;
    }
    // No error during upload?
    if ($file['error'] != '0') {
        wppa_alert(__('Error during upload', 'wp-photo-album-plus'));
        return false;
    }
    // Find the filename
    $filename = wppa_sanitize_file_name($file['name']);
    $filename = wppa_strip_ext($filename);
    // See if this filename with any extension already exists in this album
    $id = $wpdb->get_var("SELECT `id` FROM `" . WPPA_PHOTOS . "` WHERE `filename` LIKE '" . $filename . ".%' AND `album` = " . $alb);
    // Addition to an av item?
    if ($id) {
        $is_av = wppa_get_photo_item($id, 'ext') == 'xxx';
    } else {
        $is_av = false;
    }
    // see if audio / video and process
    if (wppa_switch('enable_video') && wppa_switch('user_upload_video_on') && in_array(strtolower(wppa_get_ext($file['name'])), $wppa_supported_video_extensions) || wppa_switch('enable_audio') && wppa_switch('user_upload_audio_on') && in_array(strtolower(wppa_get_ext($file['name'])), $wppa_supported_audio_extensions)) {
        $is_av = true;
        // Find the name
        if (wppa_get_post('user-name')) {
            $name = wppa_get_post('user-name');
        } else {
            $name = $file['name'];
        }
        $name = wppa_sanitize_photo_name($name);
        $filename .= '.xxx';
        // update entry
        if ($id) {
            wppa_update_photo(array('id' => $id, 'ext' => 'xxx', 'filename' => $filename));
        }
        // Add new entry
        if (!$id) {
            $id = wppa_create_photo_entry(array('album' => $alb, 'filename' => $filename, 'ext' => 'xxx', 'name' => $name, 'description' => balanceTags(wppa_get_post('user-desc'), true)));
            if (!$id) {
                wppa_alert(__('Could not insert media into db.', 'wp-photo-album-plus'));
                return false;
            }
        }
        // Housekeeping
        wppa_update_album(array('id' => $alb, 'modified' => time()));
        wppa_flush_treecounts($alb);
        wppa_flush_upldr_cache('photoid', $id);
        // Add video filetype
        $ext = strtolower(wppa_get_ext($file['name']));
        $newpath = wppa_strip_ext(wppa_get_photo_path($id)) . '.' . $ext;
        copy($file['tmp_name'], $newpath);
        // Repair name if not standard
        if (!wppa_get_post('user-name')) {
            wppa_set_default_name($id, $file['name']);
        }
        // tags
        wppa_fe_add_tags($id);
        // custom
        wppa_fe_add_custom($id);
        // Done!
        return $id;
    }
    // If not already an existing audio / video; Forget the id from a previously found item with the same filename.
    if (!$is_av) {
        $id = false;
    }
    // Is it an image?
    $imgsize = getimagesize($file['tmp_name']);
    if (!is_array($imgsize)) {
        wppa_alert(__('Uploaded file is not an image', 'wp-photo-album-plus'));
        return false;
    }
    // Is it a supported image filetype?
    if ($imgsize[2] != IMAGETYPE_GIF && $imgsize[2] != IMAGETYPE_JPEG && $imgsize[2] != IMAGETYPE_PNG) {
        wppa_alert(sprintf(__('Only gif, jpg and png image files are supported. Returned info = %s.', 'wp-photo-album-plus'), wppa_serialize($imgsize)), false, false);
        return false;
    }
    // Is it not too big?
    $ms = wppa_opt('upload_fronend_maxsize');
    if ($ms) {
        // Max size configured
        if ($imgsize[0] > $ms || $imgsize[1] > $ms) {
            wppa_alert(sprintf(__('Uploaded file is larger than the allowed maximum of %d x %d pixels.', 'wp-photo-album-plus'), $ms, $ms));
            return false;
        }
    }
    // Check for already exists
    if (wppa_switch('void_dups')) {
        if (wppa_file_is_in_album(wppa_sanitize_file_name($file['name']), $alb)) {
            wppa_alert(sprintf(__('Uploaded file %s already exists in this album.', 'wp-photo-album-plus'), wppa_sanitize_file_name($file['name'])));
            return false;
        }
    }
    // Check for max memory needed to rocess image?
    $mayupload = wppa_check_memory_limit('', $imgsize[0], $imgsize[1]);
    if ($mayupload === false) {
        $maxsize = wppa_check_memory_limit(false);
        if (is_array($maxsize)) {
            wppa_alert(sprintf(__('The image is too big. Max photo size: %d x %d (%2.1f MegaPixel)', 'wp-photo-album-plus'), $maxsize['maxx'], $maxsize['maxy'], $maxsize['maxp'] / (1024 * 1024)));
            return false;
        }
    }
    // Find extension from mimetype
    switch ($imgsize[2]) {
        // mime type
        case 1:
            $ext = 'gif';
            break;
        case 2:
            $ext = 'jpg';
            break;
        case 3:
            $ext = 'png';
            break;
    }
    // Did the user supply a photoname?
    if (wppa_get_post('user-name')) {
        $name = wppa_get_post('user-name');
    } else {
        $name = $file['name'];
    }
    // Sanitize input
    $name = wppa_sanitize_photo_name($name);
    $desc = balanceTags(wppa_get_post('user-desc'), true);
    // If BlogIt! and no descrption given, use name field - this is for the shortcode used: typ"mphoto"
    if (!$desc && isset($_POST['wppa-blogit'])) {
        $desc = 'w#name';
    }
    // Find status and other needed data
    $linktarget = '_self';
    $status = wppa_switch('upload_moderate') && !current_user_can('wppa_admin') ? 'pending' : 'publish';
    if (wppa_switch('fe_upload_private')) {
        $status = 'private';
    }
    $filename = wppa_sanitize_file_name($file['name']);
    // Create new entry if this is not a posterfile
    if (!$is_av) {
        $id = wppa_create_photo_entry(array('album' => $alb, 'ext' => $ext, 'name' => $name, 'description' => $desc, 'status' => $status, 'filename' => $filename));
    }
    if (!$id) {
        wppa_alert(__('Could not insert photo into db.', 'wp-photo-album-plus'));
        return false;
    } else {
        wppa_save_source($file['tmp_name'], $filename, $alb);
        wppa_make_o1_source($id);
        wppa_update_album(array('id' => $alb, 'modified' => time()));
        wppa_flush_treecounts($alb);
        wppa_flush_upldr_cache('photoid', $id);
    }
    if (wppa_make_the_photo_files($file['tmp_name'], $id, $ext)) {
        // Repair photoname if not standard
        if (!wppa_get_post('user-name')) {
            wppa_set_default_name($id, $file['name']);
        }
        // Custom data
        wppa_fe_add_custom($id);
        // Add tags
        wppa_fe_add_tags($id);
        // and add watermark ( optionally ) to fullsize image only
        wppa_add_watermark($id);
        // Also to thumbnail?
        if (wppa_switch('watermark_thumbs')) {
            wppa_create_thumbnail($id);
            // create new thumb
        }
        // Is it a default coverimage?
        wppa_check_coverimage($id);
        // Mail
        if (wppa_switch('upload_notify')) {
            $to = get_bloginfo('admin_email');
            $subj = sprintf(__('New photo uploaded: %s', 'wp-photo-album-plus'), $name);
            $cont['0'] = sprintf(__('User %1$s uploaded photo %2$s into album %3$s', 'wp-photo-album-plus'), wppa_get_user(), $id, wppa_get_album_name($alb));
            if (wppa_switch('upload_moderate') && !current_user_can('wppa_admin')) {
                $cont['1'] = __('This upload requires moderation', 'wp-photo-album-plus');
                $cont['2'] = '<a href="' . get_admin_url() . 'admin.php?page=wppa_admin_menu&tab=pmod&photo=' . $id . '" >' . __('Moderate manage photo', 'wp-photo-album-plus') . '</a>';
            } else {
                $cont['1'] = __('Details:', 'wp-photo-album-plus');
                $cont['1'] .= ' <a href="' . get_admin_url() . 'admin.php?page=wppa_admin_menu&tab=pmod&photo=' . $id . '" >' . __('Manage photo', 'wp-photo-album-plus') . '</a>';
            }
            wppa_send_mail($to, $subj, $cont, $id);
        }
        return $id;
    }
    return false;
}
function wppa_ajax_callback()
{
    global $wpdb;
    global $wppa_session;
    wppa('ajax', true);
    wppa('error', '0');
    wppa('out', '');
    $wppa_session['page']--;
    $wppa_session['ajax']++;
    wppa_save_session();
    // ALTHOUGH IF WE ARE HERE AS FRONT END VISITOR, is_admin() is true.
    // So, $wppa_opt switches are 'yes' or 'no' and not true or false.
    // So, always use the function wppa_switch( $slug ) to test on a bool setting
    // Globally check query args to prevent php injection
    $wppa_args = array('album', 'photo', 'slide', 'cover', 'occur', 'woccur', 'searchstring', 'topten', 'lasten', 'comten', 'featen', 'single', 'photos-only', 'debug', 'relcount', 'upldr', 'owner', 'rootsearch');
    foreach ($_REQUEST as $arg) {
        if (in_array(str_replace('wppa-', '', $arg), $wppa_args)) {
            if (strpos($arg, '<?') !== false) {
                die('Security check failure #91');
            }
            if (strpos($arg, '?>') !== false) {
                die('Security check failure #92');
            }
        }
    }
    wppa_vfy_arg('wppa-action', true);
    wppa_vfy_arg('photo-id');
    wppa_vfy_arg('comment-id');
    wppa_vfy_arg('moccur');
    wppa_vfy_arg('comemail', true);
    wppa_vfy_arg('comname', true);
    wppa_vfy_arg('tag', true);
    $wppa_action = $_REQUEST['wppa-action'];
    switch ($wppa_action) {
        case 'getssiptclist':
            $tag = str_replace('H', '#', $_REQUEST['tag']);
            $mocc = $_REQUEST['moccur'];
            $oldvalue = '';
            if (strpos($wppa_session['supersearch'], ',') !== false) {
                $ss_data = explode(',', $wppa_session['supersearch']);
                if (count($ss_data) == '4') {
                    if ($ss_data['0'] == 'p') {
                        if ($ss_data['1'] == 'i') {
                            if ($ss_data['2'] == $_REQUEST['tag']) {
                                $oldvalue = $ss_data['3'];
                            }
                        }
                    }
                }
            }
            $iptcdata = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_IPTC . "` WHERE `photo` > '0' AND `tag` = %s ORDER BY `description`", $tag), ARRAY_A);
            $last = '';
            $any = false;
            if (is_array($iptcdata)) {
                foreach ($iptcdata as $item) {
                    $desc = sanitize_text_field($item['description']);
                    $desc = str_replace(array(chr(0), chr(1), chr(2), chr(3), chr(4), chr(5), chr(6), chr(7)), '', $desc);
                    if ($desc != $last) {
                        $sel = $oldvalue && $oldvalue == $desc ? 'selected="selected"' : '';
                        if ($sel) {
                            echo 'selected:' . $oldvalue;
                        }
                        $ddesc = strlen($desc) > '32' ? substr($desc, 0, 30) . '...' : $desc;
                        echo '<option' . ' value="' . esc_attr($desc) . '"' . ' class="wppa-iptclist-' . $mocc . '"' . ' ' . $sel . ' >' . $ddesc . '</option>';
                        $last = $desc;
                        $any = true;
                    }
                }
            }
            if (!$any) {
                $query = $wpdb->prepare("DELETE FROM `" . WPPA_IPTC . "` WHERE `photo` = '0' AND `tag` = %s", $tag);
                $wpdb->query($query);
                //				wppa_log( 'dbg', $query );
            }
            wppa_exit();
            break;
        case 'getssexiflist':
            $tag = str_replace('H', '#', $_REQUEST['tag']);
            $mocc = $_REQUEST['moccur'];
            $oldvalue = '';
            if (strpos($wppa_session['supersearch'], ',') !== false) {
                $ss_data = explode(',', $wppa_session['supersearch']);
                if (count($ss_data) == '4') {
                    if ($ss_data['0'] == 'p') {
                        if ($ss_data['1'] == 'e') {
                            if ($ss_data['2'] == $_REQUEST['tag']) {
                                $oldvalue = $ss_data['3'];
                            }
                        }
                    }
                }
            }
            $exifdata = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_EXIF . "` WHERE `photo` > '0' AND `tag` = %s ORDER BY `description`", $tag), ARRAY_A);
            $last = '';
            $any = false;
            if (is_array($exifdata)) {
                foreach ($exifdata as $item) {
                    $desc = sanitize_text_field($item['description']);
                    $desc = str_replace(array(chr(0), chr(1), chr(2), chr(3), chr(4), chr(5), chr(6), chr(7)), '', $desc);
                    if ($desc != $last) {
                        $sel = $oldvalue && $oldvalue == $desc ? 'selected="selected"' : '';
                        $ddesc = strlen($desc) > '32' ? substr($desc, 0, 30) . '...' : $desc;
                        echo '<option' . ' value="' . esc_attr($desc) . '"' . ' class="wppa-exiflist-' . $mocc . '"' . ' ' . $sel . ' >' . $ddesc . '</option>';
                        $last = $desc;
                        $any = true;
                    }
                }
            }
            if (!$any) {
                $query = $wpdb->prepare("DELETE FROM `" . WPPA_EXIF . "` WHERE `photo` = '0' AND `tag` = %s", $tag);
                $wpdb->query($query);
                //				wppa_log( 'dbg', $query );
            }
            wppa_exit();
            break;
        case 'front-edit':
            if (!isset($_REQUEST['photo-id'])) {
                die('Missing required argument');
            }
            $photo = $_REQUEST['photo-id'];
            $ok = false;
            if (current_user_can('wppa_admin')) {
                $ok = true;
            }
            if (wppa_get_user() == wppa_get_photo_owner($photo) && (current_user_can('wppa_upload') || is_user_logged_in() && wppa_switch('upload_edit'))) {
                $ok = true;
            }
            if (!$ok) {
                die('You do not have sufficient rights to do this');
            }
            require_once 'wppa-photo-admin-autosave.php';
            wppa('front_edit', true);
            echo '	<div style="padding-bottom:4px;height:24px;" >
						<span style="color:#777;" >
							<i>' . __('All modifications are instantly updated on the server. The <b style="color:#070" >Remark</b> field keeps you informed on the actions taken at the background.', 'wp-photo-album-plus') . '</i>
						</span>
						<input id="wppa-fe-exit" type="button" style="float:right;color:red;font-weight:bold;" onclick="window.opener.location.reload( true );window.close();" value="' . __('Exit & Refresh', 'wp-photo-album-plus') . '" />
						<div id="wppa-fe-count" style="float:right;" ></div>
					</div><div style="clear:both;"></div>';
            wppa_album_photos('', $photo);
            wppa_exit();
            break;
        case 'do-comment':
            // Security check
            $mocc = $_REQUEST['moccur'];
            $nonce = $_REQUEST['wppa-nonce'];
            if (!wp_verify_nonce($nonce, 'wppa-nonce-' . $mocc)) {
                _e('Security check failure', 'wp-photo-album-plus');
                wppa_exit();
            }
            // Correct the fact that this is a non-admin operation, if it is only
            if (is_admin()) {
                require_once 'wppa-non-admin.php';
            }
            wppa('mocc', $_REQUEST['moccur']);
            wppa('comment_photo', isset($_REQUEST['photo-id']) ? $_REQUEST['photo-id'] : '0');
            wppa('comment_id', isset($_REQUEST['comment-edit']) ? $_REQUEST['comment-edit'] : '0');
            $comment_allowed = !wppa_switch('comment_login') || is_user_logged_in();
            if (wppa_switch('show_comments') && $comment_allowed) {
                //				if ( wppa_switch( 'search_comments' ) ) wppa_index_remove( 'photo', $_REQUEST['photo-id'] );
                wppa_do_comment($_REQUEST['photo-id']);
                // Process the comment
                if (wppa_switch('search_comments')) {
                    wppa_index_update('photo', $_REQUEST['photo-id']);
                }
            }
            wppa('no_esc', true);
            echo wppa_comment_html($_REQUEST['photo-id'], $comment_allowed);
            // Retrieve the new commentbox content
            wppa_exit();
            break;
        case 'import':
            require_once 'wppa-upload.php';
            _wppa_page_import();
            wppa_exit();
            break;
        case 'approve':
            $iret = '0';
            if (!current_user_can('wppa_moderate') && !current_user_can('wppa_comments')) {
                _e('You do not have the rights to moderate photos this way', 'wp-photo-album-plus');
                wppa_exit();
            }
            if (isset($_REQUEST['photo-id']) && current_user_can('wppa_moderate')) {
                $iret = $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_PHOTOS . "` SET `status` = 'publish' WHERE `id` = %s", $_REQUEST['photo-id']));
                wppa_flush_upldr_cache('photoid', $_REQUEST['photo-id']);
                $alb = $wpdb->get_var($wpdb->prepare("SELECT `album` FROM `" . WPPA_PHOTOS . "` WHERE `id` = %s", $_REQUEST['photo-id']));
                wppa_clear_taglist();
                wppa_flush_treecounts($alb);
            }
            if (isset($_REQUEST['comment-id'])) {
                $iret = $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_COMMENTS . "` SET `status` = 'approved' WHERE `id` = %s", $_REQUEST['comment-id']));
            }
            if ($iret) {
                echo 'OK';
            } else {
                if (isset($_REQUEST['photo-id'])) {
                    if (current_user_can('wppa_moderate')) {
                        echo sprintf(__('Failed to update stutus of photo %s', 'wp-photo-album-plus'), $_REQUEST['photo-id']) . "\n" . __('Please refresh the page', 'wp-photo-album-plus');
                    } else {
                        _e('Security check failure', 'wp-photo-album-plus');
                    }
                }
                if (isset($_REQUEST['comment-id'])) {
                    echo sprintf(__('Failed to update stutus of comment %s', 'wp-photo-album-plus'), $_REQUEST['comment-id']) . "\n" . __('Please refresh the page', 'wp-photo-album-plus');
                }
            }
            wppa_exit();
        case 'remove':
            if (isset($_REQUEST['photo-id'])) {
                // Remove photo
                if (wppa_user_is('administrator') || current_user_can('wppa_moderate') || wppa_get_user() == wppa_get_photo_owner($_REQUEST['photo-id']) && wppa_switch('upload_edit')) {
                    // Frontend delete?
                    wppa_delete_photo($_REQUEST['photo-id']);
                    echo 'OK||' . __('Photo removed', 'wp-photo-album-plus');
                    wppa_exit();
                }
            }
            if (!current_user_can('wppa_moderate') && !current_user_can('wppa_comments')) {
                _e('You do not have the rights to moderate photos this way', 'wp-photo-album-plus');
                wppa_exit();
            }
            if (isset($_REQUEST['photo-id'])) {
                // Remove photo
                if (!current_user_can('wppa_moderate')) {
                    _e('Security check failure', 'wp-photo-album-plus');
                    wppa_exit();
                }
                wppa_delete_photo($_REQUEST['photo-id']);
                echo 'OK||' . __('Photo removed', 'wp-photo-album-plus');
                wppa_exit();
            }
            if (isset($_REQUEST['comment-id'])) {
                // Remove comment
                $iret = $wpdb->query($wpdb->prepare("DELETE FROM `" . WPPA_COMMENTS . "` WHERE `id`= %s", $_REQUEST['comment-id']));
                if ($iret) {
                    echo 'OK||' . __('Comment removed', 'wp-photo-album-plus');
                } else {
                    _e('Could not remove comment', 'wp-photo-album-plus');
                }
                wppa_exit();
            }
            _e('Unexpected error', 'wp-photo-album-plus');
            wppa_exit();
        case 'downloadalbum':
            // Feature enabled?
            if (!wppa_switch('allow_download_album')) {
                echo '||ER||' . __('This feature is not enabled on this website', 'wp-photo-album-plus');
                wppa_exit();
            }
            // Validate args
            $alb = $_REQUEST['album-id'];
            $status = "`status` <> 'pending' AND `status` <> 'scheduled'";
            if (!is_user_logged_in()) {
                $status .= " AND `status` <> 'private'";
            }
            $photos = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `album` = %s AND ( ( " . $status . " ) OR owner = %s ) " . wppa_get_photo_order($alb), $alb, wppa_get_user()), ARRAY_A);
            if (!$photos) {
                echo '||ER||' . __('The album is empty', 'wp-photo-album-plus');
                wppa_exit();
            }
            // Remove obsolete files
            wppa_delete_obsolete_tempfiles();
            // Open zipfile
            if (!class_exists('ZipArchive')) {
                echo '||ER||' . __('Unable to create zip archive', 'wp-photo-album-plus');
                wppa_exit();
            }
            $zipfilename = wppa_get_album_name($alb);
            $zipfilename = wppa_sanitize_file_name($zipfilename . '.zip');
            // Remove illegal chars
            $zipfilepath = WPPA_UPLOAD_PATH . '/temp/' . $zipfilename;
            if (is_file($zipfilepath)) {
                //		unlink( $zipfilepath );	// Debug
            }
            $wppa_zip = new ZipArchive();
            $iret = $wppa_zip->open($zipfilepath, 1);
            if ($iret !== true) {
                echo '||ER||' . sprintf(__('Unable to create zip archive. code = %s', 'wp-photo-album-plus'), $iret);
                wppa_exit();
            }
            // Add photos to zip
            $stop = false;
            foreach ($photos as $p) {
                if (wppa_is_time_up()) {
                    wppa_log('obs', 'Time up during album to zip creation');
                    $stop = true;
                } else {
                    $id = $p['id'];
                    if (!wppa_is_multi($id)) {
                        $source = wppa_switch('download_album_source') && is_file(wppa_get_source_path($id)) ? wppa_get_source_path($id) : wppa_get_photo_path($id);
                        if (is_file($source)) {
                            $dest = $p['filename'] ? wppa_sanitize_file_name($p['filename']) : wppa_sanitize_file_name(wppa_strip_ext($p['name']) . '.' . $p['ext']);
                            $dest = wppa_fix_poster_ext($dest, $id);
                            $iret = $wppa_zip->addFile($source, $dest);
                            // To prevent too may files open, and to have at least a file when there are too many photos, close and re-open
                            $wppa_zip->close();
                            $wppa_zip->open($zipfilepath);
                            // wppa_log( 'dbg', 'Added ' . basename($source) . ' to ' . basename($zipfilepath));
                        }
                    }
                }
                if ($stop) {
                    break;
                }
            }
            // Close zip and return
            $zipcount = $wppa_zip->numFiles;
            $wppa_zip->close();
            // A zip is created
            $desturl = WPPA_UPLOAD_URL . '/temp/' . $zipfilename;
            echo $desturl . '||OK||';
            if ($zipcount != count($photos)) {
                echo sprintf(__('Only %s out of %s photos could be added to the zipfile', 'wp-photo-album-plus'), $zipcount, count($photos));
            }
            wppa_exit();
            break;
        case 'getalbumzipurl':
            $alb = $_REQUEST['album-id'];
            $zipfilename = wppa_get_album_name($alb);
            $zipfilename = wppa_sanitize_file_name($zipfilename . '.zip');
            // Remove illegal chars
            $zipfilepath = WPPA_UPLOAD_PATH . '/temp/' . $zipfilename;
            $zipfileurl = WPPA_UPLOAD_URL . '/temp/' . $zipfilename;
            if (is_file($zipfilepath)) {
                echo $zipfileurl;
            } else {
                echo 'ER';
            }
            wppa_exit();
            break;
        case 'makeorigname':
            $photo = $_REQUEST['photo-id'];
            $from = $_REQUEST['from'];
            if ($from == 'fsname') {
                $type = wppa_opt('art_monkey_link');
            } elseif ($from == 'popup') {
                $type = wppa_opt('art_monkey_popup_link');
            } else {
                echo '||7||' . __('Unknown source of request', 'wp-photo-album-plus');
                wppa_exit();
            }
            $data = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `id` = %s", $photo), ARRAY_A);
            if ($data) {
                // The photo is supposed to exist
                // Make the name
                if ($data['filename']) {
                    $name = $data['filename'];
                } else {
                    $name = __($data['name'], 'wp-photo-album-plus');
                }
                $name = wppa_sanitize_file_name($name);
                // Remove illegal chars
                $name = preg_replace('/\\.[^.]*$/', '', $name);
                // Remove file extension
                if (strlen($name) == '0') {
                    echo '||1||' . __('Empty filename', 'wp-photo-album-plus');
                    wppa_exit();
                }
                // Make the file
                if (wppa_switch('artmonkey_use_source')) {
                    if (is_file(wppa_get_source_path($photo))) {
                        $source = wppa_get_source_path($photo);
                    } else {
                        $source = wppa_get_photo_path($photo);
                    }
                } else {
                    $source = wppa_get_photo_path($photo);
                }
                $source = wppa_fix_poster_ext($source, $photo);
                // Fix the extension for mm items.
                if ($data['ext'] == 'xxx') {
                    $data['ext'] = wppa_get_ext($source);
                }
                $dest = WPPA_UPLOAD_PATH . '/temp/' . $name . '.' . $data['ext'];
                $zipfile = WPPA_UPLOAD_PATH . '/temp/' . $name . '.zip';
                $tempdir = WPPA_UPLOAD_PATH . '/temp';
                if (!is_dir($tempdir)) {
                    @mkdir($tempdir);
                }
                if (!is_dir($tempdir)) {
                    echo '||2||' . __('Unable to create tempdir', 'wp-photo-album-plus');
                    wppa_exit();
                }
                // Remove obsolete files
                wppa_delete_obsolete_tempfiles();
                // Make the files
                if ($type == 'file') {
                    copy($source, $dest);
                    $ext = $data['ext'];
                } elseif ($type == 'zip') {
                    if (!class_exists('ZipArchive')) {
                        echo '||8||' . __('Unable to create zip archive', 'wp-photo-album-plus');
                        wppa_exit();
                    }
                    $ext = 'zip';
                    $wppa_zip = new ZipArchive();
                    $wppa_zip->open($zipfile, 1);
                    $wppa_zip->addFile($source, basename($dest));
                    $wppa_zip->close();
                } else {
                    echo '||6||' . __('Unknown type', 'wp-photo-album-plus');
                    wppa_exit();
                }
                $desturl = WPPA_UPLOAD_URL . '/temp/' . $name . '.' . $ext;
                echo '||0||' . $desturl;
                // No error: return url
                wppa_exit();
            } else {
                echo '||9||' . __('The photo does no longer exist', 'wp-photo-album-plus');
                wppa_exit();
            }
            wppa_exit();
            break;
        case 'tinymcedialog':
            $result = wppa_make_tinymce_dialog();
            echo $result;
            wppa_exit();
            break;
        case 'bumpviewcount':
            $nonce = $_REQUEST['wppa-nonce'];
            if (wp_verify_nonce($nonce, 'wppa-check')) {
                wppa_bump_viewcount('photo', $_REQUEST['wppa-photo']);
            } else {
                _e('Security check failure', 'wp-photo-album-plus');
            }
            wppa_exit();
            break;
        case 'rate':
            // Get commandline args
            $photo = $_REQUEST['wppa-rating-id'];
            $rating = $_REQUEST['wppa-rating'];
            $occur = $_REQUEST['wppa-occur'];
            $index = $_REQUEST['wppa-index'];
            $nonce = $_REQUEST['wppa-nonce'];
            // Make errortext
            $errtxt = __('An error occurred while processing you rating request.', 'wp-photo-album-plus');
            $errtxt .= "\n" . __('Maybe you opened the page too long ago to recognize you.', 'wp-photo-album-plus');
            $errtxt .= "\n" . __('You may refresh the page and try again.', 'wp-photo-album-plus');
            $wartxt = __('Althoug an error occurred while processing your rating, your vote has been registered.', 'wp-photo-album-plus');
            $wartxt .= "\n" . __('However, this may not be reflected in the current pageview', 'wp-photo-album-plus');
            // Check on validity
            if (!wp_verify_nonce($nonce, 'wppa-check')) {
                echo '0||100||' . $errtxt;
                wppa_exit();
                // Nonce check failed
            }
            if (wppa_opt('rating_max') == '1' && $rating != '1') {
                echo '0||106||' . $errtxt . ':' . $rating;
                wppa_exit();
                // Value out of range
            } elseif (wppa_opt('rating_max') == '5' && !in_array($rating, array('-1', '1', '2', '3', '4', '5'))) {
                echo '0||106||' . $errtxt . ':' . $rating;
                wppa_exit();
                // Value out of range
            } elseif (wppa_opt('rating_max') == '10' && !in_array($rating, array('-1', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10'))) {
                echo '0||106||' . $errtxt . ':' . $rating;
                wppa_exit();
                // Value out of range
            }
            // Get other data
            if (!$wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_PHOTOS . "` WHERE `id` = %s", $photo))) {
                echo '0||999||' . __('Photo has been removed.', 'wp-photo-album-plus');
                wppa_exit();
            }
            $user = wppa_get_user();
            $mylast = $wpdb->get_row($wpdb->prepare('SELECT * FROM `' . WPPA_RATING . '` WHERE `photo` = %s AND `user` = %s ORDER BY `id` DESC LIMIT 1', $photo, $user), ARRAY_A);
            $myavgrat = '0';
            // Init
            // Rate own photo?
            if (wppa_get_photo_item($photo, 'owner') == $user && !wppa_switch('allow_owner_votes')) {
                echo '0||900||' . __('Sorry, you can not rate your own photos', 'wp-photo-album-plus');
                wppa_exit();
            }
            // Already a pending one?
            $pending = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_RATING . "` WHERE `photo` = %s AND `user` = %s AND `status` = %s", $photo, $user, 'pending'));
            // Has user motivated his vote?
            $hascommented = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_COMMENTS . "` WHERE `photo` = %s AND `user` = %s", $photo, wppa_get_user('display')));
            if ($pending) {
                if (!$hascommented) {
                    echo '0||900||' . __('Please enter a comment.', 'wp-photo-album-plus');
                    wppa_exit();
                } else {
                    $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_RATING . "` SET `status` = 'publish' WHERE `photo` = %s AND `user` = %s", $photo, $user));
                }
            }
            if (wppa_switch('vote_needs_comment')) {
                $ratingstatus = $hascommented ? 'publish' : 'pending';
            } else {
                $ratingstatus = 'publish';
            }
            // When done, we have to echo $occur.'||'.$photo.'||'.$index.'||'.$myavgrat.'||'.$allavgrat.'||'.$discount.||.$hascommented.||.$message;
            // So we have to do: process rating and find new $myavgrat, $allavgrat and $discount ( $occur, $photo and $index are known )
            // Case 0: Illegal second vote. Frontend takes care of this, but a hacker could enter an ajaxlink manually
            if ($mylast && (!(wppa_switch('rating_change') || wppa_switch('rating_multi')) || $mylast['value'] < '0' || $mylast['value'] > '0' && $rating == '-1')) {
                echo '0||109||' . __('Security check failure.', 'wp-photo-album-plus');
                wppa_exit();
            }
            // Case 1: value = -1 this is a legal dislike vote
            if ($rating == '-1') {
                // Add my dislike
                $iret = wppa_create_rating_entry(array('photo' => $photo, 'value' => $rating, 'user' => $user, 'status' => $ratingstatus));
                if (!$iret) {
                    echo '0||101||' . $errtxt;
                    wppa_exit();
                    // Fail on storing vote
                }
                // Add points
                wppa_add_credit_points(wppa_opt('cp_points_rating'), __('Photo rated', 'wp-photo-album-plus'), $photo, $rating);
                wppa_dislike_check($photo);
                // Check for email to be sent every .. dislikes
                if (!is_file(wppa_get_thumb_path($photo))) {
                    // Photo is removed
                    echo $occur . '||' . $photo . '||' . $index . '||-1||-1|0||' . wppa_opt('dislike_delete');
                    wppa_exit();
                }
            } elseif (!$mylast) {
                // Add my vote
                $iret = wppa_create_rating_entry(array('photo' => $photo, 'value' => $rating, 'user' => $user, 'status' => $ratingstatus));
                if (!$iret) {
                    echo '0||102||' . $errtxt;
                    wppa_exit();
                    // Fail on storing vote
                }
                // Add points
                wppa_add_credit_points(wppa_opt('cp_points_rating'), __('Photo rated', 'wp-photo-album-plus'), $photo, $rating);
            } elseif (wppa_switch('rating_change')) {
                // Votechanging is allowed
                $iret = $wpdb->query($wpdb->prepare('UPDATE `' . WPPA_RATING . '` SET `value` = %s WHERE `photo` = %s AND `user` = %s LIMIT 1', $rating, $photo, $user));
                if ($iret === false) {
                    echo '0||103||' . $errtxt;
                    wppa_exit();
                    // Fail on update
                }
            } elseif (wppa_switch('rating_multi')) {
                // Rating multi is allowed
                $iret = wppa_create_rating_entry(array('photo' => $photo, 'value' => $rating, 'user' => $user, 'status' => $ratingstatus));
                if (!$iret) {
                    echo '0||104||' . $errtxt;
                    wppa_exit();
                    // Fail on storing vote
                }
            } else {
                // Should never get here....
                echo '0||110||' . __('Unexpected error', 'wp-photo-album-plus');
                wppa_exit();
            }
            // Compute my avg rating
            $myrats = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . WPPA_RATING . '`  WHERE `photo` = %s AND `user` = %s AND `status` = %s ', $photo, $user, 'publish'), ARRAY_A);
            if ($myrats) {
                $sum = 0;
                $cnt = 0;
                foreach ($myrats as $rat) {
                    if ($rat['value'] == '-1') {
                        $sum += wppa_opt('dislike_value');
                    } else {
                        $sum += $rat['value'];
                    }
                    $cnt++;
                }
                $myavgrat = $sum / $cnt;
                $i = wppa_opt('rating_prec');
                $j = $i + '1';
                $myavgrat = sprintf('%' . $j . '.' . $i . 'f', $myavgrat);
            } else {
                $myavgrat = '0';
            }
            // Compute new allavgrat
            $ratings = $wpdb->get_results($wpdb->prepare('SELECT * FROM ' . WPPA_RATING . ' WHERE `photo` = %s AND `status` = %s', $photo, 'publish'), ARRAY_A);
            if ($ratings) {
                $sum = 0;
                $cnt = 0;
                foreach ($ratings as $rat) {
                    if ($rat['value'] == '-1') {
                        $sum += wppa_opt('dislike_value');
                    } else {
                        $sum += $rat['value'];
                    }
                    $cnt++;
                }
                $allavgrat = $sum / $cnt;
                if ($allavgrat == '10') {
                    $allavgrat = '9.99999999';
                }
                // For sort order reasons text field
            } else {
                $allavgrat = '0';
            }
            // Store it in the photo info
            $iret = $wpdb->query($wpdb->prepare('UPDATE `' . WPPA_PHOTOS . '` SET `mean_rating` = %s WHERE `id` = %s', $allavgrat, $photo));
            if ($iret === false) {
                echo '0||106||' . $wartxt;
                wppa_exit();
                // Fail on save
            }
            // Compute rating_count and store in the photo info
            $ratcount = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_RATING . "` WHERE `photo` = %s", $photo));
            if ($ratcount !== false) {
                $iret = $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_PHOTOS . "` SET `rating_count` = %s WHERE `id` = %s", $ratcount, $photo));
                if ($iret === false) {
                    echo '0||107||' . $wartxt;
                    wppa_exit();
                    // Fail on save
                }
            }
            // Format $allavgrat for output
            $allavgratcombi = $allavgrat . '|' . $ratcount;
            // Compute dsilike count
            $discount = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_RATING . "` WHERE `photo` = %s AND `value` = -1 AND `status` = %s", $photo, 'publish'));
            if ($discount === false) {
                echo '0||108||' . $wartxt;
                wppa_exit();
                // Fail on save
            }
            // Test for possible medal
            wppa_test_for_medal($photo);
            // Success!
            wppa_clear_cache();
            if (wppa_switch('vote_needs_comment') && !$hascommented) {
                $message = __("Please explain your vote in a comment.\nYour vote will be discarded if you don't.\n\nAfter completing your comment,\nyou can refresh the page to see\nyour vote became effective.", 'wp-photo-album-plus');
            } else {
                $message = '';
            }
            echo $occur . '||' . $photo . '||' . $index . '||' . $myavgrat . '||' . $allavgratcombi . '||' . $discount . '||' . $hascommented . '||' . $message;
            break;
        case 'render':
            $tim_1 = microtime(true);
            $nq_1 = get_num_queries();
            // Correct the fact that this is a non-admin operation, if it is
            if (is_admin()) {
                require_once 'wppa-non-admin.php';
            }
            wppa_load_theme();
            // Register geo shortcode if google-maps-gpx-vieuwer is on board. GPX does it in wp_head(), what is not done in an ajax call
            //			if ( function_exists( 'gmapv3' ) ) add_shortcode( 'map', 'gmapv3' );
            // Get the post we are working for
            if (isset($_REQUEST['wppa-fromp'])) {
                $p = $_REQUEST['wppa-fromp'];
                if (wppa_is_int($p)) {
                    $GLOBALS['post'] = get_post($p);
                }
            }
            // Render
            echo wppa_albums();
            $tim_2 = microtime(true);
            $nq_2 = get_num_queries();
            $mem = memory_get_peak_usage(true) / 1024 / 1024;
            $msg = sprintf('WPPA Ajax render: db queries: WP:%d, WPPA+: %d in %4.2f seconds, using %4.2f MB memory max', $nq_1, $nq_2 - $nq_1, $tim_2 - $tim_1, $mem);
            echo '<script type="text/javascript">wppaConsoleLog( \'' . $msg . '\', \'force\' )</script>';
            break;
        case 'delete-photo':
            $photo = $_REQUEST['photo-id'];
            $nonce = $_REQUEST['wppa-nonce'];
            // Check validity
            if (!wp_verify_nonce($nonce, 'wppa_nonce_' . $photo)) {
                echo '||0||' . __('You do not have the rights to delete a photo', 'wp-photo-album-plus');
                wppa_exit();
                // Nonce check failed
            }
            if (!is_numeric($photo)) {
                echo '||0||' . __('Security check failure', 'wp-photo-album-plus');
                wppa_exit();
                // Nonce check failed
            }
            $album = $wpdb->get_var($wpdb->prepare('SELECT `album` FROM `' . WPPA_PHOTOS . '` WHERE `id` = %s', $photo));
            wppa_delete_photo($photo);
            wppa_clear_cache();
            echo '||1||<span style="color:red" >' . sprintf(__('Photo %s has been deleted', 'wp-photo-album-plus'), $photo) . '</span>';
            echo '||';
            $a = wppa_allow_uploads($album);
            if (!$a) {
                echo 'full';
            } else {
                echo 'notfull||' . $a;
            }
            break;
        case 'update-album':
            $album = $_REQUEST['album-id'];
            $nonce = $_REQUEST['wppa-nonce'];
            $item = $_REQUEST['item'];
            $value = $_REQUEST['value'];
            $value = wppa_decode($value);
            // Check validity
            if (!wp_verify_nonce($nonce, 'wppa_nonce_' . $album)) {
                echo '||0||' . __('You do not have the rights to update album information', 'wp-photo-album-plus') . $nonce;
                wppa_exit();
                // Nonce check failed
            }
            switch ($item) {
                case 'clear_ratings':
                    $photos = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . WPPA_PHOTOS . '` WHERE `album` = %s', $album), ARRAY_A);
                    if ($photos) {
                        foreach ($photos as $photo) {
                            $iret1 = $wpdb->query($wpdb->prepare('DELETE FROM `' . WPPA_RATING . '` WHERE `photo` = %s', $photo['id']));
                            $iret2 = $wpdb->query($wpdb->prepare('UPDATE `' . WPPA_PHOTOS . '` SET `mean_rating` = %s WHERE `id` = %s', '', $photo['id']));
                        }
                    }
                    if ($photos && $iret1 !== false && $iret2 !== false) {
                        echo '||97||' . __('<b>Ratings cleared</b>', 'wp-photo-album-plus') . '||' . __('No ratings for this photo.', 'wp-photo-album-plus');
                    } elseif ($photos) {
                        echo '||1||' . __('An error occurred while clearing ratings', 'wp-photo-album-plus');
                    } else {
                        echo '||97||' . __('<b>No photos in this album</b>', 'wp-photo-album-plus') . '||' . __('No ratings for this photo.', 'wp-photo-album-plus');
                    }
                    wppa_exit();
                    break;
                case 'set_deftags':
                    // to be changed for large albums
                    $photos = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . WPPA_PHOTOS . '` WHERE `album` = %s', $album), ARRAY_A);
                    $deftag = $wpdb->get_var($wpdb->prepare('SELECT `default_tags` FROM `' . WPPA_ALBUMS . '` WHERE `id` = %s', $album));
                    if (is_array($photos)) {
                        foreach ($photos as $photo) {
                            $tags = wppa_sanitize_tags(wppa_filter_iptc(wppa_filter_exif($deftag, $photo['id']), $photo['id']));
                            $iret = $wpdb->query($wpdb->prepare('UPDATE `' . WPPA_PHOTOS . '` SET `tags` = %s WHERE `id` = %s', $tags, $photo['id']));
                            wppa_index_update('photo', $photo['id']);
                        }
                    }
                    if ($photos && $iret !== false) {
                        echo '||97||' . __('<b>Tags set to defaults</b> (reload)', 'wp-photo-album-plus');
                    } elseif ($photos) {
                        echo '||1||' . __('An error occurred while setting tags', 'wp-photo-album-plus');
                    } else {
                        echo '||97||' . __('<b>No photos in this album</b>', 'wp-photo-album-plus');
                    }
                    wppa_clear_taglist();
                    wppa_exit();
                    break;
                case 'add_deftags':
                    $photos = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . WPPA_PHOTOS . '` WHERE `album` = %s', $album), ARRAY_A);
                    $deftag = $wpdb->get_var($wpdb->prepare('SELECT `default_tags` FROM `' . WPPA_ALBUMS . '` WHERE `id` = %s', $album));
                    if (is_array($photos)) {
                        foreach ($photos as $photo) {
                            $tags = wppa_sanitize_tags(wppa_filter_iptc(wppa_filter_exif($photo['tags'] . ',' . $deftag, $photo['id']), $photo['id']));
                            $iret = $wpdb->query($wpdb->prepare('UPDATE `' . WPPA_PHOTOS . '` SET `tags` = %s WHERE `id` = %s', $tags, $photo['id']));
                            wppa_index_update('photo', $photo['id']);
                        }
                    }
                    if ($photos && $iret !== false) {
                        echo '||97||' . __('<b>Tags added width defaults</b> (reload)', 'wp-photo-album-plus');
                    } elseif ($photos) {
                        echo '||1||' . __('An error occurred while adding tags', 'wp-photo-album-plus');
                    } else {
                        echo '||97||' . __('<b>No photos in this album</b>', 'wp-photo-album-plus');
                    }
                    wppa_clear_taglist();
                    wppa_exit();
                    break;
                case 'name':
                    $value = trim(strip_tags($value));
                    if (!wppa_sanitize_file_name($value)) {
                        // Empty album name is not allowed
                        $value = 'Album-#' . $album;
                        echo '||5||' . sprintf(__('Album name may not be empty.<br />Reset to <b>%s</b>', 'wp-photo-album-plus'), $value);
                    }
                    $itemname = __('Name', 'wp-photo-album-plus');
                    break;
                case 'description':
                    $itemname = __('Description', 'wp-photo-album-plus');
                    if (wppa_switch('check_balance')) {
                        $value = str_replace(array('<br/>', '<br>'), '<br />', $value);
                        if (balanceTags($value, true) != $value) {
                            echo '||3||' . __('Unbalanced tags in album description!', 'wp-photo-album-plus');
                            wppa_exit();
                        }
                    }
                    $value = trim($value);
                    break;
                case 'a_order':
                    $itemname = __('Album order #', 'wp-photo-album-plus');
                    break;
                case 'main_photo':
                    $itemname = __('Cover photo', 'wp-photo-album-plus');
                    break;
                case 'a_parent':
                    $itemname = __('Parent album', 'wp-photo-album-plus');
                    wppa_flush_treecounts($album);
                    // Myself and my parents
                    wppa_flush_treecounts($value);
                    // My new parent
                    break;
                case 'p_order_by':
                    $itemname = __('Photo order', 'wp-photo-album-plus');
                    break;
                case 'alt_thumbsize':
                    $itemname = __('Use Alt thumbsize', 'wp-photo-album-plus');
                    break;
                case 'cover_type':
                    $itemname = __('Cover Type', 'wp-photo-album-plus');
                    break;
                case 'cover_linktype':
                    $itemname = __('Link type', 'wp-photo-album-plus');
                    break;
                case 'cover_linkpage':
                    $itemname = __('Link to', 'wp-photo-album-plus');
                    break;
                case 'owner':
                    $itemname = __('Owner', 'wp-photo-album-plus');
                    if ($value != '--- public ---' && !get_user_by('login', $value)) {
                        echo '||4||' . sprintf(__('User %s does not exist', 'wp-photo-album-plus'), $value);
                        wppa_exit();
                    }
                    break;
                case 'upload_limit_count':
                    wppa_ajax_check_range($value, false, '0', false, __('Upload limit count', 'wp-photo-album-plus'));
                    if (wppa('error')) {
                        wppa_exit();
                    }
                    $oldval = $wpdb->get_var($wpdb->prepare('SELECT `upload_limit` FROM ' . WPPA_ALBUMS . ' WHERE `id` = %s', $album));
                    $temp = explode('/', $oldval);
                    $value = $value . '/' . $temp[1];
                    $item = 'upload_limit';
                    $itemname = __('Upload limit count', 'wp-photo-album-plus');
                    break;
                case 'upload_limit_time':
                    $oldval = $wpdb->get_var($wpdb->prepare('SELECT `upload_limit` FROM ' . WPPA_ALBUMS . ' WHERE `id` = %s', $album));
                    $temp = explode('/', $oldval);
                    $value = $temp[0] . '/' . $value;
                    $item = 'upload_limit';
                    $itemname = __('Upload limit time', 'wp-photo-album-plus');
                    break;
                case 'default_tags':
                    $value = wppa_sanitize_tags($value, false, true);
                    $itemname = __('Default tags', 'wp-photo-album-plus');
                    break;
                case 'cats':
                    $value = wppa_sanitize_cats($value);
                    wppa_clear_catlist();
                    $itemname = __('Categories', 'wp-photo-album-plus');
                    break;
                case 'suba_order_by':
                    $itemname = __('Sub albums sort order', 'wp-photo-album-plus');
                    break;
                case 'year':
                case 'month':
                case 'day':
                case 'hour':
                case 'min':
                    $itemname = __('Schedule date/time', 'wp-photo-album-plus');
                    $scheduledtm = $wpdb->get_var($wpdb->prepare("SELECT `scheduledtm` FROM`" . WPPA_ALBUMS . "` WHERE `id` = %s", $album));
                    if (!$scheduledtm) {
                        $scheduledtm = wppa_get_default_scheduledtm();
                    }
                    $temp = explode(',', $scheduledtm);
                    if ($item == 'year') {
                        $temp[0] = $value;
                    }
                    if ($item == 'month') {
                        $temp[1] = $value;
                    }
                    if ($item == 'day') {
                        $temp[2] = $value;
                    }
                    if ($item == 'hour') {
                        $temp[3] = $value;
                    }
                    if ($item == 'min') {
                        $temp[4] = $value;
                    }
                    $scheduledtm = implode(',', $temp);
                    wppa_update_album(array('id' => $album, 'scheduledtm' => $scheduledtm));
                    echo '||0||' . sprintf(__('<b>%s</b> of album %s updated', 'wp-photo-album-plus'), $itemname, $album);
                    wppa_exit();
                    break;
                case 'setallscheduled':
                    $scheduledtm = $wpdb->get_var($wpdb->prepare("SELECT `scheduledtm` FROM `" . WPPA_ALBUMS . "` WHERE `id` = %s", $album));
                    if ($scheduledtm) {
                        $iret = $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_PHOTOS . "` SET `status` = 'scheduled', `scheduledtm` = %s WHERE `album` = %s", $scheduledtm, $album));
                        echo '||0||' . __('All photos set to scheduled per date', 'wp-photo-album-plus') . ' ( ' . $iret . ' ) ' . wppa_format_scheduledtm($scheduledtm);
                    }
                    wppa_exit();
                    break;
                default:
                    $itemname = $item;
            }
            $query = $wpdb->prepare('UPDATE ' . WPPA_ALBUMS . ' SET `' . $item . '` = %s WHERE `id` = %s', $value, $album);
            $iret = $wpdb->query($query);
            if ($iret !== false) {
                if ($item == 'name' || $item == 'description' || $item == 'cats') {
                    wppa_index_update('album', $album);
                }
                if ($item == 'name') {
                    wppa_create_pl_htaccess();
                }
                echo '||0||' . sprintf(__('<b>%s</b> of album %s updated', 'wp-photo-album-plus'), $itemname, $album);
                if ($item == 'upload_limit') {
                    echo '||';
                    $a = wppa_allow_uploads($album);
                    if (!$a) {
                        echo 'full';
                    } else {
                        echo 'notfull||' . $a;
                    }
                }
            } else {
                echo '||2||' . sprintf(__('An error occurred while trying to update <b>%s</b> of album %s', 'wp-photo-album-plus'), $itemname, $album);
                echo '<br>' . __('Press CTRL+F5 and try again.', 'wp-photo-album-plus');
            }
            wppa_clear_cache();
            wppa_exit();
            break;
        case 'update-comment-status':
            $photo = $_REQUEST['wppa-photo-id'];
            $nonce = $_REQUEST['wppa-nonce'];
            $comid = $_REQUEST['wppa-comment-id'];
            $comstat = $_REQUEST['wppa-comment-status'];
            // Check validity
            if (!wp_verify_nonce($nonce, 'wppa_nonce_' . $photo)) {
                echo '||0||' . __('You do not have the rights to update comment status', 'wp-photo-album-plus') . $nonce;
                wppa_exit();
                // Nonce check failed
            }
            //			if ( wppa_switch( 'search_comments' ) ) wppa_index_remove( 'photo', $photo );
            $iret = $wpdb->query($wpdb->prepare('UPDATE `' . WPPA_COMMENTS . '` SET `status` = %s WHERE `id` = %s', $comstat, $comid));
            if (wppa_switch('search_comments')) {
                wppa_index_update('photo', $photo);
            }
            if ($iret !== false) {
                echo '||0||' . sprintf(__('Status of comment #%s updated', 'wp-photo-album-plus'), $comid);
            } else {
                echo '||1||' . sprintf(__('Error updating status comment #%s', 'wp-photo-album-plus'), $comid);
            }
            wppa_exit();
            break;
        case 'watermark-photo':
            $photo = $_REQUEST['photo-id'];
            $nonce = $_REQUEST['wppa-nonce'];
            // Check validity
            if (!wp_verify_nonce($nonce, 'wppa_nonce_' . $photo)) {
                echo '||1||' . __('You do not have the rights to change photos', 'wp-photo-album-plus');
                wppa_exit();
                // Nonce check failed
            }
            wppa_cache_thumb($photo);
            if (wppa_add_watermark($photo)) {
                if (wppa_switch('watermark_thumbs')) {
                    wppa_create_thumbnail($photo);
                    // create new thumb
                }
                echo '||0||' . __('Watermark applied', 'wp-photo-album-plus');
                wppa_exit();
            } else {
                echo '||1||' . __('An error occured while trying to apply a watermark', 'wp-photo-album-plus');
                wppa_exit();
            }
        case 'update-photo':
            $photo = $_REQUEST['photo-id'];
            $nonce = $_REQUEST['wppa-nonce'];
            $item = $_REQUEST['item'];
            $value = isset($_REQUEST['value']) ? $_REQUEST['value'] : '';
            $value = wppa_decode($value);
            // Check validity
            if (!wp_verify_nonce($nonce, 'wppa_nonce_' . $photo)) {
                echo '||0||' . __('You do not have the rights to update photo information', 'wp-photo-album-plus');
                wppa_exit();
                // Nonce check failed
            }
            if (substr($item, 0, 20) == 'wppa_watermark_file_' || substr($item, 0, 19) == 'wppa_watermark_pos_') {
                wppa_update_option($item, $value);
                echo '||0||' . sprintf(__('%s updated to %s.', 'wp-photo-album-plus'), $item, $value);
                wppa_exit();
            }
            switch ($item) {
                case 'exifdtm':
                    $format = '0000:00:00 00:00:00';
                    $err = '0';
                    // Length ok?
                    if (strlen($value) != 19) {
                        $err = '1';
                    }
                    // Check on digits, colons and space
                    for ($i = 0; $i < 19; $i++) {
                        $d = substr($value, $i, 1);
                        $f = substr($format, $i, 1);
                        switch ($f) {
                            case '0':
                                if (!in_array($d, array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'))) {
                                    $err = '2';
                                }
                                break;
                            case ':':
                            case ' ':
                                if ($d != $f) {
                                    $err = '3';
                                }
                                break;
                        }
                    }
                    // Check on values if format correct, report first error only
                    if (!$err) {
                        $temp = explode(':', str_replace(' ', ':', $value));
                        if ($temp['0'] < '1970') {
                            $err = '11';
                        }
                        // Before UNIX epoch
                        if (!$err && $temp['0'] > date('Y')) {
                            $err = '12';
                        }
                        // Future
                        if (!$err && $temp['1'] < '1') {
                            $err = '13';
                        }
                        // Before january
                        if (!$err && $temp['1'] > '12') {
                            $err = '14';
                        }
                        // After december
                        if (!$err && $temp['2'] < '1') {
                            $err = '15';
                        }
                        // Before first of month
                        if (!$err && $temp['2'] > '31') {
                            $err = '17';
                        }
                        // After 31st ( forget about feb and months with 30 days )
                        if (!$err && $temp['3'] < '1') {
                            $err = '18';
                        }
                        // Before first hour
                        if (!$err && $temp['3'] > '24') {
                            $err = '19';
                        }
                        // Hour > 24
                        if (!$err && $temp['4'] < '1') {
                            $err = '20';
                        }
                        // Min < 1
                        if (!$err && $temp['4'] > '59') {
                            $err = '21';
                        }
                        // Min > 59
                        if (!$err && $temp['5'] < '1') {
                            $err = '22';
                        }
                        // Sec < 1
                        if (!$err && $temp['5'] > '59') {
                            $err = '23';
                        }
                        // Sec > 59
                    }
                    if ($err) {
                        echo '||1||' . sprintf(__('Format error %s. Must be yyyy:mm:dd hh:mm:ss', 'wp-photo-album-plus'), $err);
                    } else {
                        wppa_update_photo(array('id' => $photo, 'exifdtm' => $value));
                        echo '||0||' . __('Exif date/time updated', 'wp-photo-album-plus');
                    }
                    wppa_exit();
                    break;
                case 'lat':
                    if (!is_numeric($value) || $value < '-90.0' || $value > '90.0') {
                        echo '||1||' . __('Enter a value > -90 and < 90', 'wp-photo-album-plus');
                        wppa_exit();
                    }
                    $photodata = $wpdb->get_row($wpdb->prepare('SELECT * FROM ' . WPPA_PHOTOS . ' WHERE `id` = %s', $photo), ARRAY_A);
                    $geo = $photodata['location'] ? $photodata['location'] : '///';
                    $geo = explode('/', $geo);
                    $geo = wppa_format_geo($value, $geo['3']);
                    $iret = $wpdb->query($wpdb->prepare('UPDATE `' . WPPA_PHOTOS . '` SET `location` = %s WHERE `id` = %s', $geo, $photo));
                    if ($iret) {
                        echo '||0||' . __('Lattitude updated', 'wp-photo-album-plus');
                    } else {
                        echo '||1||' . __('Could not update lattitude', 'wp-photo-album-plus');
                    }
                    wppa_exit();
                    break;
                case 'lon':
                    if (!is_numeric($value) || $value < '-180.0' || $value > '180.0') {
                        echo '||1||' . __('Enter a value > -180 and < 180', 'wp-photo-album-plus');
                        wppa_exit();
                    }
                    $photodata = $wpdb->get_row($wpdb->prepare('SELECT * FROM ' . WPPA_PHOTOS . ' WHERE `id` = %s', $photo), ARRAY_A);
                    $geo = $photodata['location'] ? $photodata['location'] : '///';
                    $geo = explode('/', $geo);
                    $geo = wppa_format_geo($geo['2'], $value);
                    $iret = $wpdb->query($wpdb->prepare('UPDATE `' . WPPA_PHOTOS . '` SET `location` = %s WHERE `id` = %s', $geo, $photo));
                    if ($iret) {
                        echo '||0||' . __('Longitude updated', 'wp-photo-album-plus');
                    } else {
                        echo '||1||' . __('Could not update longitude', 'wp-photo-album-plus');
                    }
                    wppa_exit();
                    break;
                case 'remake':
                    if (wppa_remake_files('', $photo)) {
                        wppa_bump_photo_rev();
                        wppa_bump_thumb_rev();
                        echo '||0||' . __('Photo files remade', 'wp-photo-album-plus');
                    } else {
                        echo '||2||' . __('Could not remake files', 'wp-photo-album-plus');
                    }
                    wppa_exit();
                    break;
                case 'remakethumb':
                    if (wppa_create_thumbnail($photo)) {
                        echo '||0||' . __('Thumbnail remade', 'wp-photo-album-plus');
                    } else {
                        echo '||0||' . __('Could not remake thumbnail', 'wp-photo-album-plus');
                    }
                    wppa_exit();
                    break;
                case 'rotright':
                case 'rot180':
                case 'rotleft':
                    switch ($item) {
                        case 'rotleft':
                            $angle = '90';
                            $dir = __('left', 'wp-photo-album-plus');
                            break;
                        case 'rot180':
                            $angle = '180';
                            $dir = __('180&deg;', 'wp-photo-album-plus');
                            break;
                        case 'rotright':
                            $angle = '270';
                            $dir = __('right', 'wp-photo-album-plus');
                            break;
                    }
                    wppa('error', wppa_rotate($photo, $angle));
                    if (!wppa('error')) {
                        wppa_update_modified($photo);
                        wppa_bump_photo_rev();
                        wppa_bump_thumb_rev();
                        echo '||0||' . sprintf(__('Photo %s rotated %s', 'wp-photo-album-plus'), $photo, $dir);
                    } else {
                        echo '||' . wppa('error') . '||' . sprintf(__('An error occurred while trying to rotate photo %s', 'wp-photo-album-plus'), $photo);
                    }
                    wppa_exit();
                    break;
                case 'moveto':
                    $photodata = $wpdb->get_row($wpdb->prepare('SELECT * FROM ' . WPPA_PHOTOS . ' WHERE `id` = %s', $photo), ARRAY_A);
                    if (wppa_switch('void_dups')) {
                        // Check for already exists
                        $exists = wppa_file_is_in_album($photodata['filename'], $value);
                        if ($exists) {
                            // Already exists
                            echo '||3||' . sprintf(__('A photo with filename %s already exists in album %s.', 'wp-photo-album-plus'), $photodata['filename'], $value);
                            wppa_exit();
                            break;
                        }
                    }
                    wppa_flush_treecounts($photodata['album']);
                    // Current album
                    wppa_flush_treecounts($value);
                    // New album
                    $iret = $wpdb->query($wpdb->prepare('UPDATE ' . WPPA_PHOTOS . ' SET `album` = %s WHERE `id` = %s', $value, $photo));
                    if ($iret !== false) {
                        wppa_move_source($photodata['filename'], $photodata['album'], $value);
                        echo '||99||' . sprintf(__('Photo %s has been moved to album %s (%s)', 'wp-photo-album-plus'), $photo, wppa_get_album_name($value), $value);
                    } else {
                        echo '||3||' . sprintf(__('An error occurred while trying to move photo %s', 'wp-photo-album-plus'), $photo);
                    }
                    wppa_exit();
                    break;
                case 'copyto':
                    $photodata = $wpdb->get_row($wpdb->prepare('SELECT * FROM ' . WPPA_PHOTOS . ' WHERE `id` = %s', $photo), ARRAY_A);
                    if (wppa_switch('void_dups')) {
                        // Check for already exists
                        $exists = wppa_file_is_in_album($photodata['filename'], $value);
                        if ($exists) {
                            // Already exists
                            echo '||4||' . sprintf(__('A photo with filename %s already exists in album %s.', 'wp-photo-album-plus'), $photodata['filename'], $value);
                            wppa_exit();
                            break;
                        }
                    }
                    wppa('error', wppa_copy_photo($photo, $value));
                    wppa_flush_treecounts($value);
                    // New album
                    if (!wppa('error')) {
                        echo '||0||' . sprintf(__('Photo %s copied to album %s (%s)', 'wp-photo-album-plus'), $photo, wppa_get_album_name($value), $value);
                    } else {
                        echo '||4||' . sprintf(__('An error occurred while trying to copy photo %s', 'wp-photo-album-plus'), $photo);
                        echo '<br>' . __('Press CTRL+F5 and try again.', 'wp-photo-album-plus');
                    }
                    wppa_exit();
                    break;
                case 'status':
                    if (!current_user_can('wppa_moderate') && !current_user_can('wppa_admin')) {
                        die('Security check failure #78');
                    }
                    wppa_flush_treecounts(wppa_get_photo_item($photo, 'album'));
                    // $wpdb->get_var( $wpdb->prepare( "SELECT `album` FROM `".WPPA_PHOTOS."` WHERE `id` = %s", $photo ) ) );
                // $wpdb->get_var( $wpdb->prepare( "SELECT `album` FROM `".WPPA_PHOTOS."` WHERE `id` = %s", $photo ) ) );
                case 'owner':
                case 'name':
                case 'description':
                case 'p_order':
                case 'linkurl':
                case 'linktitle':
                case 'linktarget':
                case 'tags':
                case 'alt':
                case 'videox':
                case 'videoy':
                    switch ($item) {
                        case 'name':
                            $value = strip_tags($value);
                            $itemname = __('Name', 'wp-photo-album-plus');
                            break;
                        case 'description':
                            $itemname = __('Description', 'wp-photo-album-plus');
                            if (wppa_switch('check_balance')) {
                                $value = str_replace(array('<br/>', '<br>'), '<br />', $value);
                                if (balanceTags($value, true) != $value) {
                                    echo '||3||' . __('Unbalanced tags in photo description!', 'wp-photo-album-plus');
                                    wppa_exit();
                                }
                            }
                            break;
                        case 'p_order':
                            $itemname = __('Photo order #', 'wp-photo-album-plus');
                            break;
                        case 'owner':
                            $usr = get_user_by('login', $value);
                            if (!$usr) {
                                echo '||4||' . sprintf(__('User %s does not exists', 'wp-photo-album-plus'), $value);
                                wppa_exit();
                            }
                            $value = $usr->user_login;
                            // Correct possible case mismatch
                            wppa_flush_upldr_cache('photoid', $photo);
                            // Current owner
                            wppa_flush_upldr_cache('username', $value);
                            // New owner
                            $itemname = __('Owner', 'wp-photo-album-plus');
                            break;
                        case 'linkurl':
                            $itemname = __('Link url', 'wp-photo-album-plus');
                            break;
                        case 'linktitle':
                            $itemname = __('Link title', 'wp-photo-album-plus');
                            break;
                        case 'linktarget':
                            $itemname = __('Link target', 'wp-photo-album-plus');
                            break;
                        case 'tags':
                            $value = wppa_sanitize_tags($value, false, true);
                            $value = wppa_sanitize_tags(wppa_filter_iptc(wppa_filter_exif($value, $photo), $photo));
                            wppa_clear_taglist();
                            $itemname = __('Photo Tags', 'wp-photo-album-plus');
                            break;
                        case 'status':
                            wppa_clear_taglist();
                            wppa_flush_upldr_cache('photoid', $photo);
                            $itemname = __('Status', 'wp-photo-album-plus');
                            break;
                        case 'alt':
                            $itemname = __('HTML Alt', 'wp-photo-album-plus');
                            $value = strip_tags(stripslashes($value));
                            break;
                        case 'videox':
                            $itemname = __('Video width', 'wp-photo-album-plus');
                            if (!wppa_is_int($value) || $value < '0') {
                                echo '||3||' . __('Please enter an integer value >= 0', 'wp-photo-album-plus');
                                wppa_exit();
                            }
                            break;
                        case 'videoy':
                            $itemname = __('Video height', 'wp-photo-album-plus');
                            if (!wppa_is_int($value) || $value < '0') {
                                echo '||3||' . __('Please enter an integer value >= 0', 'wp-photo-album-plus');
                                wppa_exit();
                            }
                            break;
                        default:
                            $itemname = $item;
                    }
                    //				if ( $item == 'name' || $item == 'description' || $item == 'tags' ) wppa_index_quick_remove( 'photo', $photo );
                    $iret = $wpdb->query($wpdb->prepare('UPDATE ' . WPPA_PHOTOS . ' SET `' . $item . '` = %s WHERE `id` = %s', $value, $photo));
                    if ($item == 'name' || $item == 'description' || $item == 'tags') {
                        wppa_index_update('photo', $photo);
                    }
                    if ($item == 'status' && $value != 'scheduled') {
                        wppa_update_photo(array('id' => $photo, 'scheduledtm' => ''));
                    }
                    if ($item == 'status') {
                        wppa_flush_treecounts(wppa_get_photo_item($photo, 'album'));
                    }
                    if ($iret !== false) {
                        wppa_update_modified($photo);
                        if (wppa_is_video($photo)) {
                            echo '||0||' . sprintf(__('<b>%s</b> of video %s updated', 'wp-photo-album-plus'), $itemname, $photo);
                        } else {
                            echo '||0||' . sprintf(__('<b>%s</b> of photo %s updated', 'wp-photo-album-plus'), $itemname, $photo);
                        }
                    } else {
                        echo '||2||' . sprintf(__('An error occurred while trying to update <b>%s</b> of photo %s', 'wp-photo-album-plus'), $itemname, $photo);
                        echo '<br>' . __('Press CTRL+F5 and try again.', 'wp-photo-album-plus');
                        wppa_exit();
                    }
                    break;
                case 'year':
                case 'month':
                case 'day':
                case 'hour':
                case 'min':
                    $itemname = __('Schedule date/time', 'wp-photo-album-plus');
                    $scheduledtm = $wpdb->get_var($wpdb->prepare("SELECT `scheduledtm` FROM`" . WPPA_PHOTOS . "` WHERE `id` = %s", $photo));
                    if (!$scheduledtm) {
                        $scheduledtm = wppa_get_default_scheduledtm();
                    }
                    $temp = explode(',', $scheduledtm);
                    if ($item == 'year') {
                        $temp[0] = $value;
                    }
                    if ($item == 'month') {
                        $temp[1] = $value;
                    }
                    if ($item == 'day') {
                        $temp[2] = $value;
                    }
                    if ($item == 'hour') {
                        $temp[3] = $value;
                    }
                    if ($item == 'min') {
                        $temp[4] = $value;
                    }
                    $scheduledtm = implode(',', $temp);
                    wppa_update_photo(array('id' => $photo, 'scheduledtm' => $scheduledtm, 'status' => 'scheduled'));
                    wppa_flush_treecounts($wpdb->get_var($wpdb->prepare("SELECT `album` FROM `" . WPPA_PHOTOS . "` WHERE `id` = %s", $photo)));
                    wppa_flush_upldr_cache('photoid', $photo);
                    if (wppa_is_video($photo)) {
                        echo '||0||' . sprintf(__('<b>%s</b> of video %s updated', 'wp-photo-album-plus'), $itemname, $photo);
                    } else {
                        echo '||0||' . sprintf(__('<b>%s</b> of photo %s updated', 'wp-photo-album-plus'), $itemname, $photo);
                    }
                    break;
                case 'custom_0':
                case 'custom_1':
                case 'custom_2':
                case 'custom_3':
                case 'custom_4':
                case 'custom_5':
                case 'custom_6':
                case 'custom_7':
                case 'custom_8':
                case 'custom_9':
                    $index = substr($item, -1);
                    $custom = wppa_get_photo_item($photo, 'custom');
                    if ($custom) {
                        $custom_data = unserialize($custom);
                    } else {
                        $custom_data = array('', '', '', '', '', '', '', '', '', '');
                    }
                    $custom_data[$index] = strip_tags($value);
                    $custom = serialize($custom_data);
                    wppa_update_photo(array('id' => $photo, 'custom' => $custom, 'modified' => time()));
                    wppa_index_update('photo', $photo);
                    echo '||0||' . sprintf(__('<b>Custom field %s</b> of photo %s updated', 'wp-photo-album-plus'), wppa_opt('custom_caption_' . $index), $photo);
                    break;
                case 'file':
                    // Check on upload error
                    if ($_FILES['photo']['error']) {
                        echo '||' . $_FILES['photo']['error'] . '||' . __('<b>Error during upload.</b>', 'wp-photo-album-plus');
                        wppa_exit();
                    }
                    // Save new source
                    wppa_save_source($_FILES['photo']['tmp_name'], wppa_get_photo_item($photo, 'filename'), wppa_get_photo_item($photo, 'album'));
                    // Make the files
                    $bret = wppa_make_the_photo_files($_FILES['photo']['tmp_name'], $photo, strtolower(wppa_get_ext($_FILES['photo']['name'])));
                    if ($bret) {
                        // Update timestamps and sizes
                        $alb = wppa_get_photo_item($photo, 'album');
                        wppa_update_album(array('id' => $alb, 'modified' => time()));
                        wppa_update_photo(array('id' => $photo, 'modified' => time(), 'thumbx' => '0', 'thumby' => '0', 'photox' => '0', 'photoy' => '0'));
                        // Report success
                        echo '||0||' . __('Photo files updated.', 'wp-photo-album-plus');
                    } else {
                        // Report fail
                        echo '||1||' . __('Could not update files.', 'wp-photo-album-plus');
                    }
                    wppa_exit();
                    break;
                case 'stereo':
                    $t = microtime(true);
                    wppa_update_photo(array('id' => $photo, 'stereo' => $value));
                    wppa_create_stereo_images($photo);
                    wppa_create_thumbnail($photo);
                    $t = microtime(true) - $t;
                    echo '||0||' . sprintf(__('Stereo mode updated in %d milliseconds', 'wp-photo-album-plus'), floor($t * 1000));
                    wppa_exit();
                    break;
                default:
                    echo '||98||This update action is not implemented yet( ' . $item . ' )';
                    wppa_exit();
            }
            wppa_clear_cache();
            break;
            // The wppa-settings page calls ajax with $wppa_action == 'update-option';
        // The wppa-settings page calls ajax with $wppa_action == 'update-option';
        case 'update-option':
            // Verify that we are legally here
            $nonce = $_REQUEST['wppa-nonce'];
            if (!wp_verify_nonce($nonce, 'wppa-nonce')) {
                echo '||1||' . __('You do not have the rights to update settings', 'wp-photo-album-plus');
                wppa_exit();
                // Nonce check failed
            }
            // Initialize
            $old_minisize = wppa_get_minisize();
            // Remember for later, maybe we do something that requires regen
            $option = $_REQUEST['wppa-option'];
            // The option to be processed
            $value = isset($_REQUEST['value']) ? wppa_decode($_REQUEST['value']) : '';
            // The new value, may also contain & # and +
            $value = stripslashes($value);
            $value = trim($value);
            // Remaove surrounding spaces
            $alert = '';
            // Init the return string data
            wppa('error', '0');
            //
            $title = '';
            //
            // If it is a font family, change all double quotes into single quotes as this destroys much more than you would like
            if (strpos($option, 'wppa_fontfamily_') !== false) {
                $value = str_replace('"', "'", $value);
            }
            $option = wppa_decode($option);
            // Dispatch on option
            if (substr($option, 0, 16) == 'wppa_iptc_label_') {
                $tag = substr($option, 16);
                $q = $wpdb->prepare("UPDATE `" . WPPA_IPTC . "` SET `description`=%s WHERE `tag`=%s AND `photo`='0'", $value, $tag);
                $bret = $wpdb->query($q);
                // Produce the response text
                if ($bret) {
                    $output = '||0||' . $tag . ' updated to ' . $value . '||';
                } else {
                    $output = '||1||Failed to update ' . $tag . '||';
                }
                echo $output;
                wppa_exit();
            } elseif (substr($option, 0, 17) == 'wppa_iptc_status_') {
                $tag = substr($option, 17);
                $q = $wpdb->prepare("UPDATE `" . WPPA_IPTC . "` SET `status`=%s WHERE `tag`=%s AND `photo`='0'", $value, $tag);
                $bret = $wpdb->query($q);
                // Produce the response text
                if ($bret) {
                    $output = '||0||' . $tag . ' updated to ' . $value . '||';
                } else {
                    $output = '||1||Failed to update ' . $tag . '||';
                }
                echo $output;
                wppa_exit();
            } elseif (substr($option, 0, 16) == 'wppa_exif_label_') {
                $tag = substr($option, 16);
                $q = $wpdb->prepare("UPDATE `" . WPPA_EXIF . "` SET `description`=%s WHERE `tag`=%s AND `photo`='0'", $value, $tag);
                $bret = $wpdb->query($q);
                // Produce the response text
                if ($bret) {
                    $output = '||0||' . $tag . ' updated to ' . $value . '||';
                } else {
                    $output = '||1||Failed to update ' . $tag . '||';
                }
                echo $output;
                wppa_exit();
            } elseif (substr($option, 0, 17) == 'wppa_exif_status_') {
                $tag = substr($option, 17);
                $q = $wpdb->prepare("UPDATE `" . WPPA_EXIF . "` SET `status`=%s WHERE `tag`=%s AND `photo`='0'", $value, $tag);
                $bret = $wpdb->query($q);
                // Produce the response text
                if ($bret) {
                    $output = '||0||' . $tag . ' updated to ' . $value . '||';
                } else {
                    $output = '||1||Failed to update ' . $tag . '||';
                }
                echo $output;
                wppa_exit();
            } elseif (substr($option, 0, 5) == 'caps-') {
                // Is capability setting
                global $wp_roles;
                //$R = new WP_Roles;
                $setting = explode('-', $option);
                if ($value == 'yes') {
                    $wp_roles->add_cap($setting[2], $setting[1]);
                    echo '||0||' . __('Capability granted', 'wp-photo-album-plus') . '||';
                    wppa_exit();
                } elseif ($value == 'no') {
                    $wp_roles->remove_cap($setting[2], $setting[1]);
                    echo '||0||' . __('Capability withdrawn', 'wp-photo-album-plus') . '||';
                    wppa_exit();
                } else {
                    echo '||1||Invalid value: ' . $value . '||';
                    wppa_exit();
                }
            } else {
                switch ($option) {
                    case 'wppa_colwidth':
                        //	 ??	  fixed   low	high	title
                        wppa_ajax_check_range($value, 'auto', '100', false, __('Column width.', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_initial_colwidth':
                        wppa_ajax_check_range($value, false, '100', false, __('Initial width.', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_fullsize':
                        wppa_ajax_check_range($value, false, '100', false, __('Full size.', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_maxheight':
                        wppa_ajax_check_range($value, false, '100', false, __('Max height.', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_thumbsize':
                        wppa_ajax_check_range($value, false, '50', false, __('Thumbnail size.', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_tf_width':
                        wppa_ajax_check_range($value, false, '50', false, __('Thumbnail frame width', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_tf_height':
                        wppa_ajax_check_range($value, false, '50', false, __('Thumbnail frame height', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_tn_margin':
                        wppa_ajax_check_range($value, false, '0', false, __('Thumbnail Spacing', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_min_thumbs':
                        wppa_ajax_check_range($value, false, '0', false, __('Photocount treshold.', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_thumb_page_size':
                        wppa_ajax_check_range($value, false, '0', false, __('Thumb page size.', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_smallsize':
                        wppa_ajax_check_range($value, false, '50', false, __('Cover photo size.', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_album_page_size':
                        wppa_ajax_check_range($value, false, '0', false, __('Album page size.', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_topten_count':
                        wppa_ajax_check_range($value, false, '2', false, __('Number of TopTen photos', 'wp-photo-album-plus'), '40');
                        break;
                    case 'wppa_topten_size':
                        wppa_ajax_check_range($value, false, '32', false, __('Widget image thumbnail size', 'wp-photo-album-plus'), wppa_get_minisize());
                        break;
                    case 'wppa_max_cover_width':
                        wppa_ajax_check_range($value, false, '150', false, __('Max Cover width', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_text_frame_height':
                        wppa_ajax_check_range($value, false, '0', false, __('Minimal description height', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_cover_minheight':
                        wppa_ajax_check_range($value, false, '0', false, __('Minimal cover height', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_head_and_text_frame_height':
                        wppa_ajax_check_range($value, false, '0', false, __('Minimal text frame height', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_bwidth':
                        wppa_ajax_check_range($value, '', '0', false, __('Border width', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_bradius':
                        wppa_ajax_check_range($value, '', '0', false, __('Border radius', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_box_spacing':
                        wppa_ajax_check_range($value, '', '-20', '100', __('Box spacing', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_popupsize':
                        $floor = wppa_opt('thumbsize');
                        $temp = wppa_opt('smallsize');
                        if ($temp > $floor) {
                            $floor = $temp;
                        }
                        wppa_ajax_check_range($value, false, $floor, wppa_opt('fullsize'), __('Popup size', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_fullimage_border_width':
                        wppa_ajax_check_range($value, '', '0', false, __('Fullsize border width', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_lightbox_bordersize':
                        wppa_ajax_check_range($value, false, '0', false, __('Lightbox Bordersize', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_ovl_border_width':
                        wppa_ajax_check_range($value, false, '0', '16', __('Lightbox Borderwidth', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_ovl_border_radius':
                        wppa_ajax_check_range($value, false, '0', '16', __('Lightbox Borderradius', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_comment_count':
                        wppa_ajax_check_range($value, false, '2', '40', __('Number of Comment widget entries', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_comment_size':
                        wppa_ajax_check_range($value, false, '32', wppa_get_minisize(), __('Comment Widget image thumbnail size', 'wp-photo-album-plus'), wppa_get_minisize());
                        break;
                    case 'wppa_thumb_opacity':
                        wppa_ajax_check_range($value, false, '0', '100', __('Opacity.', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_cover_opacity':
                        wppa_ajax_check_range($value, false, '0', '100', __('Opacity.', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_star_opacity':
                        wppa_ajax_check_range($value, false, '0', '50', __('Opacity.', 'wp-photo-album-plus'));
                        break;
                        //				case 'wppa_filter_priority':
                        //					wppa_ajax_check_range( $value, false, wppa_opt( 'shortcode_priority' ), false, __( 'Filter priority' ,'wp-photo-album-plus' ) );
                        //					break;
                        //				case 'wppa_shortcode_priority':
                        //					wppa_ajax_check_range( $value, false, '0', wppa_opt( 'filter_priority' ) - '1', __( 'Shortcode_priority', 'wp-photo-album-plus' ) );
                        //					break;
                    //				case 'wppa_filter_priority':
                    //					wppa_ajax_check_range( $value, false, wppa_opt( 'shortcode_priority' ), false, __( 'Filter priority' ,'wp-photo-album-plus' ) );
                    //					break;
                    //				case 'wppa_shortcode_priority':
                    //					wppa_ajax_check_range( $value, false, '0', wppa_opt( 'filter_priority' ) - '1', __( 'Shortcode_priority', 'wp-photo-album-plus' ) );
                    //					break;
                    case 'wppa_gravatar_size':
                        wppa_ajax_check_range($value, false, '10', '256', __('Avatar size', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_watermark_opacity':
                        wppa_ajax_check_range($value, false, '0', '100', __('Watermark opacity', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_watermark_opacity_text':
                        wppa_ajax_check_range($value, false, '0', '100', __('Watermark opacity', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_ovl_txt_lines':
                        wppa_ajax_check_range($value, 'auto', '0', '24', __('Number of text lines', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_ovl_opacity':
                        wppa_ajax_check_range($value, false, '0', '100', __('Overlay opacity', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_upload_limit_count':
                        wppa_ajax_check_range($value, false, '0', false, __('Upload limit', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_dislike_mail_every':
                        wppa_ajax_check_range($value, false, '0', false, __('Notify inappropriate', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_dislike_set_pending':
                        wppa_ajax_check_range($value, false, '0', false, __('Dislike pending', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_dislike_delete':
                        wppa_ajax_check_range($value, false, '0', false, __('Dislike delete', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_max_execution_time':
                        wppa_ajax_check_range($value, false, '0', '900', __('Max execution time', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_cp_points_comment':
                    case 'wppa_cp_points_rating':
                    case 'wppa_cp_points_upload':
                        wppa_ajax_check_range($value, false, '0', false, __('Cube Points points', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_jpeg_quality':
                        wppa_ajax_check_range($value, false, '20', '100', __('JPG Image quality', 'wp-photo-album-plus'));
                        if (wppa_cdn('admin') == 'cloudinary' && !wppa('out')) {
                            wppa_delete_derived_from_cloudinary();
                        }
                        break;
                    case 'wppa_imgfact_count':
                        wppa_ajax_check_range($value, false, '1', '24', __('Number of coverphotos', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_dislike_value':
                        wppa_ajax_check_range($value, false, '-10', '0', __('Dislike value', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_slideshow_pagesize':
                        wppa_ajax_check_range($value, false, '0', false, __('Slideshow pagesize', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_pagelinks_max':
                        wppa_ajax_check_range($value, false, '0', false, __('Max Pagelinks', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_start_pause_symbol_size':
                        wppa_ajax_check_range($value, false, '0', false, __('Start/pause symbol size', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_start_pause_symbol_bradius':
                        wppa_ajax_check_range($value, false, '0', false, __('Start/pause symbol border radius', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_stop_symbol_size':
                        wppa_ajax_check_range($value, false, '0', false, __('Stop symbol size', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_stop_symbol_bradius':
                        wppa_ajax_check_range($value, false, '0', false, __('Stop symbol border radius', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_rating_clear':
                        $iret1 = $wpdb->query('TRUNCATE TABLE ' . WPPA_RATING);
                        $iret2 = $wpdb->query('UPDATE ' . WPPA_PHOTOS . ' SET mean_rating="0", rating_count="0" WHERE id > -1');
                        if ($iret1 !== false && $iret2 !== false) {
                            delete_option('wppa_' . WPPA_RATING . '_lastkey');
                            $title = __('Ratings cleared', 'wp-photo-album-plus');
                        } else {
                            $title = __('Could not clear ratings', 'wp-photo-album-plus');
                            $alert = $title;
                            wppa('error', '1');
                        }
                        break;
                    case 'wppa_viewcount_clear':
                        $iret = $wpdb->query("UPDATE `" . WPPA_PHOTOS . "` SET `views` = '0'") && $wpdb->query("UPDATE `" . WPPA_ALBUMS . "` SET `views` = '0'");
                        if ($iret !== false) {
                            $title = __('Viewcounts cleared', 'wp-photo-album-plus');
                        } else {
                            $title = __('Could not clear viewcounts', 'wp-photo-album-plus');
                            $alert = $title;
                            wppa('error', '1');
                        }
                        break;
                    case 'wppa_iptc_clear':
                        $iret = $wpdb->query('TRUNCATE TABLE ' . WPPA_IPTC);
                        if ($iret !== false) {
                            delete_option('wppa_' . WPPA_IPTC . '_lastkey');
                            $title = __('IPTC data cleared', 'wp-photo-album-plus');
                            $alert = __('Refresh this page to clear table X', 'wp-photo-album-plus');
                            update_option('wppa_index_need_remake', 'yes');
                        } else {
                            $title = __('Could not clear IPTC data', 'wp-photo-album-plus');
                            $alert = $title;
                            wppa('error', '1');
                        }
                        break;
                    case 'wppa_exif_clear':
                        $iret = $wpdb->query('TRUNCATE TABLE ' . WPPA_EXIF);
                        if ($iret !== false) {
                            delete_option('wppa_' . WPPA_EXIF . '_lastkey');
                            $title = __('EXIF data cleared', 'wp-photo-album-plus');
                            $alert = __('Refresh this page to clear table XI', 'wp-photo-album-plus');
                            update_option('wppa_index_need_remake', 'yes');
                        } else {
                            $title = __('Could not clear EXIF data', 'wp-photo-album-plus');
                            $alert = $title;
                            wppa('error', '1');
                        }
                        break;
                    case 'wppa_recup':
                        $result = wppa_recuperate_iptc_exif();
                        echo '||0||' . __('Recuperation performed', 'wp-photo-album-plus') . '||' . $result;
                        wppa_exit();
                        break;
                    case 'wppa_bgcolor_thumbnail':
                        $value = trim(strtolower($value));
                        if (strlen($value) != '7' || substr($value, 0, 1) != '#') {
                            wppa('error', '1');
                        } else {
                            for ($i = 1; $i < 7; $i++) {
                                if (!in_array(substr($value, $i, 1), array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'))) {
                                    wppa('error', '1');
                                }
                            }
                        }
                        if (!wppa('error')) {
                            $old_minisize--;
                        } else {
                            $alert = __('Illegal format. Please enter a 6 digit hexadecimal color value. Example: #77bbff', 'wp-photo-album-plus');
                        }
                        break;
                    case 'wppa_thumb_aspect':
                        $old_minisize--;
                        // Trigger regen message
                        break;
                    case 'wppa_rating_max':
                        if ($value == '5' && wppa_opt('rating_max') == '10') {
                            $rats = $wpdb->get_results('SELECT `id`, `value` FROM `' . WPPA_RATING . '`', ARRAY_A);
                            if ($rats) {
                                foreach ($rats as $rat) {
                                    $wpdb->query($wpdb->prepare('UPDATE `' . WPPA_RATING . '` SET `value` = %s WHERE `id` = %s', $rat['value'] / 2, $rat['id']));
                                }
                            }
                        }
                        if ($value == '10' && wppa_opt('rating_max') == '5') {
                            $rats = $wpdb->get_results('SELECT `id`, `value` FROM `' . WPPA_RATING . '`', ARRAY_A);
                            if ($rats) {
                                foreach ($rats as $rat) {
                                    $wpdb->query($wpdb->prepare('UPDATE `' . WPPA_RATING . '` SET `value` = %s WHERE `id` = %s', $rat['value'] * 2, $rat['id']));
                                }
                            }
                        }
                        update_option('wppa_rerate_status', 'Required');
                        $alert .= __('You just changed a setting that requires the recalculation of ratings.', 'wp-photo-album-plus');
                        $alert .= ' ' . __('Please run the appropriate action in Table VIII.', 'wp-photo-album-plus');
                        wppa_update_option($option, $value);
                        wppa('error', '0');
                        break;
                    case 'wppa_newphoto_description':
                        if (wppa_switch('check_balance') && balanceTags($value, true) != $value) {
                            $alert = __('Unbalanced tags in photo description!', 'wp-photo-album-plus');
                            wppa('error', '1');
                        } else {
                            wppa_update_option($option, $value);
                            wppa('error', '0');
                            $alert = '';
                            wppa_index_compute_skips();
                        }
                        break;
                    case 'wppa_keep_source':
                        $dir = wppa_opt('source_dir');
                        if (!is_dir($dir)) {
                            @mkdir($dir);
                        }
                        if (!is_dir($dir) || !is_writable($dir)) {
                            wppa('error', '1');
                            $alert = sprintf(__('Unable to create or write to %s', 'wp-photo-album-plus'), $dir);
                        }
                        break;
                    case 'wppa_source_dir':
                        $olddir = wppa_opt('source_dir');
                        $value = rtrim($value, '/');
                        if (strpos($value . '/', WPPA_UPLOAD_PATH . '/') !== false) {
                            wppa('error', '1');
                            $alert = sprintf(__('Source can not be inside the wppa folder.', 'wp-photo-album-plus'));
                        } else {
                            $dir = $value;
                            if (!is_dir($dir)) {
                                @mkdir($dir);
                            }
                            if (!is_dir($dir) || !is_writable($dir)) {
                                wppa('error', '1');
                                $alert = sprintf(__('Unable to create or write to %s', 'wp-photo-album-plus'), $dir);
                            } else {
                                @rmdir($olddir);
                                // try to remove when empty
                            }
                        }
                        break;
                    case 'wppa_newpag_content':
                        if (strpos($value, 'w#album') === false) {
                            $alert = __('The content must contain w#album', 'wp-photo-album-plus');
                            wppa('error', '1');
                        }
                        break;
                    case 'wppa_gpx_shortcode':
                        if (strpos($value, 'w#lat') === false || strpos($value, 'w#lon') === false) {
                            $alert = __('The content must contain w#lat and w#lon', 'wp-photo-album-plus');
                            wppa('error', '1');
                        }
                        break;
                    case 'wppa_i_responsive':
                        if ($value == 'yes') {
                            wppa_update_option('wppa_colwidth', 'auto');
                        }
                        if ($value == 'no') {
                            wppa_update_option('wppa_colwidth', '640');
                        }
                        break;
                    case 'wppa_i_downsize':
                        if ($value == 'yes') {
                            wppa_update_option('wppa_resize_on_upload', 'yes');
                            if (wppa_opt('resize_to') == '0') {
                                wppa_update_option('wppa_resize_to', '1024x768');
                            }
                        }
                        if ($value == 'no') {
                            wppa_update_option('wppa_resize_on_upload', 'no');
                        }
                        break;
                    case 'wppa_i_source':
                        if ($value == 'yes') {
                            wppa_update_option('wppa_keep_source_admin', 'yes');
                            wppa_update_option('wppa_keep_source_frontend', 'yes');
                        }
                        if ($value == 'no') {
                            wppa_update_option('wppa_keep_source_admin', 'no');
                            wppa_update_option('wppa_keep_source_frontend', 'no');
                        }
                        break;
                    case 'wppa_i_userupload':
                        if ($value == 'yes') {
                            wppa_update_option('wppa_user_upload_on', 'yes');
                            wppa_update_option('wppa_user_upload_login', 'yes');
                            wppa_update_option('wppa_owner_only', 'yes');
                            wppa_update_option('wppa_upload_moderate', 'yes');
                            wppa_update_option('wppa_upload_edit', 'yes');
                            wppa_update_option('wppa_upload_notify', 'yes');
                            wppa_update_option('wppa_grant_an_album', 'yes');
                            $grantparent = wppa_opt('grant_parent');
                            if (!wppa_album_exists($grantparent)) {
                                $id = wppa_create_album_entry(array('name' => __('Members', 'wp-photo-album-plus'), 'description' => __('Parent of the member albums', 'wp-photo-album-plus'), 'a_parent' => '-1', 'upload_limit' => '0/0'));
                                if ($id) {
                                    wppa_index_add('album', $id);
                                    wppa_update_option('wppa_grant_parent', $id);
                                }
                                $my_post = array('post_title' => __('Members', 'wp-photo-album-plus'), 'post_content' => '[wppa type="content" album="' . $id . '"][/wppa]', 'post_status' => 'publish', 'post_type' => 'page');
                                $pagid = wp_insert_post($my_post);
                            }
                            wppa_update_option('wppa_alt_is_restricted', 'yes');
                            wppa_update_option('wppa_link_is_restricted', 'yes');
                            wppa_update_option('wppa_covertype_is_restricted', 'yes');
                            wppa_update_option('wppa_porder_restricted', 'yes');
                        }
                        if ($value == 'no') {
                            wppa_update_option('wppa_user_upload_on', 'no');
                        }
                        break;
                    case 'wppa_i_rating':
                        if ($value == 'yes') {
                            wppa_update_option('wppa_rating_on', 'yes');
                        }
                        if ($value == 'no') {
                            wppa_update_option('wppa_rating_on', 'no');
                        }
                        break;
                    case 'wppa_i_comment':
                        if ($value == 'yes') {
                            wppa_update_option('wppa_show_comments', 'yes');
                            wppa_update_option('wppa_comment_moderation', 'all');
                            wppa_update_option('wppa_comment_notify', 'admin');
                        }
                        if ($value == 'no') {
                            wppa_update_option('wppa_show_comments', 'no');
                        }
                        break;
                    case 'wppa_i_share':
                        if ($value == 'yes') {
                            wppa_update_option('wppa_share_on', 'yes');
                        }
                        if ($value == 'no') {
                            wppa_update_option('wppa_share_on', 'no');
                        }
                        break;
                    case 'wppa_i_iptc':
                        if ($value == 'yes') {
                            wppa_update_option('wppa_show_iptc', 'yes');
                            wppa_update_option('wppa_save_iptc', 'yes');
                        }
                        if ($value == 'no') {
                            wppa_update_option('wppa_show_iptc', 'no');
                            wppa_update_option('wppa_save_iptc', 'no');
                        }
                        break;
                    case 'wppa_i_exif':
                        if ($value == 'yes') {
                            wppa_update_option('wppa_show_exif', 'yes');
                            wppa_update_option('wppa_save_exif', 'yes');
                        }
                        if ($value == 'no') {
                            wppa_update_option('wppa_show_exif', 'no');
                            wppa_update_option('wppa_save_exif', 'no');
                        }
                        break;
                    case 'wppa_i_gpx':
                        if ($value == 'yes') {
                            $custom_content = wppa_opt('custom_content');
                            if (strpos($custom_content, 'w#location') === false) {
                                $custom_content = $custom_content . ' w#location';
                                wppa_update_option('wppa_custom_content', $custom_content);
                            }
                            if (!wppa_switch('custom_on')) {
                                wppa_update_option('wppa_custom_on', 'yes');
                            }
                            if (wppa_opt('gpx_implementation') == 'none') {
                                wppa_update_option('wppa_gpx_implementation', 'wppa-plus-embedded');
                            }
                        }
                        break;
                    case 'wppa_i_fotomoto':
                        if ($value == 'yes') {
                            $custom_content = wppa_opt('custom_content');
                            if (strpos($custom_content, 'w#fotomoto') === false) {
                                $custom_content = 'w#fotomoto ' . $custom_content;
                                wppa_update_option('wppa_custom_content', $custom_content);
                            }
                            if (!wppa_switch('custom_on')) {
                                wppa_update_option('wppa_custom_on', 'yes');
                            }
                            wppa_update_option('wppa_fotomoto_on', 'yes');
                            wppa_update_option('wppa_custom_on', 'yes');
                        }
                        break;
                    case 'wppa_i_video':
                        if ($value == 'yes') {
                            wppa_update_option('wppa_enable_video', 'yes');
                        } else {
                            wppa_update_option('wppa_enable_video', 'no');
                        }
                        break;
                    case 'wppa_i_audio':
                        if ($value == 'yes') {
                            wppa_update_option('wppa_enable_audio', 'yes');
                        } else {
                            wppa_update_option('wppa_enable_audio', 'no');
                        }
                        break;
                    case 'wppa_i_done':
                        $value = 'done';
                        break;
                    case 'wppa_search_tags':
                    case 'wppa_search_cats':
                    case 'wppa_search_comments':
                        update_option('wppa_index_need_remake', 'yes');
                        break;
                    case 'wppa_blacklist_user':
                        // Does user exist?
                        $value = trim($value);
                        $user = get_user_by('login', $value);
                        // seems to be case insensitive
                        if ($user && $user->user_login === $value) {
                            $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_PHOTOS . "` SET `status` = 'pending' WHERE `owner` = %s", $value));
                            $black_listed_users = get_option('wppa_black_listed_users', array());
                            if (!in_array($value, $black_listed_users)) {
                                $black_listed_users[] = $value;
                                update_option('wppa_black_listed_users', $black_listed_users);
                            }
                            $alert = esc_js(sprintf(__('User %s has been blacklisted.', 'wp-photo-album-plus'), $value));
                        } else {
                            $alert = esc_js(sprintf(__('User %s does not exist.', 'wp-photo-album-plus'), $value));
                        }
                        $value = '';
                        break;
                    case 'wppa_un_blacklist_user':
                        $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_PHOTOS . "` SET `status` = 'publish' WHERE `owner` = %s", $value));
                        $black_listed_users = get_option('wppa_black_listed_users', array());
                        if (in_array($value, $black_listed_users)) {
                            foreach (array_keys($black_listed_users) as $usr) {
                                if ($black_listed_users[$usr] == $value) {
                                    unset($black_listed_users[$usr]);
                                }
                            }
                            update_option('wppa_black_listed_users', $black_listed_users);
                        }
                        $value = '0';
                        break;
                    case 'wppa_fotomoto_on':
                        if ($value == 'yes') {
                            $custom_content = wppa_opt('custom_content');
                            if (strpos($custom_content, 'w#fotomoto') === false) {
                                $custom_content = 'w#fotomoto ' . $custom_content;
                                wppa_update_option('wppa_custom_content', $custom_content);
                                $alert = __('The content of the Custom box has been changed to display the Fotomoto toolbar.', 'wp-photo-album-plus') . ' ';
                            }
                            if (!wppa_switch('custom_on')) {
                                wppa_update_option('wppa_custom_on', 'yes');
                                $alert .= __('The display of the custom box has been enabled', 'wp-photo-album-plus');
                            }
                        }
                        break;
                    case 'wppa_gpx_implementation':
                        if ($value != 'none') {
                            $custom_content = wppa_opt('custom_content');
                            if (strpos($custom_content, 'w#location') === false) {
                                $custom_content = $custom_content . ' w#location';
                                wppa_update_option('wppa_custom_content', $custom_content);
                                $alert = __('The content of the Custom box has been changed to display maps.', 'wp-photo-album-plus') . ' ';
                            }
                            if (!wppa_switch('custom_on')) {
                                wppa_update_option('wppa_custom_on', 'yes');
                                $alert .= __('The display of the custom box has been enabled', 'wp-photo-album-plus');
                            }
                        }
                        break;
                    case 'wppa_regen_thumbs_skip_one':
                        $last = get_option('wppa_regen_thumbs_last', '0');
                        $skip = $last + '1';
                        update_option('wppa_regen_thumbs_last', $skip);
                        break;
                    case 'wppa_remake_skip_one':
                        $last = get_option('wppa_remake_last', '0');
                        $skip = $last + '1';
                        update_option('wppa_remake_last', $skip);
                        break;
                    case 'wppa_errorlog_purge':
                        @unlink(WPPA_CONTENT_PATH . '/wppa-depot/admin/error.log');
                        break;
                    case 'wppa_pl_dirname':
                        $value = wppa_sanitize_file_name($value);
                        $value = trim($value, ' /');
                        if (!$value) {
                            wppa('error', '714');
                            wppa_out(__('This value can not be empty', 'wp-photo-album-plus'));
                        } else {
                            wppa_create_pl_htaccess($value);
                        }
                        break;
                    case 'wppa_new_tag_value':
                        $value = wppa_sanitize_tags($value, false, true);
                        break;
                    case 'wppa_up_tagselbox_content_1':
                    case 'wppa_up_tagselbox_content_2':
                    case 'wppa_up_tagselbox_content_3':
                        $value = wppa_sanitize_tags($value);
                        break;
                    case 'wppa_wppa_set_shortcodes':
                        $value = str_replace(' ', '', $value);
                        break;
                    case 'wppa_enable_video':
                        // if off: set all statusses of videos to pending
                        break;
                    default:
                        wppa('error', '0');
                        $alert = '';
                }
            }
            if (wppa('error')) {
                if (!$title) {
                    $title = sprintf(__('Failed to set %s to %s', 'wp-photo-album-plus'), $option, $value);
                }
                if (!$alert) {
                    $alert .= wppa('out');
                }
            } else {
                wppa_update_option($option, $value);
                if (!$title) {
                    $title = sprintf(__('Setting %s updated to %s', 'wp-photo-album-plus'), $option, $value);
                }
            }
            // Save possible error
            $error = wppa('error');
            // Something to do after changing the setting?
            wppa_initialize_runtime(true);
            // force reload new values
            // .htaccess
            wppa_create_wppa_htaccess();
            // Thumbsize
            $new_minisize = wppa_get_minisize();
            if ($old_minisize != $new_minisize) {
                update_option('wppa_regen_thumbs_status', 'Required');
                $alert .= __('You just changed a setting that requires the regeneration of thumbnails.', 'wp-photo-album-plus');
                $alert .= ' ' . __('Please run the appropriate action in Table VIII.', 'wp-photo-album-plus');
            }
            // Produce the response text
            $output = '||' . $error . '||' . esc_attr($title) . '||' . esc_js($alert);
            echo $output;
            wppa_clear_cache();
            wppa_exit();
            break;
            // End update-option
        // End update-option
        case 'maintenance':
            $slug = $_POST['slug'];
            $nonce = $_REQUEST['wppa-nonce'];
            if (!wp_verify_nonce($nonce, 'wppa-nonce')) {
                echo 'Security check failure||' . $slug . '||Error||0';
                wppa_exit();
            }
            echo wppa_do_maintenance_proc($slug);
            wppa_exit();
            break;
        case 'maintenancepopup':
            $slug = $_POST['slug'];
            $nonce = $_REQUEST['wppa-nonce'];
            if (!wp_verify_nonce($nonce, 'wppa-nonce')) {
                echo 'Security check failure||' . $slug . '||Error||0';
                wppa_exit();
            }
            echo wppa_do_maintenance_popup($slug);
            wppa_exit();
            break;
        case 'do-fe-upload':
            if (is_admin()) {
                require_once 'wppa-non-admin.php';
            }
            wppa_user_upload();
            echo wppa('out');
            wppa_exit();
            break;
        case 'sanitizetags':
            $tags = isset($_GET['tags']) ? $_GET['tags'] : '';
            $album = isset($_GET['album']) ? $_GET['album'] : '0';
            $deftags = $album ? wppa_get_album_item($album, 'default_tags') : '';
            $tags = $deftags ? $tags . ',' . $deftags : $tags;
            echo wppa_sanitize_tags($tags, false, true);
            wppa_exit();
            break;
        case 'destroyalbum':
            $album = isset($_GET['album']) ? $_GET['album'] : '0';
            if (!$album) {
                _e('Missing album id', 'wp-photo-album-plus');
                wppa_exit();
            }
            $nonce = isset($_GET['nonce']) ? $_GET['nonce'] : '';
            if (!$nonce || !wp_verify_nonce($nonce, 'wppa_nonce_' . $album)) {
                echo 'Security check failure #798';
                wppa_exit();
            }
            // May I?
            $imay = true;
            if (!wppa_switch('user_destroy_on')) {
                $may = false;
            }
            if (wppa_switch('user_create_login')) {
                if (!is_user_logged_in()) {
                    $may = false;
                }
                // Must login
            }
            if (!wppa_have_access($album)) {
                $may = false;
                // No album access
            }
            if (wppa_is_user_blacklisted()) {
                $may = false;
            }
            if (!$imay) {
                _e('You do not have the rights to delete this album', 'wp-photo-album-plus');
                wppa_exit();
            }
            // I may
            require_once 'wppa-album-admin-autosave.php';
            wppa_del_album($album, '');
            wppa_exit();
            break;
        default:
            // Unimplemented $wppa-action
            die('-1');
    }
    wppa_exit();
}
function wppa_album_select_a($args)
{
    global $wpdb;
    $args = wp_parse_args($args, array('exclude' => '', 'selected' => '', 'disabled' => '', 'addpleaseselect' => false, 'addnone' => false, 'addall' => false, 'addgeneric' => false, 'addblank' => false, 'addselected' => false, 'addseparate' => false, 'addselbox' => false, 'addowner' => false, 'disableancestors' => false, 'checkaccess' => false, 'checkowner' => false, 'checkupload' => false, 'addmultiple' => false, 'addnumbers' => false, 'path' => false, 'root' => false, 'content' => false, 'sort' => true, 'checkarray' => false, 'array' => array(), 'optionclass' => ''));
    // Provide default selection if no selected given
    if ($args['selected'] === '') {
        $args['selected'] = wppa_get_last_album();
    }
    // See if selection is valid
    if ($args['selected'] == $args['exclude'] || $args['checkupload'] && !wppa_allow_uploads($args['selected']) || $args['disableancestors'] && wppa_is_ancestor($args['exclude'], $args['selected'])) {
        $args['selected'] = '0';
    }
    // Get roughly the albums that might be in the selection
    if ($args['checkarray'] && !empty($args['array'])) {
        $albums = $wpdb->get_results("SELECT `id`, `name` " . "FROM `" . WPPA_ALBUMS . "` " . "WHERE `id` IN (" . implode(',', $args['array']) . ") " . ($args['checkowner'] && wppa_switch('upload_owner_only') && !wppa_user_is('administrator') ? "AND `owner` IN ( '--- public ---', '" . wppa_get_user() . "' ) " : "") . wppa_get_album_order($args['root']), ARRAY_A);
    } else {
        $albums = $wpdb->get_results("SELECT `id`, `name` " . "FROM `" . WPPA_ALBUMS . "` " . ($args['checkowner'] && wppa_switch('upload_owner_only') && !wppa_user_is('administrator') ? "WHERE `owner` IN ( '--- public ---', '" . wppa_get_user() . "' ) " : "") . wppa_get_album_order($args['root']), ARRAY_A);
    }
    /* Can not add to cache because only "SELECT * " can be added
    	// Add to secondary cache
    	if ( $albums ) {
    		wppa_cache_album( 'add', $albums );
    	}
    	*/
    if ($albums) {
        // Filter for root
        if ($args['root']) {
            $root = $args['root'];
            switch ($root) {
                // case '0': all, will be skipped as it returns false in 'if ( $args['root'] )'
                case '-2':
                    // Generic only
                    foreach (array_keys($albums) as $albidx) {
                        if (wppa_is_separate($albums[$albidx]['id'])) {
                            unset($albums[$albidx]);
                        }
                    }
                    break;
                case '-1':
                    // Separate only
                    foreach (array_keys($albums) as $albidx) {
                        if (!wppa_is_separate($albums[$albidx]['id'])) {
                            unset($albums[$albidx]);
                        }
                    }
                    break;
                default:
                    foreach (array_keys($albums) as $albidx) {
                        if (!wppa_is_ancestor($root, $albums[$albidx]['id'])) {
                            unset($albums[$albidx]);
                        }
                    }
                    break;
            }
        }
        // Filter for must have content
        if ($args['content']) {
            foreach (array_keys($albums) as $albidx) {
                if (wppa_get_photo_count($albums[$albidx]['id']) <= wppa_get_mincount()) {
                    unset($albums[$albidx]);
                }
            }
        }
        // Add paths
        if ($args['path']) {
            $albums = wppa_add_paths($albums);
        } else {
            foreach (array_keys($albums) as $index) {
                $albums[$index]['name'] = __(stripslashes($albums[$index]['name']));
            }
        }
        // Sort
        if ($args['sort']) {
            $albums = wppa_array_sort($albums, 'name');
        }
    }
    // Output
    $result = '';
    $selected = $args['selected'] == '0' ? ' selected="selected"' : '';
    if ($args['addpleaseselect']) {
        $result .= '<option value="0" disabled="disabled" ' . $selected . ' >' . __('- select an album -', 'wp-photo-album-plus') . '</option>';
    }
    $selected = $args['selected'] == '0' ? ' selected="selected"' : '';
    if ($args['addnone']) {
        $result .= '<option value="0"' . $selected . ' >' . __('--- none ---', 'wp-photo-album-plus') . '</option>';
    }
    $selected = $args['selected'] == '0' ? ' selected="selected"' : '';
    if ($args['addall']) {
        $result .= '<option value="0"' . $selected . ' >' . __('--- all ---', 'wp-photo-album-plus') . '</option>';
    }
    $selected = $args['selected'] == '-2' ? ' selected="selected"' : '';
    if ($args['addall']) {
        $result .= '<option value="-2"' . $selected . ' >' . __('--- generic ---', 'wp-photo-album-plus') . '</option>';
    }
    $selected = $args['selected'] == '-3' ? ' selected="selected"' : '';
    if ($args['addowner']) {
        $result .= '<option value="-3"' . $selected . ' >' . __('--- owner/public ---', 'wp-photo-album-plus') . '</option>';
    }
    $selected = $args['selected'] == '0' ? ' selected="selected"' : '';
    if ($args['addblank']) {
        $result .= '<option value="0"' . $selected . ' >' . '</option>';
    }
    $selected = $args['selected'] == '-99' ? ' selected="selected"' : '';
    if ($args['addmultiple']) {
        $result .= '<option value="-99"' . $selected . ' >' . __('--- multiple see below ---', 'wp-photo-album-plus') . '</option>';
    }
    $selected = $args['selected'] == '0' ? ' selected="selected"' : '';
    if ($args['addselbox']) {
        $result .= '<option value="0"' . $selected . ' >' . __('--- a selection box ---', 'wp-photo-album-plus') . '</option>';
    }
    // In case multiple
    if (strpos($args['selected'], ',') !== false) {
        $selarr = explode(',', $args['selected']);
    } else {
        $selarr = array($args['selected']);
    }
    if ($albums) {
        foreach ($albums as $album) {
            if ($args['disabled'] == $album['id'] || $args['exclude'] == $album['id'] || $args['checkupload'] && !wppa_allow_uploads($album['id']) || $args['disableancestors'] && wppa_is_ancestor($args['exclude'], $album['id'])) {
                $disabled = ' disabled="disabled"';
            } else {
                $disabled = '';
            }
            if (in_array($album['id'], $selarr, true) && !$disabled) {
                $selected = ' selected="selected"';
            } else {
                $selected = '';
            }
            $ok = true;
            // Assume this will be in the list
            if ($args['checkaccess'] && !wppa_have_access($album['id'])) {
                $ok = false;
            }
            /* This is in the query now
            		if ( $args['checkowner'] && wppa_switch( 'upload_owner_only' ) ) { 							// Need to check
            			if ( $album['owner'] != wppa_get_user() && $album['owner']  != '--- public ---' ) { 	// Not 'mine'
            				if ( ! wppa_user_is( 'administrator' ) ) {											// No admin
            					$ok = false;
            				}
            			}
            		}
            		*/
            /* This is in the query now
            		if ( $args['checkarray'] ) {
            			if ( ! in_array( $album['id'], $args['array'] ) ) {
            				$ok = false;
            			}
            		}
            		*/
            if ($selected && $args['addselected']) {
                $ok = true;
            }
            if ($ok) {
                if ($args['addnumbers']) {
                    $number = ' ( ' . $album['id'] . ' )';
                } else {
                    $number = '';
                }
                $result .= '<option class="' . $args['optionclass'] . '" value="' . $album['id'] . '" ' . $selected . $disabled . '>' . $album['name'] . $number . '</option>';
            }
        }
    }
    $selected = $args['selected'] == '-1' ? ' selected="selected"' : '';
    if ($args['addseparate']) {
        $result .= '<option value="-1"' . $selected . '>' . __('--- separate ---', 'wp-photo-album-plus') . '</option>';
    }
    return $result;
}
function _wppa_admin()
{
    global $wpdb;
    global $q_config;
    global $wppa_revno;
    if (get_option('wppa_revision') != $wppa_revno) {
        wppa_check_database(true);
    }
    echo '
<script type="text/javascript">
	/* <![CDATA[ */
	wppaAjaxUrl = "' . admin_url('admin-ajax.php') . '";
	wppaUploadToThisAlbum = "' . __('Upload to this album', 'wp-photo-album-plus') . '";
	wppaImageDirectory = "' . wppa_get_imgdir() . '";
	/* ]]> */
</script>
';
    // Delete trashed comments
    $query = "DELETE FROM " . WPPA_COMMENTS . " WHERE status='trash'";
    $wpdb->query($query);
    $sel = 'selected="selected"';
    // warn if the uploads directory is no writable
    if (!is_writable(WPPA_UPLOAD_PATH)) {
        wppa_error_message(__('Warning:', 'wp-photo-album-plus') . sprintf(__('The uploads directory does not exist or is not writable by the server. Please make sure that %s is writeable by the server.', 'wp-photo-album-plus'), WPPA_UPLOAD_PATH));
    }
    // Fix orphan albums and deleted target pages
    $albs = $wpdb->get_results("SELECT * FROM `" . WPPA_ALBUMS . "`", ARRAY_A);
    if ($albs) {
        foreach ($albs as $alb) {
            if ($alb['a_parent'] > '0' && wppa_get_parentalbumid($alb['a_parent']) == '-9') {
                // Parent died?
                $wpdb->query("UPDATE `" . WPPA_ALBUMS . "` SET `a_parent` = '-1' WHERE `id` = '" . $alb['id'] . "'");
            }
            if ($alb['cover_linkpage'] > '0') {
                $iret = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . $wpdb->posts . "` WHERE `ID` = %s AND `post_type` = 'page' AND `post_status` = 'publish'", $alb['cover_linkpage']));
                if (!$iret) {
                    // Page gone?
                    $wpdb->query("UPDATE `" . WPPA_ALBUMS . "` SET `cover_linkpage` = '0' WHERE `id` = '" . $alb['id'] . "'");
                }
            }
        }
    }
    if (isset($_REQUEST['tab'])) {
        // album edit page
        if ($_REQUEST['tab'] == 'edit') {
            if (isset($_REQUEST['edit_id'])) {
                $ei = $_REQUEST['edit_id'];
                if ($ei != 'new' && $ei != 'search' && !is_numeric($ei)) {
                    wp_die('Security check failure 1');
                }
            }
            if ($_REQUEST['edit_id'] == 'search') {
                $back_url = get_admin_url() . 'admin.php?page=wppa_admin_menu';
                if (isset($_REQUEST['wppa-searchstring'])) {
                    $back_url .= '&wppa-searchstring=' . wppa_sanitize_searchstring($_REQUEST['wppa-searchstring']);
                }
                $back_url .= '#wppa-edit-search-tag';
                ?>
<a name="manage-photos" id="manage-photos" ></a>
				<h2><?php 
                _e('Manage Photos', 'wp-photo-album-plus');
                if (isset($_REQUEST['bulk'])) {
                    echo ' - <small><i>' . __('Copy / move / delete / edit name / edit description / change status', 'wp-photo-album-plus') . '</i></small>';
                } elseif (isset($_REQUEST['quick'])) {
                    echo ' - <small><i>' . __('Edit photo information except copy and move', 'wp-photo-album-plus') . '</i></small>';
                } else {
                    echo ' - <small><i>' . __('Edit photo information', 'wp-photo-album-plus') . '</i></small>';
                }
                ?>
</h2>

<a href="<?php 
                echo $back_url;
                ?>
"><?php 
                _e('Back to album table', 'wp-photo-album-plus');
                ?>
</a><br /><br />

				<?php 
                if (isset($_REQUEST['bulk'])) {
                    wppa_album_photos_bulk($ei);
                } else {
                    wppa_album_photos($ei);
                }
                ?>
				<br /><a href="#manage-photos"><?php 
                _e('Top of page', 'wp-photo-album-plus');
                ?>
</a>
				<br /><a href="<?php 
                echo $back_url;
                ?>
"><?php 
                _e('Back to album table', 'wp-photo-album-plus');
                ?>
</a>
<?php 
                return;
            }
            if ($_REQUEST['edit_id'] == 'new') {
                if (!wppa_can_create_album()) {
                    wp_die('No rights to create an album');
                }
                $id = wppa_nextkey(WPPA_ALBUMS);
                if (isset($_REQUEST['parent_id'])) {
                    $parent = $_REQUEST['parent_id'];
                    if (!is_numeric($parent)) {
                        wp_die('Security check failure 2');
                    }
                    $name = wppa_get_album_name($parent) . '-#' . $id;
                    if (!current_user_can('administrator')) {
                        // someone creating an album for someone else?
                        $parentowner = $wpdb->get_var($wpdb->prepare("SELECT `owner` FROM `" . WPPA_ALBUMS . "` WHERE `id` = %s", $parent));
                        if ($parentowner !== wppa_get_user()) {
                            wp_die('You are not allowed to create an album for someone else');
                        }
                    }
                } else {
                    $parent = wppa_opt('default_parent');
                    if (!$wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_ALBUMS . "` WHERE `id` = %s", $parent))) {
                        // Deafault parent vanished
                        wppa_update_option('wppa_default_parent', '0');
                        $parent = '0';
                    }
                    $name = __('New Album', 'wp-photo-album-plus');
                    if (!wppa_can_create_top_album()) {
                        wp_die('No rights to create a top-level album');
                    }
                }
                $id = wppa_create_album_entry(array('id' => $id, 'name' => $name, 'a_parent' => $parent));
                if (!$id) {
                    wppa_error_message(__('Could not create album.', 'wp-photo-album-plus'));
                    wp_die('Sorry, cannot continue');
                } else {
                    $edit_id = $id;
                    wppa_set_last_album($edit_id);
                    wppa_flush_treecounts($edit_id);
                    wppa_index_add('album', $id);
                    wppa_update_message(__('Album #', 'wp-photo-album-plus') . ' ' . $edit_id . ' ' . __('Added.', 'wp-photo-album-plus'));
                    wppa_create_pl_htaccess();
                }
            } else {
                $edit_id = $_REQUEST['edit_id'];
            }
            $album_owner = $wpdb->get_var($wpdb->prepare("SELECT `owner` FROM " . WPPA_ALBUMS . " WHERE `id` = %s", $edit_id));
            if ($album_owner == '--- public ---' && !current_user_can('wppa_admin') || !wppa_have_access($edit_id)) {
                wp_die('You do not have the rights to edit this album');
            }
            // Apply new desc
            if (isset($_REQUEST['applynewdesc'])) {
                if (!wp_verify_nonce($_REQUEST['wppa_nonce'], 'wppa_nonce')) {
                    wp_die('You do not have the rights to do this');
                }
                $iret = $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_PHOTOS . "` SET `description` = %s WHERE `album` = %s", wppa_opt('newphoto_description'), $edit_id));
                wppa_ok_message($iret . ' descriptions updated.');
            }
            // Remake album
            if (isset($_REQUEST['remakealbum'])) {
                if (!wp_verify_nonce($_REQUEST['wppa_nonce'], 'wppa_nonce')) {
                    wp_die('You do not have the rights to do this');
                }
                if (get_option('wppa_remake_start_album_' . $edit_id)) {
                    // Continue after time up
                    wppa_ok_message('Continuing remake, please wait');
                } else {
                    update_option('wppa_remake_start_album_' . $edit_id, time());
                    wppa_ok_message('Remaking photofiles, please wait');
                }
                $iret = wppa_remake_files($edit_id);
                if ($iret) {
                    wppa_ok_message('Photo files remade');
                    update_option('wppa_remake_start_album_' . $edit_id, '0');
                } else {
                    wppa_error_message('Remake of photo files did NOT complete');
                }
            }
            // Get the album information
            $albuminfo = $wpdb->get_row($wpdb->prepare('SELECT * FROM `' . WPPA_ALBUMS . '` WHERE `id` = %s', $edit_id), ARRAY_A);
            ?>

			<div class="wrap">
				<?php 
            wppa_admin_spinner();
            ?>
				<h2><?php 
            echo __('Edit Album Information', 'wp-photo-album-plus') . ' <span style="color:blue">' . __('Auto Save', 'wp-photo-album-plus') . '</span>';
            ?>
</h2>
				<p class="description">
					<?php 
            echo __('All modifications are instantly updated on the server, except for those that require a button push.', 'wp-photo-album-plus');
            echo ' ' . __('The <b style="color:#070" >Remark</b> fields keep you informed on the actions taken at the background.', 'wp-photo-album-plus');
            ?>
				</p>
				<p>
					<?php 
            _e('Album number:', 'wp-photo-album-plus');
            echo ' ' . $edit_id . '.';
            ?>
				</p>
					<input type="hidden" id="album-nonce-<?php 
            echo $edit_id;
            ?>
" value="<?php 
            echo wp_create_nonce('wppa_nonce_' . $edit_id);
            ?>
" />
					<table class="widefat wppa-table wppa-album-table">
						<tbody>

							<!-- Name -->
							<tr>
								<th>
									<label><?php 
            _e('Name:', 'wp-photo-album-plus');
            ?>
</label>
								</th>
								<?php 
            if (wppa_switch('wppa_use_wp_editor')) {
                ?>
									<td>
										<input id="wppaalbumname" type="text" style="width: 100%;" value="<?php 
                echo esc_attr(stripslashes($albuminfo['name']));
                ?>
" />
									</td>
									<td>
										<input type="button" class="button-secundary" value="<?php 
                _e('Update Album name', 'wp-photo-album-plus');
                ?>
" onclick="wppaAjaxUpdateAlbum(<?php 
                echo $edit_id;
                ?>
, 'name', document.getElementById('wppaalbumname') )" />
									</td>
								<?php 
            } else {
                ?>
									<td>
										<input type="text" style="width: 100%;" onkeyup="wppaAjaxUpdateAlbum(<?php 
                echo $edit_id;
                ?>
, 'name', this)" onchange="wppaAjaxUpdateAlbum(<?php 
                echo $edit_id;
                ?>
, 'name', this)" value="<?php 
                echo esc_attr(stripslashes($albuminfo['name']));
                ?>
" />
									</td>
									<td>
										<span class="description"><?php 
                _e('Type the name of the album. Do not leave this empty.', 'wp-photo-album-plus');
                ?>
</span>
									</td>
								<?php 
            }
            ?>
							</tr>

							<!-- Description -->
							<tr>
								<th>
									<label><?php 
            _e('Description:', 'wp-photo-album-plus');
            ?>
</label>
								</th>
								<?php 
            if (wppa_switch('wppa_use_wp_editor')) {
                ?>
									<td colspan="2" >

										<?php 
                //	$quicktags_settings = array( 'buttons' => 'strong,em,link,block,ins,ul,ol,li,code,close' );
                //	wp_editor(stripslashes($albuminfo['description']), 'wppaalbumdesc', array('wpautop' => false, 'media_buttons' => false, 'textarea_rows' => '6', 'tinymce' => false, 'quicktags' => $quicktags_settings ));
                wp_editor(stripslashes($albuminfo['description']), 'wppaalbumdesc', array('wpautop' => true, 'media_buttons' => false, 'textarea_rows' => '6', 'tinymce' => true));
                ?>

										<input type="button" class="button-secundary" value="<?php 
                _e('Update Album description', 'wp-photo-album-plus');
                ?>
" onclick="wppaAjaxUpdateAlbum(<?php 
                echo $edit_id;
                ?>
, 'description', document.getElementById('wppaalbumdesc') )" />
										<img id="wppa-album-spin" src="<?php 
                echo wppa_get_imgdir() . 'wpspin.gif';
                ?>
" style="visibility:hidden" />
										<br />
									</td>
								<?php 
            } else {
                ?>
									<td>
										<textarea style="width: 100%; height: 80px;" onkeyup="wppaAjaxUpdateAlbum(<?php 
                echo $edit_id;
                ?>
, 'description', this)" onchange="wppaAjaxUpdateAlbum(<?php 
                echo $edit_id;
                ?>
, 'description', this)" ><?php 
                echo stripslashes($albuminfo['description']);
                ?>
</textarea>
									</td>
									<td>
										<span class="description"><?php 
                _e('Enter / modify the description for this album.', 'wp-photo-album-plus');
                ?>
</span>
									</td>
								<?php 
            }
            ?>
							</tr>

							<!-- Timestamp -->
							<tr>
								<th>
									<label><?php 
            _e('Created:', 'wp-photo-album-plus');
            ?>
</label>
								</th>
								<td>
									<?php 
            echo wppa_local_date(get_option('date_format', "F j, Y,") . ' ' . get_option('time_format', "g:i a"), $albuminfo['timestamp']) . ' ' . __('local time', 'wp-photo-album-plus');
            ?>
								</td>

							<!-- Modified -->
							<tr>
								<th>
									<label><?php 
            _e('Modified:', 'wp-photo-album-plus');
            ?>
</label>
								</th>
								<td>
									<?php 
            if ($albuminfo['modified'] > $albuminfo['timestamp']) {
                echo wppa_local_date(get_option('date_format', "F j, Y,") . ' ' . get_option('time_format', "g:i a"), $albuminfo['modified']) . ' ' . __('local time', 'wp-photo-album-plus');
            } else {
                _e('Not modified', 'wp-photo-album-plus');
            }
            ?>
									<?php 
            ?>
								</td>

							<!-- Views -->
							<tr>
								<th>
									<label><?php 
            _e('Views:', 'wp-photo-album-plus');
            ?>
</label>
								</th>
								<td>
									<?php 
            echo $albuminfo['views'];
            ?>
								</td>
							</tr>

							<!-- Owner -->
							<?php 
            // if ( wppa_switch('wppa_owner_only') ) {
            if (current_user_can('administrator')) {
                ?>
								<tr>
									<th>
										<label><?php 
                _e('Owned by:', 'wp-photo-album-plus');
                ?>
</label>
									</th>
									<?php 
                if ($albuminfo['owner'] == '--- public ---' && !current_user_can('administrator')) {
                    ?>
										<td>
											<?php 
                    _e('--- public ---', 'wp-photo-album-plus');
                    ?>
										</td>
									<?php 
                } else {
                    ?>
										<td>
											<?php 
                    $usercount = wppa_get_user_count();
                    if ($usercount > wppa_opt('max_users')) {
                        ?>
												<input type="text" value="<?php 
                        echo $albuminfo['owner'];
                        ?>
" onchange="wppaAjaxUpdateAlbum(<?php 
                        echo $edit_id;
                        ?>
, 'owner', this)" />
											<?php 
                    } else {
                        ?>
												<select onchange="wppaAjaxUpdateAlbum(<?php 
                        echo $edit_id;
                        ?>
, 'owner', this)" ><?php 
                        wppa_user_select($albuminfo['owner']);
                        ?>
</select>
											<?php 
                    }
                    ?>
										</td>
										<td>
											<?php 
                    if (!current_user_can('administrator')) {
                        ?>
												<span class="description" style="color:orange;" ><?php 
                        _e('WARNING If you change the owner, you will no longer be able to modify this album and upload or import photos to it!', 'wp-photo-album-plus');
                        ?>
</span>
											<?php 
                    }
                    ?>
											<?php 
                    if ($usercount > '1000') {
                        echo '<span class="description" >' . __('Enter user login name or <b>--- public ---</b>', 'wp-photo-album-plus'), '</span>';
                    }
                    ?>
										</td>
									<?php 
                }
                ?>
								</tr>
							<?php 
            }
            ?>

							<!-- Order # -->
							<tr>
								<th>
									<label><?php 
            _e('Album sort order #:', 'wp-photo-album-plus');
            ?>
</label>
								</th>
								<td>
									<input type="text" onkeyup="wppaAjaxUpdateAlbum(<?php 
            echo $edit_id;
            ?>
, 'a_order', this)" onchange="wppaAjaxUpdateAlbum(<?php 
            echo $edit_id;
            ?>
, 'a_order', this)" value="<?php 
            echo $albuminfo['a_order'];
            ?>
" style="width: 50px;"/>
								</td>
								<td>
									<?php 
            if (wppa_opt('list_albums_by') != '1' && $albuminfo['a_order'] != '0') {
                ?>
										<span class="description" style="color:red">
										<?php 
                _e('Album order # has only effect if you set the album sort order method to <b>Order #</b> in the Photo Albums -> Settings screen.<br />', 'wp-photo-album-plus');
                ?>
										</span>
									<?php 
            }
            ?>
									<span class="description"><?php 
            _e('If you want to sort the albums by order #, enter / modify the order number here.', 'wp-photo-album-plus');
            ?>
</span>
								</td>
							</tr>

							<!-- Parent -->
							<tr>
								<th>
									<label><?php 
            _e('Parent album:', 'wp-photo-album-plus');
            ?>
 </label>
								</th>
								<td style="max-width:210px;">
									<?php 
            if (wppa_extended_access()) {
                ?>
										<select id="wppa-parsel" style="max-width:100%;" onchange="wppaAjaxUpdateAlbum(<?php 
                echo $edit_id;
                ?>
, 'a_parent', this)" ><?php 
                echo wppa_album_select_a(array('checkaccess' => true, 'exclude' => $albuminfo['id'], 'selected' => $albuminfo['a_parent'], 'addselected' => true, 'addnone' => true, 'addseparate' => true, 'disableancestors' => true, 'path' => wppa_switch('wppa_hier_albsel')));
                ?>
</select>
									<?php 
            } else {
                ?>
										<select id="wppa-parsel" style="max-width:100%;" onchange="wppaAjaxUpdateAlbum(<?php 
                echo $edit_id;
                ?>
, 'a_parent', this)" ><?php 
                echo wppa_album_select_a(array('checkaccess' => true, 'exclude' => $albuminfo['id'], 'selected' => $albuminfo['a_parent'], 'addselected' => true, 'disableancestors' => true, 'path' => wppa_switch('wppa_hier_albsel')));
                ?>
</select>
									<?php 
            }
            ?>
								</td>
								<td>
									<span class="description">
										<?php 
            _e('If this is a sub album, select the album in which this album will appear.', 'wp-photo-album-plus');
            ?>
									</span>
								</td>
							</tr>

							<!-- P-order-by -->
							<tr>
								<th>
									<?php 
            $order = $albuminfo['p_order_by'];
            ?>
									<label><?php 
            _e('Photo order:', 'wp-photo-album-plus');
            ?>
</label>
								</th>
								<td>
									<?php 
            $options = array(__('--- default ---', 'wp-photo-album-plus'), __('Order #', 'wp-photo-album-plus'), __('Name', 'wp-photo-album-plus'), __('Random', 'wp-photo-album-plus'), __('Rating mean value', 'wp-photo-album-plus'), __('Number of votes', 'wp-photo-album-plus'), __('Timestamp', 'wp-photo-album-plus'), __('EXIF Date', 'wp-photo-album-plus'), __('Order # desc', 'wp-photo-album-plus'), __('Name desc', 'wp-photo-album-plus'), __('Rating mean value desc', 'wp-photo-album-plus'), __('Number of votes desc', 'wp-photo-album-plus'), __('Timestamp desc', 'wp-photo-album-plus'), __('EXIF Date desc', 'wp-photo-album-plus'));
            $values = array('0', '1', '2', '3', '4', '6', '5', '7', '-1', '-2', '-4', '-6', '-5', '-7');
            ?>
									<select onchange="wppaAjaxUpdateAlbum(<?php 
            echo $edit_id;
            ?>
, 'p_order_by', this)">
									<?php 
            foreach (array_keys($options) as $key) {
                $sel = $values[$key] == $order ? ' selected="selected"' : '';
                echo '<option value="' . $values[$key] . '"' . $sel . ' >' . $options[$key] . '</option>';
            }
            ?>
									</select>
								</td>
								<td>
									<span class="description">
										<?php 
            _e('Specify the way the photos should be ordered in this album.', 'wp-photo-album-plus');
            ?>
<br />
										<?php 
            if (current_user_can('wppa_settings')) {
                _e('The default setting can be changed in the <b>Photo Albums -> Settings</b> page <b>Table IV-C1</b>.', 'wp-photo-album-plus');
            }
            ?>
									</span>
								</td>
							</tr>

							<!-- Child album order -->
							<tr>
								<th>
									<label><?php 
            _e('Sub album sort order:', 'wp-photo-album-plus');
            ?>
</label>
								</th>
								<td>
									<select onchange="wppaAjaxUpdateAlbum(<?php 
            echo $edit_id;
            ?>
, 'suba_order_by', this)" >
										<option value="0" <?php 
            if (!$albuminfo['suba_order_by']) {
                echo 'selected="selected"';
            }
            ?>
><?php 
            _e('See Table IV-D1', 'wp-photo-album-plus');
            ?>
</option>
										<option value="3" <?php 
            if ($albuminfo['suba_order_by'] == '3') {
                echo 'selected="selected"';
            }
            ?>
><?php 
            _e('Random', 'wp-photo-album-plus');
            ?>
</option>
										<option value="1" <?php 
            if ($albuminfo['suba_order_by'] == '1') {
                echo 'selected="selected"';
            }
            ?>
><?php 
            _e('Order #', 'wp-photo-album-plus');
            ?>
</option>
										<option value="-1" <?php 
            if ($albuminfo['suba_order_by'] == '-1') {
                echo 'selected="selected"';
            }
            ?>
><?php 
            _e('Order # reverse', 'wp-photo-album-plus');
            ?>
</option>
										<option value="2" <?php 
            if ($albuminfo['suba_order_by'] == '2') {
                echo 'selected="selected"';
            }
            ?>
><?php 
            _e('Name', 'wp-photo-album-plus');
            ?>
</option>
										<option value="-2" <?php 
            if ($albuminfo['suba_order_by'] == '-2') {
                echo 'selected="selected"';
            }
            ?>
><?php 
            _e('Name reverse', 'wp-photo-album-plus');
            ?>
</option>
										<option value="5" <?php 
            if ($albuminfo['suba_order_by'] == '5') {
                echo 'selected="selected"';
            }
            ?>
><?php 
            _e('Timestamp', 'wp-photo-album-plus');
            ?>
</option>
										<option value="-5" <?php 
            if ($albuminfo['suba_order_by'] == '-5') {
                echo 'selected="selected"';
            }
            ?>
><?php 
            _e('Timestamp reverse', 'wp-photo-album-plus');
            ?>
</option>
									</select>
								</td>
								<td>
									<span class="description">
										<?php 
            _e('Specify the sequence order method to be used for the sub albums of this album.', 'wp-photo-album-plus');
            ?>
									</span>
								</td>
							</tr>

							<!-- Alternative thumbnail size? -->
							<?php 
            if (!wppa_switch('wppa_alt_is_restricted') || current_user_can('administrator')) {
                ?>
							<tr>
								<th>
									<label><?php 
                _e('Use alt thumbsize:', 'wp-photo-album-plus');
                ?>
</label>
								</th>
								<td>
									<select onchange="wppaAjaxUpdateAlbum(<?php 
                echo $edit_id;
                ?>
, 'alt_thumbsize', this)" >
										<option value="0" <?php 
                if (!$albuminfo['alt_thumbsize']) {
                    echo 'selected="selected"';
                }
                ?>
><?php 
                _e('no', 'wp-photo-album-plus');
                ?>
</option>
										<option value="yes" <?php 
                if ($albuminfo['alt_thumbsize']) {
                    echo 'selected="selected"';
                }
                ?>
><?php 
                _e('yes', 'wp-photo-album-plus');
                ?>
</option>
									</select>
								</td>
								<td>
									<span class="description">
										<?php 
                _e('If set to <b>yes</b> The settings in <b>Table I-C1a,3a</b> and <b>4a</b> apply rather than <b>I-C1,3</b> and <b>4</b>.', 'wp-photo-album-plus');
                ?>
									</span>
								</td>
							</tr>
							<?php 
            }
            ?>

							<!-- Cover type -->
							<?php 
            if (!wppa_switch('wppa_covertype_is_restricted') || current_user_can('administrator')) {
                ?>
							<tr>
								<th>
									<label><?php 
                _e('Cover Type:', 'wp-photo-album-plus');
                ?>
</label>
								</th>
								<td>
									<?php 
                $sel = 'selected="selected"';
                ?>
									<select onchange="wppaAjaxUpdateAlbum(<?php 
                echo $edit_id;
                ?>
, 'cover_type', this)" >
										<option value="" <?php 
                if ($albuminfo['cover_type'] == '') {
                    echo $sel;
                }
                ?>
 ><?php 
                _e('--- default ---', 'wp-photo-album-plus');
                ?>
</option>
										<option value="default" <?php 
                if ($albuminfo['cover_type'] == 'default') {
                    echo $sel;
                }
                ?>
 ><?php 
                _e('Standard', 'wp-photo-album-plus');
                ?>
</option>
										<option value="longdesc" <?php 
                if ($albuminfo['cover_type'] == 'longdesc') {
                    echo $sel;
                }
                ?>
 ><?php 
                _e('Long Descriptions', 'wp-photo-album-plus');
                ?>
</option>
										<option value="imagefactory" <?php 
                if ($albuminfo['cover_type'] == 'imagefactory') {
                    echo $sel;
                }
                ?>
 ><?php 
                _e('Image Factory', 'wp-photo-album-plus');
                ?>
</option>
										<option value="default-mcr" <?php 
                if ($albuminfo['cover_type'] == 'default-mcr') {
                    echo $sel;
                }
                ?>
 ><?php 
                _e('Standard mcr', 'wp-photo-album-plus');
                ?>
</option>
										<option value="longdesc-mcr" <?php 
                if ($albuminfo['cover_type'] == 'longdesc-mcr') {
                    echo $sel;
                }
                ?>
 ><?php 
                _e('Long Descriptions mcr', 'wp-photo-album-plus');
                ?>
</option>
										<option value="imagefactory-mcr" <?php 
                if ($albuminfo['cover_type'] == 'imagefactory-mcr') {
                    echo $sel;
                }
                ?>
 ><?php 
                _e('Image Factory mcr', 'wp-photo-album-plus');
                ?>
</option>
									</select>
								</td>
								<td>
									<span class="description">
										<?php 
                _e('The default cover type is the systems standard set in the <b>Photo Albums -> Settings</b> page <b>Table IV-D6</b>.', 'wp-photo-album-plus');
                ?>
									</span>
								</td>
							</tr>
							<?php 
            }
            ?>

							<!-- Cover photo -->
							<tr>
								<th>
									<label><?php 
            _e('Cover Photo:', 'wp-photo-album-plus');
            ?>
</label>
								</th>
								<td>
									<?php 
            echo wppa_main_photo($albuminfo['main_photo'], $albuminfo['cover_type']);
            ?>
								</td>
								<td>
									<span class="description">
										<?php 
            if (wppa_opt('cover_type') == 'default') {
                _e('Select the photo you want to appear on the cover of this album.', 'wp-photo-album-plus');
            } else {
                _e('Select the way the cover photos of this album are selected, or select a single image.', 'wp-photo-album-plus');
            }
            ?>
									</span>
								</td>
							</tr>

							<!-- Upload limit -->
							<tr>
								<th>
									<label><?php 
            _e('Upload limit:', 'wp-photo-album-plus');
            ?>
</label>
								</th>
								<td>
								<?php 
            $lims = explode('/', $albuminfo['upload_limit']);
            if (current_user_can('administrator')) {
                ?>
										<input type="text" id="upload_limit_count" value="<?php 
                echo $lims[0];
                ?>
" style="width: 50px" onchange="wppaAjaxUpdateAlbum(<?php 
                echo $edit_id;
                ?>
, 'upload_limit_count', this)" />
										<select onchange="wppaAjaxUpdateAlbum(<?php 
                echo $edit_id;
                ?>
, 'upload_limit_time', this)" >
											<option value="0" <?php 
                if ($lims[1] == '0') {
                    echo 'selected="selected"';
                }
                ?>
><?php 
                _e('for ever', 'wp-photo-album-plus');
                ?>
</option>
											<option value="3600" <?php 
                if ($lims[1] == '3600') {
                    echo 'selected="selected"';
                }
                ?>
><?php 
                _e('per hour', 'wp-photo-album-plus');
                ?>
</option>
											<option value="86400" <?php 
                if ($lims[1] == '86400') {
                    echo 'selected="selected"';
                }
                ?>
><?php 
                _e('per day', 'wp-photo-album-plus');
                ?>
</option>
											<option value="604800" <?php 
                if ($lims[1] == '604800') {
                    echo 'selected="selected"';
                }
                ?>
><?php 
                _e('per week', 'wp-photo-album-plus');
                ?>
</option>
											<option value="2592000" <?php 
                if ($lims[1] == '2592000') {
                    echo 'selected="selected"';
                }
                ?>
><?php 
                _e('per month', 'wp-photo-album-plus');
                ?>
</option>
											<option value="31536000" <?php 
                if ($lims[1] == '31536000') {
                    echo 'selected="selected"';
                }
                ?>
><?php 
                _e('per year', 'wp-photo-album-plus');
                ?>
</option>
										</select>
										</td>
										<td>
										<span class="description"><?php 
                _e('Set the upload limit (0 means unlimited) and the upload limit period.', 'wp-photo-album-plus');
                ?>
</span>
										<?php 
            } else {
                if ($lims[0] == '0') {
                    _e('Unlimited', 'wp-photo-album-plus');
                } else {
                    echo $lims[0] . ' ';
                    switch ($lims[1]) {
                        case '3600':
                            _e('per hour', 'wp-photo-album-plus');
                            break;
                        case '86400':
                            _e('per day', 'wp-photo-album-plus');
                            break;
                        case '604800':
                            _e('per week', 'wp-photo-album-plus');
                            break;
                        case '2592000':
                            _e('per month', 'wp-photo-album-plus');
                            break;
                        case '31536000':
                            _e('per year', 'wp-photo-album-plus');
                            break;
                    }
                }
            }
            ?>
								</td>
							</tr>

							<!-- Cats -->
							<tr>
								<th>
									<label><?php 
            _e('Catogories:', 'wp-photo-album-plus');
            ?>
</label>
									<span class="description" >
										<br />&nbsp;
									</span>
								</th>
								<td>
									<input id="cats" type="text" style="width:100%;" onkeyup="wppaAjaxUpdateAlbum(<?php 
            echo $edit_id;
            ?>
, 'cats', this)" onchange="wppaAjaxUpdateAlbum(<?php 
            echo $edit_id;
            ?>
, 'cats', this)" value="<?php 
            echo stripslashes(trim($albuminfo['cats'], ','));
            ?>
" />
								</td>
								<td>
									<span class="description" >
										<?php 
            _e('Separate categories with commas.', 'wp-photo-album-plus');
            ?>
&nbsp;
										<?php 
            _e('Examples:', 'wp-photo-album-plus');
            $catlist = wppa_get_catlist();
            ?>
										<select onchange="wppaAddCat(this.value, 'cats'); wppaAjaxUpdateAlbum(<?php 
            echo $edit_id;
            ?>
, 'cats', document.getElementById('cats'))" >
											<?php 
            if (is_array($catlist)) {
                echo '<option value="" >' . __('- select -', 'wp-photo-album-plus') . '</option>';
                foreach ($catlist as $cat) {
                    echo '<option value="' . $cat['cat'] . '" >' . $cat['cat'] . '</option>';
                }
            } else {
                echo '<option value="0" >' . __('No categories yet', 'wp-photo-album-plus') . '</option>';
            }
            ?>
										</select>
										<?php 
            _e('Select to add', 'wp-photo-album-plus');
            ?>
									</span>
								</td>
							</tr>

							<!-- Default tags -->
							<tr>
								<th>
									<label><?php 
            _e('Default photo tags:', 'wp-photo-album-plus');
            ?>
</label>
								</th>
								<td>
									<input type="text" id="default_tags" value="<?php 
            echo trim($albuminfo['default_tags'], ',');
            ?>
" style="width: 100%" onkeyup="wppaAjaxUpdateAlbum(<?php 
            echo $edit_id;
            ?>
, 'default_tags', this)" onchange="wppaAjaxUpdateAlbum(<?php 
            echo $edit_id;
            ?>
, 'default_tags', this)" />
								</td>
								<td>
									<span class="description"><?php 
            _e('Enter the tags that you want to be assigned to new photos in this album.', 'wp-photo-album-plus');
            ?>
</span>
								</td>
							</tr>

							<!-- Apply default tags -->
							<?php 
            $onc1 = 'if (confirm(\'' . __('Are you sure you want to set the default tags to all photos in this album?', 'wp-photo-album-plus') . '\')) { alert(\'The page will be reloaded after the action has taken place.\');wppaRefreshAfter(); wppaAjaxUpdateAlbum(' . $edit_id . ', \'set_deftags\', 0 ); }';
            ?>
							<?php 
            $onc2 = 'if (confirm(\'' . __('Are you sure you want to add the default tags to all photos in this album?', 'wp-photo-album-plus') . '\')) { alert(\'The page will be reloaded after the action has taken place.\');wppaRefreshAfter(); wppaAjaxUpdateAlbum(' . $edit_id . ', \'add_deftags\', 0 ); }';
            ?>
							<tr>
								<th>
									<a onclick="<?php 
            echo $onc1;
            ?>
" ><?php 
            _e('Apply default tags', 'wp-photo-album-plus');
            ?>
</a>
								</th>
								<td>
								</td>
								<td>
									<span class="description"><?php 
            _e('Tag all photos in this album with the default tags.', 'wp-photo-album-plus');
            ?>
</span>
								</td>
							</tr>
							<tr>
								<th>
									<a onclick="<?php 
            echo $onc2;
            ?>
" ><?php 
            _e('Add default tags', 'wp-photo-album-plus');
            ?>
</a>
								</th>
								<td>
								</td>
								<td>
									<span class="description"><?php 
            _e('Add the default tags to all photos in this album.', 'wp-photo-album-plus');
            ?>
</span>
								</td>
							</tr>

							<!-- Link type -->
							<tr>
								<th>
									<label><?php 
            _e('Link type:', 'wp-photo-album-plus');
            ?>
</label>
								</th>
								<td>
									<?php 
            $linktype = $albuminfo['cover_linktype'];
            ?>
									<?php 
            /* if ( !$linktype ) $linktype = 'content'; /* Default */
            ?>
									<?php 
            /* if ( $albuminfo['cover_linkpage'] == '-1' ) $linktype = 'none'; /* for backward compatibility */
            ?>
									<select onchange="wppaAjaxUpdateAlbum(<?php 
            echo $edit_id;
            ?>
, 'cover_linktype', this)" >
										<option value="content" <?php 
            if ($linktype == 'content') {
                echo $sel;
            }
            ?>
><?php 
            _e('the sub-albums and thumbnails', 'wp-photo-album-plus');
            ?>
</option>
										<option value="albums" <?php 
            if ($linktype == 'albums') {
                echo $sel;
            }
            ?>
><?php 
            _e('the sub-albums', 'wp-photo-album-plus');
            ?>
</option>
										<option value="thumbs" <?php 
            if ($linktype == 'thumbs') {
                echo $sel;
            }
            ?>
><?php 
            _e('the thumbnails', 'wp-photo-album-plus');
            ?>
</option>
										<option value="slide" <?php 
            if ($linktype == 'slide') {
                echo $sel;
            }
            ?>
><?php 
            _e('the album photos as slideshow', 'wp-photo-album-plus');
            ?>
</option>
										<option value="page" <?php 
            if ($linktype == 'page') {
                echo $sel;
            }
            ?>
><?php 
            _e('the link page with a clean url', 'wp-photo-album-plus');
            ?>
</option>
										<option value="none" <?php 
            if ($linktype == 'none') {
                echo $sel;
            }
            ?>
><?php 
            _e('no link at all', 'wp-photo-album-plus');
            ?>
</option>
									</select>
								</td>
								<td>
									<span class="description">
										<?php 
            if (wppa_switch('auto_page')) {
                _e('If you select "the link page with a clean url", select an Auto Page of one of the photos in this album.', 'wp-photo-album-plus');
            } else {
                _e('If you select "the link page with a clean url", make sure you enter the correct shortcode on the target page.', 'wp-photo-album-plus');
            }
            ?>
									</span>
								</td>
							</tr>

							<!-- Link page -->
							<?php 
            if (!wppa_switch('wppa_link_is_restricted') || current_user_can('administrator')) {
                ?>
							<tr>
								<th>
									<label><?php 
                _e('Link to:', 'wp-photo-album-plus');
                ?>
</label>
								</th>
								<td style="max-width:210px;" >
									<?php 
                $query = 'SELECT `ID`, `post_title` FROM `' . $wpdb->posts . '` WHERE `post_type` = \'page\' AND `post_status` = \'publish\' ORDER BY `post_title` ASC';
                $pages = $wpdb->get_results($query, ARRAY_A);
                if (empty($pages)) {
                    _e('There are no pages (yet) to link to.', 'wp-photo-album-plus');
                } else {
                    $linkpage = $albuminfo['cover_linkpage'];
                    if (!is_numeric($linkpage)) {
                        $linkpage = '0';
                    }
                    ?>
										<select onchange="wppaAjaxUpdateAlbum(<?php 
                    echo $edit_id;
                    ?>
, 'cover_linkpage', this)" style="max-width:100%;">
											<option value="0" <?php 
                    if ($linkpage == '0') {
                        echo $sel;
                    }
                    ?>
><?php 
                    _e('--- the same page or post ---', 'wp-photo-album-plus');
                    ?>
</option>
											<?php 
                    foreach ($pages as $page) {
                        ?>
												<option value="<?php 
                        echo $page['ID'];
                        ?>
" <?php 
                        if ($linkpage == $page['ID']) {
                            echo $sel;
                        }
                        ?>
><?php 
                        _e($page['post_title'], 'wp-photo-album-plus');
                        ?>
</option>
											<?php 
                    }
                    ?>
										</select>
								</td>
								<td>
										<span class="description">
											<?php 
                    _e('If you want, you can link the title to a WP page in stead of the album\'s content. If so, select the page the title links to.', 'wp-photo-album-plus');
                    ?>
										</span>
									<?php 
                }
                ?>
								</td>
							</tr>
							<?php 
            }
            ?>

							<!-- Schedule -->
							<tr>
								<th>
									<label><?php 
            _e('Schedule:', 'wp-photo-album-plus');
            ?>
</label>
									<input type="checkbox" <?php 
            if ($albuminfo['scheduledtm']) {
                echo 'checked="checked"';
            }
            ?>
 onchange="wppaChangeScheduleAlbum(<?php 
            echo $edit_id;
            ?>
, this);" />
								</th>
								<td>
									<input type="hidden" value="" id="wppa-dummy" />
									<span class="wppa-datetime-<?php 
            echo $edit_id;
            ?>
" <?php 
            if (!$albuminfo['scheduledtm']) {
                echo 'style="display:none;"';
            }
            ?>
 >
										<?php 
            echo wppa_get_date_time_select_html('album', $edit_id, true);
            ?>
									</span>
								</td>
								<td>
									<span class="description">
										<?php 
            _e('If enabled, new photos will have their status set to the dat/time specified here.', 'wp-photo-album-plus');
            ?>
									</span>
								</td>
							</tr>
							<tr class="wppa-datetime-<?php 
            echo $edit_id;
            ?>
" >
								<th>
									<a onclick="if (confirm('<?php 
            _e('Are you sure you want to schedule all photos in this album?', 'wp-photo-album-plus');
            ?>
')) { alert('The page will be reloaded after the action has taken place.'); wppaRefreshAfter(); wppaAjaxUpdateAlbum(<?php 
            echo $edit_id;
            ?>
, 'setallscheduled', 0 ) }" ><?php 
            _e('Schedule all', 'wp-photo-album-plus');
            ?>
</a>
								</th>
							</tr>

							<!-- Reset Ratings -->
							<?php 
            if (wppa_switch('wppa_rating_on')) {
                ?>
								<tr>
									<th>
										<a onclick="if (confirm('<?php 
                _e('Are you sure you want to clear the ratings in this album?', 'wp-photo-album-plus');
                ?>
')) wppaAjaxUpdateAlbum(<?php 
                echo $edit_id;
                ?>
, 'clear_ratings', 0 )" ><?php 
                _e('Reset ratings', 'wp-photo-album-plus');
                ?>
</a>
									</th>
								</tr>
							<?php 
            }
            ?>

							<!-- Goto Upload -->
							<?php 
            if (current_user_can('wppa_upload')) {
                $a = wppa_allow_uploads($albuminfo['id']);
                if ($a) {
                    $full = 'none';
                    $notfull = '';
                } else {
                    $full = '';
                    $notfull = 'none';
                }
                $onc = 'document.location = \'' . wppa_dbg_url(get_admin_url()) . '/admin.php?page=wppa_upload_photos&wppa-set-album=' . $albuminfo['id'] . '\'';
                $oncfull = 'alert(\'' . __('Change the upload limit or remove photos to enable new uploads.', 'wp-photo-album-plus') . '\')';
                ?>
								<tr>
									<th>
										<a id="notfull" style="display:<?php 
                echo $notfull;
                ?>
" onclick="<?php 
                echo $onc;
                ?>
" ><?php 
                _e('Upload to this album', 'wp-photo-album-plus');
                if ($a > '0') {
                    echo ' ' . sprintf(__('(max %d)', 'wp-photo-album-plus'), $a);
                }
                ?>
</a>
										<a id="full" style="display:<?php 
                echo $full;
                ?>
" onclick="<?php 
                echo $oncfull;
                ?>
" ><?php 
                _e('Album is full', 'wp-photo-album-plus');
                ?>
</a>
									</th>
								</tr>
							<?php 
            }
            ?>

							<!-- Apply New photo desc -->
							<?php 
            if (wppa_switch('wppa_apply_newphoto_desc')) {
                $onc = 'if ( confirm(\'Are you sure you want to set the description of all photos to \\n\\n' . esc_js(wppa_opt('wppa_newphoto_description')) . '\')) document.location=\'' . wppa_ea_url($albuminfo['id'], 'edit') . '&applynewdesc\'';
                ?>
								<tr>
									<th>
										<a onclick="<?php 
                echo $onc;
                ?>
" ><?php 
                _e('Apply new photo desc', 'wp-photo-album-plus');
                ?>
</a>
									</th>
								</tr>
							<?php 
            }
            ?>

							<!-- Remake all -->
							<?php 
            if (current_user_can('administrator')) {
                $onc = 'if ( confirm(\'Are you sure you want to remake the files for all photos in this album?\')) document.location=\'' . wppa_ea_url($albuminfo['id'], 'edit') . '&remakealbum\'';
                ?>
								<tr>
									<th>
										<a onclick="<?php 
                echo $onc;
                ?>
" ><?php 
                _e('Remake all', 'wp-photo-album-plus');
                ?>
</a>
									</th>
								</tr>
							<?php 
            }
            ?>

							<!-- Status -->
							<tr >
								<th style="color:blue;" >
									<label style="color:#070"><?php 
            _e('Remark:', 'wp-photo-album-plus');
            ?>
</label>
								</th>
								<td id="albumstatus-<?php 
            echo $edit_id;
            ?>
" >
									<?php 
            echo sprintf(__('Album %s is not modified yet', 'wp-photo-album-plus'), $edit_id);
            ?>
								</td>
							</tr>
						</tbody>
					</table>
<a name="manage-photos" id="manage-photos" ></a>
				<h2><?php 
            _e('Manage Photos', 'wp-photo-album-plus');
            if (isset($_REQUEST['bulk'])) {
                echo ' - <small><i>' . __('Copy / move / delete / edit name / edit description / change status', 'wp-photo-album-plus') . '</i></small>';
            } elseif (isset($_REQUEST['seq'])) {
                echo ' - <small><i>' . __('Change sequence order by drag and drop', 'wp-photo-album-plus') . '</i></small>';
            } elseif (isset($_REQUEST['quick'])) {
                echo ' - <small><i>' . __('Edit photo information except copy and move', 'wp-photo-album-plus') . '</i></small>';
            } else {
                echo ' - <small><i>' . __('Edit photo information', 'wp-photo-album-plus') . '</i></small>';
            }
            ?>
</h2>
				<?php 
            if (isset($_REQUEST['bulk'])) {
                wppa_album_photos_bulk($edit_id);
            } elseif (isset($_REQUEST['seq'])) {
                wppa_album_photos_sequence($edit_id);
            } else {
                wppa_album_photos($edit_id);
            }
            ?>
				<br /><a href="#manage-photos"><?php 
            _e('Top of page', 'wp-photo-album-plus');
            ?>
</a>
			</div>
<?php 
        } else {
            if ($_REQUEST['tab'] == 'cmod') {
                $photo = $_REQUEST['photo'];
                $alb = wppa_get_album_id_by_photo_id($photo);
                if (current_user_can('wppa_comments') && wppa_have_access($alb)) {
                    ?>
				<div class="wrap">
					<h2><?php 
                    _e('Moderate comment', 'wp-photo-album-plus');
                    ?>
</h2>
				<?php 
                    //	<input type="hidden" id="album-nonce-<?php echo $edit_id
                    //" value="<?php echo wp_create_nonce('wppa_nonce_'.$edit_id);
                    //" />
                    ?>
					<?php 
                    wppa_album_photos('', $photo);
                    ?>
				</div>
<?php 
                } else {
                    wp_die('You do not have the rights to do this');
                }
            } elseif ($_REQUEST['tab'] == 'pmod' || $_REQUEST['tab'] == 'pedit') {
                $photo = $_REQUEST['photo'];
                $alb = wppa_get_album_id_by_photo_id($photo);
                if (current_user_can('wppa_admin') && wppa_have_access($alb)) {
                    ?>
				<div class="wrap">
					<h2><?php 
                    if ($_REQUEST['tab'] == 'pmod') {
                        _e('Moderate photo', 'wp-photo-album-plus');
                    } else {
                        _e('Edit photo', 'wp-photo-album-plus');
                    }
                    ?>
					</h2>
					<?php 
                    wppa_album_photos('', $photo);
                    ?>
				</div>
<?php 
                } else {
                    wp_die('You do not have the rights to do this');
                }
            } else {
                if ($_REQUEST['tab'] == 'del') {
                    $album_owner = $wpdb->get_var($wpdb->prepare("SELECT `owner` FROM " . WPPA_ALBUMS . " WHERE `id` = %s", $_REQUEST['edit_id']));
                    if ($album_owner == '--- public ---' && !current_user_can('administrator') || !wppa_have_access($_REQUEST['edit_id'])) {
                        wp_die('You do not have the rights to delete this album');
                    }
                    ?>
			<div class="wrap">
				<?php 
                    $iconurl = WPPA_URL . '/images/albumdel32.png';
                    ?>
				<div id="icon-albumdel" class="icon32" style="background: transparent url(<?php 
                    echo $iconurl;
                    ?>
) no-repeat">
					<br />
				</div>

				<h2><?php 
                    _e('Delete Album', 'wp-photo-album-plus');
                    ?>
</h2>

				<p><?php 
                    _e('Album:', 'wp-photo-album-plus');
                    ?>
 <b><?php 
                    echo wppa_get_album_name($_REQUEST['edit_id']);
                    ?>
.</b></p>
				<p><?php 
                    _e('Are you sure you want to delete this album?', 'wp-photo-album-plus');
                    ?>
<br />
					<?php 
                    _e('Press Delete to continue, and Cancel to go back.', 'wp-photo-album-plus');
                    ?>
				</p>
				<form name="wppa-del-form" action="<?php 
                    echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_admin_menu');
                    ?>
" method="post">
					<?php 
                    wp_nonce_field('$wppa_nonce', WPPA_NONCE);
                    ?>
					<p>
						<?php 
                    _e('What would you like to do with photos currently in the album?', 'wp-photo-album-plus');
                    ?>
<br />
						<input type="radio" name="wppa-del-photos" value="delete" checked="checked" /> <?php 
                    _e('Delete', 'wp-photo-album-plus');
                    ?>
<br />
						<input type="radio" name="wppa-del-photos" value="move" /> <?php 
                    _e('Move to:', 'wp-photo-album-plus');
                    ?>
						<select name="wppa-move-album">
							<?php 
                    echo wppa_album_select_a(array('checkaccess' => true, 'path' => wppa_switch('wppa_hier_albsel'), 'selected' => '0', 'exclude' => $_REQUEST['edit_id'], 'addpleaseselect' => true));
                    ?>
						</select>
					</p>

					<input type="hidden" name="wppa-del-id" value="<?php 
                    echo $_REQUEST['edit_id'];
                    ?>
" />
					<input type="button" class="button-primary" value="<?php 
                    _e('Cancel', 'wp-photo-album-plus');
                    ?>
" onclick="parent.history.back()" />
					<input type="submit" class="button-primary" style="color: red" name="wppa-del-confirm" value="<?php 
                    _e('Delete', 'wp-photo-album-plus');
                    ?>
" />
				</form>
			</div>
<?php 
                }
            }
        }
    } else {
        //  'tab' not set. default, album manage page.
        // if add form has been submitted
        //		if (isset($_POST['wppa-na-submit'])) {
        //			check_admin_referer( '$wppa_nonce', WPPA_NONCE );
        //			wppa_add_album();
        //		}
        // if album deleted
        if (isset($_POST['wppa-del-confirm'])) {
            check_admin_referer('$wppa_nonce', WPPA_NONCE);
            $album_owner = $wpdb->get_var($wpdb->prepare("SELECT `owner` FROM " . WPPA_ALBUMS . " WHERE `id` = %s", $_POST['wppa-del-id']));
            if ($album_owner == '--- public ---' && !current_user_can('administrator') || !wppa_have_access($_POST['wppa-del-id'])) {
                wp_die('You do not have the rights to delete this album');
            }
            if ($_POST['wppa-del-photos'] == 'move') {
                $move = $_POST['wppa-move-album'];
                if (wppa_have_access($move)) {
                    wppa_del_album($_POST['wppa-del-id'], $move);
                } else {
                    wppa_error_message(__('Unable to move photos. Album not deleted.', 'wp-photo-album-plus'));
                }
            } else {
                wppa_del_album($_POST['wppa-del-id'], '');
            }
        }
        if (wppa_extended_access()) {
            if (isset($_REQUEST['switchto'])) {
                update_option('wppa_album_table_' . wppa_get_user(), $_REQUEST['switchto']);
            }
            $style = get_option('wppa_album_table_' . wppa_get_user(), 'flat');
        } else {
            $style = 'flat';
        }
        // The Manage Album page
        ?>
		<div class="wrap">
		<?php 
        wppa_admin_spinner();
        ?>
			<?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('Manage Albums', 'wp-photo-album-plus');
        ?>
</h2>
			<br />
			<?php 
        // The Create new album button
        if (wppa_can_create_top_album()) {
            $url = wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_admin_menu&amp;tab=edit&amp;edit_id=new');
            $vfy = __('Are you sure you want to create a new album?', 'wp-photo-album-plus');
            echo '<form method="post" action="' . get_admin_url() . 'admin.php?page=wppa_admin_menu" style="float:left; margin-right:12px;" >';
            echo '<input type="hidden" name="tab" value="edit" />';
            echo '<input type="hidden" name="edit_id" value="new" />';
            $onc = wppa_switch('confirm_create') ? 'onclick="return confirm(\'' . $vfy . '\');"' : '';
            echo '<input type="submit" class="button-primary" ' . $onc . ' value="' . __('Create New Empty Album', 'wp-photo-album-plus') . '" style="height:28px;" />';
            echo '</form>';
        }
        // The switch to button(s)
        if (wppa_extended_access()) {
            if ($style == 'flat') {
                ?>
					<input type="button" class="button-secundary" onclick="document.location='<?php 
                echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_admin_menu&amp;switchto=collapsable');
                ?>
'" value="<?php 
                _e('Switch to Collapsable table', 'wp-photo-album-plus');
                ?>
" />
				<?php 
            }
            if ($style == 'collapsable') {
                ?>
					<input type="button" class="button-secundary" onclick="document.location='<?php 
                echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_admin_menu&amp;switchto=flat');
                ?>
'" value="<?php 
                _e('Switch to Flat table', 'wp-photo-album-plus');
                ?>
" />
				<?php 
            }
        }
        ?>

			<br />
			<?php 
        // The table of existing albums
        if ($style == 'flat') {
            wppa_admin_albums_flat();
        } else {
            wppa_admin_albums_collapsable();
        }
        ?>
			<br />
		</div>
<?php 
    }
}
function _wppa_admin()
{
    global $wpdb;
    global $q_config;
    global $wppa_revno;
    if (get_option('wppa_revision') != $wppa_revno) {
        wppa_check_database(true);
    }
    echo '
<script type="text/javascript">
	/* <![CDATA[ */
	wppaAjaxUrl = "' . admin_url('admin-ajax.php') . '";
	wppaUploadToThisAlbum = "' . __('Upload to this album', 'wp-photo-album-plus') . '";
	wppaImageDirectory = "' . wppa_get_imgdir() . '";
	/* ]]> */
</script>
';
    // Delete trashed comments
    $query = "DELETE FROM " . WPPA_COMMENTS . " WHERE status='trash'";
    $wpdb->query($query);
    $sel = 'selected="selected"';
    // warn if the uploads directory is no writable
    if (!is_writable(WPPA_UPLOAD_PATH)) {
        wppa_error_message(__('Warning:', 'wp-photo-album-plus') . sprintf(__('The uploads directory does not exist or is not writable by the server. Please make sure that %s is writeable by the server.', 'wp-photo-album-plus'), WPPA_UPLOAD_PATH));
    }
    // Fix orphan albums and deleted target pages
    $albs = $wpdb->get_results("SELECT * FROM `" . WPPA_ALBUMS . "`", ARRAY_A);
    // Now we have tham, put them in cache
    wppa_cache_album('add', $albs);
    if ($albs) {
        foreach ($albs as $alb) {
            if ($alb['a_parent'] > '0' && wppa_get_parentalbumid($alb['a_parent']) == '-9') {
                // Parent died?
                $wpdb->query("UPDATE `" . WPPA_ALBUMS . "` SET `a_parent` = '-1' WHERE `id` = '" . $alb['id'] . "'");
            }
            if ($alb['cover_linkpage'] > '0') {
                $iret = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . $wpdb->posts . "` WHERE `ID` = %s AND `post_type` = 'page' AND `post_status` = 'publish'", $alb['cover_linkpage']));
                if (!$iret) {
                    // Page gone?
                    $wpdb->query("UPDATE `" . WPPA_ALBUMS . "` SET `cover_linkpage` = '0' WHERE `id` = '" . $alb['id'] . "'");
                }
            }
        }
    }
    if (isset($_REQUEST['tab'])) {
        // album edit page
        if ($_REQUEST['tab'] == 'edit') {
            if (isset($_REQUEST['edit_id'])) {
                $ei = $_REQUEST['edit_id'];
                if ($ei != 'new' && $ei != 'search' && !is_numeric($ei)) {
                    wp_die('Security check failure 1');
                }
            }
            if ($_REQUEST['edit_id'] == 'search') {
                $back_url = get_admin_url() . 'admin.php?page=wppa_admin_menu';
                if (isset($_REQUEST['wppa-searchstring'])) {
                    $back_url .= '&wppa-searchstring=' . wppa_sanitize_searchstring($_REQUEST['wppa-searchstring']);
                }
                $back_url .= '#wppa-edit-search-tag';
                ?>
<a name="manage-photos" id="manage-photos" ></a>
				<h2><?php 
                _e('Manage Photos', 'wp-photo-album-plus');
                if (isset($_REQUEST['bulk'])) {
                    echo ' - <small><i>' . __('Copy / move / delete / edit name / edit description / change status', 'wp-photo-album-plus') . '</i></small>';
                } elseif (isset($_REQUEST['quick'])) {
                    echo ' - <small><i>' . __('Edit photo information except copy and move', 'wp-photo-album-plus') . '</i></small>';
                } else {
                    echo ' - <small><i>' . __('Edit photo information', 'wp-photo-album-plus') . '</i></small>';
                }
                ?>
</h2>

<a href="<?php 
                echo $back_url;
                ?>
"><?php 
                _e('Back to album table', 'wp-photo-album-plus');
                ?>
</a><br /><br />

				<?php 
                if (isset($_REQUEST['bulk'])) {
                    wppa_album_photos_bulk($ei);
                } else {
                    wppa_album_photos($ei);
                }
                ?>
				<br /><a href="#manage-photos"><?php 
                _e('Top of page', 'wp-photo-album-plus');
                ?>
</a>
				<br /><a href="<?php 
                echo $back_url;
                ?>
"><?php 
                _e('Back to album table', 'wp-photo-album-plus');
                ?>
</a>
<?php 
                return;
            }
            if ($_REQUEST['edit_id'] == 'new') {
                if (!wppa_can_create_album()) {
                    wp_die('No rights to create an album');
                }
                $id = wppa_nextkey(WPPA_ALBUMS);
                if (isset($_REQUEST['parent_id'])) {
                    $parent = $_REQUEST['parent_id'];
                    if (!is_numeric($parent)) {
                        wp_die('Security check failure 2');
                    }
                    $name = wppa_get_album_name($parent) . '-#' . $id;
                    if (!current_user_can('administrator')) {
                        // someone creating an album for someone else?
                        $parentowner = $wpdb->get_var($wpdb->prepare("SELECT `owner` FROM `" . WPPA_ALBUMS . "` WHERE `id` = %s", $parent));
                        if ($parentowner !== wppa_get_user()) {
                            wp_die('You are not allowed to create an album for someone else');
                        }
                    }
                } else {
                    $parent = wppa_opt('default_parent');
                    if (!$wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_ALBUMS . "` WHERE `id` = %s", $parent))) {
                        // Deafault parent vanished
                        wppa_update_option('wppa_default_parent', '0');
                        $parent = '0';
                    }
                    $name = __('New Album', 'wp-photo-album-plus');
                    if (!wppa_can_create_top_album()) {
                        wp_die('No rights to create a top-level album');
                    }
                }
                $id = wppa_create_album_entry(array('id' => $id, 'name' => $name, 'a_parent' => $parent));
                if (!$id) {
                    wppa_error_message(__('Could not create album.', 'wp-photo-album-plus'));
                    wp_die('Sorry, cannot continue');
                } else {
                    $edit_id = $id;
                    wppa_set_last_album($edit_id);
                    wppa_flush_treecounts($edit_id);
                    wppa_index_add('album', $id);
                    wppa_update_message(__('Album #', 'wp-photo-album-plus') . ' ' . $edit_id . ' ' . __('Added.', 'wp-photo-album-plus'));
                    wppa_create_pl_htaccess();
                }
            } else {
                $edit_id = $_REQUEST['edit_id'];
            }
            $album_owner = $wpdb->get_var($wpdb->prepare("SELECT `owner` FROM " . WPPA_ALBUMS . " WHERE `id` = %s", $edit_id));
            if ($album_owner == '--- public ---' && !current_user_can('wppa_admin') || !wppa_have_access($edit_id)) {
                wp_die('You do not have the rights to edit this album');
            }
            // Apply new desc
            if (isset($_REQUEST['applynewdesc'])) {
                if (!wp_verify_nonce($_REQUEST['wppa_nonce'], 'wppa_nonce')) {
                    wp_die('You do not have the rights to do this');
                }
                $iret = $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_PHOTOS . "` SET `description` = %s WHERE `album` = %s", wppa_opt('newphoto_description'), $edit_id));
                wppa_ok_message($iret . ' descriptions updated.');
            }
            // Remake album
            if (isset($_REQUEST['remakealbum'])) {
                if (!wp_verify_nonce($_REQUEST['wppa_nonce'], 'wppa_nonce')) {
                    wp_die('You do not have the rights to do this');
                }
                if (get_option('wppa_remake_start_album_' . $edit_id)) {
                    // Continue after time up
                    wppa_ok_message('Continuing remake, please wait');
                } else {
                    update_option('wppa_remake_start_album_' . $edit_id, time());
                    wppa_ok_message('Remaking photofiles, please wait');
                }
                $iret = wppa_remake_files($edit_id);
                if ($iret) {
                    wppa_ok_message('Photo files remade');
                    update_option('wppa_remake_start_album_' . $edit_id, '0');
                } else {
                    wppa_error_message('Remake of photo files did NOT complete');
                }
            }
            // Get the album information
            $albuminfo = $wpdb->get_row($wpdb->prepare('SELECT * FROM `' . WPPA_ALBUMS . '` WHERE `id` = %s', $edit_id), ARRAY_A);
            // We may not use extract(), so we do something like it here manually, hence controlled.
            $id = $albuminfo['id'];
            $crypt = $albuminfo['crypt'];
            $timestamp = $albuminfo['timestamp'];
            $modified = $albuminfo['modified'];
            $views = $albuminfo['views'];
            $owner = $albuminfo['owner'];
            $a_order = $albuminfo['a_order'];
            $p_order_by = $albuminfo['p_order_by'];
            $a_parent = $albuminfo['a_parent'];
            $suba_order_by = $albuminfo['suba_order_by'];
            $name = stripslashes($albuminfo['name']);
            $description = stripslashes($albuminfo['description']);
            $alt_thumbsize = $albuminfo['alt_thumbsize'];
            $cover_type = $albuminfo['cover_type'];
            $main_photo = $albuminfo['main_photo'];
            $upload_limit = $albuminfo['upload_limit'];
            $cats = stripslashes(trim($albuminfo['cats'], ','));
            $default_tags = trim($albuminfo['default_tags'], ',');
            $cover_linktype = $albuminfo['cover_linktype'];
            // Open the photo album admin page
            echo '<div class="wrap">';
            // The spinner to indicate busyness
            wppa_admin_spinner();
            // Local js functions placed here as long as there is not yet a possibility to translate texts in js files
            ?>
<script>
function wppaTryInheritCats( id ) {

	var query;

	query = '<?php 
            echo esc_js(__('Are you sure you want to inherit categories to all (grand)children of this album?', 'wp-photo-album-plus'));
            ?>
';

	if ( confirm( query ) ) {
		wppaAjaxUpdateAlbum( id, 'inherit_cats', Math.random() );
	}
}

function wppaTryAddCats( id ) {

	var query;

	query = '<?php 
            echo esc_js(__('Are you sure you want to add the categories to all (grand)children of this album?', 'wp-photo-album-plus'));
            ?>
';

	if ( confirm( query ) ) {
		wppaAjaxUpdateAlbum( id, 'inhadd_cats', Math.random() );
	}
}

function wppaTryApplyDeftags( id ) {

	var query;

	query = '<?php 
            echo esc_js(__('Are you sure you want to set the default tags to all photos in this album?', 'wp-photo-album-plus'));
            ?>
';

	if ( confirm( query ) ) {
		wppaAjaxUpdateAlbum( id, 'set_deftags', Math.random(), true );
	}
}

function wppaTryAddDeftags( id ) {

	var query;

	query = '<?php 
            echo esc_js(__('Are you sure you want to add the default tags to all photos in this album?', 'wp-photo-album-plus'));
            ?>
';

	if ( confirm( query ) ) {
		wppaAjaxUpdateAlbum( id, 'add_deftags', Math.random(), true );
	}
}

function wppaTryScheduleAll( id ) {

	var query;

	if ( jQuery( '#schedule-box' ).attr( 'checked' ) != 'checked' ) {
		query = '<?php 
            echo esc_js(__('Please switch feature on and set dat/time to schedule first', 'wp-photo-album-plus'));
            ?>
';
		alert( query );
		return;
	}

	query = '<?php 
            echo esc_js(__('Are you sure you want to schedule all photos in this album?', 'wp-photo-album-plus'));
            ?>
';

	if ( confirm( query ) ) {
		wppaAjaxUpdateAlbum( id, 'setallscheduled', Math.random(), true );
	}
}

</script>
		<?php 
            // The header
            echo '<img src="' . WPPA_URL . '/img/album32.png' . '" alt="Album icon" />' . '<h1 style="display:inline;" >' . __('Edit Album Information', 'wp-photo-album-plus') . '</h1>' . '<p class="description">' . __('All modifications are instantly updated on the server, except for those that require a button push.', 'wp-photo-album-plus') . ' ' . __('The <b style="color:#070" >Remark</b> fields keep you informed on the actions taken at the background.', 'wp-photo-album-plus') . '</p>' . '<input' . ' type="hidden"' . ' id="album-nonce-' . $id . '"' . ' value="' . wp_create_nonce('wppa_nonce_' . $id) . '"' . ' />';
            // The edit albuminfo panel
            echo '<div' . ' id="albumitem-' . $id . '"' . ' class="wppa-table-wrap"' . ' style="width:100%;position:relative;"' . ' >';
            // Section 1
            echo "\n" . '<!-- Album Section 1 -->' . '<table' . ' class="wppa-table wppa-album-table"' . ' >' . '<tbody>' . '<tr>' . '<td>';
            // More or less static data
            // Album number
            echo __('Album number:', 'wp-photo-album-plus') . ' ' . $id . '. ';
            // Crypt
            echo __('Crypt:', 'wp-photo-album-plus') . ' ' . $crypt . '. ';
            // Created
            echo __('Created:', 'wp-photo-album-plus') . ' ' . wppa_local_date('', $timestamp) . ' ' . __('local time', 'wp-photo-album-plus') . '. ';
            // Modified
            echo __('Modified:', 'wp-photo-album-plus') . ' ';
            if ($modified > $timestamp) {
                echo wppa_local_date('', $modified) . ' ' . __('local time', 'wp-photo-album-plus') . '. ';
            } else {
                echo __('Not modified', 'wp-photo-album-plus') . '. ';
            }
            // Views
            if (wppa_switch('track_viewcounts')) {
                echo __('Views:', 'wp-photo-album-plus') . ' ' . $views . '. ';
            }
            // Clicks
            if (wppa_switch('track_clickcounts')) {
                $click_arr = $wpdb->get_col("SELECT `clicks` FROM `" . WPPA_PHOTOS . "` WHERE `album` = {$id}");
                echo __('Clicks:', 'wp-photo-album-plus') . ' ' . array_sum($click_arr) . '. ';
            }
            // Owner
            echo __('Owned by:', 'wp-photo-album-plus') . ' ';
            if (!wppa_user_is('administrator')) {
                if ($owner == '--- public ---') {
                    echo __('--- public ---', 'wp-photo-album-plus') . ' ';
                } else {
                    echo $owner . '. ';
                }
            } else {
                $usercount = wppa_get_user_count();
                if ($usercount > wppa_opt('max_users')) {
                    echo '<input' . ' type="text"' . ' value="' . esc_attr($owner) . '"' . ' onchange="wppaAjaxUpdateAlbum( ' . $id . ', \'owner\', this )"' . ' />';
                } else {
                    echo '<select' . ' onchange="wppaAjaxUpdateAlbum( ' . $id . ', \'owner\', this )"' . ' >';
                    wppa_user_select($owner);
                    echo '</select>' . ' ';
                }
            }
            // Order # -->
            echo __('Album sort order #:', 'wp-photo-album-plus') . ' ' . '<input' . ' type="text"' . ' onkeyup="wppaAjaxUpdateAlbum( ' . $id . ', \'a_order\', this )"' . ' onchange="wppaAjaxUpdateAlbum( ' . $id . ', \'a_order\', this )"' . ' value="' . esc_attr($a_order) . '"' . ' style="width:50px;' . '" />' . ' ';
            if (wppa_opt('list_albums_by') != '1' && $a_order != '0') {
                echo '<small class="description" style="color:red" >' . __('Album order # has only effect if you set the album sort order method to <b>Order #</b> in the Photo Albums -> Settings screen.<br />', 'wp-photo-album-plus') . '</small>' . ' ';
            }
            // Parent
            echo __('Parent album:', 'wp-photo-album-plus') . ' ';
            if (wppa_extended_access()) {
                echo '<select' . ' id="wppa-parsel"' . ' style="max-width:100%;"' . ' onchange="wppaAjaxUpdateAlbum( ' . $id . ', \'a_parent\', this )"' . ' >' . wppa_album_select_a(array('checkaccess' => true, 'exclude' => $id, 'selected' => $a_parent, 'addselected' => true, 'addnone' => true, 'addseparate' => true, 'disableancestors' => true, 'path' => wppa_switch('hier_albsel'))) . '</select>';
            } else {
                echo '<select' . ' id="wppa-parsel"' . ' style="max-width:100%;"' . ' onchange="wppaAjaxUpdateAlbum( ' . $id . ', \'a_parent\', this )"' . ' >' . wppa_album_select_a(array('checkaccess' => true, 'exclude' => $id, 'selected' => $a_parent, 'addselected' => true, 'disableancestors' => true, 'path' => wppa_switch('hier_albsel'))) . '</select>';
            }
            echo ' ';
            // P-order-by
            echo __('Photo order:', 'wp-photo-album-plus') . ' ';
            $options = array(__('--- default --- See Table IV-C1', 'wp-photo-album-plus'), __('Order #', 'wp-photo-album-plus'), __('Name', 'wp-photo-album-plus'), __('Random', 'wp-photo-album-plus'), __('Rating mean value', 'wp-photo-album-plus'), __('Number of votes', 'wp-photo-album-plus'), __('Timestamp', 'wp-photo-album-plus'), __('EXIF Date', 'wp-photo-album-plus'), __('Order # desc', 'wp-photo-album-plus'), __('Name desc', 'wp-photo-album-plus'), __('Rating mean value desc', 'wp-photo-album-plus'), __('Number of votes desc', 'wp-photo-album-plus'), __('Timestamp desc', 'wp-photo-album-plus'), __('EXIF Date desc', 'wp-photo-album-plus'));
            $values = array('0', '1', '2', '3', '4', '6', '5', '7', '-1', '-2', '-4', '-6', '-5', '-7');
            echo '<select' . ' onchange="wppaAjaxUpdateAlbum( ' . $id . ', \'p_order_by\', this )"' . ' >';
            foreach (array_keys($options) as $key) {
                $sel = $values[$key] == $p_order_by ? ' selected="selected"' : '';
                echo '<option value="' . $values[$key] . '"' . $sel . ' >' . $options[$key] . '</option>';
            }
            echo '</select>' . ' ';
            // Child album order
            echo __('Sub album sort order:', 'wp-photo-album-plus') . ' ' . '<select' . ' onchange="wppaAjaxUpdateAlbum( ' . $id . ', \'suba_order_by\', this )"' . ' >' . '<option value="0"' . ($suba_order_by == '0' ? 'selected="selected"' : '') . ' >' . __('--- default --- See Table IV-D1', 'wp-photo-album-plus') . '</option>' . '<option value="3"' . ($suba_order_by == '3' ? 'selected="selected"' : '') . ' >' . __('Random', 'wp-photo-album-plus') . '</option>' . '<option value="1"' . ($suba_order_by == '1' ? 'selected="selected"' : '') . ' >' . __('Order #', 'wp-photo-album-plus') . '</option>' . '<option value="-1"' . ($suba_order_by == '-1' ? 'selected="selected"' : '') . ' >' . __('Order # reverse', 'wp-photo-album-plus') . '</option>' . '<option value="2"' . ($suba_order_by == '2' ? 'selected="selected"' : '') . ' >' . __('Name', 'wp-photo-album-plus') . '</option>' . '<option value="-2"' . ($suba_order_by == '-2' ? 'selected="selected"' : '') . ' >' . __('Name reverse', 'wp-photo-album-plus') . '</option>' . '<option value="5"' . ($suba_order_by == '5' ? 'selected="selected"' : '') . ' >' . __('Timestamp', 'wp-photo-album-plus') . '</option>' . '<option value="-5"' . ($suba_order_by == '-5' ? 'selected="selected"' : '') . ' >' . __('Timestamp reverse', 'wp-photo-album-plus') . '</option>' . '</select>' . ' ';
            // Alternative thumbnail size
            if (!wppa_switch('alt_is_restricted') || current_user_can('administrator')) {
                echo __('Use alt thumbsize:', 'wp-photo-album-plus') . '<select' . ' onchange="wppaAjaxUpdateAlbum( ' . $id . ', \'alt_thumbsize\', this )"' . ' >' . '<option value="0"' . ($alt_thumbsize ? '' : ' selected="selected"') . ' >' . __('no', 'wp-photo-album-plus') . '</option>' . '<option value="yes"' . ($alt_thumbsize ? ' selected="selected"' : '') . ' >' . __('yes', 'wp-photo-album-plus') . '</option>' . '</select>' . ' ';
            }
            // Cover type
            if (!wppa_switch('covertype_is_restricted') || wppa_user_is('administrator')) {
                echo __('Cover Type:', 'wp-photo-album-plus') . ' ';
                $sel = ' selected="selected"';
                echo '<select' . ' onchange="wppaAjaxUpdateAlbum( ' . $id . ', \'cover_type\', this )"' . ' >' . '<option value=""' . ($cover_type == '' ? $sel : '') . ' >' . __('--- default --- See Table IV-D6', 'wp-photo-album-plus') . '</option>' . '<option value="default"' . ($cover_type == 'default' ? $sel : '') . ' >' . __('Standard', 'wp-photo-album-plus') . '</option>' . '<option value="longdesc"' . ($cover_type == 'longdesc' ? $sel : '') . ' >' . __('Long Descriptions', 'wp-photo-album-plus') . '</option>' . '<option value="imagefactory"' . ($cover_type == 'imagefactory' ? $sel : '') . ' >' . __('Image Factory', 'wp-photo-album-plus') . '</option>' . '<option value="default-mcr"' . ($cover_type == 'default-mcr' ? $sel : '') . ' >' . __('Standard mcr', 'wp-photo-album-plus') . '</option>' . '<option value="longdesc-mcr"' . ($cover_type == 'longdesc-mcr' ? $sel : '') . ' >' . __('Long Descriptions mcr', 'wp-photo-album-plus') . '</option>' . '<option value="imagefactory-mcr"' . ($cover_type == 'imagefactory-mcr' ? $sel : '') . ' >' . __('Image Factory mcr', 'wp-photo-album-plus') . '</option>' . '</select>' . ' ';
            }
            // Cover photo
            echo __('Cover Photo:', 'wp-photo-album-plus') . ' ' . wppa_main_photo($main_photo, $cover_type) . ' ';
            // Upload limit
            echo __('Upload limit:', 'wp-photo-album-plus') . ' ';
            $lims = explode('/', $upload_limit);
            if (!is_array($lims)) {
                $lims = array('0', '0');
            }
            if (wppa_user_is('administrator')) {
                echo '<input' . ' type="text"' . ' id="upload_limit_count"' . ' value="' . $lims[0] . '"' . ' style="width:50px"' . ' title="' . esc_attr(__('Set the upload limit (0 means unlimited).', 'wp-photo-album-plus')) . '"' . ' onchange="wppaRefreshAfter(); wppaAjaxUpdateAlbum( ' . $id . ', \'upload_limit_count\', this )"' . ' />';
                $sel = ' selected="selected"';
                echo '<select onchange="wppaRefreshAfter(); wppaAjaxUpdateAlbum( ' . $id . ', \'upload_limit_time\', this )" >' . '<option value="0"' . ($lims[1] == '0' ? $sel : '') . ' >' . __('for ever', 'wp-photo-album-plus') . '</option>' . '<option value="3600"' . ($lims[1] == '3600' ? $sel : '') . ' >' . __('per hour', 'wp-photo-album-plus') . '</option>' . '<option value="86400"' . ($lims[1] == '86400' ? $sel : '') . ' >' . __('per day', 'wp-photo-album-plus') . '</option>' . '<option value="604800"' . ($lims[1] == '604800' ? $sel : '') . ' >' . __('per week', 'wp-photo-album-plus') . '</option>' . '<option value="2592000"' . ($lims[1] == '2592000' ? $sel : '') . ' >' . __('per month', 'wp-photo-album-plus') . '</option>' . '<option value="31536000"' . ($lims[1] == '31536000' ? $sel : '') . ' >' . __('per year', 'wp-photo-album-plus') . '</option>' . '</select>' . ' ';
            } else {
                if ($lims[0] == '0') {
                    _e('Unlimited', 'wp-photo-album-plus');
                } else {
                    echo $lims[0] . ' ';
                    switch ($lims[1]) {
                        case '3600':
                            _e('per hour', 'wp-photo-album-plus');
                            break;
                        case '86400':
                            _e('per day', 'wp-photo-album-plus');
                            break;
                        case '604800':
                            _e('per week', 'wp-photo-album-plus');
                            break;
                        case '2592000':
                            _e('per month', 'wp-photo-album-plus');
                            break;
                        case '31536000':
                            _e('per year', 'wp-photo-album-plus');
                            break;
                    }
                }
                echo '. ';
            }
            // Status
            echo __('Remark:', 'wp-photo-album-plus') . ' ' . '<span' . ' id="albumstatus-' . $id . '"' . ' style="font-weight:bold;color:#00AA00;"' . ' >' . sprintf(__('Album %s is not modified yet', 'wp-photo-album-plus'), $id) . '</span>';
            echo '</td>' . '</tr>' . '</tbody>' . '</table>';
            // Section 2
            echo "\n" . '<!-- Album Section 2 -->' . '<table' . ' class="wppa-table wppa-album-table"' . ' >' . '<tbody>';
            // Name
            echo '<tr>' . '<td>' . __('Name:', 'wp-photo-album-plus') . '</td>' . '<td>' . '<input' . ' type="text"' . ' style="width:100%;"' . ' onkeyup="wppaAjaxUpdateAlbum( ' . $id . ', \'name\', this )"' . ' onchange="wppaAjaxUpdateAlbum( ' . $id . ', \'name\', this )"' . ' value="' . esc_attr($name) . '"' . ' />' . '<span class="description" >' . __('Type the name of the album. Do not leave this empty.', 'wp-photo-album-plus') . '</span>' . '</td>' . '<td>' . '</td>' . '</tr>';
            // Description
            echo '<tr>' . '<td>' . __('Description:', 'wp-photo-album-plus') . '</td>';
            if (wppa_switch('use_wp_editor')) {
                echo '<td>';
                wp_editor($description, 'wppaalbumdesc', array('wpautop' => true, 'media_buttons' => false, 'textarea_rows' => '6', 'tinymce' => true));
                echo '<input' . ' type="button"' . ' class="button-secundary"' . ' value="' . esc_attr(__('Update Album description', 'wp-photo-album-plus')) . '"' . ' onclick="wppaAjaxUpdateAlbum( ' . $id . ', \'description\', document.getElementById( \'wppaalbumdesc\' ) )"' . ' />' . '<img' . ' id="wppa-album-spin"' . ' src="' . wppa_get_imgdir() . 'spinner.gif' . '"' . ' alt="Spin"' . ' style="visibility:hidden"' . ' />' . '</td>';
            } else {
                echo '<td>' . '<textarea' . ' style="width:100%;height:60px;"' . ' onkeyup="wppaAjaxUpdateAlbum( ' . $id . ', \'description\', this )"' . ' onchange="wppaAjaxUpdateAlbum( ' . $id . ', \'description\', this )"' . ' >' . $description . '</textarea>' . '</td>';
            }
            echo '<td>' . '</td>' . '</tr>';
            // Categories
            echo '<tr>' . '<td>' . __('Catogories:', 'wp-photo-album-plus') . '</td>' . '<td>' . '<input' . ' id="cats"' . ' type="text"' . ' style="width:100%;"' . ' onkeyup="wppaAjaxUpdateAlbum( ' . $id . ', \'cats\', this )"' . ' onchange="wppaAjaxUpdateAlbum( ' . $id . ', \'cats\', this )"' . ' value="' . esc_attr($cats) . '"' . ' />' . '<br />' . '<span class="description" >' . __('Separate categories with commas.', 'wp-photo-album-plus') . '</span>' . '</td>' . '<td>' . '<select' . ' onchange="wppaAddCat( this.value, \'cats\' ); wppaAjaxUpdateAlbum( ' . $id . ', \'cats\', document.getElementById( \'cats\' ) )"' . ' >';
            $catlist = wppa_get_catlist();
            if (is_array($catlist)) {
                echo '<option value="" >' . __('- select to add -', 'wp-photo-album-plus') . '</option>';
                foreach ($catlist as $cat) {
                    echo '<option value="' . $cat['cat'] . '" >' . $cat['cat'] . '</option>';
                }
            } else {
                echo '<option value="0" >' . __('No categories yet', 'wp-photo-album-plus') . '</option>';
            }
            echo '</select>' . '</td>' . '</tr>';
            // Default tags
            echo '<tr>' . '<td>' . __('Default photo tags:', 'wp-photo-album-plus') . '</td>' . '<td>' . '<input' . ' type="text"' . ' id="default_tags"' . ' value="' . esc_attr($default_tags) . '"' . ' style="width:100%"' . ' onkeyup="wppaAjaxUpdateAlbum( ' . $id . ', \'default_tags\', this )"' . ' onchange="wppaAjaxUpdateAlbum( ' . $id . ', \'default_tags\', this )"' . ' />' . '<br />' . '<span class="description">' . __('Enter the tags that you want to be assigned to new photos in this album.', 'wp-photo-album-plus') . '</span>' . '</td>' . '<td>' . '</td>' . '</tr>';
            // Custom
            if (wppa_switch('album_custom_fields')) {
                $custom = wppa_get_album_item($edit_id, 'custom');
                if ($custom) {
                    $custom_data = unserialize($custom);
                } else {
                    $custom_data = array('', '', '', '', '', '', '', '', '', '');
                }
                foreach (array_keys($custom_data) as $key) {
                    if (wppa_opt('album_custom_caption_' . $key)) {
                        echo '<tr>' . '<td>' . apply_filters('translate_text', wppa_opt('album_custom_caption_' . $key)) . '<small style="float:right" >' . '(w#cc' . $key . ')' . '</small>:' . '</td>' . '<td>' . '<input' . ' type="text"' . ' style="width:100%;"' . ' id="album_custom_' . $key . '-' . $id . '"' . ' onkeyup="wppaAjaxUpdateAlbum( ' . $id . ', \'album_custom_' . $key . '\', this );"' . ' onchange="wppaAjaxUpdateAlbum( ' . $id . ', \'album_custom_' . $key . '\', this );"' . ' value="' . esc_attr(stripslashes($custom_data[$key])) . '"' . ' />' . '</td>' . '<td>' . '<small>' . '(w#cd' . $key . ')' . '</small>' . '</td>' . '</tr>';
                    }
                }
            }
            // Link type
            echo '<tr>' . '<td>' . __('Link type:', 'wp-photo-album-plus') . '</td>' . '<td>';
            $sel = ' selected="selected"';
            $lt = $cover_linktype;
            /* if ( !$linktype ) $linktype = 'content'; /* Default */
            /* if ( $albuminfo['cover_linkpage'] == '-1' ) $linktype = 'none'; /* for backward compatibility */
            echo '<select onchange="wppaAjaxUpdateAlbum( ' . $id . ', \'cover_linktype\', this )" >' . '<option value="content"' . ($lt == 'content' ? $sel : '') . ' >' . __('the sub-albums and thumbnails', 'wp-photo-album-plus') . '</option>' . '<option value="albums"' . ($lt == 'albums' ? $sel : '') . ' >' . __('the sub-albums', 'wp-photo-album-plus') . '</option>' . '<option value="thumbs"' . ($lt == 'thumbs' ? $sel : '') . ' >' . __('the thumbnails', 'wp-photo-album-plus') . '</option>' . '<option value="slide"' . ($lt == 'slide' ? $sel : '') . ' >' . __('the album photos as slideshow', 'wp-photo-album-plus') . '</option>' . '<option value="page"' . ($lt == 'page' ? $sel : '') . ' >' . __('the link page with a clean url', 'wp-photo-album-plus') . '</option>' . '<option value="none"' . ($lt == 'none' ? $sel : '') . ' >' . __('no link at all', 'wp-photo-album-plus') . '</option>' . '</select>' . '<br />' . '<span class="description">';
            if (wppa_switch('auto_page')) {
                _e('If you select "the link page with a clean url", select an Auto Page of one of the photos in this album.', 'wp-photo-album-plus');
            } else {
                _e('If you select "the link page with a clean url", make sure you enter the correct shortcode on the target page.', 'wp-photo-album-plus');
            }
            echo '</span>' . '</td>' . '<td>' . '</td>' . '</tr>';
            // Link page
            if (!wppa_switch('link_is_restricted') || wppa_user_is('administrator')) {
                echo '<tr>' . '<td>' . __('Link to:', 'wp-photo-album-plus') . '</td>' . '<td>';
                $query = "SELECT `ID`, `post_title` FROM `" . $wpdb->posts . "` WHERE `post_type` = 'page' AND `post_status` = 'publish' ORDER BY `post_title` ASC";
                $pages = $wpdb->get_results($query, ARRAY_A);
                if (empty($pages)) {
                    _e('There are no pages (yet) to link to.', 'wp-photo-album-plus');
                } else {
                    $linkpage = $albuminfo['cover_linkpage'];
                    if (!is_numeric($linkpage)) {
                        $linkpage = '0';
                    }
                    echo '<select' . ' onchange="wppaAjaxUpdateAlbum( ' . $id . ' , \'cover_linkpage\', this )"' . ' style="max-width:100%;"' . '>' . '<option value="0"' . ($linkpage == '0' ? $sel : '') . ' >' . __('--- the same page or post ---', 'wp-photo-album-plus') . '</option>';
                    foreach ($pages as $page) {
                        echo '<option value="' . $page['ID'] . '"' . ($linkpage == $page['ID'] ? $sel : '') . ' >' . __($page['post_title']) . '</option>';
                    }
                    echo '</select>' . '<br />' . '<span class="description" >' . __('If you want, you can link the title to a WP page in stead of the album\'s content. If so, select the page the title links to.', 'wp-photo-album-plus') . '</span>';
                }
                echo '</td>' . '<td>' . '</td>' . '</tr>';
            }
            // Schedule
            echo '<tr>' . '<td>' . __('Schedule:', 'wp-photo-album-plus') . ' ' . '<input' . ' type="checkbox"' . ' id="schedule-box"' . ($albuminfo['scheduledtm'] ? ' checked="checked"' : '') . ' onchange="wppaChangeScheduleAlbum(' . $id . ', this );"' . ' />' . '</td>' . '<td>' . '<input type="hidden" value="" id="wppa-dummy" />' . '<span class="wppa-datetime-' . $id . '"' . ($albuminfo['scheduledtm'] ? '' : ' style="display:none;"') . ' >' . wppa_get_date_time_select_html('album', $id, true) . '</span>' . '<br />' . '<span class="description" >' . __('If enabled, new photos will have their status set scheduled for publication on the date/time specified here.', 'wp-photo-album-plus') . '</span>' . '</td>' . '<td>' . '</td>' . '</tr>';
            echo '</tbody>' . '</table>';
            // Section 3, Actions
            echo "\n" . '<!-- Album Section 3 -->' . '<table' . ' class="wppa-table wppa-album-table"' . ' >' . '<tbody>' . '<tr>' . '<td>';
            // Inherit cats
            echo '<input' . ' type="button"' . ' title="' . esc_attr(__('Apply categories to all (grand)children.', 'wp-photo-album-plus')) . '"' . ' onclick="wppaTryInheritCats( ' . $id . ' )"' . ' value="' . esc_attr(__('Inherit Cats', 'wp-photo-album-plus')) . '"' . ' />' . '<input' . ' type="button"' . ' title="' . esc_attr(__('Add categories to all (grand)children.', 'wp-photo-album-plus')) . '"' . ' onclick="wppaTryAddCats( ' . $id . ' )"' . ' value="' . esc_attr(__('Add Inherit Cats', 'wp-photo-album-plus')) . '"' . ' />';
            // Apply default tags
            echo '<input' . ' type="button"' . ' title="' . esc_attr(__('Tag all photos in this album with the default tags.', 'wp-photo-album-plus')) . '"' . ' onclick="wppaTryApplyDeftags( ' . $id . ' )"' . ' value="' . esc_attr(__('Apply default tags', 'wp-photo-album-plus')) . '"' . ' />' . '<input' . ' type="button"' . ' title="' . esc_attr(__('Add the default tags to all photos in this album.', 'wp-photo-album-plus')) . '"' . ' onclick="wppaTryAddDeftags( ' . $id . ' )"' . ' value="' . esc_attr(__('Add default tags', 'wp-photo-album-plus')) . '"' . ' />';
            // Schedule all
            echo '<input' . ' type="button"' . ' title="' . esc_attr(__('Tag all photos in this album with the default tags.', 'wp-photo-album-plus')) . '"' . ' onclick="wppaTryScheduleAll( ' . $id . ' )"' . ' value="' . esc_attr(__('Schedule all', 'wp-photo-album-plus')) . '"' . ' />';
            // Reset Ratings
            if (wppa_switch('rating_on')) {
                $onc = 'if (confirm(\'' . __('Are you sure you want to clear the ratings in this album?', 'wp-photo-album-plus') . '\')) { wppaRefreshAfter(); wppaAjaxUpdateAlbum( ' . $id . ', \'clear_ratings\', 0 ); }';
                echo '<input' . ' type="button"' . ' onclick="' . $onc . '"' . ' value="' . esc_attr(__('Reset ratings', 'wp-photo-album-plus')) . '"' . ' />';
            }
            // Apply New photo desc
            if (wppa_switch('apply_newphoto_desc')) {
                $onc = 'if ( confirm(\'Are you sure you want to set the description of all photos to \\n\\n' . esc_js(wppa_opt('newphoto_description')) . '\')) document.location=\'' . wppa_ea_url($albuminfo['id'], 'edit') . '&applynewdesc\'';
                echo '<input' . ' type="button"' . ' onclick="' . $onc . '"' . ' value="' . esc_attr(__('Apply new photo desc', 'wp-photo-album-plus')) . '"' . ' />';
            }
            // Remake all
            if (wppa_user_is('administrator')) {
                $onc = 'if ( confirm(\'Are you sure you want to remake the files for all photos in this album?\')) document.location=\'' . wppa_ea_url($albuminfo['id'], 'edit') . '&remakealbum\'';
                echo '<input' . ' type="button"' . ' onclick="' . $onc . '"' . ' value="' . esc_attr(__('Remake all', 'wp-photo-album-plus')) . '"' . ' />';
            }
            // Goto Upload
            if (current_user_can('wppa_upload')) {
                $a = wppa_allow_uploads($id);
                if ($a) {
                    $full = false;
                } else {
                    $full = true;
                }
                $onc = $full ? 'alert(\'' . __('Change the upload limit or remove photos to enable new uploads.', 'wp-photo-album-plus') . '\')' : 'document.location = \'' . wppa_dbg_url(get_admin_url()) . '/admin.php?page=wppa_upload_photos&wppa-set-album=' . $id . '\'';
                $val = $full ? __('Album is full', 'wp-photo-album-plus') : __('Upload to this album', 'wp-photo-album-plus') . ($a > '0' ? ' ' . sprintf(__('(max %d)', 'wp-photo-album-plus'), $a) : '');
                echo '<input' . ' type="button"' . ' onclick="' . $onc . '"' . ' value="' . $val . '"' . ' />';
            }
            echo '</td>' . '</tr>' . '</tbody>' . '</table>';
            ?>
	</div>

					<?php 
            wppa_album_sequence($edit_id);
            ?>

<a id="manage-photos" ></a>
				<img src="<?php 
            echo WPPA_URL . '/img/camera32.png';
            ?>
" alt="Camera icon" />
				<h1 style="display:inline;" ><?php 
            _e('Manage Photos', 'wp-photo-album-plus');
            if (isset($_REQUEST['bulk'])) {
                echo ' - <small><i>' . __('Copy / move / delete / edit name / edit description / change status', 'wp-photo-album-plus') . '</i></small>';
            } elseif (isset($_REQUEST['seq'])) {
                echo ' - <small><i>' . __('Change sequence order by drag and drop', 'wp-photo-album-plus') . '</i></small>';
            } elseif (isset($_REQUEST['quick'])) {
                echo ' - <small><i>' . __('Edit photo information except copy and move', 'wp-photo-album-plus') . '</i></small>';
            } else {
                echo ' - <small><i>' . __('Edit photo information', 'wp-photo-album-plus') . '</i></small>';
            }
            ?>
</h1><div style="clear:both;" >&nbsp;</div>
				<?php 
            if (isset($_REQUEST['bulk'])) {
                wppa_album_photos_bulk($edit_id);
            } elseif (isset($_REQUEST['seq'])) {
                wppa_album_photos_sequence($edit_id);
            } else {
                wppa_album_photos($edit_id);
            }
            ?>
				<br /><a href="#manage-photos"><?php 
            _e('Top of page', 'wp-photo-album-plus');
            ?>
</a>
			</div>
<?php 
        } else {
            if ($_REQUEST['tab'] == 'cmod') {
                $photo = $_REQUEST['photo'];
                $alb = wppa_get_album_id_by_photo_id($photo);
                if (current_user_can('wppa_comments') && wppa_have_access($alb)) {
                    ?>
				<div class="wrap">
					<img src="<?php 
                    echo WPPA_URL . '/img/page_green.png';
                    ?>
" />
					<h1 style="display:inline;" ><?php 
                    _e('Moderate comment', 'wp-photo-album-plus');
                    ?>
</h1>
					<div style="clear:both;" >&nbsp;</div>
					<?php 
                    wppa_album_photos('', $photo);
                    ?>
				</div>
<?php 
                } else {
                    wp_die('You do not have the rights to do this');
                }
            } elseif ($_REQUEST['tab'] == 'pmod' || $_REQUEST['tab'] == 'pedit') {
                $photo = $_REQUEST['photo'];
                $alb = wppa_get_album_id_by_photo_id($photo);
                if (current_user_can('wppa_admin') && wppa_have_access($alb)) {
                    ?>
				<div class="wrap">
					<img src="<?php 
                    echo WPPA_URL . '/img/page_green.png';
                    ?>
" />
					<h1 style="display:inline;" ><?php 
                    if ($_REQUEST['tab'] == 'pmod') {
                        _e('Moderate photo', 'wp-photo-album-plus');
                    } else {
                        _e('Edit photo', 'wp-photo-album-plus');
                    }
                    ?>
					</h1><div style="clear:both;" >&nbsp;</div>
					<?php 
                    wppa_album_photos('', $photo);
                    ?>
				</div>
<?php 
                } else {
                    wp_die('You do not have the rights to do this');
                }
            } else {
                if ($_REQUEST['tab'] == 'del') {
                    $album_owner = $wpdb->get_var($wpdb->prepare("SELECT `owner` FROM " . WPPA_ALBUMS . " WHERE `id` = %s", $_REQUEST['edit_id']));
                    if ($album_owner == '--- public ---' && !current_user_can('administrator') || !wppa_have_access($_REQUEST['edit_id'])) {
                        wp_die('You do not have the rights to delete this album');
                    }
                    ?>
			<div class="wrap">
				<img src="<?php 
                    echo WPPA_URL . '/img/albumdel32.png';
                    ?>
" />
				<h1 style="display:inline;" ><?php 
                    _e('Delete Album', 'wp-photo-album-plus');
                    ?>
</h1>

				<p><?php 
                    _e('Album:', 'wp-photo-album-plus');
                    ?>
 <b><?php 
                    echo wppa_get_album_name($_REQUEST['edit_id']);
                    ?>
.</b></p>
				<p><?php 
                    _e('Are you sure you want to delete this album?', 'wp-photo-album-plus');
                    ?>
<br />
					<?php 
                    _e('Press Delete to continue, and Cancel to go back.', 'wp-photo-album-plus');
                    ?>
				</p>
				<form name="wppa-del-form" action="<?php 
                    echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_admin_menu');
                    ?>
" method="post">
					<?php 
                    wp_nonce_field('$wppa_nonce', WPPA_NONCE);
                    ?>
					<p>
						<?php 
                    _e('What would you like to do with photos currently in the album?', 'wp-photo-album-plus');
                    ?>
<br />
						<input type="radio" name="wppa-del-photos" value="delete" checked="checked" /> <?php 
                    _e('Delete', 'wp-photo-album-plus');
                    ?>
<br />
						<input type="radio" name="wppa-del-photos" value="move" /> <?php 
                    _e('Move to:', 'wp-photo-album-plus');
                    ?>
						<select name="wppa-move-album">
							<?php 
                    echo wppa_album_select_a(array('checkaccess' => true, 'path' => wppa_switch('hier_albsel'), 'selected' => '0', 'exclude' => $_REQUEST['edit_id'], 'addpleaseselect' => true));
                    ?>
						</select>
					</p>

					<input type="hidden" name="wppa-del-id" value="<?php 
                    echo $_REQUEST['edit_id'];
                    ?>
" />
					<input type="button" class="button-primary" value="<?php 
                    _e('Cancel', 'wp-photo-album-plus');
                    ?>
" onclick="parent.history.back()" />
					<input type="submit" class="button-primary" style="color: red" name="wppa-del-confirm" value="<?php 
                    _e('Delete', 'wp-photo-album-plus');
                    ?>
" />
				</form>
			</div>
<?php 
                }
            }
        }
    } else {
        //  'tab' not set. default, album manage page.
        // if add form has been submitted
        //		if (isset($_POST['wppa-na-submit'])) {
        //			check_admin_referer( '$wppa_nonce', WPPA_NONCE );
        //			wppa_add_album();
        //		}
        // if album deleted
        if (isset($_POST['wppa-del-confirm'])) {
            check_admin_referer('$wppa_nonce', WPPA_NONCE);
            $album_owner = $wpdb->get_var($wpdb->prepare("SELECT `owner` FROM " . WPPA_ALBUMS . " WHERE `id` = %s", $_POST['wppa-del-id']));
            if ($album_owner == '--- public ---' && !current_user_can('administrator') || !wppa_have_access($_POST['wppa-del-id'])) {
                wp_die('You do not have the rights to delete this album');
            }
            if ($_POST['wppa-del-photos'] == 'move') {
                $move = $_POST['wppa-move-album'];
                if (wppa_have_access($move)) {
                    wppa_del_album($_POST['wppa-del-id'], $move);
                } else {
                    wppa_error_message(__('Unable to move photos. Album not deleted.', 'wp-photo-album-plus'));
                }
            } else {
                wppa_del_album($_POST['wppa-del-id'], '');
            }
        }
        if (wppa_extended_access()) {
            if (isset($_REQUEST['switchto'])) {
                update_option('wppa_album_table_' . wppa_get_user(), $_REQUEST['switchto']);
            }
            $style = get_option('wppa_album_table_' . wppa_get_user(), 'flat');
        } else {
            $style = 'flat';
        }
        // The Manage Album page
        ?>
		<div class="wrap">
		<?php 
        wppa_admin_spinner();
        ?>
			<img src="<?php 
        echo WPPA_URL . '/img/album32.png';
        ?>
" />
			<h1 style="display:inline;" ><?php 
        _e('Manage Albums', 'wp-photo-album-plus');
        ?>
</h1>
			<div style="clear:both;" >&nbsp;</div>
			<?php 
        // The Create new album button
        if (wppa_can_create_top_album()) {
            $url = wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_admin_menu&amp;tab=edit&amp;edit_id=new');
            $vfy = __('Are you sure you want to create a new album?', 'wp-photo-album-plus');
            echo '<form method="post" action="' . get_admin_url() . 'admin.php?page=wppa_admin_menu" style="float:left; margin-right:12px;" >';
            echo '<input type="hidden" name="tab" value="edit" />';
            echo '<input type="hidden" name="edit_id" value="new" />';
            $onc = wppa_switch('confirm_create') ? 'onclick="return confirm(\'' . $vfy . '\');"' : '';
            echo '<input type="submit" class="button-primary" ' . $onc . ' value="' . __('Create New Empty Album', 'wp-photo-album-plus') . '" style="height:28px;" />';
            echo '</form>';
        }
        // The switch to button(s)
        if (wppa_extended_access()) {
            if ($style == 'flat') {
                ?>
					<input type="button" class="button-secundary" onclick="document.location='<?php 
                echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_admin_menu&amp;switchto=collapsable');
                ?>
'" value="<?php 
                _e('Switch to Collapsable table', 'wp-photo-album-plus');
                ?>
" />
				<?php 
            }
            if ($style == 'collapsable') {
                ?>
					<input type="button" class="button-secundary" onclick="document.location='<?php 
                echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_admin_menu&amp;switchto=flat');
                ?>
'" value="<?php 
                _e('Switch to Flat table', 'wp-photo-album-plus');
                ?>
" />
					<input
						type="button"
						class="button-secundary"
						id="wppa-open-all"
						style="display:inline;"
						onclick="	jQuery('#wppa-close-all').css('display','inline');
									jQuery(this).css('display','none');
									jQuery('.wppa-alb-onoff').css('display','');
									jQuery('.alb-arrow-off').css('display','');
									jQuery('.alb-arrow-on').css('display','none');
									"
						value="<?php 
                _e('Open all', 'wp-photo-album-plus');
                ?>
"
					/>
					<input
						type="button"
						class="button-secundary"
						id="wppa-close-all"
						style="display:none;"
						onclick="	jQuery('#wppa-open-all').css('display','inline');
									jQuery(this).css('display','none');
									jQuery('.wppa-alb-onoff').css('display','none');
									jQuery('.alb-arrow-on').css('display','');
									jQuery('.alb-arrow-off').css('display','none');
									"
						value="<?php 
                _e('Close all', 'wp-photo-album-plus');
                ?>
"
					/>
				<?php 
            }
        }
        ?>

			<br />
			<?php 
        // The table of existing albums
        if ($style == 'flat') {
            wppa_admin_albums_flat();
        } else {
            wppa_admin_albums_collapsable();
        }
        ?>
			<br />

			<?php 
        wppa_album_sequence('0');
        ?>
		</div>
<?php 
    }
}
function wppa_get_user_upload_html($xalb, $width, $where = '', $mcr = false)
{
    global $wpdb;
    global $wppa_supported_video_extensions;
    global $wppa_supported_audio_extensions;
    static $seqno;
    static $albums_granted;
    $albums_created = array();
    // Create granted albums only if not done yet i a previous occurance,
    // and an album id is given not being '0'
    if (wppa_is_int($xalb) && $xalb > '0') {
        if (!in_array($xalb, (array) $albums_granted, true)) {
            // This function will check if $xalb is a grant parent,
            // and make my subalbum if it does not already exist.
            $ta = wppa_grant_albums($xalb);
            if (!empty($ta)) {
                $albums_created = array_merge($albums_created, $ta);
            }
            // Remember we processed this possible grant parent
            $albums_granted[] = $xalb;
        }
    } elseif (wppa_is_enum($xalb)) {
        $temp = explode('.', wppa_expand_enum($xalb));
        foreach ($temp as $t) {
            if (!in_array($t, (array) $albums_granted, true)) {
                $ta = wppa_grant_albums($t);
                if (!empty($ta)) {
                    $albums_created = array_merge($albums_created, $ta);
                }
                $albums_granted[] = $t;
            }
        }
    }
    // If albums created, add them to the list, so they appear immediately
    $alb = $xalb;
    if (!empty($albums_created)) {
        foreach ($albums_created as $a) {
            $alb .= '.' . $a;
        }
    }
    // Init
    $mocc = wppa('mocc');
    $occur = wppa('occur');
    $yalb = str_replace('.', '', $xalb);
    // Open wrapper
    $result = '<div style="clear:both"></div>';
    //<div id="fe-upl-wrap-' . $mocc . '" style="background-color:#FFC;" >';
    // Using seqno to distinguish from different places within one occurrence because
    // the album no is not known when there is a selection box.
    if ($seqno) {
        $seqno++;
    } else {
        $seqno = '1';
    }
    // Feature enabled?
    if (!wppa_switch('user_upload_on')) {
        return '';
    }
    // Login required?
    if (wppa_switch('user_upload_login')) {
        if (!is_user_logged_in()) {
            return '';
        }
    } elseif (!is_user_logged_in()) {
        $public_exist = $wpdb->get_var("SELECT COUNT(*) " . "FROM `" . WPPA_ALBUMS . "` " . "WHERE `owner` = '--- public ---' ");
        if (!$public_exist) {
            return '';
        }
    }
    // Basically there are 3 possibilities for supplied album id(s)
    // 1. A single album
    // 2. '' or '0', meaning 'any'
    // 3. An album enumerations
    //
    // Now we are going to test if the visitor has access
    // Case 1. A single album. I should have access to this album ( $alb > 0 ).
    if (wppa_is_int($alb) && $alb > '0') {
        if (!wppa_have_access($alb)) {
            if (wppa_switch('upload_owner_only')) {
                return '';
            }
        }
    } elseif (!$alb) {
        $alb = trim(wppa_alb_to_enum_children('0') . '.' . wppa_alb_to_enum_children('-1'), '.');
    }
    // Case 3. An enumeration. Test for all albums in the enumeration, and remove the albums that he has no access to.
    // In this event, if a single album remains, there will not be a selectionbox, but its treated as if a single album was supplied.
    if (wppa_is_enum($alb)) {
        $albarr = explode('.', wppa_expand_enum($alb));
        foreach (array_keys($albarr) as $key) {
            if (!wppa_have_access($albarr[$key])) {
                if (wppa_switch('upload_owner_only')) {
                    unset($albarr[$key]);
                }
            }
        }
        if (empty($albarr)) {
            $alb = '';
        }
        if (count($albarr) == 1) {
            $alb = reset($albarr);
        } else {
            $alb = $albarr;
        }
    }
    // If no more albums left, no access, quit this proc.
    if (!$alb) {
        return '';
    }
    // The result is: $alb is either an album id, or an array of album ids. Always with upload access.
    // Find max files for the user
    $allow_me = wppa_allow_user_uploads();
    if (!$allow_me) {
        if (wppa_switch('show_album_full')) {
            $result .= '<h6 style="color:red">' . __('Max uploads reached', 'wp-photo-album-plus') . wppa_time_to_wait_html('0', true) . '</h6>';
        }
        return $result;
    }
    // Find max files for the album
    if (wppa_is_int($alb)) {
        $allow_alb = wppa_allow_uploads($alb);
        if (!$allow_alb) {
            if (wppa_switch('show_album_full')) {
                $result .= '<h6 style="color:red">' . __('Max uploads reached', 'wp-photo-album-plus') . wppa_time_to_wait_html($alb) . '</h6>';
            }
            return $result;
        }
    } else {
        $allow_alb = '-1';
    }
    if (wppa_is_user_blacklisted()) {
        return '';
    }
    // Find max files for the system
    $allow_sys = ini_get('max_file_uploads');
    // THE max
    if ($allow_me == '-1') {
        $allow_me = $allow_sys;
    }
    if ($allow_alb == '-1') {
        $allow_alb = $allow_sys;
    }
    $max = min($allow_me, $allow_alb, $allow_sys);
    // In a widget or multi column responsive?
    $small = wppa_in_widget() == 'upload' || $mcr;
    // Ajax upload?
    $ajax_upload = wppa_switch('ajax_upload') && wppa_browser_can_html5();
    // Create the return url
    if ($ajax_upload) {
        $returnurl = wppa_switch('ajax_non_admin') ? WPPA_URL . '/wppa-ajax-front.php' : admin_url('admin-ajax.php');
        $returnurl .= '?action=wppa&amp;wppa-action=do-fe-upload';
    } else {
        $returnurl = wppa_get_permalink();
        if ($where == 'cover') {
            $returnurl .= 'wppa-album=' . $alb . '&amp;wppa-cover=0&amp;wppa-occur=' . $occur;
        } elseif ($where == 'thumb') {
            $returnurl .= 'wppa-album=' . $alb . '&amp;wppa-cover=0&amp;wppa-occur=' . $occur;
        } elseif ($where == 'widget' || $where == 'uploadbox') {
        }
        if (wppa('page')) {
            $returnurl .= '&amp;wppa-page=' . wppa('page');
        }
        $returnurl = trim($returnurl, '?');
        $returnurl = wppa_trim_wppa_($returnurl);
    }
    // Make the HTML
    $t = $mcr ? 'mcr-' : '';
    $result .= '<a' . ' id="wppa-up-' . str_replace('.', '-', $yalb) . '-' . $mocc . '"' . ' class="wppa-upload-' . $where . ' wppa-album-cover-link"' . ' onclick="' . 'jQuery( \'#wppa-file-' . $t . str_replace('.', '-', $yalb) . '-' . $mocc . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#wppa-up-' . str_replace('.', '-', $yalb) . '-' . $mocc . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#wppa-cr-' . str_replace('.', '-', $yalb) . '-' . $mocc . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#wppa-ea-' . str_replace('.', '-', $yalb) . '-' . $mocc . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#wppa-cats-' . str_replace('.', '-', $yalb) . '-' . $mocc . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#_wppa-up-' . str_replace('.', '-', $yalb) . '-' . $mocc . '\' ).css( \'display\',\'block\' );' . '_wppaDoAutocol( ' . $mocc . ' )' . '"' . ' style="float:left; cursor:pointer;' . '" >' . __('Upload Photo', 'wp-photo-album-plus') . '</a>' . '<a' . ' id="_wppa-up-' . str_replace('.', '-', $yalb) . '-' . $mocc . '"' . ' class="wppa-upload-' . $where . ' wppa-album-cover-link"' . ' onclick="' . 'jQuery( \'#wppa-file-' . $t . str_replace('.', '-', $yalb) . '-' . $mocc . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#wppa-cr-' . str_replace('.', '-', $yalb) . '-' . $mocc . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#wppa-up-' . str_replace('.', '-', $yalb) . '-' . $mocc . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#wppa-ea-' . str_replace('.', '-', $yalb) . '-' . $mocc . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#wppa-cats-' . str_replace('.', '-', $yalb) . '-' . $mocc . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#_wppa-up-' . str_replace('.', '-', $yalb) . '-' . $mocc . '\' ).css( \'display\',\'none\' );' . '_wppaDoAutocol( ' . $mocc . ' )' . '"' . ' style="float:right; cursor:pointer;display:none;' . '" >' . __(wppa_opt('close_text'), 'wp-photo-album-plus') . '</a>' . '<div' . ' id="wppa-file-' . $t . str_replace('.', '-', $yalb) . '-' . $mocc . '"' . ' class=""' . ' style="width:100%;text-align:center;display:none; clear:both;"' . ' >' . '<form' . ' id="wppa-uplform-' . $yalb . '-' . $mocc . '"' . ' action="' . $returnurl . '"' . ' method="post"' . ' enctype="multipart/form-data"' . ' >' . wppa_nonce_field('wppa-check', 'wppa-nonce', false, false, $yalb);
    // Single Album given
    if (wppa_is_int($alb)) {
        $result .= '<input' . ' type="hidden"' . ' id="wppa-upload-album-' . $mocc . '-' . $seqno . '"' . ' name="wppa-upload-album"' . ' value="' . $alb . '"' . ' />';
    } else {
        if (!is_array($alb)) {
            $alb = explode('.', wppa_expand_enum($alb));
        }
        // Can an selection box be displayed?
        if (!wppa_opt('fe_upload_max_albums') || wppa_opt('fe_upload_max_albums') > wppa_get_uploadable_album_count($alb)) {
            // Below max
            $result .= '<select' . ' id="wppa-upload-album-' . $mocc . '-' . $seqno . '"' . ' name="wppa-upload-album"' . ' style="float:left; max-width: 100%;"' . ' onchange="jQuery( \'#wppa-sel-' . $yalb . '-' . $mocc . '\' ).trigger( \'onchange\' )"' . ' >' . wppa_album_select_a(array('addpleaseselect' => true, 'checkowner' => true, 'checkupload' => true, 'path' => wppa_switch('hier_albsel'), 'checkarray' => count($alb) > 1, 'array' => $alb)) . '</select>' . '<br />';
        } else {
            $result .= '<input' . ' id="wppa-upload-album-' . $mocc . '-' . $seqno . '"' . ' type="number"' . ' placeholder="' . esc_attr(__('Enter album id', 'wp-photo-album-plus')) . '"' . ' name="wppa-upload-album"' . ' style="float:left; max-width: 100%;"' . ' onchange="jQuery( \'#wppa-sel-' . $yalb . '-' . $mocc . '\' ).trigger( \'onchange\' )"' . ' />' . '<br />';
        }
    }
    $one_only = wppa_switch('upload_one_only');
    $multiple = !$one_only;
    $on_camera = wppa_switch('camera_connect');
    $may_video = wppa_switch('user_upload_video_on');
    $may_audio = wppa_switch('user_upload_audio_on');
    $accept = '.jpg,.gif,.png';
    if ($may_video) {
        $accept .= ',.' . implode(',.', $wppa_supported_video_extensions);
    }
    if ($may_audio) {
        $accept .= ',.' . implode(',.', $wppa_supported_audio_extensions);
    }
    if ($one_only) {
        if ($on_camera) {
            if ($may_video) {
                $value = esc_attr(__('Select Photo / Video / Camera', 'wp-photo-album-plus'));
            } else {
                $value = esc_attr(__('Select Photo / Camera', 'wp-photo-album-plus'));
            }
        } else {
            if ($may_video) {
                $value = esc_attr(__('Select Photo / Video', 'wp-photo-album-plus'));
            } else {
                $value = esc_attr(__('Select Photo', 'wp-photo-album-plus'));
            }
        }
    } else {
        if ($on_camera) {
            if ($may_video) {
                $value = esc_attr(__('Select Photos / Video / Camera', 'wp-photo-album-plus'));
            } else {
                $value = esc_attr(__('Select Photos / Camera', 'wp-photo-album-plus'));
            }
        } else {
            if ($may_video) {
                $value = esc_attr(__('Select Photos / Video', 'wp-photo-album-plus'));
            } else {
                $value = esc_attr(__('Select Photos', 'wp-photo-album-plus'));
            }
        }
    }
    $result .= '<input' . ' type="file"' . ' accept="' . $accept . '"' . ($multiple ? ' multiple="multiple"' : '') . ' style="' . 'display:none;' . '"' . ' id="wppa-user-upload-' . $yalb . '-' . $mocc . '"' . ' name="wppa-user-upload-' . $yalb . '-' . $mocc . '[]"' . ' onchange="' . 'jQuery( \'#wppa-user-submit-' . $yalb . '-' . $mocc . '\' ).css( \'display\', \'block\' );' . 'wppaDisplaySelectedFiles(\'wppa-user-upload-' . $yalb . '-' . $mocc . '\')' . '"' . ' />';
    if ($on_camera) {
        $result .= '<script>jQuery(\'#wppa-user-upload-' . $yalb . '-' . $mocc . '\').attr(\'capture\',\'capture\')</script>';
    }
    $result .= '<input' . ' type="button"' . ' style="width:100%;margin-top:8px;margin-bottom:8px;padding-left:0;padding-right:0;"' . ' id="wppa-user-upload-' . $yalb . '-' . $mocc . '-display"' . ' value="' . $value . '"' . ' onclick="jQuery( \'#wppa-user-upload-' . $yalb . '-' . $mocc . '\' ).click();"' . '/>';
    // Explanation
    if (!wppa_switch('upload_one_only')) {
        if ($max) {
            $result .= '<div style="font-size:10px;" >' . sprintf(_n('You may upload %d photo', 'You may upload up to %d photos at once if your browser supports HTML-5 multiple file upload', $max, 'wp-photo-album-plus'), $max) . '</div>';
            $maxsize = wppa_check_memory_limit(false);
            if (is_array($maxsize)) {
                $result .= '<div style="font-size:10px;" >' . sprintf(__('Max photo size: %d x %d (%2.1f MegaPixel)', 'wp-photo-album-plus'), $maxsize['maxx'], $maxsize['maxy'], $maxsize['maxp'] / (1024 * 1024)) . '</div>';
            }
        }
    }
    // Copyright notice
    if (wppa_switch('copyright_on')) {
        $result .= '<div style="width:100%;clear:both;" >' . __(wppa_opt('copyright_notice'), 'wp-photo-album-plus') . '</div>';
    }
    // Watermark
    if (wppa_switch('watermark_on') && wppa_switch('watermark_user')) {
        $result .= '<table' . ' class="wppa-watermark wppa-box-text"' . ' style="margin:0; border:0; ' . __wcs('wppa-box-text') . '"' . ' >' . '<tbody>' . '<tr valign="top" style="border: 0 none; " >' . '<td' . ' class="wppa-box-text wppa-td"' . ' style="' . __wcs('wppa-box-text') . __wcs('wppa-td') . '"' . ' >' . __('Apply watermark file:', 'wp-photo-album-plus') . '</td>' . '</tr>' . '<tr>' . '<td' . ' class="wppa-box-text wppa-td"' . ' style="width: ' . $width . ';' . __wcs('wppa-box-text') . __wcs('wppa-td') . '"' . ' >' . '<select' . ' style="margin:0; padding:0; text-align:left; width:auto; "' . ' name="wppa-watermark-file"' . ' id="wppa-watermark-file"' . ' >' . wppa_watermark_file_select() . '</select>' . '</td>' . '</tr>' . '<tr valign="top" style="border: 0 none; " >' . '<td' . ' class="wppa-box-text wppa-td"' . ' style="width: ' . $width . ';' . __wcs('wppa-box-text') . __wcs('wppa-td') . '"' . ' >' . __('Position:', 'wp-photo-album-plus') . '</td>' . ($small ? '</tr><tr>' : '') . '<td' . ' class="wppa-box-text wppa-td"' . ' style="width: ' . $width . ';' . __wcs('wppa-box-text') . __wcs('wppa-td') . '"' . ' >' . '<select' . ' style="margin:0; padding:0; text-align:left; width:auto; "' . ' name="wppa-watermark-pos"' . ' id="wppa-watermark-pos"' . ' >' . wppa_watermark_pos_select() . '</select>' . '</td>' . '</tr>' . '</tbody>' . '</table>';
    }
    // Name
    if (wppa_switch('name_user')) {
        switch (wppa_opt('newphoto_name_method')) {
            case 'none':
                $expl = '';
                break;
            case '2#005':
                $expl = __('If you leave this blank, iptc tag 005 (Graphic name) will be used as photoname if available, else the original filename will be used as photo name.', 'wp-photo-album-plus');
                break;
            case '2#120':
                $expl = __('If you leave this blank, iptc tag 120 (Caption) will be used as photoname if available, else the original filename will be used as photo name.', 'wp-photo-album-plus');
                break;
            default:
                $expl = __('If you leave this blank, the original filename will be used as photo name.', 'wp-photo-album-plus');
        }
        $result .= '<h6>' . __('Photo name', 'wp-photo-album-plus') . '</h6>' . '<div style="clear:left;font-size:10px;" >' . $expl . '</div>' . '<input' . ' type="text"' . ' class="wppa-box-text"' . ' style="border:1 px solid ' . wppa_opt('bcolor_upload') . ';clear:left; padding:0; width:100%; ' . __wcs('wppa-box-text') . '"' . ' name="wppa-user-name"' . ' />';
    }
    // Description user fillable ?
    if (wppa_switch('desc_user')) {
        $desc = wppa_switch('apply_newphoto_desc_user') ? stripslashes(wppa_opt('newphoto_description')) : '';
        $result .= '<h6>' . __('Photo description', 'wp-photo-album-plus') . '</h6>' . '<textarea' . ' class="wppa-user-textarea wppa-box-text"' . ' style="border:1 px solid ' . wppa_opt('bcolor_upload') . ';clear:left; padding:0; height:120px; width:100%; ' . __wcs('wppa-box-text') . '"' . ' name="wppa-user-desc"' . ' >' . $desc . '</textarea>';
    } elseif (wppa_switch('apply_newphoto_desc_user')) {
        $result .= '<input' . ' type="hidden"' . ' value="' . esc_attr(wppa_opt('newphoto_description')) . '"' . ' name="wppa-user-desc"' . ' />';
    }
    // Custom fields
    if (wppa_switch('fe_custom_fields')) {
        for ($i = '0'; $i < '10'; $i++) {
            if (wppa_opt('custom_caption_' . $i)) {
                $result .= '<h6>' . __(wppa_opt('custom_caption_' . $i), 'wp-photo-album-plus') . ': ' . (wppa_switch('custom_visible_' . $i) ? '' : '&nbsp;<small><i>(&nbsp;' . __('hidden', 'wp-photo-album-plus') . '&nbsp;)</i></small>') . '</h6>' . '<input' . ' type="text"' . ' class="wppa-box-text"' . ' style="border:1 px solid ' . wppa_opt('bcolor_upload') . ';clear:left; padding:0; width:100%; ' . __wcs('wppa-box-text') . '"' . ' name="wppa-user-custom-' . $i . '"' . ' />';
            }
        }
    }
    // Tags
    if (wppa_switch('fe_upload_tags')) {
        // Prepare onclick action
        $onc = 'wppaPrevTags(\'wppa-sel-' . $yalb . '-' . $mocc . '\', \'wppa-inp-' . $yalb . '-' . $mocc . '\', \'wppa-upload-album-' . $mocc . '-' . $seqno . '\', \'wppa-prev-' . $yalb . '-' . $mocc . '\')';
        // Open the tag enter area
        $result .= '<div style="clear:both;" >';
        // Selection boxes 1..3
        for ($i = '1'; $i < '4'; $i++) {
            if (wppa_switch('up_tagselbox_on_' . $i)) {
                $result .= '<h6>' . __(wppa_opt('up_tagselbox_title_' . $i), 'wp-photo-album-plus') . '</h6>' . '<select' . ' id="wppa-sel-' . $yalb . '-' . $mocc . '-' . $i . '"' . ' name="wppa-user-tags-' . $i . '[]"' . (wppa_switch('up_tagselbox_multi_' . $i) ? ' multiple' : '') . ' onchange="' . $onc . '"' . ' >';
                if (wppa_opt('up_tagselbox_content_' . $i)) {
                    // List of tags supplied
                    $tags = explode(',', wppa_opt('up_tagselbox_content_' . $i));
                    $result .= '<option value="" >&nbsp;</option>';
                    if (is_array($tags)) {
                        foreach ($tags as $tag) {
                            $result .= '<option class="wppa-sel-' . $yalb . '-' . $mocc . '" value="' . urlencode($tag) . '">' . $tag . '</option>';
                        }
                    }
                } else {
                    // All existing tags
                    $tags = wppa_get_taglist();
                    $result .= '<option value="" >&nbsp;</option>';
                    if (is_array($tags)) {
                        foreach ($tags as $tag) {
                            $result .= '<option class="wppa-sel-' . $yalb . '-' . $mocc . '" value="' . urlencode($tag['tag']) . '">' . $tag['tag'] . '</option>';
                        }
                    }
                }
                $result .= '</select><div style="clear:both;" ></div>';
            }
        }
        // New tags
        if (wppa_switch('up_tag_input_on')) {
            $result .= '<h6>' . __(wppa_opt('up_tag_input_title'), 'wp-photo-album-plus') . '</h6>' . '<input' . ' id="wppa-inp-' . $yalb . '-' . $mocc . '"' . ' type="text"' . ' class="wppa-box-text "' . ' style="padding:0; width:100%; ' . __wcs('wppa-box-text') . '"' . ' name="wppa-new-tags"' . ' onchange="' . $onc . '"' . ' />';
        }
        // Preview area
        if (wppa_switch('up_tag_preview')) {
            $result .= '<h6>' . __('Preview tags:', 'wp-photo-album-plus') . ' <small id="wppa-prev-' . $yalb . '-' . $mocc . '"></small>' . '</h6>' . '<script type="text/javascript" >jQuery( document ).ready(function() {' . $onc . '})</script>';
        }
        // Close tag enter area
        $result .= '</div>';
    }
    /* The Blogit section */
    if (($where == 'widget' || $where == 'uploadbox') && current_user_can('edit_posts') && wppa_switch('blog_it')) {
        $result .= '<div style="margin-top:6px;" >' . '<input' . ' type="button"' . ' value="' . esc_attr(__('Blog it?', 'wp-photo-album-plus')) . '"' . ' onclick="jQuery(\'#wppa-blogit-' . $yalb . '-' . $mocc . '\').trigger(\'click\')"' . ' />' . ' <input' . ' type="checkbox"' . ' id="wppa-blogit-' . $yalb . '-' . $mocc . '"' . ' name="wppa-blogit"' . ' style="display:none;"' . ' onchange="if ( jQuery(this).attr(\'checked\') ) { ' . 'jQuery(\'#blog-div-' . $yalb . '-' . $mocc . '\').css(\'display\',\'block\'); ' . 'jQuery(\'#wppa-user-submit-' . $yalb . '-' . $mocc . '\').attr(\'value\', \'' . esc_js(__('Upload and blog', 'wp-photo-album-plus')) . '\'); ' . '} ' . 'else { ' . 'jQuery(\'#blog-div-' . $yalb . '-' . $mocc . '\').css(\'display\',\'none\'); ' . 'jQuery(\'#wppa-user-submit-' . $yalb . '-' . $mocc . '\').attr(\'value\', \'' . esc_js(__('Upload photo', 'wp-photo-album-plus')) . '\'); ' . '} "' . ' />' . '<div' . ' id="blog-div-' . $yalb . '-' . $mocc . '"' . ' style="display:none;"' . ' />' . '<h6>' . __('Post title:', 'wp-photo-album-plus') . '</h6>' . '<input' . ' id="wppa-blogit-title-' . $yalb . '-' . $mocc . '"' . ' type="text"' . ' class="wppa-box-text "' . ' style="padding:0; width:100%; ' . __wcs('wppa-box-text') . '"' . ' name="wppa-post-title"' . ' />' . '<h6>' . __('Text BEFORE the image:', 'wp-photo-album-plus') . '</h6>' . '<textarea' . ' id="wppa-blogit-pretext-' . $yalb . '-' . $mocc . '"' . ' name="wppa-blogit-pretext"' . ' class=wppa-user-textarea wppa-box-text"' . ' style="border:1 px solid ' . wppa_opt('bcolor_upload') . ';clear:left; padding:0; height:120px; width:100%; ' . __wcs('wppa-box-text') . '"' . ' >' . '</textarea>' . '<h6>' . __('Text AFTER the image:', 'wp-photo-album-plus') . '</h6>' . '<textarea' . ' id="wppa-blogit-posttext-' . $yalb . '-' . $mocc . '"' . ' name="wppa-blogit-posttext"' . ' class=wppa-user-textarea wppa-box-text"' . ' style="border:1 px solid ' . wppa_opt('bcolor_upload') . ';clear:left; padding:0; height:120px; width:100%; ' . __wcs('wppa-box-text') . '"' . '>' . '</textarea>' . '</div>' . '</div>';
    }
    /* start submit section */
    // Onclick submit verify album is known
    if (!$alb) {
        $onclick = ' onclick="if ( document.getElementById( \'wppa-upload-album-' . $mocc . '-' . $seqno . '\' ).value == 0 )' . ' {alert( \'' . esc_js(__('Please select an album and try again', 'wp-photo-album-plus')) . '\' );return false;}"';
    } else {
        $onclick = '';
    }
    // The submit button
    $result .= '<div style="height:6px;;clear:both;" ></div>' . '<input' . ' type="submit"' . ' id="wppa-user-submit-' . $yalb . '-' . $mocc . '"' . $onclick . ' style="display:none; margin: 6px 0; float:right;"' . ' class="wppa-user-submit"' . ' name="wppa-user-submit-' . $yalb . '-' . $mocc . '" value="' . esc_attr(__('Upload photo', 'wp-photo-album-plus')) . '"' . ' />' . '<div style="height:6px;clear:both;"></div>';
    // if ajax: progression bar
    if ($ajax_upload) {
        $result .= '<div' . ' id="progress-' . $yalb . '-' . $mocc . '"' . ' class="wppa-progress "' . ' style="width:100%;border-color:' . wppa_opt('bcolor_upload') . '"' . ' >' . '<div id="bar-' . $yalb . '-' . $mocc . '" class="wppa-bar" ></div>' . '<div id="percent-' . $yalb . '-' . $mocc . '" class="wppa-percent" >0%</div >' . '</div>' . '<div id="message-' . $yalb . '-' . $mocc . '" class="wppa-message" ></div>';
    }
    /* End submit section */
    // Done
    $result .= '</form></div>';
    // Ajax upload script
    if ($ajax_upload) {
        $result .= '<script>' . 'jQuery(document).ready(function() {

					var options = {
						beforeSend: function() {
							jQuery("#progress-' . $yalb . '-' . $mocc . '").show();
							//clear everything
							jQuery("#bar-' . $yalb . '-' . $mocc . '").width(\'0%\');
							jQuery("#message-' . $yalb . '-' . $mocc . '").html("");
							jQuery("#percent-' . $yalb . '-' . $mocc . '").html("");
						},
						uploadProgress: function(event, position, total, percentComplete) {
							jQuery("#bar-' . $yalb . '-' . $mocc . '").width(percentComplete+\'%\');
							if ( percentComplete < 95 ) {
								jQuery("#percent-' . $yalb . '-' . $mocc . '").html(percentComplete+\'%\');
							}
							else {
								jQuery("#percent-' . $yalb . '-' . $mocc . '").html(\'Processing...\');
							}
						},
						success: function() {
							jQuery("#bar-' . $yalb . '-' . $mocc . '").width(\'100%\');
							jQuery("#percent-' . $yalb . '-' . $mocc . '").html(\'Done!\');
						},
						complete: function(response) {
							jQuery("#message-' . $yalb . '-' . $mocc . '").html( \'<span style="font-size: 10px;" >\'+response.responseText+\'</span>\' );' . ($where == 'thumb' ? 'document.location.reload(true)' : '') . '
						},
						error: function() {
							jQuery("#message-' . $yalb . '-' . $mocc . '").html( \'<span style="color: red;" >' . __('ERROR: unable to upload files.', 'wp-photo-album-plus') . '</span>\' );
						}
					};

					jQuery("#wppa-uplform-' . $yalb . '-' . $mocc . '").ajaxForm(options);
				});
			</script>';
    }
    // Close wrapper
    //	$result .= '</div>';
    return $result;
}