| [ Index ] |
PHP Cross Reference of MantisBT |
[Summary view] [Print] [Text view]
1 <?php 2 # MantisBT - A PHP based bugtracking system 3 4 # MantisBT is free software: you can redistribute it and/or modify 5 # it under the terms of the GNU General Public License as published by 6 # the Free Software Foundation, either version 2 of the License, or 7 # (at your option) any later version. 8 # 9 # MantisBT is distributed in the hope that it will be useful, 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # GNU General Public License for more details. 13 # 14 # You should have received a copy of the GNU General Public License 15 # along with MantisBT. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Date API 19 * 20 * @package CoreAPI 21 * @subpackage DateAPI 22 * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org 23 * @copyright Copyright (C) 2002 - 2011 MantisBT Team - mantisbt-dev@lists.sourceforge.net 24 * @link http://www.mantisbt.org 25 * 26 * @uses config_api.php 27 * @uses constant_inc.php 28 * @uses helper_api.php 29 * @uses html_api.php 30 * @uses lang_api.php 31 */ 32 33 require_api( 'config_api.php' ); 34 require_api( 'constant_inc.php' ); 35 require_api( 'helper_api.php' ); 36 require_api( 'html_api.php' ); 37 require_api( 'lang_api.php' ); 38 39 /** 40 * Keeps track of whether the external files required for jscalendar to work 41 * have already been included in the output sent to the client. jscalendar 42 * will not work correctly if it is included multiple times on the same page. 43 * @global bool $g_jscalendar_included_already 44 */ 45 $g_calendar_already_imported = false; 46 47 /** 48 * checks if date is null 49 * @param int $p_date 50 * @return bool 51 * @access public 52 */ 53 function date_is_null( $p_date ) { 54 return $p_date == date_get_null(); 55 } 56 57 /** 58 * gets null date 59 * @return int 60 * @access public 61 */ 62 function date_get_null() { 63 return 1; 64 } 65 66 $g_cache_timezone = array(); 67 68 /** 69 * set new timezone 70 * @return null 71 * @access public 72 */ 73 function date_set_timezone( $p_timezone ) { 74 global $g_cache_timezone; 75 76 array_push( $g_cache_timezone, date_default_timezone_get() ); 77 78 if( !date_default_timezone_set( $p_timezone ) ) { 79 // unable to set timezone 80 trigger_error( ERROR_UPDATING_TIMEZONE, WARNING ); 81 } 82 } 83 84 /** 85 * restore previous timezone 86 * @return null 87 * @access public 88 */ 89 function date_restore_timezone( ) { 90 global $g_cache_timezone; 91 92 $t_timezone = array_pop( $g_cache_timezone ); 93 94 if( $t_timezone === null ) { 95 return; 96 } 97 98 if( !date_default_timezone_set( $t_timezone ) ) { 99 // unable to set timezone 100 trigger_error( ERROR_UPDATING_TIMEZONE, WARNING ); 101 } 102 } 103 104 /** 105 * 106 * @param int $p_month 107 * @return null 108 * @access public 109 */ 110 function print_month_option_list( $p_month = 0 ) { 111 for( $i = 1;$i <= 12;$i++ ) { 112 $month_name = date( 'F', mktime( 0, 0, 0, $i, 1, 2000 ) ); 113 if( $i == $p_month ) { 114 echo "<option value=\"$i\" selected=\"selected\">" . lang_get( 'month_' . utf8_strtolower($month_name)) . "</option>"; 115 } else { 116 echo "<option value=\"$i\">" . lang_get( 'month_' . utf8_strtolower($month_name)) . "</option>"; 117 } 118 } 119 } 120 121 /** 122 * 123 * 124 * @param int $p_month 125 * @return null 126 * @access public 127 */ 128 function print_numeric_month_option_list( $p_month = 0 ) { 129 for( $i = 1;$i <= 12;$i++ ) { 130 if( $i == $p_month ) { 131 echo "<option value=\"$i\" selected=\"selected\">$i</option>"; 132 } else { 133 echo "<option value=\"$i\">$i</option>"; 134 } 135 } 136 } 137 138 /** 139 * 140 * @param int $p_day 141 * @return null 142 * @access public 143 */ 144 function print_day_option_list( $p_day = 0 ) { 145 for( $i = 1;$i <= 31;$i++ ) { 146 if( $i == $p_day ) { 147 echo "<option value=\"$i\" selected=\"selected\">$i</option>"; 148 } else { 149 echo "<option value=\"$i\">$i</option>"; 150 } 151 } 152 } 153 154 /** 155 * 156 * @param int $p_year 157 * @return null 158 * @access public 159 */ 160 function print_year_option_list( $p_year = 0 ) { 161 $current_year = date( "Y" ); 162 163 for( $i = $current_year;$i > 1999;$i-- ) { 164 if( $i == $p_year ) { 165 echo "<option value=\"$i\" selected=\"selected\">$i</option>"; 166 } else { 167 echo "<option value=\"$i\">$i</option>"; 168 } 169 } 170 } 171 172 /** 173 * 174 * @param int $p_year 175 * @param int $p_start 176 * @param int $p_end 177 * @return null 178 * @access public 179 */ 180 function print_year_range_option_list( $p_year = 0, $p_start = 0, $p_end = 0 ) { 181 $t_current = date( 'Y' ); 182 $t_forward_years = config_get( 'forward_year_count' ); 183 184 $t_start_year = $p_start; 185 if( $t_start_year == 0 ) { 186 $t_backward_years = config_get( 'backward_year_count' ); 187 $t_start_year = $t_current - $t_backward_years; 188 } 189 190 if(( $p_year < $t_start_year ) && ( $p_year != 0 ) ) { 191 $t_start_year = $p_year; 192 } 193 194 $t_end_year = $p_end; 195 if( $t_end_year == 0 ) { 196 $t_end_year = $t_current + $t_forward_years; 197 } 198 if( $p_year > $t_end_year ) { 199 $t_end_year = $p_year + $t_forward_years; 200 } 201 202 for( $i = $t_start_year;$i <= $t_end_year;$i++ ) { 203 if( $i == $p_year ) { 204 echo "<option value=\"$i\" selected=\"selected\">$i</option>"; 205 } else { 206 echo "<option value=\"$i\">$i</option>"; 207 } 208 } 209 } 210 211 /** 212 * 213 * @param string $p_name 214 * @param string $p_format 215 * @param int $p_date 216 * @param bool $p_default_disable 217 * @param bool $p_allow_blank 218 * @param int $p_year_start 219 * @param int $p_year_end 220 * @return null 221 * @access public 222 */ 223 function print_date_selection_set( $p_name, $p_format, $p_date = 0, $p_default_disable = false, $p_allow_blank = false, $p_year_start = 0, $p_year_end = 0 ) { 224 $t_chars = preg_split( '//', $p_format, -1, PREG_SPLIT_NO_EMPTY ); 225 if( $p_date != 0 ) { 226 $t_date = preg_split( '/-/', date( 'Y-m-d', $p_date ), -1, PREG_SPLIT_NO_EMPTY ); 227 } else { 228 $t_date = array( 229 0, 230 0, 231 0, 232 ); 233 } 234 235 $t_disable = ''; 236 if( $p_default_disable == true ) { 237 $t_disable = ' disabled="disabled"'; 238 } 239 $t_blank_line = ''; 240 if( $p_allow_blank == true ) { 241 $t_blank_line = "<option value=\"0\"></option>"; 242 } 243 244 foreach( $t_chars as $t_char ) { 245 if( strcmp( $t_char, "M" ) == 0 ) { 246 echo "<select ", helper_get_tab_index(), " name=\"" . $p_name . "_month\"$t_disable>"; 247 echo $t_blank_line; 248 print_month_option_list( $t_date[1] ); 249 echo "</select>\n"; 250 } 251 if( strcmp( $t_char, "m" ) == 0 ) { 252 echo "<select ", helper_get_tab_index(), " name=\"" . $p_name . "_month\"$t_disable>"; 253 echo $t_blank_line; 254 print_numeric_month_option_list( $t_date[1] ); 255 echo "</select>\n"; 256 } 257 if( strcasecmp( $t_char, "D" ) == 0 ) { 258 echo "<select ", helper_get_tab_index(), " name=\"" . $p_name . "_day\"$t_disable>"; 259 echo $t_blank_line; 260 print_day_option_list( $t_date[2] ); 261 echo "</select>\n"; 262 } 263 if( strcasecmp( $t_char, "Y" ) == 0 ) { 264 echo "<select ", helper_get_tab_index(), " name=\"" . $p_name . "_year\"$t_disable>"; 265 echo $t_blank_line; 266 print_year_range_option_list( $t_date[0], $p_year_start, $p_year_end ); 267 echo "</select>\n"; 268 } 269 } 270 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Jul 28 15:48:31 2011 | Cross-referenced by PHPXref 0.7 |