if (file_exists(ABSPATH . 'wp-includes/l10n.php')) {
    require_once ABSPATH . 'wp-includes/l10n.php';
} else {
    require_once ABSPATH . 'wp-includes/wp-l10n.php';
}
global $wpdb, $eshopoptions;
$opttable = $wpdb->prefix . 'eshop_option_names';
$optsettable = $wpdb->prefix . 'eshop_option_sets';
?>
<div class="wrap">
<div id="eshopicon" class="icon32"></div><h2><?php 
_e('Option Sets', 'eshop');
?>
</h2>
<?php 
eshop_admin_mode();
if (isset($_GET['optid']) && !isset($_POST['delete']) && !isset($_POST['eaddopt'])) {
    ?>
<p><a href="admin.php?page=eshop-options.php"><?php 
    _e('Return', 'eshop');
    ?>
</a></p>
<?php 
}
// updating options
if (isset($_POST['delete'])) {
    $optid = $_POST['optid'];
    $wpdb->query($wpdb->prepare("DELETE FROM {$opttable} where optid='%d'", $optid));
    $wpdb->query($wpdb->prepare("DELETE FROM {$optsettable} where optid='%d'", $optid));
    echo '<p class="success">' . __('Option Set Deleted', 'eshop') . '</p>';
    unset($_GET['optid']);
Example #2
0
function eshop_base_manager()
{
    global $wpdb, $eshopoptions;
    include 'eshop-base-functions.php';
    if (!isset($_GET['change'])) {
        ?>
	<div class="wrap">
	<div id="eshopicon" class="icon32"></div><h2><?php 
        _e('eShop Base Products', 'eshop');
        ?>
</h2>
	<?php 
        eshop_admin_mode();
        ?>
	<ul>
	<?php 
        $dlpage = '?page=' . $_GET['page'] . '&amp;eshopbasedl=yes';
        ?>
	<li><a href="<?php 
        echo $dlpage;
        ?>
&amp;d=1"><?php 
        _e('Download the xml file', 'eshop');
        ?>
</a></li>
	<li><a href="<?php 
        echo $dlpage;
        ?>
&amp;d=1&amp;os=mac"><?php 
        _e('Mac - Download the xml file', 'eshop');
        ?>
</a></li>
	<li><a href="<?php 
        echo $dlpage;
        ?>
"><?php 
        _e('View xml file', 'eshop');
        ?>
</a></li>
	<li><?php 
        echo sprintf(__('Direct link to file for Google Base: <a href="%1$s">%1$s</a>', 'eshop'), trim(site_url(), '/') . '/?eshopbasefeed');
        ?>
</li>
	</ul>
	<?php 
        //sort by switch statement
        $csa = $csb = $csc = $csd = $cse = $csf = '';
        if (isset($_GET['by'])) {
            switch ($_GET['by']) {
                case 'sa':
                    //date descending
                    $sortby = 'sku';
                    $csa = ' class="current"';
                    break;
                case 'sb':
                    //description alphabetically
                    $sortby = 'description';
                    $csb = ' class="current"';
                    break;
                    /*
                    	case'sd'://stock availability 
                    		$sortby='_eshop_stock';
                    		$csd=' class="current"';
                    		break;
                    */
                /*
                	case'sd'://stock availability 
                		$sortby='_eshop_stock';
                		$csd=' class="current"';
                		break;
                */
                case 'sf':
                    //date ascending
                //date ascending
                default:
                    $sortby = 'id';
                    $csf = ' class="current"';
            }
        } else {
            $csf = ' class="current"';
            $sortby = 'id';
        }
        $numoptions = $eshopoptions['options_num'];
        $metatable = $wpdb->prefix . 'postmeta';
        $poststable = $wpdb->prefix . 'posts';
        $stocktable = $wpdb->prefix . "eshop_stock";
        $range = 10;
        $max = $wpdb->get_var("SELECT COUNT(meta.post_id) FROM {$metatable} as meta, \n\t{$poststable} as posts where meta.meta_key='_eshop_product' \n\tAND posts.ID = meta.post_id\t\n\tAND posts.post_status != 'trash' AND posts.post_status != 'revision'");
        if ($eshopoptions['records'] != '' && is_numeric($eshopoptions['records'])) {
            $records = $eshopoptions['records'];
        } else {
            $records = '10';
        }
        if (isset($_GET['_p']) && is_numeric($_GET['_p'])) {
            $epage = $_GET['_p'];
        } else {
            $epage = '1';
        }
        if (!isset($_GET['eshopall'])) {
            $page_links = paginate_links(array('base' => add_query_arg('_p', '%#%'), 'format' => '', 'total' => ceil($max / $records), 'current' => $epage, 'type' => 'array'));
            $offset = $epage * $records - $records;
        } else {
            $page_links = paginate_links(array('base' => add_query_arg('_p', '%#%'), 'format' => '', 'total' => ceil($max / $records), 'current' => $epage, 'type' => 'array', 'show_all' => true));
            $offset = '0';
            $records = $max;
        }
        if ($max > 0) {
            $apge = get_admin_url() . 'admin.php?page=eshop-base.php';
            echo '<ul id="eshopsubmenu" class="stuffbox">';
            echo '<li><span>' . __('Sort Orders by &raquo;', 'eshop') . '</span></li>';
            echo '<li><a href="' . $apge . '&amp;by=sf"' . $csf . '>' . __('ID Number', 'eshop') . '</a></li>';
            echo '<li><a href="' . $apge . '&amp;by=sa"' . $csa . '>' . __('Sku', 'eshop') . '</a></li>';
            echo '<li><a href="' . $apge . '&amp;by=sb"' . $csb . '>' . __('Product', 'eshop') . '</a></li>';
            // echo '<li><a href="'.$apge.'&amp;by=sd"'.$csd.'>'.__('Stock','eshop').'</a></li>';
            echo '</ul>';
            $myrowres = $wpdb->get_results("\n\t\tSELECT DISTINCT meta.post_id\n\t\tFROM {$metatable} as meta, {$poststable} as posts\n\t\tWHERE meta.meta_key = '_eshop_product'\n\t\tAND posts.ID = meta.post_id\n\t\tAND posts.post_status != 'trash' AND posts.post_status != 'revision'\n\t\tORDER BY meta.post_id");
            $calt = 0;
            $currsymbol = $eshopoptions['currency_symbol'];
            $x = 0;
            //add in post id( doh! )
            foreach ($myrowres as $row) {
                $grabit[$x] = maybe_unserialize(get_post_meta($row->post_id, '_eshop_product', true));
                //get_post_custom($row->post_id);
                $grabit[$x]['_eshop_stock'] = get_post_meta($row->post_id, '_eshop_stock', true);
                //get_post_custom($row->post_id);
                $grabit[$x]['id'] = $row->post_id;
                $grabit[$x]['_featured'] = '1';
                $grabit[$x]['_stock'] = '1';
                if (strtolower($grabit[$x]['featured']) == 'yes') {
                    $grabit[$x]['_featured'] = '0';
                }
                if (strtolower($grabit[$x]['_eshop_stock']) == '1') {
                    $grabit[$x]['_stock'] = '0';
                }
                $x++;
            }
            $array = $grabit;
            $grab = eshop_subval_sort($array, $sortby);
            ?>
	
		<table class="widefat">
		<caption><?php 
            _e('Product Quick reference table', 'eshop');
            ?>
</caption>
		<thead>
		<tr>
		<th id="sku"><?php 
            _e('Sku', 'eshop');
            ?>
</th>
		<th id="page"><?php 
            _e('Page', 'eshop');
            ?>
</th>
		<th id="desc"><?php 
            _e('Description', 'eshop');
            ?>
</th>
		<th id="down"><?php 
            _e('Download', 'eshop');
            ?>
</th>
		<th id="stkavail"><abbr title="<?php 
            _e('Stock Available', 'eshop');
            ?>
"><?php 
            _e('Stk avail.', 'eshop');
            ?>
</abbr></th>
		<th id="stk"><?php 
            _e('Stock', 'eshop');
            ?>
</th>
		<th id="opt"><?php 
            _e('Option/Price', 'eshop');
            ?>
</th>
		<th id="imga"><?php 
            _e('Image', 'eshop');
            ?>
</th>

		</tr>
		</thead>
		<tbody>
		<?php 
            $start = $epage * $records - $records;
            if (isset($_GET['eshopall'])) {
                $start = 0;
            }
            $grab = array_slice($grab, $start, $records);
            foreach ($grab as $foo => $grabit) {
                $eshop_product = $grabit;
                if (isset($grabit['_eshop_stock'])) {
                    $stkav = $grabit['_eshop_stock'];
                } else {
                    $stkav = 0;
                }
                if (isset($eshop_product['products']['1']['price']) && $eshop_product['products']['1']['price'] != '') {
                    //get page title
                    $ptitle = get_post($grabit['id']);
                    $pdown = '';
                    //check if downloadable product
                    for ($i = 1; $i <= $eshopoptions['options_num']; $i++) {
                        if ($eshop_product['products'][$i]['option'] != '') {
                            if (isset($eshop_product['products'][$i]['download']) && $eshop_product['products'][$i]['download'] != '') {
                                $dltable = $wpdb->prefix . 'eshop_downloads';
                                $fileid = $eshop_product['products'][$i]['download'];
                                $filetitle = $wpdb->get_var("SELECT title FROM {$dltable} WHERE id='{$fileid}'");
                                $pdown .= '<a href="admin.php?page=eshop-downloads.php&amp;edit=' . $fileid . '">' . $filetitle . '</a>';
                                $pdownloads = 'yes';
                            } else {
                                $pdown .= '<br />';
                            }
                        }
                    }
                    if ($ptitle->post_title == '') {
                        $posttitle = __('(no title)', 'eshop');
                    } else {
                        $posttitle = $ptitle->post_title;
                    }
                    $calt++;
                    $alt = $calt % 2 ? '' : ' class="alternate"';
                    echo '<tr' . $alt . '>';
                    echo '<td id="sku' . $calt . '" headers="sku"><a href="admin.php?page=eshop-base.php&amp;change=' . $grabit['id'] . '" title="' . __('Change details', 'eshop') . '">' . $eshop_product['sku'] . '</a></td>';
                    echo '<td headers="page sku' . $calt . '"><a href="post.php?action=edit&amp;post=' . $grabit['id'] . '">' . $posttitle . '</a></td>';
                    echo '<td headers="desc sku' . $calt . '">' . stripslashes(esc_attr($eshop_product['description'])) . '</td>';
                    echo '<td headers="down sku' . $calt . '">' . $pdown . '</td>';
                    if ($stkav == '1') {
                        $stkchk = __('Yes', 'eshop');
                    } else {
                        $stkchk = __('No', 'eshop');
                    }
                    echo '<td headers="stkavail sku' . $calt . '">' . $stkchk . '</td>';
                    $pid = $grabit['id'];
                    if ($eshopoptions['stock_control'] == 'yes') {
                        $pravailable = '';
                        $getid = $grabit['id'];
                        for ($i = 1; $i <= $numoptions; $i++) {
                            if ($eshop_product['products'][$i]['option'] != '') {
                                $available = $wpdb->get_var("select available from {$stocktable} where post_id={$getid} && option_id={$i} limit 1");
                                if ($available == '' || $available < 0) {
                                    $available = '0';
                                }
                                if (is_numeric($available) && $eshopoptions['stock_control'] == 'yes') {
                                    $pravailable .= $available . '<br />' . "\n";
                                }
                            }
                        }
                    } else {
                        $pravailable = __('n/a', 'eshop') . '<br />';
                    }
                    echo '<td headers="stk sku' . $calt . '">' . $pravailable . '</td>';
                    echo '<td headers="opt sku' . $calt . '">';
                    for ($i = 1; $i <= $numoptions; $i++) {
                        if ($eshop_product['products'][$i]['option'] != '') {
                            echo sprintf(__('%1$s @ %2$s%3$s', 'eshop'), stripslashes(esc_attr($eshop_product['products'][$i]['option'])), $currsymbol, number_format_i18n($eshop_product['products'][$i]['price'], __('2', 'eshop'))) . '<br />';
                        }
                    }
                    echo '</td>';
                    echo '<td>';
                    $getid = $grabit['id'];
                    $w = get_option('thumbnail_size_w');
                    $h = get_option('thumbnail_size_h');
                    $imgsize = '50';
                    $w = round($w * $imgsize / 100);
                    $h = round($h * $imgsize / 100);
                    if (has_post_thumbnail($getid)) {
                        echo '<a class="itemref" href="' . get_permalink($getid) . '">' . get_the_post_thumbnail($getid, array($w, $h)) . '</a>' . "\n";
                    } else {
                        $eimage = eshop_files_directory();
                        $eshopnoimage = apply_filters('eshop_no_image', $eimage['1'] . 'noimage.png');
                        echo '<a class="itemref" href="' . get_permalink($getid) . '"><img src="' . $eshopnoimage . '" height="' . $h . '" width="' . $w . '" alt="" /></a>' . "\n";
                    }
                    echo '</td>';
                    echo '</tr>';
                }
            }
            ?>
		</tbody>
		</table>
		<?php 
            //paginate
            echo '<div class="paginate tablenav-pages stuffbox">';
            if ($records != $max) {
                $eecho = $page_links;
            }
            if (isset($_GET['eshopall'])) {
                $eshopdisp = number_format_i18n(1);
            } else {
                $eshopdisp = number_format_i18n(($epage - 1) * $records + 1);
            }
            echo sprintf('<span class="displaying-num">' . __('Displaying %s&#8211;%s of %s', 'eshop') . '</span>', $eshopdisp, number_format_i18n(min($epage * $records, $max)), number_format_i18n($max));
            if (isset($eecho)) {
                $thispage = esc_url(add_query_arg('eshopall', 'yes', $_SERVER['REQUEST_URI']));
                echo "<ul class='page-numbers'>\n\t<li>" . join("</li>\n\t<li>", $eecho) . "</li>\n<li>" . '<a href="' . $thispage . '">' . __('View All', 'eshop') . '</a>' . "</li>\n</ul>\n";
            }
            echo '<br /></div>';
            //end
        } else {
            echo '<p>' . __('There are no products available.', 'eshop') . '</p>';
        }
        echo '</div>';
    } else {
        //////////change one.
        //form checks:
        $basetable = $wpdb->prefix . "eshop_base_products";
        $change = $_GET['change'];
        if (is_numeric($change)) {
            if (isset($_POST['submit'])) {
                include 'cart-functions.php';
                if (get_magic_quotes_gpc() == 0) {
                    $_POST = stripslashes_array($_POST);
                }
                $_POST = sanitise_array($_POST);
                $err = '';
                if (isset($_POST['baseimg'])) {
                    $baseimg = esc_sql($_POST['baseimg']);
                } else {
                    $baseimg = '';
                }
                $basebrand = esc_sql($_POST['basebrand']);
                $baseean = esc_sql($_POST['baseean']);
                $baseisbn = esc_sql($_POST['baseisbn']);
                $basempn = esc_sql($_POST['basempn']);
                $baseptype = esc_sql($_POST['baseptype']);
                $baseqty = esc_sql($_POST['baseqty']);
                $basecondition = esc_sql($_POST['basecondition']);
                $baseexpiration_year = $_POST['baseexpiration_year'];
                $baseexpiration_month = $_POST['baseexpiration_month'];
                $baseexpiration_day = $_POST['baseexpiration_day'];
                if (!is_numeric($baseqty)) {
                    $baseqty = '25';
                    $err .= '<li>' . __('Quantity was not numeric, a default of 25 has been applied.', 'eshop') . '</li>';
                }
                $baseexpiration = esc_sql($baseexpiration_year . '-' . $baseexpiration_month . '-' . $baseexpiration_day);
                //enter in db - delete old record first,
                //then it will always be an insert and easier than checking for update.
                $wpdb->query("DELETE FROM {$basetable} WHERE post_id = {$change} limit 1");
                $wpdb->query("INSERT INTO {$basetable} (\n\t\t\tpost_id,img,brand,ptype,thecondition,expiry,ean,isbn,mpn,qty\n\t\t\t)VALUES(\n\t\t\t'{$change}','{$baseimg}','{$basebrand}','{$baseptype}','{$basecondition}','{$baseexpiration}',\n\t\t\t'{$baseean}','{$baseisbn}','{$basempn}','{$baseqty}'\n\t\t\t)");
                if ($err != '') {
                    echo '<div id="message" class="error fade"><p>' . __('<strong>Error</strong> the following were not valid:', 'eshop') . '</p><ul>' . $err . '</ul></div>' . "\n";
                } else {
                    echo '<div id="message" class="updated fade"><p>' . __('eshop Base details for this product have been updated.', 'eshop') . '</p></div>' . "\n";
                }
            }
            $basedata = $wpdb->get_row("SELECT * FROM {$basetable} WHERE post_id = {$change}");
            if ($basedata == '') {
                $basedata->post_id = $basedata->img = $basedata->brand = $basedata->ptype = $basedata->thecondition = $basedata->expiry = $basedata->ean = $basedata->isbn = $basedata->mpn = $basedata->qty = '';
            }
            ?>
		<div class="wrap">
		<div id="eshopicon" class="icon32"></div><h2><?php 
            _e('eShop Base Product', 'eshop');
            ?>
</h2>
		<?php 
            eshop_admin_mode();
            ?>

		<?php 
            //sort by switch statement
            $sortby = 'id';
            $csf = ' class="current"';
            $numoptions = $eshopoptions['options_num'];
            $metatable = $wpdb->prefix . 'postmeta';
            $calt = 0;
            $currsymbol = $eshopoptions['currency_symbol'];
            $x = 0;
            //add in post id( doh! )
            $grabit[$x] = get_post_custom($change);
            $grabit[$x]['id'] = array($change);
            $x++;
            /*
             * remove the bottom array to try and flatten
             * could be rather slow, but easier than trying to create
             * a different method, at least for now!
             */
            foreach ($grabit as $foo => $k) {
                foreach ($k as $bar => $v) {
                    if ($bar == '_eshop_product') {
                        $y = unserialize($v[0]);
                        foreach ($y as $nowt => $val) {
                            $grab[$foo][$nowt] = $val;
                        }
                    }
                    foreach ($v as $nowt => $val) {
                        $grab[$foo][$bar] = $val;
                    }
                }
            }
            ?>
	
		<table class="widefat">
		<caption><?php 
            _e('Product Quick reference table', 'eshop');
            ?>
</caption>
		<thead>
		<tr>
		<th id="sku"><?php 
            _e('Sku', 'eshop');
            ?>
</th>
		<th id="page"><?php 
            _e('Page', 'eshop');
            ?>
</th>
		<th id="desc"><?php 
            _e('Description', 'eshop');
            ?>
</th>
		<th id="down"><?php 
            _e('Download', 'eshop');
            ?>
</th>
		<th id="stk"><?php 
            _e('Stock', 'eshop');
            ?>
</th>
		<th id="opt"><?php 
            _e('Option/Price', 'eshop');
            ?>
</th>
		<th id="imga"><?php 
            _e('Image', 'eshop');
            ?>
</th>
		</tr>
		</thead>
		<tbody>
		<?php 
            foreach ($grab as $foo => $grabit) {
                $pdownloads = 'no';
                if ($grabit['products']['1']['price'] != '') {
                    if (isset($grabit['_eshop_stock'])) {
                        $stkav = $grabit['_eshop_stock'];
                    } else {
                        $stkav = 0;
                    }
                    //get page title
                    $ptitle = get_post($grabit['id']);
                    $pdown = '';
                    //check if downloadable product
                    for ($i = 1; $i <= $eshopoptions['options_num']; $i++) {
                        if (isset($grabit['products'][$i]['option']) && $grabit['products'][$i]['option'] != '') {
                            if (isset($grabit['products'][$i]['download']) && $grabit['products'][$i]['download'] != '') {
                                $dltable = $wpdb->prefix . 'eshop_downloads';
                                $fileid = $grabit['products'][$i]['download'];
                                $filetitle = $wpdb->get_var("SELECT title FROM {$dltable} WHERE id='{$fileid}'");
                                $pdown .= '<a href="admin.php?page=eshop-downloads.php&amp;edit=' . $fileid . '">' . $filetitle . '</a>';
                                $pdownloads = 'yes';
                            } else {
                                $pdown .= '<br />';
                            }
                        }
                    }
                    $calt++;
                    $alt = $calt % 2 ? '' : ' class="alternate"';
                    echo '<tr' . $alt . '>';
                    echo '<td id="sku' . $calt . '" headers="sku">' . $grabit['sku'] . '</td>';
                    echo '<td headers="page sku' . $calt . '"><a href="page.php?action=edit&amp;post=' . $grabit['id'] . '">' . $ptitle->post_title . '</a></td>';
                    echo '<td headers="desc sku' . $calt . '">' . stripslashes(esc_attr($grabit['description'])) . '</td>';
                    echo '<td headers="down sku' . $calt . '">' . $pdown . '</td>';
                    $pid = $grabit['id'];
                    $stocktable = $wpdb->prefix . "eshop_stock";
                    $pravailable = '';
                    if ($eshopoptions['stock_control'] == 'yes') {
                        for ($i = 1; $i <= $numoptions; $i++) {
                            if ($grabit['products'][$i]['option'] != '') {
                                $available = $wpdb->get_var("select available from {$stocktable} where post_id={$pid} && option_id={$i} limit 1");
                                if ($available == '' || $available < 0) {
                                    $available = '0';
                                }
                                if (is_numeric($available) && $eshopoptions['stock_control'] == 'yes') {
                                    $pravailable .= $available . '<br />' . "\n";
                                }
                            }
                        }
                    } else {
                        $pravailable .= __('n/a', 'eshop') . '<br />';
                    }
                    echo '<td headers="stk sku' . $calt . '">' . $pravailable . '</td>';
                    echo '<td headers="opt sku' . $calt . '">';
                    for ($i = 1; $i <= $numoptions; $i++) {
                        if (isset($grabit['products'][$i]['option']) && $grabit['products'][$i]['option'] != '') {
                            echo sprintf(__('%1$s @ %2$s%3$s', 'eshop'), stripslashes(esc_attr($grabit['products'][$i]['option'])), $currsymbol, number_format_i18n($grabit['products'][$i]['price'], __('2', 'eshop'))) . '<br />';
                        }
                    }
                    echo '</td>';
                    echo '<td>';
                    $w = get_option('thumbnail_size_w');
                    $h = get_option('thumbnail_size_h');
                    $imgsize = '50';
                    if ($imgsize != '') {
                        $w = round($w * $imgsize / 100);
                        $h = round($h * $imgsize / 100);
                    }
                    if (has_post_thumbnail($change)) {
                        echo '<a class="itemref" href="' . get_permalink($change) . '">' . get_the_post_thumbnail($change, array($w, $h)) . '</a>' . "\n";
                    } else {
                        $eimage = eshop_files_directory();
                        $eshopnoimage = apply_filters('eshop_no_image', $eimage['1'] . 'noimage.png');
                        echo '<a class="itemref" href="' . get_permalink($change) . '"><img src="' . $eshopnoimage . '" height="' . $h . '" width="' . $w . '" alt="" /></a>' . "\n";
                    }
                    echo '</td>' . "\n";
                    echo '</tr>' . "\n";
                }
                ?>
		</tbody>
		</table>
		<?php 
            }
            echo '<h3>' . __('Additional settings', 'eshop') . '</h3>' . "\n";
            $id = $grabit['id'];
            ?>
		<form method="post" action="" id="eshop-gbase-alt">
		<fieldset id="baseothers"><legend><?php 
            _e('Others', 'eshop');
            ?>
</legend>
		<?php 
            if (has_post_thumbnail($id)) {
                $grabimg = get_post_thumbnail_id($id);
                $src = wp_get_attachment_image_src($grabimg);
                ?>
		<input type="hidden" name="baseimg" value="<?php 
                echo $src['0'];
                ?>
" />
		<?php 
            }
            ?>
		<label for="basebrand"><?php 
            _e('Brand <small>The brand name of the product</small>', 'eshop');
            ?>
</label>
		<input type="text" name="basebrand" id="basebrand" value="<?php 
            echo esc_html($basedata->brand);
            ?>
" />
		<label for="baseean"><?php 
            _e('EAN <small>European Article Number is a 13 digit number often below the bar code of the item.</small>', 'eshop');
            ?>
</label>
		<input type="text" name="baseean" id="baseean" value="<?php 
            echo esc_html($basedata->ean);
            ?>
" />
		<label for="baseisbn"><?php 
            _e('ISBN <small>The unique 10- or 13-digit number assigned to every printed book.</small>', 'eshop');
            ?>
</label>
		<input type="text" name="baseisbn" id="baseisbn" value="<?php 
            echo esc_html($basedata->isbn);
            ?>
" />
		<label for="basempn"><?php 
            _e('MPN <small>Manufacturer\'s Part Number is a unique code determined by the manufacturer for that product.</small>', 'eshop');
            ?>
</label>
		<input type="text" name="basempn" id="basempn" value="<?php 
            echo esc_html($basedata->mpn);
            ?>
" />
		<label for="baseptype"><?php 
            _e('Product type <small>The type of product being offered.</small>', 'eshop');
            ?>
</label>
		<input type="text" name="baseptype" id="baseptype" value="<?php 
            echo esc_html($basedata->ptype);
            ?>
" />
		<label for="baseqty"><?php 
            _e('Quantity', 'eshop');
            ?>
</label>
		<input type="text" name="baseqty" id="baseqty" value="<?php 
            echo esc_html($basedata->qty);
            ?>
" />
	  <label for="basecondition"><?php 
            _e('Condition <small>the condition of this product</small>', 'eshop');
            ?>
</label>
	  <select name="basecondition" id="basecondition">
		<?php 
            //'
            foreach ($currentconditions as $code) {
                if ($basedata->thecondition == '') {
                    if ($code == $eshopoptions['base_condition']) {
                        $sel = ' selected="selected"';
                    } else {
                        $sel = '';
                    }
                } elseif ($code == $eshopoptions['base_condition']) {
                    $sel = ' selected="selected"';
                } else {
                    $sel = '';
                }
                echo '<option value="' . $code . '"' . $sel . '>' . $code . '</option>' . "\n";
            }
            ?>
	  </select>
	  <fieldset><legend><?php 
            _e('Expiration date <small>(or how long a product will be available.)</small>', 'eshop');
            ?>
</legend>
	  <label for="baseexpiration_year"><?php 
            _e('Year', 'eshop');
            ?>
</label>
	  <select name="baseexpiration_year" id="baseexpiration_year">
		<?php 
            // work this out!!!
            if ($basedata->expiry == '') {
                $baseexpiry = $eshopoptions['base_expiry'];
                $basedate = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d") + $baseexpiry, date("Y")));
                list($baseexpiration_year, $baseexpiration_month, $baseexpiration_day) = explode('-', $basedate);
            } else {
                list($baseexpiration_year, $baseexpiration_month, $baseexpiration_day) = explode('-', $basedata->expiry);
            }
            for ($i = date('Y'); $i <= date('Y') + 5; $i++) {
                if ($i == $baseexpiration_year) {
                    $sel = ' selected="selected"';
                } else {
                    $sel = '';
                }
                echo '<option value="' . $i . '"' . $sel . '>' . $i . '</option>' . "\n";
            }
            ?>
	  </select>
		<label for="baseexpiration_month"><?php 
            _e('Month', 'eshop');
            ?>
</label>

		  <select name="baseexpiration_month" id="baseexpiration_month">
		<?php 
            for ($i = 1; $i <= 12; $i++) {
                if ($i == $baseexpiration_month) {
                    $sel = ' selected="selected"';
                } else {
                    $sel = '';
                }
                echo '<option value="' . $i . '"' . $sel . '>' . $i . '</option>' . "\n";
            }
            ?>
	  </select>
		<label for="baseexpiration_day"><?php 
            _e('Day', 'eshop');
            ?>
</label>

		  <select name="baseexpiration_day" id="baseexpiration_day">
		<?php 
            for ($i = 1; $i <= 31; $i++) {
                if ($i == $baseexpiration_day) {
                    $sel = ' selected="selected"';
                } else {
                    $sel = '';
                }
                echo '<option value="' . $i . '"' . $sel . '>' . $i . '</option>' . "\n";
            }
            ?>
	  </select>
	  </fieldset>
	  </fieldset>
	  <p class="submit">
	  <input type="submit" name="submit" class="button-primary" value="<?php 
            _e('Update');
            ?>
" />
	</p>
		<?php 
            echo '</form></div>';
        } else {
            ?>
	<div class="wrap">
	<div id="eshopicon" class="icon32"></div><h2><?php 
            _e('Error', 'eshop');
            ?>
</h2>
	<p><?php 
            _e('That product does not exist!', 'eshop');
            ?>
</p>
	</div>
	<?php 
        }
    }
}
function eshop_products_manager()
{
    global $wpdb, $user_ID, $eshopoptions;
    get_currentuserinfo();
    //add in if current user can here
    if (current_user_can('eShop_admin')) {
        $eshopfilter = 'all';
        if (isset($_POST['eshopfiltering'])) {
            $eshopfilter = $_POST['eshopfilter'];
        }
        ?>
		<div class="wrap">
		<div id="eshopicon" class="icon32"></div><h2><?php 
        _e('Products', 'eshop');
        ?>
</h2>
		<?php 
        eshop_admin_mode();
        ?>
		<h3><?php 
        _e('Authors', 'eshop');
        ?>
</h3>
		<?php 
        if (isset($msg)) {
            echo '<div class="updated fade"><p>' . $msg . '</p></div>';
        }
        ?>
		<form action="" method="post" class="eshop filtering">
		<p><label for="eshopfilter"><?php 
        _e('Show products for', 'eshop');
        ?>
</label><select name="eshopfilter" id="eshopfilter">
		<?php 
        echo eshop_authors($eshopfilter);
        ?>
		</select><input type="submit" name="eshopfiltering" id="submit"  class="submit button-primary" value="Filter" /></p>
		</form>
		</div>
	<?php 
    }
    ?>
	<div class="wrap">
	<h3><?php 
    _e('Products Table', 'eshop');
    ?>
</h3>
	<p><?php 
    _e('A reference table for identifying products', 'eshop');
    ?>
.</p>
	<?php 
    if (isset($_POST['eshopqp']) && isset($_POST['product'])) {
        foreach ($_POST['product'] as $id => $type) {
            $pid = $id;
            $stocktable = $wpdb->prefix . "eshop_stock";
            $eshop_product = maybe_unserialize(get_post_meta($pid, '_eshop_product', true));
            $total = 0;
            for ($i = 1; $i <= $eshopoptions['options_num']; $i++) {
                if (isset($type[$i]['stkqty']) && is_numeric($type[$i]['stkqty'])) {
                    $meta_value = $type[$i]['stkqty'];
                    $results = $wpdb->get_results("select post_id from {$stocktable} where post_id={$pid} && option_id={$i}");
                    if (!empty($results)) {
                        $wpdb->query($wpdb->prepare("UPDATE {$stocktable} set available={$meta_value} where post_id={$pid} && option_id={$i}"));
                    } else {
                        $wpdb->query($wpdb->prepare("INSERT INTO {$stocktable} (post_id,option_id,available,purchases) VALUES ({$pid},{$i},{$meta_value},0)"));
                    }
                    $total = $total + $type[$i]['stkqty'];
                }
            }
            if (isset($type['sale'])) {
                $eshop_product['sale'] = 'yes';
                update_post_meta($id, '_eshop_sale', 'yes');
            } else {
                $eshop_product['sale'] = 'no';
                delete_post_meta($id, '_eshop_sale');
            }
            if (isset($type['featured'])) {
                $eshop_product['featured'] = 'Yes';
                update_post_meta($id, '_eshop_featured', 'Yes');
            } else {
                $eshop_product['featured'] = 'no';
                delete_post_meta($id, '_eshop_featured');
            }
            if (isset($type['stkavail'])) {
                $stkav = '1';
            } else {
                $stkav = '0';
            }
            if ($stkav == '1' && ($eshop_product['description'] == '' || $eshop_product['sku'] == '' || $eshop_product['products']['1']['option'] == '' || $eshop_product['products']['1']['price'] == '')) {
                $stkav = '0';
                $emsg[0] = 'set';
            }
            if ($stkav == '1' && ($total == 0 && 'yes' == $eshopoptions['stock_control'])) {
                $stkav = '0';
                $emsg[1] = 'set';
            }
            if ($stkav == '1') {
                update_post_meta($pid, '_eshop_stock', $stkav);
            } else {
                delete_post_meta($id, '_eshop_stock');
            }
            update_post_meta($pid, '_eshop_product', $eshop_product);
        }
        $msg = '';
        if (isset($emsg)) {
            if (isset($emsg[0])) {
                $msg .= __(' Some products were marked as not available due to missing information, check the individual product pages.', 'eshop');
            }
            if (isset($emsg[1])) {
                $msg .= __(' Some products were marked as not available as no stock was found.', 'eshop');
            }
        }
        echo '<div id="message" class="updated fade">' . __('Products have been updated.', 'eshop') . $msg . "</div>\n";
    }
    //sort by switch statement
    $csa = $csb = $csc = $csd = $cse = $csf = '';
    if (isset($_GET['by'])) {
        switch ($_GET['by']) {
            case 'sa':
                //date descending
                $sortby = 'sku';
                $csa = ' class="current"';
                break;
            case 'sb':
                //description alphabetically
                $sortby = 'description';
                $csb = ' class="current"';
                break;
                /*
                	case'sc'://name alphabetically (last name)
                		$sortby='shiprate';
                		$csc=' class="current"';
                		break;
                */
            /*
            	case'sc'://name alphabetically (last name)
            		$sortby='shiprate';
            		$csc=' class="current"';
            		break;
            */
            case 'sd':
                //stock availability
                $sortby = '_stock';
                $csd = ' class="current"';
                break;
            case 'se':
                //transaction id numerically
                $sortby = '_featured';
                $cse = ' class="current"';
                break;
            case 'sf':
                //date ascending
            //date ascending
            default:
                $sortby = 'id';
                $csf = ' class="current"';
        }
    } else {
        $csf = ' class="current"';
        $sortby = 'id';
    }
    if (current_user_can('eShop_admin')) {
        if ($eshopfilter == 'all') {
            $addtoq = '';
        } elseif (is_numeric($eshopfilter)) {
            $addtoq = "AND posts.post_author = {$eshopfilter}";
        } else {
            die('There was an error');
        }
    } else {
        $addtoq = "AND posts.post_author = {$user_ID} ";
    }
    $numoptions = $eshopoptions['options_num'];
    $metatable = $wpdb->prefix . 'postmeta';
    $poststable = $wpdb->prefix . 'posts';
    $range = 10;
    $max = $wpdb->get_var("SELECT COUNT(meta.post_id) FROM {$metatable} as meta, {$poststable} as posts where meta.meta_key='_eshop_product' \r\n\tAND posts.ID = meta.post_id \r\n\tAND posts.post_status != 'trash' AND posts.post_status != 'revision'" . $addtoq);
    if ($eshopoptions['records'] != '' && is_numeric($eshopoptions['records'])) {
        $records = $eshopoptions['records'];
    } else {
        $records = '10';
    }
    if (isset($_GET['_p']) && is_numeric($_GET['_p'])) {
        $epage = $_GET['_p'];
    } else {
        $epage = '1';
    }
    if (!isset($_GET['eshopall'])) {
        $page_links = paginate_links(array('base' => add_query_arg('_p', '%#%'), 'format' => '', 'total' => ceil($max / $records), 'current' => $epage, 'type' => 'array'));
        $offset = $epage * $records - $records;
    } else {
        $page_links = paginate_links(array('base' => add_query_arg('_p', '%#%'), 'format' => '', 'total' => ceil($max / $records), 'current' => $epage, 'type' => 'array', 'show_all' => true));
        $offset = '0';
        $records = $max;
    }
    if ($max > 0) {
        $apge = get_admin_url() . 'admin.php?page=' . $_GET['page'];
        echo '<ul id="eshopsubmenu" class="stuffbox">';
        echo '<li><span>' . __('Sort Products by &raquo;', 'eshop') . '</span></li>';
        echo '<li><a href="' . $apge . '&amp;by=sf"' . $csf . '>' . __('ID Number', 'eshop') . '</a></li>';
        echo '<li><a href="' . $apge . '&amp;by=sa"' . $csa . '>' . __('Sku', 'eshop') . '</a></li>';
        echo '<li><a href="' . $apge . '&amp;by=sb"' . $csb . '>' . __('Product', 'eshop') . '</a></li>';
        // echo '<li><a href="'.$apge.'&amp;by=sc"'.$csc.'>'.__('Shipping','eshop').'</a></li>';
        echo '<li><a href="' . $apge . '&amp;by=sd"' . $csd . '>' . __('Stock', 'eshop') . '</a></li>';
        echo '<li><a href="' . $apge . '&amp;by=se"' . $cse . '>' . __('Featured', 'eshop') . '</a></li>';
        echo '</ul>';
        if (current_user_can('eShop_admin')) {
            if ($eshopfilter == 'all') {
                $addtoq = '';
            } elseif (is_numeric($eshopfilter)) {
                $addtoq = "AND posts.post_author = '{$eshopfilter}'";
            } else {
                die('There was an error');
            }
        } else {
            $addtoq = "AND posts.post_author = '{$user_ID}' ";
        }
        $myrowres = $wpdb->get_results("\r\n\t\tSELECT DISTINCT meta.post_id\r\n\t\tFROM {$metatable} as meta, {$poststable} as posts\r\n\t\tWHERE meta.meta_key = '_eshop_product'\r\n\t\tAND posts.ID = meta.post_id\r\n\t\t{$addtoq}\r\n\t\tAND posts.post_status != 'trash' AND posts.post_status != 'revision'\r\n\t\tORDER BY meta.post_id");
        $calt = 0;
        $currsymbol = $eshopoptions['currency_symbol'];
        $x = 0;
        //add in post id( doh! )
        foreach ($myrowres as $row) {
            $grabit[$x] = maybe_unserialize(get_post_meta($row->post_id, '_eshop_product', true));
            //get_post_custom($row->post_id);
            $grabit[$x]['_eshop_stock'] = get_post_meta($row->post_id, '_eshop_stock', true);
            //get_post_custom($row->post_id);
            $grabit[$x]['id'] = $row->post_id;
            $grabit[$x]['_featured'] = '1';
            $grabit[$x]['_stock'] = '1';
            if (strtolower($grabit[$x]['featured']) == 'yes') {
                $grabit[$x]['_featured'] = '0';
            }
            if (strtolower($grabit[$x]['_eshop_stock']) == '1') {
                $grabit[$x]['_stock'] = '0';
            }
            $x++;
        }
        $array = $grabit;
        $grab = subval_sort($array, $sortby);
        //grabs some tax data
        if (!isset($eshopoptions['etax'])) {
            $eshopoptions['etax'] = array();
        }
        $etax = $eshopoptions['etax'];
        if (!isset($etax['bands']) || $etax['bands'] == '') {
            $etax['bands'] = '0';
        }
        ?>
	
		<form action="" method="post" class="eshop">
		<div class="eshopwidetable">
		<table class="hidealllabels widefat" summary="product listing">
		<caption><?php 
        _e('Product Quick reference table', 'eshop');
        ?>
</caption>
		<thead>
		<tr>
		<th id="sku"><?php 
        _e('Sku', 'eshop');
        ?>
</th>
		<th id="ids"><?php 
        _e('ID', 'eshop');
        ?>
</th>
		<th id="page"><?php 
        _e('Page', 'eshop');
        ?>
</th>
		<th id="desc"><?php 
        _e('Description', 'eshop');
        ?>
</th>
		<th id="down"><abbr title="<?php 
        _e('Downloads', 'eshop');
        ?>
"><?php 
        _e('DL', 'eshop');
        ?>
</abbr></th>
		<th id="ship"><abbr title="<?php 
        _e('Shipping Rate', 'eshop');
        ?>
"><?php 
        _e('S/R', 'eshop');
        ?>
</abbr></th>
		<th id="stkavail"><abbr title="<?php 
        _e('Stock Available', 'eshop');
        ?>
"><?php 
        _e('Stk avail.', 'eshop');
        ?>
</abbr></th>
		<th id="purc"><abbr title="<?php 
        _e('Number of Purchases', 'eshop');
        ?>
"><?php 
        _e('Purc.', 'eshop');
        ?>
</abbr></th>
		<th id="ftrd"><abbr title="<?php 
        _e('Marked as Featured', 'eshop');
        ?>
"><?php 
        _e('Feat.', 'eshop');
        ?>
</abbr></th>
		<th id="onsale" title="<?php 
        _e('Product on sale', 'eshop');
        ?>
"><?php 
        _e('Sale', 'eshop');
        ?>
</th>
		<th id="opt"><?php 
        _e('Option/Price', 'eshop');
        ?>
</th>
		<?php 
        if ($etax['bands'] > 0) {
            ?>
		<th id="tax"><?php 
            _e('Tax', 'eshop');
            ?>
</th>
		<?php 
        }
        ?>
		<th id="stk"><abbr title="<?php 
        _e('Stock Level', 'eshop');
        ?>
"><?php 
        _e('Stk', 'eshop');
        ?>
</abbr></th>
		<th id="associmg"><?php 
        _e('Thumbnail', 'eshop');
        ?>
</th>
		</tr>
		</thead>
		<tbody>
		<?php 
        $scc = 0;
        $start = $epage * $records - $records;
        $grab = array_slice($grab, $start, $records);
        foreach ($grab as $grabit) {
            $eshop_product = $grabit;
            if (isset($grabit['_eshop_stock']) && is_numeric($grabit['_eshop_stock'])) {
                $stkav = $grabit['_eshop_stock'];
            } else {
                $stkav = 0;
            }
            $pdownloads = 'no';
            if (isset($eshop_product['products']['1']['price']) && $eshop_product['products']['1']['price'] != '') {
                //reset array
                $purcharray = array();
                //get page title
                $ptitle = get_post($grabit['id']);
                $getid = $grabit['id'];
                //get download file title
                $pdown = '';
                //check if downloadable product
                for ($i = 1; $i <= $eshopoptions['options_num']; $i++) {
                    if ($eshop_product['products'][$i]['option'] != '') {
                        if (isset($eshop_product['products'][$i]['download']) && $eshop_product['products'][$i]['download'] != '') {
                            $dltable = $wpdb->prefix . 'eshop_downloads';
                            $fileid = $eshop_product['products'][$i]['download'];
                            $filetitle = $wpdb->get_var("SELECT title FROM {$dltable} WHERE id='{$fileid}'");
                            $pdown .= '<a href="admin.php?page=eshop-downloads.php&amp;edit=' . $fileid . '">' . $filetitle . '</a>';
                            $pdownloads = 'yes';
                        } else {
                            $pdown .= '<br />';
                        }
                    }
                }
                if ($ptitle->post_title == '') {
                    $posttitle = __('(no title)');
                } else {
                    $posttitle = $ptitle->post_title;
                }
                $calt++;
                $alt = $calt % 2 ? '' : ' class="alternate"';
                echo '<tr' . $alt . '>';
                echo '<td id="sku' . $calt . '" headers="sku">' . $eshop_product['sku'] . '</td>';
                echo '<td headers="ids sku' . $calt . '">' . $getid . '<input type="hidden" value="1" name="product[' . $getid . '][theid]" /></td>';
                echo '<td headers="page sku' . $calt . '"><a href="post.php?action=edit&amp;post=' . $getid . '" title="id: ' . $getid . '">' . $posttitle . '</a></td>';
                echo '<td headers="desc sku' . $calt . '">' . stripslashes(esc_attr($eshop_product['description'])) . '</td>';
                echo '<td headers="down sku' . $calt . '">' . $pdown . '</td>';
                echo '<td headers="ship sku' . $calt . '">' . $eshop_product['shiprate'] . '</td>';
                if ($stkav == '1') {
                    $stkchk = ' checked="checked"';
                } else {
                    $stkchk = '';
                }
                echo '<td headers="stkavail sku' . $calt . '"><label for="stkavail' . $calt . '">' . __('Stock Available', 'eshop') . '</label><input type="checkbox" value="1" name="product[' . $getid . '][stkavail]" id="stkavail' . $calt . '"' . $stkchk . ' /></td>';
                $purcharray = array();
                $dltable = $wpdb->prefix . "eshop_downloads";
                $stocktable = $wpdb->prefix . "eshop_stock";
                for ($i = 1; $i <= $eshopoptions['options_num']; $i++) {
                    if ($eshop_product['products'][$i]['option'] != '') {
                        if (isset($eshop_product['products'][$i]['download']) && $eshop_product['products'][$i]['download'] != '') {
                            $fileid = $eshop_product['products'][$i]['download'];
                            $purchases = $wpdb->get_var("SELECT purchases FROM {$dltable} WHERE id='{$fileid}'");
                            if ($purchases != '') {
                                $purcharray[] = $purchases;
                            } else {
                                $purcharray[] = '0';
                            }
                        } else {
                            $purchases = $wpdb->get_var("select purchases from {$stocktable} where post_id={$getid} && option_id={$i} limit 1");
                            if ($purchases != '') {
                                $purcharray[] = $purchases;
                            } else {
                                $purcharray[] = '0';
                            }
                        }
                    }
                    if ($pdownloads == 'no') {
                        break;
                    }
                }
                //Featured Product
                if ($eshop_product['featured'] == 'Yes') {
                    $fchk = ' checked="checked"';
                } else {
                    $fchk = '';
                }
                $feat = '<label for="featured' . $calt . '">' . __('Featured Product', 'eshop') . '</label><input type="checkbox" value="1" name="product[' . $getid . '][featured]" id="featured' . $calt . '"' . $fchk . ' />';
                echo '<td headers="purc sku' . $calt . '">' . implode("<br />", $purcharray) . '</td>';
                echo '<td headers="ftrd sku' . $calt . '">' . $feat . '</td>';
                //Sale Product
                if (isset($eshop_product['sale']) && $eshop_product['sale'] == 'yes') {
                    $salechk = ' checked="checked"';
                } else {
                    $salechk = '';
                }
                $onsale = '<label for="sale' . $calt . '">' . __('Product On Sale', 'eshop') . '</label><input type="checkbox" value="1" name="product[' . $getid . '][sale]" id="sale' . $calt . '"' . $salechk . ' />';
                echo '<td headers="onsale sku' . $calt . '">' . $onsale . '</td>';
                echo '<td headers="opt sku' . $calt . '" class="optline">';
                for ($i = 1; $i <= $numoptions; $i++) {
                    if ($eshop_product['products'][$i]['option'] != '') {
                        echo sprintf(__('%1$s @ %2$s%3$s', 'eshop'), stripslashes(esc_attr($eshop_product['products'][$i]['option'])), $currsymbol, number_format_i18n($eshop_product['products'][$i]['price'], __('2', 'eshop'))) . '<br />';
                    }
                }
                echo '</td>';
                if ($etax['bands'] > 0) {
                    echo '<td headers="tax sku' . $calt . '" class="optline">';
                    for ($i = 1; $i <= $numoptions; $i++) {
                        if (isset($eshop_product['products'][$i]['tax']) && $eshop_product['products'][$i]['tax'] != '') {
                            $tzone = sprintf(__('Band %1$d', 'eshop'), $eshop_product['products'][$i]['tax']);
                            $disptzone = apply_filters('eshop_rename_tax_zone', array());
                            if (isset($disptzone[$eshop_product['products'][$i]['tax']])) {
                                $tzone = $disptzone[$eshop_product['products'][$i]['tax']];
                            }
                            echo $tzone . '<br />';
                        } else {
                            echo '<br />';
                        }
                    }
                    echo '</td>';
                }
                //reset the string to stop multiple boxes!
                $pravailable = '';
                if ($eshopoptions['stock_control'] == 'yes') {
                    for ($i = 1; $i <= $numoptions; $i++) {
                        if ($eshop_product['products'][$i]['option'] != '') {
                            $available = $wpdb->get_var("select available from {$stocktable} where post_id={$getid} && option_id={$i} limit 1");
                            if ($available == '') {
                                $available = '0';
                            }
                            if (is_numeric($available) && $eshopoptions['stock_control'] == 'yes') {
                                $pravailable .= '<label for="stock' . $calt . '">' . __('Stock', 'eshop') . '</label><input type="text" value="' . $available . '" id="stock' . $scc . '" name="product[' . $getid . '][' . $i . '][stkqty]" size="4" /><br />' . "\n";
                                $scc++;
                            }
                        }
                    }
                } else {
                    $pravailable .= __('n/a', 'eshop') . '<br />';
                }
                echo '<td headers="stk sku' . $calt . '">' . $pravailable . '</td>';
                echo '<td headers="associmg sku' . $calt . '">';
                $w = get_option('thumbnail_size_w');
                $h = get_option('thumbnail_size_h');
                $imgsize = '50';
                $w = round($w * $imgsize / 100);
                $h = round($h * $imgsize / 100);
                if (has_post_thumbnail($getid)) {
                    echo '<a class="itemref" href="' . get_permalink($getid) . '" title="view page">' . get_the_post_thumbnail($getid, array($w, $h)) . '</a>' . "\n";
                } else {
                    $eimage = eshop_files_directory();
                    $eshopnoimage = apply_filters('eshop_no_image', $eimage['1'] . 'noimage.png');
                    echo '<a class="itemref" href="' . get_permalink($getid) . '" title="view page"><img src="' . $eshopnoimage . '" height="' . $h . '" width="' . $w . '" alt="" /></a>' . "\n";
                }
                echo '</td>';
                echo '</tr>' . "\n";
            }
        }
        ?>
		</tbody>
		</table>
		</div>
		<p><input type="submit" name="eshopqp" id="submitit" class="submit button-primary" value="<?php 
        _e('Update Products', 'eshop');
        ?>
" /></p>
		</form>
		<?php 
        //paginate
        echo '<div class="paginate tablenav-pages stuffbox">';
        if ($records != $max) {
            $eecho = $page_links;
        } else {
            --$records;
        }
        echo sprintf('<span class="displaying-num">' . __('Displaying %s&#8211;%s of %s') . '</span>', number_format_i18n(($epage - 1) * $records + 1), number_format_i18n(min($epage * $records, $max)), number_format_i18n($max));
        if (isset($eecho)) {
            $thispage = esc_url(add_query_arg('eshopall', 'yes', $_SERVER['REQUEST_URI']));
            echo "<ul class='page-numbers'>\n\t<li>" . join("</li>\n\t<li>", $eecho) . "</li>\n<li>" . '<a href="' . $thispage . '">' . __('View All', 'eshop') . '</a>' . "</li>\n</ul>\n";
        }
        echo '<br /></div>';
        //end
    } else {
        echo '<p>' . __('There are no products available.', 'eshop') . '</p>';
    }
    echo '</div>';
}
function eshop_discounts_manager()
{
    global $wpdb;
    include_once WP_PLUGIN_DIR . '/eshop/cart-functions.php';
    $legtext = __('Add a discount code', 'eshop');
    $subtext = __('Submit', 'eshop');
    $edit = false;
    $phpself = 'admin.php?page=eshop-discount-codes.php';
    $disctable = $wpdb->prefix . 'eshop_discount_codes';
    //blank - will change as we check things
    $eshop_code = $eshop_percent = $eshop_remain = $eshop_used = $eshop_live = $eshop_free_ship = $eshop_code_date = $eshop_code_type = '';
    $editid = '0';
    //delete
    if (isset($_GET['delcode']) && is_numeric($_GET['delcode'])) {
        $id = $_GET['delcode'];
        $wpdb->query("DELETE FROM {$disctable} WHERE id='{$id}' limit 1");
        echo '<div class="updated fade"><p>' . __('Discount code deleted.', 'eshop') . '</p></div>';
    }
    //edit
    if (isset($_GET['editcode']) && is_numeric($_GET['editcode'])) {
        $editid = $_GET['editcode'];
        $row = $wpdb->get_row("SELECT * FROM {$disctable} WHERE id='{$editid}'");
        $eshop_code = $row->disccode;
        $eshop_code_type = $row->dtype;
        $eshop_percent = $row->percent;
        $eshop_remain = $row->remain;
        $eshop_used = $row->used;
        $eshop_live = $row->live;
        $eshop_code_date = $row->enddate;
        if ($eshop_code_date == '0000-00-00') {
            $eshop_code_date = '';
        }
        $edit = true;
        $legtext = __('Edit a discount code', 'eshop');
        $subtext = __('Update', 'eshop');
    }
    //new or edit
    if (isset($_POST['editid'])) {
        $eshop_id = $wpdb->escape(trim($_POST['editid']));
        if (isset($_POST['eshop_live'])) {
            $eshop_live = 'yes';
        } else {
            $eshop_live = 'no';
        }
        if (isset($_POST['eshop_code_type'])) {
            $eshop_code_type = $_POST['eshop_code_type'];
        } else {
            $eshop_code_type = '';
        }
        if (isset($_POST['eshop_percent'])) {
            $eshop_percent = $_POST['eshop_percent'];
        } else {
            $eshop_percent = '';
        }
        $eshop_code_month = $_POST['eshop_code_month'];
        $eshop_code_day = $_POST['eshop_code_day'];
        $eshop_code_year = $_POST['eshop_code_year'];
        //error check - first check if discount
        switch ($eshop_code_type) {
            case '':
                $error[] = __('You must choose a discount code type', 'eshop');
                break;
            case '1':
            case '2':
            case '3':
                if (!is_numeric($eshop_percent) || $eshop_percent > 100) {
                    $error[] = __('Percentage must be a number no greater than 100.00', 'eshop');
                } elseif ($eshop_percent <= 0) {
                    $error[] = __('Percentage must be a number above 0', 'eshop');
                }
                break;
        }
        //error check if date is required it must be valid
        switch ($eshop_code_type) {
            case '2':
            case '3':
            case '5':
            case '6':
                if (!checkdate($eshop_code_month, $eshop_code_day, $eshop_code_year)) {
                    $error[] = __('The date you have chosen is not valid', 'eshop');
                }
                break;
        }
        //standard errors
        if (isset($_POST['eshop_code'])) {
            $eshop_code = $_POST['eshop_code'];
        } else {
            $eshop_code == '';
        }
        if ($eshop_code == '') {
            $error[] = __('You must specify a code', 'eshop');
        }
        if ($eshop_code != '') {
            $ecode = $wpdb->escape(trim(strtolower($eshop_code)));
            $ecount = $wpdb->get_var("SELECT COUNT(id) FROM {$disctable} WHERE LOWER(disccode)='{$ecode}' && id!='{$eshop_id}'");
            if ($ecount != 0) {
                $error[] = __('That code already exists', 'eshop');
            }
        }
        if (isset($_POST['eshop_remain'])) {
            $eshop_remain = $_POST['eshop_remain'];
        } else {
            $eshop_remain = '';
        }
        if ((!is_numeric($eshop_remain) || $eshop_remain < 0) && $eshop_remain != '') {
            $error[] = __('How many times can this be used - must be numeric, or blank', 'eshop');
        }
        if (isset($error)) {
            echo '<div class="error fade"><p>' . __('There were some errors:', 'eshop') . '</p>';
            echo '<ul>';
            foreach ($error as $err) {
                echo '<li>' . $err . "</li>\n";
            }
            echo "</ul></div>\n";
        } else {
            //no errors!
            //create date
            $eshop_code_date = $eshop_code_year . '-' . $eshop_code_month . '-' . $eshop_code_day;
            $eshop_id = $wpdb->escape(trim($_POST['editid']));
            $eshop_code = $wpdb->escape(trim($_POST['eshop_code']));
            $eshop_percent = $wpdb->escape($_POST['eshop_percent']);
            $eshop_remain = $wpdb->escape($_POST['eshop_remain']);
            $eshop_code_type = $wpdb->escape($_POST['eshop_code_type']);
            $eshop_code_month = $wpdb->escape(trim($_POST['eshop_code_month']));
            $eshop_code_day = $wpdb->escape(trim($_POST['eshop_code_day']));
            $eshop_code_year = $wpdb->escape(trim($_POST['eshop_code_year']));
            if ($eshop_id != '0') {
                //edit
                //$wpdb->query($wpdb->prepare("UPDATE $stocktable set available=$meta_value where post_id=$id"));
                $query = "UPDATE {$disctable} SET \r\n\t\t\t\tdtype='{$eshop_code_type}', \r\n\t\t\t\tdisccode='{$eshop_code}',\r\n\t\t\t\tpercent='{$eshop_percent}',\r\n\t\t\t\tremain='{$eshop_remain}',\r\n\t\t\t\tenddate='{$eshop_code_date}',\r\n\t\t\t\tlive='{$eshop_live}'\r\n\t\t\t\tWHERE id='{$eshop_id}' limit 1";
                $wpdb->query($query);
                echo '<div class="updated fade"><p>' . __('Discount code details updated', 'eshop') . '</p></div>';
            } else {
                //new
                $query = "INSERT INTO {$disctable} \r\n\t\t\t\t(dtype,disccode,percent,remain,enddate,live)\r\n\t\t\t\tVALUES\r\n\t\t\t\t('{$eshop_code_type}','{$eshop_code}','{$eshop_percent}','{$eshop_remain}','{$eshop_code_date}','{$eshop_live}')";
                $wpdb->query($wpdb->prepare($query));
                echo '<div class="updated fade"><p>' . __('Discount code details entered', 'eshop') . '</p></div>';
                //resetvalues
                $eshop_code = $eshop_percent = $eshop_remain = $eshop_used = $eshop_live = $eshop_free_ship = $eshop_code_date = $eshop_code_type = '';
                $editid = '0';
            }
        }
    }
    if ($edit == false) {
        $eshop_suggest = '<p>' . __('Suggested random codes:', 'eshop') . '</p>';
        $eshop_suggest .= '<ul>' . "\n";
        for ($i = 1; $i <= 3; $i++) {
            $eshop_suggest .= '<li>' . eshop_random_code('12') . '</li>' . "\n";
        }
        $eshop_suggest .= "</ul>\n";
    } else {
        $eshop_suggest = '<p><a href="' . $phpself . '">' . __('Enter new code', 'eshop') . '</a></p>';
    }
    ?>
	<div class="wrap">
	<div id="eshopicon" class="icon32"></div><h2><?php 
    _e('eShop Discount Codes', 'eshop');
    ?>
</h2>
	<?php 
    eshop_admin_mode();
    ?>
	<div id="eshopdisccodesform">
	<?php 
    echo $eshop_suggest;
    ?>
	<form id="eshopdisccodes" action="<?php 
    echo esc_url($_SERVER['REQUEST_URI']);
    ?>
" method="post">
		<fieldset><legend><?php 
    echo $legtext;
    ?>
</legend>
			<p><label for="eshop_code_type"><?php 
    _e('Discount type', 'eshop');
    ?>
</label>
			<select name="eshop_code_type" id="eshop_code_type">
		   	<option value=""><?php 
    _e('Please select', 'eshop');
    ?>
</option>
		   	<optgroup label="<?php 
    _e('Percentage', 'eshop');
    ?>
">
			<option value="1"<?php 
    echo $eshop_code_type == '1' ? ' selected="selected"' : '';
    ?>
><?php 
    _e('%  - Limited by Uses', 'eshop');
    ?>
</option>
			<option value="2"<?php 
    echo $eshop_code_type == '2' ? ' selected="selected"' : '';
    ?>
><?php 
    _e('%  - Limited by Date', 'eshop');
    ?>
</option>
			<option value="3"<?php 
    echo $eshop_code_type == '3' ? ' selected="selected"' : '';
    ?>
><?php 
    _e('%  - Limited by Uses and Date', 'eshop');
    ?>
</option>
			</optgroup>
			<optgroup label="<?php 
    _e('Free Shipping', 'eshop');
    ?>
">
			<option value="4"<?php 
    echo $eshop_code_type == '4' ? ' selected="selected"' : '';
    ?>
><?php 
    _e('Free Ship - Limited by Uses', 'eshop');
    ?>
</option>
			<option value="5"<?php 
    echo $eshop_code_type == '5' ? ' selected="selected"' : '';
    ?>
><?php 
    _e('Free Ship - Limited by Date', 'eshop');
    ?>
</option>
			<option value="6"<?php 
    echo $eshop_code_type == '6' ? ' selected="selected"' : '';
    ?>
><?php 
    _e('Free Ship - Limited by Uses and Date', 'eshop');
    ?>
</option>
			</optgroup>
			</select></p>
			<p><label for="eshop_code"><?php 
    _e('Code', 'eshop');
    ?>
</label><br />
			<input type="text" id="eshop_code" name="eshop_code" size="30" value="<?php 
    echo $eshop_code;
    ?>
" /></p>
			<p><label for="eshop_percent"><?php 
    _e('Discount percentage:', 'eshop');
    ?>
</label><br />
			<input type="text" id="eshop_percent" name="eshop_percent" size="4" value="<?php 
    echo $eshop_percent;
    ?>
" /></p>
			<p><label for="eshop_remain"><?php 
    _e('How many times can this be used (leave blank for unlimited)', 'eshop');
    ?>
</label><br />
			<input type="text" id="eshop_remain" name="eshop_remain" size="4" value="<?php 
    echo $eshop_remain;
    ?>
" /></p>
			<fieldset><legend><?php 
    _e('End Date', 'eshop');
    ?>
</legend>
			<p><label for="eshop_code_year"><?php 
    _e('Year', 'eshop');
    ?>
</label>
				<select name="eshop_code_year" id="eshop_code_year">
				<?php 
    // work this out!!!
    $eshopdate = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d"), date("Y")));
    if ($eshop_code_date != '') {
        $eshopdate = $eshop_code_date;
    }
    list($eshop_code_year, $eshop_code_month, $eshop_code_day) = explode('-', $eshopdate);
    for ($i = date('Y'); $i <= date('Y') + 5; $i++) {
        if ($i == $eshop_code_year) {
            $sel = ' selected="selected"';
        } else {
            $sel = '';
        }
        echo '<option value="' . $i . '"' . $sel . '>' . $i . '</option>' . "\n";
    }
    ?>
			  </select>
				<label for="eshop_code_month"><?php 
    _e('Month', 'eshop');
    ?>
</label>

				  <select name="eshop_code_month" id="eshop_code_month">
				<?php 
    for ($i = 1; $i <= 12; $i++) {
        if ($i == $eshop_code_month) {
            $sel = ' selected="selected"';
        } else {
            $sel = '';
        }
        echo '<option value="' . $i . '"' . $sel . '>' . $i . '</option>' . "\n";
    }
    ?>
			  </select>
				<label for="eshop_code_day"><?php 
    _e('Day', 'eshop');
    ?>
</label>

				  <select name="eshop_code_day" id="eshop_code_day">
				<?php 
    for ($i = 1; $i <= 31; $i++) {
        if ($i == $eshop_code_day) {
            $sel = ' selected="selected"';
        } else {
            $sel = '';
        }
        echo '<option value="' . $i . '"' . $sel . '>' . $i . '</option>' . "\n";
    }
    ?>
	 			</select></p>
	 		</fieldset>
			<p><input id="eshop_live" name="eshop_live" value="yes"<?php 
    echo $eshop_live == 'yes' ? ' checked="checked"' : '';
    ?>
 type="checkbox" /> <label for="eshop_live" class="selectit"><?php 
    _e('Active?', 'eshop');
    ?>
</label></p>
			<input type="hidden" name="editid" value="<?php 
    echo $editid;
    ?>
" />
			</fieldset>
			<p class="submit eshop"><input type="submit" id="submit" class="button-primary" value="<?php 
    echo $subtext;
    ?>
" /></p>
		</form>
	</div>
	<?php 
    $max = $wpdb->get_var("SELECT COUNT(id) FROM {$disctable} WHERE id > 0");
    if ($max > 0) {
        ?>
		<div id="eshopdisccodesexisting">
		<h3><?php 
        _e('Current Discount Codes', 'eshop');
        ?>
</h3>
		<table class="widefat" summary="<?php 
        _e('Discount Codes', 'eshop');
        ?>
">
		<caption><?php 
        _e('Discount codes reference table', 'eshop');
        ?>
</caption>
		<thead>
		<tr>
		<th id="code"><?php 
        _e('Code', 'eshop');
        ?>
</th>
		<th id="disc"><?php 
        _e('Discount', 'eshop');
        ?>
</th>
		<th id="type"><?php 
        _e('Type', 'eshop');
        ?>
</th>
		<th id="remain"><?php 
        _e('Remaining', 'eshop');
        ?>
</th>
		<th id="enddate"><?php 
        _e('End Date', 'eshop');
        ?>
</th>
		<th id="used"><?php 
        _e('Used', 'eshop');
        ?>
</th>
		<th id="active"><?php 
        _e('Active?', 'eshop');
        ?>
</th>
		<th id="delete"><?php 
        _e('Delete', 'eshop');
        ?>
</th>
		</tr>
		</thead>
		<tbody>
		<?php 
        $row = $wpdb->get_results("SELECT * FROM {$disctable}");
        $calt = 0;
        foreach ($row as $myrow) {
            $calt++;
            $alt = $calt % 2 ? '' : ' class="alternate"';
            $delete = '';
            $remain = $myrow->remain;
            if ($myrow->remain == '') {
                $remain = __('Unlimited', 'eshop');
            }
            if ($myrow->live != 'yes') {
                $delete = '<a href="' . $phpself . '&amp;delcode=' . $myrow->id . '">' . __('Delete', 'eshop') . ' ' . $myrow->disccode . '</a>';
            }
            $eshopdate = $myrow->enddate;
            //add in check to see if used.
            switch ($myrow->dtype) {
                case '1':
                    $type = __('%  - Limited by Uses', 'eshop');
                    $eshopdate = __('Not applicable', 'eshop');
                    break;
                case '2':
                    $type = __('%  - Limited by Date', 'eshop');
                    break;
                case '3':
                    $type = __('%  - Limited by Uses and Date', 'eshop');
                    break;
                case '4':
                    $type = __('Free Ship - Limited by Uses', 'eshop');
                    $eshopdate = __('Not applicable', 'eshop');
                    break;
                case '5':
                    $type = __('Free Ship - Limited by Date', 'eshop');
                    break;
                case '6':
                    $type = __('Free Ship - Limited by Uses and Date', 'eshop');
                    break;
            }
            echo '<tr' . $alt . '>
			<td headers="code" id="numb' . $calt . '"><a href="' . $phpself . '&amp;editcode=' . $myrow->id . '" title="' . __('Edit this discount', 'eshop') . '">' . $myrow->disccode . '</a></td>
			<td headers="disc numb' . $calt . '">' . number_format_i18n($myrow->percent, 2) . '%</td>
			<td headers="type numb' . $calt . '">' . $type . '</td>
			<td headers="remain numb' . $calt . '">' . $remain . '</td>
			<td headers="enddate numb' . $calt . '">' . $eshopdate . '</td>
			<td headers="used numb' . $calt . '">' . $myrow->used . '</td>
			<td headers="active numb' . $calt . '">' . $myrow->live . '</td>
			<td headers="delete numb' . $calt . '">' . $delete . '</td>' . "</tr>\n";
        }
        echo "</tbody></table></div>\n";
    }
    ?>
	</div>
	<?php 
}
Example #5
0
function eshop_downloads_manager()
{
    global $wpdb, $eshopoptions;
    $table = $wpdb->prefix . "eshop_downloads";
    $ordertable = $wpdb->prefix . "eshop_download_orders";
    $dir_upload = eshop_download_directory();
    $atitle = '';
    if (isset($_POST['up'])) {
        //borrowed this bit from wordpress
        $file_error_strings = array(false, __("The uploaded file exceeds the <code>upload_max_filesize</code> directive in <code>php.ini</code>."), __("The uploaded file exceeds the <em>MAX_FILE_SIZE</em> directive that was specified in the HTML form."), __("The uploaded file was only partially uploaded."), __("No file was uploaded."), __("Missing a temporary folder."), __("Failed to write file to disk."));
        $error = '';
        $new_name = "";
        if ($_POST['title'] != '') {
            if (function_exists('check_upload_size')) {
                //for MU
                check_upload_size($_FILES["upfile"]);
            }
            $replace = array("'", "\"", "&", " ");
            $file_name = str_replace($replace, "_", $_FILES["upfile"]["name"]);
            if (trim($_FILES["upfile"]["name"]) == "") {
                $error .= "<p>" . __('No file indicated', 'eshop') . "</p>";
            }
            if (!file_exists($dir_upload . $file_name) || $_POST['overwrite'] == 'yes') {
                if (@is_uploaded_file($_FILES["upfile"]["tmp_name"])) {
                    if (!file_exists($dir_upload . $file_name)) {
                        $newfile = 'y';
                    }
                    if (move_uploaded_file($_FILES["upfile"]["tmp_name"], $dir_upload . $file_name)) {
                        $success = '<p>' . __('File moved', 'eshop') . '</p>';
                    } else {
                        $error .= '<p>' . __('Failed to move file', 'eshop') . '</p>';
                    }
                } else {
                    $error .= "<p>" . __('Error uploading file', 'eshop') . " " . $_FILES["upfile"]["name"] . " <strong>" . $file_error_strings[$_FILES["upfile"]["error"]] . "</strong></p>";
                }
            } else {
                $error .= "<p>" . __('Error uploading file', 'eshop') . " " . $_FILES["upfile"]["name"] . " " . __('it <strong>already exists!</strong>', 'eshop') . "</p>";
            }
        } else {
            $error .= '<p>' . __('A title must be provided.', 'eshop') . '</p>';
        }
        if (isset($success) && !isset($newfile)) {
            $entfile = $wpdb->escape($file_name);
            $dafile = $wpdb->get_var("SELECT id FROM {$table} WHERE files='{$entfile}'");
            $enttitle = $wpdb->escape($_POST['title']);
            $wpdb->query("UPDATE {$table} SET title='{$enttitle}',added=NOW() WHERE id={$dafile}");
            echo '<div id="message" class="updated fade"><p>' . $_FILES["upfile"]["name"] . " " . __('has successfully overwritten existing file', 'eshop') . '</p></div>';
            do_action('eshop_file_upload', $dafile, $_POST);
            //file id & post variables
        } elseif ($error == '') {
            //ie a successful upload
            $enttitle = $wpdb->escape($_POST['title']);
            $entfile = $wpdb->escape($file_name);
            $wpdb->query("INSERT INTO {$table} (title,added,files) VALUES ('{$enttitle}',NOW(),'{$entfile}')");
            $dafile = $wpdb->get_var("SELECT id FROM {$table} WHERE files='{$entfile}'");
            do_action('eshop_file_upload', $dafile, $_POST);
            //file id & post variables
            echo '<div id="message" class="updated fade"><p>' . $_FILES["upfile"]["name"] . " " . __('has successfully uploaded', 'eshop') . '</p></div>';
        } else {
            //ie a failed upload
            echo '<div id="message" class="error fade">' . $error . '</div>';
            $atitle = $_POST['title'];
        }
        unset($_GET['edit']);
    }
    if (isset($_POST['editdelete'])) {
        // deleting entry
        $delid = $wpdb->escape($_POST['delid']);
        $delfile = $wpdb->get_var("SELECT files FROM {$table} WHERE id ={$delid}");
        $filepath = $dir_upload . $delfile;
        @unlink($filepath);
        $wpdb->query("DELETE FROM {$table} WHERE id = {$delid}");
        echo '<div id="message" class="updated fade"><p>' . __('File deleted successfully', 'eshop') . '</p></div>';
        unset($_GET['edit']);
    }
    //when edit a file this is the bit that gets used.
    if (isset($_POST['editamend'])) {
        if (is_numeric($_POST['downloads']) && is_numeric($_POST['purchases']) && $_POST['title'] != '') {
            //add in mysql update here
            $query = 'UPDATE ' . $table . ' SET title = "' . $wpdb->escape($_POST['title']) . '", downloads = "' . $wpdb->escape($_POST['downloads']) . '", purchases = "' . $wpdb->escape($_POST['purchases']) . '"  WHERE id = "' . $wpdb->escape($_POST['id']) . '"';
            $wpdb->query("{$query}");
            do_action('eshop_file_upload_amend', $_POST['id'], $_POST);
            //file id & post variables
            echo '<div id="message" class="updated fade"><p>' . __('File updated successfully', 'eshop') . '</p></div>';
        } else {
            //error handling
            if ($_POST['title'] == '') {
                $error .= '<li>' . __('The title for the file cannot be blank!', 'eshop') . '</li>';
            }
            if (!is_numeric($_POST['downloads'])) {
                $error .= '<li>' . __('Downloads should to be a number!', 'eshop') . '</li>';
            }
            if (!is_numeric($_POST['purchases'])) {
                $error .= '<li>' . __('Purchases should to be a number!', 'eshop') . '</li>';
            }
            echo '<div id="message" class="error fade"><p>' . __('Some errors were found:', 'eshop') . '</p><ul>' . $error . '</ul></div>';
        }
    }
    if (isset($_GET['eshop_orphan'])) {
        if (is_array(eshop_contains_files())) {
            foreach (eshop_contains_files() as $filename) {
                $file = $wpdb->escape($filename);
                list($title, $ext) = explode('.', $filename);
                $title = $wpdb->escape($title);
                $wpdb->query("INSERT INTO {$table} (title,added,files) VALUES ('{$title}',NOW(),'{$file}')");
            }
        }
    }
    if (isset($_GET['edit'])) {
        $id = $wpdb->escape($_GET['edit']);
        if ($wpdb->get_var("SELECT title FROM {$table} WHERE id ={$id}") != '') {
            //ie exists
            //echo '<div id="message" class="updated fade"><p>found it</p></div>';
            $row = $wpdb->get_row("SELECT * FROM {$table} WHERE id ={$id}");
            ?>
			<div class="wrap">
			<div id="eshopicon" class="icon32"></div><h2><?php 
            _e('Edit File details', 'eshop');
            ?>
</h2>
			<?php 
            eshop_admin_mode();
            ?>
			<table class="widefat" summary="<?php 
            _e('downloadable file details', 'eshop');
            ?>
">
			<caption><?php 
            _e('File details', 'eshop');
            ?>
</caption>
			<thead>
			 <tr>
			  <th id="edid"><?php 
            _e('ID', 'eshop');
            ?>
</th>
			  <th id="edtitle"><?php 
            _e('Title', 'eshop');
            ?>
</th>
			  <th id="edsize"><?php 
            _e('Size', 'eshop');
            ?>
</th>
			  <th id="edfile"><?php 
            _e('File name', 'eshop');
            ?>
</th>
			  <th id="eddate"><?php 
            _e('Upload Date', 'eshop');
            ?>
</th>
			  <th id="eddown"><?php 
            _e('Downloads', 'eshop');
            ?>
</th>
			  <th id="edpurc"><?php 
            _e('Purchases', 'eshop');
            ?>
</th>
			  <?php 
            $echo = '';
            echo apply_filters('eshop_download_table_extrahead', $echo);
            ?>
			 </tr>
			 </thead>
			 <tbody>
			 <?php 
            $size = eshop_filesize($row->files);
            $label = strlen($row->title) >= 20 ? substr($row->title, 0, 20) . "&#8230;" : $row->title;
            echo "<tr>\n";
            echo '<td id="redid' . $row->id . '" headers="edid">#' . $row->id . "</td>\n";
            echo '<td headers="edtitle redid' . $row->id . '">' . $label . "</td>\n";
            echo '<td headers="edsize redid' . $row->id . '">' . eshop_read_filesize($size) . "</td>\n";
            echo '<td headers="edfile redid' . $row->id . '">' . $row->files . "</td>\n";
            echo '<td headers="eddate redid' . $row->id . '">' . $row->added . "</td>\n";
            echo '<td headers="eddown redid' . $row->id . '">' . $row->downloads . "</td>\n";
            echo '<td headers="edpurc redid' . $row->id . '">' . $row->purchases . "</td>\n";
            $echo = '';
            echo apply_filters('eshop_download_table_extracell', $echo, $row);
            echo "</tr>\n";
            ?>
			 </tbody>
			</table>
			<?php 
            $pchk = checkfordownloads($id);
            if ($pchk['0'] == '1') {
                echo '<p class="productassociation">' . __('This file is associated with the following product pages:', 'eshop') . '</p>';
                echo '<ul class="productpages">';
                foreach ($pchk['1'] as $myrow) {
                    echo '<li><a href="post.php?action=edit&amp;post=' . $myrow . '" title="edit ' . get_the_title($myrow) . '">' . get_the_title($myrow) . '</a></li>';
                }
                echo '</ul>';
                ?>
				<p><?php 
                _e('You can only delete this file if it is <strong>not</strong> associated with a product page.', 'eshop');
                ?>
</p>
				<?php 
            }
            ?>
			<form method="post" action="" id="downloadedit">
			<fieldset><legend><?php 
            _e('Amend File details', 'eshop');
            ?>
</legend>
			<input type="hidden" name="id" value="<?php 
            echo $row->id;
            ?>
" />

			<label for="filetitle"><?php 
            _e('Title', 'eshop');
            ?>
</label><input type="text" name="title" id="filetitle" size="35" value="<?php 
            echo $row->title;
            ?>
" /><br />
			<label for="downloads"><?php 
            _e('Downloads', 'eshop');
            ?>
</label><input type="text" name="downloads" id="downloads" size="5" value="<?php 
            echo $row->downloads;
            ?>
" /><br />
			<label for="purchases"><?php 
            _e('Purchases', 'eshop');
            ?>
</label><input type="text" name="purchases" id="purchases" size="5" value="<?php 
            echo $row->purchases;
            ?>
" /><br />
			<?php 
            $echo = '';
            echo apply_filters('eshop_downloads_form_amend', $echo, $row);
            ?>
			</fieldset>
			  <p class="submit"><input type="submit" name="editamend" value="<?php 
            _e('Amend details', 'eshop');
            ?>
" class="button" /></p>
			</form>
			</div>
			<?php 
            if ($pchk['0'] == '0') {
                ?>
				<div class="wrap">
				<h2><?php 
                _e('Delete', 'eshop');
                ?>
</h2>
				<form method="post" action="" id="downloaddelete">
				<input type="hidden" name="delid" value="<?php 
                echo $row->id;
                ?>
" />
				<p class="submit"><input type="submit" name="editdelete" value="<?php 
                _e('Delete File', 'eshop');
                ?>
 '<?php 
                echo $row->title;
                ?>
'" class="button" /></p>
				</form>
				</div>
			<?php 
            }
        } else {
            //ie does not exist
            echo '<div id="message" class="error fade"><p>' . __('Product not found', 'eshop') . '.</p></div>';
        }
    } else {
        //first page you see
        $cda = $cdd = $cta = $cdwa = $cpa = $cia = '';
        if (isset($_GET['by'])) {
            switch ($_GET['by']) {
                case 'dd':
                    //date descending
                    $sortby = 'ORDER BY added DESC';
                    $cdd = ' class="current"';
                    break;
                case 'da':
                    //date ascending
                    $sortby = 'ORDER BY added ASC';
                    $cda = ' class="current"';
                    break;
                case 'ta':
                    //title alphabetically
                    $sortby = 'ORDER BY title ASC';
                    $cta = ' class="current"';
                    break;
                case 'dwa':
                    //number of downloads
                    $sortby = 'ORDER BY downloads ASC';
                    $cdwa = ' class="current"';
                    break;
                case 'pa':
                    //number of purchases
                    $sortby = 'ORDER BY purchases ASC';
                    $cpa = ' class="current"';
                    break;
                case 'ia':
                    //id
                //id
                default:
                    $sortby = 'ORDER BY id ASC';
                    $cia = ' class="current"';
            }
        } else {
            $cia = ' class="current"';
            $sortby = 'ORDER BY id ASC';
        }
        $range = 10;
        $max = $wpdb->get_var("SELECT COUNT(id) FROM {$table} WHERE id > 0");
        if ($eshopoptions['records'] != '' && is_numeric($eshopoptions['records'])) {
            $records = $eshopoptions['records'];
        } else {
            $records = '10';
        }
        if (isset($_GET['_p']) && is_numeric($_GET['_p'])) {
            $epage = $_GET['_p'];
        } else {
            $epage = '1';
        }
        if (!isset($_GET['eshopall'])) {
            $page_links = paginate_links(array('base' => add_query_arg('_p', '%#%'), 'format' => '', 'total' => ceil($max / $records), 'current' => $epage, 'type' => 'array'));
            $offset = $epage * $records - $records;
        } else {
            $page_links = paginate_links(array('base' => add_query_arg('_p', '%#%'), 'format' => '', 'total' => ceil($max / $records), 'current' => $epage, 'type' => 'array', 'show_all' => true));
            $offset = '0';
            $records = $max;
        }
        if ($max > 0) {
            $myrowres = $wpdb->get_results("Select * From {$table} {$sortby} LIMIT {$offset}, {$records}");
            //work out totals for quick stats
            $total = 0;
            $purchased = 0;
            $mycounts = $wpdb->get_row("Select SUM(downloads) as dlcount, SUM(purchases) as pucount From {$table}");
            $total = $mycounts->dlcount;
            $purchased = $mycounts->pucount;
            ?>
	<div class="wrap">
		<div id="eshopicon" class="icon32"></div><h2><?php 
            _e('Downloadable Products', 'eshop');
            ?>
</h2>
		<?php 
            eshop_admin_mode();
            ?>
		<?php 
            $apge = get_admin_url() . 'admin.php?page=eshop-downloads.php';
            echo '<ul id="eshopsubmenu" class="stuffbox">';
            echo '<li><span>' . __('Sort Orders by &raquo;', 'eshop') . '</span></li>';
            echo '<li><a href="' . $apge . '&amp;by=ia"' . $cia . '>' . __('ID Number', 'eshop') . '</a></li>';
            echo '<li><a href="' . $apge . '&amp;by=ta"' . $cta . '>' . __('Title', 'eshop') . '</a></li>';
            echo '<li><a href="' . $apge . '&amp;by=da"' . $cda . '>' . __('Date Ascending', 'eshop') . '</a></li>';
            echo '<li><a href="' . $apge . '&amp;by=dd"' . $cdd . '>' . __('Date Descending', 'eshop') . '</a></li>';
            echo '<li><a href="' . $apge . '&amp;by=dwa"' . $cdwa . '>' . __('Downloads', 'eshop') . '</a></li>';
            echo '<li><a href="' . $apge . '&amp;by=pa"' . $cpa . '>' . __('Purchases', 'eshop') . '</a></li>';
            echo '</ul>';
            ?>
		<p><strong><?php 
            _e('Total Downloads:', 'eshop');
            ?>
 </strong><?php 
            echo $total;
            ?>
<br />
		<strong><?php 
            _e('Total Purchases:', 'eshop');
            ?>
 </strong><?php 
            echo $purchased;
            ?>
<br />
		</p>  
		<table class="widefat" summary="<?php 
            _e('download listing', 'eshop');
            ?>
">
		<caption><?php 
            _e('Available downloads', 'eshop');
            ?>
</caption>
		<thead>
		 <tr>
		  <th id="edid"><?php 
            _e('ID', 'eshop');
            ?>
</th>
		  <th id="edtitle"><?php 
            _e('Title', 'eshop');
            ?>
</th>
		  <th id="edsize"><?php 
            _e('Size', 'eshop');
            ?>
</th>
		  <th id="edstatus"><?php 
            _e('Status', 'eshop');
            ?>
</th>
		  <th id="eddate"><?php 
            _e('Upload Date', 'eshop');
            ?>
</th>
		  <th id="eddown"><?php 
            _e('Downloads', 'eshop');
            ?>
</th>
		  <th id="edpurch"><?php 
            _e('Purchases', 'eshop');
            ?>
</th>
		  <?php 
            $echo = '';
            echo apply_filters('eshop_download_table_extrahead', $echo);
            ?>
		 </tr>
		 </thead>
		 <tbody>
		 <?php 
            $calt = 0;
            foreach ($myrowres as $row) {
                $size = eshop_filesize($row->files);
                $label = strlen($row->title) >= 20 ? substr($row->title, 0, 20) . "&#8230;" : $row->title;
                $calt++;
                $alt = $calt % 2 ? '' : ' class="alternate"';
                echo "<tr" . $alt . ">\n";
                echo '<td id="redid' . $row->id . '" headers="edid">#' . $row->id . "</td>\n";
                echo '<td headers="edtitle redid' . $row->id . '"><a href="?page=eshop-downloads.php&amp;edit=' . $row->id . '" title="' . __('edit details for', 'eshop') . ' ' . $row->title . '">' . $label . "</a></td>\n";
                echo '<td headers="edsize redid' . $row->id . '">' . eshop_read_filesize($size) . "</td>\n";
                echo '<td headers="edstatus redid' . $row->id . '">' . eshop_check_brokenlink($row->files) . "</td>\n";
                echo '<td headers="eddate redid' . $row->id . '">' . $row->added . "</td>\n";
                echo '<td headers="eddown redid' . $row->id . '">' . $row->downloads . "</td>\n";
                echo '<td headers="edpurch redid' . $row->id . '">' . $row->purchases . "</td>\n";
                $echo = '';
                echo apply_filters('eshop_download_table_extracell', $echo, $row);
                echo "</tr>\n";
            }
            ?>
		 </tbody>
		</table>
	<?php 
            //paginate
            echo '<div class="paginate tablenav-pages stuffbox">';
            if ($records != $max) {
                $eecho = $page_links;
            }
            echo sprintf('<span class="displaying-num">' . __('Displaying %s&#8211;%s of %s') . '</span>', number_format_i18n(($epage - 1) * $records + 1), number_format_i18n(min($epage * $records, $max)), number_format_i18n($max));
            if (isset($eecho)) {
                $thispage = esc_url(add_query_arg('eshopall', 'yes', $_SERVER['REQUEST_URI']));
                echo "<ul class='page-numbers'>\n\t<li>" . join("</li>\n\t<li>", $eecho) . "</li>\n<li>" . '<a href="' . $thispage . '">' . __('View All', 'eshop') . '</a>' . "</li>\n</ul>\n";
            }
            echo '<br /></div>';
            //end
        } else {
            ?>
		<div class="wrap">
		<div id="eshopicon" class="icon32"></div><h2><?php 
            _e('Downloadable Products', 'eshop');
            ?>
</h2>
		<?php 
            eshop_admin_mode();
            ?>
		<p><?php 
            _e('You currently have no downloadable products', 'eshop');
            ?>
.</p>
		
	<?php 
        }
        ?>
		</div>
		<?php 
        $dirpath = eshop_download_directory();
        if (!is_writeable($dirpath)) {
            echo '
			<div id="message" class="error fade">
			<p>' . __('<strong>Warning!</strong>The download directory is not currently writable! File permissions must first be changed.', 'eshop') . '
			</p>
			</div>' . "\n";
        } else {
            // only displayed if the directory is writable to.
            $eshopmaxupload = ini_get("upload_max_filesize") * 1048576;
            ?>
			<div class="wrap">
			<h2><?php 
            _e('Upload a File', 'eshop');
            ?>
</h2>
			<?php 
            $eshopmaxfilesize = ini_get("upload_max_filesize");
            //if mu use this
            if (function_exists('check_upload_size')) {
                $eshopmaxfilesize = eshop_read_filesize(1024 * get_site_option('fileupload_maxk', 1500));
            }
            ?>
			<p><?php 
            _e('Use this to upload your local file. Max file size is ', 'eshop');
            echo $eshopmaxfilesize;
            ?>
</p>
			<form action="" method="post" id="eshopup" enctype="multipart/form-data">
			<fieldset><legend><?php 
            _e('Upload', 'eshop');
            ?>
</legend>
				<input type="hidden" name="MAX_FILE_SIZE" value="<?php 
            echo $eshopmaxupload;
            ?>
" />
				<label for="filetitle" class="lab"><?php 
            _e('Title', 'eshop');
            ?>
</label><input type="text" name="title" id="filetitle" size="35" value="<?php 
            echo $atitle;
            ?>
" /><br />
			   <label for="upfile" class="lab"><?php 
            _e('Local File', 'eshop');
            ?>
</label>
				 <input name="upfile" type="file" id="upfile" size="45" />
				 <fieldset><legend><?php 
            _e('Overwrite file if it exists', 'eshop');
            ?>
</legend>
				 <input name="overwrite" type="radio" id="overwrite" value="no" checked="checked" /><label for="overwrite"><?php 
            _e('No', 'eshop');
            ?>
</label>
				 <input name="overwrite" type="radio" id="yesoverwrite" value="yes" /><label for="yesoverwrite"><?php 
            _e('Yes', 'eshop');
            ?>
</label>
				<?php 
            $echo = '';
            echo apply_filters('eshop_downloads_form', $echo);
            ?>
				 </fieldset>
				</fieldset>
				  <p class="submit"><input type="submit" name="up" value="<?php 
            _e('Upload File', 'eshop');
            ?>
" class="button-primary" /></p>
			</form>
		</div>
		<?php 
        }
        //check for downloads that were uploaded via FTP.
        if (is_array(eshop_contains_files())) {
            ?>
			<div class="wrap">
			<h2><?php 
            _e('Unknown Download Files', 'eshop');
            ?>
</h2>
			<ul>
			<?php 
            foreach (eshop_contains_files() as $contains) {
                echo '<li>' . $contains . '</li>';
            }
            ?>
			</ul>
			<p><a href="<?php 
            echo esc_url($_SERVER['REQUEST_URI']) . '&amp;eshop_orphan';
            ?>
"><?php 
            _e('Add all unknown download files', 'eshop');
            ?>
</a></p>
			</div>
			<?php 
        }
    }
}
    function on_show_page()
    {
        //we need the global screen column value to beable to have a sidebar in WordPress 2.8
        global $screen_layout_columns;
        $eshopoptions = get_option('eshop_plugin_settings');
        $err = '';
        //set up submenu here so it can accessed in the code
        if (isset($_POST['eshop-action-status'])) {
            $_GET['mstatus'] = $_POST['eshop-action-status'];
        }
        if (isset($_GET['mstatus'])) {
            $action_status = esc_attr($_GET['mstatus']);
        } else {
            $_GET['mstatus'] = $action_status = 'General';
        }
        $stati = array('General' => __('General', 'eshop'), 'Merchant' => __('Merchant Gateways', 'eshop'), 'Tax' => __('Sales Tax', 'eshop'), 'Discounts' => __('Discounts', 'eshop'), 'Downloads' => __('Downloads', 'eshop'), 'Pages' => __('Special Pages', 'eshop'), 'Base' => __('eShop Base', 'eshop'));
        foreach ($stati as $status => $label) {
            $class = '';
            if ($status == $action_status) {
                $class = ' nav-tab-active';
            }
            $dalink = add_query_arg('page', ESHOP_SETTINGS_PAGE_NAME, 'options-general.php');
            $dalink = add_query_arg('mstatus', $status, $dalink);
            $dalink = esc_url($dalink);
            $status_links[] = '<li><a href="' . $dalink . '" class="nav-tab' . $class . '">' . $label . '</a>';
        }
        //end submenu
        //add a 3rd content box now for demonstration purpose, boxes added at start of page rendering can't be switched on/off,
        //may be needed to ensure that a special box is always available
        //add_meta_box('howto-metaboxes-contentbox-3', 'Contentbox 3 Title (impossible to hide)', array(&$this, 'on_contentbox_3_content'), $this->pagehook, 'normal', 'core');
        //define some data can be given to each metabox during rendering
        $data = $eshopoptions;
        echo '<div id="eshop-metaboxes-general" class="wrap">';
        echo '<div id="eshopicon" class="icon32"></div><h2>' . __('eShop Settings', 'eshop') . '</h2>' . "\n";
        //info:
        eshop_check_error();
        eshop_admin_mode();
        //the submenu
        echo '<ul class="nav-tab-wrapper">';
        echo implode('</li>', $status_links) . '</li>';
        echo '</ul><br class="clear" />';
        if (isset($_GET['resetbase']) && $_GET['resetbase'] == 'yes') {
            $table = $wpdb->prefix . 'eshop_base_products';
            $wpdb->query("TRUNCATE TABLE {$table}");
            echo '<div id="message" class="updated fade"><p>' . __('eShop Base product data has been reset.', 'eshop') . '</p></div>' . "\n";
        } elseif (isset($_POST['submit'])) {
            echo '<div id="message" class="updated fade"><p>' . __('eshop Settings have been updated.', 'eshop') . '</p></div>' . "\n";
        }
        ?>
		<form method="post" action="admin-post.php" id="eshop-settings">
		<input type='hidden' name='option_page' value='eshop_settings' />
			<?php 
        wp_nonce_field('eshop-metaboxes-general');
        ?>
			<?php 
        wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
        ?>
			<?php 
        wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
        ?>
			<input type="hidden" name="action" value="save_eshop_metaboxes_general" />
			
			<input type="hidden" name="eshop-action-status" value="<?php 
        echo $action_status;
        ?>
" />

			<div id="poststuff" class="metabox-holder<?php 
        echo 2 == $screen_layout_columns ? ' has-right-sidebar' : '';
        ?>
">
				<div id="side-info-column" class="inner-sidebar">
				<p class="submit">
					<input type="submit" name="submit" class="button-primary" value="<?php 
        _e('Save Changes', 'eshop');
        ?>
" />
				</p>
					<?php 
        do_meta_boxes($this->pagehook, 'side', $data);
        ?>
				</div>
				<div id="post-body"<?php 
        echo 2 == $screen_layout_columns ? ' class="has-sidebar"' : '';
        ?>
 >
					<div id="post-body-content"<?php 
        echo 2 == $screen_layout_columns ? '  class="has-sidebar-content"' : '';
        ?>
>
						<?php 
        do_meta_boxes($this->pagehook, 'normal', $data);
        ?>
						<p class="submit">
							<input type="submit" name="submit" class="button-primary" value="<?php 
        _e('Save Changes', 'eshop');
        ?>
" />
						</p>
					</div>
				</div>
				<br class="clear"/>
								
			</div>	
		</form>
		</div>
	<script type="text/javascript">
		//<![CDATA[
		jQuery(document).ready( function($) {
			// close postboxes that should be closed
			$('.if-js-closed').removeClass('if-js-closed').addClass('closed');
			// postboxes setup
			postboxes.add_postbox_toggles('<?php 
        echo $this->pagehook;
        ?>
');
		});
		//]]>
	</script>
		
		<?php 
    }
Example #7
0
function eshop_form_admin_style()
{
    //make sure options exist for the style page
    //config options
    $eshopurl = eshop_files_directory();
    $styleFile = $eshopurl['0'] . 'eshop.css';
    $style = eshop_process_style($styleFile);
    $eshopoptions = get_option('eshop_plugin_settings');
    if (!is_writeable($styleFile)) {
        echo ' <div id="message" class="error fade"><p>' . __('<strong>Warning!</strong> The css file is not currently editable/writable! File permissions must first be changed.', 'eshop') . '</p>
	   	</div>' . "\n";
    }
    ?>
<div class="wrap">
<div id="eshopicon" class="icon32"></div><h2><?php 
    _e('eShop Styles', 'eshop');
    ?>
</h2>
<?php 
    eshop_admin_mode();
    ?>
</div>
<div class="wrap">
<h2><?php 
    _e('Default Style', 'eshop');
    ?>
</h2>
<?php 
    if (@file_exists(get_stylesheet_directory() . '/eshop.css')) {
        echo '<p>';
        _e('Your active theme has an eshop style sheet, eshop.css, and will be used in preference to the default style below. Therefore changes made via the style editor below will not show on your site.', 'eshop');
        echo '</p>';
    } else {
        ?>
<p><?php 
        _e('Default style is used by default. You can edit this via the editor below, or choose not to use it.', 'eshop');
        ?>
</p>
<form action="themes.php?page=eshop-style.php" method="post" id="style_form" name="style">
 <fieldset>
  <legend><?php 
        _e('Use Default Style', 'eshop');
        ?>
</legend>
  <?php 
        if ($eshopoptions['style'] == 'yes') {
            $yes = ' checked="checked"';
            $no = '';
        } else {
            $no = ' checked="checked"';
            $yes = '';
        }
        ?>
  <input type="radio" id="usestyle" name="usestyle" value="yes"<?php 
        echo $yes;
        ?>
 /><label for="usestyle"><?php 
        _e('Yes', 'eshop');
        ?>
</label> 
  <input type="radio" id="nostyle" name="usestyle" value="no"<?php 
        echo $no;
        ?>
 /><label for="nostyle"><?php 
        _e('No', 'eshop');
        ?>
</label>
  <p class="submit eshop"><input type="submit" value="<?php 
        _e('Amend', 'eshop');
        ?>
" name="submit" /></p>

</fieldset>
</form>
<?php 
    }
    //check for new css
    $plugin_dir = WP_PLUGIN_DIR;
    $dirs = wp_upload_dir();
    $upload_dir = $dirs['basedir'];
    $eshop_goto = $upload_dir . '/eshop_files/eshop.css';
    $eshop_from = $plugin_dir . '/eshop/files/eshop.css';
    $eshopver = split('\\.', ESHOP_VERSION);
    $left_string = file_get_contents($eshop_from, true);
    $right_string = file_get_contents($eshop_goto, true);
    ?>
</div>
<div class="wrap">
<h2><?php 
    _e('Style Editor', 'eshop');
    ?>
</h2>
 <p><?php 
    _e('Use this simple <abbr><span class="abbr" title="Cascading Style Sheet">CSS</span></abbr> file editor to modify the default style sheet file.', 'eshop');
    ?>
</p>
 <form method="post" action="themes.php?page=eshop-style.php" id="edit_box">
  <fieldset>
   <legend><?php 
    _e('Style File Editor.', 'eshop');
    ?>
</legend>
   <label for="stylebox"><?php 
    _e('Edit Style', 'eshop');
    ?>
</label><br />
	<textarea rows="20" cols="80" id="stylebox" name="cssFile"><?php 
    if (!is_file($styleFile)) {
        $error = 1;
    }
    if (!isset($error) && filesize($styleFile) > 0) {
        $f = "";
        $f = fopen($styleFile, 'r');
        $file = fread($f, filesize($styleFile));
        echo $file;
        fclose($f);
    } else {
        _e('Sorry. The file you are looking for could not be found', 'eshop');
    }
    ?>
</textarea>
   <p class="submit eshop"><input type="submit" class="button-primary" value="<?php 
    _e('Update Style', 'eshop');
    ?>
" name="submit" /></p>
  </fieldset>
</form>
</div>
	<?php 
    $left_string = normalize_whitespace($left_string);
    $right_string = normalize_whitespace($right_string);
    if (isset($_GET['diff'])) {
        echo '<div class="wrap" id="diff">';
        echo wp_text_diff($right_string, $left_string, array('title' => __('Comparing Current Style with latest installed version of eShop', 'eshop'), 'title_right' => __('Latest(from plugin)', 'eshop'), 'title_left' => __('Current (in use)', 'eshop')));
        echo '</div>';
    } elseif (trim($left_string) != trim($right_string)) {
        echo '<div class="wrap">';
        echo '<p>' . __('There may have been updates to the style.', 'eshop') . ' <a href="themes.php?page=eshop-style.php&amp;diff#diff">' . __('Compare Current Style with latest installed version of eShop.', 'eshop') . '</a></p>';
        echo '</div>';
    } else {
        echo '<div class="wrap">';
        echo '<p>' . __('Your CSS matches that included with eShop.', 'eshop') . '</p>';
        echo '</div>';
    }
}
function eshop_template_email()
{
    global $wpdb;
    $table = $wpdb->prefix . 'eshop_emails';
    if (isset($_POST['edit'])) {
        $subject = $wpdb->escape($_POST['subject']);
        $content = $wpdb->escape($_POST['templateContent']);
        $edit = $wpdb->escape($_POST['edit']);
        $wpdb->query("UPDATE {$table} set emailSubject='{$subject}',emailContent='{$content}' where id='{$edit}'");
        echo '<div id="message" class="updated fade"><p><strong>' . __('The Template Has Been Updated', 'eshop') . '</strong></p></div>' . "\n";
    }
    if (isset($_GET['eshopuse']) && is_numeric($_GET['eshopuse'])) {
        $edit = $_GET['eshopuse'];
        $wpdb->query("UPDATE {$table} set emailUse=(CASE WHEN emailUse=1 THEN 0 ELSE 1 END) where id='{$edit}'");
        echo '<div id="message" class="updated fade"><p><strong>' . __('The Template Has Been Changed', 'eshop') . '</strong></p></div>' . "\n";
    }
    ?>
<div class="wrap">
<div id="eshopicon" class="icon32"></div><h2><?php 
    _e('eShop Email Templates', 'eshop');
    ?>
</h2>
<?php 
    eshop_admin_mode();
    ?>
 <p><?php 
    _e('Use this page to modify your default email templates', 'eshop');
    ?>
.</p> 
<table class="eshop widefat" summary="available email templates">
<thead><tr><th id="num">#</th><th id="type"><?php 
    _e('Type', 'eshop');
    ?>
</th><th id="blank"><?php 
    _e('Template?', 'eshop');
    ?>
</th><th id="act"><?php 
    _e('Active', 'eshop');
    ?>
</th><th id="chg"><?php 
    _e('Change', 'eshop');
    ?>
</th></tr></thead>
<tbody>
<?php 
    $eshoptemplate = '1';
    if (isset($_GET['eshoptemplate']) && is_numeric($_GET['eshoptemplate'])) {
        $eshoptemplate = $_GET['eshoptemplate'];
    }
    $thisemail = $wpdb->get_results("Select * From {$table}");
    $phpself = get_admin_url() . 'admin.php?page=eshop-templates.php';
    $x = 1;
    foreach ($thisemail as $this_email) {
        $active = '';
        $state = __('Active', 'eshop');
        if ($this_email->id > 2) {
            if ($this_email->emailUse == 1) {
                $active = __('Deactivate', 'eshop') . ' ' . $this_email->id;
            } else {
                $active = __('Activate', 'eshop') . ' ' . $this_email->id;
                $state = '';
            }
        }
        $alt = $x % 2 ? '' : ' class="alternate"';
        if ($this_email->emailContent == '') {
            $ewarn = ' <span class="ewarn">' . __('Template is blank', 'eshop') . '</span>';
        } else {
            $ewarn = ' <span class="emailok">' . __('Template exists', 'eshop') . '</span>';
        }
        ?>
	<tr<?php 
        echo $alt;
        ?>
><td id="row<?php 
        echo $x;
        ?>
" headers="num"><?php 
        echo $this_email->id;
        ?>
</td><td headers="row<?php 
        echo $x;
        ?>
 num"><a href="<?php 
        echo $phpself . '&amp;eshoptemplate=' . $this_email->id;
        ?>
#edit_section" title="<?php 
        _e('edit', 'eshop');
        ?>
"><?php 
        echo $this_email->emailType;
        ?>
</a></td>
	<td headers="row<?php 
        echo $x;
        ?>
 blank"><?php 
        echo $ewarn;
        ?>
</td>
	<td headers="row<?php 
        echo $x;
        ?>
 act"><?php 
        echo $state;
        ?>
</td><td headers="row<?php 
        echo $x;
        ?>
 chg"><a href="<?php 
        echo $phpself . '&amp;eshopuse=' . $this_email->id;
        ?>
"><?php 
        echo $active;
        ?>
</a></td></tr>
	<?php 
        $x++;
    }
    ?>
</tbody>
</table>

</div>
<div class="wrap">
<?php 
    $thisemail = $wpdb->get_row("Select emailType, emailSubject,emailContent From {$table} where id={$eshoptemplate}");
    ?>
<h2 id="edit_section"><?php 
    _e('Email Template Editor', 'eshop');
    ?>
</h2>
 <p><?php 
    _e('Use this simple file editor to modify the default email template file.', 'eshop');
    ?>
</p>
 <form method="post" action="" id="edit_box">
  <fieldset>
   <legend><?php 
    _e('Template:', 'eshop');
    ?>
 <?php 
    echo $thisemail->emailType;
    ?>
 </legend>
   	<label for="subject"><?php 
    _e('Subject', 'eshop');
    ?>
<br /><input type="text" id="subject" name="subject" size="60" value="<?php 
    echo htmlspecialchars(stripslashes($thisemail->emailSubject));
    ?>
" /></label><br />

   <label for="stylebox"><?php 
    _e('Email Content', 'eshop');
    ?>
</label><br />
<textarea rows="20" cols="80" id="stylebox" name="templateContent">
<?php 
    echo htmlspecialchars(stripslashes($thisemail->emailContent));
    ?>
</textarea>
	<input type="hidden" name="edit" value="<?php 
    echo $eshoptemplate;
    ?>
" />
	<input type="hidden" name="eshoptemplate" value="<?php 
    echo $eshoptemplate;
    ?>
" />
   <p class="submit eshop"><input type="submit" class="button-primary" value="<?php 
    _e('Update Template', 'eshop');
    ?>
" name="submit" /></p>
  </fieldset>
</form>
</div>
<div class="wrap">
<h2><?php 
    _e('Template tags for Email Content', 'eshop');
    ?>
</h2>
<ul>
<li><strong>{STATUS}</strong> - <?php 
    _e('the status of the order.', 'eshop');
    ?>
</li>
<li><strong>{FIRSTNAME}</strong> - <?php 
    _e('Customers First Name.', 'eshop');
    ?>
</li>
<li><strong>{NAME}</strong> - <?php 
    _e('Customers Full Name', 'eshop');
    ?>
</li>
<li><strong>{EMAIL}</strong> - <?php 
    _e('Customers Email address', 'eshop');
    ?>
</li>
<li><strong>{CART}</strong> - <?php 
    _e('The contents of the customers order (i.e. their shopping cart)', 'eshop');
    ?>
</li>
<li><strong>{DOWNLOADS}</strong> - <?php 
    _e('A Download link along with the customers email address and password. <em>Only used when an order contains downloads</em>. (not used for cash or bank sales).', 'eshop');
    ?>
</li>
<li><strong>{ADDRESS}</strong> - <?php 
    _e('Customers Address', 'eshop');
    ?>
</li>
<li><strong>{REFCOMM}</strong> - <?php 
    _e('The reference and other messages provided by the customer.', 'eshop');
    ?>
</li>
<li><strong>{CONTACT}</strong> - <?php 
    _e('Customers shipping address phone number.', 'eshop');
    ?>
</li>
<li><strong>{ORDERDATE}</strong> - <?php 
    _e('Date and time of order.', 'eshop');
    ?>
</li>
<?php 
    do_action('eshopemailtags');
    ?>
</ul>
<p><?php 
    _e('To change the default email that notifies the customer when signing up to you site(if enabled) you may need to install another plugin such as <a href="http://wordpress.org/extend/plugins/new-user-email-set-up/">New user Email Set Up</a>.', 'eshop');
    ?>
</p>
</div>
	<?php 
}