main_class ); //Allow plugins to work with reports. $report_obj->setUserObject( $this->getCurrentUserObject() ); $report_obj->setPermissionObject( $this->getPermissionObject() ); $this->setMainClassObject( $report_obj ); return true; } /** * @return null */ function getReportObject() { return $this->getMainClassObject(); } /** * @param bool $name * @return array|bool */ function getTemplate( $name = false ) { return $this->returnHandler( $this->getReportObject()->getTemplate( $name ) ); } /** * @return array|bool */ function getConfig() { return $this->returnHandler( $this->getReportObject()->getConfig() ); } /** * @param bool $data * @return array|bool */ function setConfig( $data = false ) { return $this->returnHandler( $this->getReportObject()->setConfig( $data ) ); } /** * @return array|bool */ function getOtherConfig() { return $this->returnHandler( $this->getReportObject()->getOtherConfig() ); } /** * @return array|bool */ function getChartConfig() { return $this->returnHandler( $this->getReportObject()->getChartConfig() ); } /** * @param bool $data * @return array|bool */ function setCompanyFormConfig( $data = false ) { if ( $this->getReportObject()->checkPermissions() == true ) { return $this->returnHandler( $this->getReportObject()->setCompanyFormConfig( $data ) ); } return $this->returnHandler( false, 'VALIDATION', TTi18n::getText( 'PERMISSION DENIED' ) ); } /** * @return array|bool */ function getCompanyFormConfig() { if ( $this->getReportObject()->checkPermissions() == true ) { return $this->returnHandler( $this->getReportObject()->getCompanyFormConfig() ); } return $this->returnHandler( false, 'VALIDATION', TTi18n::getText( 'PERMISSION DENIED' ) ); } /** * @param bool $config * @param string $format * @return array|bool */ function validateReport( $config = false, $format = 'pdf' ) { $this->getReportObject()->setConfig( $config ); //Set config first, so checkPermissions can check/modify data in the config for Printing timesheets for regular employees. if ( $this->getReportObject()->checkPermissions() == true ) { $validation_obj = $this->getReportObject()->validateConfig( $format ); if ( $validation_obj->isValid() == false ) { return $this->returnHandler( false, 'VALIDATION', TTi18n::getText( 'INVALID DATA' ), [ 0 => $validation_obj->getErrorsArray() ], [ 'total_records' => 1, 'valid_records' => 0 ] ); } } else { //Display permission denied error message to user. $validator = new Validator(); $validator->isTrue( 'PERMISSION', false, TTi18n::getText( 'Permission Denied' ) ); return $this->returnHandler( false, 'VALIDATION', TTi18n::getText( 'INVALID DATA' ), [ 0 => $validator->getErrorsArray() ], [ 'total_records' => 1, 'valid_records' => 0 ] ); //return $this->getPermissionObject()->PermissionDenied(); //This won't display anything to the end-user, which should probably be fixed and used instead when we have more time. } return $this->returnHandler( true ); } /** * Use JSON API to download PDF files. * @param bool $config * @param string $format * @return array|bool */ function getReport( $config = false, $format = 'pdf' ) { if ( is_string( $format ) == false || $format == '' ) { return $this->returnHandler( false, 'VALIDATION', TTi18n::getText( 'Format is invalid' ) ); } if ( Misc::isSystemLoadValid() == false ) { return $this->returnHandler( false, 'VALIDATION', TTi18n::getText( 'Please try again later...' ) ); } if ( $this->getPermissionObject()->checkAuthenticationType( 700 ) == false ) { //700=HTTP Auth with username/password return $this->getPermissionObject()->AuthenticationTypeDenied(); } if ( is_object( $this->getReportObject()->getUserObject() ) && $this->getReportObject()->getUserObject()->getStatus() != 10 ) { //10=Active -- Make sure user record is active as well. return $this->getPermissionObject()->PermissionDenied( false, TTi18n::getText( 'Employee status must be Active to view reports' ) ); } //ProgressBar always needs to be set early to make sure validation errors are always reported to the user. //Copy progress bar from Report object to this API object so returnHandler() can attach any error messages or stop it when needed. if ( $this->isProgressBarStarted() == false ) { $this->setProgressBarObject( $this->getReportObject()->getProgressBarObject() ); } $format = Misc::trimSortPrefix( $format ); Debug::Text( 'Format: ' . $format, __FILE__, __LINE__, __METHOD__, 10 ); $this->getReportObject()->setConfig( $config ); //Set config first, so checkPermissions can check/modify data in the config for Printing timesheets for regular employees. if ( $this->getReportObject()->checkPermissions() == true ) { $this->getReportObject()->setAPIMessageID( $this->getAPIMessageID() ); //This must be set *after* the all constructor functions are called, as its primarily called from JSON. $validation_obj = $this->getReportObject()->validateConfig( $format ); if ( $validation_obj->isValid() == true ) { //return Misc::APIFileDownload( 'report.pdf', 'application/pdf', $this->getReportObject()->getOutput( $format ) ); $output_arr = $this->getReportObject()->getOutput( $format ); if ( isset( $output_arr['file_name'] ) && isset( $output_arr['mime_type'] ) && isset( $output_arr['data'] ) ) { //If using the SOAP API, return data base64 encoded so it can be decoded on the client side. if ( defined( 'TIMETREX_SOAP_API' ) && TIMETREX_SOAP_API == true ) { $output_arr['data'] = base64_encode( $output_arr['data'] ); return $this->returnHandler( $output_arr ); } else { if ( $output_arr['mime_type'] === 'text/html' ) { return $this->returnHandler( $output_arr['data'] ); } else { Misc::APIFileDownload( $output_arr['file_name'], $output_arr['mime_type'], $output_arr['data'] ); return null; //Don't send any additional data, so JSON encoding doesn't corrupt the download. } } } else if ( isset( $output_arr['api_retval'] ) ) { //Pass through validation errors. Debug::Text( 'Report returned VALIDATION error, passing through...', __FILE__, __LINE__, __METHOD__, 10 ); return $this->returnHandler( $output_arr['api_retval'], $output_arr['api_details']['code'], $output_arr['api_details']['description'] ); //return $this->returnHandler( FALSE, 'VALIDATION', TTi18n::getText('Please try again later...') ); } else if ( $output_arr !== false ) { //Likely RAW data, return untouched. return $this->returnHandler( $output_arr ); } else { //getOutput() returned FALSE, some error occurred. Likely load too high though. //return $this->returnHandler( FALSE, 'VALIDATION', TTi18n::getText('Error generating report...') ); return $this->returnHandler( false, 'VALIDATION', TTi18n::getText( 'ERROR: Report is too large, please try again later or narrow your search criteria to decrease the size of your report' ) . '...' ); } } else { return $this->returnHandler( false, 'VALIDATION', TTi18n::getText( 'INVALID DATA' ), [ 0 => $validation_obj->getErrorsArray() ], [ 'total_records' => 1, 'valid_records' => 0 ] ); } } return $this->returnHandler( false, 'VALIDATION', TTi18n::getText( 'PERMISSION DENIED' ) ); } } ?>