diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index 3b72580d73774d18a6589451aa0dd884327c3bc1..a6b4b9c4950b2614f47bd40ace87f88c0c5f3365 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -3361,5 +3361,35 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a } } } + + /* function used for showing charts on print screen */ + static function uploadChartImage() { + // upload strictly for '.png' images + $name = CRM_Utils_Request::retrieve('name', 'String', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET'); + if (preg_match('/\.png$/', trim($name))) { + // + // POST data is usually string data, but we are passing a RAW .png + // so PHP is a bit confused and $_POST is empty. But it has saved + // the raw bits into $HTTP_RAW_POST_DATA + // + $httpRawPostData = $GLOBALS['HTTP_RAW_POST_DATA']; + + // prepare the directory + $config = CRM_Core_Config::singleton(); + $defaultPath = str_replace('/persist/contribute/' , '/persist/', $config->imageUploadDir) . '/openFlashChart/'; + if (!file_exists($defaultPath)) { + mkdir($defaultPath, 0777, TRUE); + } + + // full path to the saved image including filename + $destination = $defaultPath . basename($name); + + //write and save + $jfh = fopen($destination, 'w') or die("can't open file"); + fwrite($jfh, $httpRawPostData); + fclose($jfh); + CRM_Utils_System::civiExit(); + } + } } diff --git a/CRM/Report/xml/Menu/Report.xml b/CRM/Report/xml/Menu/Report.xml index 4fe4972bf07a0456af68864c50f8d18ff46bc6ca..a338fc124bfa1e89e4fc5daf878c66a1de9ce827 100644 --- a/CRM/Report/xml/Menu/Report.xml +++ b/CRM/Report/xml/Menu/Report.xml @@ -70,4 +70,9 @@ <adminGroup>CiviReport</adminGroup> <icon>admin/small/report_list.gif</icon> </item> + <item> + <path>civicrm/report/chart</path> + <page_callback>CRM_Report_Form::uploadChartImage</page_callback> + <access_arguments>access CiviReport</access_arguments> + </item> </menu> diff --git a/templates/CRM/Report/Form.tpl b/templates/CRM/Report/Form.tpl index a1fa5f6a0bac2b8ba734c95738de2cbbf04a9820..3a701bedab43f502f8fd3e7131409f2e685152bf 100644 --- a/templates/CRM/Report/Form.tpl +++ b/templates/CRM/Report/Form.tpl @@ -23,7 +23,9 @@ | see the CiviCRM license FAQ at http://civicrm.org/licensing | +--------------------------------------------------------------------+ *} -{include file="CRM/common/crmeditable.tpl"} +{if $outputMode neq 'print'} + {include file="CRM/common/crmeditable.tpl"} +{/if} {* this div is being used to apply special css *} {if $section eq 1} <div class="crm-block crm-content-block crm-report-layoutGraph-form-block"> diff --git a/templates/CRM/Report/Form/Layout/Graph.tpl b/templates/CRM/Report/Form/Layout/Graph.tpl index 628e501ed8fc046cf43d6664f937875fbfebe2c0..dd340e8d806d4f3ce0f16a836c77518b4b7d091e 100644 --- a/templates/CRM/Report/Form/Layout/Graph.tpl +++ b/templates/CRM/Report/Form/Layout/Graph.tpl @@ -48,21 +48,16 @@ {literal} <script type="text/javascript"> cj( function( ) { - buildChart( ); + buildChart( ); - var resourceURL = "{/literal}{$config->userFrameworkResourceURL}{literal}"; - var uploadURL = "{/literal}{$uploadURL|cat:$chartId}{literal}.png"; - var uploadDir = "{/literal}{$config->imageUploadDir|replace:'/persist/contribute/':'/persist/'|cat:'openFlashChart/'}{literal}"; + cj("input[id$='submit_print'],input[id$='submit_pdf']").bind('click', function(e){ + // image creator php file path and append image name + var url = CRM.url('civicrm/report/chart', 'name=' + '{/literal}{$chartId}{literal}' + '.png'); - cj("input[id$='submit_print'],input[id$='submit_pdf']").bind('click', function(){ - var url = resourceURL +'packages/OpenFlashChart/php-ofc-library/ofc_upload_image.php'; // image creator php file path - url += '?name={/literal}{$chartId}{literal}.png'; // append image name - url += '&defaultPath=' + uploadDir; // append directory path - - //fetch object - swfobject.getObjectById("open_flash_chart_{/literal}{$uniqueId}{literal}").post_image( url, true, false ); - }); - }); + //fetch object and 'POST' image + swfobject.getObjectById("open_flash_chart_{/literal}{$uniqueId}{literal}").post_image(url, true, false); + }); + }); function buildChart( ) { var chartData = {/literal}{$openFlashChartData}{literal};