Printer PDF advice needed

Hi all,

I’m building a custom module on 7.10.6 and adding a Print PDF button, I’ve done this using theinstructions I found here

The button shows as expected but it doesn’t do anything, no errors, no nothing.

I assume at this point it relates to a mistake I’ve made in the view.details.php but I’m not experienced enough to say…


<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

require_once('include/MVC/View/views/view.detail.php');

class RemedialsViewDetail extends ViewDetail{

        function RemedialsViewDetail(){
                parent::ViewDetail();
        }

        function display(){
        $this->populateInvoiceTemplates();
        $this->displayPopupHtml();
        parent::display();
        }

        function populateInvoiceTemplates(){
        global $app_list_strings;
        $sql = "SELECT id, name FROM aos_pdf_templates WHERE deleted = 0 AND type='remedials' AND active = 1";


                $res = $this->bean->db->query($sql);
        $app_list_strings['template_ddown_c_list'] = array();
                while($row = $this->bean->db->fetchByAssoc($res)){
                        $app_list_strings['template_ddown_c_list'][$row['id']] = $row['name'];
                }
        }
}
?>

Could someone point me in the right direction? Anything to check? My module is called Remedials although on the database and install path its remed_Remedials. I’m not sure which to use in some instances.

Thanks!

Are you looking at php_errors.log? Or whatever your web server log is calle.d You should have a PHP error there.

find / -name php_errors.log 2>/dev/null

If that doesn’t give you anything, look in your Apache configuration file to determine where it is, and what it is called.

Hi pgr, I’ve enabled the logging and still nothing.

It’s like the button doesn’t action trigger the function

Did you remember to do the Quick Repair and Rebuild?

Yes.

I’ve made a little progress; I copied the view.detail.php from another module and now the button sort of works.

It prompts me to select a template; which I have setup; but then I get an Invalid Module error on a white page.


<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

/*********************************************************************************
 * SugarCRM is a customer relationship management program developed by
 * SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License version 3 as published by the
 * Free Software Foundation with the addition of the following permission added
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301 USA.
 *
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
 *
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU General Public License version 3.
 *
 * In accordance with Section 7(b) of the GNU General Public License version 3,
 * these Appropriate Legal Notices must retain the display of the "Powered by
 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
 * technical reasons, the Appropriate Legal Notices must display the words
 * "Powered by SugarCRM".
 ********************************************************************************/

require_once('include/MVC/View/views/view.detail.php');

class remed_RemedialsViewDetail extends ViewDetail {


        function __construct(){
                parent::__construct();
        }

    /**
     * @deprecated deprecated since version 7.6, PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code, use __construct instead
     */
    function remed_RemedialsViewDetail(){
        $deprecatedMessage = 'PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code';
        if(isset($GLOBALS['log'])) {
            $GLOBALS['log']->deprecated($deprecatedMessage);
        }
        else {
            trigger_error($deprecatedMessage, E_USER_DEPRECATED);
        }
        self::__construct();
    }


        /**
         * display
         * Override the display method to support customization for the buttons that display
         * a popup and allow you to copy the account's address into the selected contacts.
         * The custom_code_billing and custom_code_shipping Smarty variables are found in
         * include/SugarFields/Fields/Address/DetailView.tpl (default).  If it's a English U.S.
         * locale then it'll use file include/SugarFields/Fields/Address/en_us.DetailView.tpl.
         */
        function display(){

                if(empty($this->bean->id)){
                        global $app_strings;
                        sugar_die($app_strings['ERROR_NO_RECORD']);
                }

                require_once('modules/AOS_PDF_Templates/formLetter.php');
                formLetter::DVPopupHtml('Remedials');

                $this->dv->process();

                if(ACLController::checkAccess('Contacts', 'edit', true)) {
                        $push_billing = $this->generatePushCode('billing');
                        $push_shipping = $this->generatePushCode('shipping');
                } else {
                        $push_billing = '';
                        $push_shipping = '';
                }

                $this->ss->assign("custom_code_billing", $push_billing);
                $this->ss->assign("custom_code_shipping", $push_shipping);

        if(empty($this->bean->id)){
                        global $app_strings;
                        sugar_die($app_strings['ERROR_NO_RECORD']);
                }
                echo $this->dv->display();
        }

        function generatePushCode($param)
        {
            global $mod_strings;
            $address_fields = array('street', 'city', 'state', 'postalcode','country');

    //        $html = '<input class="button" title="' . $mod_strings['LBL_PUSH_CONTACTS_BUTTON_LABEL'] .
                     '" type="button" onclick=\'open_contact_popup("Contacts", 600, 600, "&account_name=' .
                     $this->bean->name . '&html=change_address';

            foreach ($address_fields as $value) {
                $field_name = $param.'_address_'.$value;
     //           $html .= '&primary_address_'.$value.'='.str_replace(array("\rn", "\r", "\n"), array('','','<br>'), urlencode($this->bean->$field_name)) ;
            }

          //  $html .= '", true, false);\' value="' . $mod_strings['LBL_PUSH_CONTACTS_BUTTON_TITLE']. '">';
          //  return $html;
        }
}

so it looks like it stopping when it hits this bit of code in


if(!$bean){
    sugar_die("Invalid Module");
}

in AOS_PDF_Templates/formLetterPdf.php

Why wouldn’t it pass the module name to $bean? I’m not a developer so these things take a little bit longer for me!

Thanks

I would find it very strange if your PHP error log was empty. Normally there are plenty of messages there.

If you add this line to your code

$kaboom = 3/0;

You will surely get a “division by zero” warning in your PHP log. Make sure you see it (so you know you are in the right log, and it’s working).

There you will find the reason for your white screen.

After commenting out the code


if(!$bean){
sugar_die("Invalid Module");
}

I get this error…

Fatal error: Uncaught Error: Call to a member function retrieve() on boolean in /var/www/html/suitecrm/modules/AOS_PDF_Templates/formLetterPdf.php:87 Stack trace: #0 /var/www/html/suitecrm/include/MVC/Controller/SugarController.php(1014): require_once() #1 /var/www/html/suitecrm/include/MVC/Controller/SugarController.php(465): SugarController->handleEntryPoint() #2 /var/www/html/suitecrm/include/MVC/Controller/SugarController.php(373): SugarController->process() #3 /var/www/html/suitecrm/include/MVC/SugarApplication.php(109): SugarController->execute() #4 /var/www/html/suitecrm/index.php(52): SugarApplication->execute() #5 {main} thrown in /var/www/html/suitecrm/modules/AOS_PDF_Templates/formLetterPdf.php on line 87

ok, getting somewhere. Looks like the reason the code I commented out was saying invalid module was because I used Remedials instead of remed_Remedials in my view.details.php. Now getting a new php error.

Catchable fatal error: Object of class remed_Remedials could not be converted to string in /var/www/html/suitecrm/modules/AOS_PDF_Templates/formLetterPdf.php on line 49

It looks like your passing an object of that class where it’s expecting just a string (maybe the module name).

What exactly do you have in that file on line 49?