How to overwrite the core file to remove the timezone from the print to pdf file, How can we do this through the customization?

How to overwrite the core file to remove the timezone from the print to pdf file, How can we do this through the customization?

Path: sugar\modules\Reports\sugarpdf\sugarpdf.reports.php

Code :  $this->SetHeaderData(PDF_SMALL_HEADER_LOGO, PDF_SMALL_HEADER_LOGO_WIDTH, $this->bean->name, $timedate->getNow(true)"));

$timedate->getNow(true) instead of this we need to replace "date("D M j G:i:s")

Parents
  • Hi ,

    Though it is not possible to edit the sugarpdf.reports.php, it is actually being extended by other sub-classes, which is the one you have to override. But - the only downside is that, you have to copy the whole file into your custom folder and customize it. 

    For example, for Summary report, the PDF file used is modules/Reports/sugarpdf/sugarpdf.summary.php, which extends sugarpdf.reports.php. So in order to override the report, you can copy the file from modules folder into custom/modules/Reports/sugarpdf/sugarpdf.summary.php and modify the preDisplay section to set the header that you need, eg:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    <?php
    class ReportsSugarpdfSummary extends ReportsSugarpdfReports
    {
    function preDisplay()
    {
    parent::preDisplay();
    //Set PDF document properties
    if ($this->bean->name == "untitled") {
    $this->SetHeaderData(PDF_SMALL_HEADER_LOGO, PDF_SMALL_HEADER_LOGO_WIDTH, $app_list_strings['moduleList'][$this->bean->module], date("D M j G:i:s"));
    } else {
    $this->SetHeaderData(PDF_SMALL_HEADER_LOGO, PDF_SMALL_HEADER_LOGO_WIDTH, $this->bean->name, date("D M j G:i:s"));
    }
    }
    function display()
    {
    // ... Copy and paste the code from modules/Reports/sugarpdf/sugarpdf.summary.php
    }
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    But - there is a downside to this method. Sugar currently doesn't accept custom class names, so you have to copy the entire file (with the same ClassName) from modules/Reports folder into the custom folder - which adds additional work of merge/update during Sugar Upgrades. 

  • I have tried by the same way but it's not working for me. 

  • , can you share the file and it's location? I can take a quick peek and see what's happening. 

  • File Path: custom/modules/Reports/sugarpdf/sugarpdf.summary.php

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    <?php
    class ReportsSugarpdfSummary extends ReportsSugarpdfReports
    {
    function preDisplay(){
    parent::preDisplay();
    //Set PDF document properties
    if($this->bean->name == "untitled") {
    $this->SetHeaderData(PDF_SMALL_HEADER_LOGO, PDF_SMALL_HEADER_LOGO_WIDTH, $app_list_strings['moduleList'][$this->bean->module], date("D M j G:i:s"));
    //$this->SetHeaderData(PDF_SMALL_HEADER_LOGO, PDF_SMALL_HEADER_LOGO_WIDTH, $app_list_strings['moduleList'][$this->bean->module]);
    } else {
    $this->SetHeaderData(PDF_SMALL_HEADER_LOGO, PDF_SMALL_HEADER_LOGO_WIDTH, $this->bean->name, date("D M j G:i:s"));//$timedate->getNow(true)
    //$this->SetHeaderData(PDF_SMALL_HEADER_LOGO, PDF_SMALL_HEADER_LOGO_WIDTH, $this->bean->name);//$timedate->getNow(true)
    }
    }
    function display()
    {
    global $locale;
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • The file and location looks correct to me. This raises a couple of questions:

    1. Did you do a quick repair before running the export?

    2. The override was only for the PDF Summary, so did you actually export a summary report? If not, can you give details on what kind of report you're trying to export? If you are trying to export a rows/columns report or a matrix report, it comes from a different file. You will have to extend the corresponding file:

    sugarpdf.detail_and_total.php
    sugarpdf.listview.php
    sugarpdf.reports.php
    sugarpdf.summary.php
    sugarpdf.summary_combo.php
    sugarpdf.total.php

    I have exactly the same file as you locally and I was able to see the difference in the summary report.

    Before:

    PDF

    After:

    PDF

Reply Children
  • Ah okay, looks like you're export summation+details, so the file you have to override is sugarpdf.summary_combo.php . sugarpdf.summary.php is just plain Summation report.

    You can see in the right top corner of the report, which mentions the "Report Type".


    Here are the 4 report types and their corresponding PDF generation files:

    Report Type PDF Template File
    Rows & Columns sugarpdf.listview.php
    Summation sugarpdf.summary.php
    Summation with Details sugarpdf.summary_combo.php
    Matrix sugarpdf.summary.php

  •   Thank you so much. It's Working for me.

  • Although, It is working on my local server but whenever i am trying to upload the package into other server it's showing the below error :  

    Files/custom/modules/Reports/sugarpdf/sugarpdf.reports.php
    Code attempted to call blacklisted function "getimagesize" on line 67
    Code attempted to call blacklisted function "getimagesize" on line 72
    Code attempted to call blacklisted function "getimagesize" on line 75

    How can i get rid from this. Please help!

  •  yea unfortunately, getimagesize is blacklisted. We could raise a Sugar ticket to allow custom class names for Sugar PDF, since we don't actually intend to use getimagesize here, we are only trying to extend the preDisplay method.

    The patch is simple, in : include/Sugarpdf/SugarpdfFactory.php->buildFromFile methed, they just have to use SugarAutoLoader::customClass instead of forcing the class to be 

    $class = ucfirst($module).'Sugarpdf'.ucfirst($type);

    What is the usual procedure to request such changes ?

    But for your change ,

    1. You don't have to export sugarpdf.reports.php since there is no change and we cannot override that file.

    2. For the summary pdf: you can change the code to use imagesx and imagesy instead of getimagesize.

    Eg: Change the following lines from:

    if (file_exists($imageFile) && getimagesize($imageFile) > 0) {
    $this->AddPage();
    list($width, $height) = getimagesize($imageFile);

    to something like:

    if (file_exists($imageFile) && verify_uploaded_image($imageFile)) {
    $this->AddPage();

    $chartImageResource = imagecreatefrompng($imageFile);
    $width = imagesx($chartImageResource);
    $height = imagesy($chartImageResource);
    imagedestroy($chartImageResource);

     
     
  • Thanks. I will try and let you know .

  • Your solution is working fine with getimagesize function but now it's showing the below error : 

    File Issues
    Files/custom/modules/Reports/sugarpdf/sugarpdf.summary.php
    Invalid usage of a function file_exists()
    Files/custom/modules/Reports/sugarpdf/sugarpdf.summary_combo.php
    Invalid usage of a function file_exists()

  • Yes, I got the exact alternative of file_exists(). It's Working for me. Thanks for you help Slight smile