WordPress.org

Plugin Directory

Changeset 392883


Ignore:
Timestamp:
06/03/11 22:35:11 (3 years ago)
Author:
MrWiblog
Message:

1.3: Allowed the expiry date to be a number of days in the future. Also added a start date on which a voucher will become available.

Location:
voucherpress/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • voucherpress/trunk/readme.txt

    r324796 r392883  
    55Requires at least: 2.8 
    66Tested up to: 3.0.3 
    7 Stable tag: 1.2 
     7Stable tag: 1.3 
    88 
    99VoucherPress is a Wordpress plugin that allows you to give downloadable, printable vouchers/tickets/coupons/tokens in PDF format away on your site. 
     
    2626 
    2727add_action( 'voucherpress_create', 'my_voucherpress_create_function' ); 
    28 function my_voucherpress_create_function( $id, $name, $text, $description, $template, $require_email, $limit, $expiry ) { 
     28function my_voucherpress_create_function( $id, $name, $text, $description, $template, $require_email, $limit, $startdate, $expiry ) { 
    2929    // do something here... 
    3030} 
     
    3535 
    3636add_action( 'voucherpress_edit', 'my_voucherpress_edit_function' ); 
    37 function my_voucherpress_edit_function( $id, $name, $text, $description, $template, $require_email, $limit, $expiry ) { 
     37function my_voucherpress_edit_function( $id, $name, $text, $description, $template, $require_email, $limit, $startdate, $expiry ) { 
    3838    // do something here... 
    3939} 
     
    124124== Changelog == 
    125125 
     126= 1.3 (2011/06/03) = 
     127 
     128Allowed the expiry date to be a number of days in the future. Also added a start date on which a voucher will become available. 
     129 
    126130= 1.2 (2010/12/20) = 
    127131 
  • voucherpress/trunk/voucherpress.js

    r260209 r392883  
    4343function vp_show_random() { 
    4444    jQuery("#codelengthline").show(); 
     45    jQuery("#codeprefixline").show(); 
     46    jQuery("#codesuffixline").show(); 
    4547} 
    4648function vp_check_sequential(e) { 
    4749    vp_hide_form_options(); 
    4850    if (this.checked) { 
    49         jQuery("#codeprefixline").show(); 
    50         jQuery("#codesuffixline").show(); 
     51        vp_show_sequential(); 
    5152    } 
    5253} 
    53 function vp_show_sequential(e) { 
     54function vp_show_sequential() { 
    5455    jQuery("#codeprefixline").show(); 
    5556    jQuery("#codesuffixline").show(); 
     
    6364function vp_show_custom() { 
    6465    jQuery("#customcodelistline").show(); 
     66    jQuery("#codeprefixline").hide(); 
     67    jQuery("#codesuffixline").hide(); 
    6568} 
    6669function vp_check_single(e) { 
     
    7275function vp_show_single() { 
    7376    jQuery("#singlecodetextline").show(); 
     77    jQuery("#codeprefixline").hide(); 
     78    jQuery("#codesuffixline").hide(); 
    7479} 
    7580function vp_new_window(e) { 
  • voucherpress/trunk/voucherpress.php

    r324796 r392883  
    33 * @package VoucherPress 
    44 * @author Chris Taylor 
    5  * @version 1.2 
     5 * @version 1.3 
    66 */ 
    77/* 
     
    1010Description: VoucherPress allows you to offer downloadable, printable vouchers from your Wordpress site. Vouchers can be available to anyone, or require a name and email address before they can be downloaded. 
    1111Author: Chris Taylor 
    12 Version: 1.2 
     12Version: 1.3 
    1313Author URI: http://www.stillbreathing.co.uk/ 
    1414*/ 
     
    1616// set the current version 
    1717function voucherpress_current_version() { 
    18     return "1.2"; 
     18    return "1.3"; 
    1919} 
    2020 
     
    3333function voucherpress_init() { 
    3434    if ( function_exists( "add_action" ) ) { 
     35        // add init action 
     36        add_action( "init", "voucherpress_prepare" ); 
    3537        // add template redirect action 
    3638        add_action( "template_redirect", "voucherpress_template" ); 
     
    6769} 
    6870 
     71function voucherpress_prepare() { 
     72    $plugin_dir = basename(dirname(__FILE__)); 
     73    load_plugin_textdomain( 'voucherpress', null, $plugin_dir ); 
     74} 
     75 
    6976function voucherpress_template() { 
    7077    // if requesting a voucher 
     
    115122    //} else { 
    116123        wp_die( __( "Sorry, that item has expired", "voucherpress" ) ); 
     124    //} 
     125    exit(); 
     126} 
     127 
     128// show an expired voucher page 
     129function voucherpress_notyetavailable() { 
     130    global $wp_query; 
     131    $wp_query->set_404(); 
     132    //if ( file_exists( TEMPLATEPATH.'/404.php' ) ) { 
     133    //  require TEMPLATEPATH.'/404.php'; 
     134    //} else { 
     135        wp_die( __( "Sorry, that item is not yet available", "voucherpress" ) ); 
    117136    //} 
    118137    exit(); 
     
    313332              guid varchar(36) NOT NULL, 
    314333              live TINYINT DEFAULT '0', 
     334              startdate int DEFAULT '0', 
    315335              expiry int DEFAULT '0', 
    316336              codestype varchar(12) DEFAULT 'random', 
     
    321341              deleted tinyint DEFAULT '0', 
    322342              PRIMARY KEY  id (id) 
    323             );"; 
     343            ) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"; 
    324344        dbDelta( $sql ); 
    325345         
     
    336356              downloaded TINYINT DEFAULT '0', 
    337357              PRIMARY KEY  id (id) 
    338             );"; 
     358            ) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"; 
    339359        dbDelta( $sql ); 
    340360         
     
    347367              live tinyint DEFAULT '1', 
    348368              PRIMARY KEY  id (id) 
    349             );"; 
     369            ) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"; 
    350370        dbDelta( $sql ); 
    351371         
     
    615635    <input type="text" name="limit" id="limit" class="num" value="" /> <span>' . __( "Set the number of times this voucher can be downloaded (leave blank or 0 for unlimited)", "voucherpress" ) . '</span></p> 
    616636     
     637    <p><label for="startyear">' . __( "Date voucher starts being available", "voucherpress" ) . '</label> 
     638    ' . __( "Year:", "voucherpress" ) . ' <input type="text" name="startyear" id="startyear" class="num" value="" /> 
     639    ' . __( "Month:", "voucherpress" ) . ' <input type="text" name="startmonth" id="startmonth" class="num" value="" /> 
     640    ' . __( "Day:", "voucherpress" ) . ' <input type="text" name="startday" id="startday" class="num" value="" />  
     641    <span>' . __( "Enter the date on which this voucher will become available (leave blank if this voucher is immediately available)", "voucherpress" ) . '</span></p> 
     642     
    617643    <p><label for="expiryyear">' . __( "Date voucher expires", "voucherpress" ) . '</label> 
    618644    ' . __( "Year:", "voucherpress" ) . ' <input type="text" name="expiryyear" id="expiryyear" class="num" value="" /> 
     
    621647    <span>' . __( "Enter the date on which this voucher will expire (leave blank for never)", "voucherpress" ) . '</span></p> 
    622648     
     649    <p><label for="expirydays">' . __( "Or enter the number of days the voucher will stay live", "voucherpress" ) . '</label> 
     650    <input type="text" class="num" name="expirydays" id="expirydays" value="" /></p> 
     651     
    623652    <h3>' . __( "Voucher codes", "voucherpress" ) . '</h3> 
     653     
     654    <p>' . __("The code prefix and suffix will only be used on random and sequential codes.", "voucherpress") . '</p> 
     655     
     656    <p id="codeprefixline"><label for="codeprefix">' . __( "Code prefix", "voucherpress" ) . '</label> 
     657    <input type="text" name="codeprefix" id="codeprefix" /> <span>' . __( "Text to show before the code (eg <strong>ABC</strong>123XYZ)", "voucherpress" ) . '</span></p> 
     658     
     659    <p id="codesuffixline"><label for="codesuffix">' . __( "Code suffix", "voucherpress" ) . '</label> 
     660    <input type="text" name="codesuffix" id="codesuffix" /> <span>' . __( "Text to show after the code (eg ABC123<strong>XYZ</strong>)", "voucherpress" ) . '</span></p> 
    624661     
    625662    <p><label for="randomcodes">' . __( "Use random codes", "voucherpress" ) . '</label> 
     
    637674    <p><label for="sequentialcodes">' . __( "Use sequential codes", "voucherpress" ) . '</label> 
    638675    <input type="radio" name="codestype" id="sequentialcodes" value="sequential" /> <span>' . __( "Tick this box to use sequential codes (1, 2, 3 etc) on each voucher", "voucherpress" ) . '</span></p> 
    639      
    640     <p class="hider" id="codeprefixline"><label for="codeprefix">' . __( "Sequential code prefix", "voucherpress" ) . '</label> 
    641     <input type="text" name="codeprefix" id="codeprefix" /> <span>' . __( "Text to show before the sequential code (eg <strong>ABC</strong>123XYZ)", "voucherpress" ) . '</span></p> 
    642      
    643     <p class="hider" id="codesuffixline"><label for="codesuffix">' . __( "Sequential code suffix", "voucherpress" ) . '</label> 
    644     <input type="text" name="codesuffix" id="codesuffix" /> <span>' . __( "Text to show after the sequential code (eg ABC123<strong>XYZ</strong>)", "voucherpress" ) . '</span></p> 
    645676     
    646677    <p><label for="customcodes">' . __( "Use custom codes", "voucherpress" ) . '</label> 
     
    763794        } 
    764795         
     796        // if this voucher has a start date not yet reached 
     797        if ( $voucher->startdate != "" && (int)$voucher->startdate != 0 && (int)$voucher->startdate > time() ) { 
     798            echo ' 
     799            <div id="message" class="updated fade"> 
     800                <p><strong>' . __( "This voucher is not yet available. Change the start date below to allow this voucher to be downloaded.", "voucherpress" ) . '</strong></p> 
     801            </div> 
     802            '; 
     803        } 
     804         
    765805        echo ' 
    766806        <form action="admin.php?page=vouchers&amp;id=' . $_GET["id"] . '" method="post" id="voucherform"> 
     
    840880        <input type="text" name="limit" id="limit" class="num" value="' . $voucher->limit . '" /> <span>' . __( "Set the number of times this voucher can be downloaded (leave blank for unlimited)", "voucherpress" ) . '</span></p> 
    841881         
     882        <p><label for="startyear">' . __( "Date voucher starts being available", "voucherpress" ) . '</label> 
     883        ' . __( "Year:", "voucherpress" ) . ' <input type="text" name="startyear" id="startyear" class="num" value="'; 
     884        if ( $voucher->startdate != "" && $voucher->startdate > 0 ) { 
     885            echo date( "Y", $voucher->startdate  ); 
     886        } 
     887        echo '" /> 
     888        ' . __( "Month:", "voucherpress" ) . ' <input type="text" name="startmonth" id="startmonth" class="num" value="'; 
     889        if ( $voucher->startdate != "" && $voucher->startdate > 0 ) { 
     890            echo date( "n", $voucher->startdate  ); 
     891        } 
     892        echo '" /> 
     893        ' . __( "Day:", "voucherpress" ) . ' <input type="text" name="startday" id="startday" class="num" value="'; 
     894        if ( $voucher->startdate != "" && $voucher->startdate > 0 ) { 
     895            echo date( "j", $voucher->startdate  ); 
     896        } 
     897        echo '" />  
     898        <span>' . __( "Enter the date on which this voucher will become available (leave blank if this voucher is available immediately)", "voucherpress" ) . '</span></p> 
     899         
    842900        <p><label for="expiry">' . __( "Date voucher expires", "voucherpress" ) . '</label> 
    843901        ' . __( "Year:", "voucherpress" ) . ' <input type="text" name="expiryyear" id="expiryyear" class="num" value="'; 
     
    857915        echo '" />  
    858916        <span>' . __( "Enter the date on which this voucher will expire (leave blank for never)", "voucherpress" ) . '</span></p> 
     917         
     918        <p><label for="expirydays">' . __( "Or enter the number of days the voucher will stay live", "voucherpress" ) . '</label> 
     919    <input type="text" class="num" name="expirydays" id="expirydays" value="" /></p> 
    859920         
    860921        <p><strong>' . __( "This box MUST be ticked for this voucher to be available.", "voucherpress" ) . '</strong></p> 
     
    868929        <h3>' . __( "Voucher codes", "voucherpress" ) . '</h3> 
    869930     
     931        <p>' . __("The code prefix and suffix will only be used on random and sequential codes.", "voucherpress") . '</p> 
     932     
     933        <p id="codeprefixline"><label for="codeprefix">' . __( "Code prefix", "voucherpress" ) . '</label> 
     934    <input type="text" name="codeprefix" id="codeprefix" value="' . $voucher->codeprefix . '" /> <span>' . __( "Text to show before the sequential code (eg <strong>ABC</strong>123XYZ)", "voucherpress" ) . '</span></p> 
     935     
     936        <p id="codesuffixline"><label for="codesuffix">' . __( "Code suffix", "voucherpress" ) . '</label> 
     937    <input type="text" name="codesuffix" id="codesuffix" value="' . $voucher->codesuffix . '" /> <span>' . __( "Text to show after the sequential code (eg ABC123<strong>XYZ</strong>)", "voucherpress" ) . '</span></p> 
     938     
    870939        <p><label for="randomcodes">' . __( "Use random codes", "voucherpress" ) . '</label> 
    871940        <input type="radio" name="codestype" id="randomcodes" value="random"'; 
     
    910979        } 
    911980        echo ' /> <span>' . __( "Tick this box to use sequential codes (1, 2, 3 etc) on each voucher", "voucherpress" ) . '</span></p> 
    912          
    913         <p class="hider" id="codeprefixline"><label for="codeprefix">' . __( "Sequential code prefix", "voucherpress" ) . '</label> 
    914     <input type="text" name="codeprefix" id="codeprefix" value="' . $voucher->codeprefix . '" /> <span>' . __( "Text to show before the sequential code (eg <strong>ABC</strong>123XYZ)", "voucherpress" ) . '</span></p> 
    915      
    916         <p class="hider" id="codesuffixline"><label for="codesuffix">' . __( "Sequential code suffix", "voucherpress" ) . '</label> 
    917     <input type="text" name="codesuffix" id="codesuffix" value="' . $voucher->codesuffix . '" /> <span>' . __( "Text to show after the sequential code (eg ABC123<strong>XYZ</strong>)", "voucherpress" ) . '</span></p> 
    918981         
    919982        <p><label for="customcodes">' . __( "Use custom codes", "voucherpress" ) . '</label> 
     
    13651428    if ( $id != "" ) { 
    13661429        $voucher = voucherpress_get_voucher( $id ); 
    1367         if ( $voucher && ( $voucher->expiry == "" || (int)$voucher->expiry == 0 || (int)$voucher->expiry > time() ) ) { 
     1430        if ( $voucher && ( ( $voucher->expiry == "" || (int)$voucher->expiry == 0 || (int)$voucher->expiry > time() ) ) && ( $voucher->startdate == "" || (int)$voucher->startdate == 0 || (int)$voucher->startdate < time() ) ) { 
    13681431            if ( $preview == 'true' ) { 
    13691432                return '<a href="' . voucherpress_link( $voucher->guid ) . '"><img src="' . get_option( "siteurl" ) . '/wp-content/plugins/voucherpress/templates/' . $voucher->template . '_thumb.jpg" alt="' . htmlspecialchars( $voucher->name ) . '" /></a>'; 
     
    13721435            } 
    13731436        } else { 
    1374             $r = "<!-- The shortcode for voucher " . $id . " is displaying nothing because the voucher was not found, or the expiry date has passed"; 
     1437            $r = "<!-- The shortcode for voucher " . $id . " is displaying nothing because the voucher was not found, or the expiry date has passed, or the start date is still in the future"; 
    13751438            if ( $voucher ) { 
    1376                 $r .= ". Voucher found, expiry: '" . $voucher->expiry . "'"; 
     1439                $r .= ". Voucher found, expiry: " . $voucher->expiry . ", start date: " . $voucher->startdate; 
    13771440            } 
    13781441            $r .= " -->"; 
     
    13891452    if ( $id != "" ) { 
    13901453        $voucher = voucherpress_get_voucher( $id ); 
    1391         if ( $voucher && ( $voucher->expiry == "" || (int)$voucher->expiry == 0 || (int)$voucher->expiry > time() ) ) { 
     1454        if ( $voucher && ( ( $voucher->expiry == "" || (int)$voucher->expiry == 0 || (int)$voucher->expiry > time() ) ) && ( $voucher->startdate == "" || (int)$voucher->startdate == 0 || (int)$voucher->startdate < time() ) ) { 
    13921455            return voucherpress_register_form( $voucher->guid, true ); 
    13931456        } else { 
    1394             $r = "<!-- The form shortcode for voucher " . $id . " is displaying nothing because the voucher was not found, or the expiry date has passed"; 
     1457            $r = "<!-- The form shortcode for voucher " . $id . " is displaying nothing because the voucher was not found, or the expiry date has passed, or the start date is still in the future"; 
    13951458            if ( $voucher ) { 
    1396                 $r .= ". Voucher found, expiry: '" . $voucher->expiry . "'"; 
     1459                $r .= ". Voucher found, expiry: " . $voucher->expiry . ", start date: " . $voucher->startdate; 
    13971460            } 
    13981461            $r .= " -->"; 
     
    14551518        $limit = 0; 
    14561519        if ( $_POST["limit"] != "" && $_POST["limit"] != "0" ) { $limit = (int)$_POST["limit"]; } 
     1520        $startdate = 0; 
     1521        if ( $_POST["startyear"] != "" && $_POST["startyear"] != "0" && $_POST["startmonth"] != "" && $_POST["startmonth"] != "0" && $_POST["startday"] != "" && $_POST["startday"] != "0" ) { $startdate = strtotime( $_POST["startyear"] . "/" . $_POST["startmonth"] . "/" . $_POST["startday"]); } 
    14571522        $expiry = 0; 
    14581523        if ( $_POST["expiryyear"] != "" && $_POST["expiryyear"] != "0" && $_POST["expirymonth"] != "" && $_POST["expirymonth"] != "0" && $_POST["expiryday"] != "" && $_POST["expiryday"] != "0" ) { $expiry = strtotime( $_POST["expiryyear"] . "/" . $_POST["expirymonth"] . "/" . $_POST["expiryday"]); } 
     1524        if ( $_POST["expirydays"] != "" && is_numeric( $_POST["expirydays"] ) > 0 ) { $expiry = time() + ( intval( $_POST["expirydays"] ) * 24 * 60 * 60 ); } 
     1525        if ( $_POST["expirydays"] != "" && is_numeric( $_POST["expirydays"] ) > 0 && $startdate > 0 ) { $expiry = $startdate + ( intval( $_POST["expirydays"] ) * 24 * 60 * 60 ); }  
    14591526        if ( $_POST["codestype"] == "random" || $_POST["codestype"]== "sequential" || $_POST["codestype"]== "custom" || $_POST["codestype"]== "single" ) { 
    14601527            $codestype = $_POST["codestype"]; 
     
    14791546            $codes = trim( $_POST["singlecodetext"] ); 
    14801547        } 
    1481         $array = voucherpress_create_voucher( $_POST["name"], $require_email, $limit, $_POST["text"], $_POST["description"], $_POST["template"], $_POST["font"], $_POST["terms"], $expiry, $codestype, $codelength, $codeprefix, $codesuffix, $codes ); 
     1548        $array = voucherpress_create_voucher( $_POST["name"], $require_email, $limit, $_POST["text"], $_POST["description"], $_POST["template"], $_POST["font"], $_POST["terms"], $startdate, $expiry, $codestype, $codelength, $codeprefix, $codesuffix, $codes ); 
    14821549        if ( $array && is_array( $array ) && $array[0] == true && $array[1] > 0 ) { 
    14831550            // eventually the plugin will create thumbnails for a voucher 
     
    15111578        $limit = 0; 
    15121579        if ( $_POST["limit"] != "" && $_POST["limit"] != "0" ) { $limit = (int)$_POST["limit"]; } 
     1580        $startdate = 0; 
     1581        if ( $_POST["startyear"] != "" && $_POST["startyear"] != "0" && $_POST["startmonth"] != "" && $_POST["startmonth"] != "0" && $_POST["startday"] != "" && $_POST["startday"] != "0" ) { $startdate = strtotime( $_POST["startyear"] . "/" . $_POST["startmonth"] . "/" . $_POST["startday"]); } 
    15131582        $expiry = 0; 
    15141583        if ( $_POST["expiryyear"] != "" && $_POST["expiryyear"] != "0" && $_POST["expirymonth"] != "" && $_POST["expirymonth"] != "0" && $_POST["expiryday"] != "" && $_POST["expiryday"] != "0" ) { $expiry = strtotime( $_POST["expiryyear"] . "/" . $_POST["expirymonth"] . "/" . $_POST["expiryday"]); } 
     1584        if ( $_POST["expirydays"] != "" && is_numeric( $_POST["expirydays"] ) > 0 ) { $expiry = time() + ( intval( $_POST["expirydays"] ) * 24 * 60 * 60 ); } 
     1585        if ( $_POST["expirydays"] != "" && is_numeric( $_POST["expirydays"] ) > 0 && $startdate > 0 ) { $expiry = $startdate + ( intval( $_POST["expirydays"] ) * 24 * 60 * 60 ); }  
    15151586        if ( $_POST["codestype"] == "random" || $_POST["codestype"]== "sequential" || $_POST["codestype"]== "custom" || $_POST["codestype"]== "single" ) { 
    15161587            $codestype = $_POST["codestype"]; 
     
    15351606            $codes = trim( $_POST["singlecodetext"] ); 
    15361607        } 
    1537         $done = voucherpress_edit_voucher( $_GET["id"], $_POST["name"], $require_email, $limit, $_POST["text"], $_POST["description"], $_POST["template"], $_POST["font"], $_POST["terms"], $live, $expiry, $codestype, $codelength, $codeprefix, $codesuffix, $codes ); 
     1608        $done = voucherpress_edit_voucher( $_GET["id"], $_POST["name"], $require_email, $limit, $_POST["text"], $_POST["description"], $_POST["template"], $_POST["font"], $_POST["terms"], $live, $startdate, $expiry, $codestype, $codelength, $codeprefix, $codesuffix, $codes ); 
    15381609        if ( $done ) { 
    15391610            header( "Location: admin.php?page=vouchers&id=" . $_GET["id"] . "&result=3" ); 
     
    16161687 
    16171688// create a new voucher 
    1618 function voucherpress_create_voucher( $name, $require_email, $limit, $text, $description, $template, $font, $terms, $expiry, $codestype, $codelength, $codeprefix, $codesuffix, $codes ) { 
     1689function voucherpress_create_voucher( $name, $require_email, $limit, $text, $description, $template, $font, $terms, $startdate, $expiry, $codestype, $codelength, $codeprefix, $codesuffix, $codes ) { 
    16191690 
    16201691    // check voucherpress is installed correctly 
     
    16271698    if ( isset( $wpdb->base_prefix ) ) { $prefix = $wpdb->base_prefix; } 
    16281699    $sql = $wpdb->prepare( "insert into " . $prefix . "voucherpress_vouchers  
    1629     (blog_id, name, `text`, `description`, terms, template, font, require_email, `limit`, guid, time, live, expiry, codestype, codelength, codeprefix, codesuffix, codes, deleted)  
     1700    (blog_id, name, `text`, `description`, terms, template, font, require_email, `limit`, guid, time, live, startdate, expiry, codestype, codelength, codeprefix, codesuffix, codes, deleted)  
    16301701    values  
    1631     (%d, %s, %s, %s, %s, %d, %s, %d, %d, %s, %d, %d, %d, %s, %d, %s, %s, %s, 0);",  
    1632     $blog_id, $name, $text, $description, $terms, $template, $font, $require_email, $limit, $guid, time(), 1, $expiry, $codestype, $codelength, $codeprefix, $codesuffix, $codes ); 
     1702    (%d, %s, %s, %s, %s, %d, %s, %d, %d, %s, %d, %d, %d, %d, %s, %d, %s, %s, %s, 0);",  
     1703    $blog_id, $name, $text, $description, $terms, $template, $font, $require_email, $limit, $guid, time(), 1, $startdate, $expiry, $codestype, $codelength, $codeprefix, $codesuffix, $codes ); 
    16331704    $done = $wpdb->query( $sql ); 
    16341705    $id = 0; 
    16351706    if ( $done ) { 
    16361707        $id = $wpdb->insert_id; 
    1637         do_action( "voucherpress_create", $id, $name, $text, $description, $template, $require_email, $limit, $expiry ); 
     1708        do_action( "voucherpress_create", $id, $name, $text, $description, $template, $require_email, $limit, $startdate, $expiry ); 
    16381709    } 
    16391710    return array( $done, $id ); 
     
    16411712 
    16421713// create a new voucher thumbnail 
    1643 function voucherpress_create_voucher_thumb( $id, $name, $require_email, $limit, $text, $template, $font, $terms, $expiry ) { 
     1714function voucherpress_create_voucher_thumb( $id, $name, $require_email, $limit, $text, $template, $font, $terms, $startdate, $expiry ) { 
    16441715    // do nothing 
    16451716} 
     
    16641735 
    16651736// edit a voucher 
    1666 function voucherpress_edit_voucher( $id, $name, $require_email, $limit, $text, $description, $template, $font, $terms, $live, $expiry, $codestype, $codelength, $codeprefix, $codesuffix, $codes ) { 
     1737function voucherpress_edit_voucher( $id, $name, $require_email, $limit, $text, $description, $template, $font, $terms, $live, $startdate, $expiry, $codestype, $codelength, $codeprefix, $codesuffix, $codes ) { 
    16671738 
    16681739    // check voucherpress is installed correctly 
     
    16841755    `limit` = %d, 
    16851756    live = %d, 
     1757    startdate = %d, 
    16861758    expiry = %d, 
    16871759    codestype = %s, 
     
    16921764    where id = %d  
    16931765    and blog_id = %d;",  
    1694     time(), $name, $text, $description, $terms, $template, $font, $require_email, $limit, $live, $expiry, $codestype, $codelength, $codeprefix, $codesuffix, $codes, $id, $blog_id ); 
     1766    time(), $name, $text, $description, $terms, $template, $font, $require_email, $limit, $live, $startdate, $expiry, $codestype, $codelength, $codeprefix, $codesuffix, $codes, $id, $blog_id ); 
    16951767    $done = $wpdb->query( $sql ); 
    16961768    if ( $done ) { 
    1697         do_action( "voucherpress_edit", $id, $name, $text, $description, $template, $require_email, $limit, $expiry ); 
     1769        do_action( "voucherpress_edit", $id, $name, $text, $description, $template, $require_email, $limit, $startdate, $expiry ); 
    16981770    } 
    16991771    return $done; 
     
    18071879    $prefix = $wpdb->prefix; 
    18081880    if ( isset( $wpdb->base_prefix ) ) { $prefix = $wpdb->base_prefix; } 
    1809     $sql = "select b.domain, b.path, v.id, v.name, v.`text`, v.terms, v.require_email, v.`limit`, v.live, v.expiry, v.guid,  
     1881    $sql = "select b.domain, b.path, v.id, v.name, v.`text`, v.terms, v.require_email, v.`limit`, v.live, v.startdate, v.expiry, v.guid,  
    18101882(select count(d.id) from " . $prefix . "voucherpress_downloads d where d.voucherid = v.id) as downloads 
    18111883from " . $prefix . "voucherpress_vouchers v 
     
    18281900    $prefix = $wpdb->prefix; 
    18291901    if ( isset( $wpdb->base_prefix ) ) { $prefix = $wpdb->base_prefix; } 
    1830     $sql = $wpdb->prepare( "select v.id, v.name, v.`text`, v.`description`, v.terms, v.require_email, v.`limit`, v.live, v.expiry, v.guid,  
     1902    $sql = $wpdb->prepare( "select v.id, v.name, v.`text`, v.`description`, v.terms, v.require_email, v.`limit`, v.live, v.startdate, v.expiry, v.guid,  
    18311903(select count(d.id) from " . $prefix . "voucherpress_downloads d where d.voucherid = v.id) as downloads 
    18321904from " . $prefix . "voucherpress_vouchers v 
    18331905where (%s = '1' or v.live = 1) 
     1906and (%s = '1' or (expiry = '' or expiry = 0 or expiry > %d)) 
     1907and (%s = '1' or (startdate = '' or startdate = 0 or startdate <= %d)) 
    18341908and v.blog_id = %d 
    18351909and v.deleted = 0 
    18361910order by v.time desc  
    1837 " . $limit . ";", $showall, $blog_id ); 
     1911" . $limit . ";", $showall, $showall, time(), $showall, time(), $blog_id ); 
    18381912    return $wpdb->get_results( $sql ); 
    18391913} 
     
    18471921    $prefix = $wpdb->prefix; 
    18481922    if ( isset( $wpdb->base_prefix ) ) { $prefix = $wpdb->base_prefix; } 
    1849     $sql = "select b.domain, b.path, v.id, v.name, v.`text`, v.`description`, v.terms, v.require_email, v.`limit`, v.live, v.expiry, v.guid,  
     1923    $sql = "select b.domain, b.path, v.id, v.name, v.`text`, v.`description`, v.terms, v.require_email, v.`limit`, v.live, v.startdate, v.expiry, v.guid,  
    18501924count(d.id) as downloads 
    18511925from " . $prefix . "voucherpress_downloads d  
     
    18671941    $prefix = $wpdb->prefix; 
    18681942    if ( isset( $wpdb->base_prefix ) ) { $prefix = $wpdb->base_prefix; } 
    1869     $sql = $wpdb->prepare( "select v.id, v.name, v.`text`, v.`description`, v.terms, v.require_email, v.`limit`, v.live, v.expiry, v.guid,  
     1943    $sql = $wpdb->prepare( "select v.id, v.name, v.`text`, v.`description`, v.terms, v.require_email, v.`limit`, v.live, v.startdate, v.expiry, v.guid,  
    18701944count(d.id) as downloads 
    18711945from " . $prefix . "voucherpress_downloads d  
     
    18901964    // get by id 
    18911965    if ( is_numeric( $voucher ) ) { 
    1892         $sql = $wpdb->prepare( "select v.id, v.name, v.`text`, v.`description`, v.terms, v.font, v.template, v.require_email, v.`limit`, v.expiry, v.guid, v.live, '' as registered_email, '' as registered_name, 
     1966        $sql = $wpdb->prepare( "select v.id, v.name, v.`text`, v.`description`, v.terms, v.font, v.template, v.require_email, v.`limit`, v.startdate, v.expiry, v.guid, v.live, '' as registered_email, '' as registered_name, 
    18931967        v.codestype, v.codeprefix, v.codesuffix, v.codelength, v.codes, 
    18941968        (select count(d.id) from " . $prefix . "voucherpress_downloads d where d.voucherid = v.id) as downloads 
    18951969        from " . $prefix . "voucherpress_vouchers v 
    18961970        where  
    1897         (%d = 0 or v.live = 1) 
     1971        (%s = '0' or v.live = 1) 
     1972        and (%s = '0' or (expiry = '' or expiry = 0 or expiry > %d)) 
     1973        and (%s = '0' or (startdate = '' or startdate = 0 or startdate <= %d)) 
    18981974        and v.id = %d 
    18991975        and v.deleted = 0 
    19001976        and v.blog_id = %d",  
    1901         $live, $voucher, $blog_id ); 
     1977        $live, $live, time(), $live, time(), $voucher, $blog_id ); 
    19021978    // get by guid 
    19031979    } else { 
     
    19051981        if ( $code != "") 
    19061982        { 
    1907             $sql = $wpdb->prepare( "select v.id, v.name, v.`text`, v.`description`, v.terms, v.font, v.template, v.require_email, v.`limit`, v.expiry, v.guid, v.live, r.email as registered_email, r.name as registered_name, 
     1983            $sql = $wpdb->prepare( "select v.id, v.name, v.`text`, v.`description`, v.terms, v.font, v.template, v.require_email, v.`limit`, v.startdate, v.expiry, v.guid, v.live, r.email as registered_email, r.name as registered_name, 
    19081984            v.codestype, v.codeprefix, v.codesuffix, v.codelength, v.codes, 
    19091985            (select count(d.id) from " . $prefix . "voucherpress_downloads d where d.voucherid = v.id) as downloads 
     
    19111987            left outer join " . $prefix . "voucherpress_downloads r on r.voucherid = v.id and r.guid = %s 
    19121988            where  
    1913             v.live = 1 
     1989            (%s = '0' or v.live = 1) 
     1990            and (%s = '0' or (expiry = '' or expiry = 0 or expiry > %d)) 
     1991            and (%s = '0' or (startdate = '' or startdate = 0 or startdate <= %d)) 
    19141992            and v.deleted = 0 
    19151993            and v.guid = %s 
    19161994            and v.blog_id = %d",  
    1917             $code, $voucher, $blog_id ); 
     1995            $code, $live, $live, time(), $live, time(), $voucher, $blog_id ); 
    19181996        } else { 
    1919             $sql = $wpdb->prepare( "select v.id, v.name, v.`text`, v.`description`, v.terms, v.font, v.template, v.require_email, v.`limit`, v.expiry, v.guid, v.live, '' as registered_email, '' as registered_name, 
     1997            $sql = $wpdb->prepare( "select v.id, v.name, v.`text`, v.`description`, v.terms, v.font, v.template, v.require_email, v.`limit`, v.startdate, v.expiry, v.guid, v.live, '' as registered_email, '' as registered_name, 
    19201998            v.codestype, v.codeprefix, v.codesuffix, v.codelength, v.codes, 
    19211999            (select count(d.id) from " . $prefix . "voucherpress_downloads d where d.voucherid = v.id) as downloads 
    19222000            from " . $prefix . "voucherpress_vouchers v 
    19232001            where  
    1924             (%d = 0 or v.live = 1) 
     2002            (%s = '0' or v.live = 1) 
     2003            and (%s = '0' or (expiry = '' or expiry = 0 or expiry > %d)) 
     2004            and (%s = '0' or (startdate = '' or startdate = 0 or startdate <= %d)) 
    19252005            and v.deleted = 0 
    19262006            and v.guid = %s 
    19272007            and v.blog_id = %d",  
    1928             $live, $voucher, $blog_id); 
     2008            $live, $live, time(), $live, time(), $voucher, $blog_id); 
    19292009        } 
    19302010    } 
     
    20082088            voucherpress_expired(); 
    20092089             
     2090        } else if ( $valid === "notyetavailable" )  { 
     2091         
     2092            // this voucher is not yet available 
     2093            print "<!-- The voucher is not yet available -->"; 
     2094            voucherpress_notyetavailable(); 
     2095             
    20102096        } 
    20112097    } else { 
     
    23312417        $blog_id = voucherpress_blog_id(); 
    23322418        global $wpdb; 
    2333         $sql = $wpdb->prepare( "select v.id, v.require_email, ifnull( d.email, '' ) as email, ifnull( d.downloaded, 0 ) as downloaded, v.`limit`, v.expiry from 
     2419        $sql = $wpdb->prepare( "select v.id, v.require_email, ifnull( d.email, '' ) as email, ifnull( d.downloaded, 0 ) as downloaded, v.`limit`, v.startdate, v.expiry from 
    23342420                " . $prefix . "voucherpress_vouchers v 
    23352421                left outer join " . $prefix . "voucherpress_downloads d on d.voucherid = v.id and d.guid = %s 
     
    23562442            if ( (int)$row->expiry != 0 && (int)$row->expiry <= time() ) { 
    23572443                return "expired"; 
     2444            } 
     2445             
     2446            // if there is a start date and the tart date is in the future 
     2447            if ( (int)$row->startdate != 0 && (int)$row->startdate > time() ) { 
     2448                return "notyetavailable"; 
    23582449            } 
    23592450             
     
    24612552     
    24622553        // create the random code 
    2463         $code = voucherpress_guid($voucher_codestype->codelength); 
     2554        $code = $voucher_codestype->codeprefix . voucherpress_guid($voucher_codestype->codelength) . $voucher_codestype->codesuffix; 
    24642555         
    24652556    } 
Note: See TracChangeset for help on using the changeset viewer.