Paypal Donate


( ! ) Warning: Parameter 1 to Savant2_Plugin_ahreflisting::plugin() expected to be a reference, value given in /home/ceditbiz/public_html/components/com_mtree/Savant2.php on line 1127
Call Stack
#TimeMemoryFunctionLocation
10.0007622440{main}( )../index.php:0
20.12852414152JSite->dispatch( )../index.php:68
30.13302492368JComponentHelper->renderComponent( )../application.php:124
40.16522630032require_once( '/home/ceditbiz/public_html/components/com_mtree/mtree.php' )../helper.php:162
50.18352740904viewlink( )../mtree.php:84
60.20923348112JCacheCallback->call( )../mtree.php:1850
70.20923349256JCacheCallback->get( )../callback.php:48
80.22473392712call_user_func_array:{/home/ceditbiz/public_html/libraries/joomla/cache/handler/callback.php:99} ( )../callback.php:99
90.22473393520viewlink_cache( )../callback.php:99
100.23903490448Savant2->display( )../mtree.php:1952
110.23903490448Savant2->fetch( )../Savant2.php:987
120.23963532704include( '/home/ceditbiz/public_html/components/com_mtree/templates/m2/page_listing.tpl.php' )../Savant2.php:958
130.24133536008include( '/home/ceditbiz/public_html/components/com_mtree/templates/m2/sub_listingDetails.tpl.php' )../page_listing.tpl.php:14
140.24143543064Savant2->plugin( )../sub_listingDetails.tpl.php:30
150.24143544904call_user_func_array:{/home/ceditbiz/public_html/components/com_mtree/Savant2.php:1154} ( )../Savant2.php:1154
160.24143545664Savant2->splugin( )../Savant2.php:1154
170.24283555392call_user_func_array:{/home/ceditbiz/public_html/components/com_mtree/Savant2.php:1127} ( )../Savant2.php:1127

I use these three functions to create date dropdowns in forms.  They are configured for UK dates, but could easily be modified for other locales.  You can create as many as you need on a page, just ensure that they have different names.

createDateDropdowns will create three dropdown menus to allow a user to select a date.  The parameters (which are all optional) are:
$class: the CSS class that will be applied to each dropdown
$name: the name given to the dropdown (to be used by readDateDropdowns - each dropdown is actually given a modified name)
$currentvalue: the current date to be displayed (e.g. that read from a database)
$yearupper: the number of years ahead that will be displayed
$yearlower: the number of years behind that will be displayed
$optional: whether the field is required
$monthnames: whether the months are displayed in full or as numbers
$widths(): an array of the widths for the dropdowns (three elements expected).

readDateDropdowns will read the posted values as a single variable date, so that they can be used for whatever purposes (e.g. send to MySQL database).  You just send the name of the dropdowns to the function (the same name used when they were created!). 

function createDateDropdowns( $class = '', $name = 'date', $currentvalue = '', $yearupper = 120,
 $yearlower = 120, $optional = true, $monthnames = true, $widths = array( 50, 80, 60 ) ) {
    // Create date dropdowns for easy date selection
    
    $months = array(1=>'January', 'February', 'March', 'April', 'May', 'June', 'July',
                    'August', 'September', 'October', 'November', 'December');
    if ( $currentvalue == '' && !$optional ) $currentvalue = date('Y-m-d');
    $currentyear = date('Y');
    if ( $currentvalue != '' ) {
        list($year, $month, $day) = explode( '-', $currentvalue );
        if ( $currentyear + $yearupper < $year ) $year = $currentyear + $yearupper;
    }
    $html='';
    
    // Create the day dropdown
    $html .= "<select class=\"$class\"";
    $html .= ' style="width:' . $widths[0] . 'px;"';
    $html .= ' id="' . $name . 'day"';
    $html .= ' name="' . $name . 'day"';
    $html .= ' >';
    if ( $optional ) {
        $html .= '<option value="0"';
        if ( $currentvalue == '' ) $html .= ' selected="selected"';
        $html .='>-</option>';
    }
    for ( $i=1; $i<32; $i++ ) {
        $html .= '<option value="' . $i . '"';
        if ( $i == $day ) $html .= ' selected="selected"';
        $html .= '>' . $i . '</option>';
    }
    $html .= '</select>';
    
    // Create the month dropdown
    $html .= "<select class=\"$class\"";
    $html .= ' style="width:' . $widths[1] . 'px;"';
    $html .= ' id="' . $name . 'month"';
    $html .= ' name="' . $name . 'month"';
    $html .= ' >';
    if ( $optional ) {
        $html .= '<option value="0"';
        if ( $currentvalue == '' ) $html .= ' selected="selected"';
        $html .='>-</option>';
    }
    if ( $monthnames ) {
        // Show month names
        for ( $i=1; $i<13; $i++ ) {
            $html .= '<option value="' . $i . '"';
            if ( $i == $month ) $html .= ' selected="selected"';
            $html .= '>' . $months[$i] . '</option>';
        }
        
    } else {
        // Show month numbers
        for ( $i=1; $i<13; $i++ ) {
            $html .= '<option value="' . $i . '"';
            if ( $i == $month ) $html .= ' selected="selected"';
            $html .= '>' . $i . '</option>';
        }
    }
    $html .= '</select>';
    
    // Create the year dropdown
    $html .= "<select class=\"$class\"";
    $html .= ' style="width:' . $widths[2] . 'px;"';
    $html .= ' id="' . $name . 'year"';
    $html .= ' name="' . $name . 'year"';
    $html .= ' >';
    if ( $optional ) {
        $html .= '<option value="0"';
        if ( $currentvalue == '' ) $html .= ' selected="selected"';
        $html .='>-</option>';
    }
    for ( $i = ( $currentyear - $yearlower ); $i <= ( $currentyear + $yearupper ); $i++ ) {
        $html .= '<option value="' . $i . '"';
        if ( $i == $year ) $html .= ' selected="selected"';
        $html .= '>' . $i . '</option>';
    }
    $html .= '</select>';
    return $html;
}

function readDateDropdowns( $name = 'date' ) {
    // Reads and returns the date from the date dropdowns
    $day = $_POST[$name .'day'];
    if ( $day < 1 ) return '';
    $month = $_POST[$name .'month'];
    if ( $month < 1 ) return '';
    $year = $_POST[$name .'year'];
    if ( $year < 1 ) return '';
    return "$year-$month-$day";
}

function mySQLDateToUK( $date, $monthname = true ) {
    $months = array(1=>'January', 'February', 'March', 'April', 'May', 'June', 'July',
                    'August', 'September', 'October', 'November', 'December');
    list( $year, $month, $day ) = explode( '-', $date );
    if ( $monthname ) return $day . ' ' . $months[$month] . ' ' . $year;
    return $day . ' ' . $month . ' ' . $year;
}
Copyright © 2009 www.cedit.biz. All rights reserved.