Merge pull request #4814 from atif-shaikh/CRM-14199Improvement
[civicrm-core.git] / CRM / Contact / Form / Contact.php
index 204ea6fe0ab42d0aaf2012c82613268a9f1481b6..2efd276617f2072121acc07a188759481db118da 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -65,32 +65,30 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
   public $_contactId;
 
   /**
-   * the default group id passed in via the url
+   * The default group id passed in via the url
    *
    * @var int
    */
   public $_gid;
 
   /**
-   * the default tag id passed in via the url
+   * The default tag id passed in via the url
    *
    * @var int
    */
   public $_tid;
 
   /**
-   * name of de-dupe button
+   * Name of de-dupe button
    *
    * @var string
-   * @access protected
    */
   protected $_dedupeButtonName;
 
   /**
-   * name of optional save duplicate button
+   * Name of optional save duplicate button
    *
    * @var string
-   * @access protected
    */
   protected $_duplicateButtonName;
 
@@ -118,7 +116,7 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
   public $_parseStreetAddress;
 
   /**
-   * check contact has a subtype or not
+   * Check contact has a subtype or not
    */
   public $_isContactSubType;
 
@@ -130,12 +128,11 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
   public $_preEditValues;
 
   /**
-   * build all the data structures needed to build the form
+   * Build all the data structures needed to build the form
    *
    * @return void
-   * @access public
    */
-  function preProcess() {
+  public function preProcess() {
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add');
 
     $this->_dedupeButtonName = $this->getButtonName('refresh', 'dedupe');
@@ -197,7 +194,7 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
         $returnProperities = array('id', 'contact_type', 'contact_sub_type', 'modified_date');
         CRM_Core_DAO::commonRetrieve('CRM_Contact_DAO_Contact', $params, $defaults, $returnProperities);
 
-        if (!CRM_Utils_Array::value('id', $defaults)) {
+        if (empty($defaults['id'])) {
           CRM_Core_Error::statusBounce(ts('A Contact with that ID does not exist: %1', array(1 => $this->_contactId)));
         }
 
@@ -265,9 +262,7 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
         'address_options'
       );
       $this->_parseStreetAddress = FALSE;
-      if (CRM_Utils_Array::value('street_address', $addressOptions) &&
-        CRM_Utils_Array::value('street_address_parsing', $addressOptions)
-      ) {
+      if (!empty($addressOptions['street_address']) && !empty($addressOptions['street_address_parsing'])) {
         $this->_parseStreetAddress = TRUE;
       }
       $this->set('parseStreetAddress', $this->_parseStreetAddress);
@@ -327,7 +322,7 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
     CRM_Contact_Form_Location::preProcess($this);
 
     // retain the multiple count custom fields value
-    if(CRM_Utils_Array::value('hidden_custom', $_POST)) {
+    if (!empty($_POST['hidden_custom'])) {
       $customGroupCount = CRM_Utils_Array::value('hidden_custom_group_count', $_POST);
 
       if ($contactSubType = CRM_Utils_Array::value( 'contact_sub_type', $_POST)) {
@@ -374,7 +369,7 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
       else {
         $contactSubType = $this->_contactSubType;
         // need contact sub type to build related grouptree array during post process
-        if (CRM_Utils_Array::value('contact_sub_type', $_POST)) {
+        if (!empty($_POST['contact_sub_type'])) {
           $contactSubType = $_POST['contact_sub_type'];
         }
         //only custom data has preprocess hence directly call it
@@ -387,14 +382,13 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
   }
 
   /**
-   * This function sets the default values for the form. Note that in edit/view mode
+   * Set default values for the form. Note that in edit/view mode
    * the default values are retrieved from the database
    *
-   * @access public
    *
-   * @return None
+   * @return void
    */
-  function setDefaultValues() {
+  public function setDefaultValues() {
     $defaults = $this->_values;
     $params = array();
 
@@ -413,9 +407,6 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
       }
     }
     else {
-      $currentEmployer = CRM_Contact_BAO_Relationship::getCurrentEmployer(array($this->_contactId));
-      $defaults['current_employer_id'] = CRM_Utils_Array::value('org_id', $currentEmployer[$this->_contactId]);
-
       foreach ($defaults['email'] as $dontCare => & $val) {
         if (isset($val['signature_text'])) {
           $val['signature_text_hidden'] = $val['signature_text'];
@@ -425,12 +416,10 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
         }
       }
 
-      if (CRM_Utils_Array::value('contact_sub_type', $defaults)) {
+      if (!empty($defaults['contact_sub_type'])) {
         $defaults['contact_sub_type'] = $this->_oldSubtypes;
       }
     }
-    $this->assign('currentEmployer', CRM_Utils_Array::value('current_employer_id', $defaults));
-
     // set defaults for blocks ( custom data, address, communication preference, notes, tags and groups )
     foreach ($this->_editOptions as $name => $label) {
       if (!in_array($name, array('Address', 'Notes'))) {
@@ -442,7 +431,8 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
     //set address block defaults
     CRM_Contact_Form_Edit_Address::setDefaultValues( $defaults, $this );
 
-    if (CRM_Utils_Array::value('image_URL', $defaults)) {
+
+    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);
       $this->assign('imageWidth', $imageWidth);
@@ -460,11 +450,11 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
   }
 
   /**
-   * do the set default related to location type id,
+   * Do the set default related to location type id,
    * primary location,  default country
    *
    */
-  function blockSetDefaults(&$defaults) {
+  public function blockSetDefaults(&$defaults) {
     $locationTypeKeys = array_filter(array_keys(CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id')), 'is_int');
     sort($locationTypeKeys);
 
@@ -483,6 +473,9 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
     $defIMProviderId = key(CRM_Core_OptionGroup::values('instant_messenger_service',
         FALSE, FALSE, FALSE, ' AND is_default = 1'
       ));
+    $defWebsiteTypeId = key(CRM_Core_OptionGroup::values('website_type',
+      FALSE, FALSE, FALSE, ' AND is_default = 1'
+    ));
 
     $allBlocks = $this->_blocks;
     if (array_key_exists('Address', $this->_editOptions)) {
@@ -539,6 +532,10 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
         if ($name == 'phone' && $defPhoneTypeId) {
           $defaults[$name][$instance]['phone_type_id'] = $defPhoneTypeId;
         }
+        //set default website type.
+        if ($name == 'website' && $defWebsiteTypeId) {
+          $defaults[$name][$instance]['website_type_id'] = $defWebsiteTypeId;
+        }
 
         //set default im provider.
         if ($name == 'im' && $defIMProviderId) {
@@ -550,34 +547,16 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
         $defaults[$name][1]['is_primary'] = TRUE;
       }
     }
-
-    // set defaults for country-state widget
-    if (CRM_Utils_Array::value('address', $defaults) && is_array($defaults['address'])) {
-      foreach ($defaults['address'] as $blockId => $values) {
-        CRM_Contact_Form_Edit_Address::fixStateSelect($this,
-          "address[$blockId][country_id]",
-          "address[$blockId][state_province_id]",
-          "address[$blockId][county_id]",
-          CRM_Utils_Array::value('country_id',
-            $values, $config->defaultContactCountry
-          ),
-          CRM_Utils_Array::value('state_province_id',
-            $values, $config->defaultContactStateProvince
-          )
-        );
-      }
-    }
   }
 
   /**
    * This function is used to add the rules (mainly global rules) for form.
    * All local rules are added near the element
    *
-   * @return None
-   * @access public
+   * @return void
    * @see valid_date
    */
-  function addRules() {
+  public function addRules() {
     // skip adding formRules when custom data is build
     if ($this->_addBlockName || ($this->_action & CRM_Core_Action::DELETE)) {
       return;
@@ -600,17 +579,15 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
   }
 
   /**
-   * global validation rules for the form
+   * Global validation rules for the form
    *
-   * @param array $fields     posted values of the form
-   * @param array $errors     list of errors to be posted back to the form
-   * @param int   $contactId  contact id if doing update.
+   * @param array $fields posted values of the form
+   * @param array $errors list of errors to be posted back to the form
+   * @param int $contactId contact id if doing update.
    *
-   * @return $primaryID email/openId
-   * @static
-   * @access public
+   * @return bool $primaryID email/openId@static
    */
-  static function formRule($fields, &$errors, $contactId = NULL) {
+  public static function formRule($fields, &$errors, $contactId = NULL) {
     $config = CRM_Core_Config::singleton();
 
     // validations.
@@ -640,7 +617,7 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
     foreach ($blocks as $name => $label) {
       $hasData = $hasPrimary = array();
       $name = strtolower($name);
-      if (CRM_Utils_Array::value($name, $fields) && is_array($fields[$name])) {
+      if (!empty($fields[$name]) && is_array($fields[$name])) {
         foreach ($fields[$name] as $instance => $blockValues) {
           $dataExists = self::blockDataExists($blockValues);
 
@@ -655,23 +632,21 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
             }
 
             $hasData[] = $instance;
-            if (CRM_Utils_Array::value('is_primary', $blockValues)) {
+            if (!empty($blockValues['is_primary'])) {
               $hasPrimary[] = $instance;
               if (!$primaryID &&
                 in_array($name, array(
-                  'email', 'openid')) &&
-                CRM_Utils_Array::value($name, $blockValues)
-              ) {
+                  'email', 'openid')) && !empty($blockValues[$name])) {
                 $primaryID = $blockValues[$name];
               }
             }
 
-            if (!CRM_Utils_Array::value('location_type_id', $blockValues)) {
+            if (empty($blockValues['location_type_id'])) {
               $errors["{$name}[$instance][location_type_id]"] = ts('The Location Type should be set if there is  %1 information.', array(1 => $label));
             }
           }
 
-          if ($name == 'openid' && CRM_Utils_Array::value($name, $blockValues)) {
+          if ($name == 'openid' && !empty($blockValues[$name])) {
             $oid         = new CRM_Core_DAO_OpenID();
             $oid->openid = $openIds[$instance] = CRM_Utils_Array::value($name, $blockValues);
             $cid         = isset($contactId) ? $contactId : 0;
@@ -716,7 +691,7 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
         foreach ($fields['address'] as $cnt => $address) {
           if ($streetNumber = CRM_Utils_Array::value('street_number', $address)) {
             $parsedAddress = CRM_Core_BAO_Address::parseStreetAddress($address['street_number']);
-            if (!CRM_Utils_Array::value('street_number', $parsedAddress)) {
+            if (empty($parsedAddress['street_number'])) {
               $invalidStreetNumbers[] = $cnt;
             }
           }
@@ -734,10 +709,9 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
   }
 
   /**
-   * Function to actually build the form
+   * Build the form object
    *
-   * @return None
-   * @access public
+   * @return void
    */
   public function buildQuickForm() {
     //load form for child blocks
@@ -762,7 +736,12 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
         CRM_Core_Action::DELETE,
         array(
           'id' => $this->_contactId,
-        )
+        ),
+        ts('more'),
+        FALSE,
+        'contact.image.delete',
+        'Contact',
+        $this->_contactId
       );
       $this->assign('deleteURL', $deleteURL);
     }
@@ -778,15 +757,14 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
     }
 
     // subtype is a common field. lets keep it here
-    $subtypes = CRM_Contact_BAO_ContactType::subTypePairs($this->_contactType);
+    $subtypes = CRM_Contact_BAO_Contact::buildOptions('contact_sub_type', 'create', array('contact_type' => $this->_contactType));
     if (!empty($subtypes)) {
       $sel = $this->add('select', 'contact_sub_type', ts('Contact Type'),
         $subtypes, FALSE,
         array(
           'id' => 'contact_sub_type',
           'multiple' => 'multiple',
-          'title' => '- ' . ts('select') . ' -',
-          'class' => $buildCustomData,
+          'class' => $buildCustomData . ' crm-select2',
         )
       );
     }
@@ -806,7 +784,7 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
 
     // build tags and groups
     CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($this, 0, CRM_Contact_Form_Edit_TagsAndGroups::ALL,
-      FALSE, NULL, 'Group(s)', 'Tag(s)', NULL, 'crmasmSelect');
+      FALSE, NULL, 'Group(s)', 'Tag(s)', NULL, 'select');
 
     // build location blocks.
     CRM_Contact_Form_Edit_Lock::buildQuickForm($this);
@@ -837,19 +815,21 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
         'subName' => 'view',
         'isDefault' => TRUE,
       ),
-      array(
+    );
+    if (CRM_Core_Permission::check('add contacts')) {
+      $buttons[] = array(
         'type' => 'upload',
         'name' => ts('Save and New'),
         'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
         'subName' => 'new',
-      ),
-      array(
-        'type' => 'cancel',
-        'name' => ts('Cancel'),
-      ),
+      );
+    }
+    $buttons[] = array(
+      'type' => 'cancel',
+      'name' => ts('Cancel'),
     );
 
-    if (CRM_Utils_Array::value('contact_sub_type', $this->_values)) {
+    if (!empty($this->_values['contact_sub_type'])) {
       $this->_oldSubtypes = explode(CRM_Core_DAO::VALUE_SEPARATOR,
         trim($this->_values['contact_sub_type'], CRM_Core_DAO::VALUE_SEPARATOR)
       );
@@ -862,9 +842,8 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
   /**
    * Form submission of new/edit contact is processed.
    *
-   * @access public
    *
-   * @return None
+   * @return void
    */
   public function postProcess() {
     // check if dedupe button, if so return.
@@ -886,13 +865,11 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
 
     CRM_Contact_BAO_Contact_Optimizer::edit( $params, $this->_preEditValues );
 
-    if (CRM_Utils_Array::value('image_URL', $params)) {
+    if (!empty($params['image_URL'])) {
       CRM_Contact_BAO_Contact::processImageParams($params);
     }
 
-    if (is_numeric(CRM_Utils_Array::value('current_employer_id', $params))
-      && CRM_Utils_Array::value('current_employer', $params)
-    ) {
+    if (is_numeric(CRM_Utils_Array::value('current_employer_id', $params)) && !empty($params['current_employer'])) {
       $params['current_employer'] = $params['current_employer_id'];
     }
 
@@ -913,10 +890,7 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
     }
 
     //make deceased date null when is_deceased = false
-    if ($this->_contactType == 'Individual' &&
-      CRM_Utils_Array::value('Demographics', $this->_editOptions) &&
-      !CRM_Utils_Array::value('is_deceased', $params)
-    ) {
+    if ($this->_contactType == 'Individual' && !empty($this->_editOptions['Demographics']) && empty($params['is_deceased'])) {
       $params['is_deceased'] = FALSE;
       $params['deceased_date'] = NULL;
     }
@@ -970,14 +944,12 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
       unset($params['group']);
     }
 
-    if (CRM_Utils_Array::value('contact_id', $params) && ($this->_action & CRM_Core_Action::UPDATE)) {
+    if (!empty($params['contact_id']) && ($this->_action & CRM_Core_Action::UPDATE)) {
       // figure out which all groups are intended to be removed
       $contactGroupList = CRM_Contact_BAO_GroupContact::getContactGroup($params['contact_id'], 'Added');
       if (is_array($contactGroupList)) {
         foreach ($contactGroupList as $key) {
-          if ((!array_key_exists($key['group_id'], $params['group']) || $params['group'][$key['group_id']] != 1)
-            && !CRM_Utils_Array::value('is_hidden', $key)
-          ) {
+          if ((!array_key_exists($key['group_id'], $params['group']) || $params['group'][$key['group_id']] != 1) && empty($key['is_hidden'])) {
             $params['group'][$key['group_id']] = -1;
           }
         }
@@ -1080,15 +1052,14 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
   }
 
   /**
-   * is there any real significant data in the hierarchical location array
+   * Is there any real significant data in the hierarchical location array
    *
    * @param array $fields the hierarchical value representation of this location
    *
    * @return boolean true if data exists, false otherwise
    * @static
-   * @access public
    */
-  static function blockDataExists(&$fields) {
+  public static function blockDataExists(&$fields) {
     if (!is_array($fields)) {
       return FALSE;
     }
@@ -1124,16 +1095,17 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
   }
 
   /**
-   * Function to that checks for duplicate contacts
+   * That checks for duplicate contacts
+   *
+   * @param array $fields fields array which are submitted
+   * @param $errors
+   * @param int $contactID contact id
+   * @param string $contactType contact type
    *
-   *  @param array  $fields      fields array which are submitted
-   *  @param array  $error       error message array
-   *  @param int    $contactID   contact id
-   *  @param string $contactType contact type
    */
-  static function checkDuplicateContacts(&$fields, &$errors, $contactID, $contactType) {
+  public static function checkDuplicateContacts(&$fields, &$errors, $contactID, $contactType) {
     // if this is a forced save, ignore find duplicate rule
-    if (!CRM_Utils_Array::value('_qf_Contact_upload_duplicate', $fields)) {
+    if (empty($fields['_qf_Contact_upload_duplicate'])) {
 
       $dedupeParams = CRM_Dedupe_Finder::formatParams($fields, $contactType);
       $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, $contactType, 'Supervised', array($contactID));
@@ -1184,14 +1156,19 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
         $template = CRM_Core_Smarty::singleton();
         $template->assign('isDuplicate', 1);
       }
-      elseif (CRM_Utils_Array::value('_qf_Contact_refresh_dedupe', $fields)) {
+      elseif (!empty($fields['_qf_Contact_refresh_dedupe'])) {
         // add a session message for no matching contacts
         CRM_Core_Session::setStatus(ts('No matching contact found.'), ts('None Found'), 'info');
       }
     }
   }
 
-  function getTemplateFileName() {
+  /**
+   * Use the form name to create the tpl file name
+   *
+   * @return string
+   */
+  public function getTemplateFileName() {
     if ($this->_contactSubType) {
       $templateFile = "CRM/Contact/Form/Edit/SubType/{$this->_contactSubType}.tpl";
       $template = CRM_Core_Form::getTemplate();
@@ -1204,16 +1181,15 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
 
   /**
    * Parse all address blocks present in given params
-     * and return parse result for all address blocks,
-     * This function either parse street address in to child
-     * elements or build street address from child elements.
-     *
-     * @params $params an array of key value consist of address  blocks.
-     *
-   * @return $parseSuccess as array of sucess/fails for each address block
-   * @static
-     */
-  function parseAddress(&$params) {
+   * and return parse result for all address blocks,
+   * This function either parse street address in to child
+   * elements or build street address from child elements.
+   *
+   * @param $params array of key value consist of address  blocks.
+   *
+   * @return array $parseSuccess as array of sucess/fails for each address block@static
+   */
+  public function parseAddress(&$params) {
     $parseSuccess = $parsedFields = array();
     if (!is_array($params['address']) ||
       CRM_Utils_System::isNull($params['address'])
@@ -1226,7 +1202,7 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
       $parseFieldName = 'street_address';
       foreach (array(
         'street_number', 'street_name', 'street_unit') as $fld) {
-        if (CRM_Utils_Array::value($fld, $address)) {
+        if (!empty($address[$fld])) {
           $parseFieldName = 'street_number';
           $buildStreetAddress = TRUE;
           break;
@@ -1268,9 +1244,7 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
         $success = TRUE;
         // consider address is automatically parseable,
         // when we should found street_number and street_name
-        if (!CRM_Utils_Array::value('street_name', $parsedFields) ||
-          !CRM_Utils_Array::value('street_number', $parsedFields)
-        ) {
+        if (empty($parsedFields['street_name']) || empty($parsedFields['street_number'])) {
           $success = FALSE;
         }
 
@@ -1293,15 +1267,14 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
   }
 
   /**
-   * check parse result and if some address block fails then this
+   * Check parse result and if some address block fails then this
    * function return the status message for all address blocks.
    *
    * @param  $parseResult an array of address blk instance and its status.
    *
-   * @return $statusMsg   string status message for all address blocks.
-   * @static
+   * @return null|string $statusMsg   string status message for all address blocks.@static
    */
-  static function parseAddressStatusMsg($parseResult) {
+  public static function parseAddressStatusMsg($parseResult) {
     $statusMsg = NULL;
     if (!is_array($parseResult) || empty($parseResult)) {
       return $statusMsg;
@@ -1332,7 +1305,7 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
    * @return ordinal number for given number.
    * @static
    */
-  static function ordinalNumber($number) {
+  public static function ordinalNumber($number) {
     if (empty($number)) {
       return NULL;
     }
@@ -1365,18 +1338,16 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
    *
    * @param  $deceasedParams array  having contact id and deceased value.
    *
-   * @return $updateMembershipMsg string  status message for updated membership.
+   * @return null|string $updateMembershipMsg string  status message for updated membership.
    */
-  function updateMembershipStatus($deceasedParams) {
+  public function updateMembershipStatus($deceasedParams) {
     $updateMembershipMsg = NULL;
     $contactId           = CRM_Utils_Array::value('contact_id', $deceasedParams);
     $deceasedDate        = CRM_Utils_Array::value('deceased_date', $deceasedParams);
 
     // process to set membership status to deceased for both active/inactive membership
     if ($contactId &&
-      $this->_contactType == 'Individual' &&
-      CRM_Utils_Array::value('is_deceased', $deceasedParams)
-    ) {
+      $this->_contactType == 'Individual' && !empty($deceasedParams['is_deceased'])) {
 
       $session = CRM_Core_Session::singleton();
       $userId = $session->get('userID');
@@ -1457,4 +1428,3 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
     return $updateMembershipMsg;
   }
 }
-