Merge pull request #13689 from eileenmcnaughton/no_record_payment
[civicrm-core.git] / CRM / Profile / Form.php
index 6912994ce9b2a8fd01b4b64482399f1e94ab786f..4c110de5d40298124b7e6d14df29932ccf298f4f 100644 (file)
@@ -68,7 +68,7 @@ class CRM_Profile_Form extends CRM_Core_Form {
   /**
    * @var array details of the UFGroup used on this page
    */
-  protected $_ufGroup = array('name' => 'unknown');
+  protected $_ufGroup = ['name' => 'unknown'];
 
   /**
    * The group id that we are passing in url.
@@ -79,7 +79,7 @@ class CRM_Profile_Form extends CRM_Core_Form {
 
   /**
    * Name of button for saving matching contacts.
-   * @var
+   * @var string
    */
   protected $_duplicateButtonName;
   /**
@@ -113,6 +113,7 @@ class CRM_Profile_Form extends CRM_Core_Form {
   /**
    * Dedupe using a specific rule (CRM-6131).
    * Not currently exposed in profile settings, but can be set in a buildForm hook.
+   * @var int
    */
   public $_ruleGroupID = NULL;
 
@@ -137,8 +138,9 @@ class CRM_Profile_Form extends CRM_Core_Form {
   /**
    * Store profile ids if multiple profile ids are passed using comma separated.
    * Currently lets implement this functionality only for dialog mode.
+   * @var array
    */
-  protected $_profileIds = array();
+  protected $_profileIds = [];
 
   /**
    * Contact profile having activity fields?
@@ -318,7 +320,7 @@ class CRM_Profile_Form extends CRM_Core_Form {
       }
 
       if ($this->_multiRecord &&
-        !in_array($this->_multiRecord, array(CRM_Core_Action::UPDATE, CRM_Core_Action::ADD, CRM_Core_Action::DELETE))
+        !in_array($this->_multiRecord, [CRM_Core_Action::UPDATE, CRM_Core_Action::ADD, CRM_Core_Action::DELETE])
       ) {
         CRM_Core_Error::fatal(ts('Proper action not specified for this custom value record profile'));
       }
@@ -373,9 +375,9 @@ class CRM_Profile_Form extends CRM_Core_Form {
       $dao->free();
 
       if (!CRM_Utils_Array::value('is_active', $this->_ufGroup)) {
-        CRM_Core_Error::fatal(ts('The requested profile (gid=%1) is inactive or does not exist.', array(
+        CRM_Core_Error::fatal(ts('The requested profile (gid=%1) is inactive or does not exist.', [
           1 => $this->_gid,
-        )));
+        ]));
       }
     }
     $this->assign('ufGroupName', $this->_ufGroup['name']);
@@ -423,17 +425,17 @@ class CRM_Profile_Form extends CRM_Core_Form {
             && ($this->_multiRecord == CRM_Core_Action::UPDATE || $this->_multiRecord == CRM_Core_Action::DELETE)
           ) {
             CRM_Core_Error::fatal(ts('The requested Profile (gid=%1) requires record id while performing this action',
-              array(1 => $this->_gid)
+              [1 => $this->_gid]
             ));
           }
           elseif (empty($this->_multiRecordFields)) {
             CRM_Core_Error::fatal(ts('No Multi-Record Fields configured for this profile (gid=%1)',
-              array(1 => $this->_gid)
+              [1 => $this->_gid]
             ));
           }
 
           $fieldId = CRM_Core_BAO_CustomField::getKeyID(key($this->_multiRecordFields));
-          $customGroupDetails = CRM_Core_BAO_CustomGroup::getGroupTitles(array($fieldId));
+          $customGroupDetails = CRM_Core_BAO_CustomGroup::getGroupTitles([$fieldId]);
           $this->_customGroupTitle = $customGroupDetails[$fieldId]['groupTitle'];
           $this->_customGroupId = $customGroupDetails[$fieldId]['groupID'];
 
@@ -450,7 +452,7 @@ class CRM_Profile_Form extends CRM_Core_Form {
             else {
               $this->_recordExists = FALSE;
               if ($this->_multiRecord & CRM_Core_Action::UPDATE) {
-                CRM_Core_Session::setStatus(ts('Note: The record %1 doesnot exists. Upon save a new record will be create', array(1 => $this->_recordId)), ts('Record doesnot exist'), 'alert');
+                CRM_Core_Session::setStatus(ts('Note: The record %1 doesnot exists. Upon save a new record will be create', [1 => $this->_recordId]), ts('Record doesnot exist'), 'alert');
               }
             }
           }
@@ -463,10 +465,10 @@ class CRM_Profile_Form extends CRM_Core_Form {
 
         }
         elseif (!empty($this->_multiRecordFields)
-          && (!$this->_multiRecord || !in_array($this->_multiRecord, array(
+          && (!$this->_multiRecord || !in_array($this->_multiRecord, [
             CRM_Core_Action::DELETE,
             CRM_Core_Action::UPDATE,
-          )))
+          ]))
         ) {
           CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js', 1, 'html-header');
           //multi-record listing page
@@ -523,7 +525,7 @@ class CRM_Profile_Form extends CRM_Core_Form {
    *
    */
   public function setDefaultsValues() {
-    $this->_defaults = array();
+    $this->_defaults = [];
     if ($this->_multiRecordProfile && ($this->_multiRecord == CRM_Core_Action::DELETE)) {
       return;
     }
@@ -535,7 +537,7 @@ class CRM_Profile_Form extends CRM_Core_Form {
 
     if ($this->_id && !$this->_multiRecordProfile) {
       if ($this->_isContactActivityProfile) {
-        $contactFields = $activityFields = array();
+        $contactFields = $activityFields = [];
         foreach ($this->_fields as $fieldName => $field) {
           if (CRM_Utils_Array::value('field_type', $field) == 'Activity') {
             $activityFields[$fieldName] = $field;
@@ -561,7 +563,7 @@ class CRM_Profile_Form extends CRM_Core_Form {
         $fieldIds[] = CRM_Core_BAO_CustomField::getKeyID($key);
       }
 
-      $defaultValues = array();
+      $defaultValues = [];
       if ($this->_multiRecord && $this->_multiRecord == CRM_Core_Action::UPDATE) {
         $defaultValues = CRM_Core_BAO_CustomValueTable::getEntityValues($this->_id, NULL, $fieldIds, TRUE);
         if ($this->_recordExists == TRUE) {
@@ -609,8 +611,9 @@ class CRM_Profile_Form extends CRM_Core_Form {
 
               $deleteExtra = ts("Are you sure you want to delete attached file?");
               $fileId = $url['file_id'];
+              $fileHash = CRM_Core_BAO_File::generateFileHash($entityId, $fileId);
               $deleteURL = CRM_Utils_System::url('civicrm/file',
-                "reset=1&id={$fileId}&eid=$entityId&fid={$key}&action=delete"
+                "reset=1&id={$fileId}&eid=$entityId&fid={$key}&action=delete&fcs={$fileHash}"
               );
               $text = ts("Delete Attached File");
               $customFiles[$field['name']]['deleteURL'] = "<a href=\"{$deleteURL}\" onclick = \"if (confirm( ' $deleteExtra ' )) this.href+='&amp;confirmed=1'; else return false;\">$text</a>";
@@ -649,8 +652,9 @@ class CRM_Profile_Form extends CRM_Core_Form {
 
               $deleteExtra = ts("Are you sure you want to delete attached file?");
               $fileId = $url['file_id'];
+              $fileHash = CRM_Core_BAO_File::generateFileHash($entityId, $fileId); /* fieldId=$customFieldID */
               $deleteURL = CRM_Utils_System::url('civicrm/file',
-                "reset=1&id={$fileId}&eid=$entityId&fid={$customFieldID}&action=delete"
+                "reset=1&id={$fileId}&eid=$entityId&fid={$customFieldID}&action=delete&fcs={$fileHash}"
               );
               $text = ts("Delete Attached File");
               $customFiles[$field['name']]['deleteURL'] = "<a href=\"{$deleteURL}\" onclick = \"if (confirm( ' $deleteExtra ' )) this.href+='&amp;confirmed=1'; else return false;\">$text</a>";
@@ -676,14 +680,6 @@ class CRM_Profile_Form extends CRM_Core_Form {
       $this->removeFileRequiredRules('image_URL');
     }
 
-    if (array_key_exists('contact_sub_type', $this->_defaults) &&
-      !empty($this->_defaults['contact_sub_type'])
-    ) {
-      $this->_defaults['contact_sub_type'] = explode(CRM_Core_DAO::VALUE_SEPARATOR,
-        trim($this->_defaults['contact_sub_type'], CRM_Core_DAO::VALUE_SEPARATOR)
-      );
-    }
-
     $this->setDefaults($this->_defaults);
   }
 
@@ -717,7 +713,7 @@ class CRM_Profile_Form extends CRM_Core_Form {
 
     if (($this->_multiRecord & CRM_Core_Action::DELETE)) {
       if (!$this->_recordExists) {
-        CRM_Core_Session::setStatus(ts('The record %1 doesnot exists', array(1 => $this->_recordId)), ts('Record doesnot exists'), 'alert');
+        CRM_Core_Session::setStatus(ts('The record %1 doesnot exists', [1 => $this->_recordId]), ts('Record doesnot exists'), 'alert');
       }
       else {
         $this->assign('deleteRecord', TRUE);
@@ -767,7 +763,7 @@ class CRM_Profile_Form extends CRM_Core_Form {
           $return = TRUE;
           if (!$statusMessage) {
             $statusMessage = ts("This profile is configured for contact type '%1'. It cannot be used to edit contacts of other types.",
-                array(1 => $profileSubType ? $profileSubType : $profileType));
+                [1 => $profileSubType ? $profileSubType : $profileType]);
           }
         }
       }
@@ -775,7 +771,7 @@ class CRM_Profile_Form extends CRM_Core_Form {
       if (
       in_array(
         $profileType,
-        array("Membership", "Participant", "Contribution")
+        ["Membership", "Participant", "Contribution"]
       )
       ) {
         $return = TRUE;
@@ -831,7 +827,7 @@ class CRM_Profile_Form extends CRM_Core_Form {
     }
     $this->assign('anonUser', $anonUser);
 
-    $addCaptcha = array();
+    $addCaptcha = [];
     $emailPresent = FALSE;
 
     // add the form elements
@@ -945,14 +941,14 @@ class CRM_Profile_Form extends CRM_Core_Form {
    * @return array
    */
   public static function validateContactActivityProfile($activityId, $contactId, $gid) {
-    $errors = array();
+    $errors = [];
     if (!$activityId) {
       $errors[] = ts('Profile is using one or more activity fields, and is missing the activity Id (aid) in the URL.');
       return $errors;
     }
 
-    $activityDetails = array();
-    $activityParams = array('id' => $activityId);
+    $activityDetails = [];
+    $activityParams = ['id' => $activityId];
     CRM_Activity_BAO_Activity::retrieve($activityParams, $activityDetails);
 
     if (empty($activityDetails)) {
@@ -1075,7 +1071,7 @@ class CRM_Profile_Form extends CRM_Core_Form {
         $customizedValue = CRM_Core_PseudoConstant::getKey('CRM_Contact_BAO_Contact', $greeting . '_id', 'Customized');
         if ($customizedValue == $greetingType && empty($fields[$greeting . '_custom'])) {
           $errors[$greeting . '_custom'] = ts('Custom  %1 is a required field if %1 is of type Customized.',
-            array(1 => ucwords(str_replace('_', ' ', $greeting)))
+            [1 => ucwords(str_replace('_', ' ', $greeting))]
           );
         }
       }
@@ -1095,15 +1091,15 @@ class CRM_Profile_Form extends CRM_Core_Form {
     if ($this->_deleteButtonName) {
       if (!empty($_POST[$this->_deleteButtonName]) && $this->_recordId) {
         $filterParams['id'] = $this->_customGroupId;
-        $returnProperties = array('is_multiple', 'table_name');
+        $returnProperties = ['is_multiple', 'table_name'];
         CRM_Core_DAO::commonRetrieve("CRM_Core_DAO_CustomGroup", $filterParams, $returnValues, $returnProperties);
         if (!empty($returnValues['is_multiple'])) {
           if ($tableName = CRM_Utils_Array::value('table_name', $returnValues)) {
             $sql = "DELETE FROM {$tableName} WHERE id = %1 AND entity_id = %2";
-            $sqlParams = array(
-              1 => array($this->_recordId, 'Integer'),
-              2 => array($this->_id, 'Integer'),
-            );
+            $sqlParams = [
+              1 => [$this->_recordId, 'Integer'],
+              2 => [$this->_id, 'Integer'],
+            ];
             CRM_Core_DAO::executeQuery($sql, $sqlParams);
             CRM_Core_Session::setStatus(ts('Your record has been deleted.'), ts('Deleted'), 'success');
           }
@@ -1116,13 +1112,13 @@ class CRM_Profile_Form extends CRM_Core_Form {
       CRM_Contact_BAO_Contact::processImageParams($params);
     }
 
-    $greetingTypes = array(
+    $greetingTypes = [
       'addressee' => 'addressee_id',
       'email_greeting' => 'email_greeting_id',
       'postal_greeting' => 'postal_greeting_id',
-    );
+    ];
 
-    $details = array();
+    $details = [];
     if ($this->_id) {
       $contactDetails = CRM_Contact_BAO_Contact::getHierContactDetails($this->_id,
         $greetingTypes
@@ -1159,7 +1155,7 @@ class CRM_Profile_Form extends CRM_Core_Form {
 
     //used to send subscribe mail to the group which user want.
     //if the profile double option in is enabled
-    $mailingType = array();
+    $mailingType = [];
 
     $result = NULL;
     foreach ($params as $name => $values) {
@@ -1169,18 +1165,18 @@ class CRM_Profile_Form extends CRM_Core_Form {
     }
 
     //array of group id, subscribed by contact
-    $contactGroup = array();
+    $contactGroup = [];
     if (!empty($params['group']) &&
       CRM_Core_BAO_UFGroup::isProfileDoubleOptin()
     ) {
-      $groupSubscribed = array();
+      $groupSubscribed = [];
       if (!empty($result['email'])) {
         if ($this->_id) {
           $contactGroups = new CRM_Contact_DAO_GroupContact();
           $contactGroups->contact_id = $this->_id;
           $contactGroups->status = 'Added';
           $contactGroups->find();
-          $contactGroup = array();
+          $contactGroup = [];
           while ($contactGroups->fetch()) {
             $contactGroup[] = $contactGroups->group_id;
             $groupSubscribed[$contactGroups->group_id] = 1;
@@ -1225,13 +1221,13 @@ class CRM_Profile_Form extends CRM_Core_Form {
       ) {
         if (!count($contactGroup)) {
           //array of group id, subscribed by contact
-          $contactGroup = array();
+          $contactGroup = [];
           if ($this->_id) {
             $contactGroups = new CRM_Contact_DAO_GroupContact();
             $contactGroups->contact_id = $this->_id;
             $contactGroups->status = 'Added';
             $contactGroups->find();
-            $contactGroup = array();
+            $contactGroup = [];
             while ($contactGroups->fetch()) {
               $contactGroup[] = $contactGroups->group_id;
               $groupSubscribed[$contactGroups->group_id] = 1;
@@ -1264,7 +1260,7 @@ class CRM_Profile_Form extends CRM_Core_Form {
 
     $profileFields = $this->_fields;
     if (($this->_mode & self::MODE_EDIT) && $this->_activityId && $this->_isContactActivityProfile) {
-      $profileFields = $activityParams = array();
+      $profileFields = $activityParams = [];
       foreach ($this->_fields as $fieldName => $field) {
         if (CRM_Utils_Array::value('field_type', $field) == 'Activity') {
           if (isset($params[$fieldName])) {
@@ -1311,7 +1307,7 @@ class CRM_Profile_Form extends CRM_Core_Form {
       CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($mailingType, $result, $this->_id, 'profile');
     }
 
-    $ufGroups = array();
+    $ufGroups = [];
     if ($this->_gid) {
       $ufGroups[$this->_gid] = 1;
     }