Merge pull request #5076 from colemanw/Attachment
[civicrm-core.git] / CRM / Contact / Form / Contact.php
index 19d52d4cf396b2897b0ffb1fa8958af4327d4698..eae321ae3906b09f1fcb2cb8d2a463813e34d412 100644 (file)
@@ -23,7 +23,7 @@
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
@@ -433,7 +433,6 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
     //set address block defaults
     CRM_Contact_Form_Edit_Address::setDefaultValues($defaults, $this);
 
-
     if (!empty($defaults['image_URL'])) {
       list($imageWidth, $imageHeight) = getimagesize(CRM_Utils_String::unstupifyUrl($defaults['image_URL']));
       list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight);
@@ -499,11 +498,10 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
         // make we require one primary block, CRM-5505
         if ($updateMode) {
           if (!$hasPrimary) {
-            $hasPrimary =
-              CRM_Utils_Array::value(
-                'is_primary',
-                CRM_Utils_Array::value($instance, $defaults[$name])
-              );
+            $hasPrimary = CRM_Utils_Array::value(
+              'is_primary',
+              CRM_Utils_Array::value($instance, $defaults[$name])
+            );
           }
           continue;
         }
@@ -591,7 +589,6 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
    *
    * @return bool
    *   email/openId
-   * @static
    */
   public static function formRule($fields, &$errors, $contactId = NULL) {
     $config = CRM_Core_Config::singleton();
@@ -643,7 +640,7 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
               if (!$primaryID &&
                 in_array($name, array(
                   'email',
-                  'openid'
+                  'openid',
                 )) && !empty($blockValues[$name])
               ) {
                 $primaryID = $blockValues[$name];
@@ -734,14 +731,13 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
     if ($this->_action == CRM_Core_Action::UPDATE) {
       $deleteExtra = ts('Are you sure you want to delete contact image.');
       $deleteURL = array(
-        CRM_Core_Action::DELETE =>
-          array(
-            'name' => ts('Delete Contact Image'),
-            'url' => 'civicrm/contact/image',
-            'qs' => 'reset=1&cid=%%id%%&action=delete',
-            'extra' =>
-              'onclick = "if (confirm( \'' . $deleteExtra . '\' ) ) this.href+=\'&confirmed=1\'; else return false;"',
-          ),
+        CRM_Core_Action::DELETE => array(
+          'name' => ts('Delete Contact Image'),
+          'url' => 'civicrm/contact/image',
+          'qs' => 'reset=1&cid=%%id%%&action=delete',
+          'extra' =>
+          'onclick = "if (confirm( \'' . $deleteExtra . '\' ) ) this.href+=\'&confirmed=1\'; else return false;"',
+        ),
       );
       $deleteURL = CRM_Core_Action::formLink($deleteURL,
         CRM_Core_Action::DELETE,
@@ -867,7 +863,7 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
     $params = $this->controller->exportValues($this->_name);
 
     $group = CRM_Utils_Array::value('group', $params);
-    if ($group && is_array($group)) {
+    if (!empty($group) && is_array($group)) {
       unset($params['group']);
       foreach ($group as $key => $value) {
         $params['group'][$value] = 1;
@@ -952,11 +948,11 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
     // process shared contact address.
     CRM_Contact_BAO_Contact_Utils::processSharedAddress($params['address']);
 
-    if (!array_key_exists('TagsAndGroups', $this->_editOptions)) {
+    if (!array_key_exists('TagsAndGroups', $this->_editOptions) && !empty($params['group'])) {
       unset($params['group']);
     }
 
-    if (!empty($params['contact_id']) && ($this->_action & CRM_Core_Action::UPDATE)) {
+    if (!empty($params['contact_id']) && ($this->_action & CRM_Core_Action::UPDATE) && !empty($params['group'])) {
       // figure out which all groups are intended to be removed
       $contactGroupList = CRM_Contact_BAO_GroupContact::getContactGroup($params['contact_id'], 'Added');
       if (is_array($contactGroupList)) {
@@ -1069,9 +1065,8 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
    * @param array $fields
    *   The hierarchical value representation of this location.
    *
-   * @return boolean
+   * @return bool
    *   true if data exists, false otherwise
-   * @static
    */
   public static function blockDataExists(&$fields) {
     if (!is_array($fields)) {
@@ -1085,7 +1080,7 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
       'provider_id',
       'country_id',
       'website_type_id',
-      'master_id'
+      'master_id',
     );
     foreach ($fields as $name => $value) {
       $skipField = FALSE;
@@ -1140,18 +1135,18 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
         $duplicateContactsLinks = '<div class="matching-contacts-found">';
         $duplicateContactsLinks .= ts('One matching contact was found. ', array(
             'count' => count($contactLinks['rows']),
-            'plural' => '%count matching contacts were found.<br />'
+            'plural' => '%count matching contacts were found.<br />',
           ));
         if ($contactLinks['msg'] == 'view') {
           $duplicateContactsLinks .= ts('You can View the existing contact', array(
               'count' => count($contactLinks['rows']),
-              'plural' => 'You can View the existing contacts'
+              'plural' => 'You can View the existing contacts',
             ));
         }
         else {
           $duplicateContactsLinks .= ts('You can View or Edit the existing contact', array(
               'count' => count($contactLinks['rows']),
-              'plural' => 'You can View or Edit the existing contacts'
+              'plural' => 'You can View or Edit the existing contacts',
             ));
         }
         if ($contactLinks['msg'] == 'merge') {
@@ -1183,7 +1178,6 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
 
         $errors['_qf_default'] = $duplicateContactsLinks;
 
-
         // let smarty know that there are duplicates
         $template = CRM_Core_Smarty::singleton();
         $template->assign('isDuplicate', 1);
@@ -1222,7 +1216,6 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
    *
    * @return array
    *   as array of sucess/fails for each address block
-   * @static
    */
   public function parseAddress(&$params) {
     $parseSuccess = $parsedFields = array();
@@ -1238,7 +1231,7 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
       foreach (array(
                  'street_number',
                  'street_name',
-                 'street_unit'
+                 'street_unit',
                ) as $fld) {
         if (!empty($address[$fld])) {
           $parseFieldName = 'street_number';
@@ -1271,11 +1264,11 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
                    'street_number',
                    'street_number_suffix',
                    'street_name',
-                   'street_unit'
+                   'street_unit',
                  ) as $fld) {
           if (in_array($fld, array(
             'street_name',
-            'street_unit'
+            'street_unit',
           ))) {
             $streetAddress .= ' ';
           }
@@ -1317,8 +1310,8 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
    * @param array $parseResult
    *   An array of address blk instance and its status.
    *
-   * @return null|string $statusMsg   string status message for all address blocks.
-   * @static
+   * @return null|string
+   *   $statusMsg   string status message for all address blocks.
    */
   public static function parseAddressStatusMsg($parseResult) {
     $statusMsg = NULL;
@@ -1349,8 +1342,8 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
    * @param int $number
    *   number to convert in to ordinal number.
    *
-   * @return ordinal number for given number.
-   * @static
+   * @return string
+   *   ordinal number for given number.
    */
   public static function ordinalNumber($number) {
     if (empty($number)) {
@@ -1386,7 +1379,8 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
    * @param array $deceasedParams
    *   having contact id and deceased value.
    *
-   * @return null|string $updateMembershipMsg string  status message for updated membership.
+   * @return null|string
+   *   $updateMembershipMsg string  status message for updated membership.
    */
   public function updateMembershipStatus($deceasedParams) {
     $updateMembershipMsg = NULL;
@@ -1404,7 +1398,6 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
         $userId = $contactId;
       }
 
-
       // get deceased status id
       $allStatus = CRM_Member_PseudoConstant::membershipStatus();
       $deceasedStatusId = array_search('Deceased', $allStatus);
@@ -1443,7 +1436,6 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
           'max_related' => $dao->max_related,
         );
 
-
         CRM_Member_BAO_MembershipLog::add($membershipLog, CRM_Core_DAO::$_nullArray);
 
         //create activity when membership status is changed
@@ -1476,4 +1468,5 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
 
     return $updateMembershipMsg;
   }
+
 }