CRM-12926 : convert the flash to image and upload the image
[civicrm-core.git] / CRM / Report / Form.php
index 3b72580d73774d18a6589451aa0dd884327c3bc1..a6b4b9c4950b2614f47bd40ace87f88c0c5f3365 100644 (file)
@@ -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();
+    }
+  }
 }