Merge pull request #6404 from eileenmcnaughton/master
[civicrm-core.git] / CRM / PCP / Form / Campaign.php
index 2dc0b891d78de58a77f91b3d6b64a7932e447658..129965934ccfb3d3f12ab512c30062a9e432c94e 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
@@ -86,6 +86,7 @@ class CRM_PCP_Form_Campaign extends CRM_Core_Form {
       $defaults['is_active'] = 1;
       $defaults['is_honor_roll'] = 1;
       $defaults['is_thermometer'] = 1;
+      $defaults['is_notify'] = 1;
     }
 
     $this->_contactID = CRM_Utils_Array::value('contact_id', $defaults);
@@ -95,7 +96,7 @@ class CRM_PCP_Form_Campaign extends CRM_Core_Form {
   }
 
   /**
-   * Build the form object
+   * Build the form object.
    *
    * @return void
    */
@@ -127,7 +128,23 @@ class CRM_PCP_Form_Campaign extends CRM_Core_Form {
 
     $this->addElement('checkbox', 'is_thermometer', ts('Progress Bar'));
     $this->addElement('checkbox', 'is_honor_roll', ts('Honor Roll'), NULL);
+    if ($this->_pageId) {
+      $params = array('id' => $this->_pageId);
+      CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $params, $pcpInfo);
+      $owner_notification_option = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCPBlock', $pcpInfo['pcp_block_id'], 'owner_notify_id');
+    }
+    else {
+      $owner_notification_option = CRM_PCP_BAO_PCP::getOwnerNotificationId($this->controller->get('component_page_id'), $this->_component ? $this->_component : 'contribute');
+    }
+    if ($owner_notification_option == CRM_Core_OptionGroup::getValue('pcp_owner_notify', 'owner_chooses', 'name')) {
+      $this->assign('owner_notification_option', TRUE);
+      $this->addElement('checkbox', 'is_notify', ts('Notify me via email when someone donates to my page'), NULL);
+    }
+
     $this->addElement('checkbox', 'is_active', ts('Active'));
+    if ($this->_context == 'dashboard') {
+      CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/admin/pcp', 'reset=1'));
+    }
 
     $this->addButtons(
       array(
@@ -146,7 +163,7 @@ class CRM_PCP_Form_Campaign extends CRM_Core_Form {
   }
 
   /**
-   * Global form rule
+   * Global form rule.
    *
    * @param array $fields
    *   The input form values.
@@ -170,14 +187,14 @@ class CRM_PCP_Form_Campaign extends CRM_Core_Form {
   }
 
   /**
-   * Process the form submission
+   * Process the form submission.
    *
    *
    * @return void
    */
   public function postProcess() {
     $params = $this->controller->exportValues($this->_name);
-    $checkBoxes = array('is_thermometer', 'is_honor_roll', 'is_active');
+    $checkBoxes = array('is_thermometer', 'is_honor_roll', 'is_active', 'is_notify');
 
     foreach ($checkBoxes as $key) {
       if (!isset($params[$key])) {
@@ -352,4 +369,5 @@ class CRM_PCP_Form_Campaign extends CRM_Core_Form {
       $session->pushUserContext(CRM_Utils_System::url('civicrm/admin/pcp', 'reset=1'));
     }
   }
+
 }