Ejemplo n.º 1
0
	function format_date_value($in_tag, $in_value, $in_label)
	{

		$text = "";

        if ( !$in_value )
            return $text;

		$in_label = get_locale_date_format ( $in_label );


 

		$dy_tag = $in_tag."_DAY";
		$mn_tag = $in_tag."_MONTH";
		$yr_tag = $in_tag."_YEAR";

		$tag = "";
		$tag .= '<input  type="hidden" name="HIDDEN_'.$in_tag.'"';
		$tag .= ' size="'.($this->column_length).'"';
		$tag .= ' maxlength="'.$this->column_length.'"';
		$tag .= ' value="'.$in_value.'">';
		$text .= $tag;

		if ( AJAX_ENABLED )
		{
			$tag = "";

       			if ( preg_match ( "/TODATE/", $in_tag ) )
              			$tag .= "";
			$tag .= '<input  class="'.$this->lookup_query->getBootstrapStyle('textfield').'swDateField" id="swDateField_'.$in_tag.'" style="z-index: 1000" type="text" name="MANUAL_'.$in_tag.'"';
			$tag .= ' size="20"';
			$tag .= ' maxlength="20"';
			$tag .= ' value="'.$in_value.'">';
			$text .= $tag;
			return $text;
		}

		switch ( $this->criteria_display )
		{
			case "YMDFIELD":
			case "MDYFIELD":
			case "DMYFIELD":
			case "DMYFORM":

				$dyinput = '<SELECT name="'.$dy_tag.'">';
				for ( $ct = 1; $ct <= 31; $ct++ )
				{
					$checked="";
					if ( $ct == (int)$dy )
						$checked="selected";
		
					$dyinput .= '<OPTION '.$checked.' label="'.$ct.'" value="'.$ct.'">'.$ct.'</OPTION>';
				}
				$dyinput .= '</SELECT>';
		
				$mtinput = '<SELECT name="'.$mn_tag.'">';
				$cal = array  ( sw_translate('January'), sw_translate('February'), sw_translate('March'), sw_translate('April'), sw_translate('May'), sw_translate('June'),
					sw_translate('July'), sw_translate('August'), sw_translate('September'), sw_translate('October'), sw_translate('November'), sw_translate('December') );
				for ( $ct = 0; $ct <= 11; $ct++ )
				{
					$checked="";
					if ( $ct == $mn - 1 )
						$checked="selected";
		
					$mtinput .= '<OPTION '.$checked.' label="'.$cal[$ct].'" value="'.$ct.'">'.$cal[$ct].'</OPTION>';
				}
				$mtinput .= '</SELECT>';
		
				$yrinput = '<SELECT name="'.$yr_tag.'">';
				for ( $ct = 2000; $ct <= 2020; $ct++ )
				{
					$checked="";
					if ( $ct == $yr )
						$checked="selected";
		
					$yrinput .= '<OPTION '.$checked.' label="'.$ct.'" value="'.$ct.'">'.$ct.'</OPTION>';
				}
				$yrinput .= '</SELECT>';

				switch ( $this->criteria_display )
				{
					case "YMDFIELD":
						$text .= $yrinput . $mtinput . $dyinput;
						break;

					case "MDYFIELD":
						$text .= $mtinput . $dyinput . $yrinput;
						break;

					case "DMYFIELD":
					case "DMYFORM":
					default:
						$text .= $dyinput . $mtinput . $yrinput;
						break;
				}

				break;

				default:
					$tag = "";

					if ( preg_match ( "/TODATE/", $in_tag ) )
						$tag .= "";
						$tag .= '<input  type="text" name="MANUAL_'.$in_tag.'"';
						$tag .= ' size="20"';
					//$tag .= ' maxlength="'.$this->column_length.'"';
						$tag .= ' maxlength="20"';
						$tag .= ' value="'.$in_value.'">';
						$text .= $tag;


		}
		return $text;
		
	}
Ejemplo n.º 2
0
function parse_date($in_keyword, $in_time = false, $in_mask = "%d/%m/%Y")
{
    $in_mask = get_locale_date_format($in_mask);
    if (!$in_time) {
        $in_time = time();
    }
    $now = localtime($in_time, true);
    // Begin calculating the required data/time value
    switch ($in_keyword) {
        case "FIRSTOFLASTMONTH":
            $now["tm_mday"] = 1;
            $now["tm_mon"]--;
            if ($now["tm_mon"] < 0) {
                $now["tm_year"]--;
                $now["tm_mon"] = 11;
            }
            break;
        case "FIRSTOFYEAR":
            $now["tm_mday"] = 1;
            $now["tm_mon"] = 0;
            break;
        case "FIRSTOFLASTYEAR":
            $now["tm_mday"] = 1;
            $now["tm_mon"] = 0;
            $now["tm_year"]--;
            break;
        case "LASTOFYEAR":
            $now["tm_mday"] = 31;
            $now["tm_mon"] = 11;
            break;
        case "LASTOFLASTYEAR":
            $now["tm_mday"] = 31;
            $now["tm_mon"] = 11;
            $now["tm_year"]--;
            break;
        case "LASTOFLASTMONTH":
        case "FIRSTOFMONTH":
            $now["tm_mday"] = 1;
            break;
        case "LASTOFMONTH":
            $now["tm_mday"] = 1;
            $now["tm_mon"]++;
            if ($now["tm_mon"] == 12) {
                $now["tm_year"]++;
                $now["tm_mon"] = 0;
            }
            break;
        case "STARTOFWEEK":
        case "ENDOFWEEK":
        case "STARTOFLASTWEEK":
        case "ENDOFLASTWEEK":
        case "YESTERDAY":
        case "TOMORROW":
        case "TODAY":
            break;
        default:
            return $in_keyword;
    }
    if ($now["tm_year"] < 1000) {
        $now["tm_year"] += 1900;
    }
    // Convert the modified date time values back to to UNIX time
    $new_time = mktime($now["tm_hour"], $now["tm_min"], $now["tm_sec"], $now["tm_mon"] + 1, $now["tm_mday"], $now["tm_year"]);
    //$now["tm_isdst"] );
    // Apply any element transformations to get the reuqired UNIX date
    switch ($in_keyword) {
        case "YESTERDAY":
            $new_time -= 60 * 60 * 24;
            break;
        case "TOMORROW":
            $new_time += 60 * 60 * 24;
            break;
        case "LASTOFLASTMONTH":
        case "LASTOFMONTH":
            $new_time -= 60 * 60 * 24;
            break;
        case "STARTOFWEEK":
            ///$new_time = strtotime("last Saturday");
            $new_time = strtotime("this week");
            break;
        case "ENDOFWEEK":
            $new_time = strtotime("next week - 1 day");
            break;
        case "STARTOFLASTWEEK":
            ///$new_time = strtotime("last Saturday");
            $new_time = strtotime("last week");
            break;
        case "ENDOFLASTWEEK":
            $new_time = strtotime("this week - 1 day");
            break;
        case "FIRSTOFMONTH":
        default:
            break;
    }
    if (!class_exists("DateTime", false)) {
        handle_error("This version of PHP does not have the DateTime class. Must be PHP >= 5.3 to use date criteria");
        return false;
    }
    try {
        $datetime = new DateTime("@{$new_time}");
    } catch (Exception $e) {
        handle_error("Error in date formatting<BR>" . $e->getMessage());
        return "";
    }
    $ret = $datetime->format($in_mask);
    return $ret;
}