eli_napdf.class.php

Go to the documentation of this file.
00001 <?php
00002 /**
00003     \file eli_napdf.class.php
00004     
00005     \brief This file creates and dumps a Eastern Long Island meeting list in PDF form.
00006 */
00007 // Get the napdf class, which is used to fetch the data and construct the file.
00008 require_once ( dirname ( __FILE__ ).'/../pdf_generator/printableList.class.php' );
00009 require_once ( dirname ( __FILE__ ).'/pdf_decls.php' );
00010 
00011 /**
00012     \brief  This creates and manages an instance of the napdf class, and creates
00013     the PDF file.
00014 */
00015 class eli_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     
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         $this->page_x = 11;         ///< The width, in inches, of each page
00032         $this->page_y = 17;         ///< The height, in inches, of each page.
00033         $this->units = 'in';        ///< The measurement units (inches)
00034         $this->font = 'Helvetica';  ///< The font we'll use
00035         $this->font_size = 12;      ///< The font size we'll use
00036         $this->orientation = 'L';   ///< The orientation (portrait)
00037         /// These are the sort keys, for sorting the meetings before display
00038         $this->sort_keys = array (  'weekday_tinyint' => true,          ///< First, weekday
00039                                     'location_municipality' => true,    ///< Next, the town.
00040                                     'start_time' => true,               ///< Finally, the time the meeting starts
00041                                     'week_starts' => 2                  ///< Our week starts on Monday (2)
00042                                     );
00043         /// These are the parameters that we send over to the root server, in order to get our meetings.
00044         $this->out_http_vars = array ('do_search' => 'yes',                     ///< Do a search
00045                                     'bmlt_search_type' => 'advanced',           ///< We'll be very specific in our request
00046                                     'advanced_service_bodies' => array (        ///< We will be asking for meetings in specific Service Bodies.
00047                                                                         1001,   ///< SASASC
00048                                                                         1002,   ///< NASC
00049                                                                         1003,   ///< ELIASC
00050                                                                         1004    ///< SSASC
00051                                                                         )
00052                                     );
00053         
00054         parent::__construct ( $in_http_vars );
00055     }
00056     /*************************** INTERFACE FUNCTIONS ***************************/
00057     /********************************************************************
00058         \brief This function actually assembles the PDF. It does not output it.
00059         
00060         \returns a boolean. true if successful.
00061     */
00062     function AssemblePDF ()
00063     {
00064         $ret = false;
00065         
00066         if ( $this->napdf_instance instanceof napdf )
00067             {
00068             $page_margins = 0.35;
00069         
00070             $meeting_data =& $this->napdf_instance->meeting_data;
00071             
00072             if ( $meeting_data )
00073                 {
00074                 // Calculate the overall layout of the list
00075                 
00076                 // The front and back panels are quarter page panels.
00077                 $panelpage['margin'] = $page_margins;
00078                 $panelpage['height'] = $this->napdf_instance->h - ($panelpage['margin'] * 2);
00079                 $panelpage['width'] = ($this->napdf_instance->w / 4) - ($panelpage['margin'] * 2);
00080                 
00081                 // List pages are half page panels.
00082                 $listpage['margin'] = $page_margins;
00083                 $listpage['height'] = $this->napdf_instance->h - ($listpage['margin'] * 2);
00084                 $listpage[width] = ($this->napdf_instance->w / 2) - ($listpage['margin'] * 2);
00085                 
00086                 // These are the actual drawing areas.
00087                 
00088                 // The panel that is up front of the folded list.
00089                 $frontpanel_x_offset = $panelpage['width'] + ($panelpage['margin'] * 3);
00090                 $frontpanel_max_x_offset = $frontpanel_x_offset + $panelpage['width'];
00091                 $frontpanel_y_offset = $panelpage['margin'];
00092                 $frontpanel_max_y_offset = $frontpanel_y_offset + $panelpage['height'];
00093                 
00094                 // The panel that is on the back of the folded list.
00095                 $backpanel_x_offset = $panelpage['margin'];
00096                 $backpanel_max_x_offset = $backpanel_x_offset + $panelpage['width'];
00097                 $backpanel_y_offset = $panelpage['margin'];
00098                 $backpanel_max_y_offset = $backpanel_y_offset + $panelpage['height'];
00099                 
00100                 // Each page is separated by a vertical line.
00101                 $vertical_separator_x = ($this->napdf_instance->w / 2);
00102                 $vertical_separator_y = $page_margins;
00103                 $vertical_separator_y_2 = $this->napdf_instance->h - $page_margins;
00104                 
00105                 // The front page has half dedicated to a single list panel.
00106                 $frontlist_x_offset = $frontpanel_max_x_offset + $panelpage['margin'] + $listpage['margin'];
00107                 $frontlist_max_x_offset = $frontlist_x_offset + $listpage['width'];
00108                 $frontlist_y_offset = $listpage['margin'];
00109                 $frontlist_max_y_offset = $frontlist_y_offset + $listpage['height'];
00110                 
00111                 // The back page has two list panels.
00112                 $backlist_page_1_x_offset = $listpage['margin'];
00113                 $backlist_page_1_max_x_offset = $backlist_page_1_x_offset + $listpage['width'];
00114                 $backlist_page_1_y_offset = $listpage['margin'];
00115                 $backlist_page_1_max_y_offset = $backlist_page_1_y_offset + $listpage['height'];
00116                 
00117                 $backlist_page_2_x_offset = $backlist_page_1_max_x_offset + ($listpage['margin'] * 2);
00118                 $backlist_page_2_max_x_offset = $backlist_page_2_x_offset + $listpage['width'];
00119                 $backlist_page_2_y_offset = $listpage['margin'];
00120                 $backlist_page_2_max_y_offset = $backlist_page_2_y_offset + $listpage['height'];
00121                 
00122                 global $columns, $maxwidth, $fSize, $y;
00123                 $maxwidth = $listpage['width'] + 1;
00124                 $columns = "";
00125                 $fSize = $this->napdf_instance->FontSizePt;
00126                                 
00127                 foreach ( $meeting_data as &$meeting )
00128                     {
00129                     $meeting['location'] = $meeting['location_text'].', '.$meeting['location_street'];
00130                     }
00131                 
00132                 $this->napdf_instance->AddPage ( );
00133                 
00134                 $pos = $this->DrawListPanel ( $backlist_page_1_x_offset, $backlist_page_1_y_offset, $backlist_page_1_max_x_offset, $backlist_page_1_max_y_offset, $meeting_data );
00135                 
00136                 $this->napdf_instance->Line ( $vertical_separator_x, $vertical_separator_y, $vertical_separator_x, $vertical_separator_y_2 );
00137                 
00138                 $pos = $this->DrawListPanel ( $backlist_page_2_x_offset, $backlist_page_2_y_offset, $backlist_page_2_max_x_offset, $backlist_page_2_max_y_offset, $meeting_data, $pos['day'], $pos['count'] );
00139                 
00140                 $this->napdf_instance->AddPage ( );
00141                 $this->DrawRearPanel ( $backpanel_x_offset, $backpanel_y_offset, $backpanel_max_x_offset, $backpanel_max_y_offset, $this->napdf_instance->format_data );
00142 
00143                 $inPrinter_Date = date ( '\U\p\d\a\t\e\d F jS, Y' );
00144 
00145                 $this->DrawFrontPanel ( $frontpanel_x_offset, $frontpanel_y_offset, $frontpanel_max_x_offset, $frontpanel_max_y_offset, $inPrinter_Date );
00146                 
00147                 $this->napdf_instance->Line ( $vertical_separator_x, $vertical_separator_y, $vertical_separator_x, $vertical_separator_y_2 );
00148                 
00149                 if ( $pos )
00150                     {
00151                     $this->DrawListPanel ( $frontlist_x_offset, $frontlist_y_offset, $frontlist_max_x_offset, $frontlist_max_y_offset, $meeting_data, $pos['day'], $pos['count'] );
00152                     }
00153                 else
00154                     {
00155                     $y = $frontlist_y_offset;
00156                     }
00157                 
00158                 $this->DrawLastPageTrailer ( $frontlist_x_offset, $y, $frontlist_max_x_offset, $frontlist_max_y_offset );
00159                 }
00160             $ret = true;
00161             }
00162         
00163         return $ret;
00164     }
00165     
00166     /********************************************************************
00167     */
00168     function OutputPDF ()
00169     {
00170         $d = date ( "Y_m_d" );
00171         $this->napdf_instance->Output( "ELI_PrintableList_$d.pdf", "D" );
00172     }
00173     
00174     /*************************** INTERNAL FUNCTIONS ***************************/
00175     
00176     /********************************************************************
00177     */
00178     private function DrawLastPageTrailer ( $left, $top, $right, $bottom )
00179         {
00180         $y = $top + 0.125;
00181         $fontFamily = $this->napdf_instance->FontFamily;
00182         $fontSize = $this->napdf_instance->FontSizePt;
00183 
00184         $s_array = array();
00185         $na_dom = new DOMDocument;
00186         if ( $na_dom )
00187             {
00188             if ( @$na_dom->loadHTML($this->call_curl ( "http://newyorkna.org/Events_and_Meetings/eli.html" )) )
00189                 {
00190                 $div_contents = $na_dom->getElementByID ( "meeting_times" );
00191                 
00192                 if ( $div_contents )
00193                     {
00194                     $p_list = $div_contents->getElementsByTagName ( "p" );
00195                     if ( $p_list && $p_list->length )
00196                         {
00197                         for ( $i = 0; $i < $p_list->length; $i++ )
00198                             {
00199                             $the_item = $p_list->item($i);
00200                             if ( $the_item )
00201                                 {
00202                                 if ( "first" == $the_item->getAttribute ( "class" ) )
00203                                     {
00204                                     $p_list2 = $the_item->getElementsByTagName ( "b" );
00205                                     $a['_name'] = $p_list2->item(0)->nodeValue;
00206                                     $a['_description'] = '';
00207                                     
00208                                     while ( $p_list->item($i + 1) && ("first" != $p_list->item($i + 1)->getAttribute ( "class" )) )
00209                                         {
00210                                         if ( $a['_description'] )
00211                                             {
00212                                             $a['_description'] .= "\n";
00213                                             }
00214                                         $a['_description'] .= $p_list->item(++$i)->nodeValue;
00215                                         }
00216                                     }
00217                                 
00218                                 array_push ( $s_array, $a );
00219                                 }
00220                             }
00221                         }
00222                     }
00223                 }
00224             }
00225 
00226         $this->napdf_instance->Line ( $left, $y, $right, $y );
00227         
00228         $this->napdf_instance->SetXY ( $left, $y );
00229         $this->napdf_instance->SetFont ( $fontFamily, 'B', ($fontSize - 3) );
00230         $this->napdf_instance->SetLeftMargin ( $left );
00231         
00232         $y = $this->napdf_instance->GetY ( );
00233         
00234         $y += 0.125;
00235         
00236         $this->napdf_instance->SetFont ( $fontFamily, 'B', ($fontSize - 3) );
00237         $stringWidth = $this->napdf_instance->GetStringWidth ( _PDF_SASNA_LIST_ELI_SUBCOMMITTEES );
00238         
00239         $cellleft = (($right + $left) / 2) - ($stringWidth / 2);
00240         
00241         $this->napdf_instance->SetXY ( $cellleft, $y );
00242 
00243         $this->napdf_instance->Cell ( 0, 0, _PDF_SASNA_LIST_ELI_SUBCOMMITTEES );
00244 
00245         $y += 0.25;
00246 
00247         if ( is_array ( $s_array ) && count ( $s_array ) )
00248             {
00249             $this->napdf_instance->SetFont ( $fontFamily, 'B', ($fontSize - 4) );
00250         
00251             $count = 0;
00252             $offset = 0;
00253             foreach ( $s_array as $row )
00254                 {
00255                 $offset = max ( $offset, ($this->napdf_instance->GetStringWidth ( $row['_name'] ) + 0.1) );
00256                 $sub_table[$count++] = $row;
00257                 }
00258                 
00259             for ( $c = 0; $c < $count; $c++ )
00260                 {
00261                 $this->napdf_instance->SetFont ( $fontFamily, 'B', ($fontSize - 4) );
00262                 $this->napdf_instance->SetLeftMargin ( $left );
00263                 $this->napdf_instance->SetXY ( $left, $y );
00264                 $this->napdf_instance->MultiCell ( $offset, ($fontSize - 4) / 72, $sub_table[$c]['_name'] );
00265                 $this->napdf_instance->SetFont ( $fontFamily, '', ($fontSize - 4) );
00266                 $this->napdf_instance->SetLeftMargin ( $left + $offset );
00267                 $this->napdf_instance->SetXY ( $left + $offset, $y );
00268                 $this->napdf_instance->MultiCell ( ($right - ($left + $offset)), ($fontSize - 4) / 72, $sub_table[$c]['_description'] );
00269                 $y = $this->napdf_instance->GetY ( ) + 0.1;
00270                 }
00271             }
00272         
00273         $y += 0.05;
00274         
00275         $this->napdf_instance->Line ( $left, $y, $right, $y );
00276 
00277         $y += 0.15;
00278         $this->napdf_instance->SetFont ( $fontFamily, 'B', ($fontSize - 2) );
00279         $this->napdf_instance->SetLeftMargin ( $left );
00280         $this->napdf_instance->SetXY ( $left, $y );
00281         $this->napdf_instance->MultiCell ( 0, ($fontSize - 2) / 72, _PDF_SASNA_LIST_WHATIS_HEADER );
00282         $y = $this->napdf_instance->GetY ( ) + 0.05;
00283         $this->napdf_instance->SetFont ( $fontFamily, 'I', ($fontSize - 2) );
00284         $this->napdf_instance->SetXY ( $left, $y );
00285         $this->napdf_instance->MultiCell ( 0, ($fontSize - 2) / 72, _PDF_SASNA_LIST_WHATIS_TEXT );
00286 
00287         $y = $this->napdf_instance->GetY ( ) + 0.15;
00288         $this->napdf_instance->SetFont ( $fontFamily, 'B', ($fontSize - 2) );
00289         $this->napdf_instance->SetLeftMargin ( $left );
00290         $this->napdf_instance->SetXY ( $left, $y );
00291         $this->napdf_instance->MultiCell ( 0, ($fontSize - 2) / 72, _PDF_SASNA_LIST_WDR_HEADER );
00292         $y = $this->napdf_instance->GetY ( ) + 0.05;
00293         $this->napdf_instance->SetFont ( $fontFamily, 'I', ($fontSize - 2) );
00294         $this->napdf_instance->SetXY ( $left, $y );
00295         $this->napdf_instance->MultiCell ( 0, ($fontSize - 2) / 72, _PDF_SASNA_LIST_WDR_TEXT );
00296         }
00297     
00298     /********************************************************************
00299     */
00300     private function DrawListPanel ( $left, $top, $right, $bottom, $meetings, $day = -1, $count = 0 )
00301         {
00302         $meetings_days = self::break_meetings_by_day ( $meetings );
00303         global $columns, $maxwidth, $fSize, $y;
00304         
00305         $pos['day'] = $day;
00306         $pos['count'] = $count;
00307 
00308         $y = $top + 0.125;
00309 
00310         $last_line = 0;
00311         $daygap = 0.2;
00312         $sep = 0.05;
00313         
00314         if ( $day == -1 )
00315             {
00316             $fSize = $this->font_size + 2;
00317         
00318             $columns['day'] = 0;
00319             $columns['town'] = 0;
00320             $columns['name'] = 0;
00321             $columns['location'] = 0;
00322             $columns['time'] = 0;
00323             $columns['duration'] = 0;
00324             $columns['format'] =  0;
00325             
00326             while ( ($maxwidth > ($right - $left)) && ($fSize > 0) )
00327                 {
00328                 $fSize -= 0.1;
00329                 $this->napdf_instance->SetFont ( $this->font, 'B', $fSize );
00330             
00331                 $columns['day'] = $daygap;
00332                 $columns['town'] = $this->napdf_instance->GetStringWidth ( _PDF_SASNA_LIST_HEADER_TOWN ) + $sep;
00333                 $columns['name'] =  $this->napdf_instance->GetStringWidth ( _PDF_SASNA_LIST_HEADER_NAME ) + $sep;
00334                 $columns['location'] =  $this->napdf_instance->GetStringWidth ( _PDF_SASNA_LIST_HEADER_LOCATION ) + $sep;
00335                 $columns['time'] =  $this->napdf_instance->GetStringWidth ( _PDF_SASNA_LIST_HEADER_TIME ) + $sep;
00336                 $columns['format'] =  $this->napdf_instance->GetStringWidth ( _PDF_SASNA_LIST_HEADER_FORMAT );
00337                 
00338                 $this->napdf_instance->SetFont ( $this->font, '', $fSize );
00339     
00340                 foreach ( $meetings as $meeting )
00341                     {
00342                     $columns['town'] = max ( $columns['town'], ($this->napdf_instance->GetStringWidth ( $meeting['location_municipality'] ) + $sep) );
00343                     $columns['name'] = max ( $columns['name'], ($this->napdf_instance->GetStringWidth ( $meeting['meeting_name'] ) + $sep) );
00344                     $columns['location'] = max ( $columns['location'], ($this->napdf_instance->GetStringWidth ( $meeting['location'] ) + $sep) );
00345                     $columns['time'] = max ( $columns['time'], ($this->napdf_instance->GetStringWidth ( $this->translate_time ( $meeting['start_time'] ) ) + $sep) );
00346                     $columns['format'] = max ( $columns['format'], $this->napdf_instance->GetStringWidth ( $this->RearrangeFormats ( $meeting['formats'] ) ) );
00347                     }
00348                 
00349                 $line_height = $fSize / 72;
00350                 $duration_width = $line_height;
00351                 $duration_gap = $duration_width / 8;
00352                 $columns['duration'] =  ($duration_width * 2) + ($duration_gap * 2);
00353         
00354                 $maxwidth = ($columns['day'] + $columns['town'] + $columns['name'] + $columns['location'] + $columns['time'] + $columns['duration'] + $columns['format']);
00355                 }
00356             }
00357         
00358         $line_height = $fSize / 72;
00359         $duration_width = $line_height;
00360         $duration_gap = $duration_width / 8;
00361         $columns['duration'] =  ($duration_width * 2) + ($duration_gap * 2);
00362         
00363         $this->napdf_instance->SetFont ( $this->font, 'B', $fSize );
00364         $x = $left + $daygap;
00365         
00366         $this->napdf_instance->SetXY ( $x, $y );
00367         $this->napdf_instance->Cell ( 0, 0, _PDF_SASNA_LIST_HEADER_TOWN );
00368 
00369         $x += ($columns['town']);
00370         $this->napdf_instance->SetX ( $x );
00371         $this->napdf_instance->Cell ( 0, 0, _PDF_SASNA_LIST_HEADER_NAME );
00372         $x += ($columns['name']);
00373         $this->napdf_instance->SetX ( $x );
00374         $this->napdf_instance->Cell ( 0, 0, _PDF_SASNA_LIST_HEADER_LOCATION );
00375         $x += ($columns['location']);
00376         $this->napdf_instance->SetX ( $x );
00377         $this->napdf_instance->Cell ( 0, 0, _PDF_SASNA_LIST_HEADER_TIME );
00378         $x += ($columns['time']+$columns['duration']);
00379         $this->napdf_instance->SetX ( $x );
00380         $this->napdf_instance->Cell ( 0, 0, _PDF_SASNA_LIST_HEADER_FORMAT );
00381         
00382         $this->napdf_instance->SetFont ( $this->font, '', $fSize );
00383         $y += $line_height;
00384         
00385         if ( $pos['day'] == -1 )
00386             {
00387             $pos['day'] = 1;
00388             }
00389             
00390         for ( ; $pos['day'] < 7; $pos['day']++ )
00391             {
00392             $grayLine = 0;
00393             $day_name = $this->weekday_names[$pos['day']];
00394         
00395             $slen = strlen ( $day_name );
00396             
00397             $ya = $y + $line_height + 0.125;
00398             
00399             if ( (max($ya, ($slen * 0.125))) >= $bottom )
00400                 {
00401                 break;
00402                 }
00403             
00404             $this->napdf_instance->Line ( $left, $y, $right, $y );
00405             $y += $line_height;
00406             $x = $left + 0.1;
00407             
00408             $this->napdf_instance->SetFont ( $this->font, '', $fSize );
00409             
00410             $meetings_day = $meetings_days[$pos['day']];
00411             $count = count ( $meetings_day );
00412             for ( ; $pos['count'] < $count; $pos['count']++ )
00413                 {
00414                 $x = $left + $daygap;
00415 
00416                 if ( $grayLine == 1 )
00417                     {
00418                     $this->napdf_instance->SetFillColor ( 220 );
00419                     $this->napdf_instance->Rect ( $left + $daygap, $y - ($fSize / 144), $right - ($left + $daygap), $fSize / 72, 'F' );
00420                     $grayLine = 0;
00421                     }
00422                 else
00423                     {
00424                     $grayLine = 1;
00425                     }
00426                 
00427                 $this->napdf_instance->SetXY ( $x, $y );
00428                 $this->napdf_instance->Cell ( $columns['town'], 0, $meetings_day[$pos['count']]['location_municipality'] );
00429                 $x += $columns['town'];
00430                 $this->napdf_instance->SetX ( $x );
00431                 $this->napdf_instance->Cell ( $columns['name'], 0, $meetings_day[$pos['count']]['meeting_name'] );
00432                 $x += $columns['name'];
00433                 $this->napdf_instance->SetX ( $x );
00434                 $this->napdf_instance->Cell ( $columns['location'], 0, $meetings_day[$pos['count']]['location'] );
00435                 $x += $columns['location'];
00436                 $this->napdf_instance->SetX ( $x );
00437                 $this->napdf_instance->Cell ( $columns['time'], 0, $this->translate_time ( $meetings_day[$pos['count']]['start_time'] ), 0, 0, 'R' );
00438                 $x += $columns['time'];
00439                 $this->napdf_instance->SetX ( $x );
00440 
00441                 if ( $meetings_day[$pos['count']]['duration_time'] == "00:00:00" )
00442                     {
00443                     $meetings_day[$pos['count']]['duration_time'] = "01:30:00";
00444                     }
00445                 
00446                 $base_dir = "images/";
00447                 $duration = split ( ":", $meetings_day[$pos['count']]['duration_time'] );
00448                 
00449                 $duration[0] = intval ( $duration[0] );
00450                 $duration[1] = intval ( $duration[1] );
00451                 
00452                 $ClockGraphic1 = "";
00453                 $ClockGraphic2 = "";
00454 
00455                 if ( $duration[0] > 0 )
00456                     {
00457                     $ClockGraphic1 = "C_60";
00458                     if ( $duration[0] > 1 )
00459                         {
00460                         $ClockGraphic2 = "C_60";
00461                         }
00462                     }
00463                 
00464                 if ( !$ClockGraphic2 )
00465                     {
00466                     if ( $duration[1] > 45 )
00467                         {
00468                         $ClockGraphic2 = "C_60";
00469                         }
00470                     elseif ( $duration[1] > 30 )
00471                         {
00472                         $ClockGraphic2 = "C_45";
00473                         }
00474                     elseif ( $duration[1] > 15 )
00475                         {
00476                         $ClockGraphic2 = "C_30";
00477                         }
00478                     elseif ( $duration[1] > 0 )
00479                         {
00480                         $ClockGraphic2 = "C_15";
00481                         }
00482                     }
00483                 
00484                 if ( $ClockGraphic1 )
00485                     {
00486                     $this->napdf_instance->Image ( "$base_dir$ClockGraphic1.png", $x, $y-($duration_width/2), $duration_width, 0, 'PNG' );
00487                     }
00488                 
00489                 $x += $duration_width + $duration_gap;
00490                 
00491                 if ( $ClockGraphic2 )
00492                     {
00493                     $this->napdf_instance->Image ( "$base_dir$ClockGraphic2.png", $x, $y-($duration_width/2), $duration_width, 0, 'PNG' );
00494                     }
00495                 
00496                 $x += $duration_width + $duration_gap;
00497 
00498                 $this->napdf_instance->SetXY ( $x, $y );
00499                 $this->napdf_instance->Cell ( $columns['format'], 0, $this->RearrangeFormats ( $meetings_day[$pos['count']]['formats'] ) );
00500                 $y += $line_height;
00501                 
00502                 if ( ($y + $line_height) >= $bottom )
00503                     {
00504                     $pos['count']++;
00505                     break;
00506                     }
00507                 }
00508             
00509             $this->napdf_instance->SetFont ( $this->font, 'B', 14 );
00510 
00511             for ( $a = 0; $a < $slen; $a++ )
00512                 {
00513                 $letter = $day_name[$a];
00514                 $this->napdf_instance->SetXY ( $left, $ya );
00515                 $this->napdf_instance->Cell ( $daygap, 0, $letter, 0, 0, 'C' );
00516                 $ya += 0.2;
00517                 
00518                 if ( ($ya + 0.125) >= $y )
00519                     {
00520                     break;
00521                     }
00522                 }
00523 
00524             if ( ($pos['count'] < ($count - 1)) && (($y + $line_height) >= $bottom) )
00525                 {
00526                 break;
00527                 }
00528             
00529             $pos['count'] = 0;
00530 
00531             if ( $pos['day'] == 0 )
00532                 {
00533                 $pos = "";
00534                 break;
00535                 }
00536             
00537             if ( $pos['day'] == 6 )
00538                 {
00539                 $pos['day'] = -1;
00540                 }
00541             
00542             $next_day = $pos['day'] + 1;
00543             
00544             $next_day_count = count ( $meetings_days[$next_day] );
00545             $next_day_y = ($next_day_count * $line_height);
00546             $next_day_slen = strlen ( $this->weekday_names[$next_day_count] );
00547             $next_day_y = max ( $next_day_y, ($next_day_slen * 0.125) );
00548             if ( ($y + $next_day_y) >= $bottom )
00549                 {
00550                 $pos['day']++;
00551                 break;
00552                 }
00553             }
00554         return $pos;
00555         }
00556     
00557     /********************************************************************
00558     */
00559     private function DrawRearPanel ( $left, $top, $right, $bottom, $formats )
00560         {
00561         $y = $top + 0.125;
00562 
00563         $fontSize = $this->font_size;
00564 
00565     //  $this->napdf_instance->Rect ( $left, $top, ($right - $left), ($bottom - $top) );
00566         
00567         $this->napdf_instance->SetFont ( $this->font, 'B', ($fontSize - 3) );
00568         $stringWidth = $this->napdf_instance->GetStringWidth ( _PDF_SASNA_LIST_FORMAT_KEY );
00569         $cellleft = (($right + $left) / 2) - ($stringWidth / 2);
00570         
00571         $this->napdf_instance->SetXY ( $cellleft, $y );
00572 
00573         $this->napdf_instance->Cell ( 0, 0, _PDF_SASNA_LIST_FORMAT_KEY );
00574         $y += 0.125;
00575         
00576         $count = count ( $formats );
00577         $w1 = $left + 0.25;
00578         $fSize = $fontSize - 4;
00579         
00580         $this->napdf_instance->SetY ( $y );
00581 
00582         foreach ( $formats as $format )
00583             {
00584             $this->napdf_instance->SetFont ( $this->font, 'B', $fSize );
00585             $this->napdf_instance->SetLeftMargin ( $left );
00586             $str = $format['key_string'];
00587             $this->napdf_instance->SetX ( $left );
00588             $this->napdf_instance->Cell ( 0, 0.13, $str );
00589             $this->napdf_instance->SetFont ( $this->font, '', $fSize );
00590             $str = $format['description_string'];
00591             $this->napdf_instance->SetLeftMargin ( $w1 );
00592             $this->napdf_instance->SetX ( $w1 );
00593             $this->napdf_instance->MultiCell ( ($right - $w1), 0.13, $str );
00594             $this->napdf_instance->SetY ( $this->napdf_instance->GetY ( ) + 0.01 );
00595             }
00596         
00597         $y = $this->napdf_instance->GetY ( ) + 0.1;
00598                 
00599         $base_dir = "images/";
00600         
00601         $ClockGraphic1 = "C_15";
00602         $ClockGraphic2 = "C_30";
00603         $ClockGraphic3 = "C_45";
00604         $ClockGraphic4 = "C_60";
00605         
00606         $duration_width = 0.12;
00607         $duration_gap = $duration_width / 4;
00608 
00609         $x = $left;
00610         $this->napdf_instance->SetLeftMargin ( $x );
00611         $this->napdf_instance->SetXY ( $x, $y );
00612         $str = _PDF_SASNA_LIST_DUR_INTRO." ";
00613         $l = $this->napdf_instance->GetStringWidth ( $str );
00614         $this->napdf_instance->Cell ( $l, 0.13, $str );
00615         $x += $l + $duration_gap;
00616         
00617         $this->napdf_instance->Image ( "$base_dir$ClockGraphic1.png", $x, $y, $duration_width, 0, 'PNG' );
00618         $x += $duration_width + $duration_gap;
00619         $str = _PDF_SASNA_LIST_DUR_15.", ";
00620         $l = $this->napdf_instance->GetStringWidth ( $str );
00621         $this->napdf_instance->SetX ( $x );
00622         $this->napdf_instance->Cell ( $l, 0.13, $str );
00623         $x += $l + $duration_gap;
00624         
00625         $this->napdf_instance->Image ( "$base_dir$ClockGraphic2.png", $x, $y, $duration_width, 0, 'PNG' );
00626         $x += $duration_width + $duration_gap;
00627         $str = _PDF_SASNA_LIST_DUR_30.", ";
00628         $l = $this->napdf_instance->GetStringWidth ( $str );
00629         $this->napdf_instance->SetX ( $x );
00630         $this->napdf_instance->Cell ( $l, 0.13, $str );
00631         $x += $l + $duration_gap;
00632         
00633         $this->napdf_instance->Image ( "$base_dir$ClockGraphic3.png", $x, $y, $duration_width, 0, 'PNG' );
00634         $x += $duration_width + $duration_gap;
00635         $str = _PDF_SASNA_LIST_DUR_45.", ";
00636         $l = $this->napdf_instance->GetStringWidth ( $str );
00637         $this->napdf_instance->SetX ( $x );
00638         $this->napdf_instance->Cell ( $l, 0.13, $str );
00639         $x += $l + $duration_gap;
00640         
00641         $this->napdf_instance->Image ( "$base_dir$ClockGraphic4.png", $x, $y, $duration_width, 0, 'PNG' );
00642         $x += $duration_width + $duration_gap;
00643         $str = _PDF_SASNA_LIST_DUR_60;
00644         $l = $this->napdf_instance->GetStringWidth ( $str );
00645         $this->napdf_instance->SetX ( $x );
00646         $this->napdf_instance->Cell ( $l, 0.13, $str );
00647         
00648         $y = $this->napdf_instance->GetY ( ) + 0.25;
00649         
00650         $this->napdf_instance->SetFont ( $this->font, 'B', ($fontSize + 1) );
00651         $this->napdf_instance->SetXY ( $left + 0.2, $y );
00652         $this->napdf_instance->MultiCell ( ($right - $left), (($fontSize + 1) / 72), _PDF_SASNA_LIST_MAILING_ELI );
00653         
00654         $y = $this->napdf_instance->GetY ( ) + 0.05;
00655         $this->napdf_instance->SetFont ( $this->font, 'B', ($fontSize - 1) );
00656 
00657         $this->napdf_instance->SetXY ( $left + 0.3, $y );
00658         $this->napdf_instance->MultiCell ( ($right - $left), (($fontSize + 1) / 72), _PDF_SASNA_LIST_ELI );
00659         
00660         $y = $this->napdf_instance->GetY ( ) + 0.03;
00661         $this->napdf_instance->SetFont ( $this->font, '', $fontSize - 1 );
00662 
00663         $this->napdf_instance->SetXY ( $left + 0.3, $y );
00664         $this->napdf_instance->MultiCell ( ($right - $left), (($fontSize - 1) / 72), _PDF_SASNA_LIST_PO_ELI );
00665         
00666         $y = $this->napdf_instance->GetY ( ) + 0.03;
00667         $this->napdf_instance->SetFont ( $this->font, '', $fontSize - 1 );
00668 
00669         $this->napdf_instance->SetXY ( $left + 0.3, $y );
00670         $this->napdf_instance->MultiCell ( ($right - $left), (($fontSize - 1) / 72), _PDF_SASNA_LIST_TOWN_ELI );
00671         
00672         $this->napdf_instance->SetFont ( $this->font, '', $fontSize );
00673         }
00674     
00675     /********************************************************************
00676     */
00677     private function DrawFrontPanel ( $left, $top, $right, $bottom, $date )
00678         {
00679         $inTitleGraphic = "../ny_printed_lists/images/ELI_Cover_Logo.png";
00680         
00681         $y = $top + 0.125;
00682 
00683         $fontSize = $this->font_size;
00684         
00685         $this->napdf_instance->SetFont ( $this->font, 'B', ($fontSize - 4) );
00686         
00687         $stringWidth = $this->napdf_instance->GetStringWidth ( $date );
00688         
00689         $cellleft = (($right + $left) / 2) - ($stringWidth / 2);
00690         
00691         $this->napdf_instance->SetXY ( $cellleft, $y );
00692 
00693         $this->napdf_instance->Cell ( 0, 0, $date );
00694         $y += 0.2;
00695 
00696         $this->napdf_instance->SetFont ( $this->font, 'B', ($fontSize + 4) );
00697         $stringWidth = $this->napdf_instance->GetStringWidth ( _PDF_SASNA_LIST_BANNER );
00698         $cellleft = (($right + $left) / 2) - ($stringWidth / 2);
00699         
00700         $this->napdf_instance->SetXY ( $cellleft, $y );
00701 
00702         $this->napdf_instance->Cell ( 0, 0, _PDF_SASNA_LIST_BANNER );
00703         $y += 0.21;
00704         
00705         $this->napdf_instance->SetFont ( $this->font, 'B', ($fontSize - 4) );
00706         $stringWidth = $this->napdf_instance->GetStringWidth ( _PDF_SASNA_LIST_BANNER_2 );
00707         $cellleft = (($right + $left) / 2) - ($stringWidth / 2);
00708         
00709         $this->napdf_instance->SetXY ( $cellleft, $y );
00710 
00711         $this->napdf_instance->Cell ( 0, 0, _PDF_SASNA_LIST_BANNER_2 );
00712         $y += 0.15;
00713         
00714         $this->napdf_instance->SetFont ( $this->font, 'B', ($fontSize + 1) );
00715         $stringWidth = $this->napdf_instance->GetStringWidth ( _PDF_SASNA_LIST_BANNER_3 );
00716         $cellleft = (($right + $left) / 2) - ($stringWidth / 2);
00717         
00718         $this->napdf_instance->SetXY ( $cellleft, $y );
00719         $this->napdf_instance->Cell ( 0, 0, _PDF_SASNA_LIST_BANNER_3 );
00720 
00721         $y += 0.2;
00722         
00723         $this->napdf_instance->SetFont ( $fontFamily, 'I', $fontSize );
00724         $stringWidth = $this->napdf_instance->GetStringWidth ( _PDF_SASNA_LIST_BANNER_4 );
00725         $cellleft = (($right + $left) / 2) - ($stringWidth / 2);
00726         
00727         $this->napdf_instance->SetXY ( $cellleft, $y );
00728         $this->napdf_instance->Cell ( 0, 0, _PDF_SASNA_LIST_BANNER_4 );
00729         
00730         $this->napdf_instance->Image ( $inTitleGraphic, ($left + .85), 1.45, (($right - $left) - 1.7), 0, 'PNG' );
00731         $this->napdf_instance->SetFont ( $fontFamily, 'B', ($fontSize + 1) );
00732         $y = 3.5;
00733 
00734         $cellleft = $left + 0.6;
00735 
00736         $this->napdf_instance->SetXY ( $cellleft, $y );
00737         $this->napdf_instance->Cell ( 0, 0, _PDF_SASNA_LIST_HELPLINES );
00738         $y += 0.2;
00739 
00740         $this->napdf_instance->SetFont ( $this->font, '', ($fontSize - 2) );
00741         
00742         $this->napdf_instance->SetXY ( $cellleft, $y );
00743         $this->napdf_instance->Cell ( 0, 0, _PDF_SASNA_LIST_HELPLINE_ELI );
00744 
00745         $y += 0.16;
00746 
00747         $this->napdf_instance->SetFont ( $this->font, '', ($fontSize - 2) );
00748         
00749         $this->napdf_instance->SetXY ( $cellleft, $y );
00750         $this->napdf_instance->Cell ( 0, 0, _PDF_SASNA_LIST_HELPLINE_NASSAU );
00751         $y += 0.16;
00752 
00753         $this->napdf_instance->SetXY ( $cellleft, $y );
00754 
00755         $this->napdf_instance->Cell ( 0, 0, _PDF_SASNA_LIST_HELPLINE_QUEENS );
00756 
00757         $y += 0.25;
00758 
00759         $this->napdf_instance->SetFont ( $this->font, 'B', ($fontSize + 1) );
00760 
00761         $cellleft = $left;
00762         $this->napdf_instance->SetXY ( $cellleft, $y );
00763         $st_width = $this->napdf_instance->GetStringWidth ( _PDF_SASNA_LIST_WELCOME );
00764         $this->napdf_instance->Cell ( 0, 0, _PDF_SASNA_LIST_WELCOME );
00765         $y += 0.125;
00766         
00767         $this->napdf_instance->SetFont ( $this->font, '', $fontSize );
00768 
00769         $this->napdf_instance->SetLineWidth ( 0.02 );
00770         $this->napdf_instance->Line ( ($st_width + $left) + 0.0625, $y, $right, $y );
00771         
00772         while ( $y < ($bottom - 0.3) )
00773             {
00774             $y += 0.3;
00775             $this->napdf_instance->Line ( $left + 0.0625, $y, $right, $y );
00776             }
00777         }
00778 
00779     /********************************************************************
00780     */
00781     private function RearrangeFormats ( $inFormats )
00782     {
00783     $inFormats = split ( ",", $inFormats );
00784     
00785     if ( !in_array ( "C", $inFormats ) && !in_array ( "O", $inFormats ) )
00786         {
00787         array_push ( $inFormats, "C" );
00788         }
00789     
00790     if ( !$ignore_bk && !in_array ( "BK", $inFormats ) && ((in_array ( "BT", $inFormats ) || in_array ( "IW", $inFormats ) || in_array ( "JT", $inFormats ) || in_array ( "SG", $inFormats ))) )
00791         {
00792         array_push ( $inFormats, "BK" );
00793         }
00794     
00795     usort ( $inFormats, 'eli_napdf::sort_cmp' );
00796     
00797     $tFormats = $inFormats;
00798     
00799     $inFormats = array();
00800     
00801     foreach ( $tFormats as $format )
00802         {
00803         $format = trim ( $format );
00804         if ( $format )
00805             {
00806             array_push ( $inFormats, $format );
00807             }
00808         }
00809     
00810     return join ( ",", $inFormats );
00811     }
00812 
00813     /********************************************************************
00814     */
00815     private static function break_meetings_by_day ( $in_meetings_array ) 
00816     {
00817         $last_day = -1;
00818         $meetings_day = array();
00819         
00820         foreach ( $in_meetings_array as $meeting )
00821             {
00822             if ( $meeting['weekday_tinyint'] != $last_day )
00823                 {
00824                 $last_day = $meeting['weekday_tinyint'] -1;
00825                 }
00826             
00827             $meetings_day[$last_day][] = $meeting;
00828             }
00829         
00830         return $meetings_day;
00831     }
00832 
00833     /********************************************************************
00834     */
00835     private static function sort_cmp ($a, $b) 
00836     {
00837     $order_array = array(   0=>"O", 1=>"C",
00838                             2=>"ES", 3=>"B", 4=>"M", 5=>"W", 6=>"GL", 7=>"YP", 8=>"BK", 9=>"IP", 10=>"Pi", 11=>"RF", 12=>"Rr",
00839                             13=>"So", 14=>"St", 15=>"To", 16=>"Tr", 17=>"OE", 18=>"D", 19=>"SD", 20=>"TW", 21=>"IL",
00840                             22=>"BL", 23=>"IW", 24=>"BT", 25=>"SG", 26=>"JT",
00841                             27=>"Ti", 28=>"Sm", 29=>"NS", 30=>"CL", 31=>"CS", 32=>"NC", 33=>"SC", 34=>"CH", 35=>"SL", 36=>"WC" );
00842     
00843     if ( in_array ( $a, $order_array ) || in_array ( $b, $order_array ) )
00844         {
00845         return (array_search ( $a, $order_array ) < array_search ( $b, $order_array )) ? -1 : 1;
00846         }
00847     else
00848         {
00849         return 0;
00850         }
00851     }
00852 
00853     /********************************************************************
00854     */
00855     private static function translate_time ( $in_time_string ) 
00856     {
00857         $split = split ( ":", $in_time_string );
00858         if ( $in_time_string == "12:00:00" )
00859             {
00860             return "Noon";
00861             }
00862         elseif ( ($split[0] == "23") && (intval ( $split[1] ) > 45) )
00863             {
00864             return "Midnight";
00865             }
00866         else
00867             {
00868             return date ( "g:i A", strtotime ( $in_time_string ) );
00869             }
00870     }
00871 
00872     /********************************************************************
00873     */
00874     private static function translate_duration ( $in_time_string ) 
00875     {
00876         $t = split ( ":", $in_time_string );
00877         $hours = intval ( $t[0] );
00878         $minutes = intval ( $t[1] );
00879         
00880         $ret = '';
00881         
00882         if ( $hours )
00883             {
00884             $ret .= "$hours hour";
00885             
00886             if ( $hours > 1 )
00887                 {
00888                 $ret .= "s";
00889                 }
00890                 
00891             if ( $minutes )
00892                 {
00893                 $ret .= " and ";
00894                 }
00895             }
00896         
00897         if ( $minutes )
00898             {
00899             $ret .= "$minutes minutes";
00900             }
00901         
00902         return $ret;
00903     }
00904 
00905     /********************************************************************
00906         \brief This is a function that returns the results of an HTTP call to a URI.
00907         It is a lot more secure than file_get_contents, but does the same thing.
00908         
00909         \returns a string, containing the response. Null if the call fails to get any data.
00910         
00911         \throws an exception if the call fails.
00912     */
00913     private static function call_curl ( $in_uri,                ///< A string. The URI to call.
00914                                         $in_post = true,        ///< If false, the transaction is a GET, not a POST. Default is true.
00915                                         &$http_status = null    ///< Optional reference to a string. Returns the HTTP call status.
00916                                         )
00917     {
00918     $ret = null;
00919     
00920     // If the curl extension isn't loaded, we try one backdoor thing. Maybe we can use file_get_contents.
00921     if ( !extension_loaded ( 'curl' ) )
00922         {
00923         if ( ini_get ( 'allow_url_fopen' ) )
00924             {
00925             $ret = file_get_contents ( $in_uri );
00926             }
00927         }
00928     else
00929         {
00930         // Create a new cURL resource.
00931         $resource = curl_init();
00932         
00933         // If we will be POSTing this transaction, we split up the URI.
00934         if ( $in_post )
00935             {
00936             $spli = explode ( "?", $in_uri, 2 );
00937             
00938             if ( is_array ( $spli ) && count ( $spli ) )
00939                 {
00940                 $in_uri = $spli[0];
00941                 $in_params = $spli[1];
00942             
00943                 curl_setopt ( $resource, CURLOPT_POST, true );
00944                 curl_setopt ( $resource, CURLOPT_POSTFIELDS, $in_params );
00945                 }
00946             }
00947         
00948         // Set url to call.
00949         curl_setopt ( $resource, CURLOPT_URL, $in_uri );
00950         
00951         // Make curl_exec() function (see below) return requested content as a string (unless call fails).
00952         curl_setopt ( $resource, CURLOPT_RETURNTRANSFER, true );
00953         
00954         // By default, cURL prepends response headers to string returned from call to curl_exec().
00955         // You can control this with the below setting.
00956         // Setting it to false will remove headers from beginning of string.
00957         // If you WANT the headers, see the Yahoo documentation on how to parse with them from the string.
00958         curl_setopt ( $resource, CURLOPT_HEADER, false );
00959         
00960         // Allow  cURL to follow any 'location:' headers (redirection) sent by server (if needed set to true, else false- defaults to false anyway).
00961         // Disabled, because some servers disable this for security reasons.
00962 //      curl_setopt ( $resource, CURLOPT_FOLLOWLOCATION, true );
00963         
00964         // Set maximum times to allow redirection (use only if needed as per above setting. 3 is sort of arbitrary here).
00965         curl_setopt ( $resource, CURLOPT_MAXREDIRS, 3 );
00966         
00967         // Set connection timeout in seconds (very good idea).
00968         curl_setopt ( $resource, CURLOPT_CONNECTTIMEOUT, 10 );
00969         
00970         // Direct cURL to send request header to server allowing compressed content to be returned and decompressed automatically (use only if needed).
00971         curl_setopt ( $resource, CURLOPT_ENCODING, 'gzip,deflate' );
00972         
00973         // Execute cURL call and return results in $content variable.
00974         $content = curl_exec ( $resource );
00975         
00976         // Check if curl_exec() call failed (returns false on failure) and handle failure.
00977         if ( $content === false )
00978             {
00979             // Cram as much info into the exception as possible.
00980             throw new Exception ( "curl failure calling $in_uri, ".curl_error ( $resource ).", ".curl_errno ( $resource ) );
00981             }
00982         else
00983             {
00984             // Do what you want with returned content (e.g. HTML, XML, etc) here or AFTER curl_close() call below as it is stored in the $content variable.
00985         
00986             // You MIGHT want to get the HTTP status code returned by server (e.g. 200, 400, 500).
00987             // If that is the case then this is how to do it.
00988             $http_status = curl_getinfo ($resource, CURLINFO_HTTP_CODE );
00989             }
00990         
00991         // Close cURL and free resource.
00992         curl_close ( $resource );
00993         
00994         // Maybe echo $contents of $content variable here.
00995         if ( $content !== false )
00996             {
00997             $ret = $content;
00998             }
00999         }
01000     
01001     return $ret;
01002     }
01003 };
01004 ?>
 All Data Structures Files Functions Variables Enumerations