CoolFace
Apppublic

kenken999/php

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
reportpage.php1408 linesDownload Raw Back to classes
1<?php2class ReportPage extends RunnerPage3{4 5	public $pagestart = 0;6 7	public $arrReport = array();8 9	/**10	 * Array of groups per page for report with group fields11	 * @var array12	 * @intellisense13	 */14	public $arrGroupsPerPage = array();15 16	/**17	 * The flag indicating that report is cross-table18	 */19	public $crossTable = false;20 21	/**22	 * Refresh the crosstab report23	 */24	public $crosstableRefresh = false;25 26	/**27	 * @type Boolean28	 */29	protected $noRecordsFound = false;30 31	protected $crossTableObj = null;32 33	public $pdfJson = false;34 35	public $x;36	public $y;37	public $dataField;38	public $operation;39	public $xType;40	public $yType;41	public $selectedAxis;42	public $requestGoto;43	/**44	 * @constructor45	 * @param &Array params46	 */47	function __construct( &$params )48	{49		parent::__construct($params);50 51		$this->crossTable = $this->pSet->isCrossTabReport();52 53		$this->jsSettings['tableSettings'][ $this->tName ]['crossTable'] = $this->crossTable;54		$this->jsSettings['tableSettings'][ $this->tName ]['simpleSearchActive'] = $this->searchClauseObj->simpleSearchActive;55 56		if( $this->mode == REPORT_DASHBOARD || $this->mode == REPORT_DETAILS || $this->mode == REPORT_DASHDETAILS )57		{58			if( $this->mode != REPORT_DETAILS )59			{60				$this->formBricks["header"] = array(61					array( "name" => "details_found", "align" => "right" )62				);63			}64			$this->formBricks["footer"] = array( "pagination_block" );65		}66 67		$this->controlsMap["pdfSettings"] = array();68		$this->controlsMap["pdfSettings"]["allPagesMode"] = 0;69	}70 71	/**72	 * Set the page's session prefix73	 */74	protected function assignSessionPrefix()75	{76		if( $this->mode == REPORT_DASHBOARD )77			$this->sessionPrefix = $this->dashTName."_".$this->tName;78		else79			$this->sessionPrefix = $this->tName;80	}81 82	/**83	 * Set session variables84	 */85	public function setSessionVariables()86	{87		parent::setSessionVariables();88 89		$_SESSION[$this->sessionPrefix.'_advsearch'] = serialize($this->searchClauseObj);90 91		if( !$_SESSION[$this->sessionPrefix."_pagesize"] )92			$_SESSION[$this->sessionPrefix."_pagesize"] = $this->pSet->getInitialPageSize();93 94		$this->pageSize = $_SESSION[$this->sessionPrefix."_pagesize"];95 96		if( !$_SESSION[ $this->sessionPrefix."_pagenumber" ] )97			$_SESSION[ $this->sessionPrefix."_pagenumber" ] = 1;98 99		if( $this->requestGoto )100			$_SESSION[ $this->sessionPrefix."_pagenumber" ] = $this->requestGoto;101 102		$this->myPage = $_SESSION[$this->sessionPrefix."_pagenumber"];103 104		$this->pagestart = ($this->myPage - 1) * $this->pageSize;105		if( $this->pageSize < 0 ) {106			$this->pagestart = 0;107		}108	}109 110 111	/**112	 * Process the page113	 */114	public function process()115	{116		if( $this->mode == REPORT_DASHDETAILS117			|| $this->mode == REPORT_DETAILS && ( $this->masterPageType == PAGE_LIST || $this->masterPageType == PAGE_REPORT ))118			$this->updateDetailsTabTitles();119 120		if( $this->crossTable && !$this->checkCrossParams() )121		{122			if( $this->mode == REPORT_SIMPLE )123			{124				$this->crossTableBaseRedirect();125				return;126			}127 128			$this->setDefaultParams();129		}130 131		//	Before Process event132		if( $this->eventsObject->exists("BeforeProcessReport") )133			$this->eventsObject->BeforeProcessReport( $this );134 135		$this->setDetailsBadgeStyles();136		// array with extra report params137		$extraParams = $this->getExtraReportParams();138 139		$this->setGoogleMapsParams( $extraParams['fieldsArr'] );140		$this->fillAdvancedMapData();141		if( $this->googleMapCfg['isUseGoogleMap'] )142			$this->initGmaps();143 144		if( $this->mode != REPORT_DASHBOARD ) {145			$this->buildSearchPanel();146			$this->assignSimpleSearch();147		}148 149		// build tabs and set current150		$this->processGridTabs();151 152		RunnerContext::pushSearchContext( $this->searchClauseObj );153 154		$this->setReportData( $extraParams );155 156		$this->addCommonJs();157		$this->addButtonHandlers();158		$this->commonAssign();159		$this->doCommonAssignments();160		$this->addCustomCss();161 162		// display the 'Back to Master' link and master table info163		if( $this->mode == REPORT_SIMPLE )164			$this->displayMasterTableInfo();165 166		$this->showPage();167	}168 169	/**170	 * @return Boolean171	 */172	protected function checkCrossParams()173	{174		if( !$this->crossTable )175			return true;176 177		return strlen( $this->x ) && strlen( $this->y ) && strlen( $this->dataField );178	}179 180	/**181	 *182	 */183	protected function setDefaultParams()184	{185		$prms = $this->getDefaultCrossParams();186 187		$this->x = $prms["x"];188		$this->y = $prms["y"];189		$this->dataField = $prms["data"];190		$this->operation = $prms["op"];191	}192 193	/**194	 * Fix it!195	 * @return Array196	 */197	protected function getDefaultCrossParams()198	{199		if( !$this->crossTable )200			return array();201 202		$xNames = array();203		$yNames = array();204		$allNames = array();205		foreach( $this->pSet->getReportGroupFieldsData() as $ind => $value )206		{207			$axisName = $value["strGroupField"];208 209			if( $value["crossTabAxis"] == 0 )210				$xNames[] = $axisName;211			elseif( $value["crossTabAxis"] == 1 )212				$yNames[] = $axisName;213			else214				$allNames[]= $axisName;215		}216 217		if( $xNames )218			$x = $xNames[0];219		else220			$x = $allNames[0];221 222		if( $yNames )223			$y = $yNames[0];224		else225		{226			if( !$xNames )227				$y = $allNames[1];228			else229				$y = $allNames[0];230		}231 232		$dataField = "";233		$operation = "";234		$reportFields = $this->pSet->getFieldsList();235		foreach( $reportFields as $field )236		{237			$operation = "";238			$fieldInfo = $this->pSet->reportFieldInfo( $field );239			if( $fieldInfo ) {240				if( $fieldInfo["max"] )241					$operation = "max";242				else if( $fieldInfo["min"] )243					$operation = "min";244				else if( $fieldInfo["avg"] )245					$operation = "avg";246				else if( $fieldInfo["sum"] )247					$operation = "sum";248			}249			if( $operation )250			{251				$dataField = $field;252				break;253			}254		}255 256		return array( "x" => $x, "y" => $y, "data" => $dataField, "op" => $operation );257	}258 259	/**260	 * @return Array261	 */262	protected function getCurrentCrossParams()263	{264		$prms = array( "x" => $this->x, "y" => $this->y, "data" => $this->dataField, "op" => $this->operation );265 266		if( $this->xType )267			$prms["xtype"] = $this->xType;268 269		if( $this->yType )270			$prms["ytype"] = $this->yType;271 272		return $prms;273	}274 275	/**276	 * @return String277	 */278	protected function getDefaultCrossParamsString()279	{280		$prms = $this->getDefaultCrossParams();281		return "x=".$prms["x"]."&y=".$prms["y"]."&data=".$prms["data"]."&op=".$prms["op"];282	}283 284	/**285	 *286	 */287	protected function crossTableBaseRedirect()288	{289		HeaderRedirect( $this->pSet->getShortTableName(), $this->getPageType(),290			implode( '&', array( $this->getDefaultCrossParamsString(), $this->getStateUrlParams() ) ) );291		exit();292	}293 294	/**295	 * Get the report data, assign corresponding xt variables296	 * @param Array options297	 */298	public function setReportData( $options )299	{300		if( $this->crossTable )301			$this->setCrosstabData( $options );302		else303			$this->setStandartData( $options );304	}305 306	/**307	 *308	 */309	protected function getCrossGroupFieldsSettings( $repGroupFields )310	{311		$groupFields = array();312 313		$xNames = array();314		$yNames = array();315 316		$xFieldsCount = array();317		$yFieldsCount = array();318 319		foreach( $repGroupFields as $ind => $value )320		{321			if( $value["crossTabAxis"] == 0 || $value["crossTabAxis"] == 2 )322				++$xFieldsCount[ $value["strGroupField"] ];323			if( $value["crossTabAxis"] == 1 || $value["crossTabAxis"] == 2 )324				++$yFieldsCount[ $value["strGroupField"] ];325		}326 327		foreach( $repGroupFields as $ind => $value )328		{329			$groupFields[ $ind ]["name"] = $value["strGroupField"];330 331			$xAxis = ($value["crossTabAxis"] == 0 || $value["crossTabAxis"] == 2);332			$yAxis = ($value["crossTabAxis"] == 1 || $value["crossTabAxis"] == 2);333 334			if( 0 == $value["groupInterval"] ||335				$xAxis && $xFieldsCount[ $value["strGroupField"] ] < 2 ||336				$yAxis && $yFieldsCount[ $value["strGroupField"] ] < 2 )337			{338				$groupFields[ $ind ]["label"] = $this->pSet->label( $value["strGroupField"] );339			}340			else341			{342				$groupFields[ $ind ]["label"] = $this->pSet->label( $value["strGroupField"] ) . " - " . CrossTableReport::getCrossIntervalName( $this->pSet->getFieldType( $value["strGroupField"] ), $value["groupInterval"] );343 344			}345 346			$groupFields[ $ind ]["uniqueName"] = true;347			$groupFields[ $ind ]["int_type"] = $value["groupInterval"];348 349			if( !$xNames[ $value["strGroupField"] ] )350				$xNames[ $value["strGroupField"] ] = array();351 352			if( !$yNames[ $value["strGroupField"] ] )353				$yNames[ $value["strGroupField"] ] = array();354 355			if( $value["crossTabAxis"] == 0 )356			{357				$groupFields[ $ind ]["group_type"] = "x";358				$xNames[ $value["strGroupField"] ][] = $ind;359			}360			elseif( $value["crossTabAxis"] == 1 )361			{362				$groupFields[ $ind ]["group_type"] = "y";363				$yNames[ $value["strGroupField"] ][] = $ind;364			}365			else366			{367				$groupFields[ $ind ]["group_type"] = "all";368				$xNames[ $value["strGroupField"] ][] = $ind;369				$yNames[ $value["strGroupField"] ][] = $ind;370			}371		}372 373 374		foreach( $xNames as $fName => $indices )375		{376			if( count( $indices ) > 1 )377			{378				foreach( $indices as $ind )379				{380					$groupFields[ $ind ]["uniqueName"] = false;381				}382			}383		}384 385 386		foreach( $yNames as $fName => $indices )387		{388			if( count( $indices ) > 1 )389			{390				foreach( $indices as $ind )391				{392					$groupFields[ $ind ]["uniqueName"] = false;393				}394			}395		}396 397		return $groupFields;398	}399 400	/**401	 * Get data for crosstab and assign with xt402	 * @param &Array _options403	 */404	public function setCrosstabData( &$_options )405	{406		if( $this->pSetSearch->noRecordsOnFirstPage() && !$this->isSearchFunctionalityActivated() )407		{408			$this->xt->assign("container_grid", false);409			$this->showNoRecordsMessage();410		}411 412		include_once( getabspath("classes/crosstable_report.php") );413 414		$params = array();415 416		$params["selectedAxis"] = $this->selectedAxis;417		$params["x"] = $this->x;418		$params["y"] = $this->y;419		$params["data"] = $this->dataField;420		$params["xType"] = $this->xType;421		$params["yType"] = $this->yType;422		$params["operation"] = $this->operation;423 424		$params["headerClass"] = $this->getFieldClass( $this->x );425		$params["dataClass"] = $this->getFieldClass( $this->dataField );426 427		$params["tableName"] = $this->tName;428		$params["pageType"] = $this->pageType;429 430		$params["groupFields"] = $this->getCrossGroupFieldsSettings( $_options["repGroupFields"] );431 432		$params["xSummary"] = $this->pSet->reportHasHorizontalSummary();433		$params["ySummary"] = $this->pSet->reportHasVerticalSummary();434		$params["totalSummary"] = $params["xSummary"] || $params["ySummary"];435 436 437		foreach( $_options["fieldsArr"] as $ind => $value )438		{439			$params["totals"][ $value["name"] ]["name"] = $value["name"];440			$params["totals"][ $value["name"] ]["label"] = $value["label"];441 442			$params["totals"][ $value["name"] ]["max"] = $value["totalMax"];443			$params["totals"][ $value["name"] ]["min"] = $value["totalMin"];444			$params["totals"][ $value["name"] ]["sum"] = $value["totalSum"];445			$params["totals"][ $value["name"] ]["avg"] = $value["totalAvg"];446		}447 448		if( $this->pdfJsonMode() )449			$params["pdfJSON"] = true;450 451		$this->crossTableObj = new CrossTableReport( $params, $this );452 453		if( $this->crosstableRefresh )454		{455			$this->refreshCrossTable();456			return;457		}458 459		if( $this->crossTableObj->isEmpty() )460		{461			$this->noRecordsFound = true;462			$this->jsSettings["tableSettings"][ $this->tName ]["crossParams"] = $this->getCurrentCrossParams();463		}464 465		$this->crossTableCommonAssign( $params["totalSummary"] );466	}467 468	/**469	 *470	 */471	protected function refreshCrossTable()472	{473		$reportData = array();474 475		$reportData["rowsInfo"] = $this->crossTableObj->getCrossTableData();476		$reportData["totalsName"] = $this->crossTableObj->getTotalsName();477		$reportData["columnSummary"] = $this->crossTableObj->getCrossTableSummary();478		$reportData["totalSummary"] = $this->crossTableObj->getTotalSummary();479 480		$reportData["groupFuncCtrl"] = $this->getOperationCtrlMarkup();481		$reportData["dataClass"] = $this->getFieldClass( $this->dataField );482 483		echo printJSON( $reportData );484		exit();485	}486 487	/**488	 * @param String axis489	 * @return String490	 */491	protected function getCrossFieldCtrlMarkup( $axis )492	{493		$classAttr = "form-control bs-cross-dd".$axis;494 495		$options = array();496		$lastLabel = "";497		foreach( $this->crossTableObj->getCrossFieldsData( $axis ) as $fData )498		{499			$intervalDataAttr = $fData["intervalType"] ? " data-".$axis."type=\"". $fData["intervalType"] ."\" " : "";500			$lastLabel = $fData["label"];501			$options[] = "<option ". $intervalDataAttr ." value=\"".$fData["value"]."\" ".$fData["selected"].">".$lastLabel."</option>";502		}503 504		$hiddenAttr = "";505		$labelTag = "";506		if ( count($options) < 2 )507		{508			$labelTag = "<span class=\"" . $classAttr . " like-text\">". $lastLabel ."</span>";509			$hiddenAttr = "style=\"display: none;\"";510		}511 512		return "<select ".$hiddenAttr." id=\"select_group_" . $axis . $this->id."\" class=\"" . $classAttr . "\">". implode("", $options) ."</select>" . $labelTag ;513	}514 515	/**516	 * @return String517	 */518	protected function getDataFieldCtrlMarkup()519	{520		$classAttr = "form-control bs-cross-ddvalue";521 522		$options = array();523		$lastLabel = "";524		foreach( $this->crossTableObj->getDataFieldsList() as $fData )525		{526			$lastLabel = runner_htmlspecialchars( $fData["label"] );527			$options[] = "<option value=\"". $fData["value"] ."\" ". $fData["selected"] .">". $lastLabel ."</option>";528		}529 530		$hiddenAttr = "";531		$labelTag = "";532		if ( count($options) < 2 )533		{534			$labelTag = "<span class=\"" . $classAttr . " like-text\">". $lastLabel ."</span>";535			$hiddenAttr = "style=\"display: none;\"";536		}537 538		return "<select ".$hiddenAttr." id=\"select_data".$this->id."\" class=\"" . $classAttr . "\">". implode("", $options) ."</select>" . $labelTag;539 540 541	}542 543	/**544	 * @deprecated545	 * @return String546	 */547	protected function getOldOperationCtrlMarkup()548	{549		$inputCtrls = array();550		foreach( $this->crossTableObj->getCurrentOperationList() as $opData )551		{552			$cheked = $opData["selected"] == "selected" ? "checked" : "";553			$inputCtrls[] = "<input type=radio value='".$opData["value"]."' name=\"group_func".$this->id."\" ".$cheked."> ".$opData["label"];554		}555 556		return implode( "&nbsp;&nbsp;", $inputCtrls );557	}558 559	/**560	 * @return String561	 */562	protected function getOperationCtrlMarkup()563	{564		$options = array();565		$lastLabel = "";566		foreach( $this->crossTableObj->getCurrentOperationList() as $opData )567		{568			$lastLabel = runner_htmlspecialchars( $opData["label"] );569			$options[] = "<option value=\"". $opData["value"] ."\" ". $opData["selected"] .">". $lastLabel ."</option>";570		}571 572		if ( count($options) < 2 )573			return  "<span id=\"group_func". $this->id."\" class=\"bs-cross-ddgroup form-control like-text\">". $lastLabel ."</span>";574 575		return "<select id=\"group_func". $this->id ."\" class=\"bs-cross-ddgroup form-control\">". implode("", $options) ."</select>";576	}577 578	/**579	 * Assign values obtained from crossTable object to580	 * the basic cross table xt variables581	 * @param Boolean showSummary582	 */583	protected function crossTableCommonAssign( $showSummary )584	{585		$this->xt->assign( "cross_controls", true );586 587		$this->xt->assign( "select_group_x", $this->getCrossFieldCtrlMarkup("x") );588		$this->xt->assign( "select_group_y", $this->getCrossFieldCtrlMarkup("y") );589		$this->xt->assign("select_data", $this->getDataFieldCtrlMarkup() );590		$this->xt->assign( "select_group", $this->getOperationCtrlMarkup() );591 592		$this->hideItemType("details_found");593		$this->hideItemType("page_size");594 595 596		$this->xt->assign( "totals", $this->crossTableObj->getTotalsName() );597 598		$grid_row["data"] = $this->crossTableObj->getCrossTableData();599 600		if( !Security::permissionsAvailable() ) {601			$allow_export = true;602		} else {603			$allow_export = $this->permis[ $this->tName ]["export"];604		}605		$this->xt->assign( "export_link", $allow_export && !$this->noRecordsFound );606 607		$this->xt->assign( "prints_block", $this->printAvailable() && !$this->noRecordsFound );608 609		if ( !$this->isDashboardElement() )610			$this->xt->assign("print_friendly", $this->printAvailable() && !$this->noRecordsFound );611 612 613		if( !$this->noRecordsFound )614		{615			$this->xt->assign("grid_row", $grid_row);616			$headers = $this->crossTableObj->getCrossTableHeader();617			$this->xt->assignbyref("group_header", $headers );618			$this->xt->assignbyref("col_summary", $this->crossTableObj->getCrossTableSummary());619			$this->xt->assignbyref("total_summary", $this->crossTableObj->getTotalSummary());620			$this->xt->assignbyref("summary_class", $this->getFieldClass( $this->dataField ));621			$this->xt->assign("cross_totals", $showSummary);622 623			$headerColspan = count( $grid_row["data"][0]["row_record"]["data"] );624 625			if( $grid_row["data"][0]["row_record"]["cross_totals"] )626				++$headerColspan;627 628			if( $headerColspan > 1 )629				$this->xt->assign( "xselcell_attrs", "colspan=".$headerColspan );630		}631 632		$this->xt->assign( "grid_header", !$this->noRecordsFound );633 634		//$this->xt->assign("crosstable_attrs", "&x=".$this->x."&y=".$this->y."&data=".$this->dataField."&op=".$this->operation);635	}636 637 638	/**639	 * Get data for standart report and assign with xt640	 * @param &Array _options641	 */642	public function setStandartData(&$_options)643	{644		include_once(getabspath('classes/reportlib.php'));645 646		$pageSize = $this->pageSize;647		if ( $this->pageSize == -1 ) {648			$pageSize = 0;649		}650 651		$rb = new Report( $this->pSet->getOrderIndexes(), $this->connection, $pageSize, 0, $_options, $this );652 653		$this->arrReport = $rb->getReport( $this->pagestart );654 655		$this->setRecordsId();656		$this->setDetailLinks();657 658		$this->buildPagination();659 660		$this->standardReportCommonAssign();661		$this->assignColumnHeaderClasses();662	}663 664	/**665	 * Get where clause for an active master-detail relationship666	 * @return string667	 */668	public function getMasterTableSQLClause()669	{670		if( $this->mode == REPORT_DASHBOARD && !isset($this->dashElementData["masterTable"]) )671			return "";672		return parent::getMasterTableSQLClause();673	}674 675	/**676	 * Assign the basic cross table xt variables677	 */678	protected function standardReportCommonAssign()679	{680		$this->xt->assign(GoodFieldName($this->tName)."_dtable_column", true); //fix it!681		$this->xt->assign("dtables_link", true);682 683		foreach($this->arrReport['page'] as $key => $value)684		{685			$this->xt->assign($key, $value);686		}687 688		foreach($this->arrReport['global'] as $key => $value)689		{690			$this->xt->assign($key, $value);691		}692 693		if( !!$this->arrReport['list'] )694			$this->xt->assign('grid_row', array('data' => $this->arrReport['list']));695		else696			$this->noRecordsFound = true;697 698		if( !Security::permissionsAvailable() ) {699			$allow_export = true;700			$allow_search = true;701		} else {702			$allow_export = $this->permis[ $this->tName ]["export"];703			$allow_search = $this->permis[ $this->tName ]["search"];704		}705		$this->xt->assign("export_link", $allow_export && $this->arrReport['countRows'] > 0);706		$this->xt->assign("prints_block", $allow_export && $this->arrReport['countRows'] > 0);707		$this->xt->assign("printall_link", $allow_export && $this->arrReport['countRows'] > $this->pageSize && $this->pageSize > 0);708		$this->xt->assign("print_recspp", $this->pSet->getReportPrintGroupsPerPage() );709 710		if ( !$this->isDashboardElement() )711		{712			$this->xt->assign("print_friendly", $this->printAvailable() && $this->arrReport['countRows'] > 0 );713			$this->xt->assign("print_friendly_all", $this->printAvailable() && $this->arrReport['countRows'] > 0);714		}715 716		if( $this->mode == REPORT_SIMPLE && $allow_search && !!$this->arrGroupsPerPage )717		{718			$this->xt->assign("recordspp_block", true);719			$this->createPerPage();720		}721 722 723		$this->xt->assign("details_found", $this->arrReport['countRows'] != 0);724 725		if( $this->noRecordsFound )726		{727			$this->hideItemType("details_found");728			$this->hideItemType("page_size");729		}730 731		$this->xt->assign("details_block", $this->arrReport['countRows'] != 0);732		$this->xt->assign("records_found", $this->arrReport['countRows']);733		$this->xt->assign("pages_block", $this->arrReport['countRows'] != 0);734		$this->xt->assign("page", $this->myPage);735		$this->xt->assign("maxpages", $this->maxPages);736 737 738		$this->xt->assign( "global_summary", !$this->noRecordsFound );739		$this->xt->assign( "page_summary", !$this->noRecordsFound );740		$this->xt->assign( "summary_header", !$this->noRecordsFound );741 742		// tabular report743		$this->xt->assign( "grid_header", !$this->noRecordsFound );744	}745 746	/**747	 * Assign pagination_block, pagination xt variables748	 */749	public function buildPagination()750	{751		//	prepare for create pagination752		$this->maxPages = $this->arrReport['maxpages'];753 754		$lastrecord = $this->myPage * $this->pageSize;755		if( $this->pageSize < 0 || $lastrecord > $this->arrReport['countRows'] )756			$lastrecord = $this->arrReport['countRows'];757 758		$this->prepareRecordsIndicator( ( $this->myPage - 1 ) * $this->pageSize + 1, $lastrecord, $this->arrReport['countRows'] );759 760		$separator = "";761		$advSeparator = "";762 763		if($this->maxPages > 1)764		{765			$this->xt->assign("pagination_block", true);766			$pagination = '';767			$limit = 10;768			if( $this->mobileTemplateMode() )769				$limit = 5;770 771			$counterstart = $this->myPage - ($limit - 1);772			if($this->myPage % $limit != 0)773				$counterstart = $this->myPage -($this->myPage % $limit) + 1;774 775			$counterend = $counterstart + ($limit - 1);776			if($counterend > $this->maxPages)777				$counterend = $this->maxPages;778 779			if($counterstart != 1)780			{781				$pagination.= $this->getPaginationLink(1, "First").$advSeparator;782				$pagination.= $this->getPaginationLink($counterstart - 1, "Previous").$separator;783			}784 785			$pageLinks = "";786 787			for($counter = $counterstart; $counter <= $counterend; $counter ++)788			{789				$pageLinks .= $separator . $this->getPaginationLink($counter,$counter, $counter == $this->myPage );790			}791 792			$pagination.= $pageLinks;793 794			if($counterend != $this->maxPages)795			{796				$pagination.= $separator . $this->getPaginationLink($counterend + 1, "Next") . $advSeparator;797				$pagination.= $separator . $this->getPaginationLink($this->maxPages, "Last");798			}799 800			$pagination = '<nav><ul class="pagination" data-function="pagination' . $this->id . '">' . $pagination . '</ul></nav>';801 802			$this->xt->assign("pagination", $pagination);803		}804		else if( !$this->myPage )805		{806			$this->myPage = 1; //temporary fix807		}808	}809 810	protected function setRecordsId() {811		$recCount = count( $this->arrReport['list'] );812		for( $i = 0; $i < $recCount; ++$i ) {813			$this->genId();814			$this->arrReport['list'][$i]["recId"] = $this->recId;815		}816	}817 818	/**819	 * fix it!820	 */821	protected function setDetailLinks()822	{823		if( $this->mode == REPORT_DASHBOARD )824			return;825 826		//	no details in reports currently827		return;828 829		// set detail links830		foreach( $this->allDetailsTablesArr as $detailTableData )831		{832			// get perm for det tables833			$this->permis[ $detailTableData['dDataSourceTable'] ] = $this->getPermissions( $detailTableData['dDataSourceTable'] );834			// field names of detail keys of passed detail table, when current is master835			$this->detailKeysByD[] = $this->pSet->getDetailKeysByDetailTable( $detailTableData['dDataSourceTable'] );836		}837 838		$this->controlsMap['gridRows'] = array();839		$arrReportList = array();840		foreach ($this->arrReport['list'] as $key => $data)841		{842			if (!isset($data['row_data']))843				continue;844			$record = array();845			//$this->genId();846			$recId = $data["recId"];847 848			$gridRowInd = count($this->controlsMap['gridRows']);849			$this->controlsMap['gridRows'][$gridRowInd] = array();850			$this->controlsMap['gridRows'][$gridRowInd]['id'] = $recId;851			$this->controlsMap['gridRows'][$gridRowInd]['rowInd'] = $gridRowInd;852			//Add the connection with containing row. It's important for vertical layout's multiple records per row mode853			$this->controlsMap['gridRows'][$gridRowInd]['keyFields'] = array();854			$this->controlsMap['gridRows'][$gridRowInd]['keys'] = array();855 856			//	???857			for($i = 0; $i < count($tKeys); $i ++) {858				$this->controlsMap['gridRows'][$gridRowInd]['keyFields'][$i] = $tKeys[$i];859				$this->controlsMap['gridRows'][$gridRowInd]['keys'][$i] = $data[$tKeys[$i].'_value'];860			}861 862			$this->proccessDetailGridInfo($record, $data, $gridRowInd);863			$record["recordattrs"] = "data-record-id=\"".$recId."\"";864			//$record["recId"] = $recId;865			$record["rowattrs"] = " id=\"gridRow".$recId."\"";866			$arrReportList[$key] = array_merge_assoc($data, $record);867			$this->recIds[] = $recId;868		}869 870		foreach($arrReportList as $key => $data)871		{872			$this->arrReport['list'][$key] = $data;873		}874		// end set detail links875	}876 877 878	/**879	 * Prepare detail for edit and view880	 */881	public function prepareDetailsForEditViewPage()882	{883		$this->addButtonHandlers();884		$this->commonAssign();885 886		$this->setReportData( $this->getExtraReportParams() );887		$this->xt->assign("cross_controls", false);888 889 890		$this->xt->assign("grid_block", true);891		$this->xt->assign("recordspp_block", true);892 893		$this->doCommonAssignments();894 895		$this->createPerPage();896 897 898		$this->body["begin"] = '';899		$this->body["end"] = '';900		$this->xt->assign("body", $this->body);901	}902 903	/**904	 * @return Array905	 */906	public function getExtraReportParams()907	{908		$extraParams = array();909 910		if( !$this->crossTable )911		{912			$extraParams['tName'] = $this->tName;913			$extraParams['shortTName'] = $this->shortTableName;914			$extraParams['sessionPrefix'] = $this->sessionPrefix;915			$extraParams['shortTableName'] = $this->shortTableName;916 917			$extraParams['tKeyFields'] = $this->pSet->getTableKeys();918			$extraParams['repPageSummary'] = $this->pSet->reportHasPageSummary();919			$extraParams['repGlobalSummary'] = $this->pSet->reportHasGlobalSummary();920			$extraParams['repLayout'] = $this->pSet->getReportLayout();921			$extraParams['showGroupSummaryCount'] = $this->pSet->isGroupSummaryCountShown();922			$extraParams['repShowDet'] = $this->pSet->reportDetailsShown();923			// if any field used for totals924			$extraParams['isExistTotalFields'] = $this->pSet->reportTotalFieldsExist();925		}926 927		// report field info928		$extraParams['repGroupFields'] = $this->pSet->getReportGroupFieldsData();929		$extraParams['repGroupFieldsCount'] = count( $extraParams['repGroupFields'] );930 931		$paramfieldArr = array();932		$reportFields = $this->pSet->getFieldsList();933		foreach( $reportFields as $field )934		{935			$fieldArr = array();936			$fieldArr['name'] = $field;937			//'fName' added for maps938			$fieldArr['fName'] = $field;939			$fieldArr['label'] = $this->pSet->label( $field );940			$fieldArr['goodName'] = GoodFieldName( $field );941			$fieldArr['repPage'] = true; //"@f.bReportPage";942			$fieldArr['viewFormat'] = $this->pSet->getViewFormat( $field );943			$fieldArr['editFormat'] = $this->pSet->getEditFormat( $field );944 945			$fieldInfo = $this->pSet->reportFieldInfo( $field );946			if( $fieldInfo ) {947				$fieldArr['totalMax'] = !!$fieldInfo["max"];948				$fieldArr['totalMin'] = !!$fieldInfo["min"];949				$fieldArr['totalAvg'] = !!$fieldInfo["avg"];950				$fieldArr['totalSum'] = !!$fieldInfo["sum"];951			}952			$paramfieldArr[] = $fieldArr;953		}954 955		$extraParams['fieldsArr'] = $paramfieldArr;956 957		return $extraParams;958	}959 960	/**961	 * Assign recsPerPage, recsPerPage xt variables962	 */963	public function createPerPage()964	{965		$classString = 'class="form-control"';966		$allMessage = "All";967 968		$rpp = "<select ".$classString." id=\"recordspp".$this->id."\">";969 970		// use group fields on report page or not971		$reportGroupFields = $this->pSet->isReportWithGroups();972 973		if( $reportGroupFields )974		{975			for($i = 0; $i < count($this->arrGroupsPerPage); $i++)976			{977				if( $this->arrGroupsPerPage[$i] != -1 )978					$rpp.= "<option value=\"".$this->arrGroupsPerPage[$i]."\" ".($this->pageSize == $this->arrGroupsPerPage[$i] ? "selected" : "").">".$this->arrGroupsPerPage[$i]."</option>";979				else980					$rpp.= "<option value=\"-1\" ".($this->pageSize == $this->arrGroupsPerPage[$i] ? "selected" : "").">".$allMessage."</option>";981			}982		}983		else984		{985			for($i = 0; $i < count($this->arrRecsPerPage); $i++)986			{987				if( $this->arrRecsPerPage[$i] != -1 )988					$rpp.= "<option value=\"".$this->arrRecsPerPage[$i]."\" ".($this->pageSize == $this->arrRecsPerPage[$i] ? "selected" : "").">".$this->arrRecsPerPage[$i]."</option>";989				else990					$rpp.= "<option value=\"-1\" ".($this->pageSize == $this->arrRecsPerPage[$i] ? "selected" : "").">".$allMessage."</option>";991			}992		}993 994		$rpp.= "</select>";995 996		$this->xt->assign("grpsPerPage", $rpp);997	}998 999	/**1000	 *1001	 */1002	public function doCommonAssignments() //make it protected1003	{1004		$this->xt->assign("left_block", true);1005 1006		$this->assignBody();1007 1008		$this->setLangParams();1009 1010		//set the Search panel1011		$this->xt->assign("searchPanel", true);1012 1013		if( $this->isShowMenu() )1014			$this->xt->assign("menu_block", true);1015 1016		if( $this->mobileTemplateMode() )1017			$this->xt->assign('tableinfomobile_block', true);1018 1019 1020		if( !Security::permissionsAvailable() ) {1021			$allow_search = true;1022			$allow_export = true;1023		} else {1024			$allow_search = $this->permis[ $this->tName ]["search"];1025			$allow_export = $this->permis[ $this->tName ]["export"];1026		}1027 1028		$this->xt->assign("grid_block", $allow_search);1029		$this->xt->assign("toplinks_block", $allow_search);1030		$this->xt->assign("asearch_link", $allow_search);1031 1032		$this->xt->assign("print_link", $allow_export);1033		$this->xt->assign("printlink_attrs", "id=print_".$this->id." href='#'");1034		$this->xt->assign("printalllink_attrs", "id=printAll_".$this->id." href='#'");1035 1036		$this->xt->assign("excellink_attrs", "id=export_to_excel".$this->id." href='#'");1037		$this->xt->assign("wordlink_attrs", "id=export_to_word".$this->id." href='#'");1038		$this->xt->assign("pdflink_attrs", "id=export_to_pdf".$this->id." href='#'");1039 1040		$this->xt->assign("advsearchlink_attrs", "id=\"advButton".$this->id."\"");1041 1042		if( $this->noRecordsFound )1043			$this->showNoRecordsMessage();1044 1045		foreach( $this->pSet->getPageFields() as $f )1046		{1047			$gf = GoodFieldName($f);1048			$this->xt->assign( $gf . "_class", $this->fieldClass( $f ));1049			$this->xt->assign( $gf . "_align", $this->fieldAlign( $f ));1050		}1051 1052		if( $this->pdfJsonMode() )1053			$this->xt->assign( "pdfFonts", my_json_encode( getPdfFonts() ) );1054	}1055 1056	/**1057	 * Add common javascript files and code1058	 */1059	function addCommonJs()1060	{1061		parent::addCommonJs();1062	}1063 1064	/**1065	 *1066	 */1067	protected function assignBody()1068	{1069		$this->body["begin"].= GetBaseScriptsForPage( $this->isDisplayLoading );1070 1071		if( $this->mode == REPORT_SIMPLE && !$this->mobileTemplateMode() )1072			$this->body["begin"].= "<div id=\"search_suggest\" class=\"search_suggest\"></div>";1073 1074		// assign body end in such way, to prevent collisions with flyId increment1075		$this->body['end'] = XTempl::create_method_assignment( "assignBodyEnd", $this);1076 1077		$this->xt->assignbyref("body", $this->body);1078	}1079 1080	/**1081	 *1082	 */1083	public function beforeShowReport()1084	{1085		if( $this->eventsObject->exists("BeforeShowReport") )1086			$this->eventsObject->BeforeShowReport($this->xt, $this->templatefile, $this);1087	}1088 1089	/**1090	 * Display the report page1091	 */1092	public function showPage()1093	{1094		$this->beforeShowReport();1095 1096		if( $this->mode == REPORT_SIMPLE )1097		{1098			$this->display( $this->templatefile );1099			return;1100		}1101 1102		$this->body["begin"] = '';1103		$this->body["end"] = '';1104		$this->xt->assign("body", $this->body);1105 1106		$this->xt->assign("header", false);1107		$this->xt->assign("footer", false);1108 1109		if( $this->mode == REPORT_DASHBOARD )1110		{1111			$this->xt->prepare_template( $this->templatefile );1112 1113			$this->addControlsJSAndCSS();1114			$this->fillSetCntrlMaps();1115 1116			$returnJSON = array();1117			global $pagesData;1118			$returnJSON["pagesData"] = $pagesData;1119			$returnJSON['settings'] = $this->jsSettings;1120			$returnJSON['controlsMap'] = $this->controlsHTMLMap;1121			$returnJSON['viewControlsMap'] = $this->viewControlsHTMLMap;1122 1123			if( $this->formBricks["footer"] )1124				$returnJSON["footerCont"] = $this->fetchBlocksList( $this->formBricks["footer"], true );1125			if( $this->formBricks["header"] )1126				$returnJSON["headerCont"] = $this->fetchBlocksList( $this->formBricks["header"], true );1127 1128			//	prepend headerCont with the page title1129			$returnJSON['headerCont'] = '<span class="rnr-dbebrick">'1130				. $this->getPageTitle( $this->pageName, GoodFieldName($this->tName) )1131				. "</span>"1132				. $returnJSON['headerCont'];1133 1134			$icon = getIconHTML( $this->dashElementData["item"]["icon"] );1135			if( $icon )1136				$returnJSON["iconHtml"] = $icon;1137 1138 1139			$this->assignFormFooterAndHeaderBricks(false);1140			$this->xt->prepareContainers();1141 1142			$returnJSON["html"] = $this->fetchBlocksList( array( "above-grid_block", "grid_tabs", "grid_block" ) );1143			//$returnJSON["html"] = $this->xt->fetch_loaded("message_block").$this->xt->fetch_loaded("grid_block");1144 1145			$returnJSON['idStartFrom'] = $this->flyId;1146			$returnJSON['success'] = true;1147 1148			$returnJSON["additionalJS"] = $this->grabAllJsFiles();1149			$returnJSON["CSSFiles"] = $this->grabAllCSSFiles();1150 1151			echo printJSON($returnJSON);1152			exit();1153			return;1154		}1155 1156		if( $this->mode == REPORT_DETAILS || $this->mode == REPORT_DASHDETAILS )1157		{1158			$this->showDpAjax();1159			exit();1160			return;1161		}1162 1163		if( $this->mode && $this->mode == "listdetailspopup" ) //a currently unused option1164		{1165			$this->xt->assign("container_master", false);1166 1167			$this->xt->assign("cross_controls", false);1168			$this->xt->prepare_template($this->templatefile);1169			$respArr = array();1170			$respArr['success'] = true;1171			$respArr['body'] = $this->xt->fetch_loaded("body");1172			$respArr['counter'] = postvalue('counter');1173 1174			echo printJSON($respArr);1175			exit();1176			return;1177		}1178	}1179 1180	/**1181	 * Display the inline report preview in respone on an ajax-like request1182	 */1183	protected function showDpAjax()1184	{1185		$returnJSON = array();1186 1187		if( $this->mode == REPORT_DETAILS1188			&& $this->dashTName1189			&& $this->dashElementName1190			&& !$this->shouldDisplayDetailsPage()1191			&& ($this->masterPageType == PAGE_EDIT ||  $this->masterPageType == PAGE_VIEW)1192			)1193		{1194			$returnJSON['noData'] = true;1195			echo printJSON( $returnJSON );1196			return;1197		}1198 1199		if( $this->mode == REPORT_DETAILS1200			&& $this->masterPageType == PAGE_LIST

Showing the first 1,200 of 1408 lines. Download the file for the rest.