function DBTimeStamp($ts)
 {
     if (is_string($ts)) {
         $d = ADORecordSet::UnixTimeStamp($ts);
     }
     return 'TO_DATE(' . adodb_date($this->fmtTimeStamp, $ts) . ",'RRRR-MM-DD, HH:MI:SS AM')";
 }
	function DBTimeStamp($ts)
	{

		if (is_string($ts)) $ts = ADORecordSet::UnixTimeStamp($ts);
		if (is_object($ts)) $ds = $ts->format($this->fmtDate);
		else $ds = adodb_date($this->fmtTimeStamp,$ts);
		return 'TO_DATE('.$ds.",'RRRR-MM-DD, HH:MI:SS AM')";
	}
 public function metaform()
 {
     $timestamp = $this->getValue();
     if (!is_numeric($timestamp)) {
         $timestamp = self::strtotime($timestamp);
     }
     if (!empty($timestamp)) {
         $datepicker = adodb_date(self::getDateFormat(), $timestamp);
         $hour = adodb_date('H', $timestamp);
         $minute = adodb_date('i', $timestamp);
     } else {
         $datepicker = $hour = $minute = null;
     }
     $data = $this->getData();
     $form = array();
     $form[] = array('#type' => 'textfield', '#title' => $this->getTitle(), '#attributes' => array('class' => 'js-wpt-date', 'style' => 'width:150px;'), '#name' => $this->getName() . '[datepicker]', '#value' => $datepicker, '#validate' => $this->getValidationData());
     if (!empty($data['add_time'])) {
         // Hour
         $hours = 24;
         $options = array();
         for ($index = 0; $index < $hours; $index++) {
             $prefix = $index < 10 ? '0' : '';
             $options[$index] = array('#title' => $prefix . strval($index), '#value' => $index);
         }
         $form[] = array('#type' => 'select', '#title' => __('Hour'), '#options' => $options, '#default_value' => $hour, '#name' => $this->getName() . '[hour]', '#inline' => true);
         // Minutes
         $minutes = 60;
         $options = array();
         for ($index = 0; $index < $minutes; $index++) {
             $prefix = $index < 10 ? '0' : '';
             $options[$index] = array('#title' => $prefix . strval($index), '#value' => $index);
         }
         $form[] = array('#type' => 'select', '#title' => __('Minute'), '#options' => $options, '#default_value' => $minute, '#name' => $this->getName() . '[minute]', '#inline' => true);
     }
     return $form;
 }
Example #4
0
function adodb_date2($fmt, $d = false, $is_gmt = false)
{
    if ($d !== false) {
        if (!preg_match("|^([0-9]{4})[-/\\.]?([0-9]{1,2})[-/\\.]?([0-9]{1,2})[ -]?(([0-9]{1,2}):?([0-9]{1,2}):?([0-9\\.]{1,4}))?|", $d, $rr)) {
            return adodb_date($fmt, false, $is_gmt);
        }
        if ($rr[1] <= 100 && $rr[2] <= 1) {
            return adodb_date($fmt, false, $is_gmt);
        }
        // h-m-s-MM-DD-YY
        if (!isset($rr[5])) {
            $d = adodb_mktime(0, 0, 0, $rr[2], $rr[3], $rr[1]);
        } else {
            $d = @adodb_mktime($rr[5], $rr[6], $rr[7], $rr[2], $rr[3], $rr[1]);
        }
    }
    return adodb_date($fmt, $d, $is_gmt);
}
Example #5
0
/**
 * Fix due to a bug saving date as array.
 * 
 * BUGS
 * 'timestamp' is saved without Hour and Minute appended.
 * 
 * @param type $value
 * @param type $field
 */
function __wpcf_fields_date_check_leftover($value, $field, $use_cache = true)
{
    if (empty($value)) {
        return $value;
    }
    if (!is_object($field)) {
        $post_id = wpcf_get_post_id();
        $field_id = isset($field['id']) ? $field['id'] : false;
        $meta_id = isset($field['__meta_id']) ? $field['__meta_id'] : false;
    } else {
        $post_id = isset($field->meta_object->post_id) ? $field->meta_object->post_id : false;
        $field_id = isset($field->cf['id']) ? $field->cf['id'] : false;
        $meta_id = isset($field->meta_object->meta_id) ? $field->meta_object->meta_id : false;
    }
    if (empty($post_id) || empty($meta_id) || empty($field_id)) {
        return $value;
    }
    $field_slug = wpcf_types_get_meta_prefix() . $field_id;
    // Check if cached
    static $cache = array();
    $cache_key = $meta_id;
    if (isset($cache[$cache_key]) && $use_cache) {
        return $cache[$cache_key];
    }
    $_meta = wpcf_get_post_meta($post_id, '_wpcf_' . $field_id . '_hour_and_minute', true);
    /*
     * If meta exists - it's outdated value
     * and Hour and Minute should be appended and removed.
     */
    if (!empty($_meta) && is_array($_meta) && isset($_meta[$meta_id])) {
        $meta = $_meta[$meta_id];
        // Return empty date if can not be calculated
        if (!empty($meta['timestamp']) || !empty($meta['datepicker'])) {
            $meta['timestamp'] = wpcf_fields_date_value_get_filter($meta, $field, 'timestamp', 'check_leftover');
            // Check if calculation needed
            if (isset($meta['hour']) && $meta['hour'] != adodb_date('H', $meta['timestamp']) || isset($meta['minute']) && $meta['minute'] != adodb_date('i', $meta['timestamp'])) {
                $value = wpcf_fields_date_calculate_time($meta);
            }
        }
    }
    // Cache it
    if ($use_cache) {
        $cache[$cache_key] = $value;
    }
    return $value;
}
Example #6
0
 function _fetch()
 {
     $rs = $this->_queryID;
     if (!$rs or $rs->EOF) {
         $this->fields = false;
         return false;
     }
     $this->fields = array();
     if (!$this->_tarr) {
         $tarr = array();
         $flds = array();
         for ($i = 0, $max = $this->_numOfFields; $i < $max; $i++) {
             $f = $rs->Fields($i);
             $flds[] = $f;
             $tarr[] = $f->Type;
         }
         // bind types and flds only once
         $this->_tarr = $tarr;
         $this->_flds = $flds;
     }
     $t = reset($this->_tarr);
     $f = reset($this->_flds);
     if ($this->hideErrors) {
         $olde = error_reporting(E_ERROR | E_CORE_ERROR);
     }
     // sometimes $f->value be null
     for ($i = 0, $max = $this->_numOfFields; $i < $max; $i++) {
         //echo "<p>",$t,' ';var_dump($f->value); echo '</p>';
         switch ($t) {
             case 135:
                 // timestamp
                 if (!strlen((string) $f->value)) {
                     $this->fields[] = false;
                 } else {
                     if (!is_numeric($f->value)) {
                         $val = variant_date_to_timestamp($f->value);
                     } else {
                         $val = $f->value;
                     }
                     $this->fields[] = adodb_date('Y-m-d H:i:s', $val);
                 }
                 break;
             case 133:
                 // A date value (yyyymmdd)
                 if ($val = $f->value) {
                     $this->fields[] = substr($val, 0, 4) . '-' . substr($val, 4, 2) . '-' . substr($val, 6, 2);
                 } else {
                     $this->fields[] = false;
                 }
                 break;
             case 7:
                 // adDate
                 if (!strlen((string) $f->value)) {
                     $this->fields[] = false;
                 } else {
                     if (!is_numeric($f->value)) {
                         $val = variant_date_to_timestamp($f->value);
                     } else {
                         $val = $f->value;
                     }
                     if ($val % 86400 == 0) {
                         $this->fields[] = adodb_date('Y-m-d', $val);
                     } else {
                         $this->fields[] = adodb_date('Y-m-d H:i:s', $val);
                     }
                 }
                 break;
             case 1:
                 // null
                 $this->fields[] = false;
                 break;
             case 6:
                 // currency is not supported properly;
                 ADOConnection::outp('<b>' . $f->Name . ': currency type not supported by PHP</b>');
                 $this->fields[] = (double) $f->value;
                 break;
             default:
                 $this->fields[] = $f->value;
                 break;
         }
         //print " $f->value $t, ";
         $f = next($this->_flds);
         $t = next($this->_tarr);
     }
     // for
     if ($this->hideErrors) {
         error_reporting($olde);
     }
     @$rs->MoveNext();
     // @ needed for some versions of PHP!
     if ($this->fetchMode & ADODB_FETCH_ASSOC) {
         $this->fields =& $this->GetRowAssoc(ADODB_ASSOC_CASE);
     }
     return true;
 }
Example #7
0
 function DBTimeStamp($ts, $isfld = false)
 {
     if (empty($ts) && $ts !== 0) {
         return 'null';
     }
     if (is_string($ts)) {
         $ts = ADORecordSet::UnixTimeStamp($ts);
     }
     return 'TO_DATE(' . adodb_date($this->fmtTimeStamp, $ts) . ",'YYYY-MM-DD HH24:MI:SS')";
 }
Example #8
0
 function FormatDate($format, $date)
 {
     if ($this->UseAdodbTime) {
         return adodb_date($format, $date);
     } else {
         return date($format, $date);
     }
 }
Example #9
0
 function _fetch()
 {
     $rs = $this->_queryID;
     if (!$rs or $rs->EOF) {
         $this->fields = false;
         return false;
     }
     $this->fields = array();
     if (!$this->_tarr) {
         $tarr = array();
         $flds = array();
         $i = 0;
         for ($max = $this->_numOfFields; $i < $max; ++$i) {
             $f = $rs->Fields($i);
             $flds[] = $f;
             $tarr[] = $f->Type;
         }
         $this->_tarr = $tarr;
         $this->_flds = $flds;
     }
     $t = reset($this->_tarr);
     $f = reset($this->_flds);
     if ($this->hideErrors) {
         $olde = error_reporting(E_ERROR | E_CORE_ERROR);
     }
     $i = 0;
     for ($max = $this->_numOfFields; $i < $max; ++$i) {
         switch ($t) {
             case 135:
                 if (!strlen((string) $f->value)) {
                     $this->fields[] = false;
                     break;
                 } else {
                     if (!is_numeric($f->value)) {
                         $val = variant_date_to_timestamp($f->value);
                     } else {
                         $val = $f->value;
                     }
                     $this->fields[] = adodb_date('Y-m-d H:i:s', $val);
                     break;
                 }
                 break;
             case 133:
                 if ($val = $f->value) {
                     $this->fields[] = substr($val, 0, 4) . '-' . substr($val, 4, 2) . '-' . substr($val, 6, 2);
                     break;
                 } else {
                     $this->fields[] = false;
                     break;
                 }
                 break;
             case 7:
                 if (!strlen((string) $f->value)) {
                     $this->fields[] = false;
                     break;
                 } else {
                     if (!is_numeric($f->value)) {
                         $val = variant_date_to_timestamp($f->value);
                     } else {
                         $val = $f->value;
                     }
                     if ($val % 86400 == 0) {
                         $this->fields[] = adodb_date('Y-m-d', $val);
                         break;
                     } else {
                         $this->fields[] = adodb_date('Y-m-d H:i:s', $val);
                         break;
                     }
                     break;
                 }
                 break;
             case 1:
                 $this->fields[] = false;
                 break;
             case 6:
                 adoconnection::outp('<b>' . $f->Name . ': currency type not supported by PHP</b>');
                 $this->fields[] = (double) $f->value;
                 break;
             default:
                 $this->fields[] = $f->value;
                 break;
         }
         $f = next($this->_flds);
         $t = next($this->_tarr);
     }
     if ($this->hideErrors) {
         error_reporting($olde);
     }
     @$rs->MoveNext();
     if ($this->fetchMode & ADODB_FETCH_ASSOC) {
         $this->fields =& $this->GetRowAssoc(ADODB_ASSOC_CASE);
     }
     return true;
 }
Example #10
0
 public function wpt_localize_extended_date()
 {
     if (!isset($_POST['date'])) {
         die;
     }
     $date = $_POST['date'];
     $date_format = '';
     if (isset($_POST['date-format'])) {
         $date_format = $_POST['date-format'];
     }
     if ($date_format == '') {
         $date_format = get_option('date_format');
     }
     $date = adodb_mktime(0, 0, 0, substr($date, 2, 2), substr($date, 0, 2), substr($date, 4, 4));
     $date_format = str_replace('\\\\', '\\', $date_format);
     echo json_encode(array('display' => adodb_date($date_format, $date), 'timestamp' => $date));
     die;
 }
Example #11
0
 function DBTimeStamp($ts)
 {
     if (empty($ts) && $ts !== 0) {
         return 'null';
     }
     if (is_string($ts)) {
         $ts = ADORecordSet::UnixTimeStamp($ts);
     }
     return 'TO_DATE(' . adodb_date($this->fmtTimeStamp, $ts) . ",'RRRR-MM-DD, HH:MI:SS AM')";
 }
 function DBTimeStamp($ts)
 {
     if (empty($ts) && $ts !== 0) {
         return 'null';
     }
     if (is_string($ts)) {
         $ts = ADORecordSet::UnixTimeStamp($ts);
     }
     // See #8387 for more details
     // original: return 'TO_DATE('.adodb_date($this->fmtTimeStamp,$ts).",'YYYY-MM-DD HH24:MI:SS')";
     return adodb_date($this->fmtTimeStamp, $ts);
 }
Example #13
0
/**
 * View function.
 * 
 * @param type $params 
 */
function wpcf_fields_date_view($params)
{
    global $wp_locale;
    $defaults = array('format' => get_option('date_format'), 'style' => '');
    $params = wp_parse_args($params, $defaults);
    $output = '';
    // Make sure value is right
    $__timestamp = wpcf_fields_date_value_get_filter($params['field_value'], $params['field'], 'timestamp');
    if (is_null($__timestamp)) {
        return '';
    } else {
        $params['field_value'] = $__timestamp;
    }
    switch ($params['style']) {
        case 'calendar':
            $output .= wpcf_fields_date_get_calendar($params, true, false);
            break;
        default:
            $field_name = '';
            // Extract the Full month and Short month from the format.
            // We'll replace with the translated months if possible.
            $format = $params['format'];
            //$format = str_replace( 'F', '#111111#', $format );
            //$format = str_replace( 'M', '#222222#', $format );
            // Same for the Days
            //$format = str_replace( 'D', '#333333#', $format );
            //$format = str_replace( 'l', '#444444#', $format );
            $date_out = adodb_date($format, $params['field_value']);
            //$month = adodb_date( 'm', $params['field_value'] );
            //$month_full = $wp_locale->get_month( $month );
            //$date_out = str_replace( '#111111#', $month_full, $date_out );
            //$month_short = $wp_locale->get_month_abbrev( $month_full );
            //$date_out = str_replace( '#222222#', $month_short, $date_out );
            //$day = adodb_date( 'w', $params['field_value'] );
            //$day_full = $wp_locale->get_weekday( $day );
            //$date_out = str_replace( '#444444#', $day_full, $date_out );
            //$day_short = $wp_locale->get_weekday_abbrev( $day_full );
            //$date_out = str_replace( '#333333#', $day_short, $date_out );
            $output .= $date_out;
            break;
    }
    return $output;
}
 /**
  * cred-post-expiration-shortcode: cred-post-expiration
  *
  * Description: Display the expiration date/time of the current post
  *
  * Parameters:
  * id => post ID, defaults to global $post->ID
  * format => Format string for the date. Defaults to Wordpress settings option (date_format)
  * 
  * Example usage:
  * Expiration on [cred-post-expiration format="F jS, Y"]
  *
  * Link:
  * Format parameter is the same as here: http://codex.wordpress.org/Formatting_Date_and_Time
  *
  * Note:
  *
  */
 function cred_pe_shortcode_cred_post_expiration($atts)
 {
     extract(shortcode_atts(array('id' => '', 'format' => get_option('date_format')), $atts));
     $out = '';
     $post_id = $id;
     global $post;
     if (empty($post_id) && isset($post->ID)) {
         $post_id = $post->ID;
     }
     if (!empty($post_id)) {
         $post_expiration_time = get_post_meta($post_id, $this->_post_expiration_time_field, true);
         if (self::_isTimestampInRange($post_expiration_time)) {
             $out = apply_filters('the_time', adodb_date($format, $post_expiration_time));
         }
     }
     return $out;
 }
Example #15
0
 /**
  * Format date according to a format string, uses ATK's language files to translate
  * months, weekdays etc.
  *
  * @param $date    mixed  timestamp or date array (gotten with getdate())
  * @param $format  string format string, compatible with PHP's date format functions
  * @param $weekday bool always include day-of-week or not
  *
  * @return string formatted date
  */
 public static function atkFormatDate($date, $format, $weekday = false)
 {
     static $langcache = [];
     if (!is_array($date)) {
         $date = getdate($date);
     }
     /* format month */
     $format = str_replace('M', '%-%', $format);
     $format = str_replace('F', '%=%', $format);
     /* format day */
     $format = str_replace('D', '%&%', $format);
     $format = str_replace('l', '%*%', $format);
     if ($weekday && strpos($format, '%&%') === false && strpos($format, '%*%') === false) {
         $format = str_replace('d', '%*% d', $format);
         $format = str_replace('j', '%*% j', $format);
     }
     /* get date string */
     $str_date = adodb_date($format, $date[0]);
     $month = $date['month'];
     $shortmonth = substr(strtolower($date['month']), 0, 3);
     /* store the self::text calls */
     if (!isset($langcache[$month])) {
         $langcache[$month] = self::atktext(strtolower($month), 'atk');
     }
     if (!isset($langcache[$shortmonth])) {
         $langcache[$shortmonth] = self::atktext($shortmonth);
     }
     /* replace month/week name */
     $str_date = str_replace('%-%', $langcache[$shortmonth], $str_date);
     $str_date = str_replace('%=%', $langcache[$month], $str_date);
     $str_date = str_replace('%*%', self::atktext(strtolower($date['weekday']), 'atk'), $str_date);
     $str_date = str_replace('%&%', self::atktext(substr(strtolower($date['weekday']), 0, 3), 'atk'), $str_date);
     /* return string */
     return $str_date;
 }
 function cal_to_include($args)
 {
     //echo "<p>cal_to_include("; print_r($args); echo ")</p>\n";
     $user = intval($args['owner']);
     if ($user <= 0 && !checkdate($args['month'], $args['day'], $args['year'])) {
         return False;
     }
     if (!is_object($GLOBALS['phpgw']->html)) {
         $GLOBALS['phpgw']->html = CreateObject('phpgwapi.html');
     }
     $GLOBALS['phpgw']->translation->add_app('infolog');
     $do_events = $args['location'] == 'calendar_include_events';
     $to_include = array();
     $date_wanted = sprintf('%04d/%02d/%02d', $args['year'], $args['month'], $args['day']);
     $query = array('order' => 'info_startdate', 'sort' => $do_events ? 'ASC' : 'DESC', 'filter' => "user{$user}" . ($do_events ? 'date' : 'opentoday') . $date_wanted, 'start' => 0);
     while ($infos = $this->search($query)) {
         foreach ($infos as $info) {
             $time = (int) adodb_date('Hi', $info['info_startdate']);
             $date = adodb_date('Y/m/d', $info['info_startdate']);
             if ($do_events && !$time || !$do_events && $time && $date == $date_wanted) {
                 continue;
             }
             $title = ($do_events ? $GLOBALS['phpgw']->common->formattime(adodb_date('H', $info['info_startdate']), adodb_date('i', $info['info_startdate'])) . ' ' : '') . $info['info_subject'];
             $view = $this->link->view('infolog', $info['info_id']);
             $content = array();
             foreach ($icons = array($info['info_type'] => 'infolog', $info['info_status'] => 'infolog') as $name => $app) {
                 $content[] = $GLOBALS['phpgw']->html->image($app, $name, lang($name), 'border="0" width="15" height="15"') . ' ';
             }
             $content[] = $GLOBALS['phpgw']->html->a_href($title, $view);
             $content = $GLOBALS['phpgw']->html->table(array(1 => $content));
             $to_include[] = array('starttime' => $info['info_startdate'], 'endtime' => $info['info_enddate'] ? $info['info_enddate'] : $info['info_startdate'], 'title' => $title, 'view' => $view, 'icons' => $icons, 'content' => $content);
         }
         if ($query['total'] <= ($query['start'] += count($infos))) {
             break;
             // no more availible
         }
     }
     //echo "boinfolog::cal_to_include("; print_r($args); echo ")<pre>"; print_r($to_include); echo "</pre>\n";
     return $to_include;
 }
 function mkActiveDate($param, $acttime = false)
 {
     if (!$acttime) {
         $acttime = $this->timetoday;
     }
     if (function_exists("adodb_date")) {
         return adodb_date($param, $acttime);
     } else {
         return date($param, $acttime);
     }
 }
/**
 * Single condition form elements.
 *
 * @param type $data
 * @param type $condition
 * @param type $key
 * @return string
 */
function wpcf_cd_admin_form_single_filter($data, $condition, $key = null, $group = false, $force_multi = false)
{
    global $wpcf;
    if ($group) {
        $name = 'wpcf[group][conditional_display]';
    } else {
        $name = 'wpcf[fields][' . $data['id'] . '][conditional_display]';
    }
    $group_id = isset($_GET['group_id']) ? intval($_GET['group_id']) : false;
    /*
     *
     *
     * TODO Review this allowing fields from same group as conditional (self loop)
     * I do not remember allowing fields from same group as conditional (self loop)
     * on Group Fields edit screen.
     */
    //    if ( $group_id && !$group ) {// Allow group to use other fields
    //        $fields = wpcf_admin_fields_get_fields_by_group( $group_id );
    //    } else {
    $fields = wpcf_admin_fields_get_fields(true, false, true);
    ksort($fields, SORT_STRING);
    //    }
    if ($group) {
        $_distinct = wpcf_admin_fields_get_fields_by_group($group_id);
        foreach ($_distinct as $_field_id => $_field) {
            if (isset($fields[$_field_id])) {
                unset($fields[$_field_id]);
            }
        }
    }
    $options = array();
    $ignore_field_type_array = array('audio', 'checkboxes', 'embed', 'file', 'image', 'video', 'wysiwyg');
    $flag_repetitive = false;
    foreach ($fields as $field_id => $field) {
        if (!$group && $data['id'] == $field_id) {
            continue;
        }
        // WE DO NOT ALLOW repetitive fields to be compared.
        if (wpcf_admin_is_repetitive($field)) {
            $flag_repetitive = true;
            continue;
        }
        /**
         * Skip some files
         */
        if (in_array($field['type'], $ignore_field_type_array)) {
            continue;
        }
        /**
         * build options
         */
        $options[$field_id] = array('#value' => $field_id, '#title' => stripslashes($field['name']), '#attributes' => array('class' => 'wpcf-conditional-select-' . $field['type']));
    }
    /*
     * Special case
     * https://icanlocalize.basecamphq.com/projects/7393061-wp-views/todo_items/153565054/comments
     *
     * When field is new and only one diff field in list - that
     * means one field is saved but other not yet.
     */
    $is_new = isset($data['id']) && isset($fields[$data['id']]) ? false : true;
    $special_stop = false;
    if ($is_new) {
        if (count($options) == 1) {
            $special_stop = true;
        }
    }
    /*
     *
     * This means all fields are repetitive and no one left to compare with.
     * WE DO NOT ALLOW repetitive fields to be compared.
     */
    if (!$group && empty($options) && $flag_repetitive) {
        return array('cd' => array('#type' => 'markup', '#markup' => '<p class="wpcf-error">' . __('Conditional display is only working based on non-repeating fields. All fields in this group are repeating, so you cannot set their display based on other fields.', 'wpcf') . '</p>' . wpcf_conditional_disable_add_js($data['id'])));
    } else {
        if (!$group && (empty($options) || $special_stop)) {
            return array('cd' => array('#type' => 'markup', '#markup' => '<p>' . __('You will be able to set conditional field display when you save more fields.', 'wpcf') . '</p>'));
        }
    }
    $id = !is_null($key) ? $key : strval('condition_' . wpcf_unique_id(serialize($data) . serialize($condition) . $key . $group));
    $form = array();
    $before = '<div class="wpcf-cd-entry"><br />';
    $form['cd']['field_' . $id] = array('#type' => 'select', '#name' => $name . '[conditions][' . $id . '][field]', '#options' => $options, '#inline' => true, '#before' => $before, '#default_value' => isset($condition['field']) ? $condition['field'] : null, '#attributes' => array('class' => 'wpcf-cd-field'));
    $form['cd']['operation_' . $id] = array('#type' => 'select', '#name' => $name . '[conditions][' . $id . '][operation]', '#options' => array_flip(wpcf_cd_admin_operations()), '#inline' => true, '#default_value' => isset($condition['operation']) ? $condition['operation'] : null, '#attributes' => array('class' => 'wpcf-cd-operation'));
    $form['cd']['value_' . $id] = array('#type' => 'textfield', '#name' => $name . '[conditions][' . $id . '][value]', '#inline' => true, '#value' => isset($condition['value']) ? $condition['value'] : '', '#attributes' => array('class' => 'wpcf-cd-value'));
    /*
     *
     * Adjust for date
     */
    if (!empty($condition['value'])) {
        WPCF_Loader::loadInclude('fields/date/functions.php');
        $timestamp = wpcf_fields_date_convert_datepicker_to_timestamp($condition['value']);
        if ($timestamp !== false) {
            $date_value = adodb_date('d', $timestamp) . ',' . adodb_date('m', $timestamp) . ',' . adodb_date('Y', $timestamp);
            $date_function = 'date';
        } else {
            if (wpcf_fields_date_timestamp_is_valid($condition['value'])) {
                $date_value = adodb_date('d', $condition['value']) . ',' . adodb_date('m', $condition['value']) . ',' . adodb_date('Y', $condition['value']);
                $date_function = 'date';
            }
        }
    }
    if (empty($date_value)) {
        $date_value = '';
        $date_function = false;
    }
    $form['cd']['value_date_' . $id] = array('#type' => 'markup', '#markup' => '<br />' . wpcf_conditional_add_date_controls($date_function, $date_value, $name . '[conditions][' . $id . ']'), '#attributes' => array('class' => 'wpcf-cd-value-date'));
    $form['cd']['remove_' . $id] = array('#type' => 'button', '#name' => 'remove', '#value' => __('Remove condition', 'wpcf'), '#attributes' => array('onclick' => 'wpcfCdRemoveCondition(jQuery(this));', 'class' => 'wpcf-add-condition'), '#after' => '</div><br />');
    return $form['cd'];
}
/**
* wpv_render_datepicker
*
* Renders the datepicker for date based frontend filters
*
* @param $url_param (string) the URL parameter used on the frontend filter
* @param $date_format (string) the date format to use when displaying the selected date besides the datepicker
* @param $default_date (string) the default date to be used when there is no value passed by the URL parameter - special case NONE
*
* @return (string) containing the needed inputs
*
* @since unknown
*
* @note $default_date default value was changed in 1.7 from NOW() to NONE; empty will mean NONE too
*
* @todo add an attribute for themes http://rtsinani.github.io/jquery-datepicker-skins/ 
* OR better an option in the Views settings, because we can not have two different styles for two datepickers
*/

function wpv_render_datepicker( $url_param, $date_format, $default_date = '' ) {
    
    static $support_loaded = false;
	$display_date = $datepicker_date = '';
	// TODO we need to enqueue this style in the right way. We are loading it twice! And it can not be unregistered...
    if ( !$support_loaded && 1 === 0 ) {
        ?>
            <script type="text/javascript">
                jQuery(document).ready(function () {
                    jQuery('head').append('<link rel="stylesheet" href="<?php echo WPV_URL_EMBEDDED . '/common/toolset-forms/css/wpt-jquery-ui/datepicker.css';?>" type="text/css" />');
                });
            </script>
        <?php
        $support_loaded = true;
    }
    
    if ( $date_format == '' ) {
        $date_format = get_option( 'date_format' );
    }
	
	$clear_button_style = '';
	$date = '';
    
    if( isset( $_GET[$url_param] ) ) {
        if ( $_GET[$url_param] == '' || $_GET[$url_param] == '0' ) {
			$date = '';
		} else {
			$date = $_GET[$url_param];
		}
    } else {
		if ( 
			$default_date == '' 
			|| $default_date == 'NONE' 
		) {
			$date = '';
		} else {
			$date = wpv_filter_parse_date( $default_date );
		}
    }
	
	if ( is_numeric( $date ) ) {
		if (
			$date < -12219292800 
			|| $date > 32535215940
		) {
			$date = '';
		}
	} else {
		$date = '';
	}
	
	if ( $date != '' ) {
    	$display_date = adodb_date( $date_format, $date );
	} else {
		$clear_button_style = ' style="display:none"';
	}

    
    $out = '';
    $out .= '<span class="wpv_date_input js-wpv-date-param-' . $url_param . ' js-wpv-date-display" data-param="' . $url_param . '">' . $display_date . '</span> ';
    $out .= '<input type="hidden" class="js-wpv-date-param-' . $url_param . '-value js-wpv-filter-trigger" name="' . $url_param . '" value="' . $date . '" />';
    $out .= '<input type="hidden" class="js-wpv-date-param-' . $url_param . '-format" name="' . $url_param . '-format" value="' . $date_format . '" />';

	if ( $date != '' ) {
    	$datepicker_date = adodb_date( 'dmY', $date );
	}
    $out .= '<input type="hidden" data-param="' . $url_param . '" class="wpv-date-front-end js-wpv-frontend-datepicker js-wpv-date-front-end-' . $url_param . '" value="' . $datepicker_date . '"/>';
	
	$delete_date_image = WPV_URL_EMBEDDED_FRONTEND . '/res/img/delete.png';
	$delete_date_image = apply_filters( 'wpv_filter_wpv_delete_date_image', $delete_date_image );
	$delete_date_image = apply_filters( 'wptoolset_filter_wptoolset_delete_date_image', $delete_date_image );
	
	$out .= '<img src="' . $delete_date_image . '" title="' . esc_attr( __( 'Clear date', 'wpv-views' ) ) . '" alt="' . esc_attr( __( 'Clear date', 'wpv-views' ) ) . '" class="wpv-date-front-end-clear js-wpv-date-front-end-clear js-wpv-date-front-end-clear-' . $url_param . '" data-param="' . $url_param . '"' . $clear_button_style . ' />';

    return $out;
}
 function DBTimeStamp($ts, $isfld = false)
 {
     if (empty($ts) && $ts !== 0) {
         return 'null';
     }
     if ($isfld) {
         return 'TO_DATE(substr(' . $ts . ",1,19),'RRRR-MM-DD, HH24:MI:SS')";
     }
     if (is_string($ts)) {
         $ts = ADORecordSet::UnixTimeStamp($ts);
     }
     return 'TO_DATE(' . adodb_date("'Y-m-d H:i:s'", $ts) . ",'RRRR-MM-DD, HH24:MI:SS')";
 }
Example #21
0
<?php

include_once '../adodb-time.inc.php';
//adodb_date_test();
//require("adodb-time.inc.php");
echo adodb_date('d/m/Y', adodb_mktime(0, 0, 0, 12, 1, 2056));
$datestring = "1963-12-04";
// string normally from mySQL
$stringArray = explode("-", $datestring);
$date = adodb_mktime(0, 0, 0, $stringArray[1], $stringArray[2], $stringArray[0]);
$convertedDate = date("d-M-Y", $date);
// converted string to UK style date
echo "Birthday: {$convertedDate}";
//why is string returned as one day (3 not 4) less for this example??
	function DBTimeStamp($ts)
	{
		if (empty($ts) && $ts !== 0) return 'null';
		if (is_string($ts)) $ts = ADORecordSet::UnixTimeStamp($ts);
		return 'TO_DATE('.adodb_date("'Y-m-d H:i:s'",$ts).",'RRRR-MM-DD, HH24:MI:SS')";
	}
Example #23
0
 public static function timetodate($timestamp, $format = null)
 {
     if (is_null($format)) {
         $format = self::getDateFormat();
     }
     return self::_isTimestampInRange($timestamp) ? @adodb_date($format, $timestamp) : false;
 }
 function wpv_format_date()
 {
     $date_format = $_POST['date-format'];
     if ($date_format == '') {
         $date_format = get_option('date_format');
     }
     // this is needed to escape characters in the date_i18n function
     $date_format = str_replace('\\\\', '\\', $date_format);
     $date = $_POST['date'];
     // We can not be sure that the adodb_xxx functions are available, so we do different things whether they exist or not
     if (defined('ADODB_DATE_VERSION')) {
         $date = adodb_mktime(0, 0, 0, substr($date, 2, 2), substr($date, 0, 2), substr($date, 4, 4));
         echo json_encode(array('display' => adodb_date($date_format, $date), 'timestamp' => $date));
     } else {
         $date = mktime(0, 0, 0, substr($date, 2, 2), substr($date, 0, 2), substr($date, 4, 4));
         echo json_encode(array('display' => date_i18n($date_format, intval($date)), 'timestamp' => $date));
     }
     die;
 }
	function _fetch()
	{
		$rs = $this->_queryID;
		if (!$rs or $rs->EOF) {
			$this->fields = false;
			return false;
		}
		$this->fields = array();

		if (!$this->_tarr) {
			$tarr = array();
			$flds = array();
			for ($i=0,$max = $this->_numOfFields; $i < $max; $i++) {
				$f = $rs->Fields($i);
				$flds[] = $f;
				$tarr[] = $f->Type;
			}
			// bind types and flds only once
			$this->_tarr = $tarr;
			$this->_flds = $flds;
		}
		$t = reset($this->_tarr);
		$f = reset($this->_flds);

		if ($this->hideErrors)  $olde = error_reporting(E_ERROR|E_CORE_ERROR);// sometimes $f->value be null
		for ($i=0,$max = $this->_numOfFields; $i < $max; $i++) {
			//echo "<p>",$t,' ';var_dump($f->value); echo '</p>';
			switch($t) {
			case 135: // timestamp
				if (!strlen((string)$f->value)) $this->fields[] = false;
				else {
					if (!is_numeric($f->value)) # $val = variant_date_to_timestamp($f->value);
						// VT_DATE stores dates as (float) fractional days since 1899/12/30 00:00:00
						$val= (float) variant_cast($f->value,VT_R8)*3600*24-2209161600;
					else
						$val = $f->value;
					$this->fields[] = adodb_date('Y-m-d H:i:s',$val);
				}
				break;
			case 133:// A date value (yyyymmdd)
				if ($val = $f->value) {
					$this->fields[] = substr($val,0,4).'-'.substr($val,4,2).'-'.substr($val,6,2);
				} else
					$this->fields[] = false;
				break;
			case 7: // adDate
				if (!strlen((string)$f->value)) $this->fields[] = false;
				else {
					if (!is_numeric($f->value)) $val = variant_date_to_timestamp($f->value);
					else $val = $f->value;

					if (($val % 86400) == 0) $this->fields[] = adodb_date('Y-m-d',$val);
					else $this->fields[] = adodb_date('Y-m-d H:i:s',$val);
				}
				break;
			case 1: // null
				$this->fields[] = false;
				break;
			case 20:
			case 21: // bigint (64 bit)
    			$this->fields[] = (float) $f->value; // if 64 bit PHP, could use (int)
    			break;
			case 6: // currency is not supported properly;
				ADOConnection::outp( '<b>'.$f->Name.': currency type not supported by PHP</b>');
				$this->fields[] = (float) $f->value;
				break;
			case 11: //BIT;
				$val = "";
				if(is_bool($f->value))	{
					if($f->value==true) $val = 1;
					else $val = 0;
				}
				if(is_null($f->value)) $val = null;

				$this->fields[] = $val;
				break;
			default:
				$this->fields[] = $f->value;
				break;
			}
			//print " $f->value $t, ";
			$f = next($this->_flds);
			$t = next($this->_tarr);
		} // for
		if ($this->hideErrors) error_reporting($olde);
		@$rs->MoveNext(); // @ needed for some versions of PHP!

		if ($this->fetchMode & ADODB_FETCH_ASSOC) {
			$this->fields = $this->GetRowAssoc(ADODB_ASSOC_CASE);
		}
		return true;
	}
 function BindTimeStamp($ts)
 {
     if (empty($ts) && $ts !== 0) {
         return 'null';
     }
     if (is_string($ts)) {
         $ts = ADORecordSet::UnixTimeStamp($ts);
     }
     if (is_object($ts)) {
         $tss = $ts->format("'Y-m-d H:i:s'");
     } else {
         $tss = adodb_date("'Y-m-d H:i:s'", $ts);
     }
     return $tss;
 }
Example #27
0
function adodb_strftime($fmt, $ts = false, $is_gmt = false)
{
    global $ADODB_DATE_LOCALE;
    if (!defined('ADODB_TEST_DATES')) {
        if (abs($ts) <= 0x7fffffff) {
            // check if number in 32-bit signed range
            if (!defined('ADODB_NO_NEGATIVE_TS') || $ts >= 0) {
                // if windows, must be +ve integer
                return $is_gmt ? @gmstrftime($fmt, $ts) : @strftime($fmt, $ts);
            }
        }
    }
    if (empty($ADODB_DATE_LOCALE)) {
        /*
        	$tstr = strtoupper(gmstrftime('%c',31366800)); // 30 Dec 1970, 1 am
        	$sep = substr($tstr,2,1);
        	$hasAM = strrpos($tstr,'M') !== false;
        */
        # see http://phplens.com/lens/lensforum/msgs.php?id=14865 for reasoning, and changelog for version 0.24
        $dstr = gmstrftime('%x', 31366800);
        // 30 Dec 1970, 1 am
        $sep = substr($dstr, 2, 1);
        $tstr = strtoupper(gmstrftime('%X', 31366800));
        // 30 Dec 1970, 1 am
        $hasAM = strrpos($tstr, 'M') !== false;
        $ADODB_DATE_LOCALE = array();
        $ADODB_DATE_LOCALE[] = strncmp($tstr, '30', 2) == 0 ? 'd' . $sep . 'm' . $sep . 'y' : 'm' . $sep . 'd' . $sep . 'y';
        $ADODB_DATE_LOCALE[] = $hasAM ? 'h:i:s a' : 'H:i:s';
    }
    $inpct = false;
    $fmtdate = '';
    for ($i = 0, $max = strlen($fmt); $i < $max; $i++) {
        $ch = $fmt[$i];
        if ($ch == '%') {
            if ($inpct) {
                $fmtdate .= '%';
                $inpct = false;
            } else {
                $inpct = true;
            }
        } else {
            if ($inpct) {
                $inpct = false;
                switch ($ch) {
                    case '0':
                    case '1':
                    case '2':
                    case '3':
                    case '4':
                    case '5':
                    case '6':
                    case '7':
                    case '8':
                    case '9':
                    case 'E':
                    case 'O':
                        /* ignore format modifiers */
                        $inpct = true;
                        break;
                    case 'a':
                        $fmtdate .= 'D';
                        break;
                    case 'A':
                        $fmtdate .= 'l';
                        break;
                    case 'h':
                    case 'b':
                        $fmtdate .= 'M';
                        break;
                    case 'B':
                        $fmtdate .= 'F';
                        break;
                    case 'c':
                        $fmtdate .= $ADODB_DATE_LOCALE[0] . $ADODB_DATE_LOCALE[1];
                        break;
                    case 'C':
                        $fmtdate .= '\\C?';
                        break;
                        // century
                    // century
                    case 'd':
                        $fmtdate .= 'd';
                        break;
                    case 'D':
                        $fmtdate .= 'm/d/y';
                        break;
                    case 'e':
                        $fmtdate .= 'j';
                        break;
                    case 'g':
                        $fmtdate .= '\\g?';
                        break;
                        //?
                    //?
                    case 'G':
                        $fmtdate .= '\\G?';
                        break;
                        //?
                    //?
                    case 'H':
                        $fmtdate .= 'H';
                        break;
                    case 'I':
                        $fmtdate .= 'h';
                        break;
                    case 'j':
                        $fmtdate .= '?z';
                        $parsej = true;
                        break;
                        // wrong as j=1-based, z=0-basd
                    // wrong as j=1-based, z=0-basd
                    case 'm':
                        $fmtdate .= 'm';
                        break;
                    case 'M':
                        $fmtdate .= 'i';
                        break;
                    case 'n':
                        $fmtdate .= "\n";
                        break;
                    case 'p':
                        $fmtdate .= 'a';
                        break;
                    case 'r':
                        $fmtdate .= 'h:i:s a';
                        break;
                    case 'R':
                        $fmtdate .= 'H:i:s';
                        break;
                    case 'S':
                        $fmtdate .= 's';
                        break;
                    case 't':
                        $fmtdate .= "\t";
                        break;
                    case 'T':
                        $fmtdate .= 'H:i:s';
                        break;
                    case 'u':
                        $fmtdate .= '?u';
                        $parseu = true;
                        break;
                        // wrong strftime=1-based, date=0-based
                    // wrong strftime=1-based, date=0-based
                    case 'U':
                        $fmtdate .= '?U';
                        $parseU = true;
                        break;
                        // wrong strftime=1-based, date=0-based
                    // wrong strftime=1-based, date=0-based
                    case 'x':
                        $fmtdate .= $ADODB_DATE_LOCALE[0];
                        break;
                    case 'X':
                        $fmtdate .= $ADODB_DATE_LOCALE[1];
                        break;
                    case 'w':
                        $fmtdate .= '?w';
                        $parseu = true;
                        break;
                        // wrong strftime=1-based, date=0-based
                    // wrong strftime=1-based, date=0-based
                    case 'W':
                        $fmtdate .= '?W';
                        $parseU = true;
                        break;
                        // wrong strftime=1-based, date=0-based
                    // wrong strftime=1-based, date=0-based
                    case 'y':
                        $fmtdate .= 'y';
                        break;
                    case 'Y':
                        $fmtdate .= 'Y';
                        break;
                    case 'Z':
                        $fmtdate .= 'T';
                        break;
                }
            } else {
                if ('A' <= $ch && $ch <= 'Z' || 'a' <= $ch && $ch <= 'z') {
                    $fmtdate .= "\\" . $ch;
                } else {
                    $fmtdate .= $ch;
                }
            }
        }
    }
    //echo "fmt=",$fmtdate,"<br>";
    if ($ts === false) {
        $ts = time();
    }
    $ret = adodb_date($fmtdate, $ts, $is_gmt);
    return $ret;
}
Example #28
0
$states->draw($img);
$iards->draw($img);
$bar640t->draw($img);
$rs = pg_prepare($coopdb, "SELECT", "SELECT station, \n\tsum(precip) as s_prec, sum(gdd50(high,low)) as s_gdd50,\n\tsum(sdd86(high,low)) as s_sdd86, min(low) as s_mintemp,\n\tmax(high) as s_maxtemp from alldata \n\tWHERE day >= \$1 and day <= \$2 GROUP by station \n\tORDER by station ASC");
$rs = pg_execute($coopdb, "SELECT", array(adodb_date("Y-m-d", $sts), adodb_date("Y-m-d", $ets)));
for ($i = 0; $row = @pg_fetch_array($rs, $i); $i++) {
    $ukey = $row["station"];
    if (!isset($cities[$ukey])) {
        continue;
    }
    // Red Dot...
    $pt = ms_newPointObj();
    $pt->setXY($cities[$ukey]['lon'], $cities[$ukey]['lat'], 0);
    $pt->draw($map, $ponly, $img, 0, '');
    // City Name
    $pt = ms_newPointObj();
    $pt->setXY($cities[$ukey]['lon'], $cities[$ukey]['lat'], 0);
    $pt->draw($map, $snet, $img, 3, $cities[$ukey]['name']);
    // Value UL
    $pt = ms_newPointObj();
    $pt->setXY($cities[$ukey]['lon'], $cities[$ukey]['lat'], 0);
    $pt->draw($map, $snet, $img, 0, round($row["s_" . $var], $rnd[$var]));
}
if ($i == 0) {
    plotNoData($map, $img);
}
$title = sprintf("%s (%s through %s)", $varDef[$var], adodb_date("Y-m-d", $sts), adodb_date("Y-m-d", $ets));
mktitlelocal($map, $img, $title);
$map->drawLabelCache($img);
header("Content-type: image/png");
$img->saveImage('');
Example #29
0
 /**
  * @param v  	is the character date in YYYY-MM-DD format, returned by database
  * @param fmt 	is the format to apply to it, using date()
  *
  * @return a date formated as user desires
  */
 function UserDate($v, $fmt = 'Y-m-d')
 {
     $tt = $this->UnixDate($v);
     // $tt == -1 if pre TIMESTAMP_FIRST_YEAR
     if (($tt === false || $tt == -1) && $v != false) {
         return $v;
     } else {
         if ($tt == 0) {
             return $this->emptyDate;
         } else {
             if ($tt == -1) {
                 // pre-TIMESTAMP_FIRST_YEAR
             }
         }
     }
     return adodb_date($fmt, $tt);
 }
Example #30
0
File: Ak.php Project: joeymetal/v1
 /**
  * Return formatted date.
  * 
  * You can supply a format as defined at http://php.net/date
  * 
  * Default date is in ISO format 
  */
 function getDate($timestamp = null, $format = null)
 {
     $timestamp = !isset($timestamp) ? Ak::time() : $timestamp;
     $use_adodb = $timestamp <= -3600 || $timestamp >= 2147468400;
     if ($use_adodb) {
         require_once AK_CONTRIB_DIR . DS . 'adodb' . DS . 'adodb-time.inc.php';
     }
     if (!isset($format)) {
         return $use_adodb ? adodb_date('Y-m-d H:i:s', $timestamp) : date('Y-m-d H:i:s', $timestamp);
     } elseif (!empty($format)) {
         return $use_adodb ? adodb_date($format, $timestamp) : date($format, $timestamp);
     }
     trigger_error(Ak::t('You must supply a valid UNIX timetamp. You can get the timestamp by calling Ak::getTimestamp("2006-09-27 20:45:57")'));
     return false;
 }