Merge pull request #4961 from pratikshad/core-bugs
[civicrm-core.git] / CRM / Contribute / Page / Tab.php
index c63ae358cf635297480b17a805e054fccfa4311d..12a8f68c06d6c65d6116c8a2734b15d996aa5ded 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -38,7 +38,6 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page {
    * The action links that we need to display for the browse screen
    *
    * @var array
-   * @static
    */
   static $_links = NULL;
   static $_recurLinks = NULL;
@@ -46,8 +45,6 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page {
   public $_contactId = NULL;
   public $_crid = NULL;
 
-  //end of function
-
   /**
    * This method returns the links that are given for recur search row.
    * currently the links added for each row are:
@@ -59,9 +56,8 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page {
    * @param string $context
    *
    * @return array
-   * @access public
    */
-  static function &recurLinks($recurID = FALSE, $context = 'contribution') {
+  public static function &recurLinks($recurID = FALSE, $context = 'contribution') {
     if (!(self::$_links)) {
       self::$_links = array(
         CRM_Core_Action::VIEW => array(
@@ -86,13 +82,14 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page {
 
     if ($recurID) {
       $paymentProcessorObj = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($recurID, 'recur', 'obj');
-      if (is_object( $paymentProcessorObj) && $paymentProcessorObj->isSupported('cancelSubscription')) {
+      if (is_object($paymentProcessorObj) && $paymentProcessorObj->isSupported('cancelSubscription')) {
         unset(self::$_links[CRM_Core_Action::DISABLE]['extra'], self::$_links[CRM_Core_Action::DISABLE]['ref']);
         self::$_links[CRM_Core_Action::DISABLE]['url'] = "civicrm/contribute/unsubscribe";
         self::$_links[CRM_Core_Action::DISABLE]['qs'] = "reset=1&crid=%%crid%%&cid=%%cid%%&context={$context}";
       }
-      if (is_object( $paymentProcessorObj) && $paymentProcessorObj->isSupported('updateSubscriptionBillingInfo')) {
-        self::$_links[CRM_Core_Action::RENEW] = array('name' => ts('Change Billing Details'),
+      if (is_object($paymentProcessorObj) && $paymentProcessorObj->isSupported('updateSubscriptionBillingInfo')) {
+        self::$_links[CRM_Core_Action::RENEW] = array(
+          'name' => ts('Change Billing Details'),
           'title' => ts('Change Billing Details'),
           'url' => 'civicrm/contribute/updatebilling',
           'qs' => "reset=1&crid=%%crid%%&cid=%%cid%%&context={$context}",
@@ -105,18 +102,16 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page {
   // end function
 
   /**
-   * This function is called when action is browse
+   * called when action is browse
    *
-   * return null
-   * @access public
    */
-  function browse() {
+  public function browse() {
     // add annual contribution
     $annual = array();
     list($annual['count'],
       $annual['amount'],
       $annual['avg']
-    ) = CRM_Contribute_BAO_Contribution::annual($this->_contactId);
+      ) = CRM_Contribute_BAO_Contribution::annual($this->_contactId);
     $this->assign('annual', $annual);
 
     $controller = new CRM_Core_Controller_Simple(
@@ -187,7 +182,7 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page {
       list($softCreditTotals['amount'],
         $softCreditTotals['avg'],
         $softCreditTotals['currency']
-      ) = CRM_Contribute_BAO_ContributionSoft::getSoftContributionTotals($this->_contactId, $isTest);
+        ) = CRM_Contribute_BAO_ContributionSoft::getSoftContributionTotals($this->_contactId, $isTest);
 
       $this->assign('softCredit', TRUE);
       $this->assign('softCreditRows', $softCreditList);
@@ -202,12 +197,11 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page {
   }
 
   /**
-   * This function is called when action is view
+   * called when action is view
    *
-   * return null
-   * @access public
+   * @return null
    */
-  function view() {
+  public function view() {
     $controller = new CRM_Core_Controller_Simple(
       'CRM_Contribute_Form_ContributionView',
       ts('View Contribution'),
@@ -221,12 +215,11 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page {
   }
 
   /**
-   * This function is called when action is update or new
+   * called when action is update or new
    *
-   * return null
-   * @access public
+   * @return null
    */
-  function edit() {
+  public function edit() {
     // set https for offline cc transaction
     $mode = CRM_Utils_Request::retrieve('mode', 'String', $this);
     if ($mode == 'test' || $mode == 'live') {
@@ -245,16 +238,22 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page {
     return $controller->run();
   }
 
-  function preProcess() {
-    $context       = CRM_Utils_Request::retrieve('context', 'String', $this);
+  public function preProcess() {
+    $context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
-    $this->_id     = CRM_Utils_Request::retrieve('id', 'Positive', $this);
+    $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
 
     if ($context == 'standalone') {
       $this->_action = CRM_Core_Action::ADD;
     }
     else {
-      $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
+      $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, empty($this->_id));
+      if (empty($this->_contactId)) {
+        $this->_contactId = civicrm_api3('contribution', 'getvalue', array(
+            'id' => $this->_id,
+            'return' => 'contact_id',
+          ));
+      }
       $this->assign('contactId', $this->_contactId);
 
       // check logged in url permission
@@ -270,13 +269,12 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page {
   }
 
   /**
-   * This function is the main function that is called when the page
+   * the main function that is called when the page
    * loads, it decides the which action has to be taken for the page.
    *
-   * return null
-   * @access public
+   * @return null
    */
-  function run() {
+  public function run() {
     $this->preProcess();
 
     // check if we can process credit card contribs
@@ -297,7 +295,7 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page {
     return parent::run();
   }
 
-  function setContext() {
+  public function setContext() {
     $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this);
     $context = CRM_Utils_Request::retrieve('context', 'String',
       $this, FALSE, 'search'
@@ -356,7 +354,7 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page {
         if ($context == 'advanced') {
           $url = CRM_Utils_System::url('civicrm/contact/search/advanced', $extraParams);
         }
-        else if ($searchContext) {
+        elseif ($searchContext) {
           $url = CRM_Utils_System::url("civicrm/$searchContext/search", $extraParams);
         }
         else {
@@ -434,7 +432,7 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page {
         break;
 
       case 'fulltext':
-        $keyName   = '&qfKey';
+        $keyName = '&qfKey';
         $urlParams = 'force=1';
         $urlString = 'civicrm/contact/search/custom';
         if ($this->_action == CRM_Core_Action::UPDATE) {
@@ -467,4 +465,3 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page {
     $session->pushUserContext($url);
   }
 }
-