function wppa_get_the_bestof($count, $period, $sortby, $what)
{
    global $wpdb;
    // Phase 1, find the period we are talking about
    // find $start and $end
    switch ($period) {
        case 'lastweek':
            $start = wppa_get_timestamp('lastweekstart');
            $end = wppa_get_timestamp('lastweekend');
            break;
        case 'thisweek':
            $start = wppa_get_timestamp('thisweekstart');
            $end = wppa_get_timestamp('thisweekend');
            break;
        case 'lastmonth':
            $start = wppa_get_timestamp('lastmonthstart');
            $end = wppa_get_timestamp('lastmonthend');
            break;
        case 'thismonth':
            $start = wppa_get_timestamp('thismonthstart');
            $end = wppa_get_timestamp('thismonthend');
            break;
        case 'lastyear':
            $start = wppa_get_timestamp('lastyearstart');
            $end = wppa_get_timestamp('lastyearend');
            break;
        case 'thisyear':
            $start = wppa_get_timestamp('thisyearstart');
            $end = wppa_get_timestamp('thisyearend');
            break;
        default:
            return 'Unimplemented period: ' . $period;
    }
    // Phase 2, get the ratings of the period
    // find $ratings, ordered by photo id
    $ratings = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_RATING . "` WHERE `timestamp` >= %s AND `timestamp` < %s ORDER BY `photo`", $start, $end), ARRAY_A);
    // Phase 3, set up an array with data we need
    // There are two methods: photo oriented and owner oriented, depending on
    // Each element reflects a photo ( key = photo id ) and is an array with items: maxratings, meanrating, ratings, totvalue.
    $ratmax = wppa_opt('rating_max');
    $data = array();
    foreach ($ratings as $rating) {
        $key = $rating['photo'];
        if (!isset($data[$key])) {
            $data[$key] = array();
            $data[$key]['ratingcount'] = '1';
            $data[$key]['maxratingcount'] = $rating['value'] == $ratmax ? '1' : '0';
            $data[$key]['totvalue'] = $rating['value'];
        } else {
            $data[$key]['ratingcount'] += '1';
            $data[$key]['maxratingcount'] += $rating['value'] == $ratmax ? '1' : '0';
            $data[$key]['totvalue'] += $rating['value'];
        }
    }
    foreach (array_keys($data) as $key) {
        $thumb = wppa_cache_thumb($key);
        $data[$key]['meanrating'] = $data[$key]['totvalue'] / $data[$key]['ratingcount'];
        $user = get_user_by('login', $thumb['owner']);
        if ($user) {
            $data[$key]['user'] = $user->display_name;
        } else {
            // user deleted
            $data[$key]['user'] = $thumb['owner'];
        }
        $data[$key]['owner'] = $thumb['owner'];
    }
    // Now we split into search for photos and search for owners
    if ($what == 'photo') {
        // Pase 4, sort to the required sequence
        $data = wppa_array_sort($data, $sortby, SORT_DESC);
    } else {
        // $what == 'owner'
        // Phase 4, combine all photos of the same owner
        wppa_array_sort($data, 'user');
        $temp = $data;
        $data = array();
        foreach (array_keys($temp) as $key) {
            if (!isset($data[$temp[$key]['user']])) {
                $data[$temp[$key]['user']]['photos'] = '1';
                $data[$temp[$key]['user']]['ratingcount'] = $temp[$key]['ratingcount'];
                $data[$temp[$key]['user']]['maxratingcount'] = $temp[$key]['maxratingcount'];
                $data[$temp[$key]['user']]['totvalue'] = $temp[$key]['totvalue'];
                $data[$temp[$key]['user']]['owner'] = $temp[$key]['owner'];
            } else {
                $data[$temp[$key]['user']]['photos'] += '1';
                $data[$temp[$key]['user']]['ratingcount'] += $temp[$key]['ratingcount'];
                $data[$temp[$key]['user']]['maxratingcount'] += $temp[$key]['maxratingcount'];
                $data[$temp[$key]['user']]['totvalue'] += $temp[$key]['totvalue'];
            }
        }
        foreach (array_keys($data) as $key) {
            $data[$key]['meanrating'] = $data[$key]['totvalue'] / $data[$key]['ratingcount'];
        }
        $data = wppa_array_sort($data, $sortby, SORT_DESC);
    }
    // Phase 5, truncate to the desired length
    $c = '0';
    foreach (array_keys($data) as $key) {
        $c += '1';
        if ($c > $count) {
            unset($data[$key]);
        }
    }
    // Phase 6, return the result
    if (count($data)) {
        return $data;
    } else {
        return __('There are no ratings between', 'wp-photo-album-plus') . '<br />' . wppa_local_date('F j, Y, H:i s', $start) . ' ' . __('and', 'wp-photo-album-plus') . '<br />' . wppa_local_date('F j, Y, H:i s', $end) . '.';
    }
}
Example #2
0
function wppa_get_album_desc($id)
{
    if (!is_numeric($id) || $id < '1') {
        wppa_dbg_msg('Invalid arg wppa_get_album_desc( ' . $id . ' )', 'red');
    }
    $album = wppa_cache_album($id);
    $desc = $album['description'];
    // Raw data
    if (!$desc) {
        return '';
    }
    // No content, need no filtering
    $desc = stripslashes($desc);
    // Unescape
    $desc = __($desc);
    // qTranslate
    $desc = wppa_html($desc);
    // Enable html
    $desc = balanceTags($desc, true);
    // Balance tags
    if (strpos($desc, 'w#') !== false) {
        // Is there any 'w#' ?
        // Keywords
        $keywords = array('name', 'owner', 'id', 'views');
        foreach ($keywords as $keyword) {
            $replacement = __(trim(stripslashes($album[$keyword])));
            if ($replacement == '') {
                $replacement = '&lsaquo;' . __a('none', 'wppa') . '&rsaquo;';
            }
            $desc = str_replace('w#' . $keyword, $replacement, $desc);
        }
        // Timestamps
        $timestamps = array('timestamp', 'modified');
        // Identical, there is only timestamp, but it acts as modified
        foreach ($timestamps as $timestamp) {
            if ($album['timestamp']) {
                $desc = str_replace('w#' . $timestamp, wppa_local_date(get_option('date_format', "F j, Y,") . ' ' . get_option('time_format', "g:i a"), $album['timestamp']), $desc);
            } else {
                $desc = str_replace('w#' . $timestamp, '&lsaquo;' . __a('unknown') . '&rsaquo;', $desc);
            }
        }
    }
    // To prevent recursive rendering of scripts or shortcodes:
    $desc = str_replace(array('%%wppa%%', '[wppa', '[/wppa]'), array('%-wppa-%', '{wppa', '{/wppa}'), $desc);
    if (wppa_switch('wppa_allow_foreign_shortcodes_general')) {
        $desc = do_shortcode($desc);
    } else {
        $desc = strip_shortcodes($desc);
    }
    // Convert links and mailto:
    $desc = make_clickable($desc);
    // CMTooltipGlossary on board?
    $desc = wppa_filter_glossary($desc);
    return $desc;
}
function wppa_do_maintenance_popup($slug)
{
    global $wpdb;
    global $thumb;
    $result = '';
    switch ($slug) {
        case 'wppa_list_index':
            $start = get_option('wppa_list_index_display_start', '');
            $total = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_INDEX . "`");
            $indexes = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_INDEX . "` WHERE `slug` >= %s ORDER BY `slug` LIMIT 1000", $start), ARRAY_A);
            $result .= '
			<style>td, th { border-right: 1px solid darkgray; } </style>
			<h2>List of Searcheable words <small>( Max 1000 entries of total ' . $total . ' )</small></h2>
			<div style="float:left; clear:both; width:100%; overflow:auto; background-color:#f1f1f1; border:1px solid #ddd;" >';
            if ($indexes) {
                $result .= '
				<table>
					<thead>
						<tr>
							<th><span style="float:left;" >Word</span></th>
							<th style="max-width:400px;" ><span style="float:left;" >Albums</span></th>
							<th><span style="float:left;" >Photos</span></th>
						</tr>
						<tr><td colspan="3"><hr /></td></tr>
					</thead>
					<tbody>';
                foreach ($indexes as $index) {
                    $result .= '
						<tr>
							<td>' . $index['slug'] . '</td>
							<td style="max-width:400px; word-wrap: break-word;" >' . $index['albums'] . '</td>
							<td>' . $index['photos'] . '</td>
						</tr>';
                }
                $result .= '
					</tbody>
				</table>';
            } else {
                $result .= __('There are no index items.', 'wppa');
            }
            $result .= '
				</div><div style="clear:both;"></div>';
            break;
        case 'wppa_list_errorlog':
            $filename = WPPA_CONTENT_PATH . '/wppa-depot/admin/error.log';
            $result .= '
				<h2>List of WPPA+ error messages <small>( Newest first )</small></h2>
				<div style="float:left; clear:both; width:100%; overflow:auto; word-wrap:none; background-color:#f1f1f1; border:1px solid #ddd;" >';
            if (!($file = @fopen($filename, 'r'))) {
                $result .= __('There are no error log messages', 'wppa');
            } else {
                $size = filesize($filename);
                $data = fread($file, $size);
                $messages = explode("\n", $data);
                $count = count($messages);
                $idx = $count - '2';
                while ($idx >= '0') {
                    $msg = $messages[$idx];
                    $msg = htmlspecialchars(strip_tags($msg));
                    // Security fix
                    $result .= $msg . '<br />';
                    $idx--;
                }
            }
            $result .= '
				</div><div style="clear:both;"></div>
				';
            break;
        case 'wppa_list_rating':
            $total = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_RATING . "`");
            $ratings = $wpdb->get_results("SELECT * FROM `" . WPPA_RATING . "` ORDER BY `timestamp` DESC LIMIT 1000", ARRAY_A);
            $result .= '
			<style>td, th { border-right: 1px solid darkgray; } </style>
			<h2>List of recent ratings <small>( Max 1000 entries of total ' . $total . ' )</small></h2>
			<div style="float:left; clear:both; width:100%; overflow:auto; background-color:#f1f1f1; border:1px solid #ddd;" >';
            if ($ratings) {
                $result .= '
				<table>
					<thead>
						<tr>
							<th>Id</th>
							<th>Timestamp</th>
							<th>Date/time</th>
							<th>Status</th>
							<th>User</th>
							<th>Value</th>
							<th>Photo id</th>
							<th></th>
							<th># ratings</th>
							<th>Average</th>
						</tr>
						<tr><td colspan="10"><hr /></td></tr>
					</thead>
					<tbody>';
                foreach ($ratings as $rating) {
                    wppa_cache_thumb($rating['photo']);
                    $result .= '
						<tr>
							<td>' . $rating['id'] . '</td>
							<td>' . $rating['timestamp'] . '</td>
							<td>' . ($rating['timestamp'] ? wppa_local_date(get_option('date_format', "F j, Y,") . ' ' . get_option('time_format', "g:i a"), $rating['timestamp']) : 'pre-historic') . '</td>
							<td>' . $rating['status'] . '</td>
							<td>' . $rating['user'] . '</td>
							<td>' . $rating['value'] . '</td>
							<td>' . $rating['photo'] . '</td>
							<td style="width:250px; text-align:center;"><img src="' . wppa_get_thumb_url($rating['photo']) . '" 
								style="height: 40px;" 
								onmouseover="jQuery(this).stop().animate({height:this.naturalHeight}, 200);"
								onmouseout="jQuery(this).stop().animate({height:\'40px\'}, 200);" /></td>
							<td>' . $thumb['rating_count'] . '</td>
							<td>' . $thumb['mean_rating'] . '</td>
						</tr>';
                }
                $result .= '
					</tbody>
				</table>';
            } else {
                $result .= __('There are no ratings', 'wppa');
            }
            $result .= '
				</div><div style="clear:both;"></div>';
            break;
        case 'wppa_list_session':
            $total = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_SESSION . "` WHERE `status` = 'valid'");
            $sessions = $wpdb->get_results("SELECT * FROM `" . WPPA_SESSION . "` WHERE `status` = 'valid' ORDER BY `id` DESC LIMIT 1000", ARRAY_A);
            $result .= '
			<style>td, th { border-right: 1px solid darkgray; } </style>
			<h2>List of active sessions <small>( Max 1000 entries of total ' . $total . ' )</small></h2>
			<div style="float:left; clear:both; width:100%; overflow:auto; background-color:#f1f1f1; border:1px solid #ddd;" >';
            if ($sessions) {
                $result .= '
				<table>
					<thead>
						<tr>
							<th>Id</th>
							<th>Session id</th>
							<th>User</th>
							<th>Rs</th>
							<th>Started</th>
							<th>Count</th>
							<th>Page</th>
							<th>Ajax</th>
							<th>Albums viewed</th>
							<th>Photos viewed</th>
							<th>Search string</th>
							<th>root</th>
							<th>sub</th>
							<th>Superview</th>
						</tr>
						<tr><td colspan="14"><hr /></td></tr>
					</thead>
					<tbody>';
                foreach ($sessions as $session) {
                    $data = unserialize($session['data']);
                    $result .= '
							<tr>
								<td>' . $session['id'] . '</td>
								<td>' . $session['session'] . '</td>
								<td>' . $session['user'] . '</td>
								<td>' . $data['randseed'] . '</td>
								<td style="text-wrap:none;" >' . wppa_local_date(get_option('date_format', "F j, Y,") . ' ' . get_option('time_format', "g:i a"), $session['timestamp']) . '</td>
								<td>' . $session['count'] . '</td>
								<td>' . (isset($data['page']) ? $data['page'] : '') . '</td>
								<td>' . (isset($data['ajax']) ? $data['ajax'] : '') . '</td>
								<td>' . (isset($data['album']) ? wppa_index_array_to_string(array_keys($data['album'])) : '') . '</td>
								<td>' . (isset($data['photo']) ? wppa_index_array_to_string(array_keys($data['photo'])) : '') . '</td>
								<td>' . (isset($data['use_searchstring']) ? $data['use_searchstring'] : '') . '</td>
								<td style="text-wrap:unrestricted; max-width:300px;" >' . (isset($data['search_root']) ? $data['search_root'] . ' ' : '') . (isset($data['rootbox']) ? $data['rootbox'] ? 'on' : 'off' : '') . '</td>
								<td>' . (isset($data['subbox']) ? $data['subbox'] ? 'Y' : 'N' : '') . '</td>
								<td>' . (isset($data['superalbum']) ? $data['superalbum'] . ' ' : '') . (isset($data['superview']) ? $data['superview'] : '') . '</td>
							</tr>';
                }
                $result .= '
					</tbody>
				</table>';
            } else {
                $result .= __('There are no active sessions', 'wppa');
            }
            $result .= '
				</div><div style="clear:both;"></div>';
            break;
        default:
            $result = 'Error: Unimplemented slug: ' . $slug . ' in wppa_do_maintenance_popup()';
    }
    return $result;
}
function wppa_get_potd()
{
    global $wpdb;
    global $thumb;
    $image = '';
    switch (wppa_opt('wppa_widget_method')) {
        case '1':
            // Fixed photo
            $id = wppa_opt('wppa_widget_photo');
            if ($id != '') {
                $image = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `id` = %s LIMIT 0,1", $id), ARRAY_A);
                wppa_dbg_q('Q-Potd');
                wppa_cache_photo('add', $image);
            }
            break;
        case '2':
            // Random
            $album = wppa_opt('wppa_widget_album');
            if ($album == 'topten') {
                $images = wppa_get_widgetphotos($album);
                if (count($images) > 1) {
                    // Select a random first from the current selection
                    $idx = rand(0, count($images) - 1);
                    $image = $images[$idx];
                }
            } elseif ($album != '') {
                $images = wppa_get_widgetphotos($album, "ORDER BY RAND() LIMIT 0,1");
                $image = $images[0];
            }
            break;
        case '3':
            // Last upload
            $album = wppa_opt('wppa_widget_album');
            if ($album == 'topten') {
                $images = wppa_get_widgetphotos($album);
                if ($images) {
                    // fid last uploaded image in the $images pool
                    $temp = 0;
                    foreach ($images as $img) {
                        if ($img['timestamp'] > $temp) {
                            $temp = $img['timestamp'];
                            $image = $img;
                        }
                    }
                }
            } elseif ($album != '') {
                $images = wppa_get_widgetphotos($album, "ORDER BY timestamp DESC LIMIT 0,1");
                $image = $images[0];
            }
            break;
        case '4':
            // Change every
            $album = wppa_opt('wppa_widget_album');
            if ($album != '') {
                $per = wppa_opt('wppa_widget_period');
                $photos = wppa_get_widgetphotos($album);
                if ($per == '0') {
                    if ($photos) {
                        $image = $photos[rand(0, count($photos) - 1)];
                    } else {
                        $image = '';
                    }
                } elseif ($per == 'day-of-week') {
                    $image = '';
                    if ($photos) {
                        $d = wppa_local_date('w');
                        if (!$d) {
                            $d = '7';
                        }
                        foreach ($photos as $img) {
                            if ($img['p_order'] == $d) {
                                $image = $img;
                            }
                        }
                    }
                } elseif ($per == 'day-of-month') {
                    $image = '';
                    if ($photos) {
                        $d = wppa_local_date('d');
                        if (substr($d, '0', '1') == '0') {
                            $d = substr($d, '1');
                        }
                        foreach ($photos as $img) {
                            if ($img['p_order'] == $d) {
                                $image = $img;
                            }
                        }
                    }
                } else {
                    $u = date("U");
                    // Seconds since 1-1-1970
                    $u /= 3600;
                    //  hours since
                    $u = floor($u);
                    $u /= $per;
                    $u = floor($u);
                    if ($photos) {
                        $p = count($photos);
                        $idn = fmod($u, $p);
                        $image = $photos[$idn];
                    } else {
                        $image = '';
                    }
                }
            } else {
                $image = '';
            }
            break;
        default:
            $image = '';
    }
    $thumb = $image;
    return $image;
}
function wppa_create_textual_watermark_file($args)
{
    // See what we have
    $args = wp_parse_args((array) $args, array('content' => '---preview---', 'pos' => 'cencen', 'id' => '', 'font' => wppa_opt('wppa_textual_watermark_font'), 'text' => '', 'style' => wppa_opt('wppa_textual_watermark_type'), 'filebasename' => 'dummy', 'url' => false, 'width' => '', 'height' => '', 'transp' => '0'));
    // We may have been called from wppa_get_water_file_and_pos() just to find the settings
    // In this case there is no id given.
    $id = $args['id'];
    if (!$id && $args['content'] != '---preview---') {
        return false;
    }
    if ($id && wppa_is_video($id)) {
        //		return false;
    }
    // Set special values in case of preview
    if ($args['content'] == '---preview---') {
        $preview = true;
        $fontsize = $args['font'] == 'system' ? 5 : 12;
        $padding = 6;
        $linespacing = ceil($fontsize * 2 / 3);
    } else {
        $preview = false;
        $fontsize = wppa_opt('wppa_textual_watermark_size');
        if ($args['font'] == 'system') {
            $fontsize = min($fontsize, 5);
        }
        $padding = 12;
        $linespacing = ceil($fontsize * 2 / 3);
    }
    // Set font specific vars
    $fontfile = $args['font'] == 'system' ? '' : WPPA_UPLOAD_PATH . '/fonts/' . $args['font'] . '.ttf';
    // Output file
    if ($preview) {
        $filename = WPPA_UPLOAD_PATH . '/fonts/wmf' . $args['filebasename'] . '.png';
    } else {
        $filename = WPPA_UPLOAD_PATH . '/temp/wmf' . $args['filebasename'] . '.png';
    }
    // Preprocess the text
    if (!$args['text']) {
        switch ($args['content']) {
            case '---preview---':
                $text = strtoupper(substr($args['font'], 0, 1)) . strtolower(substr($args['font'], 1));
                break;
            case '---filename---':
                $text = wppa_get_photo_item($id, 'filename');
                break;
            case '---name---':
                $text = wppa_get_photo_name($id);
                break;
            case '---description---':
                $text = strip_tags(wppa_strip_tags(wppa_get_photo_desc($id), 'style&script'));
                break;
            case '---predef---':
                $text = wppa_opt('wppa_textual_watermark_text');
                if ($args['font'] != 'system') {
                    $text = str_replace('( c )', '&copy;', $text);
                    $text = str_replace('( R )', '&reg;', $text);
                }
                $text = html_entity_decode($text);
                $text = str_replace('w#site', get_bloginfo('url'), $text);
                $text = str_replace('w#owner', wppa_get_photo_item($id, 'owner'), $text);
                $text = str_replace('w#id', $id, $text);
                $text = str_replace('w#name', wppa_get_photo_name($id), $text);
                $text = str_replace('w#filename', wppa_get_photo_item($id, 'filename'), $text);
                $text = str_replace('w#timestamp', wppa_local_date(get_option('date_format', "F j, Y,") . ' ' . get_option('time_format', "g:i a"), wppa_get_photo_item($id, 'timestamp')), $text);
                $text = trim($text);
                break;
            default:
                wppa_log('Error', 'Unimplemented arg ' . $arg . ' in wppa_create_textual_watermark_file()');
                return false;
        }
    } else {
        $text = $args['text'];
    }
    // Any text anyway?
    if (!strlen($text)) {
        wppa_log('Error', 'No text for textual watermark. photo=' . $id);
        return false;
        // No text -> no watermark
    }
    // Split text on linebreaks
    $text = str_replace("\n", '\\n', $text);
    $lines = explode('\\n', $text);
    // Trim and remove empty lines
    $temp = $lines;
    $lines = array();
    foreach ($temp as $line) {
        $line = trim($line);
        if ($line) {
            $lines[] = $line;
        }
    }
    // Find image width
    if ($args['width']) {
        $image_width = $args['width'];
    } else {
        $image_width = '';
    }
    if ($args['height']) {
        $image_height = $args['height'];
    } else {
        $image_height = '';
    }
    if ($preview) {
        if (!$image_width) {
            $image_width = 2000;
        }
        if (!$image_height) {
            $image_height = 1000;
        }
    } else {
        //		$temp = getimagesize( wppa_get_photo_path( $id ) );
        $temp = wppa_get_imagexy($id);
        if (!is_array($temp)) {
            wppa_log('Error', 'Trying to apply a watermark on a non image file. Id = ' . $id);
            return false;
            // not an image
        }
        if (!$image_width) {
            $image_width = $temp[0];
        }
        if (!$image_height) {
            $image_height = $temp[1];
        }
    }
    $width_fits = false;
    while (!$width_fits) {
        // Find pixel linelengths
        foreach (array_keys($lines) as $key) {
            $lines[$key] = trim($lines[$key]);
            if ($args['font'] == 'system') {
                $lengths[$key] = strlen($lines[$key]) * imagefontwidth($fontsize);
            } else {
                $temp = imagettfbbox($fontsize, 0.0, $fontfile, $lines[$key]);
                $lengths[$key] = $temp[2] - $temp[0];
            }
        }
        $maxlen = wppa_array_max($lengths);
        // Find canvas size
        $nlines = count($lines);
        if ($args['font'] == 'system') {
            $lineheight = imagefontheight($fontsize);
        } else {
            $temp = imagettfbbox($fontsize, 0.0, $fontfile, $lines[0]);
            $lineheight = $temp[3] - $temp[7];
        }
        $canvas_width = wppa_array_max($lengths) + 4 * $padding;
        $canvas_height = ($lineheight + $linespacing) * count($lines) + 2 * $padding;
        // Does it fit?
        if ($canvas_width > $image_width) {
            // Break the longest line into two sublines. There should be a space in the right half, if not: fail
            $i = 0;
            $l = 0;
            foreach (array_keys($lines) as $key) {
                if (strlen($lines[$key]) > $l) {
                    $i = $key;
                    $l = strlen($lines[$key]);
                }
            }
            $temp = $lines;
            $lines = array();
            $j = 0;
            while ($j < $i) {
                $lines[$j] = $temp[$j];
                $j++;
            }
            //
            $j = $i;
            $llen = strlen($temp[$i]);
            $spos = floor($llen / 2);
            while ($spos < $llen && substr($temp[$i], $spos, 1) != ' ') {
                $spos++;
            }
            if ($spos == $llen) {
                // Unable to find a space, give up
                wppa_log('Error', 'Trying to apply a watermark that is too wide for the image. Id = ' . $id);
                return false;
                // too wide
            }
            $lines[$j] = substr($temp[$i], 0, $spos);
            $lines[$j + 1] = trim(str_replace($lines[$j], '', $temp[$i]));
            $i++;
            //
            $j = $i + 1;
            while ($j <= count($temp)) {
                $lines[$j] = $temp[$i];
                $j++;
            }
        } else {
            $width_fits = true;
        }
        if ($canvas_height > $image_height) {
            wppa_log('Error', 'Trying to apply a watermark that is too high for the image. Id = ' . $id);
            return false;
            // not an image
        }
    }
    // Create canvas
    $canvas = imagecreatetruecolor($canvas_width, $canvas_height);
    $bgcolor = imagecolorallocatealpha($canvas, 0, 0, 0, 127);
    // Transparent
    $white = imagecolorallocatealpha($canvas, 255, 255, 255, $args['transp']);
    $black = imagecolorallocatealpha($canvas, 0, 0, 0, $args['transp']);
    imagefill($canvas, 0, 0, $bgcolor);
    //	imagerectangle( $canvas, 0, 0, $canvas_width-1, $canvas_height-1, $white );	// debug
    // Define the text colors
    switch ($args['style']) {
        case 'tvstyle':
        case 'whiteonblack':
            $fg = $white;
            $bg = $black;
            break;
        case 'utopia':
        case 'blackonwhite':
            $fg = $black;
            $bg = $white;
            break;
        case 'white':
            $fg = $white;
            $bg = $bgcolor;
            break;
        case 'black':
            $fg = $black;
            $bg = $bgcolor;
            break;
    }
    // Plot the text
    foreach (array_keys($lines) as $lineno) {
        if (strpos($args['pos'], 'lft') !== false) {
            $indent = 0;
        } elseif (strpos($args['pos'], 'rht') !== false) {
            $indent = $maxlen - $lengths[$lineno];
        } else {
            $indent = floor(($maxlen - $lengths[$lineno]) / 2);
        }
        switch ($args['style']) {
            case 'tvstyle':
            case 'utopia':
                for ($i = -1; $i <= 1; $i++) {
                    for ($j = -1; $j <= 1; $j++) {
                        if ($args['font'] == 'system') {
                            imagestring($canvas, $fontsize, 2 * $padding + $i + $indent, $padding + $lineno * ($lineheight + $linespacing) + $j, $lines[$lineno], $bg);
                        } else {
                            imagettftext($canvas, $fontsize, 0, 2 * $padding + $i + $indent, $padding + ($lineno + 1) * $lineheight + $lineno * $linespacing + $j, $bg, $fontfile, $lines[$lineno]);
                        }
                    }
                }
                if ($args['font'] == 'system') {
                    imagestring($canvas, $fontsize, 2 * $padding + $indent, $padding + $lineno * ($lineheight + $linespacing), $lines[$lineno], $fg);
                } else {
                    imagettftext($canvas, $fontsize, 0, 2 * $padding + $indent, $padding + ($lineno + 1) * $lineheight + $lineno * $linespacing, $fg, $fontfile, $lines[$lineno]);
                }
                break;
            case 'blackonwhite':
            case 'whiteonblack':
            case 'white':
            case 'black':
                $lft = $padding + $indent;
                $rht = 3 * $padding + $indent + $lengths[$lineno];
                $top = $lineno * ($lineheight + $linespacing) + $padding;
                $bot = ($lineno + 1) * ($lineheight + $linespacing) + $padding;
                imagefilledrectangle($canvas, $lft, $top + 1, $rht, $bot, $bg);
                //				imagerectangle( $canvas, $lft, $top, $rht, $bot, $fg );	// debug
                $top = $padding + $lineno * ($lineheight + $linespacing) + floor($linespacing / 2);
                $lft = 2 * $padding + $indent;
                $bot = $padding + ($lineno + 1) * ($lineheight + $linespacing) - ceil($linespacing / 2);
                if ($args['font'] == 'system') {
                    imagestring($canvas, $fontsize, $lft, $top, $lines[$lineno], $fg);
                } else {
                    imagettftext($canvas, $fontsize, 0, $lft, $bot - 1, $fg, $fontfile, $lines[$lineno]);
                }
                break;
        }
    }
    imagesavealpha($canvas, true);
    imagepng($canvas, $filename);
    imagedestroy($canvas);
    if ($preview || $args['url']) {
        $url = str_replace(WPPA_UPLOAD_PATH, WPPA_UPLOAD_URL, $filename);
        return $url;
    } else {
        return $filename;
    }
}
function wppa_user_upload()
{
    global $wpdb;
    static $done;
    wppa_dbg_msg('Usr_upl entered');
    if ($done) {
        return;
    }
    // Already done
    $done = true;
    // Mark as done
    // Upload possible?
    $may_upload = wppa_switch('user_upload_on');
    if (wppa_switch('user_upload_login')) {
        if (!is_user_logged_in()) {
            $may_upload = false;
        }
        // Must login
    }
    // Create album possible?
    $may_create = wppa_switch('user_create_on');
    if (wppa_switch('user_create_login')) {
        if (!is_user_logged_in()) {
            $may_create = false;
        }
        // Must login
    }
    // Edit album possible?
    $may_edit = wppa_switch('user_album_edit_on');
    // Do create
    if ($may_create) {
        if (wppa_get_post('wppa-fe-create')) {
            // Create album
            $nonce = wppa_get_post('nonce');
            if (wppa_get_post('wppa-album-name')) {
                $albumname = trim(strip_tags(wppa_get_post('wppa-album-name')));
            }
            if (!wppa_sanitize_file_name($albumname)) {
                $albumname = __('New Album', 'wp-photo-album-plus');
            }
            $ok = wp_verify_nonce($nonce, 'wppa-album-check');
            if (!$ok) {
                die('<b>' . __('ERROR: Illegal attempt to create an album.', 'wp-photo-album-plus') . '</b>');
            }
            // Check captcha
            if (wppa_switch('user_create_captcha')) {
                $captkey = wppa_get_randseed('session');
                if (!wppa_check_captcha($captkey)) {
                    wppa_alert(__('Wrong captcha, please try again', 'wp-photo-album-plus'));
                    return;
                }
            }
            $parent = strval(intval(wppa_get_post('wppa-album-parent')));
            if (!wppa_user_is('administrator') && wppa_switch('default_parent_always')) {
                $parent = wppa_opt('default_parent');
            }
            $album = wppa_create_album_entry(array('name' => $albumname, 'description' => strip_tags(wppa_get_post('wppa-album-desc')), 'a_parent' => $parent, 'owner' => wppa_switch('frontend_album_public') ? '--- public ---' : wppa_get_user()));
            if ($album) {
                if (wppa_switch('fe_alert')) {
                    wppa_alert(sprintf(__('Album #%s created', 'wp-photo-album-plus'), $album));
                }
                wppa_flush_treecounts($parent);
                wppa_create_pl_htaccess();
            } else {
                wppa_alert(__('Could not create album', 'wp-photo-album-plus'));
            }
        }
    }
    // Do Upload
    if ($may_upload) {
        $blogged = false;
        if (wppa_get_post('wppa-upload-album')) {
            // Upload photo
            $nonce = wppa_get_post('nonce');
            $ok = wp_verify_nonce($nonce, 'wppa-check');
            if (!$ok) {
                die('<b>' . __('ERROR: Illegal attempt to upload a file.', 'wp-photo-album-plus') . '</b>');
            }
            $alb = wppa_get_post('wppa-upload-album');
            $alb = strval(intval($alb));
            // Force numeric
            if (!wppa_album_exists($alb)) {
                $alert = sprintf(__('Album %s does not exist', 'wp-photo-album-plus'), $alb);
                wppa_alert($alert);
                return;
            }
            $uploaded_ids = array();
            if (is_array($_FILES)) {
                $iret = true;
                $filecount = '1';
                $done = '0';
                $fail = '0';
                foreach ($_FILES as $file) {
                    if (!is_array($file['error'])) {
                        $iret = wppa_do_frontend_file_upload($file, $alb);
                        // this should no longer happen since the name is incl []
                        if ($iret) {
                            $uploaded_ids[] = $iret;
                            $done++;
                            wppa_set_last_album($alb);
                        } else {
                            $fail++;
                        }
                    } else {
                        $filecount = count($file['error']);
                        for ($i = '0'; $i < $filecount; $i++) {
                            if ($iret) {
                                $f['error'] = $file['error'][$i];
                                $f['tmp_name'] = $file['tmp_name'][$i];
                                $f['name'] = $file['name'][$i];
                                $f['type'] = $file['type'][$i];
                                $f['size'] = $file['size'][$i];
                                $iret = wppa_do_frontend_file_upload($f, $alb);
                                if ($iret) {
                                    $uploaded_ids[] = $iret;
                                    $done++;
                                    wppa_set_last_album($alb);
                                } else {
                                    $fail++;
                                }
                            }
                        }
                    }
                }
                $points = '0';
                $alert = '';
                $reload = wppa_switch('home_after_upload') && $done ? 'home' : false;
                if ($done) {
                    // SUCCESSFUL UPLOAD, Blog It?
                    if (current_user_can('edit_posts') && isset($_POST['wppa-blogit'])) {
                        $title = $_POST['wppa-post-title'];
                        if (!$title) {
                            $title = wppa_local_date();
                        }
                        $pretxt = $_POST['wppa-blogit-pretext'];
                        $posttxt = $_POST['wppa-blogit-posttext'];
                        $status = wppa_switch('blog_it_moderate') ? 'pending' : 'publish';
                        $post_content = $pretxt;
                        foreach ($uploaded_ids as $id) {
                            $post_content .= str_replace('#id', $id, wppa_opt('blog_it_shortcode'));
                        }
                        $post_content .= $posttxt;
                        $post = array('post_title' => $title, 'post_content' => $post_content, 'post_status' => $status);
                        $post = sanitize_post($post, 'db');
                        $iret = wp_insert_post($post);
                        $blogged = true;
                    }
                    // ADD POINTS
                    $points = wppa_opt('cp_points_upload') * $done;
                    $bret = wppa_add_credit_points($points, __('Photo upload', 'wp-photo-album-plus'));
                    $alert .= sprintf(_n('%d photo successfully uploaded', '%d photos successfully uploaded', $done, 'wp-photo-album-plus'), $done);
                    if ($bret) {
                        $alert .= ' ' . sprintf(__('%s points added', 'wp-photo-album-plus'), $points);
                    }
                    if (wppa_switch('fe_alert')) {
                        wppa_alert($alert, $reload);
                    } else {
                        wppa_alert('', $reload);
                    }
                    // Blogged?
                    if ($blogged) {
                        if (wppa_switch('fe_alert')) {
                            if ($status == 'pending') {
                                wppa_alert(__('Your post is awaiting moderation.', 'wp-photo-album-plus'));
                            }
                        }
                        echo '<script type="text/javascript" >document.location.href=\'' . home_url() . '\';</script>';
                        wppa_exit();
                    }
                }
                if ($fail) {
                    if (!$done) {
                        $alert .= __('Upload failed', 'wp-photo-album-plus');
                    } else {
                        $alert .= sprintf(_n('%d upload failed', '%d uploads failed', $fail, 'wp-photo-album-plus'), $fail);
                    }
                    wppa_alert($alert, $reload);
                }
            }
        }
    }
    // Do Edit
    if ($may_edit) {
        if (wppa_get_post('wppa-albumeditsubmit')) {
            // Get album id
            $alb = wppa_get_post('wppa-albumeditid');
            if (!$alb || !wppa_album_exists($alb)) {
                die('Security check failure');
            }
            // Valid request?
            if (!wp_verify_nonce(wppa_get_post('wppa-albumeditnonce'), 'wppa_nonce_' . $alb)) {
                die('Security check failure');
            }
            // Name
            $name = wppa_get_post('wppa-albumeditname');
            $name = trim(strip_tags($name));
            if (!$name) {
                // Empty album name is not allowed
                $name = 'Album-#' . $alb;
            }
            // Description
            $description = wppa_get_post('wppa-albumeditdesc');
            // Custom data
            $custom = wppa_get_album_item($alb, 'custom');
            if ($custom) {
                $custom_data = unserialize($custom);
            } else {
                $custom_data = array('', '', '', '', '', '', '', '', '', '');
            }
            $idx = '0';
            while ($idx < '10') {
                if (isset($_POST['custom_' . $idx])) {
                    $value = wppa_get_post('custom_' . $idx);
                    $custom_data[$idx] = wppa_sanitize_custom_field($value);
                }
                $idx++;
            }
            $custom = serialize($custom_data);
            // Update
            wppa_update_album(array('id' => $alb, 'name' => $name, 'description' => $description, 'custom' => $custom, 'modified' => time()));
            wppa_index_update('album', $alb);
            wppa_create_pl_htaccess();
        }
    }
}
function wppa_album_photos($album = '', $photo = '', $owner = '', $moderate = false)
{
    global $wpdb;
    // Check input
    wppa_vfy_arg('wppa-page');
    $pagesize = wppa_opt('photo_admin_pagesize');
    $page = isset($_GET['wppa-page']) ? $_GET['wppa-page'] : '1';
    $skip = ($page - '1') * $pagesize;
    $limit = $pagesize < '1' ? '' : ' LIMIT ' . $skip . ',' . $pagesize;
    if ($album) {
        if ($album == 'search') {
            $count = wppa_get_edit_search_photos('', 'count_only');
            $photos = wppa_get_edit_search_photos($limit);
            $link = wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_admin_menu&tab=edit&edit_id=' . $album . '&wppa-searchstring=' . wppa_sanitize_searchstring($_REQUEST['wppa-searchstring']));
        } else {
            $counts = wppa_treecount_a($album);
            $count = $counts['selfphotos'] + $counts['pendphotos'];
            $photos = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . WPPA_PHOTOS . '` WHERE `album` = %s ' . wppa_get_photo_order($album, 'norandom') . $limit, $album), ARRAY_A);
            $link = wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_admin_menu&tab=edit&edit_id=' . $album);
        }
    } elseif ($photo && !$moderate) {
        $count = '1';
        $photos = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . WPPA_PHOTOS . '` WHERE `id` = %s', $photo), ARRAY_A);
        $link = '';
    } elseif ($owner) {
        $count = $wpdb->get_var($wpdb->prepare('SELECT COUNT(*) FROM `' . WPPA_PHOTOS . '` WHERE `owner` = %s', $owner));
        $photos = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . WPPA_PHOTOS . '` WHERE `owner` = %s ORDER BY `timestamp` DESC' . $limit, $owner), ARRAY_A);
        $link = wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_edit_photo');
    } elseif ($moderate) {
        if (!current_user_can('wppa_moderate')) {
            wp_die(__('You do not have the rights to do this', 'wp-photo-album-plus'));
        }
        if ($photo) {
            $count = '1';
            $photos = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . WPPA_PHOTOS . '` WHERE `id` = %s', $photo), ARRAY_A);
            $link = '';
        } else {
            // Photos with pending comments?
            $cmt = $wpdb->get_results("SELECT `photo` FROM `" . WPPA_COMMENTS . "` WHERE `status` = 'pending'", ARRAY_A);
            if ($cmt) {
                $orphotois = '';
                foreach ($cmt as $c) {
                    $orphotois .= "OR `id` = " . $c['photo'] . " ";
                }
            } else {
                $orphotois = '';
            }
            $count = $wpdb->get_var($wpdb->prepare('SELECT COUNT(*) FROM `' . WPPA_PHOTOS . '` WHERE `status` = %s ' . $orphotois, 'pending'));
            $photos = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . WPPA_PHOTOS . '` WHERE `status` = %s ' . $orphotois . ' ORDER BY `timestamp` DESC' . $limit, 'pending'), ARRAY_A);
            $link = wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_moderate_photos');
        }
        if (empty($photos)) {
            if ($photo) {
                echo '<p>' . __('This photo is no longer awaiting moderation.', 'wp-photo-album-plus') . '</p>';
            } else {
                echo '<p>' . __('There are no photos awaiting moderation at this time.', 'wp-photo-album-plus') . '</p>';
            }
            if (current_user_can('administrator')) {
                echo '<h3>' . __('Manage all photos by timestamp', 'wp-photo-album-plus') . '</h3>';
                $count = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_PHOTOS . "`");
                $photos = $wpdb->get_results("SELECT * FROM `" . WPPA_PHOTOS . "` ORDER BY `timestamp` DESC" . $limit, ARRAY_A);
                $link = wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_moderate_photos');
            } else {
                return;
            }
        }
    } else {
        wppa_dbg_msg('Missing required argument in wppa_album_photos() 1', 'red', 'force');
    }
    if ($link && isset($_REQUEST['quick'])) {
        $link .= '&quick';
    }
    wppa_show_search_statistics();
    if (empty($photos)) {
        if ($photo) {
            echo '<div id="photoitem-' . $photo . '" class="photoitem" style="width: 99%; background-color: rgb( 255, 255, 224 ); border-color: rgb( 230, 219, 85 );">
						<span style="color:red">' . sprintf(__('Photo %s has been removed.', 'wp-photo-album-plus'), $photo) . '</span>
					</div>';
        } else {
            if (isset($_REQUEST['wppa-searchstring'])) {
                echo '<h3>' . __('No photos matching your search criteria.', 'wp-photo-album-plus') . '</h3>';
            } else {
                echo '<h3>' . __('No photos yet in this album.', 'wp-photo-album-plus') . '</h3>';
            }
        }
    } else {
        $wms = array('toplft' => __('top - left', 'wp-photo-album-plus'), 'topcen' => __('top - center', 'wp-photo-album-plus'), 'toprht' => __('top - right', 'wp-photo-album-plus'), 'cenlft' => __('center - left', 'wp-photo-album-plus'), 'cencen' => __('center - center', 'wp-photo-album-plus'), 'cenrht' => __('center - right', 'wp-photo-album-plus'), 'botlft' => __('bottom - left', 'wp-photo-album-plus'), 'botcen' => __('bottom - center', 'wp-photo-album-plus'), 'botrht' => __('bottom - right', 'wp-photo-album-plus'));
        $temp = wppa_get_water_file_and_pos('0');
        $wmfile = isset($temp['select']) ? $temp['select'] : '';
        $wmpos = isset($temp['pos']) && isset($wms[$temp['pos']]) ? $wms[$temp['pos']] : '';
        wppa_admin_page_links($page, $pagesize, $count, $link);
        foreach ($photos as $photo) {
            $is_multi = wppa_is_multi($photo['id']);
            $is_video = wppa_is_video($photo['id']);
            $has_audio = wppa_has_audio($photo['id']);
            ?>
			<a id="photo_<?php 
            echo $photo['id'];
            ?>
" name="photo_<?php 
            echo $photo['id'];
            ?>
"></a>
			<div class="widefat wppa-table-wrap" id="photoitem-<?php 
            echo $photo['id'];
            ?>
" style="width:99%; position: relative;" >

				<!-- Left half starts here -->
				<div style="width:49.5%; float:left; border-right:1px solid #ccc; margin-right:0;">
					<input type="hidden" id="photo-nonce-<?php 
            echo $photo['id'];
            ?>
" value="<?php 
            echo wp_create_nonce('wppa_nonce_' . $photo['id']);
            ?>
" />
					<table class="wppa-table wppa-photo-table" style="width:98%" >
						<tbody>

							<!-- Preview -->
							<tr>
								<th>
									<label ><?php 
            echo 'ID = ' . $photo['id'] . '. ' . __('Preview:', 'wp-photo-album-plus');
            ?>
</label>
									<br />
									<?php 
            echo sprintf(__('Album: %d<br />(%s)', 'wp-photo-album-plus'), $photo['album'], wppa_get_album_name($photo['album']));
            ?>
									<br /><br />
									<?php 
            if (!$is_video) {
                ?>
										<?php 
                _e('Rotate', 'wp-photo-album-plus');
                ?>
										<a onclick="if ( confirm( '<?php 
                _e('Are you sure you want to rotate this photo left?', 'wp-photo-album-plus');
                ?>
' ) ) wppaAjaxUpdatePhoto( <?php 
                echo $photo['id'];
                ?>
, 'rotleft', 0, <?php 
                echo wppa('front_edit') ? 'false' : 'true';
                ?>
 ); " ><?php 
                _e('left', 'wp-photo-album-plus');
                ?>
</a>

										<a onclick="if ( confirm( '<?php 
                _e('Are you sure you want to rotate this photo 180&deg;?', 'wp-photo-album-plus');
                ?>
' ) ) wppaAjaxUpdatePhoto( <?php 
                echo $photo['id'];
                ?>
, 'rot180', 0, <?php 
                echo wppa('front_edit') ? 'false' : 'true';
                ?>
 ); " ><?php 
                _e('180&deg;', 'wp-photo-album-plus');
                ?>
</a>

										<a onclick="if ( confirm( '<?php 
                _e('Are you sure you want to rotate this photo right?', 'wp-photo-album-plus');
                ?>
' ) ) wppaAjaxUpdatePhoto( <?php 
                echo $photo['id'];
                ?>
, 'rotright', 0, <?php 
                echo wppa('front_edit') ? 'false' : 'true';
                ?>
 ); " ><?php 
                _e('right', 'wp-photo-album-plus');
                ?>
</a>
										<br />

										<span style="font-size: 9px; line-height: 10px; color:#666;">
											<?php 
                if (wppa('front_edit')) {
                    _e('If it says \'Photo rotated\', the photo is rotated.', 'wp-photo-album-plus');
                } else {
                    $refresh = '<a onclick="wppaReload()" >' . __('Refresh', 'wp-photo-album-plus') . '</a>';
                    echo sprintf(__('If it says \'Photo rotated\', the photo is rotated. %s the page.', 'wp-photo-album-plus'), $refresh);
                }
                ?>
										</span>
									<?php 
            }
            ?>
								</th>
								<td>
									<?php 
            $src = wppa_get_thumb_url($photo['id']);
            $big = wppa_get_photo_url($photo['id']);
            if ($is_video) {
                reset($is_video);
                $big = str_replace('xxx', current($is_video), $big);
                ?>
										<a href="<?php 
                echo $big;
                ?>
" target="_blank" title="<?php 
                _e('Preview fullsize video', 'wp-photo-album-plus');
                ?>
" >
											<?php 
                echo wppa_get_video_html(array('id' => $photo['id'], 'width' => '160', 'height' => '160' * wppa_get_videoy($photo['id']) / wppa_get_videox($photo['id']), 'controls' => false, 'use_thumb' => true));
                ?>
										</a><?php 
            } else {
                if ($has_audio) {
                    $big = wppa_fix_poster_ext($big, $photo['id']);
                    $src = wppa_fix_poster_ext($src, $photo['id']);
                }
                ?>
										<a href="<?php 
                echo $big;
                ?>
" target="_blank" title="<?php 
                _e('Preview fullsize photo', 'wp-photo-album-plus');
                ?>
" >
											<img src="<?php 
                echo $src;
                ?>
" alt="<?php 
                echo $photo['name'];
                ?>
" style="max-width: 160px; vertical-align:middle;" />
										</a><?php 
                if ($has_audio) {
                    $audio = wppa_get_audio_html(array('id' => $photo['id'], 'width' => '160', 'controls' => true));
                    ?>
											<br />
											<?php 
                    if ($audio) {
                        echo $audio;
                    } else {
                        echo '<span style="color:red;">' . __('Audio disabled', 'wp-photo-album-plus') . '</span>';
                    }
                }
            }
            ?>
								</td>
							</tr>

							<!-- Upload -->
							<tr>
								<th  >
									<label><?php 
            _e('Upload:', 'wp-photo-album-plus');
            ?>
</label>
								</th>
								<td>
									<?php 
            $timestamp = $photo['timestamp'];
            if ($timestamp) {
                echo wppa_local_date(get_option('date_format', "F j, Y,") . ' ' . get_option('time_format', "g:i a"), $timestamp) . ' ' . __('local time', 'wp-photo-album-plus') . ' ';
            }
            if ($photo['owner']) {
                if (wppa_switch('photo_owner_change') && wppa_user_is('administrator')) {
                    echo '</td></tr><tr><th><label>' . __('Owned by:', 'wp-photo-album-plus') . '</label></th><td>';
                    echo '<input type="text" onkeyup="wppaAjaxUpdatePhoto( \'' . $photo['id'] . '\', \'owner\', this )" onchange="wppaAjaxUpdatePhoto( \'' . $photo['id'] . '\', \'owner\', this )" value="' . $photo['owner'] . '" />';
                } else {
                    echo __('By:', 'wp-photo-album-plus') . ' ' . $photo['owner'];
                }
            }
            ?>
								</td>
							</tr>

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

							<!-- EXIF Date -->
							<tr>
								<th>
									<label><?php 
            _e('EXIF Date', 'wp-photo-album-plus');
            ?>
</label>
								</th>
								<td>
								<?php 
            if (wppa_user_is('administrator')) {
                echo '<input type="text" onkeyup="wppaAjaxUpdatePhoto( \'' . $photo['id'] . '\', \'exifdtm\', this )" onchange="wppaAjaxUpdatePhoto( \'' . $photo['id'] . '\', \'exifdtm\', this )" value="' . $photo['exifdtm'] . '" />';
            } else {
                echo $photo['exifdtm'];
            }
            ?>
								</td>
							</tr>

							<!-- Rating -->
							<tr  >
								<th  >
									<label><?php 
            _e('Rating:', 'wp-photo-album-plus');
            ?>
</label>
								</th>
								<td class="wppa-rating" >
									<?php 
            $entries = wppa_get_rating_count_by_id($photo['id']);
            if ($entries) {
                echo __('Entries:', 'wp-photo-album-plus') . ' ' . $entries . '. ' . __('Mean value:', 'wp-photo-album-plus') . ' ' . wppa_get_rating_by_id($photo['id'], 'nolabel') . '.';
            } else {
                _e('No ratings for this photo.', 'wp-photo-album-plus');
            }
            $dislikes = wppa_dislike_get($photo['id']);
            if ($dislikes) {
                echo ' <span style="color:red" >' . sprintf(__('Disliked by %d visitors', 'wp-photo-album-plus'), $dislikes) . '</span>';
            }
            $pending = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_RATING . "` WHERE `photo` = %s AND `status` = 'pending'", $photo['id']));
            if ($pending) {
                echo ' <span style="color:orange" >' . sprintf(__('%d pending votes.', 'wp-photo-album-plus'), $pending) . '</span>';
            }
            ?>

								</td>
							</tr>

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

							<!-- P_order -->
							<?php 
            if (!wppa_switch('porder_restricted') || current_user_can('administrator')) {
                ?>
							<tr  >
								<th  >
									<label><?php 
                _e('Photo sort order #:', 'wp-photo-album-plus');
                ?>
</label>
								</th>
								<td >
									<input type="text" id="porder-<?php 
                echo $photo['id'];
                ?>
" value="<?php 
                echo $photo['p_order'];
                ?>
" style="width: 50px" onkeyup="wppaAjaxUpdatePhoto( <?php 
                echo $photo['id'];
                ?>
, 'p_order', this )" onchange="wppaAjaxUpdatePhoto( <?php 
                echo $photo['id'];
                ?>
, 'p_order', this )" />
								</td>
							</tr>
							<?php 
            }
            ?>

							<?php 
            if (!isset($_REQUEST['quick'])) {
                ?>
								<?php 
                if (!isset($album_select[$photo['album']])) {
                    $album_select[$photo['album']] = wppa_album_select_a(array('checkaccess' => true, 'path' => wppa_switch('hier_albsel'), 'exclude' => $photo['album'], 'selected' => '0', 'addpleaseselect' => true));
                }
                ?>
								<!-- Move -->
								<tr  >
									<th  >
										<input type="button" style="" onclick="if( document.getElementById( 'moveto-<?php 
                echo $photo['id'];
                ?>
' ).value != 0 ) { if ( confirm( '<?php 
                _e('Are you sure you want to move this photo?', 'wp-photo-album-plus');
                ?>
' ) ) wppaAjaxUpdatePhoto( <?php 
                echo $photo['id'];
                ?>
, 'moveto', document.getElementById( 'moveto-<?php 
                echo $photo['id'];
                ?>
' ) ) } else { alert( '<?php 
                _e('Please select an album to move the photo to first.', 'wp-photo-album-plus');
                ?>
' ); return false;}" value="<?php 
                echo esc_attr(__('Move photo to', 'wp-photo-album-plus'));
                ?>
" />
									</th>
									<td >
										<select id="moveto-<?php 
                echo $photo['id'];
                ?>
" style="width:100%;" ><?php 
                echo $album_select[$photo['album']];
                ?>
</select>
									</td>
								</tr>
								<!-- Copy -->
								<tr  >
									<th  >
										<input type="button" style="" onclick="if ( document.getElementById( 'copyto-<?php 
                echo $photo['id'];
                ?>
' ).value != 0 ) { if ( confirm( '<?php 
                _e('Are you sure you want to copy this photo?', 'wp-photo-album-plus');
                ?>
' ) ) wppaAjaxUpdatePhoto( <?php 
                echo $photo['id'];
                ?>
, 'copyto', document.getElementById( 'copyto-<?php 
                echo $photo['id'];
                ?>
' ) ) } else { alert( '<?php 
                _e('Please select an album to copy the photo to first.', 'wp-photo-album-plus');
                ?>
' ); return false;}" value="<?php 
                echo esc_attr(__('Copy photo to', 'wp-photo-album-plus'));
                ?>
" />
									</th>
									<td >
										<select id="copyto-<?php 
                echo $photo['id'];
                ?>
" style="width:100%;" ><?php 
                echo $album_select[$photo['album']];
                ?>
</select>
									</td>
								</tr>
							<?php 
            }
            ?>

							<!-- Delete -->
							<?php 
            if (!wppa('front_edit')) {
                ?>
							<tr  >
								<th  style="padding-top:0; padding-bottom:4px;">
									<input type="button" style="color:red;" onclick="if ( confirm( '<?php 
                _e('Are you sure you want to delete this photo?', 'wp-photo-album-plus');
                ?>
' ) ) wppaAjaxDeletePhoto( <?php 
                echo $photo['id'];
                ?>
 )" value="<?php 
                echo esc_attr(__('Delete photo', 'wp-photo-album-plus'));
                ?>
" />
								</th>
							</tr>
							<?php 
            }
            ?>

							<!-- Auto Page -->
							<?php 
            if (wppa_switch('auto_page') && (current_user_can('edit_posts') || current_user_can('edit_pages'))) {
                ?>
							<tr style=="vertical-align:bottom;" >
								<th  style="padding-top:0; padding-bottom:4px;">
									<label>
										<?php 
                _e('Autopage Permalink:', 'wp-photo-album-plus');
                ?>
									</label>
								</th>
								<td >
									<?php 
                echo get_permalink(wppa_get_the_auto_page($photo['id']));
                ?>
								</td>
							</tr>
							<?php 
            }
            ?>

							<!-- Link url -->
							<?php 
            if (!wppa_switch('link_is_restricted') || current_user_can('administrator')) {
                ?>
								<tr  >
									<th  >
										<label><?php 
                _e('Link url:', 'wp-photo-album-plus');
                ?>
</label>
									</th>
									<td >
										<input type="text" style="width:60%;" onkeyup="wppaAjaxUpdatePhoto( <?php 
                echo $photo['id'];
                ?>
, 'linkurl', this )" onchange="wppaAjaxUpdatePhoto( <?php 
                echo $photo['id'];
                ?>
, 'linkurl', this )" value="<?php 
                echo stripslashes($photo['linkurl']);
                ?>
" />
										<select style="float:right;" onchange="wppaAjaxUpdatePhoto( <?php 
                echo $photo['id'];
                ?>
, 'linktarget', this )" >
											<option value="_self" <?php 
                if ($photo['linktarget'] == '_self') {
                    echo 'selected="selected"';
                }
                ?>
><?php 
                _e('Same tab', 'wp-photo-album-plus');
                ?>
</option>
											<option value="_blank" <?php 
                if ($photo['linktarget'] == '_blank') {
                    echo 'selected="selected"';
                }
                ?>
><?php 
                _e('New tab', 'wp-photo-album-plus');
                ?>
</option>
										</select>
									</td>
								</tr>

								<!-- Link title -->
								<tr  >
									<th  >
										<label><?php 
                _e('Link title:', 'wp-photo-album-plus');
                ?>
</label>
									</th>
									<td >
										<input type="text" style="width:97%;" onkeyup="wppaAjaxUpdatePhoto( <?php 
                echo $photo['id'];
                ?>
, 'linktitle', this )" onchange="wppaAjaxUpdatePhoto( <?php 
                echo $photo['id'];
                ?>
, 'linktitle', this )" value="<?php 
                echo stripslashes($photo['linktitle']);
                ?>
" />
									</td>
								</tr>
								<?php 
                if (current_user_can('wppa_settings')) {
                    ?>
								<tr style="padding-left:10px; font-size:9px; line-height:10px; color:#666;" >
									<td colspan="2" style="padding-top:0" >
										<?php 
                    _e('If you want this link to be used, check \'PS Overrule\' checkbox in table VI.', 'wp-photo-album-plus');
                    ?>
									</td>
								</tr>
								<?php 
                }
                ?>
							<?php 
            }
            ?>

							<!-- Alt custom field -->
							<?php 
            if (wppa_opt('alt_type') == 'custom') {
                ?>
							<tr  >
								<th  >
									<label><?php 
                _e('HTML Alt attribute:', 'wp-photo-album-plus');
                ?>
</label>
								</th>
								<td >
									<input type="text" style="width:100%;" onkeyup="wppaAjaxUpdatePhoto( <?php 
                echo $photo['id'];
                ?>
, 'alt', this )" onchange="wppaAjaxUpdatePhoto( <?php 
                echo $photo['id'];
                ?>
, 'alt', this )" value="<?php 
                echo stripslashes($photo['alt']);
                ?>
" />
								</td>
							</tr>
							<?php 
            }
            ?>

						</tbody>
					</table>
				</div>

				<!-- Right half starts here -->
				<div style="width:50%; float:left; border-left:1px solid #ccc; margin-left:-1px;">
					<table class="wppa-table wppa-photo-table" >
						<tbody>

							<!-- Filename -->
							<tr>
								<th>
									<label><?php 
            _e('Filename:', 'wp-photo-album-plus');
            ?>
</label>
								</th>
								<td>
									<?php 
            echo $photo['filename'];
            if (wppa_user_is('administrator') || !wppa_switch('reup_is_restricted')) {
                ?>
										<input type="button" onclick="jQuery( '#re-up-<?php 
                echo $photo['id'];
                ?>
' ).css( 'display', '' );" value="<?php 
                _e('Update file', 'wp-photo-album-plus');
                ?>
" />
									<?php 
            }
            ?>
								</td>
							</tr>
							<?php 
            if (wppa_user_is('administrator') || !wppa_switch('reup_is_restricted')) {
                ?>
							<tr id="re-up-<?php 
                echo $photo['id'];
                ?>
" style="display:none" >
								<th>
								</th>
								<td>
									<form id="wppa-re-up-form-<?php 
                echo $photo['id'];
                ?>
" onsubmit="wppaReUpload( event,<?php 
                echo $photo['id'];
                ?>
, '<?php 
                echo $photo['filename'];
                ?>
' )" >
										<input type="file" id="wppa-re-up-file-<?php 
                echo $photo['id'];
                ?>
" />
										<input type="submit" id="wppa-re-up-butn-<?php 
                echo $photo['id'];
                ?>
" value="<?php 
                _e('Upload', 'wp-photo-album-plus');
                ?>
" />
									</form>
								</td>
							</tr>
							<?php 
            }
            ?>

							<!--- Video sizes -->
							<?php 
            if ($is_video) {
                ?>
							<tr>
								<th>
									<label><?php 
                _e('Video size:', 'wp-photo-album-plus');
                ?>
								</th>
								<td>
									<table class="wppa-subtable" >
										<tr>
											<td>
												<?php 
                _e('Width:', 'wp-photo-album-plus');
                ?>
											</td>
											<td>
												<input style="width:50px;margin:0 4px;" onkeyup="wppaAjaxUpdatePhoto( <?php 
                echo $photo['id'];
                ?>
, 'videox', this ); " onchange="wppaAjaxUpdatePhoto( <?php 
                echo $photo['id'];
                ?>
, 'videox', this ); " value="<?php 
                echo $photo['videox'];
                ?>
" /><?php 
                echo sprintf(__('pix, (0=default:%s)', 'wp-photo-album-plus'), wppa_opt('video_width'));
                ?>
											</td>
										</tr>
										<tr>
											<td>
												<?php 
                _e('Height:', 'wp-photo-album-plus');
                ?>
											</td>
											<td>
												<input style="width:50px;margin:0 4px;" onkeyup="wppaAjaxUpdatePhoto( <?php 
                echo $photo['id'];
                ?>
, 'videoy', this ); " onchange="wppaAjaxUpdatePhoto( <?php 
                echo $photo['id'];
                ?>
, 'videoy', this ); " value="<?php 
                echo $photo['videoy'];
                ?>
" /><?php 
                echo sprintf(__('pix, (0=default:%s)', 'wp-photo-album-plus'), wppa_opt('video_height'));
                ?>
											</td>
										</tr>
									</table>
								</td>
							</tr>
							<tr>
								<th>
									<label><?php 
                _e('Formats:', 'wp-photo-album-plus');
                ?>
								</th>
								<td>
									<table class="wppa-subtable" >
										<?php 
                foreach ($is_video as $fmt) {
                    echo '<tr>' . '<td>' . $fmt . '</td>' . '<td>' . __('Filesize:', 'wp-photo-album-plus') . '</td>' . '<td>' . wppa_get_filesize(str_replace('xxx', $fmt, wppa_get_photo_path($photo['id']))) . '</td>' . '</tr>';
                }
                ?>
									</table>
								</td>
							</tr>
							<?php 
            }
            ?>

							<!-- Audio -->
							<?php 
            if ($has_audio) {
                ?>
							<tr>
								<th>
									<label><?php 
                _e('Formats:', 'wp-photo-album-plus');
                ?>
								</th>
								<td>
									<table class="wppa-subtable" >
										<?php 
                foreach ($has_audio as $fmt) {
                    echo '<tr>' . '<td>' . $fmt . '</td>' . '<td>' . __('Filesize:', 'wp-photo-album-plus') . '</td>' . '<td>' . wppa_get_filesize(str_replace('xxx', $fmt, wppa_get_photo_path($photo['id']))) . '</td>' . '</tr>';
                }
                ?>
									</table>
								</td>
							</tr>
							<?php 
            }
            ?>

							<!-- Filesizes -->
							<tr>
								<th>
									<label><?php 
            $is_video || $has_audio ? _e('Poster:', 'wp-photo-album-plus') : _e('Photo sizes:', 'wp-photo-album-plus');
            ?>
</label>
								</th>
								<td>
									<table class="wppa-subtable" >
										<tr>
											<td>
												<?php 
            _e('Source file:', 'wp-photo-album-plus');
            ?>
											</td>
												<?php 
            $sp = wppa_get_source_path($photo['id']);
            if (is_file($sp)) {
                $ima = getimagesize($sp);
                ?>

											<td>
												<?php 
                echo $ima['0'] . ' x ' . $ima['1'] . ' px.';
                ?>
											</td>
											<td>
												<?php 
                echo wppa_get_filesize($sp);
                ?>
											</td>
											<td>
												<a style="cursor:pointer; font-weight:bold;" title="<?php 
                _e('Remake display file and thumbnail file', 'wp-photo-album-plus');
                ?>
" onclick="wppaAjaxUpdatePhoto( <?php 
                echo $photo['id'];
                ?>
, 'remake', this )"><?php 
                _e('Remake files', 'wp-photo-album-plus');
                ?>
</a>
											</td>
								<?php 
            } else {
                ?>
											<td>
												<span style="color:orange;"><?php 
                _e('Unavailable', 'wp-photo-album-plus');
                ?>
</span>
											</td>
											<td>
											</td>
											<td>
											</td>
								<?php 
            }
            ?>
										</tr>
										<tr>
											<td>
												<?php 
            _e('Display file:', 'wp-photo-album-plus');
            ?>
											</td>
												<?php 
            $dp = wppa_fix_poster_ext(wppa_get_photo_path($photo['id']), $photo['id']);
            if (is_file($dp)) {
                ?>
											<td>
												<?php 
                echo floor(wppa_get_photox($photo['id'])) . ' x ' . floor(wppa_get_photoy($photo['id'])) . ' px.';
                ?>
											</td>
											<td>
												<?php 
                echo wppa_get_filesize($dp);
                ?>
											</td>
											<td>
											</td>
												<?php 
            } else {
                ?>
											<td>
												<span style="color:red;"><?php 
                _e('Unavailable', 'wp-photo-album-plus');
                ?>
</span>
											</td>
											<td>
											</td>
											<td>
											</td>
												<?php 
            }
            ?>
										</tr>
										<tr>
											<td>
												<?php 
            _e('Thumbnail file:', 'wp-photo-album-plus');
            ?>
											</td>
												<?php 
            $tp = wppa_fix_poster_ext(wppa_get_thumb_path($photo['id']), $photo['id']);
            if (is_file($tp)) {
                ?>
											<td>
												<?php 
                echo floor(wppa_get_thumbx($photo['id'])) . ' x ' . floor(wppa_get_thumby($photo['id'])) . ' px.';
                ?>
											</td>
											<td>
												<?php 
                echo wppa_get_filesize($tp);
                ?>
											</td>
												<?php 
            } else {
                ?>
											<td>
												<span style="color:red;"><?php 
                _e('Unavailable', 'wp-photo-album-plus');
                ?>
</span>
											</td>
											<td>
											</td>
												<?php 
            }
            ?>
											<td>
												<a style="cursor:pointer; font-weight:bold;" title="<?php 
            _e('Remake thumbnail file', 'wp-photo-album-plus');
            ?>
" onclick="wppaAjaxUpdatePhoto( <?php 
            echo $photo['id'];
            ?>
, 'remakethumb', this )"><?php 
            _e('Remake', 'wp-photo-album-plus');
            ?>
</a>
											</td>
										</tr>
									</table>
								</td>
							</tr>

							<!-- Stereo -->
							<?php 
            if (wppa_switch('enable_stereo')) {
                ?>
							<tr>
								<th>
									<label><?php 
                _e('Stereophoto:', 'wp-photo-album-plus');
                ?>
</label>
								</th>
								<td>
									<select id="stereo-<?php 
                echo $photo['id'];
                ?>
" onchange="wppaAjaxUpdatePhoto( <?php 
                echo $photo['id'];
                ?>
, 'stereo', this )" >
										<option value="0" <?php 
                if ($photo['stereo'] == '0') {
                    echo 'selected="selected" ';
                }
                ?>
><?php 
                _e('no stereo image or ready anaglyph', 'wp-photo-album-plus');
                ?>
</option>
										<option value="1" <?php 
                if ($photo['stereo'] == '1') {
                    echo 'selected="selected" ';
                }
                ?>
><?php 
                _e('Left - right stereo image', 'wp-photo-album-plus');
                ?>
</option>
										<option value="-1" <?php 
                if ($photo['stereo'] == '-1') {
                    echo 'selected="selected" ';
                }
                ?>
><?php 
                _e('Right - left stereo image', 'wp-photo-album-plus');
                ?>
</option>
									<select>
								<td>
							</tr>
							<tr>
								<th>
									<label><?php 
                _e('Images:', 'wp-photo-album-plus');
                ?>
</label>
								</th>
								<td>
									<?php 
                $files = glob(WPPA_UPLOAD_PATH . '/stereo/' . $photo['id'] . '-*.*');
                if (!empty($files)) {
                    sort($files);
                    $c = 0;
                    echo '<table><tbody>';
                    foreach ($files as $file) {
                        if (!$c) {
                            echo '<tr>';
                        }
                        if (is_file($file)) {
                            echo '<td style="padding:0;" ><a href="' . str_replace(WPPA_UPLOAD_PATH, WPPA_UPLOAD_URL, $file) . '" target="_blank" >' . basename($file) . '</a></td>';
                        }
                        if (strpos(basename($file), '_flat')) {
                            $c++;
                        }
                        $c = ($c + 1) % 2;
                        if (!$c) {
                            echo '</tr>';
                        }
                    }
                    if ($c) {
                        echo '<td style="padding:0;" ></td></tr>';
                    }
                    echo '</tbody></table>';
                }
                ?>
								</td>
							</tr>
							<?php 
            }
            ?>

							<!-- Location -->
							<?php 
            if ($photo['location'] || wppa_switch('geo_edit')) {
                ?>
							<tr>
								<th>
									<label><?php 
                _e('Location:', 'wp-photo-album-plus');
                ?>
</label>
								</th>
								<td>
									<?php 
                $loc = $photo['location'] ? $photo['location'] : '///';
                $geo = explode('/', $loc);
                echo $geo['0'] . ' ' . $geo['1'] . ' ';
                if (wppa_switch('geo_edit')) {
                    ?>
										<?php 
                    _e('Lat:', 'wp-photo-album-plus');
                    ?>
<input type="text" style="width:100px;" id="lat-<?php 
                    echo $photo['id'];
                    ?>
" onkeyup="wppaAjaxUpdatePhoto( <?php 
                    echo $photo['id'];
                    ?>
, 'lat', this );" onchange="wppaAjaxUpdatePhoto( <?php 
                    echo $photo['id'];
                    ?>
, 'lat', this );" value="<?php 
                    echo $geo['2'];
                    ?>
" />
										<?php 
                    _e('Lon:', 'wp-photo-album-plus');
                    ?>
<input type="text" style="width:100px;" id="lon-<?php 
                    echo $photo['id'];
                    ?>
" onkeyup="wppaAjaxUpdatePhoto( <?php 
                    echo $photo['id'];
                    ?>
, 'lon', this );" onchange="wppaAjaxUpdatePhoto( <?php 
                    echo $photo['id'];
                    ?>
, 'lon', this );" value="<?php 
                    echo $geo['3'];
                    ?>
" />
										<?php 
                    if (!wppa('front_edit')) {
                        ?>
											<span class="description"><br /><?php 
                        _e('Refresh the page after changing to see the degrees being updated', 'wp-photo-album-plus');
                        ?>
</span>
										<?php 
                    }
                    ?>
									<?php 
                }
                ?>
								</td>
							</tr>
							<?php 
            }
            ?>

							<!-- Name -->
							<tr  >
								<th  >
									<label><?php 
            _e('Photoname:', 'wp-photo-album-plus');
            ?>
</label>
								</th>
								<?php 
            if (wppa_switch('use_wp_editor')) {
                ?>
								<td>
									<input type="text" style="width:100%;" id="pname-<?php 
                echo $photo['id'];
                ?>
" value="<?php 
                echo esc_attr(stripslashes($photo['name']));
                ?>
" />

									<input type="button" class="button-secundary" value="<?php 
                _e('Update Photo name', 'wp-photo-album-plus');
                ?>
" onclick="wppaAjaxUpdatePhoto( <?php 
                echo $photo['id'];
                ?>
, 'name', document.getElementById( 'pname-<?php 
                echo $photo['id'];
                ?>
' ) );" />
								</td>
								<?php 
            } else {
                ?>
									<td>
										<input type="text" style="width:100%;" id="pname-<?php 
                echo $photo['id'];
                ?>
" onkeyup="wppaAjaxUpdatePhoto( <?php 
                echo $photo['id'];
                ?>
, 'name', this );" onchange="wppaAjaxUpdatePhoto( <?php 
                echo $photo['id'];
                ?>
, 'name', this );" value="<?php 
                echo esc_attr(stripslashes($photo['name']));
                ?>
" />
									</td>
								<?php 
            }
            ?>
							</tr>

							<!-- Description -->
							<?php 
            if (!wppa_switch('desc_is_restricted') || wppa_user_is('administrator')) {
                ?>
							<tr>
								<th>
									<label><?php 
                _e('Description:', 'wp-photo-album-plus');
                ?>
</label>
								</th>
								<?php 
                if (wppa_switch('use_wp_editor')) {
                    ?>
								<td>

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

									<input
										type="button" class="button-secundary" value="<?php 
                    _e('Update Photo description', 'wp-photo-album-plus');
                    ?>
" onclick="wppaAjaxUpdatePhoto( <?php 
                    echo $photo['id'];
                    ?>
, 'description', document.getElementById( 'wppaphotodesc'+'<?php 
                    echo $alfaid;
                    ?>
' ), false, '<?php 
                    echo $alfaid;
                    ?>
' )" />
									<img id="wppa-photo-spin-<?php 
                    echo $photo['id'];
                    ?>
" src="<?php 
                    echo wppa_get_imgdir() . 'wpspin.gif';
                    ?>
" style="visibility:hidden" />
								</td>
								<?php 
                } else {
                    ?>
								<td>
									<textarea style="width: 100%; height:120px;" onkeyup="wppaAjaxUpdatePhoto( <?php 
                    echo $photo['id'];
                    ?>
, 'description', this )" onchange="wppaAjaxUpdatePhoto( <?php 
                    echo $photo['id'];
                    ?>
, 'description', this )" ><?php 
                    echo stripslashes($photo['description']);
                    ?>
</textarea>
								</td>
								<?php 
                }
                ?>
							</tr>
							<?php 
            } else {
                ?>
							<tr>
								<th>
									<label><?php 
                _e('Description:', 'wp-photo-album-plus');
                ?>
</label>
								</th>
								<td>
									<div style="width: 100%; height:120px; overflow:auto;" ><?php 
                echo stripslashes($photo['description']);
                ?>
</div>
								</td>
							</tr>
							<?php 
            }
            ?>

							<!-- Custom -->
							<?php 
            if (wppa_switch('custom_fields')) {
                $custom = wppa_get_photo_item($photo['id'], 'custom');
                if ($custom) {
                    $custom_data = unserialize($custom);
                } else {
                    $custom_data = array('', '', '', '', '', '', '', '', '', '');
                }
                foreach (array_keys($custom_data) as $key) {
                    if (wppa_opt('custom_caption_' . $key)) {
                        ?>
												<tr>
													<th>
														<label><?php 
                        echo wppa_opt('custom_caption_' . $key) . ':<br /><small>(w#cc' . $key . ')</small>';
                        ?>
</label>
													</th>
													<td>
														<?php 
                        echo '<small>(w#cd' . $key . ')</small>';
                        ?>
														<input 	type="text"
																style="width:85%; float:right;"
																id="pname-<?php 
                        echo $photo['id'];
                        ?>
"
																onkeyup="wppaAjaxUpdatePhoto( <?php 
                        echo $photo['id'];
                        ?>
, 'custom_<?php 
                        echo $key;
                        ?>
', this );"
																onchange="wppaAjaxUpdatePhoto( <?php 
                        echo $photo['id'];
                        ?>
, 'custom_<?php 
                        echo $key;
                        ?>
', this );"
																value="<?php 
                        echo esc_attr(stripslashes($custom_data[$key]));
                        ?>
"
																/>

													</td>
												</tr>
											<?php 
                    }
                }
            }
            ?>
							<!-- Tags -->
							<tr style="vertical-align:middle;" >
								<th  >
									<label ><?php 
            _e('Tags:', 'wp-photo-album-plus');
            ?>
</label>
									<span class="description" >
										<br />&nbsp;
									</span>
								</th>
								<td >
									<input id="tags-<?php 
            echo $photo['id'];
            ?>
" type="text" style="width:100%;" onchange="wppaAjaxUpdatePhoto( <?php 
            echo $photo['id'];
            ?>
, 'tags', this )" value="<?php 
            echo stripslashes(trim($photo['tags'], ','));
            ?>
" />
									<span class="description" >
										<?php 
            _e('Separate tags with commas.', 'wp-photo-album-plus');
            ?>
&nbsp;
										<?php 
            _e('Examples:', 'wp-photo-album-plus');
            ?>
										<select onchange="wppaAddTag( this.value, 'tags-<?php 
            echo $photo['id'];
            ?>
' ); wppaAjaxUpdatePhoto( <?php 
            echo $photo['id'];
            ?>
, 'tags', document.getElementById( 'tags-<?php 
            echo $photo['id'];
            ?>
' ) )" >
											<?php 
            $taglist = wppa_get_taglist();
            if (is_array($taglist)) {
                echo '<option value="" >' . __('- select -', 'wp-photo-album-plus') . '</option>';
                foreach ($taglist as $tag) {
                    echo '<option value="' . $tag['tag'] . '" >' . $tag['tag'] . '</option>';
                }
            } else {
                echo '<option value="0" >' . __('No tags yet', 'wp-photo-album-plus') . '</option>';
            }
            ?>
										</select>
										<?php 
            _e('Select to add', 'wp-photo-album-plus');
            ?>
									</span>
								</td>
							</tr>

							<!-- Status -->
							<tr style="vertical-align:middle;" >
								<th>
									<label ><?php 
            _e('Status:', 'wp-photo-album-plus');
            ?>
</label>
								</th>
								<td>
								<?php 
            if ((current_user_can('wppa_admin') || current_user_can('wppa_moderate')) && !isset($_REQUEST['quick'])) {
                ?>
									<table>
										<tr>
											<td>
												<select id="status-<?php 
                echo $photo['id'];
                ?>
" onchange="wppaAjaxUpdatePhoto( <?php 
                echo $photo['id'];
                ?>
, 'status', this ); wppaPhotoStatusChange( <?php 
                echo $photo['id'];
                ?>
 ); ">
													<option value="pending" <?php 
                if ($photo['status'] == 'pending') {
                    echo 'selected="selected"';
                }
                ?>
 ><?php 
                _e('Pending', 'wp-photo-album-plus');
                ?>
</option>
													<option value="publish" <?php 
                if ($photo['status'] == 'publish') {
                    echo 'selected="selected"';
                }
                ?>
 ><?php 
                _e('Publish', 'wp-photo-album-plus');
                ?>
</option>
													<?php 
                if (wppa_switch('ext_status_restricted') && !wppa_user_is('administrator')) {
                    $dis = ' disabled';
                } else {
                    $dis = '';
                }
                ?>
													<option value="featured" <?php 
                if ($photo['status'] == 'featured') {
                    echo 'selected="selected"';
                }
                echo $dis;
                ?>
 ><?php 
                _e('Featured', 'wp-photo-album-plus');
                ?>
</option>
													<option value="gold" <?php 
                if ($photo['status'] == 'gold') {
                    echo 'selected="selected"';
                }
                echo $dis;
                ?>
 ><?php 
                _e('Gold', 'wp-photo-album-plus');
                ?>
</option>
													<option value="silver" <?php 
                if ($photo['status'] == 'silver') {
                    echo 'selected="selected"';
                }
                echo $dis;
                ?>
 ><?php 
                _e('Silver', 'wp-photo-album-plus');
                ?>
</option>
													<option value="bronze" <?php 
                if ($photo['status'] == 'bronze') {
                    echo 'selected="selected"';
                }
                echo $dis;
                ?>
 ><?php 
                _e('Bronze', 'wp-photo-album-plus');
                ?>
</option>
													<option value="scheduled" <?php 
                if ($photo['status'] == 'scheduled') {
                    echo 'selected="selected"';
                }
                echo $dis;
                ?>
 ><?php 
                _e('Scheduled', 'wp-photo-album-plus');
                ?>
</option>
													<option value="private" <?php 
                if ($photo['status'] == 'private') {
                    echo 'selected="selected"';
                }
                echo $dis;
                ?>
 ><?php 
                _e('Private', 'wp-photo-album-plus');
                ?>
</option>
												</select>
											</td>
											<td class="wppa-datetime-<?php 
                echo $photo['id'];
                ?>
" >
												<?php 
                echo wppa_get_date_time_select_html('photo', $photo['id'], true);
                ?>
											</td>
										</tr>
									</table>
								<?php 
            } else {
                ?>
										<input type="hidden" id="status-<?php 
                echo $photo['id'];
                ?>
" value="<?php 
                echo $photo['status'];
                ?>
" />
									<table>
										<tr>
											<td>
												<?php 
                if ($photo['status'] == 'pending') {
                    _e('Pending', 'wp-photo-album-plus');
                } elseif ($photo['status'] == 'publish') {
                    _e('Publish', 'wp-photo-album-plus');
                } elseif ($photo['status'] == 'featured') {
                    _e('Featured', 'wp-photo-album-plus');
                } elseif ($photo['status'] == 'gold') {
                    _e('Gold', 'wp-photo-album-plus');
                } elseif ($photo['status'] == 'silver') {
                    _e('Silver', 'wp-photo-album-plus');
                } elseif ($photo['status'] == 'bronze') {
                    _e('Bronze', 'wp-photo-album-plus');
                } elseif ($photo['status'] == 'scheduled') {
                    _e('Scheduled', 'wp-photo-album-plus');
                } elseif ($photo['status'] == 'private') {
                    _e('Private', 'wp-photo-album-plus');
                }
                ?>
											</td>
											<td class="wppa-datetime-<?php 
                echo $photo['id'];
                ?>
" >
												<?php 
                echo wppa_get_date_time_select_html('photo', $photo['id'], false);
                ?>
											</td>
										</tr>
									</table>
									<?php 
            }
            ?>
									<span id="psdesc-<?php 
            echo $photo['id'];
            ?>
" class="description" style="display:none;" ><?php 
            _e('Note: Featured photos should have a descriptive name; a name a search engine will look for!', 'wp-photo-album-plus');
            ?>
</span>

								</td>
							</tr>

							<!-- Watermark -->
							<?php 
            if (!$is_video || is_file(wppa_fix_poster_ext(wppa_get_photo_path($photo['id']), $photo['id']))) {
                ?>
								<tr style="vertical-align:middle;" >
									<th  >
										<label><?php 
                _e('Watermark:', 'wp-photo-album-plus');
                ?>
</label>
									</th>
									<td>
										<?php 
                $user = wppa_get_user();
                if (wppa_switch('watermark_on')) {
                    if (wppa_switch('watermark_user') || current_user_can('wppa_settings')) {
                        echo __('File:', 'wppa', 'wp-photo-album-plus') . ' ';
                        ?>
												<select id="wmfsel_<?php 
                        echo $photo['id'];
                        ?>
" onchange="wppaAjaxUpdatePhoto( <?php 
                        echo $photo['id'];
                        ?>
, 'wppa_watermark_file_<?php 
                        echo $user;
                        ?>
', this );" >
												<?php 
                        echo wppa_watermark_file_select();
                        ?>
												</select>
												<?php 
                        echo '<br />' . __('Pos:', 'wp-photo-album-plus') . ' ';
                        ?>
												<select id="wmpsel_<?php 
                        echo $photo['id'];
                        ?>
" onchange="wppaAjaxUpdatePhoto( <?php 
                        echo $photo['id'];
                        ?>
, 'wppa_watermark_pos_<?php 
                        echo $user;
                        ?>
', this );" >
												<?php 
                        echo wppa_watermark_pos_select();
                        ?>
												</select>
												<input type="button" class="button-secundary" value="<?php 
                        _e('Apply watermark', 'wp-photo-album-plus');
                        ?>
" onclick="if ( confirm( '<?php 
                        echo esc_js(__('Are you sure? Once applied it can not be removed!', 'wp-photo-album-plus')) . '\\n\\n' . esc_js(__('And I do not know if there is already a watermark on this photo', 'wp-photo-album-plus'));
                        ?>
' ) ) wppaAjaxApplyWatermark( <?php 
                        echo $photo['id'];
                        ?>
, document.getElementById( 'wmfsel_<?php 
                        echo $photo['id'];
                        ?>
' ).value, document.getElementById( 'wmpsel_<?php 
                        echo $photo['id'];
                        ?>
' ).value )" />
												<?php 
                    } else {
                        echo __('File:', 'wppa', 'wp-photo-album-plus') . ' ' . __($wmfile, 'wp-photo-album-plus');
                        if ($wmfile != '--- none ---') {
                            echo ' ' . __('Pos:', 'wp-photo-album-plus') . ' ' . $wmpos;
                        }
                    }
                    ?>
											<img id="wppa-water-spin-<?php 
                    echo $photo['id'];
                    ?>
" src="<?php 
                    echo wppa_get_imgdir() . 'wpspin.gif';
                    ?>
" style="visibility:hidden" /><?php 
                } else {
                    _e('Not configured', 'wp-photo-album-plus');
                }
                ?>
									</td>
								</tr>
							<?php 
            }
            ?>
							<!-- Remark -->
							<tr style="vertical-align: middle;" >
								<th >
									<label style="color:#070"><?php 
            _e('Remark:', 'wp-photo-album-plus');
            ?>
</label>
								</th>
								<td id="photostatus-<?php 
            echo $photo['id'];
            ?>
" style="padding-left:10px; width: 400px;">
									<?php 
            if (wppa_is_video($photo['id'])) {
                echo sprintf(__('Video %s is not modified yet', 'wp-photo-album-plus'), $photo['id']);
            } else {
                echo sprintf(__('Photo %s is not modified yet', 'wp-photo-album-plus'), $photo['id']);
            }
            ?>
								</td>
							</tr>

						</tbody>
					</table>
					<script type="text/javascript">wppaPhotoStatusChange( <?php 
            echo $photo['id'];
            ?>
 )</script>
				</div>

				<div style="clear:both;"></div>

				<?php 
            if (!isset($_REQUEST['quick'])) {
                ?>
				<div class="wppa-links" >
					<table style="width:100%" >
						<tbody>
							<?php 
                if (current_user_can('edit_posts') || current_user_can('edit_pages')) {
                    ?>
							<tr>
								<td><?php 
                    _e('Single image shortcode', 'wp-photo-album-plus');
                    ?>
:</td>
								<td><?php 
                    echo esc_js('[wppa type="photo" photo="' . $photo['id'] . '" size="' . wppa_opt('fullsize') . '"][/wppa]');
                    ?>
</td>
							</tr>
							<?php 
                }
                ?>
							<?php 
                if (is_file(wppa_get_source_path($photo['id']))) {
                    ?>
							<tr>
								<td><?php 
                    _e('Permalink', 'wp-photo-album-plus');
                    ?>
:</td>
								<td><?php 
                    echo wppa_get_source_pl($photo['id']);
                    ?>
</td>
							</tr>
							<?php 
                }
                ?>
							<tr>
								<td><?php 
                _e('Hi resolution url', 'wp-photo-album-plus');
                ?>
:</td>
								<td><?php 
                echo wppa_get_hires_url($photo['id']);
                ?>
</td>
							</tr>
							<?php 
                if (is_file(wppa_get_photo_path($photo['id']))) {
                    ?>
							<tr>
								<td><?php 
                    _e('Display file url', 'wp-photo-album-plus');
                    ?>
:</td>
								<td><?php 
                    echo wppa_get_lores_url($photo['id']);
                    ?>
</td>
							</tr>
							<?php 
                }
                ?>
							<?php 
                if (is_file(wppa_get_thumb_path($photo['id']))) {
                    ?>
							<tr>
								<td><?php 
                    _e('Thumbnail file url', 'wp-photo-album-plus');
                    ?>
:</td>
								<td><?php 
                    echo wppa_get_tnres_url($photo['id']);
                    ?>
</td>
							</tr>
							<?php 
                }
                ?>
						</tbody>
					</table>
				</div>
				<?php 
            }
            ?>

</div>
				<!-- Comments -->
				<?php 
            $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_COMMENTS . "` WHERE `photo` = %s ORDER BY `timestamp` DESC", $photo['id']), ARRAY_A);
            if ($comments) {
                ?>
				<div class="widefat" style="width:99%; font-size:11px;" >
					<table class="wppa-table widefat wppa-setting-table" >
						<thead>
							<tr style="font-weight:bold;" >
								<td style="padding:0 4px;" >#</td>
								<td style="padding:0 4px;" >User</td>
								<td style="padding:0 4px;" >Time since</td>
								<td style="padding:0 4px;" >Status</td>
								<td style="padding:0 4px;" >Comment</td>
							</tr>
						</thead>
						<tbody>
							<?php 
                foreach ($comments as $comment) {
                    echo '
							<tr>
								<td style="padding:0 4px;" >' . $comment['id'] . '</td>
								<td style="padding:0 4px;" >' . $comment['user'] . '</td>
								<td style="padding:0 4px;" >' . wppa_get_time_since($comment['timestamp']) . '</td>';
                    if (current_user_can('wppa_comments') || current_user_can('wppa_moderate') || wppa_get_user() == $photo['owner'] && wppa_switch('owner_moderate_comment')) {
                        $p = $comment['status'] == 'pending' ? 'selected="selected" ' : '';
                        $a = $comment['status'] == 'approved' ? 'selected="selected" ' : '';
                        $s = $comment['status'] == 'spam' ? 'selected="selected" ' : '';
                        $t = $comment['status'] == 'trash' ? 'selected="selected" ' : '';
                        echo '
										<td style="padding:0 4px;" >
											<select style="height: 20px; font-size: 11px; padding:0;" onchange="wppaAjaxUpdateCommentStatus( ' . $photo['id'] . ', ' . $comment['id'] . ', this.value )" >
												<option value="pending" ' . $p . '>' . __('Pending', 'wp-photo-album-plus') . '</option>
												<option value="approved" ' . $a . '>' . __('Approved', 'wp-photo-album-plus') . '</option>
												<option value="spam" ' . $s . '>' . __('Spam', 'wp-photo-album-plus') . '</option>
												<option value="trash" ' . $t . '>' . __('Trash', 'wp-photo-album-plus') . '</option>
											</select >
										</td>
									';
                    } else {
                        echo '<td style="padding:0 4px;" >';
                        if ($comment['status'] == 'pending') {
                            _e('Pending', 'wp-photo-album-plus');
                        } elseif ($comment['status'] == 'approved') {
                            _e('Approved', 'wp-photo-album-plus');
                        } elseif ($comment['status'] == 'spam') {
                            _e('Spam', 'wp-photo-album-plus');
                        } elseif ($comment['status'] == 'trash') {
                            _e('Trash', 'wp-photo-album-plus');
                        }
                        echo '</td>';
                    }
                    echo '<td style="padding:0 4px;" >' . $comment['comment'] . '</td>
							</tr>
							';
                }
                ?>
						</tbody>
					</table>
				</div>
			<?php 
            }
            ?>
		<!--	</div> -->
			<div style="clear:both;margin-top:7px;"></div>
<?php 
        }
        /* foreach photo */
        wppa_admin_page_links($page, $pagesize, $count, $link);
    }
    /* photos not empty */
}
function wppa_get_default_scheduledtm()
{
    $result = wppa_local_date('Y,m,d,H,i');
    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);
    // 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_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_album_photos($album = '', $photo = '', $owner = '', $moderate = false)
{
    global $wpdb;
    // Check input
    wppa_vfy_arg('wppa-page');
    $pagesize = wppa_opt('photo_admin_pagesize');
    $page = isset($_GET['wppa-page']) ? $_GET['wppa-page'] : '1';
    $skip = ($page - '1') * $pagesize;
    $limit = $pagesize < '1' ? '' : ' LIMIT ' . $skip . ',' . $pagesize;
    // Edit the photos in a specific album
    if ($album) {
        // Special album case: search (see last album line in album table)
        if ($album == 'search') {
            $count = wppa_get_edit_search_photos('', 'count_only');
            $photos = wppa_get_edit_search_photos($limit);
            $link = wppa_dbg_url(get_admin_url() . 'admin.php' . '?page=wppa_admin_menu' . '&tab=edit' . '&edit_id=' . $album . '&wppa-searchstring=' . wppa_sanitize_searchstring($_REQUEST['wppa-searchstring']));
        } else {
            $counts = wppa_treecount_a($album);
            $count = $counts['selfphotos'] + $counts['pendphotos'];
            $photos = $wpdb->get_results($wpdb->prepare("SELECT * " . "FROM `" . WPPA_PHOTOS . "` " . "WHERE `album` = %s " . wppa_get_photo_order($album, 'norandom') . $limit, $album), ARRAY_A);
            $link = wppa_dbg_url(get_admin_url() . 'admin.php' . '?page=wppa_admin_menu' . '&tab=edit' . '&edit_id=' . $album);
        }
    } elseif ($photo && !$moderate) {
        $count = '1';
        $photos = $wpdb->get_results($wpdb->prepare("SELECT * " . "FROM `" . WPPA_PHOTOS . "` " . "WHERE `id` = %s", $photo), ARRAY_A);
        $link = '';
    } elseif ($owner) {
        $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) " . "FROM `" . WPPA_PHOTOS . "` " . "WHERE `owner` = %s", $owner));
        $photos = $wpdb->get_results($wpdb->prepare("SELECT * " . "FROM `" . WPPA_PHOTOS . "` " . "WHERE `owner` = %s " . "ORDER BY `timestamp` DESC " . $limit, $owner), ARRAY_A);
        $link = wppa_dbg_url(get_admin_url() . 'admin.php' . '?page=wppa_edit_photo');
    } elseif ($moderate) {
        // Can i moderate?
        if (!current_user_can('wppa_moderate')) {
            wp_die(__('You do not have the rights to do this', 'wp-photo-album-plus'));
        }
        // Moderate a single photo
        if ($photo) {
            $count = '1';
            $photos = $wpdb->get_results($wpdb->prepare("SELECT * " . "FROM `" . WPPA_PHOTOS . "` " . "WHERE `id` = %s", $photo), ARRAY_A);
            $link = '';
        } else {
            $cmt = $wpdb->get_results("SELECT `photo` " . "FROM `" . WPPA_COMMENTS . "` " . "WHERE `status` = 'pending' " . "OR `status` = 'spam'", ARRAY_A);
            if ($cmt) {
                $orphotois = '';
                foreach ($cmt as $c) {
                    $orphotois .= "OR `id` = " . $c['photo'] . " ";
                }
            } else {
                $orphotois = '';
            }
            $count = $wpdb->get_var("SELECT COUNT(*) " . "FROM `" . WPPA_PHOTOS . "` " . "WHERE `status` = 'pending' " . $orphotois);
            $photos = $wpdb->get_results("SELECT * " . "FROM `" . WPPA_PHOTOS . "` " . "WHERE `status` = 'pending' " . $orphotois . " " . "ORDER BY `timestamp` DESC " . $limit, ARRAY_A);
            $link = wppa_dbg_url(get_admin_url() . 'admin.php' . '?page=wppa_moderate_photos');
        }
        // No photos to moderate
        if (empty($photos)) {
            // Single photo moderate requested
            if ($photo) {
                echo '<p>' . __('This photo is no longer awaiting moderation.', 'wp-photo-album-plus') . '</p>';
            } else {
                echo '<p>' . __('There are no photos awaiting moderation at this time.', 'wp-photo-album-plus') . '</p>';
            }
            // If i am admin, i can edit all photos here, sorted by timestamp desc
            if (wppa_user_is('administrator')) {
                echo '<h3>' . __('Manage all photos by timestamp', 'wp-photo-album-plus') . '</h3>';
                $count = $wpdb->get_var("SELECT COUNT(*) " . "FROM `" . WPPA_PHOTOS . "`");
                $photos = $wpdb->get_results("SELECT * " . "FROM `" . WPPA_PHOTOS . "` " . "ORDER BY `timestamp` DESC" . $limit, ARRAY_A);
                $link = wppa_dbg_url(get_admin_url() . 'admin.php' . '?page=wppa_moderate_photos');
            } else {
                return;
            }
        }
    } else {
        wppa_dbg_msg('Missing required argument in wppa_album_photos() 1', 'red', 'force');
        return;
    }
    // Quick edit skips a few time consuming settings like copy and move to other album
    $quick = isset($_REQUEST['quick']);
    if ($link && $quick) {
        $link .= '&quick';
    }
    // In case it is a seaerch and edit, show the search statistics
    wppa_show_search_statistics();
    // If no photos selected produce apprpriate message and quit
    if (empty($photos)) {
        // A specific photo requested
        if ($photo) {
            echo '<div id="photoitem-' . $photo . '" class="photoitem" style="width:100%; background-color: rgb( 255, 255, 224 ); border-color: rgb( 230, 219, 85 );">' . '<span style="color:red">' . sprintf(__('Photo %s has been removed.', 'wp-photo-album-plus'), $photo) . '</span>' . '</div>';
        } else {
            // Search
            if (isset($_REQUEST['wppa-searchstring'])) {
                echo '<h3>' . __('No photos matching your search criteria.', 'wp-photo-album-plus') . '</h3>';
            } else {
                echo '<h3>' . __('No photos yet in this album.', 'wp-photo-album-plus') . '</h3>';
            }
        }
        return;
    } else {
        // Local js functions placed here as long as there is not yet a possibility to translate texts in js files
        ?>
<script>
function wppaTryMove( id, video ) {

	var query;

	if ( ! jQuery( '#target-' + id ).val() ) {
		alert( '<?php 
        echo esc_js(__('Please select an album to move to first.', 'wp-photo-album-plus'));
        ?>
' );
		return false;
	}

	if ( video ) {
		query = '<?php 
        echo esc_js(__('Are you sure you want to move this video?', 'wp-photo-album-plus'));
        ?>
';
	}
	else {
		query = '<?php 
        echo esc_js(__('Are you sure you want to move this photo?', 'wp-photo-album-plus'));
        ?>
';
	}

	if ( confirm( query ) ) {
		wppaAjaxUpdatePhoto( id, 'moveto', document.getElementById( 'target-' + id ) );
	}
}

function wppaTryCopy( id, video ) {

	var query;

	if ( ! jQuery( '#target-' + id ).val() ) {
		alert( '<?php 
        echo esc_js(__('Please select an album to copy to first.', 'wp-photo-album-plus'));
        ?>
' );
		return false;
	}

	if ( video ) {
		query = '<?php 
        echo esc_js(__('Are you sure you want to copy this video?', 'wp-photo-album-plus'));
        ?>
';
	}
	else {
		query = '<?php 
        echo esc_js(__('Are you sure you want to copy this photo?', 'wp-photo-album-plus'));
        ?>
';
	}

	if ( confirm( query ) ) {
		wppaAjaxUpdatePhoto( id, 'copyto', document.getElementById( 'target-' + id ) );
	}
}

function wppaTryDelete( id, video ) {

	var query;

	if ( video ) {
		query = '<?php 
        echo esc_js(__('Are you sure you want to delete this video?', 'wp-photo-album-plus'));
        ?>
';
	}
	else {
		query = '<?php 
        echo esc_js(__('Are you sure you want to delete this photo?', 'wp-photo-album-plus'));
        ?>
';
	}

	if ( confirm( query ) ) {
		wppaAjaxDeletePhoto( id )
	}
}

function wppaTryRotLeft( id ) {

	var query = '<?php 
        echo esc_js(__('Are you sure you want to rotate this photo left?', 'wp-photo-album-plus'));
        ?>
';

	if ( confirm( query ) ) {
		wppaAjaxUpdatePhoto( id, 'rotleft', 0, <?php 
        echo wppa('front_edit') ? 'false' : 'true';
        ?>
 );
	}
}

function wppaTryRot180( id ) {

	var query = '<?php 
        echo esc_js(__('Are you sure you want to rotate this photo 180&deg;?', 'wp-photo-album-plus'));
        ?>
';

	if ( confirm( query ) ) {
		wppaAjaxUpdatePhoto( id, 'rot180', 0, <?php 
        echo wppa('front_edit') ? 'false' : 'true';
        ?>
 );
	}
}

function wppaTryRotRight( id ) {

	var query = '<?php 
        echo esc_js(__('Are you sure you want to rotate this photo right?', 'wp-photo-album-plus'));
        ?>
';

	if ( confirm( query ) ) {
		wppaAjaxUpdatePhoto( id, 'rotright', 0, <?php 
        echo wppa('front_edit') ? 'false' : 'true';
        ?>
 );
	}
}

function wppaTryFlip( id ) {

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

	if ( confirm( query ) ) {
		wppaAjaxUpdatePhoto( id, 'flip', 0, <?php 
        echo wppa('front_edit') ? 'false' : 'true';
        ?>
 );
	}
}

function wppaTryWatermark( id ) {

	var wmFile = jQuery( '#wmfsel_' + id ).val();
	if ( wmFile == '--- none ---' ) {
		alert( '<?php 
        echo esc_js(__('No watermark selected', 'wp-photo-album-plus'));
        ?>
' );
		return;
	}
	var query = '<?php 
        echo esc_js(__('Are you sure? Once applied it can not be removed!', 'wp-photo-album-plus'));
        ?>
';
	query += '\n';
	query += '<?php 
        echo esc_js(__('And I do not know if there is already a watermark on this photo', 'wp-photo-album-plus'));
        ?>
';

	if ( confirm( query ) ) {
		wppaAjaxApplyWatermark( id, document.getElementById( 'wmfsel_' + id ).value, document.getElementById( 'wmpsel_' + id ).value );
	}
}

</script>
<?php 
        // Get the current watermark file settings
        $wms = array('toplft' => __('top - left', 'wp-photo-album-plus'), 'topcen' => __('top - center', 'wp-photo-album-plus'), 'toprht' => __('top - right', 'wp-photo-album-plus'), 'cenlft' => __('center - left', 'wp-photo-album-plus'), 'cencen' => __('center - center', 'wp-photo-album-plus'), 'cenrht' => __('center - right', 'wp-photo-album-plus'), 'botlft' => __('bottom - left', 'wp-photo-album-plus'), 'botcen' => __('bottom - center', 'wp-photo-album-plus'), 'botrht' => __('bottom - right', 'wp-photo-album-plus'));
        $temp = wppa_get_water_file_and_pos('0');
        $wmfile = isset($temp['select']) ? $temp['select'] : '';
        $wmpos = isset($temp['pos']) && isset($wms[$temp['pos']]) ? $wms[$temp['pos']] : '';
        $mvt = esc_attr(__('Move video', 'wp-photo-album-plus'));
        $mpt = esc_attr(__('Move photo', 'wp-photo-album-plus'));
        $cvt = esc_attr(__('Copy video', 'wp-photo-album-plus'));
        $cpt = esc_attr(__('Copy photo', 'wp-photo-album-plus'));
        // Display the pagelinks
        wppa_admin_page_links($page, $pagesize, $count, $link);
        // Display all photos
        foreach ($photos as $photo) {
            // We may not use extract(), so we do something like it here manually, hence controlled.
            $id = $photo['id'];
            $timestamp = $photo['timestamp'];
            $modified = $photo['modified'];
            $owner = $photo['owner'];
            $crypt = $photo['crypt'];
            $album = $photo['album'];
            $name = stripslashes($photo['name']);
            $description = stripslashes($photo['description']);
            $exifdtm = $photo['exifdtm'];
            $views = $photo['views'];
            $clicks = $photo['clicks'];
            $p_order = $photo['p_order'];
            $linktarget = $photo['linktarget'];
            $linkurl = $photo['linkurl'];
            $linktitle = stripslashes($photo['linktitle']);
            $alt = stripslashes($photo['alt']);
            $filename = $photo['filename'];
            $videox = $photo['videox'];
            $videoy = $photo['videoy'];
            $location = $photo['location'];
            $status = $photo['status'];
            $tags = trim(stripslashes($photo['tags']), ',');
            $stereo = $photo['stereo'];
            // See if item is a multimedia item
            $is_multi = wppa_is_multi($id);
            $is_video = wppa_is_video($id);
            // returns array of extensions
            $b_is_video = empty($is_video) ? 0 : 1;
            // boolean
            $has_audio = wppa_has_audio($id);
            // returns array of extensions
            $b_has_audio = empty($has_audio) ? 0 : 1;
            // boolean
            // Various usefull vars
            $owner_editable = wppa_switch('photo_owner_change') && wppa_user_is('administrator');
            $sortby_orderno = wppa_get_album_item($album, 'p_order_by') == '1' || wppa_get_album_item($album, 'p_order_by') == '-1';
            echo "\n" . '<a id="photo_' . $id . '" ></a>';
            echo '<div' . ' id="photoitem-' . $id . '"' . ' class="wppa-table-wrap"' . ' style="width:100%;position:relative;"' . ' >';
            echo '<input' . ' type="hidden"' . ' id="photo-nonce-' . $id . '"' . ' value="' . wp_create_nonce('wppa_nonce_' . $id) . '"' . ' />';
            echo "\n" . '<!-- Section 1 -->' . '<table' . ' class="wppa-table wppa-photo-table"' . ' style="width:100%;"' . ' >' . '<tbody>';
            // -- Preview thumbnail ---
            echo '<tr>' . '<td>';
            $src = wppa_get_thumb_url($id);
            $big = wppa_get_photo_url($id);
            if ($is_video) {
                reset($is_video);
                $big = str_replace('xxx', current($is_video), $big);
                echo '<a' . ' href="' . $big . '"' . ' target="_blank"' . ' title="' . esc_attr(__('Preview fullsize video', 'wp-photo-album-plus')) . '"' . ' >' . wppa_get_video_html(array('id' => $id, 'tagid' => 'video-' . $id, 'width' => '160', 'height' => '160' * wppa_get_videoy($id) / wppa_get_videox($id), 'controls' => false, 'use_thumb' => true)) . '</a>';
            } else {
                if ($has_audio) {
                    $big = wppa_fix_poster_ext($big, $id);
                    $src = wppa_fix_poster_ext($src, $id);
                }
                echo '<a' . ' href="' . $big . '"' . ' target="_blank"' . ' title="' . esc_attr(__('Preview fullsize photo', 'wp-photo-album-plus')) . '"' . ' >' . '<img' . ' src="' . $src . '"' . ' alt="' . esc_attr($name) . '"' . ' style="max-width: 160px; vertical-align:middle;"' . ' />' . '</a>';
                if ($has_audio) {
                    $audio = wppa_get_audio_html(array('id' => $id, 'tagid' => 'audio-' . $id, 'width' => '160', 'controls' => true));
                    echo '<br />' . ($audio ? $audio : '<span style="color:red;">' . __('Audio disabled', 'wp-photo-album-plus') . '</span>');
                }
            }
            echo '</td>';
            echo '<td>' . 'ID = ' . $id . '. ' . __('Crypt:', 'wp-photo-album-plus') . ' ' . $crypt . '. ' . __('Filename:', 'wp-photo-album-plus') . ' ' . $filename . '. ' . __('Upload:', 'wp-photo-album-plus') . ' ' . wppa_local_date('', $timestamp) . ' ' . __('local time', 'wp-photo-album-plus') . '. ' . ($owner_editable ? '' : __('By:', 'wp-photo-album-plus') . ' ' . $owner);
            if ($owner_editable) {
                echo __('Owned by:', 'wp-photo-album-plus') . '<input' . ' type="text"' . ' onkeyup="wppaAjaxUpdatePhoto( ' . $id . ', \'owner\', this )"' . ' onchange="wppaAjaxUpdatePhoto( ' . $id . ', \'owner\', this )"' . ' value="' . $owner . '"' . ' />';
            }
            echo ' ' . sprintf(__('Album: %d (%s).', 'wp-photo-album-plus'), $album, wppa_get_album_name($album));
            // Modified
            if ($modified > $timestamp) {
                echo ' ' . __('Modified:', 'wp-photo-album-plus') . ' ' . wppa_local_date('', $modified) . ' ' . __('local time', 'wp-photo-album-plus');
            } else {
                echo ' ' . __('Not modified', 'wp-photo-album-plus');
            }
            echo '. ' . __('EXIF Date:', 'wp-photo-album-plus');
            if (wppa_user_is('administrator')) {
                // Admin may edit exif date
                echo '<input' . ' type="text"' . ' style="width:125px;"' . ' onkeyup="wppaAjaxUpdatePhoto( ' . $id . ', \'exifdtm\', this )"' . ' onchange="wppaAjaxUpdatePhoto( ' . $id . ', \'exifdtm\', this )"' . ' value="' . $exifdtm . '"' . ' />';
            } else {
                echo $exifdtm . '.';
            }
            echo ' ';
            // Location
            if ($photo['location'] || wppa_switch('geo_edit')) {
                echo __('Location:', 'wp-photo-album-plus') . ' ';
                $loc = $location ? $location : '///';
                $geo = explode('/', $loc);
                echo $geo['0'] . ' ' . $geo['1'] . '. ';
                if (wppa_switch('geo_edit')) {
                    echo __('Lat:', 'wp-photo-album-plus') . '<input' . ' type="text"' . ' style="width:100px;"' . ' id="lat-' . $id . '"' . ' onkeyup="wppaAjaxUpdatePhoto( ' . $id . ', \'lat\', this );"' . ' onchange="wppaAjaxUpdatePhoto( ' . $id . ', \'lat\', this );"' . ' value="' . $geo['2'] . '"' . ' />' . __('Lon:', 'wp-photo-album-plus') . '<input type="text"' . ' style="width:100px;"' . ' id="lon-' . $id . '"' . ' onkeyup="wppaAjaxUpdatePhoto( ' . $id . ', \'lon\', this );"' . ' onchange="wppaAjaxUpdatePhoto( ' . $id . ', \'lon\', this );"' . ' value="' . $geo['3'] . '"' . ' />';
                }
            }
            // Changeable p_order
            echo __('Photo sort order #:', 'wp-photo-album-plus');
            if ($sortby_orderno && (!wppa_switch('porder_restricted') || wppa_user_is('administrator'))) {
                echo '<input' . ' type="text"' . ' id="porder-' . $id . '"' . ' value="' . $p_order . '"' . ' style="width:30px;"' . ' onkeyup="wppaAjaxUpdatePhoto( ' . $id . ', \'p_order\', this )"' . ' onchange="wppaAjaxUpdatePhoto( ' . $id . ', \'p_order\', this )"' . ' />' . ' ';
            } else {
                echo $p_order . '. ';
            }
            // Rating
            $entries = wppa_get_rating_count_by_id($id);
            if ($entries) {
                if (wppa_opt('rating_display_type') == 'likes') {
                    echo __('Likes:', 'wp-photo-album-plus') . ' ' . $entries . '. ';
                } else {
                    echo __('Rating:', 'wp-photo-album-plus') . ' ' . __('Entries:', 'wp-photo-album-plus') . ' ' . $entries . ', ' . __('Mean value:', 'wp-photo-album-plus') . ' ' . wppa_get_rating_by_id($id, 'nolabel') . '. ';
                }
            } else {
                echo __('No ratings for this photo.', 'wp-photo-album-plus') . ' ';
            }
            $dislikes = wppa_dislike_get($id);
            if ($dislikes) {
                echo '<span style="color:red" >' . sprintf(__('Disliked by %d visitors', 'wp-photo-album-plus'), $dislikes) . '. ' . '</span>';
            }
            $pending = wppa_pendrat_get($id);
            if ($pending) {
                echo '<span style="color:orange" >' . sprintf(__('%d pending votes.', 'wp-photo-album-plus'), $pending) . ' ' . '</span>';
            }
            // Views
            if (wppa_switch('track_viewcounts')) {
                echo __('Views', 'wp-photo-album-plus') . ': ' . $views . '. ';
            }
            // Clicks
            if (wppa_switch('track_clickcounts')) {
                echo __('Clicks', 'wp-photo-album-plus') . ': ' . $clicks . '. ';
            }
            // Status
            echo '<br />' . __('Status:', 'wp-photo-album-plus') . ' ';
            if (current_user_can('wppa_admin') || current_user_can('wppa_moderate')) {
                if (wppa_switch('ext_status_restricted') && !wppa_user_is('administrator')) {
                    $dis = ' disabled="disabled"';
                } else {
                    $dis = '';
                }
                $sel = ' selected="selected"';
                echo '<select' . ' id="status-' . $id . '"' . ' onchange="wppaAjaxUpdatePhoto( ' . $id . ', \'status\', this ); wppaPhotoStatusChange( ' . $id . ' );"' . ' >' . '<option value="pending"' . ($status == 'pending' ? $sel : '') . ' >' . __('Pending', 'wp-photo-album-plus') . '</option>' . '<option value="publish"' . ($status == 'publish' ? $sel : '') . ' >' . __('Publish', 'wp-photo-album-plus') . '</option>' . '<option value="featured"' . ($status == 'featured' ? $sel : '') . $dis . ' >' . __('Featured', 'wp-photo-album-plus') . '</option>' . '<option value="gold"' . ($status == 'gold' ? $sel : '') . $dis . ' >' . __('Gold', 'wp-photo-album-plus') . '</option>' . '<option value="silver"' . ($status == 'silver' ? $sel : '') . $dis . ' >' . __('Silver', 'wp-photo-album-plus') . '</option>' . '<option value="bronze"' . ($status == 'bronze' ? $sel : '') . $dis . ' >' . __('Bronze', 'wp-photo-album-plus') . '</option>' . '<option value="scheduled"' . ($status == 'scheduled' ? $sel : '') . $dis . ' >' . __('Scheduled', 'wp-photo-album-plus') . '</option>' . '<option value="private"' . ($status == 'private' ? $sel : '') . $dis . ' >' . __('Private', 'wp-photo-album-plus') . '</option>' . '</select>' . wppa_get_date_time_select_html('photo', $id, true);
            } else {
                echo '<input' . ' type="hidden"' . ' id="status-' . $id . '"' . ' value="' . $status . '"' . ' />';
                if ($status == 'pending') {
                    _e('Pending', 'wp-photo-album-plus');
                } elseif ($status == 'publish') {
                    _e('Publish', 'wp-photo-album-plus');
                } elseif ($status == 'featured') {
                    _e('Featured', 'wp-photo-album-plus');
                } elseif ($status == 'gold') {
                    _e('Gold', 'wp-photo-album-plus');
                } elseif ($status == 'silver') {
                    _e('Silver', 'wp-photo-album-plus');
                } elseif ($status == 'bronze') {
                    _e('Bronze', 'wp-photo-album-plus');
                } elseif ($status == 'scheduled') {
                    _e('Scheduled', 'wp-photo-album-plus');
                } elseif ($status == 'private') {
                    _e('Private', 'wp-photo-album-plus');
                }
                echo wppa_get_date_time_select_html('photo', $id, false) . '<span id="psdesc-' . $id . '" class="description" style="display:none;" >' . __('Note: Featured photos should have a descriptive name; a name a search engine will look for!', 'wp-photo-album-plus') . '</span>';
            }
            echo ' ';
            // Update status field
            echo __('Remark:', 'wp-photo-album-plus') . ' ' . '<span' . ' id="photostatus-' . $id . '"' . ' style="font-weight:bold;color:#00AA00;"' . ' >' . ($is_video ? sprintf(__('Video %s is not modified yet', 'wp-photo-album-plus'), $id) : sprintf(__('Photo %s is not modified yet', 'wp-photo-album-plus'), $id)) . '</span>';
            // New Line
            echo '<br />';
            // --- Available files ---
            echo __('Available files:', 'wp-photo-album-plus') . ' ';
            // Source
            echo __('Source file:', 'wp-photo-album-plus') . ' ';
            $sp = wppa_get_source_path($id);
            if (is_file($sp)) {
                $ima = getimagesize($sp);
                echo $ima['0'] . ' x ' . $ima['1'] . ' px, ' . wppa_get_filesize($sp) . '. ';
            } else {
                echo __('Unavailable', 'wp-photo-album-plus') . '. ';
            }
            // Display
            echo ($is_video || $has_audio ? __('Poster file:', 'wp-photo-album-plus') : __('Display file:', 'wp-photo-album-plus')) . ' ';
            $dp = wppa_fix_poster_ext(wppa_get_photo_path($id), $id);
            if (is_file($dp)) {
                echo floor(wppa_get_photox($id)) . ' x ' . floor(wppa_get_photoy($id)) . ' px, ' . wppa_get_filesize($dp) . '. ';
            } else {
                echo '<span style="color:red;" >' . __('Unavailable', 'wp-photo-album-plus') . '. ' . '</span>';
            }
            // Thumbnail
            if (!$is_video) {
                echo __('Thumbnail file:', 'wp-photo-album-plus') . ' ';
                $tp = wppa_fix_poster_ext(wppa_get_thumb_path($id), $id);
                if (is_file($tp)) {
                    echo floor(wppa_get_thumbx($id)) . ' x ' . floor(wppa_get_thumby($id)) . ' px, ' . wppa_get_filesize($tp) . '. ';
                } else {
                    echo '<span style="color:red;" >' . __('Unavailable', 'wp-photo-album-plus') . '. ' . '</span>';
                }
            }
            // New line
            echo '<br />';
            // Video
            if ($b_is_video) {
                echo __('Video size:', 'wp-photo-album-plus') . ' ' . __('Width:', 'wp-photo-album-plus') . '<input' . ' style="width:50px;margin:0 4px;"' . ' onkeyup="wppaAjaxUpdatePhoto( ' . $id . ', \'videox\', this )"' . ' onchange="wppaAjaxUpdatePhoto( ' . $id . ', \'videox\', this )"' . ' value="' . $videox . '"' . ' />' . sprintf(__('pix, (0=default:%s)', 'wp-photo-album-plus'), wppa_opt('video_width')) . __('Height:', 'wp-photo-album-plus') . '<input' . ' style="width:50px;margin:0 4px;"' . ' onkeyup="wppaAjaxUpdatePhoto( ' . $id . ', \'videoy\', this )"' . ' onchange="wppaAjaxUpdatePhoto( ' . $id . ', \'videoy\', this )"' . ' value="' . $videoy . '"' . ' />' . sprintf(__('pix, (0=default:%s)', 'wp-photo-album-plus'), wppa_opt('video_height')) . ' ' . __('Formats:', 'wp-photo-album-plus') . ' ';
                $c = 0;
                foreach ($is_video as $fmt) {
                    echo $fmt . ' ' . __('Filesize:', 'wp-photo-album-plus') . ' ' . wppa_get_filesize(str_replace('xxx', $fmt, wppa_get_photo_path($id)));
                    $c++;
                    if ($c == count($is_video)) {
                        echo '. ';
                    } else {
                        echo ', ';
                    }
                }
            }
            // Audio
            if ($b_has_audio) {
                echo __('Formats:', 'wp-photo-album-plus') . ' ';
                $c = 0;
                foreach ($has_audio as $fmt) {
                    echo $fmt . ' ' . __('Filesize:', 'wp-photo-album-plus') . ' ' . wppa_get_filesize(str_replace('xxx', $fmt, wppa_get_photo_path($id)));
                    $c++;
                    if ($c == count($is_video)) {
                        echo '. ';
                    } else {
                        echo ', ';
                    }
                }
            }
            echo '</td>' . '</tr>' . '</tbody>' . '</table>';
            echo "\n" . '<!-- Section 2 -->';
            if (wppa_switch('enable_stereo') && !$is_multi || (!$is_multi || is_file(wppa_fix_poster_ext(wppa_get_photo_path($id), $id)))) {
                echo '<table' . ' class="wppa-table wppa-photo-table"' . ' style="width:100%;"' . ' >' . '<tbody>' . '<tr>' . '<td>';
                // Stereo
                if (wppa_switch('enable_stereo') && !$is_multi) {
                    echo __('Stereophoto:', 'wp-photo-album-plus') . ' ' . '<select' . ' id="stereo-' . $id . '"' . ' onchange="wppaAjaxUpdatePhoto( ' . $id . ', \'stereo\', this )"' . ' >' . '<option value="0"' . ($stereo == '0' ? ' selected="selected"' : '') . ' >' . __('no stereo image or ready anaglyph', 'wp-photo-album-plus') . '</option>' . '<option value="1"' . ($stereo == '1' ? ' selected="selected"' : '') . ' >' . __('Left - right stereo image', 'wp-photo-album-plus') . '</option>' . '<option value="-1"' . ($stereo == '-1' ? ' selected="selected"' : '') . ' >' . __('Right - left stereo image', 'wp-photo-album-plus') . '</option>' . '</select>' . ' ';
                    __('Images:', 'wp-photo-album-plus') . ' ';
                    $files = glob(WPPA_UPLOAD_PATH . '/stereo/' . $id . '-*.*');
                    $c = 0;
                    if (!empty($files)) {
                        sort($files);
                        foreach ($files as $file) {
                            echo '<a href="' . str_replace(WPPA_UPLOAD_PATH, WPPA_UPLOAD_URL, $file) . '" target="_blank" >' . basename($file) . '</a>';
                            $c++;
                            if ($c == count($files)) {
                                echo '. ';
                            } else {
                                echo ', ';
                            }
                        }
                    }
                }
                // Watermark
                if (!$is_multi || is_file(wppa_fix_poster_ext(wppa_get_photo_path($id), $id))) {
                    echo __('Watermark:', 'wp-photo-album-plus') . ' ';
                    if (wppa_switch('watermark_on')) {
                        $user = wppa_get_user();
                        if (wppa_switch('watermark_user') || current_user_can('wppa_settings')) {
                            echo '<select' . ' id="wmfsel_' . $id . '"' . ' onchange="wppaAjaxUpdatePhoto( ' . $id . ', \'wppa_watermark_file_' . $user . '\', this );"' . ' >' . wppa_watermark_file_select() . '</select>' . __('Pos:', 'wp-photo-album-plus') . ' ' . '<select' . ' id="wmpsel_' . $id . '"' . ' onchange="wppaAjaxUpdatePhoto( ' . $id . ', \'wppa_watermark_pos_' . $user . '\', this );"' . ' >' . wppa_watermark_pos_select() . '</select>' . '<input' . ' type="button"' . ' class="button-secundary"' . ' value="' . esc_attr(__('Apply watermark', 'wp-photo-album-plus')) . '"' . ' onclick="wppaTryWatermark( ' . $id . ' )"' . ' />';
                        } else {
                            echo __('File:', 'wp-photo-album-plus') . ' ' . __($wmfile, 'wp-photo-album-plus') . ' ';
                            if ($wmfile != '--- none ---') {
                                echo __('Pos:', 'wp-photo-album-plus') . ' ' . $wmpos;
                            }
                        }
                        echo '<img' . ' id="wppa-water-spin-' . $id . '"' . ' src="' . wppa_get_imgdir() . 'spinner.gif' . '"' . ' alt="Spin"' . ' style="visibility:hidden"' . ' />';
                    } else {
                        echo __('Not configured', 'wp-photo-album-plus');
                    }
                    echo ' ';
                }
                echo '</td>' . '</tr>' . '</tbody>' . '</table>';
            }
            echo "\n" . '<!-- Section 3 -->' . '<table' . ' class="wppa-table wppa-photo-table"' . ' style="width:100%;"' . ' >' . '<tbody>' . '<tr>' . '<td>';
            // --- Actions ---
            // Rotate
            if (!$b_is_video) {
                echo '<input' . ' type="button"' . ' onclick="wppaTryRotLeft( ' . $id . ' )"' . ' value="' . esc_attr(__('Rotate left', 'wp-photo-album-plus')) . '"' . ' />' . ' ' . '<input' . ' type="button"' . ' onclick="wppaTryRot180( ' . $id . ' )"' . ' value="' . esc_attr(__('Rotate 180&deg;', 'wp-photo-album-plus')) . '"' . ' />' . ' ' . '<input' . ' type="button"' . ' onclick="wppaTryRotRight( ' . $id . ' )"' . ' value="' . esc_attr(__('Rotate right', 'wp-photo-album-plus')) . '"' . ' />' . ' ' . '<input' . ' type="button"' . ' onclick="wppaTryFlip( ' . $id . ' )"' . ' value="' . esc_attr(__('Flip', 'wp-photo-album-plus')) . '"' . ' />' . ' ';
            }
            // Remake displayfiles
            if (!$is_video) {
                echo '<input' . ' type="button"' . ' title="' . esc_attr(__('Remake display file and thumbnail file', 'wp-photo-album-plus')) . '"' . ' onclick="wppaAjaxUpdatePhoto( ' . $id . ', \'remake\', this, ' . (wppa('front_edit') ? 'false' : 'true') . ' )"' . ' value="' . esc_attr(__('Remake files', 'wp-photo-album-plus')) . '"' . ' />' . ' ';
            }
            // Remake thumbnail
            if (!$is_video) {
                echo '<input' . ' type="button"' . ' title=' . esc_attr(__('Remake thumbnail file', 'wp-photo-album-plus')) . '"' . ' onclick="wppaAjaxUpdatePhoto( ' . $id . ', \'remakethumb\', this, ' . (wppa('front_edit') ? 'false' : 'true') . ' )"' . ' value="' . esc_attr(__('Remake thumbnail file', 'wp-photo-album-plus')) . '"' . ' />' . ' ';
            }
            // Move/copy
            if (!$quick) {
                $max = wppa_opt('photo_admin_max_albums');
                if (!$max || wppa_get_total_album_count() < $max) {
                    // If not done yet, get the album options html with the current album excluded
                    if (!isset($album_select[$album])) {
                        $album_select[$album] = wppa_album_select_a(array('checkaccess' => true, 'path' => wppa_switch('hier_albsel'), 'exclude' => $album, 'selected' => '0', 'addpleaseselect' => true));
                    }
                    echo __('Target album for copy/move:', 'wp-photo-album-plus') . '<select' . ' id="target-' . $id . '"' . ' >' . $album_select[$album] . '</select>';
                } else {
                    echo __('Target album for copy/move:', 'wp-photo-album-plus') . '<input' . ' id="target-' . $id . '"' . ' type="number"' . ' style="height:20px;"' . ' placeholder="' . __('Album id', 'wp-photo-album-plus') . '"' . ' />';
                }
                echo ' ';
                echo '<input' . ' type="button"' . ' onclick="wppaTryMove( ' . $id . ', ' . $b_is_video . ' )"' . ' value="' . ($b_is_video ? $mvt : $mpt) . '"' . ' />' . ' ' . '<input' . ' type="button"' . ' onclick="wppaTryCopy( ' . $id . ', ' . $b_is_video . ' )"' . ' value="' . ($b_is_video ? $cvt : $cpt) . '"' . ' />' . ' ';
            }
            // Delete
            if (!wppa('front_edit')) {
                echo '<input' . ' type="button"' . ' style="color:red;"' . ' onclick="wppaTryDelete( ' . $id . ', ' . $b_is_video . ' )"' . ' value="' . ($b_is_video ? esc_attr(__('Delete video', 'wp-photo-album-plus')) : esc_attr(__('Delete photo', 'wp-photo-album-plus'))) . '"' . ' />' . ' ';
            }
            // Re-upload
            if (wppa_user_is('administrator') || !wppa_switch('reup_is_restricted')) {
                echo '<input' . ' type="button"' . ' onclick="jQuery( \'#re-up-' . $id . '\' ).css( \'display\', \'inline-block\' )"' . ' value="' . esc_attr(__('Re-upload file', 'wp-photo-album-plus')) . '"' . ' />' . '<div id="re-up-' . $id . '" style="display:none" >' . '<form' . ' id="wppa-re-up-form-' . $id . '"' . ' onsubmit="wppaReUpload( event, ' . $id . ', \'' . $filename . '\' )"' . ' >' . '<input' . ' type="file"' . ' id="wppa-re-up-file-' . $id . '"' . ' />' . '<input' . ' type="submit"' . ' id="wppa-re-up-butn-' . $id . '"' . ' value="' . esc_attr(__('Upload', 'wp-photo-album-plus')) . '"' . ' />' . '</form>' . '</div>';
            }
            // Refresh
            /*
            if ( ! wppa( 'front_edit' ) ) {
            	echo
            	'<input' .
            		' type="button"' .
            		' onclick="wppaReload( \'#photo_' . $id . '\')"' .
            		' value="' . esc_attr( __( 'Refresh page', 'wp-photo-album-plus' ) ) . '"' .
            	' />';
            }
            */
            echo '</td>' . '</tr>' . '</tbody>' . '</table>';
            echo "\n" . '<!-- Section 4 -->' . '<table' . ' class="wppa-table wppa-photo-table"' . ' style="width:100%;"' . ' >' . '<tbody>';
            // Name
            echo '<tr>' . '<td>' . __('Photoname:', 'wp-photo-album-plus') . '</td>' . '<td>' . '<input' . ' type="text"' . ' style="width:100%;"' . ' id="pname-' . $id . '"' . ' onkeyup="wppaAjaxUpdatePhoto( ' . $id . ', \'name\', this );"' . ' onchange="wppaAjaxUpdatePhoto( ' . $id . ', \'name\', this );"' . ' value="' . esc_attr(stripslashes($name)) . '"' . ' />' . '</td>' . '<td>' . '</td>' . '</tr>';
            // Description
            if (!wppa_switch('desc_is_restricted') || wppa_user_is('administrator')) {
                echo '<tr>' . '<td>' . __('Description:', 'wp-photo-album-plus') . '</td>';
                if (wppa_switch('use_wp_editor')) {
                    $alfaid = wppa_alfa_id($id);
                    echo '<td>';
                    wp_editor($description, 'wppaphotodesc' . $alfaid, array('wpautop' => true, 'media_buttons' => false, 'textarea_rows' => '6', 'tinymce' => true));
                    echo '</td>' . '<td>' . '<input' . ' type="button"' . ' class="button-secundary"' . ' value="' . esc_attr(__('Update Photo description', 'wp-photo-album-plus')) . '"' . ' onclick="wppaAjaxUpdatePhoto( ' . $id . ', \'description\', document.getElementById( \'wppaphotodesc' . $alfaid . '\' ), false, \'' . $alfaid . '\' )"' . ' />' . '<img' . ' id="wppa-photo-spin-' . $id . '"' . ' src="' . wppa_get_imgdir() . 'spinner.gif"' . ' style="visibility:hidden"' . ' />' . '</td>';
                } else {
                    echo '<td>' . '<textarea' . ' style="width:100%;height:60px;"' . ' onkeyup="wppaAjaxUpdatePhoto( ' . $id . ', \'description\', this )"' . ' onchange="wppaAjaxUpdatePhoto( ' . $id . ', \'description\', this )"' . ' >' . $description . '</textarea>' . '</td>' . '<td>' . '</td>';
                }
                echo '</tr>';
            } else {
                echo '<tr>' . '<td>' . __('Description:', 'wp-photo-album-plus') . '</td>' . '<td>' . $description . '</td>' . '<td>' . '</td>' . '</tr>';
            }
            // Tags
            echo '<tr>' . '<td>' . __('Tags:', 'wp-photo-album-plus') . '</td>' . '<td>' . '<input' . ' id="tags-' . $id . '"' . ' type="text"' . ' style="width:100%;"' . ' onchange="wppaAjaxUpdatePhoto( ' . $id . ', \'tags\', this )"' . ' value="' . $tags . '"' . ' />' . '<br />' . '<span class="description" >' . __('Separate tags with commas.', 'wp-photo-album-plus') . '</span>' . '</td>' . '<td>' . '<select' . ' onchange="wppaAddTag( this.value, \'tags-' . $id . '\' ); wppaAjaxUpdatePhoto( ' . $id . ', \'tags\', document.getElementById( \'tags-' . $id . '\' ) )"' . ' >';
            $taglist = wppa_get_taglist();
            if (is_array($taglist)) {
                echo '<option value="" >' . __('- select -', 'wp-photo-album-plus') . '</option>';
                foreach ($taglist as $tag) {
                    echo '<option value="' . $tag['tag'] . '" >' . $tag['tag'] . '</option>';
                }
            } else {
                echo '<option value="0" >' . __('No tags yet', 'wp-photo-album-plus') . '</option>';
            }
            echo '</select>' . '<br />' . '<span class="description" >' . __('Select to add', 'wp-photo-album-plus') . '</span>' . '</td>' . '</tr>';
            // Custom
            if (wppa_switch('custom_fields')) {
                $custom = wppa_get_photo_item($photo['id'], 'custom');
                if ($custom) {
                    $custom_data = unserialize($custom);
                } else {
                    $custom_data = array('', '', '', '', '', '', '', '', '', '');
                }
                foreach (array_keys($custom_data) as $key) {
                    if (wppa_opt('custom_caption_' . $key)) {
                        echo '<tr>' . '<td>' . apply_filters('translate_text', wppa_opt('custom_caption_' . $key)) . '<small style="float:right" >' . '(w#cc' . $key . ')' . '</small>:' . '</td>' . '<td>' . '<input' . ' type="text"' . ' style="width:100%;"' . ' id="custom_' . $key . '-' . $id . '"' . ' onkeyup="wppaAjaxUpdatePhoto( ' . $id . ', \'custom_' . $key . '\', this );"' . ' onchange="wppaAjaxUpdatePhoto( ' . $id . ', \'custom_' . $key . '\', this );"' . ' value="' . esc_attr(stripslashes($custom_data[$key])) . '"' . '/>' . '</td>' . '<td>' . '<small>(w#cd' . $key . ')</small>' . '</td> ' . '</tr>';
                    }
                }
            }
            // -- Auto Page --
            if (wppa_switch('auto_page') && (current_user_can('edit_posts') || current_user_can('edit_pages'))) {
                $appl = get_permalink(wppa_get_the_auto_page($id));
                echo '<tr>' . '<td>' . __('Autopage Permalink:', 'wp-photo-album-plus') . '</td>' . '<td>' . '<a href="' . $appl . '" target="_blank" >' . $appl . '</a>' . '</td>' . '<td>' . '</td>' . '</tr>';
            }
            // -- Link url --
            if (!wppa_switch('link_is_restricted') || wppa_user_is('administrator')) {
                echo '<tr>' . '<td>' . __('Photo specific link url:', 'wp-photo-album-plus') . '</td>' . '<td>' . '<input' . ' type="text"' . ' id="pislink-' . $id . '"' . ' style="width:100%;"' . ' onkeyup="wppaAjaxUpdatePhoto( ' . $id . ', \'linkurl\', this )"' . ' onchange="wppaAjaxUpdatePhoto( ' . $id . ', \'linkurl\', this )"' . ' value="' . esc_attr($linkurl) . '"' . ' />' . '</td>' . '<td>' . '<select' . ' id="pistarget-' . $id . '"' . ' onchange="wppaAjaxUpdatePhoto( ' . $id . ', \'linktarget\', this )"' . ' >' . '<option' . ' value="_self"' . ($linktarget == '_self' ? ' selected="selected"' : '') . ' >' . __('Same tab', 'wp-photo-album-plus') . '</option>' . '<option' . ' value="_blank"' . ($linktarget == '_blank' ? ' selected="selected"' : '') . ' >' . __('New tab', 'wp-photo-album-plus') . '</option>' . '</select>' . '<input' . ' type="button"' . ' onclick="window.open( jQuery( \'#pislink-' . $id . '\' ).val(), jQuery( \'#pistarget-' . $id . '\' ).val() );"' . ' value="' . __('Tryit!', 'wp-photo-album-plus') . '"' . ' />' . '</td>' . '</tr>';
                // -- Link title --
                echo '<tr>' . '<td>' . __('Photo specific link title:', 'wp-photo-album-plus') . '</td>' . '<td>' . '<input' . ' type="text"' . ' style="width:100%;"' . ' onkeyup="wppaAjaxUpdatePhoto( ' . $id . ', \'linktitle\', this )"' . ' onchange="wppaAjaxUpdatePhoto( ' . $id . ', \'linktitle\', this )"' . ' value="' . esc_attr($linktitle) . '"' . ' />';
                if (current_user_can('wppa_settings')) {
                    echo '<br />' . '<span class="description" >' . __('If you want this link to be used, check \'PS Overrule\' checkbox in table VI.', 'wp-photo-album-plus') . '</span>';
                }
                echo '</td>' . '<td>' . '</td>' . '</tr>';
            }
            // -- Custom ALT field --
            if (wppa_opt('alt_type') == 'custom') {
                echo '<tr>' . '<td>' . __('HTML Alt attribute:', 'wp-photo-album-plus') . '</td>' . '<td>' . '<input' . ' type="text"' . ' style="width:100%;"' . ' onkeyup="wppaAjaxUpdatePhoto( ' . $id . ', \'alt\', this )"' . ' onchange="wppaAjaxUpdatePhoto( ' . $id . ', \'alt\', this )"' . ' value="' . esc_attr($alt) . '"' . ' />' . '</td>' . '<td>' . '</td>' . '</tr>';
            }
            // If Quick, skip the following items for speed and space
            if (!$quick) {
                // Shortcode
                if (current_user_can('edit_posts') || current_user_can('edit_pages')) {
                    echo '<tr>' . '<td>' . __('Single image shortcode', 'wp-photo-album-plus') . ':' . '</td>' . '<td>' . '[wppa type="photo" photo="' . $id . '"][/wppa]' . '</td>' . '<td>' . '<small>' . sprintf(__('See %s The documentation %s for more shortcode options.', 'wp-photo-album-plus'), '<a href="http://wppa.nl/shortcode-reference/" target="_blank" >', '</a>') . '</small>' . '</td>' . '</tr>';
                }
                // Source permalink
                if (is_file(wppa_get_source_path($id))) {
                    $spl = wppa_get_source_pl($id);
                    echo '<tr>' . '<td>' . __('Permalink', 'wp-photo-album-plus') . ':' . '</td>' . '<td>' . '<a href="' . $spl . '" target="_blank" >' . $spl . '</a>' . '</td>' . '<td>' . '</td>' . '</tr>';
                }
                // High resolution url
                $hru = wppa_get_hires_url($id);
                echo '<tr>' . '<td>' . __('Hi resolution url', 'wp-photo-album-plus') . ':' . '</td>' . '<td>' . '<a href="' . $hru . '" target="_blank" >' . $hru . '</a>' . '</td>' . '<td>' . '</td>' . '</tr>';
                // Display file
                if (is_file(wppa_fix_poster_ext(wppa_get_photo_path($id), $id))) {
                    $lru = wppa_fix_poster_ext(wppa_get_lores_url($id), $id);
                    echo '<tr>' . '<td>' . __('Display file url', 'wp-photo-album-plus') . ':' . '</td>' . '<td>' . '<a href="' . $lru . '" target="_blank" >' . $lru . '</a>' . '</td>' . '<td>' . '</td>' . '</tr>';
                }
                // Thumbnail
                if (is_file(wppa_fix_poster_ext(wppa_get_thumb_path($id), $id))) {
                    $tnu = wppa_fix_poster_ext(wppa_get_tnres_url($id), $id);
                    echo '<tr>' . '<td>' . __('Thumbnail file url', 'wp-photo-album-plus') . ':' . '</td>' . '<td>' . '<a href="' . $tnu . '" target="_blank" >' . $tnu . '</a>' . '</td>' . '<td>' . '</td>' . '</tr>';
                }
            }
            echo '</tbody>' . '</table>';
            echo "\n" . '<!-- Section 5 -->';
            // Comments
            $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_COMMENTS . "` WHERE `photo` = %s ORDER BY `timestamp` DESC", $id), ARRAY_A);
            if ($comments && !$quick) {
                echo '<table' . ' class="wppa-table wppa-photo-table"' . ' style="width:100%;"' . ' >' . '<thead>' . '<tr style="font-weight:bold;" >' . '<td style="padding:0 4px;" >#</td>' . '<td style="padding:0 4px;" >User</td>' . '<td style="padding:0 4px;" >Time since</td>' . '<td style="padding:0 4px;" >Status</td>' . '<td style="padding:0 4px;" >Comment</td>' . '</tr>' . '</thead>' . '<tbody>';
                foreach ($comments as $comment) {
                    echo '
								<tr id="com-tr-' . $comment['id'] . '" >
									<td style="padding:0 4px;" >' . $comment['id'] . '</td>
									<td style="padding:0 4px;" >' . $comment['user'] . '</td>
									<td style="padding:0 4px;" >' . wppa_get_time_since($comment['timestamp']) . '</td>';
                    if (current_user_can('wppa_comments') || current_user_can('wppa_moderate') || wppa_get_user() == $photo['owner'] && wppa_switch('owner_moderate_comment')) {
                        $p = $comment['status'] == 'pending' ? 'selected="selected" ' : '';
                        $a = $comment['status'] == 'approved' ? 'selected="selected" ' : '';
                        $s = $comment['status'] == 'spam' ? 'selected="selected" ' : '';
                        $t = $comment['status'] == 'trash' ? 'selected="selected" ' : '';
                        echo '<td style="padding:0 4px;" >' . '<select' . ' id="com-stat-' . $comment['id'] . '"' . ' style=""' . ' onchange="wppaAjaxUpdateCommentStatus( ' . $id . ', ' . $comment['id'] . ', this.value );wppaSetComBgCol(' . $comment['id'] . ');"' . ' >' . '<option value="pending" ' . $p . '>' . __('Pending', 'wp-photo-album-plus') . '</option>' . '<option value="approved" ' . $a . '>' . __('Approved', 'wp-photo-album-plus') . '</option>' . '<option value="spam" ' . $s . '>' . __('Spam', 'wp-photo-album-plus') . '</option>' . '<option value="trash" ' . $t . '>' . __('Trash', 'wp-photo-album-plus') . '</option>' . '</select >' . '</td>';
                    } else {
                        echo '<td style="padding:0 4px;" >';
                        if ($comment['status'] == 'pending') {
                            _e('Pending', 'wp-photo-album-plus');
                        } elseif ($comment['status'] == 'approved') {
                            _e('Approved', 'wp-photo-album-plus');
                        } elseif ($comment['status'] == 'spam') {
                            _e('Spam', 'wp-photo-album-plus');
                        } elseif ($comment['status'] == 'trash') {
                            _e('Trash', 'wp-photo-album-plus');
                        }
                        echo '</td>';
                    }
                    echo '<td style="padding:0 4px;" >' . $comment['comment'] . '</td>
								</tr>' . '<script>wppaSetComBgCol(' . $comment['id'] . ')</script>';
                }
                echo '</tbody>' . '</table>';
            }
            echo '<script>wppaPhotoStatusChange( ' . $id . ' )</script>' . '<div style="clear:both;"></div>' . '</div>' . '<div style="clear:both;margin-top:7px;"></div>';
        }
        /* foreach photo */
        wppa_admin_page_links($page, $pagesize, $count, $link);
    }
    /* photos not empty */
}
function wppa_do_maintenance_popup($slug)
{
    global $wpdb;
    global $wppa_log_file;
    // Open wrapper with dedicated styles
    $result = '<div' . ' id="wppa-maintenance-list"' . ' >' . '<style' . ' tyle="text/css"' . ' >' . '#wppa-maintenance-list h2 {' . 'margin-top:0;' . '}' . '#wppa-maintenance-list div {' . 'background-color:#f1f1f1; border:1px solid #ddd;' . '}' . '#wppa-maintenance-list td, #wppa-maintenance-list th {' . 'border-right: 1px solid darkgray;' . '}' . '</style>';
    switch ($slug) {
        // List the search index table
        case 'wppa_list_index':
            $start = get_option('wppa_list_index_display_start', '');
            $total = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_INDEX . "`");
            $indexes = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_INDEX . "` WHERE `slug` >= %s ORDER BY `slug` LIMIT 1000", $start), ARRAY_A);
            $result .= '<h2>' . sprintf(__('List of Searcheable words <small>( Max 1000 entries of total %d )</small>', 'wp-photo-album-plus'), $total) . '</h2>' . '<div' . ' style="float:left; clear:both; width:100%; overflow:auto;"' . ' >';
            if ($indexes) {
                $result .= '
				<table>
					<thead>
						<tr>
							<th><span style="float:left;" >Word</span></th>
							<th style="max-width:400px;" ><span style="float:left;" >Albums</span></th>
							<th><span style="float:left;" >Photos</span></th>
						</tr>
						<tr><td colspan="3"><hr /></td></tr>
					</thead>
					<tbody>';
                foreach ($indexes as $index) {
                    $result .= '
						<tr>
							<td>' . $index['slug'] . '</td>
							<td style="max-width:400px; word-wrap: break-word;" >' . $index['albums'] . '</td>
							<td>' . $index['photos'] . '</td>
						</tr>';
                }
                $result .= '
					</tbody>
				</table>';
            } else {
                $result .= __('There are no index items.', 'wp-photo-album-plus');
            }
            $result .= '
				</div><div style="clear:both;"></div>';
            break;
        case 'wppa_list_errorlog':
            $result .= '<h2>' . __('List of WPPA+ log messages', 'wp-photo-album-plus') . '</h2>' . '<div style="float:left; clear:both; width:100%; overflow:auto; word-wrap:none;" >';
            if (!($file = @fopen($wppa_log_file, 'r'))) {
                $result .= __('There are no error log messages', 'wp-photo-album-plus');
            } else {
                $size = filesize($wppa_log_file);
                $data = fread($file, $size);
                $data = htmlspecialchars(strip_tags($data));
                $data = str_replace(array('{b}', '{/b}', "\n"), array('<b>', '</b>', '<br />'), $data);
                $result .= $data;
                fclose($file);
            }
            $result .= '
				</div><div style="clear:both;"></div>
				';
            break;
        case 'wppa_list_rating':
            $total = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_RATING . "`");
            $ratings = $wpdb->get_results("SELECT * FROM `" . WPPA_RATING . "` ORDER BY `timestamp` DESC LIMIT 1000", ARRAY_A);
            $result .= '<h2>' . sprintf(__('List of recent ratings <small>( Max 1000 entries of total %d )</small>', 'wp-photo-album-plus'), $total) . '</h2>' . '<div' . ' style="float:left; clear:both; width:100%; overflow:auto;"' . ' >';
            if ($ratings) {
                $result .= '
				<table>
					<thead>
						<tr>
							<th>Id</th>
							<th>Timestamp</th>
							<th>Date/time</th>
							<th>Status</th>
							<th>User</th>
							<th>Value</th>
							<th>Photo id</th>
							<th></th>
							<th># ratings</th>
							<th>Average</th>
						</tr>
						<tr><td colspan="10"><hr /></td></tr>
					</thead>
					<tbody>';
                foreach ($ratings as $rating) {
                    $thumb = wppa_cache_thumb($rating['photo']);
                    $result .= '
						<tr>
							<td>' . $rating['id'] . '</td>
							<td>' . $rating['timestamp'] . '</td>
							<td>' . ($rating['timestamp'] ? wppa_local_date(get_option('date_format', "F j, Y,") . ' ' . get_option('time_format', "g:i a"), $rating['timestamp']) : 'pre-historic') . '</td>
							<td>' . $rating['status'] . '</td>
							<td>' . $rating['user'] . '</td>
							<td>' . $rating['value'] . '</td>
							<td>' . $rating['photo'] . '</td>
							<td style="width:250px; text-align:center;"><img src="' . wppa_get_thumb_url($rating['photo']) . '"
								style="height: 40px;"
								onmouseover="jQuery(this).stop().animate({height:this.naturalHeight}, 200);"
								onmouseout="jQuery(this).stop().animate({height:\'40px\'}, 200);" /></td>
							<td>' . $thumb['rating_count'] . '</td>
							<td>' . $thumb['mean_rating'] . '</td>
						</tr>';
                }
                $result .= '
					</tbody>
				</table>';
            } else {
                $result .= __('There are no ratings', 'wp-photo-album-plus');
            }
            $result .= '
				</div><div style="clear:both;"></div>';
            break;
        case 'wppa_list_session':
            $total = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_SESSION . "`");
            $sessions = $wpdb->get_results("SELECT * FROM `" . WPPA_SESSION . "` ORDER BY `id` DESC LIMIT 1000", ARRAY_A);
            $result .= '<h2>' . sprintf(__('List of sessions <small>( Max 1000 entries of total %d )</small>', 'wp-photo-album-plus'), $total) . '</h2>' . '<div' . ' style="float:left; clear:both; width:100%; overflow:auto;"' . ' >';
            if ($sessions) {
                $result .= '
				<table>
					<thead>
						<tr>
							<th>Id</th>

							<th>IP</th>
							<th>Started</th>
							<th>Count</th>
							<th>Status</th>
							<th>Data</th>
							<th>Uris</th>
						</tr>
						<tr><td colspan="7"><hr /></td></tr>
					</thead>
					<tbody style="overflow:auto;" >';
                foreach ($sessions as $session) {
                    $data = unserialize($session['data']);
                    $result .= '
							<tr>
								<td>' . $session['id'] . '</td>

								<td>' . (strlen($session['ip']) > 15 ? substr($session['ip'], 0, 12) . '...' : $session['ip']) . '</td>
								<td style="width:150px;" >' . wppa_local_date(get_option('date_format', "F j, Y,") . ' ' . get_option('time_format', "g:i a"), $session['timestamp']) . '</td>
								<td>' . $session['count'] . '</td>' . '<td>' . $session['status'] . '</td>' . '<td style="border-bottom:1px solid gray;max-width:300px;" >';
                    if (is_array($data)) {
                        foreach (array_keys($data) as $key) {
                            if ($key != 'uris') {
                                if (is_array($data[$key])) {
                                    $result .= '[' . $key . '] => Array(' . implode(',', array_keys($data[$key])) . ')<br />';
                                } else {
                                    $result .= '[' . $key . '] => ' . $data[$key] . '<br />';
                                }
                            }
                        }
                    }
                    $result .= '
								</td>
								<td style="border-bottom:1px solid gray;" >';
                    if (is_array($data['uris'])) {
                        foreach ($data['uris'] as $uri) {
                            $result .= $uri . '<br />';
                        }
                    }
                    $result .= '
								</td>
							</tr>';
                }
                $result .= '
					</tbody>
				</table>';
            } else {
                $result .= __('There are no active sessions', 'wp-photo-album-plus');
            }
            $result .= '
				</div><div style="clear:both;"></div>';
            break;
        case 'wppa_list_comments':
            $total = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_COMMENTS . "`");
            $order = wppa_opt('list_comments_by');
            if ($order == 'timestamp') {
                $order .= ' DESC';
            }
            if ($order == 'name') {
                $order = 'user';
            }
            $query = "SELECT * FROM `" . WPPA_COMMENTS . "` ORDER BY " . $order . " LIMIT 1000";
            //	$result .= $query.'<br />';
            $comments = $wpdb->get_results($query, ARRAY_A);
            $result .= '<h2>' . sprintf(__('List of comments <small>( Max 1000 entries of total %d )</small>', 'wp-photo-album-plus'), $total) . '</h2>' . '<div style="float:left; clear:both; width:100%; overflow:auto;" >';
            if ($comments) {
                $result .= '
				<table>
					<thead>
						<tr>
							<th>Id</th>
							<th>Timestamp</th>
							<th>Date/time</th>
							<th>Status</th>
							<th>User</th>
							<th>Email</th>
							<th>Photo id</th>
							<th></th>
							<th>Comment</th>
						</tr>
						<tr><td colspan="10"><hr /></td></tr>
					</thead>
					<tbody>';
                foreach ($comments as $comment) {
                    $thumb = wppa_cache_thumb($comment['photo']);
                    $result .= '
						<tr>
							<td>' . $comment['id'] . '</td>
							<td>' . $comment['timestamp'] . '</td>
							<td>' . ($comment['timestamp'] ? wppa_local_date(get_option('date_format', "F j, Y,") . ' ' . get_option('time_format', "g:i a"), $comment['timestamp']) : 'pre-historic') . '</td>
							<td>' . $comment['status'] . '</td>
							<td>' . $comment['user'] . '</td>
							<td>' . $comment['email'] . '</td>
							<td>' . $comment['photo'] . '</td>
							<td style="width:250px; text-align:center;"><img src="' . wppa_get_thumb_url($comment['photo']) . '"
								style="height: 40px;"
								onmouseover="jQuery(this).stop().animate({height:this.naturalHeight}, 200);"
								onmouseout="jQuery(this).stop().animate({height:\'40px\'}, 200);" /></td>
							<td>' . $comment['comment'] . '</td>
						</tr>';
                }
                $result .= '
					</tbody>
				</table>';
            } else {
                $result .= __('There are no comments', 'wp-photo-album-plus');
                $result .= '<br />Query=' . $wpdb->prepare("SELECT * FROM `" . WPPA_COMMENTS . "` ORDER BY %s DESC LIMIT 1000", wppa_opt('list_comments_by'));
            }
            $result .= '
				</div><div style="clear:both;"></div>';
            break;
        default:
            $result = 'Error: Unimplemented slug: ' . $slug . ' in wppa_do_maintenance_popup()';
    }
    $result .= '</div>';
    return $result;
}
function wppa_translate_album_keywords($id, $text)
{
    $result = $text;
    // Does album exist and is there any 'w#' ?
    if (wppa_album_exists($id) && strpos($result, 'w#') !== false) {
        // Get album data
        $album = wppa_cache_album($id);
        // Keywords
        $keywords = array('name', 'owner', 'id', 'views');
        foreach ($keywords as $keyword) {
            $replacement = __(trim(stripslashes($album[$keyword])), 'wp-photo-album-plus');
            if ($replacement == '') {
                $replacement = '&lsaquo;' . __('none', 'wp-photo-album-plus') . '&rsaquo;';
            }
            $result = str_replace('w#' . $keyword, $replacement, $result);
        }
        // Timestamps
        $timestamps = array('timestamp', 'modified');
        foreach ($timestamps as $timestamp) {
            if ($album[$timestamp]) {
                $result = str_replace('w#' . $timestamp, wppa_local_date(get_option('date_format', "F j, Y,") . ' ' . get_option('time_format', "g:i a"), $album['timestamp']), $result);
            } else {
                $result = str_replace('w#' . $timestamp, '&lsaquo;' . __('unknown', 'wp-photo-album-plus') . '&rsaquo;', $result);
            }
        }
        // Custom data fields
        if (wppa_switch('custom_fields')) {
            $custom = $album['custom'];
            $custom_data = $custom ? unserialize($custom) : array('', '', '', '', '', '', '', '', '', '');
            for ($i = '0'; $i < '10'; $i++) {
                if (wppa_opt('album_custom_caption_' . $i)) {
                    // Field defined
                    if (wppa_switch('album_custom_visible_' . $i)) {
                        // May be displayed
                        $result = str_replace('w#cc' . $i, __(wppa_opt('album_custom_caption_' . $i), 'wp-photo-album-plus') . ':', $result);
                        // Caption
                        $result = str_replace('w#cd' . $i, __(stripslashes($custom_data[$i]), 'wp-photo-album-plus'), $result);
                        // Data
                    } else {
                        // May not be displayed
                        $result = str_replace('w#cc' . $i, '', $result);
                        // Remove
                        $result = str_replace('w#cd' . $i, '', $result);
                        // Remove
                    }
                } else {
                    // Field not defined
                    $result = str_replace('w#cc' . $i, '', $result);
                    // Remove
                    $result = str_replace('w#cd' . $i, '', $result);
                    // Remove
                }
            }
        }
    }
    // Done!
    return $result;
}
function _wppa_sidebar_page_options()
{
    global $wpdb;
    global $wppa_defaults;
    wppa_set_defaults();
    $onch = 'myReload()';
    // Handle spinner js and declare functions
    echo '<script type="text/javascript" >' . 'var didsome=false;' . 'jQuery(document).ready(function() {' . 'jQuery(\'#wppa-spinner\').css(\'display\', \'none\');' . '});' . 'function myReload() {' . 'jQuery(\'#wppa-spinner\').css(\'display\', \'block\');' . '_wppaRefreshAfter = true;' . '};' . 'function wppaSetFixed(id) {' . 'if (jQuery(\'#wppa-widget-photo-\' + id).attr(\'checked\') == \'checked\' ) {' . '_wppaRefreshAfter = true;' . 'wppaAjaxUpdateOptionValue(\'potd_photo\', id);' . '}' . '};' . '</script>';
    // The spinner
    echo '<img' . ' id="wppa-spinner"' . ' style="position:fixed;top:50%;left:50%;z-index:1000;margin-top:-33px;margin-left:-33px;display:block;"' . ' src="' . wppa_get_imgdir('loader.gif') . '"' . '/>';
    // Open wrapper
    echo '<div class="wrap">';
    // The settings icon
    echo '<img src="' . wppa_get_imgdir('settings32.png') . '" />';
    // The Page title
    echo '<h1 style="display:inline;" >' . __('Photo of the Day (Widget) Settings', 'wp-photo-album-plus') . '</h1>' . __('Changes are updated immediately. The page will reload if required.', 'wp-photo-album-plus') . '<br />&nbsp;';
    // The nonce
    wp_nonce_field('wppa-nonce', 'wppa-nonce');
    // The settings table
    echo '<table class="widefat wppa-table wppa-setting-table">';
    // The header
    echo '<thead style="font-weight: bold; " class="wppa_table_1">' . '<tr>' . '<td>' . __('#', 'wp-photo-album-plus') . '</td>' . '<td>' . __('Name', 'wp-photo-album-plus') . '</td>' . '<td>' . __('Description', 'wp-photo-album-plus') . '</td>' . '<td>' . __('Setting', 'wp-photo-album-plus') . '</td>' . '<td>' . __('Help', 'wp-photo-album-plus') . '</td>' . '</tr>' . '</thead>';
    // Open the table body
    echo '<tbody class="wppa_table" >';
    $name = __('Widget Title:', 'wp-photo-album-plus');
    $desc = __('The title of the widget.', 'wp-photo-album-plus');
    $help = esc_js(__('Enter/modify the title for the widget. This is a default and can be overriden at widget activation.', 'wp-photo-album-plus'));
    $slug = 'wppa_potd_title';
    $html = wppa_input($slug, '85%');
    wppa_setting($slug, '1', $name, $desc, $html, $help);
    $name = __('Widget Photo Width:', 'wp-photo-album-plus');
    $desc = __('Enter the desired display width of the photo in the sidebar.', 'wp-photo-album-plus');
    $help = '';
    $slug = 'wppa_potd_widget_width';
    $html = wppa_input($slug, '40px', '', __('pixels wide', 'wp-photo-album-plus'));
    wppa_setting($slug, '2', $name, $desc, $html, $help);
    $name = __('Horizontal alignment:', 'wp-photo-album-plus');
    $desc = __('Enter the desired display alignment of the photo in the sidebar.', 'wp-photo-album-plus');
    $help = '';
    $slug = 'wppa_potd_align';
    $opts = array(__('--- none ---', 'wp-photo-album-plus'), __('left', 'wp-photo-album-plus'), __('center', 'wp-photo-album-plus'), __('right', 'wp-photo-album-plus'));
    $vals = array('none', 'left', 'center', 'right');
    $html = wppa_select($slug, $opts, $vals);
    wppa_setting($slug, '3', $name, $desc, $html, $help);
    $linktype = wppa_opt('potd_linktype');
    if ($linktype == 'custom') {
        $name = __('Link to:', 'wp-photo-album-plus');
        $desc = __('Enter the url. Do\'nt forget the HTTP://', 'wp-photo-album-plus');
        $help = '';
        $slug = 'wppa_potd_linkurl';
        $html = wppa_input($slug, '85%');
        wppa_setting($slug, '4', $name, $desc, $html, $help);
        $name = __('Link Title:', 'wp-photo-album-plus');
        $desc = __('The balloon text when hovering over the photo.', 'wp-photo-album-plus');
        $help = '';
        $slug = 'wppa_potd_linktitle';
        $html = wppa_input($slug, '85%');
        wppa_setting($slug, '4a', $name, $desc, $html, $help);
    } else {
        $name = __('Link to:', 'wp-photo-album-plus');
        $desc = __('Links are set on the <b>Photo Albums -> Settings</b> screen.', 'wp-photo-album-plus');
        $help = '';
        $slug = 'wppa_potd_linkurl';
        $html = '';
        wppa_setting($slug, '4', $name, $desc, $html, $help);
    }
    $name = __('Subtitle:', 'wp-photo-album-plus');
    $desc = __('Select the content of the subtitle.', 'wp-photo-album-plus');
    $help = '';
    $slug = 'wppa_potd_subtitle';
    $opts = array(__('--- none ---', 'wp-photo-album-plus'), __('Photo Name', 'wp-photo-album-plus'), __('Description', 'wp-photo-album-plus'), __('Owner', 'wp-photo-album-plus'));
    $vals = array('none', 'name', 'desc', 'owner');
    $html = wppa_select($slug, $opts, $vals);
    wppa_setting($slug, '5', $name, $desc, $html, $help);
    $name = __('Counter:', 'wp-photo-album-plus');
    $desc = __('Display a counter of other photos in the album.', 'wp-photo-album-plus');
    $help = '';
    $slug = 'wppa_potd_counter';
    $html = wppa_checkbox($slug);
    wppa_setting($slug, '6', $name, $desc, $html, $help);
    $name = __('Link to:', 'wp-photo-album-plus');
    $desc = __('The counter links to.', 'wp-photo-album-plus');
    $help = '';
    $slug = 'wppa_potd_counter_link';
    $opts = array(__('thumbnails', 'wp-photo-album-plus'), __('slideshow', 'wp-photo-album-plus'), __('single image', 'wp-photo-album-plus'));
    $vals = array('thumbs', 'slide', 'single');
    $html = wppa_select($slug, $opts, $vals);
    wppa_setting($slug, '7', $name, $desc, $html, $help);
    $name = __('Type of album(s) to use:', 'wp-photo-album-plus');
    $desc = __('Select physical or virtual.', 'wp-photo-album-plus');
    $help = '';
    $slug = 'wppa_potd_album_type';
    $opts = array(__('physical albums', 'wp-photo-album-plus'), __('virtual albums', 'wp-photo-album-plus'));
    $vals = array('physical', 'virtual');
    $html = wppa_select($slug, $opts, $vals, $onch);
    wppa_setting($slug, '8', $name, $desc, $html, $help);
    $name = __('Albums to use:', 'wp-photo-album-plus');
    $desc = __('Select the albums to use for the photo of the day.', 'wp-photo-album-plus');
    $help = '';
    $slug = 'wppa_potd_album';
    if (get_option('wppa_potd_album_type') == 'physical') {
        $html = '<select' . ' id="wppa_potd_album"' . ' name="wppa_potd_album"' . ' style="float:left; max-width: 100%;"' . ' multiple="multiple"' . ' onchange="didsome=true;wppaAjaxUpdateOptionValue(\'potd_album\', this, true)"' . ' onmouseout="if(didsome)document.location.reload(true);"' . ' size="10"' . ' >' . wppa_album_select_a(array('path' => true, 'optionclass' => 'potd_album', 'selected' => get_option('wppa_potd_album'))) . '</select>' . '<img id="img_potd_album" class="" src="' . wppa_get_imgdir() . 'star.ico" title="' . __('Setting unmodified', 'wp-photo-album-plus') . '" style="padding:0 4px; float:left; height:16px; width:16px;" />';
        wppa_setting($slug, '9', $name, $desc, $html, $help);
    } else {
        $desc = __('Select the albums to use for the photo of the day.', 'wp-photo-album-plus');
        $opts = array(__('- all albums -', 'wp-photo-album-plus'), __('- all -separate- albums -', 'wp-photo-album-plus'), __('- all albums except -separate-', 'wp-photo-album-plus'), __('- top rated photos -', 'wp-photo-album-plus'));
        $vals = array('all', 'sep', 'all-sep', 'topten');
        $html = wppa_select($slug, $opts, $vals);
        wppa_setting($slug, '9', $name, $desc, $html, $help);
    }
    if (get_option('wppa_potd_album_type') == 'physical') {
        $name = __('Include (grand)children:', 'wp-photo-album-plus');
        $desc = __('Include the photos of all sub albums?', 'wp-photo-album-plus');
        $help = '';
        $slug = 'wppa_potd_include_subs';
        $html = wppa_checkbox($slug, $onch);
        wppa_setting($slug, '9a', $name, $desc, $html, $help);
        $name = __('Inverse selection:', 'wp-photo-album-plus');
        $desc = __('Use any album, except the selection made above.', 'wp-photo-album-plus');
        $help = '';
        $slug = 'wppa_potd_inverse';
        $html = wppa_checkbox($slug, $onch);
        wppa_setting($slug, '9b', $name, $desc, $html, $help);
    }
    $name = __('Status filter:', 'wp-photo-album-plus');
    $desc = __('Use only photos with a certain status.', 'wp-photo-album-plus');
    $help = esc_js(__('Select - none - if you want no filtering on status.', 'wp-photo-album-plus'));
    $slug = 'wppa_potd_status_filter';
    $opts = array(__('- none -', 'wp-photo-album-plus'), __('Publish', 'wp-photo-album-plus'), __('Featured', 'wp-photo-album-plus'), __('Gold', 'wp-photo-album-plus'), __('Silver', 'wp-photo-album-plus'), __('Bronze', 'wp-photo-album-plus'), __('Any medal', 'wp-photo-album-plus'));
    $vals = array('none', 'publish', 'featured', 'gold', 'silver', 'bronze', 'anymedal');
    $html = wppa_select($slug, $opts, $vals);
    wppa_setting($slug, '10', $name, $desc, $html, $help);
    $name = __('Display method:', 'wp-photo-album-plus');
    $desc = __('Select the way a photo will be selected.', 'wp-photo-album-plus');
    $help = '';
    $slug = 'wppa_potd_method';
    $opts = array(__('Fixed photo', 'wp-photo-album-plus'), __('Random', 'wp-photo-album-plus'), __('Last upload', 'wp-photo-album-plus'), __('Change every', 'wp-photo-album-plus'));
    $vals = array('1', '2', '3', '4');
    $html = wppa_select($slug, $opts, $vals, $onch);
    wppa_setting($slug, '11', $name, $desc, $html, $help);
    if (get_option('wppa_potd_method') == '4') {
        // Change every
        $name = __('Change every period:', 'wp-photo-album-plus');
        $desc = __('The time period a certain photo is used.', 'wp-photo-album-plus');
        $help = '';
        $slug = 'wppa_potd_period';
        $opts = array(__('pageview.', 'wp-photo-album-plus'), __('hour.', 'wp-photo-album-plus'), __('day.', 'wp-photo-album-plus'), __('week.', 'wp-photo-album-plus'), __('month.', 'wp-photo-album-plus'), __('day of week is order#', 'wp-photo-album-plus'), __('day of month is order#', 'wp-photo-album-plus'), __('day of year is order#', 'wp-photo-album-plus'));
        $vals = array('0', '1', '24', '168', '736', 'day-of-week', 'day-of-month', 'day-of-year');
        $html = wppa_select($slug, $opts, $vals, $onch);
        wppa_setting($slug, '11a', $name, $desc, $html, $help);
        $wppa_widget_period = get_option('wppa_potd_period');
        if (substr($wppa_widget_period, 0, 7) == 'day-of-') {
            switch (substr($wppa_widget_period, 7)) {
                case 'week':
                    $n_days = '7';
                    $date_key = 'w';
                    break;
                case 'month':
                    $n_days = '31';
                    $date_key = 'd';
                    break;
                case 'year':
                    $n_days = '366';
                    $date_key = 'z';
                    break;
            }
            while (get_option('wppa_potd_offset', '0') > $n_days) {
                update_option('wppa_potd_offset', get_option('wppa_potd_offset') - $n_days);
            }
            while (get_option('wppa_potd_offset', '0') < '0') {
                update_option('wppa_potd_offset', get_option('wppa_potd_offset') + $n_days);
            }
            $name = __('Day offset:', 'wp-photo-album-plus');
            $desc = __('The difference between daynumber and photo order number.', 'wp-photo-album-plus');
            $help = '';
            $slug = 'wppa_potd_offset';
            $opts = array();
            $day = '0';
            while ($day < $n_days) {
                $opts[] = $day;
                $day++;
            }
            $vals = $opts;
            $html = '<span style="float:left;" >' . sprintf(__('Current day# = %s, offset =', 'wp-photo-album-plus'), wppa_local_date($date_key)) . '</span> ' . wppa_select($slug, $opts, $vals, $onch);
            $photo_order = wppa_local_date($date_key) - get_option('wppa_potd_offset', '0');
            while ($photo_order < '0') {
                $photo_order += $n_days;
            }
            $html .= sprintf(__('Todays photo order# = %s.', 'wp-photo-album-plus'), $photo_order);
            wppa_setting($slug, '11b', $name, $desc, $html, $help);
        }
    }
    $name = __('Preview', 'wp-photo-album-plus');
    $desc = __('Current "photo of the day":', 'wp-photo-album-plus');
    $help = '';
    $slug = 'wppa_potd_photo';
    $photo = wppa_get_potd();
    if ($photo) {
        $html = '<div style="display:inline-block;width:25%;text-align:center;vertical-align:middle;">' . '<img src="' . wppa_fix_poster_ext(wppa_get_thumb_url($photo['id']), $photo['id']) . '" />' . '</div>' . '<div style="display:inline-block;width:75%;text-align:center;vertical-align:middle;" >' . __('Album', 'wp-photo-album-plus') . ': ' . wppa_get_album_name($photo['album']) . '<br />' . __('Uploader', 'wp-photo-album-plus') . ': ' . $photo['owner'] . '</div>';
    } else {
        $html = __('Not found.', 'wp-photo-album-plus');
    }
    wppa_setting($slug, '12', $name, $desc, $html, $help);
    $name = __('Show selection', 'wp-photo-album-plus');
    $desc = __('Show the photos in the current selection.', 'wp-photo-album-plus');
    $help = '';
    $slug = 'wppa_potd_preview';
    $html = wppa_checkbox($slug, $onch);
    wppa_setting($slug, '13', $name, $desc, $html, $help);
    // Cose table body
    echo '</tbody>';
    // Table footer
    echo '<tfoot style="font-weight: bold;" >' . '<tr>' . '<td>' . __('#', 'wp-photo-album-plus') . '</td>' . '<td>' . __('Name', 'wp-photo-album-plus') . '</td>' . '<td>' . __('Description', 'wp-photo-album-plus') . '</td>' . '<td>' . __('Setting', 'wp-photo-album-plus') . '</td>' . '<td>' . __('Help', 'wp-photo-album-plus') . '</td>' . '</tr>' . '</tfoot>' . '</table>';
    // Diagnostic
    //		echo
    //		'Diagnostic: wppa_potd_album = ' . get_option( 'wppa_potd_album' ) . ' wppa_potd_photo = ' . get_option( 'wppa_potd_photo' );
    // Status star must be here for js
    echo '<img' . ' id="img_potd_photo"' . ' src="' . wppa_get_imgdir('star.ico') . '" style="height:12px;display:none;"' . ' />';
    // The potd photo pool
    echo '<table class="widefat wppa-table wppa-setting-table" >';
    // Table header
    echo '<thead>' . '<tr>' . '<td>' . __('Photos in the current selection', 'wp-photo-album-plus') . '</td>' . '</tr>' . '</thead>';
    // Table body
    if (wppa_switch('potd_preview')) {
        echo '<tbody>' . '<tr>' . '<td>';
        // Get the photos
        $alb = wppa_opt('potd_album');
        $opt = wppa_is_int($alb) ? ' ' . wppa_get_photo_order($alb) . ' ' : '';
        $photos = wppa_get_widgetphotos($alb, $opt);
        // Count them
        $cnt = count($photos);
        // Find current
        $curid = wppa_opt('potd_photo');
        // See if we do this
        if (empty($photos)) {
            _e('No photos in the selection', 'wp-photo-album-plus');
        } elseif ($cnt > '5000') {
            echo sprintf(__('There are too many photos in the selection to show a preview ( %d )', 'wp-photo-album-plus'), $cnt);
        } else {
            // Yes, display the pool
            foreach ($photos as $photo) {
                $id = $photo['id'];
                // Open container div
                echo '<div' . ' class="photoselect"' . ' style="' . 'width:180px;' . 'height:300px;' . '" >';
                // Open image container div
                echo '<div' . ' style="' . 'width:180px;' . 'height:135px;' . 'overflow:hidden;' . 'text-align:center;' . '" >';
                // The image if a video
                if (wppa_is_video($id)) {
                    echo wppa_get_video_html(array('id' => $id, 'style' => 'width:180px;'));
                } else {
                    echo '<img' . ' src=" ' . wppa_fix_poster_ext(wppa_get_thumb_url($id), $id) . '"' . ' style="' . 'max-width:180px;' . 'max-height:135px;' . 'margin:auto;' . '"' . ' alt="' . esc_attr(wppa_get_photo_name($id)) . '" />';
                    // Audio ?
                    if (wppa_has_audio($id)) {
                        echo wppa_get_audio_html(array('id' => $id, 'style' => 'width:180px;' . 'position:relative;' . 'bottom:' . (wppa_get_audio_control_height() + 4) . 'px;'));
                    }
                }
                // Close image container div
                echo '</div>';
                // The order# and select radio box
                echo '<div style="clear:both;width:100%;margin:3px 0;position:relative;top:5px;" >' . '<div style="font-size:9px; line-height:10px;float:left;">(#' . $photo['p_order'] . ')</div>';
                if (get_option('wppa_potd_method') == '1') {
                    // Only if fixed photo
                    echo '<input' . ' style="float:right;"' . ' type="radio"' . ' name="wppa-widget-photo"' . ' id="wppa-widget-photo-' . $id . '"' . ' value="' . $id . '"' . ($id == $curid ? 'checked="checked"' : '') . ' onchange="wppaSetFixed(' . $id . ');"' . ' />';
                }
                echo '</div>';
                // The name/desc boxecho
                echo '<div style="clear:both;overflow:hidden;height:150px;position:relative;top:10px;" >' . '<div style="font-size:11px; overflow:hidden;">' . wppa_get_photo_name($id) . '</div>' . '<div style="font-size:9px; line-height:10px;">' . wppa_get_photo_desc($id) . '</div>' . '</div>';
                // Close container
                echo '</div>';
            }
            echo '<div class="clear"></div>';
        }
        // Close the table
        echo '</td>' . '</tr>' . '</tbody>';
    }
    echo '</table>';
    // Close wrap
    echo '</div>';
}
function wppa_do_maintenance_popup($slug)
{
    global $wpdb;
    $result = '';
    switch ($slug) {
        case 'wppa_list_index':
            $start = get_option('wppa_list_index_display_start', '');
            $total = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_INDEX . "`");
            $indexes = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_INDEX . "` WHERE `slug` >= %s ORDER BY `slug` LIMIT 1000", $start), ARRAY_A);
            $result .= '
			<style>td, th { border-right: 1px solid darkgray; } </style>
			<h2>List of Searcheable words <small>( Max 1000 entries of total ' . $total . ' )</small></h2>
			<div style="float:left; clear:both; width:100%; overflow:auto; background-color:#f1f1f1; border:1px solid #ddd;" >';
            if ($indexes) {
                $result .= '
				<table>
					<thead>
						<tr>
							<th><span style="float:left;" >Word</span></th>
							<th style="max-width:400px;" ><span style="float:left;" >Albums</span></th>
							<th><span style="float:left;" >Photos</span></th>
						</tr>
						<tr><td colspan="3"><hr /></td></tr>
					</thead>
					<tbody>';
                foreach ($indexes as $index) {
                    $result .= '
						<tr>
							<td>' . $index['slug'] . '</td>
							<td style="max-width:400px; word-wrap: break-word;" >' . $index['albums'] . '</td>
							<td>' . $index['photos'] . '</td>
						</tr>';
                }
                $result .= '
					</tbody>
				</table>';
            } else {
                $result .= __('There are no index items.', 'wp-photo-album-plus');
            }
            $result .= '
				</div><div style="clear:both;"></div>';
            break;
        case 'wppa_list_errorlog':
            $filename = WPPA_CONTENT_PATH . '/wppa-depot/admin/error.log';
            $result .= '
				<h2>List of WPPA+ error messages</h2>
				<div style="float:left; clear:both; width:100%; overflow:auto; word-wrap:none; background-color:#f1f1f1; border:1px solid #ddd;" >';
            if (!($file = @fopen($filename, 'r'))) {
                $result .= __('There are no error log messages', 'wp-photo-album-plus');
            } else {
                $size = filesize($filename);
                $data = fread($file, $size);
                $data = htmlspecialchars(strip_tags($data));
                $data = str_replace(array('{b}', '{/b}', "\n"), array('<b>', '</b>', '<br />'), $data);
                $result .= $data;
                fclose($file);
            }
            $result .= '
				</div><div style="clear:both;"></div>
				';
            break;
        case 'wppa_list_rating':
            $total = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_RATING . "`");
            $ratings = $wpdb->get_results("SELECT * FROM `" . WPPA_RATING . "` ORDER BY `timestamp` DESC LIMIT 1000", ARRAY_A);
            $result .= '
			<style>td, th { border-right: 1px solid darkgray; } </style>
			<h2>List of recent ratings <small>( Max 1000 entries of total ' . $total . ' )</small></h2>
			<div style="float:left; clear:both; width:100%; overflow:auto; background-color:#f1f1f1; border:1px solid #ddd;" >';
            if ($ratings) {
                $result .= '
				<table>
					<thead>
						<tr>
							<th>Id</th>
							<th>Timestamp</th>
							<th>Date/time</th>
							<th>Status</th>
							<th>User</th>
							<th>Value</th>
							<th>Photo id</th>
							<th></th>
							<th># ratings</th>
							<th>Average</th>
						</tr>
						<tr><td colspan="10"><hr /></td></tr>
					</thead>
					<tbody>';
                foreach ($ratings as $rating) {
                    $thumb = wppa_cache_thumb($rating['photo']);
                    $result .= '
						<tr>
							<td>' . $rating['id'] . '</td>
							<td>' . $rating['timestamp'] . '</td>
							<td>' . ($rating['timestamp'] ? wppa_local_date(get_option('date_format', "F j, Y,") . ' ' . get_option('time_format', "g:i a"), $rating['timestamp']) : 'pre-historic') . '</td>
							<td>' . $rating['status'] . '</td>
							<td>' . $rating['user'] . '</td>
							<td>' . $rating['value'] . '</td>
							<td>' . $rating['photo'] . '</td>
							<td style="width:250px; text-align:center;"><img src="' . wppa_get_thumb_url($rating['photo']) . '"
								style="height: 40px;"
								onmouseover="jQuery(this).stop().animate({height:this.naturalHeight}, 200);"
								onmouseout="jQuery(this).stop().animate({height:\'40px\'}, 200);" /></td>
							<td>' . $thumb['rating_count'] . '</td>
							<td>' . $thumb['mean_rating'] . '</td>
						</tr>';
                }
                $result .= '
					</tbody>
				</table>';
            } else {
                $result .= __('There are no ratings', 'wp-photo-album-plus');
            }
            $result .= '
				</div><div style="clear:both;"></div>';
            break;
        case 'wppa_list_session':
            $total = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_SESSION . "` WHERE `status` = 'valid'");
            $sessions = $wpdb->get_results("SELECT * FROM `" . WPPA_SESSION . "` WHERE `status` = 'valid' ORDER BY `id` DESC LIMIT 1000", ARRAY_A);
            $result .= '
			<style>td, th { border-right: 1px solid darkgray; } </style>
			<h2>List of active sessions <small>( Max 1000 entries of total ' . $total . ' )</small></h2>
			<div style="float:left; clear:both; width:100%; overflow:auto; background-color:#f1f1f1; border:1px solid #ddd;" >';
            if ($sessions) {
                $result .= '
				<table>
					<thead>
						<tr>
							<th>Id</th>
							<th>Session id</th>
							<th>IP</th>
							<th>Started</th>
							<th>Count</th>
							<th>Data</th>
						</tr>
						<tr><td colspan="14"><hr /></td></tr>
					</thead>
					<tbody>';
                foreach ($sessions as $session) {
                    $data = unserialize($session['data']);
                    $result .= '
							<tr>
								<td>' . $session['id'] . '</td>
								<td>' . $session['session'] . '</td>
								<td>' . $session['ip'] . '</td>
								<td style="width:150px;" >' . wppa_local_date(get_option('date_format', "F j, Y,") . ' ' . get_option('time_format', "g:i a"), $session['timestamp']) . '</td>
								<td>' . $session['count'] . '</td>' . '<td style="border-bottom:1px solid gray;" >';
                    foreach (array_keys($data) as $key) {
                        if (is_array($data[$key])) {
                            $result .= '[' . $key . '] => Array(' . implode(',', array_keys($data[$key])) . ')<br />';
                        } else {
                            $result .= '[' . $key . '] => ' . $data[$key] . '<br />';
                        }
                    }
                    '</td>
							</tr>';
                }
                $result .= '
					</tbody>
				</table>';
            } else {
                $result .= __('There are no active sessions', 'wp-photo-album-plus');
            }
            $result .= '
				</div><div style="clear:both;"></div>';
            break;
        default:
            $result = 'Error: Unimplemented slug: ' . $slug . ' in wppa_do_maintenance_popup()';
    }
    return $result;
}