Ejemplo n.º 1
0
	/**
	 * Renders a calendar or time-period validity period, e.g. Year 2007, March - May 2007, December 2006 - January 2007, etc.
	 *
	 * @param  int|null  $expiryTime   Unix-time
	 * @param  int|null  $startTime    Unix-time
	 * @param  string    $varName      variable name ( 'validity' (default) or 'first_validity' )
	 * @param  string    $reason       payment reason: 'N'=new subscription (default), 'R'=renewal, 'U'=update (needed only if $expiryTime is NULL)
	 * @param  int       $occurrences  number of occurrences (needed only if $expiryTime is NULL)
	 * @param  boolean   $displayOne   Display significant 1s also if it's 1: e.g. TRUE: 1 year, FALSE: year
	 * @param  boolean   $html         true: Display for html with non-breaking spaces
	 * @return string
	 */
	public function getFormattedValidity( $expiryTime, $startTime, $varName, $reason = null, $occurrences = 1, $displayOne = true, $html = false ) {
		global $_CB_framework;

		$this->fixVarName( $varName );

		$text = '';
		if ( $this->isCalendarValidity( $varName ) ) {
			$offset		=	(int) $_CB_framework->getCfg( 'offset' ) * 3600;
			$now		=	$_CB_framework->now();
			if ( $startTime === null ) {
				$startTime = $now;
			}
			if ( $expiryTime === null ) {
				$expiryTime = $this->getExpiryTime( $startTime, $varName, $occurrences, $reason );		// WARNING: adjusts $startTime to the real Start-time, which is wanted here
			}
			$now		+= $offset;
			$startTime	+= $offset;
			$expiryTime	+= $offset;
			$isValid	= ( /*removed otherwise renew buttons display wrong: ( $startTime <= $now  ) && */ ( $now < $expiryTime ) );
			list( $y, $c, $d, /* $h */, /* $m */, /* $s */ ) = $this->getValidity( $varName );	// = sscanf( substr( $this->get( $varName ), 2 ), '%d-%d-%d %d:%d:%d' );
			list( $yn, $cn, $dn )	=	sscanf( date( 'Y-m-d', $now ),		  '%d-%d-%d' );
			list( $ys, $cs, $ds )	=	sscanf( date( 'Y-m-d', $startTime ),  '%d-%d-%d' );
			list( $ye, $ce, $de )	=	sscanf( date( 'Y-m-d', $expiryTime ), '%d-%d-%d' );
			$calStart	=	$this->calendarYearStart( $varName );
			if ( $y && ( $calStart == '01-01' ) ) {
				if ( ( $y == 1 ) && ( $ye <= ( $ys + 1 ) ) ) {
					$text .= sprintf( $this->_htmlNbsp( CBPTXT::T("Year %s"), $html ), $ye );						// 'Year 2007'
					if ( $ye != $yn && $isValid ) {
						$text .= ' (' . CBPTXT::T("valid from now on") . ')';
					}
				} else {
					$years = $ye - $ys + 1;
					if ( ( ! $isValid ) || ( ( $y == $years ) && ( $ys == $yn ) ) ) {
						$text .= sprintf( $this->_htmlNbsp( CBPTXT::T("Years %s - %s"), $html ), $ys, $ye );		// 'Years 2006 - 2007'
					} else {
						if ( $y == $years ) {
							$text .= sprintf( $this->_htmlNbsp( CBPTXT::T("Years %s - %s"), $html ), $ys, $ye );	// 'Years 2007 - 2008'
						} else {
							$text .= sprintf( $this->_htmlNbsp( CBPTXT::T("Years %s - %s"), $html ), $ys + 1, $ye ); // 'Years 2007 - 2008'
						}
						$text .= ' (' . CBPTXT::T("valid from now on") . ')';
					}
				}
			} elseif ( $c || $y ) {
				if ( ( $calStart != '01-01' ) && ! preg_match( '/$..-01/', $calStart ) ) {
					// $text .= $calStart . date( 'Y-m-d H:i:s', $startTime ) .( $c + ( $y * 12 ) ) . '_' . ($ce - $cs + 1 + ( ( $ye - $ys ) * 12 )) . '_';
					$text .= CBPTXT::Tdate( 'j F', $startTime) . ( ( $ys != $ye ) ? $this->_htmlNbsp( ' ', $html ) . $ys : '' );	// 'January' or 'December 2006'
					$text .= $this->_htmlNbsp( ' - ', $html );														// ' - '
					$text .= CBPTXT::Tdate( 'j F', $expiryTime) . $this->_htmlNbsp( ' ', $html ) . $ye;						// 'February 2007'
					if ( ( ! ( ( $cs == $cn ) && ( $ys == $yn ) ) ) && $isValid ) {
						$text .= ' (' . CBPTXT::T("valid from now on") . ')';
					}
				} else {
					$months = $ce - $cs + 1 + ( ( $ye - $ys ) * 12 );
					if ( ( ( $c == 1 ) && ( $y == 0 ) ) || ( $months == 1 ) ) {
						$text .= CBPTXT::Tdate( 'F', $expiryTime) . $this->_htmlNbsp( ' ', $html ) . $ye;		// 'January 2007'
						if ( $ce != $cn  && $isValid ) {
							$text .= ' (' . CBPTXT::T("valid from now on") . ')';
						}
					} else {
						// if ( ( $c + ( $y * 12 ) ) == $months ) {
						$text .= CBPTXT::Tdate( 'F', $startTime) . ( ( $ys != $ye ) ? $this->_htmlNbsp( ' ', $html ) . $ys : '' );	// 'January' or 'December 2006'
						$text .= $this->_htmlNbsp( ' - ', $html );														// ' - '
						$text .= CBPTXT::Tdate( 'F', $expiryTime) . $this->_htmlNbsp( ' ', $html ) . $ye;						// 'February 2007'
						if ( ( ! ( ( $cs == $cn ) && ( $ys == $yn ) ) ) && $isValid ) {
							$text .= ' (' . CBPTXT::T("valid from now on") . ')';
						}
						// } else {		//TBD: check if this else is still needed
						/*	list($ynn, $cnn, $dnn, $hnn, $mnn, $snn) = sscanf( date( 'Y-m-d H:i:s', $startTime ), '%d-%d-%d %d:%d:%d' );
							$cnn += 2;
							$dnn = 0;
							$nextMonthTime = mktime($hnn, $mnn, $snn, $cnn, $dnn, $ynn);
							$text .= date( 'F', $nextMonthTime) . ( ( $ynn != $ye ) ? $this->_htmlNbsp( ' ', $html ) . $ynn : '' );	// 'January' or 'December 2006'
							$text .= $this->_htmlNbsp( ' - ', $html );														// ' - '
							$text .= date( 'F', $expiryTime) . $this->_htmlNbsp( ' ', $html ) . $ye;						// 'February 2007'
							if ( $isValid ) {
								$text .= ' (' . CBPTXT::T("valid from now on") . ')';
							}
						*/
						// }
					}
				}
			} elseif ( $d ) {
				if ( $de == $dn ) {
					$text .= CBPTXT::T("Today");
				} elseif ( ( $de == ( $dn + 1 ) ) || ( ( $de == 1 ) && ( ( $expiryTime - $now ) < 48*3600 ) ) ) {
					if ( $d == 1 ) {
						$text .= CBPTXT::T("Tomorrow");
						if ( $isValid ) {
							$text .= ' (' . CBPTXT::T("valid from now on") . ')';
						}
					} else {
						$text .= CBPTXT::T("Today and tomorrow");
					}
				} else {
					if ( $isValid ) {
						$days = (int) floor( ( $expiryTime - $now ) / ( 24 * 3600 ) );
						if ( ( $days < $d ) && ( $ds == $dn ) ) {
							$t		=	CBPTXT::T("Today and next %d days");
							if ( $html ) {
								$t	=	str_replace( ' %d ', '&nbsp;%d&nbsp;', $t );
							}
							$text .= sprintf( $t, $days );
						} else {
							$text .= sprintf( $this->_htmlNbsp( CBPTXT::T("Next %d days"), $html ), $days ) . ' (' . CBPTXT::T("in addition of today, valid from now on") . ')';
						}
					} else {
						$showtime	= false;
						cbimport( 'cb.tabs' );		// cbFormatDate is in comprofiler.class.php
						$expText	= cbFormatDate( $expiryTime, 0, $showtime );
						$startText	= cbFormatDate( $startTime, 0, $showtime );
						$text		.= $startText;
						if ( $startText != $expText ) {
							$text	.= $this->_htmlNbsp( ' - ', $html ) . $expText;
						}
					}
				}
			}

		} else {
			$text = $this->_htmlNbsp( $this->renderPeriod( $this->getValidity( $varName ), 1, $displayOne ), $html );
		}
		return trim( $text );
	}
 /**
  * Renders a calendar or time-period validity period, e.g. Year 2007, March - May 2007, December 2006 - January 2007, etc.
  *
  * @param  int|null  $expiryTime   Unix-time
  * @param  int|null  $startTime    Unix-time
  * @param  string    $varName      variable name ( 'validity' (default) or 'first_validity' )
  * @param  string    $reason       payment reason: 'N'=new subscription (default), 'R'=renewal, 'U'=update (needed only if $expiryTime is NULL)
  * @param  int       $occurrences  number of occurrences (needed only if $expiryTime is NULL)
  * @param  boolean   $displayOne   Display significant 1s also if it's 1: e.g. TRUE: 1 year, FALSE: year
  * @param  boolean   $html         true: Display for html with non-breaking spaces
  * @param  string    $status       status of subscription
  * @return string
  */
 public function getFormattedValidity($expiryTime, $startTime, $varName, $reason = null, $occurrences = 1, $displayOne = true, $html = false, $status = 'I')
 {
     $this->fixVarName($varName);
     $text = '';
     if ($this->isCalendarValidity($varName)) {
         $now = cbpaidTimes::getInstance()->startTime();
         if ($startTime === null) {
             $startTime = $now;
         }
         if ($expiryTime === null) {
             $expiryTime = $this->getExpiryTime($startTime, $varName, $occurrences, $reason, $status);
             // WARNING: adjusts $startTime to the real Start-time, which is wanted here
         }
         $isValid = $now < $expiryTime;
         list($y, $c, $d, , , ) = $this->getValidity($varName);
         // = sscanf( substr( $this->get( $varName ), 2 ), '%d-%d-%d %d:%d:%d' );
         list($yn, $cn, $dn) = sscanf(cbpaidTimes::getInstance()->localDate('Y-m-d', $now), '%d-%d-%d');
         list($ys, $cs, $ds) = sscanf(cbpaidTimes::getInstance()->localDate('Y-m-d', $startTime), '%d-%d-%d');
         list($ye, $ce, $de) = sscanf(cbpaidTimes::getInstance()->localDate('Y-m-d', $expiryTime), '%d-%d-%d');
         $calStart = $this->calendarYearStart($varName);
         if ($y && $calStart == '01-01') {
             if ($y == 1 && $ye <= $ys + 1) {
                 $text .= sprintf($this->_htmlNbsp(CBPTXT::T("Year %s"), $html), $ye);
                 // 'Year 2007'
                 if ($ye != $yn && $isValid) {
                     $text .= ' (' . CBPTXT::T("valid from now on") . ')';
                 }
             } else {
                 $years = $ye - $ys + 1;
                 if (!$isValid || $y == $years && $ys == $yn) {
                     $text .= sprintf($this->_htmlNbsp(CBPTXT::T("Years %s - %s"), $html), $ys, $ye);
                     // 'Years 2006 - 2007'
                 } else {
                     if ($y == $years) {
                         $text .= sprintf($this->_htmlNbsp(CBPTXT::T("Years %s - %s"), $html), $ys, $ye);
                         // 'Years 2007 - 2008'
                     } else {
                         $text .= sprintf($this->_htmlNbsp(CBPTXT::T("Years %s - %s"), $html), $ys + 1, $ye);
                         // 'Years 2007 - 2008'
                     }
                     $text .= ' (' . CBPTXT::T("valid from now on") . ')';
                 }
             }
         } elseif ($c || $y) {
             if ($calStart != '01-01' && !preg_match('/$..-01/', $calStart)) {
                 // $text .= $calStart . date( 'Y-m-d H:i:s', $startTime ) .( $c + ( $y * 12 ) ) . '_' . ($ce - $cs + 1 + ( ( $ye - $ys ) * 12 )) . '_';
                 $text .= CBPTXT::Tdate('j F', $startTime) . ($ys != $ye ? $this->_htmlNbsp(' ', $html) . $ys : '');
                 // 'January' or 'December 2006'
                 $text .= $this->_htmlNbsp(' - ', $html);
                 // ' - '
                 $text .= CBPTXT::Tdate('j F', $expiryTime) . $this->_htmlNbsp(' ', $html) . $ye;
                 // 'February 2007'
                 if (($ys > $yn || $cs > $cn && $ys == $yn) && $isValid) {
                     $text .= ' (' . CBPTXT::T("valid from now on") . ')';
                 }
             } else {
                 $months = $ce - $cs + 1 + ($ye - $ys) * 12;
                 if ($c == 1 && $y == 0 || $months == 1) {
                     $text .= CBPTXT::Tdate('F', $expiryTime) . $this->_htmlNbsp(' ', $html) . $ye;
                     // 'January 2007'
                     if ($ce != $cn && $isValid) {
                         $text .= ' (' . CBPTXT::T("valid from now on") . ')';
                     }
                 } else {
                     // if ( ( $c + ( $y * 12 ) ) == $months ) {
                     $text .= CBPTXT::Tdate('F', $startTime) . ($ys != $ye ? $this->_htmlNbsp(' ', $html) . $ys : '');
                     // 'January' or 'December 2006'
                     $text .= $this->_htmlNbsp(' - ', $html);
                     // ' - '
                     $text .= CBPTXT::Tdate('F', $expiryTime) . $this->_htmlNbsp(' ', $html) . $ye;
                     // 'February 2007'
                     if (!($cs == $cn && $ys == $yn) && $isValid) {
                         $text .= ' (' . CBPTXT::T("valid from now on") . ')';
                     }
                     // } else {		//TBD: check if this else is still needed
                     /*	list($ynn, $cnn, $dnn, $hnn, $mnn, $snn) = sscanf( gmdate( 'Y-m-d H:i:s', $startTime ), '%d-%d-%d %d:%d:%d' );
                     				$cnn += 2;
                     				$dnn = 0;
                     				$nextMonthTime = mktime($hnn, $mnn, $snn, $cnn, $dnn, $ynn);
                     				$text .= gmdate( 'F', $nextMonthTime) . ( ( $ynn != $ye ) ? $this->_htmlNbsp( ' ', $html ) . $ynn : '' );	// 'January' or 'December 2006'
                     				$text .= $this->_htmlNbsp( ' - ', $html );														// ' - '
                     				$text .= gmdate( 'F', $expiryTime) . $this->_htmlNbsp( ' ', $html ) . $ye;						// 'February 2007'
                     				if ( $isValid ) {
                     					$text .= ' (' . CBPTXT::T("valid from now on") . ')';
                     				}
                     			*/
                     // }
                 }
             }
         } elseif ($d) {
             if ($de == $dn) {
                 $text .= CBPTXT::T("Today");
             } elseif ($de == $dn + 1 || $de == 1 && $expiryTime - $now < 48 * 3600) {
                 if ($d == 1) {
                     $text .= CBPTXT::T("Tomorrow");
                     if ($isValid) {
                         $text .= ' (' . CBPTXT::T("valid from now on") . ')';
                     }
                 } else {
                     $text .= CBPTXT::T("Today and tomorrow");
                 }
             } else {
                 if ($isValid) {
                     $days = (int) floor(($expiryTime - $now) / (24 * 3600));
                     if ($days < $d && $ds == $dn) {
                         $t = CBPTXT::T("Today and next %d days");
                         if ($html) {
                             $t = str_replace(' %d ', '&nbsp;%d&nbsp;', $t);
                         }
                         $text .= sprintf($t, $days);
                     } else {
                         $text .= sprintf($this->_htmlNbsp(CBPTXT::T("Next %d days"), $html), $days) . ' (' . CBPTXT::T("in addition of today, valid from now on") . ')';
                     }
                 } else {
                     $showtime = false;
                     cbimport('cb.tabs');
                     // cbFormatDate is in comprofiler.class.php
                     $expText = cbFormatDate($expiryTime, 0, $showtime);
                     $startText = cbFormatDate($startTime, 0, $showtime);
                     $text .= $startText;
                     if ($startText != $expText) {
                         $text .= $this->_htmlNbsp(' - ', $html) . $expText;
                     }
                 }
             }
         }
     } else {
         $text = $this->_htmlNbsp($this->renderPeriod($this->getValidity($varName), 1, $displayOne), $html);
     }
     return trim($text);
 }
 /**
  * Returns formatted time period ( xxx weeks , or xxx years xxx months xxx days xxx hours xxx minutes xxx seconds
  *
  * @param  string        $varName                    'validity' or 'fist_validity'
  * @param  int           $occurrences                [default: 1] multiply period by the occurrences before displaying
  * @param  boolean       $displayOne                 [default: true] displays also if only 1 unit of something
  * @param  boolean       $displayCalendarYearStart   [default: true] displays start of calendar year if not January 1st
  * @return string
  */
 private function _renderPeriodOfValiditiy($varName, $occurrences = 1, $displayOne = true, $displayCalendarYearStart = true)
 {
     $ycdhmsArray = $this->getValidity($varName);
     $prefix = $this->isCalendarValidity($varName) ? CBPTXT::T("calendar ") : '';
     $text = $this->renderPeriod($ycdhmsArray, $occurrences, $displayOne, $prefix);
     $calStart = $this->calendarYearStart($varName);
     if ($prefix && $calStart != '01-01' && $displayCalendarYearStart) {
         list($m, $d) = explode('-', $calStart);
         $text .= ' ' . CBPTXT::T("starting") . ' ' . CBPTXT::Tdate('F j', cbpaidTimes::getInstance()->localStrToTime((int) $m . '/' . (int) $d));
     }
     return $text;
 }