listprint_napdf.class.php

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