<?php
/*************************
  Coppermine Photo Gallery
  ************************
  Copyright (c) 2003-2005 Coppermine Dev Team
  v1.1 originaly written by Gregory DEMAR

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.
  
  This version with shop hack by madeinhawaii, adapted by casper.
  ********************************************
  Coppermine version: 1.4.3
  $Source: /cvsroot/coppermine/stable/displayimage.php,v $
  $Revision: 1.20 $
  $Author: tranzndance $
  $Date: 2005/12/27 20:06:13 $
**********************************************/

define('IN_COPPERMINE', true);
define('DISPLAYIMAGE_PHP', true);
define('INDEX_PHP', true);
//define('SMILIES_PHP', true);

require('include/init.inc.php');

if (!USER_ID && $CONFIG['allow_unlogged_access'] == 0) {
    $redirect = $redirect . "login.php";
    header("Location: $redirect");
    exit();
}

if ($CONFIG['enable_smilies']) include("include/smilies.inc.php");

$breadcrumb = '';
$breadcrumb_text = '';
$cat_data = array();

if($CONFIG['read_exif_data'] ){
        include("include/exif_php.inc.php");
}
if($CONFIG['read_iptc_data'] ){
        include("include/iptc.inc.php");
}


/**
 * Local functions definition
 */

# Sanitize the data - to fix the XSS vulnerability - Aditya
function sanitize_data(&$value, $key)
{
	if (is_array($value)) {
		array_walk($value, 'sanitize_data');
	} else {
		# sanitize against sql/html injection; trim any nongraphical non-ASCII character:
		$value = trim(htmlentities(strip_tags(trim($value,"\x7f..\xff\x0..\x1f")),ENT_QUOTES));
	}
}
function html_picture_menu()
{
    global $lang_display_image_php, $CURRENT_PIC_DATA, $CURRENT_ALBUM_DATA, $CONFIG;

    $mime_content = cpg_get_type($CURRENT_PIC_DATA['filename']);
    $picmenu = '';

  if (false) { //(!($mime_content['content']=='image')) {
    $picmenu = <<<EOT
     <a href="#" onclick="return MM_openBrWindow('setplayer.php?={$mime_content['extension']}','Set_Player','scrollbars=no,toolbar=no,status=no,resizable=no')" class="admin_menu" >{$lang_display_image_php['set_player']}</a>
EOT;
  }

  if ((USER_ADMIN_MODE && $CURRENT_ALBUM_DATA['category'] == FIRST_USER_CAT + USER_ID) || ($CONFIG['users_can_edit_pics'] && $CURRENT_PIC_DATA['owner_id'] == USER_ID && USER_ID != 0) || GALLERY_ADMIN_MODE) {
    $picmenu .= <<<EOT
     <a href="javascript:;" onclick="return MM_openBrWindow('picEditor.php?id={$CURRENT_PIC_DATA['pid']}','Crop_Picture','scrollbars=yes,toolbar=no,status=yes,resizable=yes')" class="admin_menu" >{$lang_display_image_php['crop_pic']}</a> <a href="editOnePic.php?id={$CURRENT_PIC_DATA['pid']}&amp;what=picture"  class="admin_menu">{$lang_display_image_php['edit_pic']}</a> <a href="delete.php?id={$CURRENT_PIC_DATA['pid']}&amp;what=picture"  class="admin_menu" onclick="return confirm('{$lang_display_image_php['confirm_del']}'); return false; ">{$lang_display_image_php['del_pic']}</a>
EOT;
  }

  return $picmenu;
}

// Display picture information
function html_picinfo()
{
    global $CONFIG, $CURRENT_PIC_DATA, $CURRENT_ALBUM_DATA, $THEME_DIR, $FAVPICS;
    global $album, $lang_picinfo, $lang_display_image_php, $lang_byte_units, $lastup_date_fmt;

    if ($CURRENT_PIC_DATA['owner_id'] && $CURRENT_PIC_DATA['owner_name']) {
        $owner_link = '<a href ="profile.php?uid=' . $CURRENT_PIC_DATA['owner_id'] . '">' . $CURRENT_PIC_DATA['owner_name'] . '</a> ';
    } else {
        $owner_link = '';
    }

    if (GALLERY_ADMIN_MODE && $CURRENT_PIC_DATA['pic_raw_ip']) {
        if ($CURRENT_PIC_DATA['pic_hdr_ip']) {
            $ipinfo = ' (' . $CURRENT_PIC_DATA['pic_hdr_ip'] . '[' . $CURRENT_PIC_DATA['pic_raw_ip'] . ']) / ';
        } else {
            $ipinfo = ' (' . $CURRENT_PIC_DATA['pic_raw_ip'] . ') / ';
        }
    } else {
        if ($owner_link) {
            $ipinfo = '/ ';
        } else {
            $ipinfo = '';
        }
    }

    $info[$lang_picinfo['Filename']] = htmlspecialchars($CURRENT_PIC_DATA['filename']);
    $info[$lang_picinfo['Album name']] = '<span class="alblink">' . $owner_link . $ipinfo . '<a href="thumbnails.php?album=' . $CURRENT_PIC_DATA['aid'] . '">' . $CURRENT_ALBUM_DATA['title'] . '</a></span>';

    if ($CURRENT_PIC_DATA['votes'] > 0) {
        if (defined('THEME_HAS_RATING_GRAPHICS')) {
            $prefix = $THEME_DIR;
        } else {
            $prefix = '';
        }
        if (GALLERY_ADMIN_MODE) {
          $width = 800;
          $height = 500;
        } else {
          $width = 700;
          $height = 250;
        }

        $detailsLink = $CONFIG['vote_details'] ? ' (<a href="#" onclick="MM_openBrWindow(\'stat_details.php?type=vote&amp;pid='.$CURRENT_PIC_DATA['pid'].'&amp;sort=sdate&amp;dir=&amp;sdate=1&amp;ip=1&amp;rating=1&amp;referer=1&amp;browser=1&amp;os=1\',\'\',\'resizable=yes,width='.$width.',height='.$height.',top=50,left=50,scrollbars=yes\'); return false;">'.$lang_picinfo['details'].'</a>)' : '';
        $info[sprintf($lang_picinfo['Rating'], $CURRENT_PIC_DATA['votes'])] = '<img src="' . $prefix . 'images/rating' . round($CURRENT_PIC_DATA['pic_rating'] / 2000) . '.gif" align="middle" alt="" />'.$detailsLink;
    }

    if ($CURRENT_PIC_DATA['keywords'] != "") {
        $info[$lang_picinfo['Keywords']] = '<span class="alblink">' . preg_replace("/(\S+)/", "<a href=\"thumbnails.php?album=search&amp;search=\\1\">\\1</a>" , $CURRENT_PIC_DATA['keywords']) . '</span>';
    }

    for ($i = 1; $i <= 4; $i++) {
        if ($CONFIG['user_field' . $i . '_name']) {
            if ($CURRENT_PIC_DATA['user' . $i] != "") {
                $info[$CONFIG['user_field' . $i . '_name']] = make_clickable($CURRENT_PIC_DATA['user' . $i]);
            }
        }
    }

    $info[$lang_picinfo['File Size']] = ($CURRENT_PIC_DATA['filesize'] > 10240 ? ($CURRENT_PIC_DATA['filesize'] >> 10) . '&nbsp;' . $lang_byte_units[1] : $CURRENT_PIC_DATA['filesize'] . '&nbsp;' . $lang_byte_units[0]);
    $info[$lang_picinfo['File Size']] = '<span dir="ltr">' . $info[$lang_picinfo['File Size']] . '</span>';
    $info[$lang_picinfo['Date Added']] = localised_date($CURRENT_PIC_DATA['ctime'],$lastup_date_fmt);
    $info[$lang_picinfo['Dimensions']] = sprintf($lang_display_image_php['size'], $CURRENT_PIC_DATA['pwidth'], $CURRENT_PIC_DATA['pheight']);
    $detailsLink = ($CURRENT_PIC_DATA['hits'] && $CONFIG['vote_details'] && GALLERY_ADMIN_MODE) ? ' (<a href="#" onclick="MM_openBrWindow(\'stat_details.php?type=hits&amp;pid='.$CURRENT_PIC_DATA['pid'].'&amp;sort=sdate&amp;dir=&amp;sdate=1&amp;ip=1&amp;search_phrase=1&amp;referer=1&amp;browser=1&amp;os=1\',\'\',\'resizable=yes,width=800,height=500,top=50,left=50,scrollbars=yes\'); return false;">'.$lang_picinfo['details'].'</a>)' : '';
    $info[$lang_picinfo['Displayed']] = sprintf($lang_display_image_php['views'], $CURRENT_PIC_DATA['hits']);
    $info[$lang_picinfo['Displayed']] .= $detailsLink;

    $path_to_pic = $CONFIG['fullpath'] . $CURRENT_PIC_DATA['filepath'] . $CURRENT_PIC_DATA['filename'];

    if ($CONFIG['read_exif_data']) $exif = exif_parse_file($path_to_pic);

    if (isset($exif) && is_array($exif)) {
		array_walk($exif, 'sanitize_data');
        $info = array_merge($info,$exif);
    }

    if ($CONFIG['read_iptc_data']) $iptc = get_IPTC($path_to_pic);

    if (isset($iptc) && is_array($iptc)) {
		array_walk($iptc, 'sanitize_data');
        if (isset($iptc['Title'])) $info[$lang_picinfo['iptcTitle']] = $iptc['Title'];
        if (isset($iptc['Copyright'])) $info[$lang_picinfo['iptcCopyright']] = $iptc['Copyright'];
        if (!empty($iptc['Keywords'])) $info[$lang_picinfo['iptcKeywords']] = implode(' ',$iptc['Keywords']);
        if (isset($iptc['Category'])) $info[$lang_picinfo['iptcCategory']] = $iptc['Category'];
        if (!empty($iptc['SubCategories'])) $info[$lang_picinfo['iptcSubCategories']] = implode(' ',$iptc['SubCategories']);
    }
    // Create the absolute URL for display in info
    $info[$lang_picinfo['URL']] = '<a href="' . $CONFIG["ecards_more_pic_target"] . (substr($CONFIG["ecards_more_pic_target"], -1) == '/' ? '' : '/') .basename($_SERVER['PHP_SELF']) . "?pos=-$CURRENT_PIC_DATA[pid]" . '" >' . $CONFIG["ecards_more_pic_target"] . (substr($CONFIG["ecards_more_pic_target"], -1) == '/' ? '' : '/') . basename($_SERVER['PHP_SELF']) . "?pos=-$CURRENT_PIC_DATA[pid]" . '</a>';
    // with subdomains the variable is $_SERVER["SERVER_NAME"] does not return the right value instead of using a new config variable I reused $CONFIG["ecards_more_pic_target"] no trailing slash in the configure
    // Create the add to fav link
    if (!in_array($CURRENT_PIC_DATA['pid'], $FAVPICS)) {
        $info[$lang_picinfo['addFavPhrase']] = "<a href=\"addfav.php?pid=" . $CURRENT_PIC_DATA['pid'] . "\" >" . $lang_picinfo['addFav'] . '</a>';
    } else {
        $info[$lang_picinfo['addFavPhrase']] = "<a href=\"addfav.php?pid=" . $CURRENT_PIC_DATA['pid'] . "\" >" . $lang_picinfo['remFav'] . '</a>';
    }

    /**
     * Filter file information
     */
    $info = CPGPluginAPI::filter('file_info',$info);

    return theme_html_picinfo($info);
}

function get_subcat_data($parent, $level)
{
    global $CONFIG, $ALBUM_SET_ARRAY;

    $result = cpg_db_query("SELECT cid, name, description FROM {$CONFIG['TABLE_CATEGORIES']} WHERE parent = '$parent'");
    if (mysql_num_rows($result) > 0) {
        $rowset = cpg_db_fetch_rowset($result);
        foreach ($rowset as $subcat) {
            $result = cpg_db_query("SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = {$subcat['cid']}");
            $album_count = mysql_num_rows($result);
            while ($row = mysql_fetch_array($result)) {
                $ALBUM_SET_ARRAY[] = $row['aid'];
            } // while
        }
        if ($level > 1) get_subcat_data($subcat['cid'], $level -1);
    }
}

/**
 * Main code
 */

$pos = isset($_GET['pos']) ? (int)$_GET['pos'] : 0;

/**
 * Hack added by tarique to prevent incorrect picture being seen on last view or last uploaded
 */

$pid = isset($_GET['pid']) ? (int)$_GET['pid'] : 0;

$cat = isset($_GET['cat']) ? (int)$_GET['cat'] : 0;
$album = isset($_GET['album']) ? $_GET['album'] : '';
// Build the album set if required
/*
//disabled by donnoman
if (!is_numeric($album) && $cat) { // Meta albums, we need to restrict the albums to the current category
    if ($cat < 0) {
        $ALBUM_SET .= 'AND aid IN (' . (- $cat) . ') ';
    } else {
        $ALBUM_SET_ARRAY = array();
        if ($cat == USER_GAL_CAT)
            $where = 'category > ' . FIRST_USER_CAT;
        else
            $where = "category = '$cat'";

        $result = cpg_db_query("SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE $where");
        while ($row = mysql_fetch_array($result)) {
            $ALBUM_SET_ARRAY[] = $row['aid'];
        } // while
        get_subcat_data($cat, $CONFIG['subcat_level']);
        // Treat the album set
        if (count($ALBUM_SET_ARRAY)) {
            $set = '';
            foreach ($ALBUM_SET_ARRAY as $album_id) $set .= ($set == '') ? $album_id : ',' . $album_id;
            $ALBUM_SET .= "AND aid IN ($set) ";
        }
    }
}
//disabled by donnoman
*/
//get_meta_album_set in functions.inc.php will populate the $ALBUM_SET instead; matches $META_ALBUM_SET.
get_meta_album_set($cat,$ALBUM_SET);
$META_ALBUM_SET = $ALBUM_SET; //displayimage uses $ALBUM_SET but get_pic_data in functions now uses $META_ALBUM_SET

//attempt to fix topn images for keyworded albums
if ($cat < 0) {
    $result = cpg_db_query("SELECT category, title, aid, keyword, description, alb_password_hint FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid='" . (- $cat) . "'");
    if (mysql_num_rows($result) > 0) {
        $CURRENT_ALBUM_DATA = mysql_fetch_array($result);
        $CURRENT_ALBUM_KEYWORD = $CURRENT_ALBUM_DATA['keyword'];
    }
}
// Retrieve data for the current picture
if ($pos < 0 || $pid > 0) {
    $pid = ($pos < 0) ? -$pos : $pid;
    $result = cpg_db_query("SELECT aid from {$CONFIG['TABLE_PICTURES']} WHERE pid='$pid' $ALBUM_SET LIMIT 1");
    if (mysql_num_rows($result) == 0) cpg_die(ERROR, $lang_errors['non_exist_ap'], __FILE__, __LINE__);
    $row = mysql_fetch_array($result);
    $album = $row['aid'];
    $pic_data = get_pic_data($album, $pic_count, $album_name, -1, -1, false);
    for($pos = 0; $pic_data[$pos]['pid'] != $pid && $pos < $pic_count; $pos++);
    $pic_data = get_pic_data($album, $pic_count, $album_name, $pos, 1, false);
    $CURRENT_PIC_DATA = $pic_data[0];

} elseif (isset($_GET['pos'])) {
    $pic_data = get_pic_data($album, $pic_count, $album_name, $pos, 1, false);
    if ($pic_count == 0) {
        cpg_die(INFORMATION, $lang_errors['no_img_to_display'], __FILE__, __LINE__);
    } elseif (count($pic_data) == 0 && $pos >= $pic_count) {
        $pos = $pic_count - 1;
        $human_pos = $pos + 1;
        $pic_data = get_pic_data($album, $pic_count, $album_name, $pos, 1, false);
    }
    $CURRENT_PIC_DATA = $pic_data[0];
}

// Retrieve data for the current album
if (isset($CURRENT_PIC_DATA)) {
    $result = cpg_db_query("SELECT title, comments, votes, category, aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid='{$CURRENT_PIC_DATA['aid']}' LIMIT 1");
    if (!mysql_num_rows($result)) cpg_die(CRITICAL_ERROR, sprintf($lang_errors['pic_in_invalid_album'], $CURRENT_PIC_DATA['aid']), __FILE__, __LINE__);
    $CURRENT_ALBUM_DATA = mysql_fetch_array($result);

    if (is_numeric($album)) {
        $cat = - $album;
        $actual_cat = $CURRENT_ALBUM_DATA['category'];
        breadcrumb($actual_cat, $breadcrumb, $breadcrumb_text);
        $cat = - $album;
    } else {
        $actual_cat = $CURRENT_ALBUM_DATA['category'];
        breadcrumb($actual_cat, $breadcrumb, $breadcrumb_text);
    }
}

if (isset($_GET['fullsize'])) {
    theme_display_fullsize_pic();
    ob_end_flush();
} elseif (isset($_GET['slideshow'])) {
    theme_slideshow();
    ob_end_flush();
} else {
    if (!isset($_GET['pos'])) cpg_die(ERROR, $lang_errors['non_exist_ap'], __FILE__, __LINE__);
    $picture_title = $CURRENT_PIC_DATA['title'] ? $CURRENT_PIC_DATA['title'] : strtr(preg_replace("/(.+)\..*?\Z/", "\\1", htmlspecialchars($CURRENT_PIC_DATA['filename'])), "_", " ");

    $nav_menu = theme_html_img_nav_menu();
    $picture = theme_html_picture();
    $votes = theme_html_rating_box();
    $pic_info = html_picinfo();
    $comments = theme_html_comments($CURRENT_PIC_DATA['pid']);
    if ($CURRENT_PIC_DATA['keywords']) { $meta_keywords = "<meta name=\"keywords\" content=\"".$CURRENT_PIC_DATA['keywords']."\"/>"; }
        //$meta_nav .= "<link rel=\"alternate\" type=\"text/xml\" title=\"RSS feed\" href=\"rss.php\" />
       // ";
        $meta_keywords .= $meta_nav;
    pageheader($album_name . '/' . $picture_title, $meta_keywords, false);
    // Display Breadcrumbs
    if ($breadcrumb && !(strpos($CONFIG['main_page_layout'],"breadcrumb")===false)) {
        theme_display_breadcrumb($breadcrumb, $cat_data);
    }
    // Display Filmstrip if the album is not search
    if ($album != 'search') {
        $film_strip = display_film_strip($album, (isset($cat) ? $cat : 0), $pos, true);
    }
    CPGPluginAPI::filter('post_breadcrumb',null);
    theme_display_image($nav_menu, $picture, $votes, $pic_info, $comments, $film_strip);
	
//BEGIN Paypal Mod

// Get picture thumbnail url
$pid = $CURRENT_PIC_DATA['pid'];
// Get picture url and some constants to use with this form
$result = cpg_db_query("SELECT * from {$CONFIG['TABLE_PICTURES']} WHERE pid='$pid' $ALBUM_SET");
if (!mysql_num_rows($result)) cpg_die(ERROR, $lang_errors['non_exist_ap'], __FILE__, __LINE__);
 $row = mysql_fetch_array($result);
   $pic_url = get_pic_url($row, 'fullsize');      // url to fullsize picture
   $pic_normal_url = get_pic_url($row, 'normal'); // url to intermediate sized picture
   $pic_thumb_url = get_pic_url($row, 'thumb');   // url to thumbnail
   $pic_title = $row['title'];   // file title
   $caption = $row['caption'];   // file caption
   $pic_id   = $row['filename']; // filename
   $aid = $row['aid'];     // album #
   $pwidth = $row['pwidth'];     // width of fullsize image
   $pheight = $row['pheight'];   // height of fullsize image
   $set_item = $row['title'];    // we will use this in our product descriptions.
   $user1 = $row['user1'];
   $user2 = $row['user2'] ;
   $user3 = $row['user3'];
   $user4 = $row['user4'];
   $keywords = $row['keywords'];


$result = cpg_db_query("SELECT * from {$CONFIG['TABLE_ALBUMS']} WHERE aid='$aid' $ALBUM_SET");
if (!mysql_num_rows($result)) cpg_die(ERROR, $lang_errors['non_exist_ap'], __FILE__, __LINE__);
   $row = mysql_fetch_array($result);
   $album=  $row['title'];

// Set paypal ID and currency type
   $paypal_ID = "{$CONFIG['paypal_email']}";
   $currency_code = "{$CONFIG[currency]}";
   $currency_sign = "{$CONFIG[currency_symbol]}";

// Set custom image description field to be used for setting price (Default is the first field or $user1, other options are $user2,$user3,and $user4).
   $pricing_setup = $user1;

// Set dropdown list options. EDIT these pairs to set your price and descriptions accordingly.
// IF/Else Set Pricing Block
if ($pricing_setup=="1")  //custom field entry is "{$CONFIG['main_option_1']}"
   {
   $Option1    = " {$CONFIG['1size1']} @{$CONFIG['1size1_price']} ";
   $Desc1      = " {$CONFIG['1size1']} @ {$CONFIG[currency_symbol]}{$CONFIG['1size1_price']} " ;
   $Option2    = " {$CONFIG['1size2']} @{$CONFIG['1size2_price']} ";
   $Desc2      = " {$CONFIG['1size2']} @ {$CONFIG[currency_symbol]}{$CONFIG['1size2_price']} ";
   $Option3    = " {$CONFIG['1size3']} @{$CONFIG['1size3_price']} ";
   $Desc3      = " {$CONFIG['1size3']} @ {$CONFIG[currency_symbol]}{$CONFIG['1size3_price']} ";
   $Option4    = " {$CONFIG['1size4']} @{$CONFIG['1size4_price']} ";
   $Desc4      = " {$CONFIG['1size4']} @ {$CONFIG[currency_symbol]}{$CONFIG['1size4_price']} ";
   $Option5    = " {$CONFIG['1size5']} @{$CONFIG['1size5_price']} ";
   $Desc5      = " {$CONFIG['1size5']} @ {$CONFIG[currency_symbol]}{$CONFIG['1size5_price']} ";
   $Option6    = "{$CONFIG['1size6']} @{$CONFIG['1size6_price']}";
   $Desc6      = "{$CONFIG['1size6']} @ {$CONFIG[currency_symbol]}{$CONFIG['1size6_price']}";

   }
   else

// 2nd option
if ($pricing_setup=="2")    
   {
   $Option1    = " {$CONFIG['2size1']} @{$CONFIG['2size1_price']} ";
   $Desc1      = " {$CONFIG['2size1']} @ {$CONFIG[currency_symbol]}{$CONFIG['2size1_price']} " ;
   
   }
else
// third option
if ($pricing_setup=="3")
   {
   $Option1    = " {$CONFIG['3size1']} @{$CONFIG['3size1_price']} ";
   $Desc1      = " {$CONFIG['3size1']} @ {$CONFIG[currency_symbol]}{$CONFIG['3size1_price']} " ;
   $Option2    = " {$CONFIG['3size2']} @{$CONFIG['3size2_price']} ";
   $Desc2      = " {$CONFIG['3size2']} @ {$CONFIG[currency_symbol]}{$CONFIG['3size2_price']} ";

   }
   else
 // fourth option
if ($pricing_setup=="4")
   {
   $Option1    = " {$CONFIG['4size1']} @{$CONFIG['4size1_price']} ";
   $Desc1      = " {$CONFIG['4size1']} @ {$CONFIG[currency_symbol]}{$CONFIG['4size1_price']} " ;
   $Option2    = " {$CONFIG['4size2']} @{$CONFIG['4size2_price']} ";
   $Desc2      = " {$CONFIG['4size2']} @ {$CONFIG[currency_symbol]}{$CONFIG['4size2_price']} ";
   $Option3    = " {$CONFIG['4size3']} @{$CONFIG['4size3_price']} ";
   $Desc3      = " {$CONFIG['4size3']} @ {$CONFIG[currency_symbol]}{$CONFIG['4size3_price']} ";
   $Option4    = " {$CONFIG['4size4']} @{$CONFIG['4size4_price']} ";
   $Desc4      = " {$CONFIG['4size4']} @ {$CONFIG[currency_symbol]}{$CONFIG['4size4_price']} ";
   $Option5    = " {$CONFIG['4size5']} @{$CONFIG['4size5_price']} ";
   $Desc5      = " {$CONFIG['4size5']} @ {$CONFIG[currency_symbol]}{$CONFIG['4size5_price']} ";
   $Option6    = "{$CONFIG['4size6']} @{$CONFIG['4size6_price']}";
   $Desc6      = "{$CONFIG['4size6']} @ {$CONFIG[currency_symbol]}{$CONFIG['4size6_price']}";
   $Option7    = "{$CONFIG['4size7']} @{$CONFIG['4size7_price']}";
   $Desc7      = "{$CONFIG['4size7']} @ {$CONFIG[currency_symbol]}{$CONFIG['4size7_price']}";
   $Option8    = "{$CONFIG['4size8']} @{$CONFIG['4size8_price']}";
   $Desc8      = "{$CONFIG['4size8']} @ {$CONFIG[currency_symbol]}{$CONFIG['4size8_price']}";
   $Option9    = "{$CONFIG['4size9']} @{$CONFIG['4size9_price']}";
   $Desc9      = "{$CONFIG['4size9']} @ {$CONFIG[currency_symbol]}{$CONFIG['4size9_price']}";
   $Option10   = "{$CONFIG['4size10']} @{$CONFIG['4size10_price']}";
   $Desc10     = "{$CONFIG['4size10']} @ {$CONFIG[currency_symbol]}{$CONFIG['4size10_price']}";
   }
   else 
   // fifth option
if ($pricing_setup=="5")
   {
   $Option1    = " {$CONFIG['5size1']} @{$CONFIG['5size1_price']} ";
   $Desc1      = " {$CONFIG['5size1']} @ {$CONFIG[currency_symbol]}{$CONFIG['5size1_price']} " ;
   $Option2    = " {$CONFIG['5size2']} @{$CONFIG['5size2_price']} ";
   $Desc2      = " {$CONFIG['5size2']} @ {$CONFIG[currency_symbol]}{$CONFIG['5size2_price']} ";
   $Option3    = " {$CONFIG['5size3']} @{$CONFIG['5size3_price']} ";
   $Desc3      = " {$CONFIG['5size3']} @ {$CONFIG[currency_symbol]}{$CONFIG['5size3_price']} ";
   $Option4    = " {$CONFIG['5size4']} @{$CONFIG['5size4_price']} ";
   $Desc4      = " {$CONFIG['5size4']} @ {$CONFIG[currency_symbol]}{$CONFIG['5size4_price']} ";
   $Option5    = " {$CONFIG['5size5']} @{$CONFIG['5size5_price']} ";
   $Desc5      = " {$CONFIG['5size5']} @ {$CONFIG[currency_symbol]}{$CONFIG['5size5_price']} ";
   $Option6    = "{$CONFIG['5size6']} @{$CONFIG['5size6_price']}";
   $Desc6      = "{$CONFIG['5size6']} @ {$CONFIG[currency_symbol]}{$CONFIG['5size6_price']}";
   $Option7    = "{$CONFIG['5size7']} @{$CONFIG['5size7_price']}";
   $Desc7      = "{$CONFIG['5size7']} @ {$CONFIG[currency_symbol]}{$CONFIG['5size7_price']}";
   $Option8    = "{$CONFIG['5size8']} @{$CONFIG['5size8_price']}";
   $Desc8      = "{$CONFIG['5size8']} @ {$CONFIG[currency_symbol]}{$CONFIG['5size8_price']}";
   $Option9    = "{$CONFIG['5size9']} @{$CONFIG['5size9_price']}";
   $Desc9      = "{$CONFIG['5size9']} @ {$CONFIG[currency_symbol]}{$CONFIG['5size9_price']}";
   $Option10   = "{$CONFIG['5size10']} @{$CONFIG['5size10_price']}";
   $Desc10     = "{$CONFIG['5size10']} @ {$CONFIG[currency_symbol]}{$CONFIG['5size10_price']}";
   }
else
// fall back when nothing matches.
   {
   $Option1    = "{$lang_picinfo['sorry']}";
   $Desc1      = "{$lang_picinfo['sorry']}" ;
   $Option2    = "";
   $Desc2      = "";
   $Option3    = "";
   $Desc3      = "";
   $Option4    = "";
   $Desc4      = "";
   $Option5    = "  ";
   $Desc5      = "  ";
   $Option6    = "  ";
   $Desc6      = "  ";
   $Desc8      = "  ";
   $Option9    = "  ";
   $Desc9      = "  ";
   $Option10   = "  ";
   $Desc10     = "  ";
   }
 }

Print <<<EOT
<!--//Start JavaScript for Mod -->
<script type="text/javascript">
<!-- // Hide from Xhtml validators
function Dollar (val) {  // force to valid dollar amount
var str,pos,rnd=0;
  if (val < .995) rnd = 1;  // for old Netscape browsers
  str = escape (val*1.0 + 0.005001 + rnd);  // float, round, escape
  pos = str.indexOf (".");
  if (pos > 0) str = str.substring (rnd, pos + 3);
  return str;
}

var amt,des,obj,val,op1a,op1b,op2a,op2b,itmn;

function ChkTok (obj1) {
var j,tok,ary=new Array ();       // where we parse
  ary = val.split (" ");          // break apart
  for (j=0; j<ary.length; j++) {  // look at all items
// first we do single character tokens...
    if (ary[j].length < 2) continue;
    tok = ary[j].substring (0,1); // first character
    val = ary[j].substring (1);   // get data
    if (tok == "@") amt = val * 1.0;
    if (tok == "+") amt = amt + val*1.0;
    if (tok == "%") amt = amt + (amt * val/100.0);
    if (tok == "#") {             // record item number
      if (obj1.item_number) obj1.item_number.value = val;
      ary[j] = "";                // zap this array element
    }
// Now we do 3-character tokens...
    if (ary[j].length < 4) continue;
    tok = ary[j].substring (0,3); // first 3 chars
    val = ary[j].substring (3);   // get data
    if (tok == "s1=") {           // value for shipping
      if (obj1.shipping)  obj1.shipping.value  = val;
      ary[j] = "";                // clear it out
    }
    if (tok == "s2=") {           // value for shipping2
      if (obj1.shipping2) obj1.shipping2.value = val;
      ary[j] = "";                // clear it out
    }
  }
  val = ary.join (" ");           // rebuild val with what's left
}

function StorVal () {
var tag;
  tag = obj.name.substring (obj.name.length-2);  // get flag
  if      (tag == "1a") op1a = op1a + " " + val;
  else if (tag == "1b") op1b = op1b + " " + val;
  else if (tag == "2a") op2a = op2a + " " + val;
  else if (tag == "2b") op2b = op2b + " " + val;
  else if (tag == "3i") itmn = itmn + " " + val;
  else if (des.length == 0) des = val;
  else des = des + ", " + val;
}

function ReadForm (obj1, tst) { // Read the user form
var i,j,pos;
  amt=0;des="";op1a="";op1b="";op2a="";op2b="";itmn="";
  if (obj1.baseamt) amt  = obj1.baseamt.value*1.0;  // base amount
  if (obj1.basedes) des  = obj1.basedes.value;  // base description
  if (obj1.baseon0) op1a = obj1.baseon0.value;  // base options
  if (obj1.baseos0) op1b = obj1.baseos0.value;
  if (obj1.baseon1) op2a = obj1.baseon1.value;
  if (obj1.baseos1) op2b = obj1.baseos1.value;
  if (obj1.baseitn) itmn = obj1.baseitn.value;
  for (i=0; i<obj1.length; i++) {     // run entire form
    obj = obj1.elements[i];           // a form element
    if (obj.type == "select-one") {   // just selects
      if (obj.name == "quantity" ||
          obj.name == "amount") continue;
      pos = obj.selectedIndex;        // which option selected
      val = obj.options[pos].value;   // selected value
      ChkTok (obj1);                  // check for any specials

      if (obj.name == "on0" ||        // let this go where it wants
          obj.name == "os0" ||
          obj.name == "on1" ||
          obj.name == "os1") continue;

      StorVal ();

    } else
    if (obj.type == "checkbox" ||     // just get checkboxex
        obj.type == "radio") {        //  and radios
      if (obj.checked) {
        val = obj.value;              // the value of the selection
        ChkTok (obj1);
        StorVal ();
      }
    } else
    if (obj.type == "select-multiple") {  //one or more
      for (j=0; j<obj.options.length; j++) {  // run all options
        if (obj.options[j].selected) {
          val = obj.options[j].value; // selected value (default)
          ChkTok (obj1);
          StorVal ();
        }
      }
    } else
    if ((obj.type == "text" ||        // just read text,
         obj.type == "textarea") &&
         obj.name != "tot" &&         //  but not from here
         obj.name != "quantity") {
      val = obj.value;                // get the data
      if (val == "" && tst) {         // force an entry
        alert ("Enter data for " + obj.name);
        return false;
      }
      StorVal ();
    }
  }
// Now summarize stuff we just processed, above
  if (op1a.length > 0) obj1.on0.value = op1a;
  if (op1b.length > 0) obj1.os0.value = op1b;
  if (op2a.length > 0) obj1.on1.value = op2a;
  if (op2b.length > 0) obj1.os1.value = op2b;
  if (itmn.length > 0) obj1.item_number.value = itmn;
  obj1.item_name.value = des;
  obj1.amount.value = Dollar (amt);
  if (obj1.tot) obj1.tot.value = "$" + Dollar (amt);
}
function TallyIt (obj1) {  // process un-named selects
            var i,obj,pos,tot=0,txt="";
              for (i=0; i<obj1.length; i++) {     // run entire form
             obj = obj1.elements[i];           // a form element
             if (obj.type == "select-one" &&   // what sort is it
              obj.name == "") {             // must be un-named
               pos = obj.selectedIndex;        // which option selected
               tot = tot + obj.options[pos].value*1.00;    // price mod
               txt = txt + " +" + obj.options[pos].text;  // and text
                   }
              }

              obj1.amount.value = Dollar ( tot + amt);

            }
-->
</script>
<!--//End JavaScript for Mod-->

<!--Start Form Block for purchase options -->
<!--// Display image storyline-->

<table  align="center"  width="90%">
	<tr >
       	<td>
            <fieldset><legend><b><big><big>{$lang_picinfo['confidence']}</big></big></b> </legend>
                	<blockquote><div align="justify"  >  <font size=-1>
                    <p><center>{$lang_picinfo['looking']} <b>$pic_title</b>, file ref:<i> $pic_id</i>. </center><br />
                    {$lang_picinfo['looking2']}</p>
                 	</font>
                    </blockquote></fieldset>
         </td>
     </tr>
</table>
<!--// END image storyline-->

<!--// START purchase FORM block -->
    <form action="https://www.paypal.com/cgi-bin/webscr" method="post"
		onsubmit="this.target = 'paypal';
    		      return ReadForm(this, true);">
		<input type="hidden" name="cmd" value="_cart" />
		<input type="hidden" name="add" value="1" />
		<input type="hidden" name="business" value="$paypal_ID" />
		<input type="hidden" name="item_name" value="" />
		<input type="hidden" name="amount" value="" />
		<input type="hidden" name="currency_code" value="$currency_code" />
		<input type="hidden" name="basedes" value="Title: $pic_title, Ref#: $pic_id " />
		<input type="hidden" name="baseon0" value="" />
		<input type="hidden" name="baseon1" value="" />
 		<input type="hidden" name="baseon2" value="" />
		<input type="hidden" name="baseon3" value="" />
		<input type="hidden" name="baseitn" value="" />
		<input type="hidden" name="item_number" value="$pid" />

<!--//START 1st Dropdown List for Form -->
<table  align="center" width="80%" class="tableb">
	<tr >
       	<td>

 <fieldset><legend>
    	<font size="4">{$lang_picinfo['customise']}</font></legend>
			<blockquote><blockquote>
		<font size="2"><b>{$lang_picinfo['select']} {$CONFIG['main_option_name']}</b></font>
			<blockquote>
              <select onchange="ReadForm (this.form, false);">
			  		
                    <option value='$Option1 selected'>		  $Desc1</option>
                    <option value='$Option2'>         $Desc2</option>
                    <option value='$Option3'>		  $Desc3</option>
  					<option value='$Option4'>         $Desc4</option>
                    <option value='$Option5'>         $Desc5</option>
                    <option value='$Option6'>         $Desc6</option>
                    <option value='$Option7'>         $Desc7</option>
                    <option value='$Option8'>         $Desc8</option>
  					<option value='$Option9'>         $Desc9</option>
                    <option value='$Option10'>        $Desc10</option>
              </select></blockquote>
<!--//END 1st Dropdown List Form -->
EOT;


if ($CONFIG['option2_name'] != '') 

echo <<<EOT

<!--//START Radio Buttons-->
			  <font size="2"><b>{$lang_picinfo['select']}  {$CONFIG['option2_name']}</b></font>
 			  <blockquote>                                                         
  			  <input onclick="ReadForm (this.form, false);" type=radio CHECKED  value=	"{$CONFIG['option2_name']}: {$CONFIG['2option1']} {$CONFIG['2option1_charge']}"   name=r1> {$CONFIG['2option1']}
  									<br />
  			  <input onclick="ReadForm (this.form, false);" type=radio value=			"{$CONFIG['option2_name']}: {$CONFIG['2option2']} {$CONFIG['2option2_charge']}" name=r1> {$CONFIG['2option2']}
  									<br />
  			  <input onclick="ReadForm (this.form, false);" type=radio value=			"{$CONFIG['option2_name']}: {$CONFIG['2option3']} {$CONFIG['2option3_charge']}" name=r1> {$CONFIG['2option3']}   
              </blockquote>

<!--//END Radio Buttons-->
EOT;
if ($CONFIG['option3_name'] != '') 
echo <<<EOT
<!--//START 2nd Dropdown List Form -->
			  <font size="2"><b>{$lang_picinfo['select']}  {$CONFIG['option3_name']}</b></font>
			  <blockquote>
              <select onchange="ReadForm (this.form, false);">
                                  
              		<option value=' {$CONFIG['option3_name']}:{$CONFIG['3option1']} {$CONFIG['3option1_charge']}' selected> {$CONFIG['3option1']} </option>
                    <option value=' {$CONFIG['option3_name']}:{$CONFIG['3option2']} {$CONFIG['3option2_charge']} '> 	{$CONFIG['3option2']}</option>
  					<option value=' {$CONFIG['option3_name']}:{$CONFIG['3option3']} {$CONFIG['3option3_charge']}'> 			{$CONFIG['3option3']}</option>
<option value=' {$CONFIG['option3_name']}:{$CONFIG['3option4']} {$CONFIG['3option4_charge']}'>{$CONFIG['3option4']}</option>
<option value=' {$CONFIG['option3_name']}:{$CONFIG['3option5']} {$CONFIG['3option5_charge']}'>{$CONFIG['3option5']}</option>
              </select> </blockquote>

<!--//END 2nd Dropdown List Form -->
EOT;
if ($CONFIG['option4_name'] != '')
echo <<<EOT
<!--//START 3rd Dropdown List Form -->
        		<font size="2"><b>{$lang_picinfo['select']} {$CONFIG['option4_name']}</b></font>
			  	<blockquote>
				<select>          
					<option value="{$CONFIG['option4_name']}:None">Select.</option>
					
  					<option value="{$CONFIG['option4_name']}:{$CONFIG['4option1']} {$CONFIG['4option1_charge']}" select>{$CONFIG['4option1']}</option>
                    <option value="{$CONFIG['option4_name']}:{$CONFIG['4option2']} {$CONFIG['4option2_charge']}" select>{$CONFIG['4option2']}</option>
<option value="{$CONFIG['option4_name']}:{$CONFIG['4option3']} {$CONFIG['4option3_charge']}" select>{$CONFIG['4option3']}</option>
<option value="{$CONFIG['option4_name']}:{$CONFIG['4option4']} {$CONFIG['4option4_charge']}" select>{$CONFIG['4option4']}</option>
<option value="{$CONFIG['option4_name']}:{$CONFIG['4option5']} {$CONFIG['4option5_charge']}" select>{$CONFIG['4option5']}</option>

				</select> </blockquote>

<!--//END 3rd Dropdown List Form -->
EOT;
if ($CONFIG['option5_name'] != '')
echo <<<EOT
<!--//START 4th dropdown list Form-->
        		<font size="2"><b>{$lang_picinfo['select']}  {$CONFIG['option5_name']}</b></font> 
			  	<blockquote>
				<select>          
					<option value="{$CONFIG['option5_name']}:No Thankyou.">Select.</option>
					<option value="{$CONFIG['option5_name']}:No Thankyou.">No Thankyou.</option>
  					<option value="{$CONFIG['option5_name']}:{$CONFIG['5option1']} {$CONFIG['5option1_charge']}" select>{$CONFIG['5option1']}</option>
                    <option value="{$CONFIG['option5_name']}:{$CONFIG['5option2']} {$CONFIG['5option2_charge']}" select>{$CONFIG['5option2']}</option>
<option value="{$CONFIG['option5_name']}:{$CONFIG['5option3']} {$CONFIG['5option3_charge']}" select>{$CONFIG['5option3']}</option>
<option value="{$CONFIG['option5_name']}:{$CONFIG['5option4']} {$CONFIG['5option4_charge']}" select>{$CONFIG['5option4']}</option>
<option value="{$CONFIG['option5_name']}:{$CONFIG['5option5']} {$CONFIG['5option5_charge']}" select>{$CONFIG['5option5']}</option>

				</select> </blockquote>

<!--//END 4th Dropdown list Form -->
EOT;
if ($CONFIG['option6_name'] != '')
echo <<<EOT
<!--//START 5th dropdown list Form-->
        		<font size="2"><b>{$lang_picinfo['select']} {$CONFIG['option6_name']}</b></font> 
			  	<blockquote>
                    <select>          
					<option value="{$CONFIG['option6_name']}:None">Select.</option>
					<option value="{$CONFIG['option6_name']}:None">No Thankyou.</option>
  					<option value="{$CONFIG['option6_name']}:{$CONFIG['6option1']} {$CONFIG['6option1_charge']}" select>{$CONFIG['6option1']}</option>
                    <option value="{$CONFIG['option6_name']}:{$CONFIG['6option2']} {$CONFIG['6option2_charge']}" select>{$CONFIG['6option2']}</option>
<option value="{$CONFIG['option6_name']}:{$CONFIG['6option3']} {$CONFIG['6option3_charge']}" select>{$CONFIG['6option3']}</option>
<option value="{$CONFIG['option6_name']}:{$CONFIG['6option4']} {$CONFIG['6option4_charge']}" select>{$CONFIG['6option4']}</option>
<option value="{$CONFIG['option6_name']}:{$CONFIG['6option5']} {$CONFIG['6option5_charge']}" select>{$CONFIG['6option5']}</option>
<option value="{$CONFIG['option6_name']}:{$CONFIG['6option6']} {$CONFIG['6option6_charge']}" select>{$CONFIG['6option6']}</option>
<option value="{$CONFIG['option6_name']}:{$CONFIG['6option7']} {$CONFIG['6option7_charge']}" select>{$CONFIG['6option7']}</option>
<option value="{$CONFIG['option6_name']}:{$CONFIG['6option8']} {$CONFIG['6option8_charge']}" select>{$CONFIG['6option8']}</option>

						</select>   </blockquote>
EOT;


				  
echo <<<EOT
					  </fieldset>
					  
					  
       </td>
      </tr>
   </table>
<!--//END 5th dropdown list-->

<!--//START Order Now process -->
     <table align = "center">
          <tr>

                <td >
	                   <input type="submit" value="Place Order" border="0" name="Order Now!"
    	                      onclick = "TallyIt (this.form);">
                       <input type="hidden" name="add" value="1">
                       &nbsp;
                </td>
                <td>
                       <input type    = "button" value   = "Reset Form"
                               onclick = "this.form.reset ();" />
                </td>
    </form>
<!--//END Order Now process -->
<!--//START view cart Form -->
		   <form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="viewcart" name="viewcart">
      				   <input type="hidden" name="cmd" value="_cart" />
      				   <input type="hidden" name="display" value="1" />
      				   <input type="hidden" name="business" value="$paypal_ID" />
  		   </form>
            	<td> &nbsp; &nbsp;
                		<input type="submit" value="View Purchases" border="0" name="View Cart"
  						onclick="document.forms.viewcart.target = 'paypal';
           						 document.forms.viewcart.submit ();
           						 return false;" />
                </td>
     	 </tr>
     </table>

<!-- //End of the viewcart FORM -->
 <hr>


  

EOT;
//END PAYPAL MOD
	
    pagefooter();
    ob_end_flush();


?>
