00001 <?php
00002
00003
00004
00005
00006
00007
00008 require_once ( dirname ( __FILE__ ).'/../pdf_generator/printableList.class.php' );
00009 require_once ( dirname ( __FILE__ ).'/pdf_decls.php' );
00010
00011
00012
00013
00014
00015 class gnyr_napdf extends printableList implements IPrintableList
00016 {
00017 var $weekday_names = array ( "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" );
00018 var $pos = array ( 'start' => 1, 'end' => '', 'count' => 0, 'y' => 0, 'weekday' => 1 );
00019 var $right_offset = 0;
00020 var $formats = 0;
00021 var $special_formats = '';
00022
00023
00024
00025
00026
00027
00028
00029 function __construct ( $in_http_vars
00030 )
00031 {
00032 $this->page_x = 4.25;
00033 $this->page_y = 5.25;
00034 $this->units = 'in';
00035 $this->font = 'Times';
00036 $this->font_size = 7.25;
00037 $this->orientation = 'P';
00038
00039 $this->sort_keys = array ( 'weekday_tinyint' => true,
00040 'start_time' => true,
00041 'week_starts' => 1
00042 );
00043
00044 $this->out_http_vars = array ('do_search' => 'yes',
00045 'bmlt_search_type' => 'advanced',
00046 'advanced_service_bodies' => array (
00047 1,
00048 2,
00049 1001,
00050 1002,
00051 1003,
00052 1004,
00053 1005,
00054 1006,
00055 1007,
00056 1008,
00057 1009,
00058 1010,
00059 1011,
00060 1012,
00061 1013,
00062 1014,
00063 1015,
00064 1016,
00065 1017
00066 )
00067 );
00068
00069 $this->lang_search = array ( 'en', 'es' );
00070
00071 napdf::$sort_callback = 'gnyr_napdf::sort_meeting_data_callback_ny';
00072
00073 parent::__construct ( $in_http_vars, $this->lang_search );
00074 }
00075
00076
00077
00078
00079
00080
00081 function AssemblePDF ()
00082 {
00083 $ret = false;
00084
00085 if ( $this->napdf_instance instanceof napdf )
00086 {
00087 $this->DrawFormatPage ( );
00088 while ( !$this->pos['end'] )
00089 {
00090 $this->DrawListPage ();
00091 }
00092 $ret = true;
00093 }
00094
00095 return $ret;
00096 }
00097
00098
00099
00100 function OutputPDF ()
00101 {
00102 $d = date ( "Y_m_d" );
00103 $this->napdf_instance->Output( "GNYR_PrintableList_$d.pdf", "D" );
00104 }
00105
00106
00107
00108
00109 private static function sort_cmp_formats ($a, $b)
00110 {
00111 $order_array = array( 0=>"O", 1=>"C",
00112 2=>"ES", 3=>"B", 4=>"M", 5=>"W", 6=>"GL", 7=>"YP", 8=>"BK", 9=>"IP", 10=>"Pi", 11=>"RF", 12=>"Rr",
00113 13=>"So", 14=>"St", 15=>"To", 16=>"Tr", 17=>"OE", 18=>"D", 19=>"SD", 20=>"TW", 21=>"IL",
00114 22=>"BL", 23=>"IW", 24=>"BT", 25=>"SG", 26=>"JT",
00115 27=>"Ti", 28=>"Sm", 29=>"NS", 30=>"CL", 31=>"CS", 32=>"NC", 33=>"SC", 34=>"CH", 35=>"SL", 36=>"WC" );
00116
00117 if ( in_array ( $a['key_string'], $order_array ) || in_array ( $b['key_string'], $order_array ) )
00118 {
00119 return (array_search ( $a['key_string'], $order_array ) < array_search ( $b['key_string'], $order_array )) ? -1 : 1;
00120 }
00121 else
00122 {
00123 return 0;
00124 }
00125 }
00126
00127
00128
00129
00130
00131
00132
00133 private static function sort_formats( $in_format_data
00134 )
00135 {
00136 $ret = array();
00137
00138 foreach ( $in_format_data as $format )
00139 {
00140 if ( $format['lang'] == 'en' )
00141 {
00142 $s_desc = ((isset ( $in_format_data[$format['id'].'_es'] )) ? '('.$in_format_data[$format['id'].'_es']['name_string'].') '.$in_format_data[$format['id'].'_es']['description_string'] : null);
00143 $r_temp = array ( 'key_string' => $format['key_string'],
00144 'description_string' => '('.$format['name_string'].') '.$format['description_string']
00145 );
00146 if ( $s_desc )
00147 {
00148 $r_temp['description_string'] .= "\n$s_desc";
00149 }
00150
00151 array_push ( $ret, $r_temp );
00152 }
00153 }
00154
00155 usort ( $ret, 'gnyr_napdf::sort_cmp_formats' );
00156
00157 return $ret;
00158 }
00159
00160
00161
00162 private function DrawFormatPage ( )
00163 {
00164 $formats = self::sort_formats ( $this->napdf_instance->format_data );
00165
00166 $this->napdf_instance->SetFont ( $this->font, '', $this->font_size );
00167 $heading_height = 9;
00168 $height = ($heading_height/72) + 0.01;
00169 $top = 0.125;
00170 $left = 0.125;
00171 $bottom = $this->napdf_instance->h - 0.125;
00172 $right = $this->napdf_instance->w - 0.125;
00173 $fontFamily = $this->napdf_instance->FontFamily;
00174 $fontSize = $this->napdf_instance->FontSizePt;
00175 $fontSizeSmaller = $fontSize - 0.25;
00176 $fSize = $fontSizeSmaller / 72;
00177 $this->right_offset = 0.4;
00178 $space_needed = (($fontSizeSmaller / 72) * 5) + 0.02;
00179 $y_offset = $bottom - $fSize;
00180
00181 $newpage = 2;
00182
00183 $countmax = count ( $formats );
00184
00185 $this->special_formats = array ( 'WC' => '', 'NC' => '' );
00186
00187 for ( $count = 0; $count < $countmax; $count++ )
00188 {
00189 $format_code = $formats[$count]['key_string'];
00190 $format_english = $formats[$count]['description_string'];
00191
00192 if ( isset ( $this->special_formats[$format_code] ) )
00193 {
00194 $this->special_formats[$format_code] = $format_english;
00195 $format_code = null;
00196 }
00197
00198 if ( $format_code )
00199 {
00200 if ( $newpage )
00201 {
00202 $this->napdf_instance->AddPage();
00203 $this->napdf_instance->SetFont ( $fontFamily, 'B', 7 );
00204 $this->napdf_instance->Line ( $left, $y_offset - 0.1, $right, $y_offset - 0.1 );
00205 $this->napdf_instance->SetXY ( $left, $y_offset );
00206 global $resized;
00207
00208 $this->napdf_instance->Cell ( 0, 0, _PDF_CHANGE_NOTE );
00209 $this->napdf_instance->SetXY ( $right, $y_offset );
00210 $this->napdf_instance->Cell ( 0, 0, _PDF_PAGE." ".$this->napdf_instance->PageNo(), 0, 0, "R" );
00211 $this->napdf_instance->SetFont ( $fontFamily, '', $fontSize );
00212 $this->napdf_instance->SetFillColor ( 0 );
00213 $this->napdf_instance->SetTextColor ( 255 );
00214 $header = ""._PDF_LEGEND_HEADER."";
00215 if ( $newpage != 2 )
00216 {
00217 $header .= _PDF_CONTD;
00218 }
00219
00220 $this->napdf_instance->SetFont ( $fontFamily, 'B', $heading_height );
00221 $stringWidth = $this->napdf_instance->GetStringWidth ( $header );
00222 $cellleft = (($right + $left) / 2) - ($stringWidth / 2);
00223 $this->napdf_instance->Rect ( $left, $top, ($right - $left), $height, "F" );
00224 $this->napdf_instance->SetXY ( $cellleft, $top + 0.01 );
00225 $this->napdf_instance->Cell ( 0, $heading_height/72, $header );
00226 $this->napdf_instance->SetFillColor ( 255 );
00227 $this->napdf_instance->SetTextColor ( 0 );
00228 $newpage = "";
00229 $this->napdf_instance->SetY ( $top + $height );
00230 }
00231 else
00232 {
00233 $this->napdf_instance->Line ( $left, $this->napdf_instance->GetY() + 0.01, $right, $this->napdf_instance->GetY() + 0.01 );
00234 $this->napdf_instance->SetY ( $this->napdf_instance->GetY() + 0.02 );
00235 }
00236
00237 $y = $this->napdf_instance->GetY();
00238
00239 $this->napdf_instance->SetFont ( $fontFamily, 'B', $fontSizeSmaller );
00240 $this->napdf_instance->SetLeftMargin ( $left );
00241 $this->napdf_instance->SetXY ( $left, $y );
00242 $this->napdf_instance->MultiCell ( $this->right_offset - $left, $fSize, utf8_decode ( $format_code ), 0, "L" );
00243
00244 $this->napdf_instance->SetFont ( $fontFamily, '', $fontSizeSmaller );
00245 $this->napdf_instance->SetLeftMargin ( $this->right_offset );
00246 $this->napdf_instance->SetXY ( $this->right_offset, $y );
00247 $this->napdf_instance->MultiCell ( $right - $this->right_offset, $fSize, utf8_decode ( $format_english ), 0, "L" );
00248
00249 if ( ($this->napdf_instance->GetY() + 0.01 + $space_needed) >= $y_offset )
00250 {
00251 $newpage = 1;
00252 }
00253 }
00254 }
00255
00256 if ( ($this->napdf_instance->GetY() + 0.3 + $fSize/72) > $y_offset )
00257 {
00258 $this->napdf_instance->AddPage();
00259 $y = $y_offset;
00260 }
00261 else
00262 {
00263 $y = $this->napdf_instance->GetY() + 0.3;
00264 }
00265
00266 $this->napdf_instance->Line ( $left, $y - 0.1, $right, $y - 0.1 );
00267 $this->napdf_instance->SetXY ( $left, $y );
00268 $this->napdf_instance->SetFont ( $fontFamily, 'I', $fontSize );
00269 $this->napdf_instance->Cell ( 0, $fSize/72, _DEFAULT_DURATION );
00270 $this->napdf_instance->SetFont ( $fontFamily, '', $fontSize );
00271 $this->napdf_instance->SetLeftMargin ( $left );
00272 }
00273
00274
00275
00276 private function DrawListPage ( )
00277 {
00278 $meetings =& $this->napdf_instance->meeting_data;
00279
00280 $count_max = count ( $meetings );
00281
00282 $fontFamily = $this->napdf_instance->FontFamily;
00283 $fontSize = $this->napdf_instance->FontSizePt;
00284
00285 $top = 0.125;
00286 $left = 0.125;
00287 $bottom = $this->napdf_instance->h - 0.125;
00288 $right = $this->napdf_instance->w - 0.125;
00289 $this->right_offset = 1.5;
00290
00291 $heading_height = 9;
00292 $height = ($heading_height/72) + 0.01;
00293 $gap2 = 0.02;
00294
00295 $fSize = $fontSize / 70;
00296 $fSizeSmall = ($fontSize - 1) / 70;
00297
00298 $height_one_meeting = ($fSize * 3) + $gap2;
00299
00300 $y_offset = $bottom - $fSize;
00301
00302 $current_county = " ";
00303 $current_day = " ";
00304
00305 $extra_height = $height + 0.05;
00306
00307 $this->napdf_instance->AddPage();
00308 $this->pos['y'] = $top;
00309 $watermark_pos = 1.0;
00310
00311 if ( $this->pos['start'] )
00312 {
00313 $this->pos['count'] = 0;
00314 }
00315
00316 while ( !$this->pos['end'] && (($this->pos['y'] + $height_one_meeting + $extra_height + ($fSizeSmall * 2)) < ($y_offset - 0.1)) )
00317 {
00318 $extra = 0;
00319 $contd = "";
00320 $meeting = $meetings[intval($this->pos['count'])];
00321 $this->napdf_instance->SetLeftMargin ( $left );
00322
00323 $county = $meeting['location_city_subsection'];
00324 if ( !$county )
00325 {
00326 $county = $meeting['location_sub_province'];
00327 }
00328
00329 if ( $this->pos['start'] || ($current_county != $county) || ($current_day != $meeting['weekday_tinyint']) )
00330 {
00331 $this->napdf_instance->SetFillColor ( 0 );
00332 $this->napdf_instance->SetTextColor ( 255 );
00333 if ( $this->pos['start'] )
00334 {
00335 $this->pos['start'] = "";
00336 }
00337 else
00338 {
00339 if ( ($this->pos['y'] == $top) && ($this->pos['weekday'] == $meeting['weekday_tinyint']) && ($this->pos['county'] == $county) )
00340 {
00341 $contd = _PDF_CONTD;
00342 }
00343 }
00344 if ( ($this->pos['y'] == $top) && ($this->pos['weekday'] == $meeting['weekday_tinyint']) && ($this->pos['county'] == $county) )
00345 {
00346 $contd = _PDF_CONTD;
00347 }
00348
00349 if ( $current_day != $meeting['weekday_tinyint'] )
00350 {
00351 $this->pos['weekday'] = $meeting['weekday_tinyint'];
00352 $current_day = $this->pos['weekday'];
00353 }
00354
00355 if ( $current_county != $county )
00356 {
00357 $this->pos['county'] = $county;
00358 $current_county = $this->pos['county'];
00359 }
00360
00361 $header = $current_county." - ".$this->weekday_names[$current_day - 1];
00362
00363 $header .= $contd;
00364
00365 $current_county = $meeting['location_city_subsection'];
00366 if ( !$current_county )
00367 {
00368 $current_county = $meeting['location_sub_province'];
00369 }
00370
00371 $this->napdf_instance->SetFont ( $fontFamily, 'B', $heading_height );
00372 $this->napdf_instance->Rect ( $left, $this->pos['y'], ($right - $left), $height, "F" );
00373 $stringWidth = $this->napdf_instance->GetStringWidth ( $header );
00374 $cellleft = (($right + $left) / 2) - ($stringWidth / 2);
00375 $this->napdf_instance->SetXY ( $cellleft, $this->pos['y'] + 0.005 );
00376 $this->napdf_instance->Cell ( 0, $heading_height/72, $header );
00377 $this->pos['y'] += ($height);
00378 }
00379 else
00380 {
00381 $this->napdf_instance->Line ( $left, $this->pos['y'], $right, $this->pos['y'] );
00382 }
00383
00384 $this->napdf_instance->SetFillColor ( 255 );
00385 $this->napdf_instance->SetTextColor ( 0 );
00386
00387 $cell_top = $this->pos['y'] + $gap2;
00388 $this->napdf_instance->SetXY ( $left, $cell_top );
00389
00390 $this->napdf_instance->SetFont ( $fontFamily, 'B', $fontSize );
00391
00392 $left_string = self::translate_time ( $meeting['start_time'] );
00393 $meeting['duration_time'] = trim ( $meeting['duration_time'] );
00394
00395 if ( isset ( $meeting['duration_time'] ) && $meeting['duration_time'] && ('01:30:00' != $meeting['duration_time']) )
00396 {
00397 $left_string .= " (".self::translate_duration ( $meeting['duration_time'] ).")";
00398 }
00399
00400 $left_string .= " (".$this->RearrangeFormats ( $meeting['formats'] ).")";
00401
00402 $this->napdf_instance->SetX ( $left );
00403 $this->napdf_instance->MultiCell ( $this->right_offset - $left, $fSize, utf8_decode ( $left_string ), 0, "L" );
00404
00405 $left_string = $meeting['location_neighborhood'];
00406
00407 if ( !$left_string )
00408 {
00409 $left_string = $meeting['location_municipality'];
00410 }
00411
00412 if ( $meeting['location_province'] != 'NY' )
00413 {
00414 if ( $left_string )
00415 {
00416 $left_string .= ', ';
00417 }
00418
00419 $left_string .= trim ( $meeting['location_province'] );
00420 }
00421
00422 $this->napdf_instance->SetX ( $left );
00423 $this->napdf_instance->MultiCell ( $this->right_offset - $left, $fSize, utf8_decode ( $left_string ), 0, "L" );
00424
00425 $desc = $this->Get_Special_Format_Text ( $meeting['formats'] );
00426
00427 if ( $meeting['description_string'] )
00428 {
00429 if ( $desc )
00430 {
00431 $desc .= ", ";
00432 }
00433 $desc = $meeting['description_string'];
00434 }
00435
00436 if ( $meeting['comments'] )
00437 {
00438 if ( $desc )
00439 {
00440 $desc .= ", ";
00441 }
00442 $desc .= $meeting['comments'];
00443 }
00444
00445 $desc = preg_replace ( "/[\n|\r]/", ", ", $desc );
00446 $desc = preg_replace ( "/,\s*,/", ",", $desc );
00447 $desc = stripslashes ( stripslashes ( $desc ) );
00448
00449 $trueLeft = $left;
00450
00451 $yMax = $this->napdf_instance->GetY ( );
00452
00453
00454
00455 $this->napdf_instance->SetLeftMargin ( $this->right_offset );
00456 $this->napdf_instance->SetFont ( $fontFamily, '', $fontSize );
00457 $right_string = $meeting['meeting_name'];
00458 $this->napdf_instance->SetXY ( $this->right_offset, $cell_top );
00459
00460 if ( isset ( $meeting['location_text'] ) )
00461 {
00462 $meeting['location_text'] = trim ( $meeting['location_text'] );
00463
00464 if ( $meeting['location_text'] )
00465 {
00466 $right_string .= " (".$meeting['location_text'].")";
00467 }
00468 }
00469
00470 $this->napdf_instance->MultiCell ( $right - $this->right_offset, $fSize, utf8_decode ( $right_string ), 0, "L" );
00471
00472 $right_string = $meeting['location_street'];
00473
00474 if ( isset ( $meeting['location_info'] ) )
00475 {
00476 $meeting['location_info'] = trim ( $meeting['location_info'] );
00477
00478 if ( $meeting['location_info'] )
00479 {
00480 $right_string .= " (".$meeting['location_info'].")";
00481 }
00482 }
00483
00484 $this->napdf_instance->SetX ( $this->right_offset );
00485 $this->napdf_instance->MultiCell ( $right - $this->right_offset, $fSize, utf8_decode ( $right_string ), 0, "L" );
00486
00487 $yMax = max ( $yMax, $this->napdf_instance->GetY ( ) );
00488
00489 if ( $desc )
00490 {
00491 $extra = ($fSizeSmall * 3);
00492 $this->napdf_instance->SetFont ( $fontFamily, 'I', $fontSize - 1 );
00493 $this->napdf_instance->SetXY ( $left, $yMax );
00494 $this->napdf_instance->MultiCell ( $right - $left, $fSizeSmall, utf8_decode ( $desc ), 0, "L" );
00495 }
00496
00497 $yMax = max ( $yMax, $this->napdf_instance->GetY ( ) ) + $gap2;
00498 $this->pos['y'] = $yMax;
00499 $this->pos['count']++;
00500
00501 if ( $this->pos['count'] == $count_max )
00502 {
00503 $this->pos['end'] = 1;
00504 }
00505 else
00506 {
00507 $next_meeting = $meetings[intval($this->pos['count'])];
00508
00509 $next_meeting_county = $next_meeting['location_city_subsection'];
00510 if ( !$next_meeting_county )
00511 {
00512 $next_meeting_county = $next_meeting['location_sub_province'];
00513 }
00514
00515 if ( ($current_county != $next_meeting_county)
00516 || ($current_day != $next_meeting['weekday_tinyint']))
00517 {
00518 $extra_height = $height + 0.05;
00519 }
00520 else
00521 {
00522 $extra_height = 0;
00523 }
00524 }
00525 }
00526
00527 $this->napdf_instance->SetFont ( $fontFamily, 'B', 7 );
00528 $this->napdf_instance->Line ( $left, $y_offset - 0.1, $right, $y_offset - 0.1 );
00529 $this->napdf_instance->SetXY ( $left, $y_offset );
00530 $this->napdf_instance->Cell ( 0, 0, _PDF_CHANGE_NOTE );
00531 $this->napdf_instance->SetXY ( $right, $y_offset );
00532 $this->napdf_instance->Cell ( 0, 0, _PDF_PAGE." ".$this->napdf_instance->PageNo(), 0, 0, "R" );
00533 $this->napdf_instance->SetFont ( $fontFamily, '', $fontSize );
00534 }
00535
00536
00537
00538 private function Get_Special_Format_Text ( $inFormats )
00539 {
00540 $ret = "";
00541
00542 $format_array = split ( ",", $inFormats );
00543
00544 foreach ( $format_array as $format )
00545 {
00546 if ( $this->special_formats[$format] )
00547 {
00548 if ( $ret )
00549 {
00550 $ret .= ", ";
00551 }
00552
00553 $ret .= $this->special_formats[$format];
00554 }
00555 }
00556
00557 return $ret;
00558 }
00559
00560
00561
00562 private function RearrangeFormats ( $inFormats )
00563 {
00564 $inFormats = split ( ",", $inFormats );
00565
00566 if ( !in_array ( "C", $inFormats ) && !in_array ( "O", $inFormats ) )
00567 {
00568 array_push ( $inFormats, "C" );
00569 }
00570
00571 if ( !$ignore_bk && !in_array ( "BK", $inFormats ) && ((in_array ( "BT", $inFormats ) || in_array ( "IW", $inFormats ) || in_array ( "JT", $inFormats ) || in_array ( "SG", $inFormats ))) )
00572 {
00573 array_push ( $inFormats, "BK" );
00574 }
00575
00576 for ( $c = 0; $c < count ( $inFormats ); $c++ )
00577 {
00578 if ( array_key_exists ( $inFormats[$c], $this->special_formats ) )
00579 {
00580 $inFormats[$c] = null;
00581 unset ( $inFormats[$c] );
00582 }
00583 }
00584
00585 uasort ( $inFormats, 'gnyr_napdf::sort_cmp' );
00586
00587 $tFormats = $inFormats;
00588
00589 $inFormats = array();
00590
00591 foreach ( $tFormats as $format )
00592 {
00593 $format = trim ( $format );
00594 if ( $format )
00595 {
00596 array_push ( $inFormats, $format );
00597 }
00598 }
00599
00600 return join ( ",", $inFormats );
00601 }
00602
00603
00604
00605 private static function sort_cmp ($a, $b)
00606 {
00607 $order_array = array( 0=>"O", 1=>"C",
00608 2=>"ES", 3=>"B", 4=>"M", 5=>"W", 6=>"GL", 7=>"YP", 8=>"BK", 9=>"IP", 10=>"Pi", 11=>"RF", 12=>"Rr",
00609 13=>"So", 14=>"St", 15=>"To", 16=>"Tr", 17=>"OE", 18=>"D", 19=>"SD", 20=>"TW", 21=>"IL",
00610 22=>"BL", 23=>"IW", 24=>"BT", 25=>"SG", 26=>"JT",
00611 27=>"Ti", 28=>"Sm", 29=>"NS", 30=>"CL", 31=>"CS", 32=>"NC", 33=>"SC", 34=>"CH", 35=>"SL", 36=>"WC" );
00612
00613 if ( in_array ( $a, $order_array ) || in_array ( $b, $order_array ) )
00614 {
00615 return (array_search ( $a, $order_array ) < array_search ( $b, $order_array )) ? -1 : 1;
00616 }
00617 else
00618 {
00619 return 0;
00620 }
00621 }
00622
00623
00624
00625 private static function translate_time ( $in_time_string )
00626 {
00627 $split = split ( ":", $in_time_string );
00628 if ( $in_time_string == "12:00:00" )
00629 {
00630 return "Noon";
00631 }
00632 elseif ( ($split[0] == "23") && (intval ( $split[1] ) > 45) )
00633 {
00634 return "Midnight";
00635 }
00636 else
00637 {
00638 return date ( "g:i A", strtotime ( $in_time_string ) );
00639 }
00640 }
00641
00642
00643
00644 private static function translate_duration ( $in_time_string )
00645 {
00646 $t = split ( ":", $in_time_string );
00647 $hours = intval ( $t[0] );
00648 $minutes = intval ( $t[1] );
00649
00650 $ret = '';
00651
00652 if ( $hours )
00653 {
00654 $ret .= "$hours hour";
00655
00656 if ( $hours > 1 )
00657 {
00658 $ret .= "s";
00659 }
00660
00661 if ( $minutes )
00662 {
00663 $ret .= " and ";
00664 }
00665 }
00666
00667 if ( $minutes )
00668 {
00669 $ret .= "$minutes minutes";
00670 }
00671
00672 return $ret;
00673 }
00674
00675
00676
00677
00678
00679
00680
00681 static function sort_meeting_data_callback_ny ( &$in_a,
00682 &$in_b
00683 )
00684 {
00685 $ret = 0;
00686
00687 if ( is_array ( $in_a ) && is_array ( $in_b ) && is_array ( napdf::$sort_order_keys ) )
00688 {
00689
00690 $sort_keys = array_reverse ( napdf::$sort_order_keys, true );
00691
00692 foreach ( $sort_keys as $key => $value )
00693 {
00694 if ( isset ( $in_a[$key] ) && isset ( $in_b[$key] ) )
00695 {
00696 $val_a = trim ( $in_a[$key] );
00697 $val_b = trim ( $in_b[$key] );
00698
00699 if ( ('weekday_tinyint' == $key) && (napdf::$week_starts > 1) && (napdf::$week_starts < 8) )
00700 {
00701 $val_a -= napdf::$week_starts;
00702
00703 if ( $val_a < 0 )
00704 {
00705 $val_a += 8;
00706 }
00707 else
00708 {
00709 $val_a += 1;
00710 }
00711
00712 $val_b -= napdf::$week_starts;
00713
00714 if ( $val_b < 0 )
00715 {
00716 $val_b += 8;
00717 }
00718 else
00719 {
00720 $val_b += 1;
00721 }
00722 }
00723
00724
00725 switch ( $key )
00726 {
00727 case 'start_time':
00728 case 'duration_time':
00729 $val_a = strtotime ( $val_a );
00730 $val_b = strtotime ( $val_b );
00731 case 'weekday_tinyint':
00732 case 'id_bigint':
00733 case 'shared_group_id_bigint':
00734 case 'service_body_bigint':
00735 $val_a = intval ( $val_a );
00736 $val_b = intval ( $val_b );
00737 case 'longitude':
00738 case 'latitude':
00739 if ( $val_a > $val_b )
00740 {
00741 $ret = 1;
00742 }
00743 elseif ( $val_b > $val_a )
00744 {
00745 $ret = -1;
00746 }
00747 break;
00748
00749 default:
00750
00751 if ( strlen ( $val_a ) && strlen ( $val_b ) )
00752 {
00753 $tmp = strcmp ( strtolower ( $val_a ), strtolower ( $val_b ) );
00754
00755 if ( $tmp != 0 )
00756 {
00757 $ret = $tmp;
00758 }
00759 }
00760 break;
00761 }
00762 }
00763
00764 if ( !$value )
00765 {
00766 $ret = -$ret;
00767 }
00768 }
00769
00770 $county_a = trim ( $in_a['location_city_subsection'] );
00771 if ( !$county_a )
00772 {
00773 $county_a = trim ( $in_a['location_sub_province'] );
00774 }
00775
00776 $county_b = trim ( $in_b['location_city_subsection'] );
00777 if ( !$county_b )
00778 {
00779 $county_b = trim ( $in_b['location_sub_province'] );
00780 }
00781
00782 if ( isset ( $county_a ) && isset ( $county_b ) )
00783 {
00784 $tmp = strcmp ( strtolower ( $county_a ), strtolower ( $county_b ) );
00785
00786 if ( $tmp != 0 )
00787 {
00788 $ret = $tmp;
00789 }
00790 }
00791 }
00792
00793 return $ret;
00794 }
00795 };
00796 ?>