Merge branch 'phpunit-ob-fix' of https://github.com/giant-rabbit/civicrm-core into...
[civicrm-core.git] / CRM / Contact / Form / Task / PDFLetterCommon.php
index 5127d365d14e510132beda06af9c916b47175e25..ea36fb09d5b8a5af671df926b9f5f66b4355b117 100644 (file)
@@ -40,9 +40,9 @@
 class CRM_Contact_Form_Task_PDFLetterCommon {
 
   /**
-   * build all the data structures needed to build the form
+   * Build all the data structures needed to build the form
    *
-   * @param $form
+   * @param CRM_Core_Form $form
    *
    * @return void
    * @access public
@@ -64,8 +64,8 @@ class CRM_Contact_Form_Task_PDFLetterCommon {
   }
 
   /**
-   * @param $form
-   * @param $cid
+   * @param CRM_Core_Form $form
+   * @param int $cid
    */
   static function preProcessSingle(&$form, $cid) {
     $form->_contactIds = array($cid);
@@ -74,7 +74,7 @@ class CRM_Contact_Form_Task_PDFLetterCommon {
   }
 
   /**
-   * Build the form
+   * Build the form object
    *
    * @var CRM_Core_Form $form
    *
@@ -155,6 +155,17 @@ class CRM_Contact_Form_Task_PDFLetterCommon {
       array('size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"),
       TRUE
     );
+
+    $config = CRM_Core_Config::singleton();
+    if ($config->wkhtmltopdfPath == false) {
+      $form->add(
+        'text',
+        'stationery',
+        ts('Stationery (relative path to PDF you wish to use as the background)'),
+        array('size' => 25, 'maxlength' => 900, 'onkeyup' => "showUpdateFormatChkBox();"),
+        FALSE
+      );
+    }
     $form->add('checkbox', 'bind_format', ts('Always use this Page Format with the selected Template'));
     $form->add('checkbox', 'update_format', ts('Update Page Format (this will affect all templates that use this format)'));
 
@@ -164,53 +175,19 @@ class CRM_Contact_Form_Task_PDFLetterCommon {
 
     CRM_Mailing_BAO_Mailing::commonLetterCompose($form);
 
-    if ($form->_single) {
-      $cancelURL = CRM_Utils_System::url(
-        'civicrm/contact/view',
-        "reset=1&cid={$form->_cid}&selectedChild=activity",
-        FALSE,
-        NULL,
-        FALSE
+    $buttons = array();
+    if ($form->get('action') != CRM_Core_Action::VIEW) {
+      $buttons[] = array(
+        'type' => 'submit',
+        'name' => $form->_single ? ts('Make PDF') : ts('Make PDFs'),
+        'isDefault' => TRUE,
       );
-      if ($form->get('action') == CRM_Core_Action::VIEW) {
-        $form->addButtons(array(
-            array(
-              'type' => 'cancel',
-              'name' => ts('Done'),
-              'js' => array('onclick' => "location.href='{$cancelURL}'; return false;"),
-            ),
-          )
-        );
-      }
-      else {
-        $form->addButtons(array(
-            array(
-              'type' => 'submit',
-              'name' => ts('Make PDF Letter'),
-              'isDefault' => TRUE,
-            ),
-            array(
-              'type' => 'cancel',
-              'name' => ts('Done'),
-              'js' => array('onclick' => "location.href='{$cancelURL}'; return false;"),
-            ),
-          )
-        );
-      }
-    }
-    else {
-      $form->addButtons(array(
-        array(
-          'type' => 'submit',
-          'name' => ts('Make PDF Letters'),
-          'isDefault' => TRUE,
-        ),
-        array(
-          'type' => 'cancel',
-          'name' => ts('Done'),
-        ),
-      ));
     }
+    $buttons[] = array(
+      'type' => 'cancel',
+      'name' => $form->get('action') == CRM_Core_Action::VIEW ? ts('Done') : ts('Cancel'),
+    );
+    $form->addButtons($buttons);
 
     $form->addFormRule(array('CRM_Contact_Form_Task_PDFLetterCommon', 'formRule'), $form);
   }
@@ -225,7 +202,7 @@ class CRM_Contact_Form_Task_PDFLetterCommon {
   }
 
   /**
-   * form rule
+   * Form rule
    *
    * @param array $fields    the input form values
    * @param array $dontCare
@@ -259,11 +236,11 @@ class CRM_Contact_Form_Task_PDFLetterCommon {
   }
 
   /**
-   * part of the post process which prepare and extract information from the template
+   * Part of the post process which prepare and extract information from the template
    *
    * @access protected
    *
-   * @param $form
+   * @param CRM_Core_Form $form
    *
    * @return array( $categories, $html_message, $messageToken, $returnProperties )
    */
@@ -334,11 +311,11 @@ class CRM_Contact_Form_Task_PDFLetterCommon {
   }
 
   /**
-   * process the form after the input has been submitted and validated
+   * Process the form after the input has been submitted and validated
    *
    * @access public
    *
-   * @param $form
+   * @param CRM_Core_Form $form
    *
    * @return void
    */
@@ -387,7 +364,7 @@ class CRM_Contact_Form_Task_PDFLetterCommon {
   }
 
   /**
-   * @param $form
+   * @param CRM_Core_Form $form
    * @param $html_message
    * @param $contactIds
    *