Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008 require_once ( dirname ( __FILE__ ).'/fpdf16/fpdf.php' );
00009 require_once ( dirname ( __FILE__ ).'/../standalone/BMLT_Satellite.class.php' );
00010
00011
00012
00013
00014
00015
00016
00017 class napdf extends FPDF
00018 {
00019 static $fpdf_instance = null;
00020 static $sort_order_keys = null;
00021 static $week_starts = 1;
00022 static $sort_callback = 'napdf::sort_meeting_data_callback';
00023
00024 var $bmlt_instance = null;
00025 var $meeting_data = null;
00026 var $format_data = null;
00027 var $lang_search = array ( 'en' );
00028
00029
00030
00031
00032
00033
00034
00035 private function FetchCSV ( $in_http_vars = null
00036 )
00037 {
00038 if ( $this->bmlt_instance instanceof BMLT_Satellite )
00039 {
00040
00041 $format_data = $this->bmlt_instance->Execute ( 'csv_formats', array ( 'lang_enum' => $this->lang_search ) );
00042 if ( $format_data )
00043 {
00044 $format_data_ar = explode ( "\n", $format_data );
00045
00046 if ( is_array ( $format_data_ar ) && (count ( $format_data_ar ) > 1) )
00047 {
00048 $this->format_data = array();
00049
00050 $keys = explode ( '","', $format_data_ar[0] );
00051
00052 for ( $c = 0; $c < count ( $keys ); $c++ )
00053 {
00054 $keys[$c] = stripslashes ( preg_replace ( '/^\"|\"$/', '', $keys[$c] ) );
00055 }
00056
00057 $format_data_ar[0] = null;
00058 unset ( $format_data_ar[0] );
00059
00060 foreach ( $format_data_ar as $format )
00061 {
00062 $format = explode ( '","', $format );
00063 if ( is_array ( $format ) && (count ( $format ) == count ( $keys )) )
00064 {
00065 $fmt = array ();
00066 $count = 0;
00067 foreach ( $keys as $key )
00068 {
00069 $fmt[$key] = stripslashes ( preg_replace ( '/^\"|\"$/', '', $format[$count++] ) );
00070 }
00071
00072 $this->format_data[$fmt['id'].'_'.$fmt['lang']] = $fmt;
00073 }
00074 }
00075 }
00076 }
00077
00078 $meeting_data = $this->bmlt_instance->Execute ( 'csv', $in_http_vars );
00079 if ( $meeting_data )
00080 {
00081 $meeting_data_ar = explode ( "\n", $meeting_data );
00082
00083 if ( is_array ( $meeting_data_ar ) && (count ( $meeting_data_ar ) > 1) )
00084 {
00085 $this->meeting_data = array();
00086
00087 $keys = explode ( '","', $meeting_data_ar[0] );
00088
00089 for ( $c = 0; $c < count ( $keys ); $c++ )
00090 {
00091 $keys[$c] = stripslashes ( preg_replace ( '/^\"|\"$/', '', $keys[$c] ) );
00092 }
00093
00094 $meeting_data_ar[0] = null;
00095 unset ( $meeting_data_ar[0] );
00096
00097 foreach ( $meeting_data_ar as $meeting )
00098 {
00099 $meeting = explode ( '","', $meeting );
00100 if ( is_array ( $meeting ) && (count ( $meeting ) == count ( $keys )) )
00101 {
00102 $mtg = array ();
00103 $count = 0;
00104 foreach ( $keys as $key )
00105 {
00106 $mtg[$key] = stripslashes ( preg_replace ( '/^\"|\"$/', '', $meeting[$count++] ) );
00107 }
00108
00109 array_push ( $this->meeting_data, $mtg );
00110 }
00111 }
00112 }
00113 }
00114 }
00115 else
00116 {
00117 throw new Exception ( 'No BMLT object!' );
00118 }
00119 }
00120
00121
00122
00123
00124
00125
00126
00127
00128 static function MakeNAPDF ( $in_x,
00129 $in_y,
00130 $in_http_vars,
00131 $in_units = 'in',
00132
00133
00134
00135
00136
00137
00138 $in_orientation = 'P',
00139
00140
00141
00142
00143 $in_keys = null,
00144 $in_lang_search = null
00145 )
00146 {
00147 self::$fpdf_instance = null;
00148 self::$fpdf_instance = new napdf ( $in_x, $in_y, $in_http_vars, $in_units, $in_orientation, $in_lang_search );
00149
00150 if ( self::$fpdf_instance instanceof napdf )
00151 {
00152 if ( (self::$fpdf_instance->bmlt_instance instanceof BMLT_Satellite) && is_array ( self::$fpdf_instance->meeting_data ) )
00153 {
00154 if ( is_array ( $in_keys ) )
00155 {
00156 self::$fpdf_instance->set_sort ( $in_keys );
00157 }
00158 }
00159 else
00160 {
00161 self::$fpdf_instance = null;
00162 }
00163 }
00164 else
00165 {
00166 self::$fpdf_instance = null;
00167 }
00168
00169 return self::$fpdf_instance;
00170 }
00171
00172
00173
00174
00175 function set_sort ( $in_keys
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189 )
00190 {
00191 if ( isset ( $in_keys['week_starts'] ) && ($in_keys['week_starts'] > 0) && ($in_keys['week_starts'] < 8) )
00192 {
00193 self::$week_starts = $in_keys['week_starts'];
00194 }
00195
00196 self::$sort_order_keys = $in_keys;
00197
00198 return usort ( $this->meeting_data, self::$sort_callback );
00199 }
00200
00201
00202
00203
00204
00205
00206
00207 static function sort_meeting_data_callback ( &$in_a,
00208 &$in_b
00209 )
00210 {
00211 $ret = 0;
00212
00213 if ( is_array ( $in_a ) && is_array ( $in_b ) && is_array ( napdf::$sort_order_keys ) )
00214 {
00215
00216 $sort_keys = array_reverse ( napdf::$sort_order_keys, true );
00217
00218 foreach ( $sort_keys as $key => $value )
00219 {
00220 if ( isset ( $in_a[$key] ) && isset ( $in_b[$key] ) )
00221 {
00222 $val_a = trim ( $in_a[$key] );
00223 $val_b = trim ( $in_b[$key] );
00224
00225 if ( ('weekday_tinyint' == $key) && (napdf::$week_starts > 1) && (napdf::$week_starts < 8) )
00226 {
00227 $val_a -= napdf::$week_starts;
00228
00229 if ( $val_a < 0 )
00230 {
00231 $val_a += 8;
00232 }
00233 else
00234 {
00235 $val_a += 1;
00236 }
00237
00238 $val_b -= napdf::$week_starts;
00239
00240 if ( $val_b < 0 )
00241 {
00242 $val_b += 8;
00243 }
00244 else
00245 {
00246 $val_b += 1;
00247 }
00248 }
00249
00250
00251 switch ( $key )
00252 {
00253 case 'start_time':
00254 case 'duration_time':
00255 $val_a = strtotime ( $val_a );
00256 $val_b = strtotime ( $val_b );
00257 case 'weekday_tinyint':
00258 case 'id_bigint':
00259 case 'shared_group_id_bigint':
00260 case 'service_body_bigint':
00261 $val_a = intval ( $val_a );
00262 $val_b = intval ( $val_b );
00263 case 'longitude':
00264 case 'latitude':
00265 if ( $val_a > $val_b )
00266 {
00267 $ret = 1;
00268 }
00269 elseif ( $val_b > $val_a )
00270 {
00271 $ret = -1;
00272 }
00273 break;
00274
00275 default:
00276
00277 if ( strlen ( $val_a ) && strlen ( $val_b ) )
00278 {
00279 $tmp = strcmp ( strtolower ( $val_a ), strtolower ( $val_b ) );
00280
00281 if ( $tmp != 0 )
00282 {
00283 $ret = $tmp;
00284 }
00285 }
00286 break;
00287 }
00288 }
00289
00290 if ( !$value )
00291 {
00292 $ret = -$ret;
00293 }
00294 }
00295 }
00296
00297 return $ret;
00298 }
00299
00300
00301
00302
00303
00304
00305 private function __construct ( $in_x,
00306 $in_y,
00307 $in_http_vars,
00308 $in_units = 'in',
00309
00310
00311
00312
00313
00314
00315 $in_orientation = 'P',
00316
00317
00318
00319
00320 $in_lang_search = null
00321 )
00322 {
00323 if ( is_array ( $in_lang_search ) && count ( $in_lang_search ) )
00324 {
00325 $this->lang_search = $in_lang_search;
00326 }
00327
00328 $this->bmlt_instance = BMLT_Satellite::MakeBMLT ( true );
00329
00330
00331 if ( !($this->bmlt_instance instanceof BMLT_Satellite) )
00332 {
00333 throw new Exception ( 'The BMLT object could not be created' );
00334 }
00335 $this->FPDF ( $in_orientation, $in_units, array ( $in_x, $in_y ) );
00336 $this->SetAutoPageBreak ( 0 );
00337 $this->SetAuthor ( "BMLT" );
00338 $this->SetCreator ( "BMLT" );
00339 $this->SetSubject ( "Printable Meeting List" );
00340 $this->SetTitle ( "Printable Meeting List" );
00341 $this->FetchCSV ( $in_http_vars );
00342
00343 }
00344 };
00345 ?>