Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2015-03-09-21-44-34
[civicrm-core.git] / CRM / Pledge / Page / AJAX.php
old mode 100644 (file)
new mode 100755 (executable)
index 7faeff9..33cec34
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -23,7 +23,7 @@
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
 class CRM_Pledge_Page_AJAX {
 
   /**
-   * Function for building Pledge Name combo box
+   * Building Pledge Name combo box.
    */
-  static function pledgeName() {
+  public static function pledgeName() {
 
     $getRecords = FALSE;
     if (isset($_GET['name']) && $_GET['name']) {
-      $name        = CRM_Utils_Type::escape($_GET['name'], 'String');
-      $name        = str_replace('*', '%', $name);
+      $name = CRM_Utils_Type::escape($_GET['name'], 'String');
+      $name = str_replace('*', '%', $name);
       $whereClause = "p.creator_pledge_desc LIKE '%$name%' ";
-      $getRecords  = TRUE;
+      $getRecords = TRUE;
     }
 
     if (isset($_GET['id']) && is_numeric($_GET['id'])) {
-      $pledgeId    = CRM_Utils_Type::escape($_GET['id'], 'Integer');
+      $pledgeId = CRM_Utils_Type::escape($_GET['id'], 'Integer');
       $whereClause = "p.id = {$pledgeId} ";
-      $getRecords  = TRUE;
+      $getRecords = TRUE;
     }
 
     if ($getRecords) {
@@ -78,7 +78,8 @@ WHERE {$whereClause}
       if (!$name && isset($_GET['id'])) {
         $name = $_GET['id'];
       }
-      $elements[] = array('name' => trim($name, '*'),
+      $elements[] = array(
+        'name' => trim($name, '*'),
         'value' => trim($name, '*'),
       );
     }
@@ -87,5 +88,19 @@ WHERE {$whereClause}
     echo CRM_Utils_JSON::encode($elements, 'value');
     CRM_Utils_System::civiExit();
   }
-}
 
+  /**
+   * Function to setDefaults according to Pledge Id
+   * for batch entry pledges
+   */
+  public function getPledgeDefaults() {
+    $details = array();
+    if (!empty($_POST['pid'])) {
+      $pledgeID = CRM_Utils_Type::escape($_POST['pid'], 'Integer');
+      $details = CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment($pledgeID);
+    }
+    echo json_encode($details);
+    CRM_Utils_System::civiExit();
+  }
+
+}