kenken999/php
0
1<?php2class PrintPage extends RunnerPage3{4 public $allPagesMode = false;5 public $recordset = null;6 7 public $fetchedRecordCount = 0;8 public $splitByRecords = 0;9 public $detailTables;10 11 public $pageBody = array();12 13 14 protected $recordsRenderData = array();15 16 /**17 * Array of field names that used for totals18 * @type array19 * totalsFields = array('fName'=>"@f.strName s", 'totalsType'=>'@f.strTotalsType', 'viewFormat'=>"@f.strViewFormat");20 */21 public $totalsFields = array();22 23 /**24 * Temporary totals results25 * @type array26 */27 public $totals = array();28 29 /**30 * Total number of records in the query31 */32 public $totalRowCount = false;33 34 public $queryPageNo = 1;35 public $queryPageSize = 0;36 37 public $_eof = false;38 public $nextRecord = null;39 40 public $customFieldForSort = array();41 public $customHowFieldSort = array();42 43 public $pageNo = 1;44 45 public $hideColumns = array();46 47 protected $_notEmptyFieldColumns = array();48 49 protected $queryCommand = null;50 51 /**52 * @constructor53 */54 function __construct(&$params = "")55 {56 parent::__construct($params);57 $this->pSetEdit = new ProjectSettings($this->tName, PAGE_SEARCH);58 59 if( $this->selection )60 $this->allPagesMode = true;61 62 if( !$this->detailTables )63 $this->detailTables = array();64 65 if( !is_array( $this->detailTables ) )66 $this->detailTables = array( $this->detailTables );67 68 // save selected records and detail tables in session in normal mode69 $this->pageData["printSelection"] = $this->selection;70 $this->pageData["printDetails"] = $this->detailTables;71 $this->pageData["printAll"] = $this->allPagesMode;72 73 $this->printGridLayout = $this->pSet->getPrintGridLayout();74 $this->recsPerRowPrint = $this->pSet->getRecordsPerRowPrint();75 if ( !$this->recsPerRowPrint )76 $this->recsPerRowPrint = 1;77 78 $this->totalsFields = $this->pSet->getTotalsFields();79 80 if( !$this->splitByRecords )81 $this->splitByRecords = $this->pSet->getPrinterSplitRecords();82 83 $this->pageData["printRecords"] = $this->splitByRecords;84 85 if( $this->showHideFieldsFeatureEnabled() )86 {87 $hideColumns = $this->getColumnsToHide();88 $this->hideColumns = $hideColumns[DESKTOP];89 90 if( !is_array( $this->hideColumns ) )91 $this->hideColumns = array();92 93 foreach( $this->hideColumns as $f ) {94 $this->hideField( $this->pSet->getFieldByGoodFieldName($f) );95 }96 }97 }98 99 /**100 * @param String table101 * @return Array102 */103 public static function readSelectedRecordsFromRequest( $table )104 {105 if( !postvalue( "selection" ) )106 return array();107 108 $pSet = new ProjectSettings( $table );109 $keyFields = $pSet->getTableKeys();110 111 $selected_recs = array();112 foreach( postvalue( "selection" ) as $keyblock)113 {114 $arr = explode("&", refine($keyblock));115 if( count($arr) < count($keyFields) )116 continue;117 118 $keys = array();119 foreach($arr as $i => $value)120 {121 $keys[ $keyFields[$i] ] = urldecode( $value );122 }123 $selected_recs[] = $keys;124 }125 126 return $selected_recs;127 }128 129 /**130 *131 */132 protected function prepareCustomListQueryLegacySorting()133 {134 if( !$this->eventsObject->exists("ListQuery") )135 return;136 137 $arrFieldForSort = array();138 $arrHowFieldSort = array();139 require_once getabspath('classes/orderclause.php');140 141 $fieldList = unserialize( $_SESSION[ $this->sessionPrefix . "_orderFieldsList" ] );142 for($i = 0; $fieldList && $i < count($fieldList); $i++)143 {144 $this->customFieldForSort[] = $fieldList[$i]->fieldIndex;145 $this->customHowFieldSort[] = $fieldList[$i]->orderDirection;146 }147 }148 149 /**150 *151 */152 protected function calcPageSizeAndNumber()153 {154 if( $this->allPagesMode )155 return;156 157 $this->queryPageNo = (integer)$_SESSION[ $this->sessionPrefix . "_pagenumber" ];158 if( !$this->queryPageNo )159 $this->queryPageNo = 1;160 161 // page size162 $this->queryPageSize = (integer)$_SESSION[$this->sessionPrefix . "_pagesize"];163 if(!$this->queryPageSize)164 $this->queryPageSize = $this->pSet->getInitialPageSize();165 166 if($this->queryPageSize < 0)167 $this->allPagesMode = true;168 }169 170 /**171 *172 */173 protected function setMapParams()174 {175 $fieldsArr = array();176 foreach( $this->pSet->getPrinterFields() as $f )177 {178 $fieldsArr[] = array( 'fName' => $f, 'viewFormat' => $this->pSet->getViewFormat($f) );179 }180 $this->setGoogleMapsParams( $fieldsArr );181 }182 183 /**184 * Process the page185 */186 public function process()187 {188 // Before Process event189 if( $this->eventsObject->exists("BeforeProcessPrint") )190 $this->eventsObject->BeforeProcessPrint( $this );191 192 // prepare maps193 loadMaps( $this->pSet );194 195 196 // build tabs197 $this->processGridTabs();198 199 $this->setMapParams();200 201 RunnerContext::pushSearchContext( $this->searchClauseObj );202 // call SQL events, calculate record count203 $this->calcPageSizeAndNumber();204 $this->calculateRecordCount();205 206 $this->recordset = $this->dataSource->getList( $this->queryCommand );207 if( !$this->recordset ) {208 showError( $this->dataSource->lastError() );209 }210 211 $this->doFirstPageAssignments();212 if( !$this->splitByRecords )213 {214 $this->fillGridPage();215 $this->assignTotals();216 217 // display the 'Back to Master' link and master table info218 $this->displayMasterTableInfo();219 $this->addPage();220 }221 else222 {223 $masterAdded = false;224 while( true )225 {226 if( !$masterAdded )227 {228 $this->displayMasterTableInfo();229 $masterAdded = true;230 }231 else232 {233 // hide master table info everywhere except the first page234 $this->pageBody["container_master"] = false;235 $this->pageBody["container_pdf"] = false;236 }237 238 $this->fillGridPage();239 if($this->EOF())240 break;241 242 $this->wrapPageBody();243 244 $this->addPage();245 ++$this->pageNo;246 $this->pageBody = array();247 }248 249 // add totals to the last page250 $this->assignTotals();251 252 $this->wrapPageBody();253 $this->addPage();254 }255 256 $this->hideEmptyFields();257 258 $this->prepareJsSettings();259 $this->addButtonHandlers();260 $this->addCommonJs();261 262 $this->commonAssign();263 $this->fillAdvancedMapData();264 265 266 $this->doCommonAssignments();267 $this->addCustomCss();268 $this->addDetailsCss();269 270 $this->displayPrintPage();271 }272 273 protected function calcAllDataTotals() {274 $currentPageSize = $this->queryPageSize;275 if ( !$this->allPagesMode && $this->pSet->getRecordsLimit() )276 $currentPageSize = $this->pSet->getRecordsLimit() - ( $this->queryPageSize * ($this->queryPageNo - 1) );277 278 279 return $this->pSet->calcTotalsFor() == TOTALS_ALL_DATA 280 && !$this->allPagesMode && $this->queryPageSize < $this->totalRowCount;281 }282 283 protected function hideEmptyFields()284 {285 if( $this->printGridLayout == gltHORIZONTAL )286 {287 foreach( $this->pSet->getFieldsToHideIfEmpty() as $f )288 {289 if( !$this->_notEmptyFieldColumns[ $f ] )290 $this->hideField( $f );291 }292 }293 }294 295 function addPage() {296 $this->body["data"][] = $this->pageBody;297 298 // put into recordsRenderData links to all records299 $pageIdx = count( $this->body["data"] ) - 1;300 $pageRows = &$this->body["data"][ $pageIdx ]["grid_row"]["data"];301 302 $this->fillRenderedData( $pageRows );303 }304 305 /**306 * put into recordsRenderData links to all records307 */308 protected function fillRenderedData( &$pageRows )309 {310 for( $rowIdx = 0; $rowIdx < count( $pageRows ); ++$rowIdx )311 {312 if( !$this->manyRecordsInRow() )313 $this->recordsRenderData[ $pageRows[ $rowIdx ]['recId'] ] = &$pageRows[ $rowIdx ];314 else315 {316 $records = &$pageRows[ $rowIdx ]["grid_record"]["data"];317 for( $recordIdx = 0; $recordIdx < count( $records ); ++$recordIdx ) {318 $this->recordsRenderData[ $records[ $recordIdx ]['recId'] ] = &$records[ $recordIdx ];319 }320 }321 }322 }323 324 protected function wrapPageBody()325 {326 $this->pageBody["begin"] = "<div class=\"rp-presplitpage rp-page\">";327 $this->pageBody["end"] = "</div>";328 }329 330 /**331 *332 */333 protected function assignTotals() {334 if( !$this->totalsFields )335 return;336 337 if( $this->calcAllDataTotals() )338 $this->buildAllDataTotals();339 else340 $this->buildTotals( $this->totals );341 }342 343 344 function buildTotals( &$totals ) { 345 $record = array();346 $this->pageBody["totals_record"] = true;347 foreach( $this->totalsFields as $tf ) {348 $total = GetTotals( $tf["fName"],349 $totals[ $tf["fName"] ],350 $tf[ "totalsType" ],351 $tf["numRows"],352 $tf[ "viewFormat" ],353 PAGE_PRINT,354 $this->pSet,355 false,356 $this );357 358 $this->pageBody[ GoodFieldName( $tf['fName'] ) . "_total" ] = $total;359 $this->pageBody[ GoodFieldName( $tf['fName'] ) . "_showtotal"] = true;360 $record[ GoodFieldName( $tf['fName'] ) . "_showtotal"] = true;361 }362 363 $this->pageBody[ "totals_row" ] = array("data" => array(0 => $record)); 364 }365 366 /**367 * @return Boolean368 */369 protected function EOF()370 {371 $currentPageSize = $this->queryPageSize;372 if ( !$this->allPagesMode && $this->pSet->getRecordsLimit() )373 {374 $currentPageSize = $this->pSet->getRecordsLimit() - ($this->queryPageSize * ($this->queryPageNo - 1));375 }376 else if ( $this->allPagesMode )377 {378 $currentPageSize = $this->limitRowCount($this->totalRowCount);379 }380 381 if ( $this->fetchedRecordCount >= $currentPageSize )382 return true;383 384 $this->readNextRecordInternal();385 if( $this->_eof )386 return true;387 388 return false;389 }390 391 /**392 * reads the next record and fills in $this->nextRecord393 */394 protected function readNextRecordInternal()395 {396 // no more data397 if( $this->_eof )398 return;399 400 // next record already read401 if( $this->nextRecord )402 return;403 404 // read the record and store it in $this->nextRecord405 while(true)406 {407 if( $this->eventsObject->exists("ListFetchArray") )408 $data = $this->eventsObject->ListFetchArray($this->recordset, $this);409 else410 $data = $this->cipherer->DecryptFetchedArray( $this->recordset->fetchAssoc() );411 412 if( !$data )413 {414 $this->_eof = true;415 return;416 }417 418 if( $this->eventsObject->exists("BeforeProcessRowPrint") )419 {420 if( !$this->eventsObject->BeforeProcessRowPrint($data, $this) )421 {422 continue;423 }424 }425 426 $this->nextRecord = $data;427 return;428 }429 }430 431 /**432 * @return Mixed433 */434 protected function readNextRecord()435 {436 if($this->EOF())437 return false;438 ++$this->fetchedRecordCount;439 $data = $this->nextRecord;440 $this->nextRecord = false;441 return $data;442 }443 444 /**445 * @param Array data446 * @param &Array row447 * @return Array448 */449 protected function buildGridRecord( $data, &$row )450 {451 $this->genId();452 453 $record = array();454 $record["recordattrs"] = "data-record-id=\"".$this->recId."\"";455 $record["recId"] = $this->recId;456 457 if( !$this->calcAllDataTotals() )458 $this->countTotals( $this->totals , $data );459 460 $keyFields = $this->pSet->getTableKeys();461 $keylink = "";462 $keys = array();463 for($i = 0; $i < count( $keyFields ); $i ++)464 {465 $keylink.= "&key".($i + 1) . "=" . runner_htmlspecialchars( rawurlencode( @$data[ $keyFields[$i] ] ) );466 $keys[$i] = $data[ $keyFields[$i] ];467 }468 469 if( $this->eventsObject->exists("BeforeMoveNextPrint") )470 $this->eventsObject->BeforeMoveNextPrint($data, $row, $record, $record["recId"], $this);471 472 $fieldsToHideIfEmpty = $this->pSet->getFieldsToHideIfEmpty();473 474 $printFields = &$this->pSet->getPrinterFields();475 for($i = 0; $i < count($printFields); $i++)476 {477 $dbValue = $this->showDBValue( $printFields[$i], $data, $keylink );478 if( !$this->pdfJsonMode() ) {479 $record[GoodFieldName($printFields[$i])."_value"] = $dbValue;480 } else {481 $record[GoodFieldName($printFields[$i])."_pdfvalue"] = $dbValue;482 }483 484 $isEmptyValue = $this->pdfJsonMode() && $dbValue == "''" || !$this->pdfJsonMode() && $dbValue == "";485 486 if( in_array( $printFields[$i], $fieldsToHideIfEmpty ) )487 {488 if( $this->printGridLayout != gltHORIZONTAL && $isEmptyValue )489 $this->hideField( $printFields[$i], $this->recId );490 else if( $this->printGridLayout == gltHORIZONTAL && !$isEmptyValue )491 {492 $this->_notEmptyFieldColumns[ $printFields[$i] ] = true;493 }494 }495 496 $this->setRowClassNames($record, $printFields[$i]);497 }498 499 $this->spreadRowStyles($data, $row, $record);500 $this->setRowCssRules($record);501 502 $record["grid_recordheader"] = true;503 $record["grid_vrecord"] = true;504 505 if( $this->pSet->hasMap() )506 $this->addBigGoogleMapMarkers( $data, $keys );507 508 return $record;509 }510 511 /**512 * @param Array columns513 */514 protected function showGridHeader( $columns )515 {516 517 $this->pageBody[ "record_header" ] = array("data"=>array());518 $this->pageBody[ "record_footer" ] = array("data"=>array());519 520 for($i = 0; $i < $columns; $i++)521 {522 $rheader = array();523 $rfooter = array();524 if($i < $columns - 1)525 {526 $rheader["endrecordheader_block"] = true;527 $rfooter["endrecordheader_block"] = true;528 }529 $this->pageBody[ "record_header" ]["data"][] = $rheader;530 $this->pageBody[ "record_footer" ]["data"][] = $rfooter;531 }532 $this->pageBody[ "grid_header" ] = true;533 $this->pageBody[ "grid_footer" ] = true;534 }535 536 protected function manyRecordsInRow() {537 return $this->printGridLayout == gltVERTICAL || $this->recsPerRowPrint != 1;538 }539 540 /**541 *542 */543 protected function fillGridPage()544 {545 $this->pageBody["grid_row"] = array();546 $this->pageBody["grid_row"]["data"] = array();547 $recno = 0;548 549 $recordsPrinted = 0;550 551 $row = array();552 while( $data = $this->readNextRecord() )553 {554 RunnerContext::pushRecordContext( $data, $this );555 556 $row["details"] = array();557 // create new row558 $row = array();559 $row["grid_record"] = array();560 $row["grid_record"]["data"] = array();561 $row["details_record"] = array();562 $row["details_record"]["data"] = array();563 564 // add the record to the row565 if( $this->manyRecordsInRow() )566 {567 $builtrow = $this->buildGridRecord( $data, $row );568 569 foreach( $this->detailTables as $dt ) {570 $assignmentMethod = $this->buildDetailsXtMethod($dt, $data);571 if ( $assignmentMethod ) {572 $this->showItemType("details_preview");573 $builtrow["details_" . $dt] = true;574 $builtrow["displayDetailTable_" . $dt] = $assignmentMethod;575 }576 }577 578 $row["grid_record"]["data"][] = $builtrow;579 }580 else581 {582 // simplify row/record structure - put everything to $row583 $builtrow = $this->buildGridRecord( $data, $row );584 foreach( $builtrow as $index => $value)585 {586 $row[ $index ] = $value;587 }588 $row["grid_record"] = true;589 590 foreach( $this->detailTables as $dt ) {591 $assignmentMethod = $this->buildDetailsXtMethod($dt, $data);592 if ( $assignmentMethod ) {593 $this->showItemType("details_preview");594 $row["details_" . $dt] = true;595 $row["displayDetailTable_" . $dt] = $assignmentMethod;596 }597 }598 }599 600 RunnerContext::pop();601 602 // hide group fields603 if ( $prevData )604 {605 $grFields = $this->pSet->getGroupFields();606 foreach( $grFields as $grF )607 {608 if ( $data[ $grF ] != $prevData[ $grF ] )609 break;610 611 foreach ( $this->pSet->getFieldItems( $grF ) as $fItemId )612 {613 $this->hideItem( $fItemId, $builtrow['recId'] );614 }615 }616 }617 $prevData = $data;618 619 // finalize row if needed620 ++$recno;621 $this->pageBody["grid_row"]["data"][] = $row;622 623 if( $this->splitByRecords && $recno >= $this->splitByRecords )624 break;625 }626 $this->showGridHeader( $this->recsPerRowPrint < $recno ? $this->recsPerRowPrint : $recno);627 $this->pageBody["pageno"] = $this->pageNo;628 629 if ( $this->allPagesMode )630 {631 $this->xt->assign( "print_pages", true );632 foreach ( $this->pSet->printPagesLabelsData() as $itemId => $mLString )633 {634 $label = str_replace( "%current%", $this->pageNo, GetMLString( $mLString ) );635 $this->pageBody[ "print_pages_label".$itemId ] = $label;636 }637 }638 }639 640 /**641 *642 */643 public function doCommonAssignments()644 {645 $this->xt->assign( "pagecount", $this->pageNo );646 647 $this->body['begin'].= GetBaseScriptsForPage( false );648 649 // assign body end650 $this->body['end'] = XTempl::create_method_assignment( "assignBodyEnd", $this );651 652 if ( $this->allPagesMode && !!$this->body["data"] )653 {654 // update %total% value655 $total = count( $this->body["data"] );656 foreach ( $this->pSet->printPagesLabelsData() as $itemId => $mLString )657 {658 foreach( $this->body["data"] as $idx => $pageBody )659 {660 $this->body["data"][$idx][ "print_pages_label".$itemId ] = str_replace( "%total%", $total, $pageBody[ "print_pages_label".$itemId ] );661 }662 }663 }664 665 if( $this->mode == PRINT_PDFJSON ) {666 $pdfBody = &$this->body;667 unset( $pdfBody["begin"] );668 unset( $pdfBody["end"] );669 for( $p = 0; $pdfBody["data"] && $p < count( $pdfBody["data"] ); ++$p ) {670 unset( $pdfBody["data"][$p]["begin"] );671 unset( $pdfBody["data"][$p]["end"] );672 }673 $this->xt->assignbyref('body', $pdfBody );674 675 $this->xt->assign( "pdfFonts", my_json_encode( getPdfFonts() ) );676 } else677 $this->xt->assignbyref('body', $this->body);678 679 $this->xt->assign("grid_block", true);680 $this->xt->assign("page_number",true);681 682 683 // display Prepare for printing or PDF buttons684 if( !$this->splitByRecords || $this->pSet->isPrinterPagePDF() )685 {686 $this->xt->assign("printbuttons", true);687 }688 689 $this->xt->assign("printheader",true);690 691 if ( count($this->gridTabs) > 1 )692 {693 $curTabId = $this->getCurrentTabId();694 $this->xt->assign("printtabheader",true);695 $this->xt->assign("printtabheader_text", $this->getTabTitle($curTabId));696 }697 foreach( $this->pSet->getPrinterFields() as $f )698 {699 $gf = GoodFieldName($f);700 $this->xt->assign( $gf . "_fieldheadercolumn", true );701 $this->xt->assign( $gf . "_fieldheader", true);702 $this->xt->assign( $gf . "_class", $this->fieldClass( $f ));703 $this->xt->assign( $gf . "_align", $this->fieldAlign( $f ));704 $this->xt->assign( $gf . "_fieldcolumn", true );705 $this->xt->assign( $gf . "_fieldfootercolumn", true );706 }707 708 if( $this->pSet->hasMap() ) {709 foreach( $this->googleMapCfg['mainMapIds'] as $mapId ) {710 $this->xt->assign_event( $mapId, $this, 'createMap', array('mapId' => $mapId ) );711 }712 }713 }714 715 function createMap( &$params )716 {717 $provider = getMapProvider();718 719 $mapId = $params['mapId'];720 721 $apiKey = $this->googleMapCfg["APIcode"];722 $zoom = $this->googleMapCfg['mapsData'][ $mapId ]['zoom'];723 $markers = $this->googleMapCfg['mapsData'][ $mapId ]['markers'];724 //$icon = $markers[0]['mapIcon'];725 726 $masData = $this->pSet->mapsData();727 728 // designer width729 $width = $masData[ $mapId ]['width'];730 if( !$width )731 $width = $this->googleMapCfg['mapsData'][ $mapId ]['width'] ? $this->googleMapCfg['mapsData'][ $mapId ]['width'] : 400;732 733 // designer height734 $height = $masData[ $mapId ]['height'];735 if( !$height )736 $height = $this->googleMapCfg['mapsData'][ $mapId ]['height'] ? $this->googleMapCfg['mapsData'][ $mapId ]['height'] : 300;737 738 $locations = array();739 foreach( $markers as $marker )740 {741 if( $marker['lat'] == "" && $marker['lng'] == "" )742 {743 if( $provider == GOOGLE_MAPS )744 $locations[] = $marker['address'];745 else746 {747 $locationByAddress = getLatLngByAddr( $marker['address'] );748 $locations[] = $locationByAddress['lat'].','.$locationByAddress['lng'];749 }750 }751 else752 $locations[] = $marker['lat'].','.$marker['lng'];753 }754 755 switch( $provider )756 {757 case GOOGLE_MAPS:758 $src = 'https://maps.googleapis.com/maps/api/staticmap?size='.$width.'x'.$height.'&key='.$apiKey.'&';759 760 if( !( $markers ) )761 $src.= "center=0,0&zoom=".( $zoom ? $zoom : 5 );762 else763 $src.= ( $zoom ? "zoom=".$zoom."&" : "" )."markers=".rawurlencode( implode( '|', $locations ) );764 break;765 case OPEN_STREET_MAPS:766 $src = 'https://staticmap.openstreetmap.de/staticmap.php?size='.$width.'x'.$height.'&';767 768 if( !( $markers ) )769 $src.= "center=0,0&zoom=".( $zoom ? $zoom : 3 );770 else771 $src.= "center=".$locations[0]."&zoom=".( $zoom ? $zoom : 3 )."&markers=".rawurlencode( implode( '|', $locations ) );772 break;773 case BING_MAPS:774 if( !( $markers ) )775 $src = 'https://dev.virtualearth.net/REST/v1/Imagery/Map/Road/0,0/'.( $zoom ? $zoom : 5 )776 .'/?key='.$apiKey.'&mapSize='.$width.','.$height;777 else778 {779 // You can specify up to 18 pushpins within a URL780 $mParams = 'pp='.rawurlencode( implode( '&pp=', array_slice( $locations, 0, 17 ) ));781 $src = 'https://dev.virtualearth.net/REST/v1/Imagery/Map/Road?'.$mParams782 .'&key='.$apiKey.'&mapSize='.$width.','.$height;783 if( $zoom )784 $src.= '&zoomLevel='.$zoom;785 }786 break;787 case HERE_MAPS:788 $src = 'https://image.maps.ls.hereapi.com/mia/1.6/mapview?'789 .'apiKey='.$apiKey790 .'&w='.$width791 .'&h='.$height792 .'&poi='.rawurlencode( implode( ',', $locations ) );793 794 if( $zoom )795 $src.= '&z='.$zoom;796 797 case MAPQUEST_MAPS:798 $src = 'https://www.mapquestapi.com/staticmap/v5/map?'799 .'key='.$apiKey800 .'&locations='.rawurlencode( implode( '||', $locations ) )801 .'&size='.$width.','.$height;802 803 if( $zoom )804 $src.= '&zoom='.$zoom; 805 806 break;807 default:808 $src = '';809 }810 811 if( $this->pdfJsonMode() )812 {813 $content = myurl_get_contents_binary( $src );814 815 $imageType = SupposeImageType( $content );816 if( $imageType == "image/jpeg" || $imageType == "image/png" )817 {818 echo '{819 image: "' . jsreplace( 'data:'. $imageType . ';base64,' . base64_bin2str( $content ) ) . '",820 width: '. $width .',821 height:'. $height .',822 }';823 return;824 }825 826 echo '""';827 return;828 }829 830 echo '<img id="'.$params['mapId'].'" src="'.$src.'">';831 }832 833 /**834 *835 */836 protected function prepareJsSettings()837 {838 if( isRTL() )839 $this->jsSettings['tableSettings'][ $this->tName ]['isRTL'] = true;840 841 if( $this->pSet->isPrinterPagePDF() )842 $this->jsSettings['tableSettings'][ $this->tName ]['printerPagePDF'] = true;843 844 $this->jsSettings['tableSettings'][ $this->tName ]['printerPageOrientation'] = $this->pSet->getPrinterPageOrientation();845 $this->jsSettings['tableSettings'][ $this->tName ]['printerPageScale'] = $this->pSet->getPrinterPageScale();846 $this->jsSettings['tableSettings'][ $this->tName ]['isPrinterPageFitToPage'] = $this->pSet->isPrinterPageFitToPage();847 $this->jsSettings['tableSettings'][ $this->tName ]['printerSplitRecords'] = $this->pSet->getPrinterSplitRecords();848 $this->jsSettings['tableSettings'][ $this->tName ]['printerPDFSplitRecords'] = $this->pSet->getPrinterPDFSplitRecords();849 850 if( $this->printGridLayout )851 $this->jsSettings['tableSettings'][$this->tName]['printGridLayout'] = $this->printGridLayout;852 853 if( $this->showHideFieldsFeatureEnabled() )854 $this->jsSettings['tableSettings'][ $this->tName ]['isAllowShowHideFields'] = true;855 $this->prepareColumnOrderSettings();856 }857 858 protected function reorderFieldsFeatureEnabled() {859 return parent::reorderFieldsFeatureEnabled() && $this->pSet->listColumnsOrderOnPrint();860 }861 862 protected function prepareColumnOrderSettings()863 {864 if( $this->reorderFieldsFeatureEnabled() && $this->printGridLayout == gltHORIZONTAL && $this->recsPerRowPrint == 1 )865 {866 $this->jsSettings['tableSettings'][ $this->tName ]['isAllowFieldsReordering'] = true;867 868 include_once getabspath("classes/paramsLogger.php");869 $logger = new paramsLogger( $this->tName, FORDER_PARAMS_TYPE );870 871 $columnOrder = $logger->getData();872 if( $columnOrder )873 $this->jsSettings['tableSettings'][ $this->tName ]['columnOrder'] = $columnOrder;874 }875 }876 877 /**878 *879 */880 public function displayPrintPage()881 {882 $templateFile = $this->templatefile;883 if($this->eventsObject->exists("BeforeShowPrint"))884 $this->eventsObject->BeforeShowPrint($this->xt, $templateFile, $this);885 886 if( $this->mode == PRINT_PDFJSON )887 {888 $this->preparePDFBackground();889 $this->xt->assign( "standalone_page", true );890 $this->xt->displayJSON($this->templatefile);891 return;892 }893 894 $this->display( $this->templatefile );895 }896 897 898 public function doFirstPageAssignments()899 {900 $this->hideItemType("details_preview");901 902 foreach( $this->googleMapCfg['mainMapIds'] as $mapId ) {903 $this->pageBody[ "map_".$mapId ] = true;904 }905 906 if( $this->pSet->isPrinterPagePDF() ) {907 $this->pageBody["pdflink_block"] = true;908 } else {909 $this->hideItemType("print_pdf");910 }911 }912 913 /**914 * Show the field on the page915 * @param String fieldName916 */917 function showField($fieldName)918 {919 $gf = GoodFieldName($fieldName);920 foreach ($this->body["data"] as $key => $value)921 {922 $this->body["data"][$key][ $gf . "_fieldheadercolumn"] = true;923 $this->body["data"][$key][ $gf . "_fieldcolumn"] = true;924 $this->body["data"][$key][ $gf . "_fieldfootercolumn"] = true;925 }926 }927 928 protected function addDetailsCss() {929 foreach( $this->detailTables as $dt )930 {931 $dtName = GetTableByShort( $dt );932 933 $tSet = $this->pSet->getTable( $dtName );934 $tType = $tSet->getTableType();935 $pageType = $tType == PAGE_REPORT ? PAGE_RPRINT : PAGE_PRINT;936 937 $pageName = $this->pSet->detailsPageId( $dtName );938 $dpSet = new ProjectSettings( $dtName, $pageType, $pageName );939 940 $pageLayout = GetPageLayout( $dtName, $dpSet->pageName() );941 $templatefile = GetTemplateName( GetTableURL( $dtName ), $dpSet->pageName() );942 943 $cssFiles = $pageLayout->getCSSFiles( isRTL(), isPageLayoutMobile( $templatefile ), false );944 $this->AddCSSFile( $cssFiles );945 946 include_once getabspath('classes/controls/ViewControlsContainer.php');947 $viewControls = new ViewControlsContainer(new ProjectSettings($dtName, $pageType), $pageType);948 $viewControls->addControlsJSAndCSS();949 $this->AddCSSFile( $viewControls->includes_css );950 }951 }952 953 /**954 * @param Array data955 * @return Array956 */957 protected function buildDetails( $data )958 {959 $details = array();960 foreach( $this->detailTables as $dt )961 {962 $assignmentMethod = $this->buildDetailsXtMethod($dt, $data);963 if ( $assignmentMethod )964 $details[] = array( "details" => $assignmentMethod );965 }966 967 return $details;968 }969 970 protected function buildDetailsXtMethod($dt, $data)971 {972 $dTable = GetTableByShort( $dt );973 $mkeys = $this->pSet->getMasterKeysByDetailTable( $dTable );974 if( !$mkeys )975 return false;976 977 $tSet = $this->pSet->getTable( $dTable );978 $tType = $tSet->getTableType();979 980 $dtableArrParams = array();981 $dtableArrParams = array();982 $dtableArrParams["id"] = $this->genId() + 1; // it may rewrite pageData983 $dtableArrParams["xt"] = new Xtempl();984 $dtableArrParams["tName"] = $dTable;985 $dtableArrParams["multipleDetails"] = count($this->detailTables) > 1;986 987 $dtableArrParams["pageName"] = $this->pSet->detailsPageId( $dTable );988 989 $dtableArrParams["masterTable"] = $this->tName;990 $dtableArrParams["masterKeysReq"] = array();991 $i = 0;992 foreach( $mkeys as $mkey )993 {994 $i++;995 $dtableArrParams["masterKeysReq"][$i] = $data[$mkey] ;996 }997 998 if ( $tType == PAGE_REPORT )999 {1000 $dtableArrParams["pageType"] = PAGE_RPRINT;1001 $dtableArrParams["isDetail"] = true;1002 }1003 else1004 {1005 $dtableArrParams["pageType"] = PAGE_PRINT;1006 }1007 1008 if( $this->pdfJsonMode() )1009 $dtableArrParams["mode"] = PRINT_PDFJSON;1010 1011 return XTempl::create_method_assignment( "showDetails", $this, $dtableArrParams );1012 }1013 1014 /**1015 * @param Array params1016 */1017 public function showDetails( $params )1018 {1019 if ( $params["pageType"] == PAGE_RPRINT )1020 {1021 $detailsObject = new ReportPrintPage( $params );1022 $detailsObject->init();1023 $detailsObject->processDetailPrint();1024 }1025 else1026 {1027 $detailsObject = new PrintPage_Details( $params );1028 $detailsObject->init();1029 $detailsObject->process();1030 1031 $this->includes_js = array_merge($this->includes_js, $detailsObject->includes_js);1032 1033 $this->viewControlsMap["dViewControlsMap"][ $params["tName"] ] = $detailsObject->viewControlsMap;1034 $this->viewControlsMap["dViewControlsMap"][ $params["tName"] ]["id"] = $detailsObject->id;1035 }1036 }1037 1038 protected function getColumnsToHide()1039 {1040 return $this->getCombinedHiddenColumns();1041 }1042 1043 function fieldClass($f) {1044 $ret = parent::fieldClass($f);1045 if( $ret && $this->printGridLayout == gltVERTICAL || $this->printGridLayout == gltCOLUMNS )1046 $ret = '';1047 return $ret;1048 }1049 1050 function getDataSourceFilterCriteria( $ignoreFilterField = "" )1051 {1052 $filter = parent::getDataSourceFilterCriteria();1053 $selectedRecords = $this->getSelectedRecords();1054 if( $selectedRecords !== null ) {1055 1056 $keyFields = $this->pSet->getTableKeys();1057 $recConditions = array();1058 foreach( $selectedRecords as $keys ) {1059 $recConditions[] = DataCondition::FieldsEqual( $keyFields, $keys );1060 }1061 $filter = DataCondition::_And( array(1062 $filter,1063 DataCondition::_Or( $recConditions )1064 ));1065 1066 }1067 return $filter;1068 }1069 1070 function callBeforeQueryEvent( $dc ) {1071 if( !$this->eventsObject->exists("BeforeQueryPrint") ) {1072 return;1073 }1074 $prep = $this->dataSource->prepareSQL( $dc );1075 $where = $prep["where"];1076 $order = $prep["order"];1077 $sql = $prep["sql"];1078 $this->eventsObject->BeforeQueryPrint($sql, $where, $order, $this);1079 1080 if( $sql != $prep["sql"] )1081 $this->dataSource->overrideSQL( $dc, $sql );1082 else {1083 if( $where != $prep["where"] )1084 $this->dataSource->overrideWhere( $dc, $where );1085 if( $order != $prep["order"] ) 1086 $this->dataSource->overrideOrder( $dc, $order );1087 }1088 } 1089 1090 function calculateRecordCount()1091 {1092 $this->queryCommand = $this->getSubsetDataCommand();1093 $this->callBeforeQueryEvent( $this->queryCommand );1094 $this->totalRowCount = $this->dataSource->getCount( $this->queryCommand );1095 1096 }1097 1098 public function getSubsetDataCommand( $ignoreFilterField = "" ) {1099 1100 $dc = parent::getSubsetDataCommand( $ignoreFilterField );1101 1102 $this->reoderCommandForReoderedRows( $this->getListPSet(), $dc );1103 1104 if( !$this->allPagesMode ) {1105 $dc->reccount = $this->queryPageSize;1106 $dc->startRecord = $this->queryPageSize * ( $this->queryPageNo - 1 );1107 }1108 return $dc;1109 }1110 1111 1112 function pdfJsonMode() {1113 return $this->mode == PRINT_PDFJSON;1114 }1115 1116 function &findRecordAssigns( $recordId ) {1117 return $this->recordsRenderData[ $recordId ];1118 }1119 1120 public function getSecurityCondition() {1121 return Security::SelectCondition( "P", $this->pSet );1122 }1123 1124 protected function getTotalDataCommand() {1125 return parent::getSubsetDataCommand();1126 }1127}1128?>