bulk comment fix
[civicrm-core.git] / CRM / Core / BAO / UFGroup.php
index b8a54e652cc7d08c56ee927ec291f1ca0f599668..7395d7366b12083e4afac106ed9e0515f2f25a9f 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | 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$
  *
  */
@@ -128,8 +128,10 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
   /**
    * get all the registration fields
    *
-   * @param int $action   what action are we doing
-   * @param int $mode     mode
+   * @param int $action what action are we doing
+   * @param int $mode mode
+   *
+   * @param null $ctype
    *
    * @return array the fields that are needed for registration
    * @static
@@ -169,7 +171,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
 
       // we do not allow duplicates. the first field is the winner
       foreach ($subset as $name => $field) {
-        if (!CRM_Utils_Array::value($name, $fields)) {
+        if (empty($fields[$name])) {
           $fields[$name] = $field;
         }
       }
@@ -181,12 +183,15 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
   /**
    * get all the listing fields
    *
-   * @param int     $action            what action are we doing
-   * @param int     $visibility        visibility of fields we are interested in
-   * @param bool    $considerSelector  whether to consider the in_selector parameter
-   * @param array   $ufGroupIds
+   * @param int $action what action are we doing
+   * @param int $visibility visibility of fields we are interested in
+   * @param bool $considerSelector whether to consider the in_selector parameter
+   * @param array $ufGroupIds
    * @param boolean $searchable
    *
+   * @param null $restrict
+   * @param bool $skipPermission
+   * @param int $permissionType
    * @return array   the fields that are listings related
    * @static
    * @access public
@@ -248,14 +253,21 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
    * and format for use with buildProfile. This is the SQL analog of
    * formatUFFields().
    *
-   * @param mix      $id           the id of the UF group or ids of ufgroup
-   * @param int      $register     are we interested in registration fields
-   * @param int      $action       what action are we doing
-   * @param int      $visibility   visibility of fields we are interested in
+   * @param mix $id the id of the UF group or ids of ufgroup
+   * @param bool|int $register are we interested in registration fields
+   * @param int $action what action are we doing
+   * @param int $visibility visibility of fields we are interested in
    * @param          $searchable
-   * @param boolean  $showall
-   * @param string   $restrict     should we restrict based on a specified profile type
+   * @param bool $showAll
+   * @param string $restrict should we restrict based on a specified profile type
+   *
+   * @param bool $skipPermission
+   * @param null $ctype
+   * @param int $permissionType
+   * @param string $orderBy
+   * @param null $orderProfiles
    *
+   * @internal param bool $showall
    * @return array   the fields that belong to this ufgroup(s)
    * @static
    * @access public
@@ -350,9 +362,13 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
    *
    * @param array $groupArr (mimic CRM_UF_DAO_UFGroup)
    * @param array $fieldArrs list of fields (each mimics CRM_UF_DAO_UFField)
-   * @param bool $visibility   visibility of fields we are interested in
+   * @param bool $visibility visibility of fields we are interested in
    * @param bool $searchable
-   * @param bool $showall
+   * @param bool $showAll
+   * @param null $ctype
+   * @param int $permissionType
+   *
+   * @internal param bool $showall
    * @return array
    * @see getFields
    */
@@ -425,8 +441,10 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
       $addressCustom = TRUE;
       $name = "address_{$name}";
     }
-
-    if (!empty($field->location_type_id)) {
+    if ($field->field_name == 'url') {
+      $name .= "-{$field->website_type_id}";
+    }
+    elseif (!empty($field->location_type_id)) {
       $name .= "-{$field->location_type_id}";
     }
     else {
@@ -459,6 +477,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
       'in_selector' => $field->in_selector,
       'rule' => CRM_Utils_Array::value('rule', CRM_Utils_Array::value($field->field_name, $importableFields)),
       'location_type_id' => isset($field->location_type_id) ? $field->location_type_id : NULL,
+      'website_type_id' => isset($field->website_type_id) ? $field->website_type_id : NULL,
       'phone_type_id' => isset($field->phone_type_id) ? $field->phone_type_id : NULL,
       'group_id' => $group->id,
       'add_to_group_id' => isset($group->add_to_group_id) ? $group->add_to_group_id : NULL,
@@ -646,7 +665,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
       $customFields = CRM_Core_BAO_CustomField::getFieldsForImport($ctype, FALSE, FALSE, FALSE, TRUE, TRUE);
 
       // hack to add custom data for components
-      $components = array('Contribution', 'Participant', 'Membership', 'Activity');
+      $components = array('Contribution', 'Participant', 'Membership', 'Activity', 'Case');
       foreach ($components as $value) {
         $customFields = array_merge($customFields, CRM_Core_BAO_CustomField::getFieldsForImport($value));
       }
@@ -928,7 +947,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
       }
 
       // skip fields that should not be displayed separately
-      if (CRM_Utils_Array::value('skipDisplay', $field)) {
+      if (!empty($field['skipDisplay'])) {
         continue;
       }
 
@@ -1057,9 +1076,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
               if ($htmlType == 'File') {
                 $entityId = $cid;
                 if (!$cid &&
-                  $fieldType == 'Activity' &&
-                  CRM_Utils_Array::value(2, $componentWhere[0])
-                ) {
+                  $fieldType == 'Activity' && !empty($componentWhere[0][2])) {
                   $entityId = $componentWhere[0][2];
                 }
 
@@ -1100,7 +1117,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
                   $cfID,
                   $options
                 );
-                if ($htmlType == 'Autocomplete-Select') {
+                if ($field['data_type'] == 'ContactReference') {
                   $params[$index] = $values[$index];
                 }
                 if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField',
@@ -1469,6 +1486,10 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
    * @params int $displayName if set return display name in array
    * @params int $status if set return module other than default modules (User Account/User registration/Profile)
    *
+   * @param null $ufGroupId
+   * @param null $displayName
+   * @param null $status
+   *
    * @return array $ufGroupJoinRecords
    *
    * @access public
@@ -1575,11 +1596,12 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
    * Function to get the uf group for a module
    *
    * @param string $moduleName module name
-   * @param int    $count no to increment the weight
-   * @param bool   $skipPermision - whether to add permission clause
-   * @param int    $op - which operation (view, edit, create, etc) to check permission for
+   * @param int $count no to increment the weight
+   * @param bool $skipPermission
+   * @param int $op - which operation (view, edit, create, etc) to check permission for
    * @param array|NULL $returnFields list of UFGroup fields to return; NULL for default
    *
+   * @internal param bool $skipPermision - whether to add permission clause
    * @return array $ufGroups array of ufgroups for a module
    * @access public
    * @static
@@ -1652,6 +1674,9 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
    *
    * @params int $ufGroupId uf group id (profile id)
    *
+   * @param $ufGroupId
+   * @param null $contactID
+   *
    * @return boolean true or false
    * @static
    * @access public
@@ -1695,6 +1720,16 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
    * @params array   $field      array field properties
    * @params int     $mode       profile mode
    * @params int     $contactID  contact id
+   * @params string  $usedFor    for building up prefixed fieldname for special cases (e.g. onBehalf, Honor)
+   *
+   * @param $form
+   * @param $field
+   * @param $mode
+   * @param null $contactId
+   * @param bool $online
+   * @param null $usedFor
+   * @param null $rowNumber
+   * @param string $prefix
    *
    * @return null
    * @static
@@ -1706,7 +1741,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
     $mode,
     $contactId = NULL,
     $online = FALSE,
-    $onBehalf = FALSE,
+    $usedFor = NULL,
     $rowNumber = NULL ,
     $prefix = ''
   ) {
@@ -1726,9 +1761,12 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
       return;
     }
 
-    if ($onBehalf) {
+    if ($usedFor == 'onbehalf') {
       $name = "onbehalf[$fieldName]";
     }
+    elseif ($usedFor == 'honor') {
+      $name = "honor[$fieldName]";
+    }
     elseif ($contactId && !$online) {
       $name = "field[$contactId][$fieldName]";
     }
@@ -1758,7 +1796,12 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
         CRM_Core_Action::DELETE,
         array('id' => $form->get('id'),
           'gid' => $form->get('gid'),
-        )
+        ),
+        ts('more'),
+        FALSE,
+        'contact.profileimage.delete',
+        'Contact',
+        $form->get('id')
       );
       $form->assign('deleteURL', $deleteURL);
     }
@@ -1798,7 +1841,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
       if ($addressOptions['county']) {
         $form->add('select', $name, $title,
           array(
-            '' => ts('- select state -')), $required
+            '' => ts('(choose state first)')), $required
         );
       }
     }
@@ -1809,7 +1852,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
     elseif (substr($fieldName, 0, 2) === 'im') {
       $form->add('text', $name, $title, $attributes, $required);
       if (!$contactId) {
-        if ($onBehalf) {
+        if ($usedFor) {
           if (substr($name, -1) == ']') {
             $providerName = substr($name, 0, -1) . '-provider_id]';
           }
@@ -1866,10 +1909,13 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
       foreach ($gender as $key => $var) {
         $genderOptions[$key] = $form->createElement('radio', NULL, ts('Gender'), $var, $key);
       }
-      $form->addGroup($genderOptions, $name, $title);
+      $group = $form->addGroup($genderOptions, $name, $title);
       if ($required) {
         $form->addRule($name, ts('%1 is a required field.', array(1 => $title)), 'required');
       }
+      else {
+        $group->setAttribute('allowClear', TRUE);
+      }
     }
     elseif ($fieldName === 'prefix_id' || $fieldName === 'suffix_id') {
       $form->add('select', $name, $title,
@@ -1879,9 +1925,12 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
     }
     elseif ($fieldName === 'contact_sub_type') {
       $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field);
-      if ($onBehalf) {
+      if ($usedFor == 'onbehalf') {
         $profileType = 'Organization';
       }
+      elseif ($usedFor == 'honor') {
+        $profileType = CRM_Core_BAO_UFField::getProfileType($form->_params['honoree_profile_id']);
+      }
       else {
         $profileType = $gId ? CRM_Core_BAO_UFField::getProfileType($gId) : NULL;
         if ($profileType == 'Contact') {
@@ -1986,17 +2035,6 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
       );
 
       $form->addRule($name, ts('Enter a valid Website.'), 'url');
-
-      //Website type select
-      if ($onBehalf) {
-        if (substr($name, -1) == ']') {
-          $websiteTypeName = substr($name, 0, -1) . '-website_type_id]';
-        }
-        $form->addElement('select', $websiteTypeName, NULL, CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id'));
-      }
-      else {
-        $form->addElement('select', $name . '-website_type_id', NULL, CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id'));
-      }
     }
     // Note should be rendered as textarea
     elseif (substr($fieldName, -4) == 'note') {
@@ -2023,7 +2061,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
       $form->addElement('checkbox', $name, $title);
     }
     elseif ($fieldName == 'soft_credit') {
-      CRM_Contact_Form_NewContact::buildQuickForm($form, $rowNumber, NULL, FALSE, 'soft_credit_');
+      $form->addEntityRef("soft_credit_contact_id[$rowNumber]", ts('Soft Credit To'), array('create' => TRUE));
       $form->addMoney("soft_credit_amount[{$rowNumber}]", ts('Amount'), FALSE, NULL, FALSE);
     }
     elseif ($fieldName == 'product_name') {
@@ -2059,6 +2097,16 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
           '' => ts('- select -')) + $contributionStatuses, $required
       );
     }
+    elseif ($fieldName == 'soft_credit_type') {
+      $form->add('select', $name, $title,
+        array(
+          '' => ts('- select -')) + CRM_Core_OptionGroup::values("soft_credit_type")
+      );
+      $form->addElement('hidden', 'sct_default_id',
+        CRM_Core_OptionGroup::getDefaultValue("soft_credit_type"),
+        array('id' => 'sct_default_id')
+      );
+    }
     elseif ($fieldName == 'currency') {
       $form->addCurrency($name, $title, $required);
     }
@@ -2097,7 +2145,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
       );
     }
     elseif ($fieldName == 'participant_role') {
-      if (CRM_Utils_Array::value('is_multiple', $field)) {
+      if (!empty($field['is_multiple'])) {
         $form->addCheckBox($name, $title, CRM_Event_PseudoConstant::participantRole(), NULL, NULL, NULL, NULL, '&nbsp', TRUE);
       }
       else {
@@ -2154,8 +2202,8 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
       // lets always add the hidden
       //subtype value if there is any, and we won't have to
       // compute it while processing.
-      if ($onBehalf) {
-        $form->addElement('hidden', 'onbehalf[contact_sub_type]', $field['field_type']);
+      if ($usedFor) {
+        $form->addElement('hidden', $usedFor . '[contact_sub_type]', $field['field_type']);
       }
       else {
         $form->addElement('hidden', 'contact_sub_type_hidden', $field['field_type']);
@@ -2172,7 +2220,14 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
       'non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount'))) {
       $form->addRule($name, ts('Please enter a valid amount.'), 'money');
     }
-
+    $stateCountryMap = array();
+    if (!empty($form->_stateCountryMap['state_province']) && !empty($form->_stateCountryMap['country'])) {
+      foreach ($form->_stateCountryMap['state_province'] as $key => $value) {
+        $stateCountryMap[$key]['state_province'] = $value;
+        $stateCountryMap[$key]['country'] = $form->_stateCountryMap['country'][$key];
+      }
+      CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
+    }
     if ($rule) {
       if (!($rule == 'email' && $mode == CRM_Profile_Form::MODE_SEARCH)) {
         $form->addRule($name, ts('Please enter a valid %1', array(1 => $title)), $rule);
@@ -2189,6 +2244,13 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
    * @params boolean $singleProfile  true for single profile else false(batch update)
    * @params int     $componentId    id for specific components like contribute, event etc
    *
+   * @param $contactId
+   * @param $fields
+   * @param $defaults
+   * @param bool $singleProfile
+   * @param null $componentId
+   * @param null $component
+   *
    * @return null
    * @static
    * @access public
@@ -2224,7 +2286,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
           CRM_Contact_Form_Edit_TagsAndGroups::setDefaults($contactId, $defaults, CRM_Contact_Form_Edit_TagsAndGroups::TAG, $fldName);
         }
 
-        if (CRM_Utils_Array::value($name, $details) || isset($details[$name])) {
+        if (!empty($details[$name]) || isset($details[$name])) {
           //to handle custom data (checkbox) to be written
           // to handle birth/deceased date, greeting_type and few other fields
           if (($name == 'birth_date') || ($name == 'deceased_date')) {
@@ -2282,28 +2344,14 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
                 }
                 break;
 
-              case 'Autocomplete-Select':
-                if ($customFields[$customFieldId]['data_type'] == 'ContactReference') {
-                  if (is_numeric($details[$name])) {
-                    $defaults[$fldName . '_id'] = $details[$name];
-                    $defaults[$fldName] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $details[$name], 'sort_name');
-                  }
-                }
-                else {
-                  $label = CRM_Core_BAO_CustomOption::getOptionLabel($customFieldId, $details[$name]);
-                  $defaults[$fldName . '_id'] = $details[$name];
-                  $defaults[$fldName] = $label;
-                }
-                break;
-
               case 'Select Date':
                 // CRM-6681, set defult values according to date and time format (if any).
                 $dateFormat = NULL;
-                if (CRM_Utils_Array::value('date_format', $customFields[$customFieldId])) {
+                if (!empty($customFields[$customFieldId]['date_format'])) {
                   $dateFormat = $customFields[$customFieldId]['date_format'];
                 }
 
-                if (!CRM_Utils_Array::value('time_format', $customFields[$customFieldId])) {
+                if (empty($customFields[$customFieldId]['time_format'])) {
                   list($defaults[$fldName]) = CRM_Utils_Date::setDateDefaults($details[$name], NULL,
                     $dateFormat
                   );
@@ -2351,7 +2399,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
                 // fixed for CRM-665
                 if (is_numeric($locTypeId)) {
                   if ($primaryLocationType || $locTypeId == CRM_Utils_Array::value('location_type_id', $value)) {
-                    if (CRM_Utils_Array::value($fieldName, $value)) {
+                    if (!empty($value[$fieldName])) {
                       //to handle stateprovince and country
                       if ($fieldName == 'state_province') {
                         $defaults[$fldName] = $value['state_province_id'];
@@ -2412,13 +2460,10 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
           }
           else {
             if (is_array($details)) {
-              if ($fieldName === 'url') {
-                if (!empty($details['website'])) {
-                  foreach ($details['website'] as $val) {
-                    $defaults[$fldName] = CRM_Utils_Array::value('url', $val);
-                    $defaults[$fldName . '-website_type_id'] = $val['website_type_id'];
-                  }
-                }
+              if ($fieldName === 'url'
+                && !empty($details['website'])
+                && !empty($details['website'][$locTypeId])) {
+                $defaults[$fldName] = CRM_Utils_Array::value('url', $details['website'][$locTypeId]);
               }
             }
           }
@@ -2552,8 +2597,10 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
   /**
    * Function to get default value for Register.
    *
-   * @return $defaults
-   * @static
+   * @param $fields
+   * @param $defaults
+   *
+   * @return mixed $defaults@static
    * @access public
    */
   static function setRegisterDefaults(&$fields, &$defaults) {
@@ -2637,6 +2684,9 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
    * @params int     $contactId      contact id
    * @params array   $values         associative array of name/value pair
    *
+   * @param $contactID
+   * @param $values
+   *
    * @return void
    * @access public
    */
@@ -2697,6 +2747,11 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
    * @params $cid      contact id
    * @params $params   associative array
    *
+   * @param $gid
+   * @param $cid
+   * @param $params
+   * @param bool $skipCheck
+   *
    * @return array
    * @access public
    */
@@ -2730,6 +2785,10 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
    * @params int     $gid      group id
    * @params array   $values   associative array of fields
    *
+   * @param $gid
+   * @param $values
+   * @param $template
+   *
    * @return void
    * @access public
    */
@@ -2746,6 +2805,8 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
    *
    * @param array $params associated array
    *
+   * @param null $contactId
+   *
    * @return array $data assoicated formatted array
    * @access public
    * @static
@@ -2782,7 +2843,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
 
         // if we are getting in a new primary email, dont overwrite the new one
         if ($locTypeId == $primaryLocationType) {
-          if (CRM_Utils_Array::value('email-' . $primaryLocationType, $params)) {
+          if (!empty($params['email-' . $primaryLocationType])) {
             $data['location'][$loc]['email'][$loc]['email'] = $fields['email-' . $primaryLocationType];
           }
           elseif (isset($primaryEmail)) {
@@ -2877,9 +2938,11 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
   /**
    * calculate the profile type 'group_type' as per profile fields.
    *
-   * @param int $gid           profile id
+   * @param $gId
+   * @param bool $includeTypeValues
    * @param int $ignoreFieldId ignore particular profile field
    *
+   * @internal param int $gid profile id
    * @return array list of calculated group type
    */
   static function calculateGroupType($gId, $includeTypeValues = FALSE, $ignoreFieldId = NULL) {
@@ -2891,9 +2954,11 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
   /**
    * calculate the profile type 'group_type' as per profile fields.
    *
-   * @param int $gid           profile id
+   * @param $ufFields
+   * @param bool $includeTypeValues
    * @param int $ignoreFieldId ignore perticular profile field
    *
+   * @internal param int $gid profile id
    * @return array list of calculated group type
    */
   static function _calculateGroupType($ufFields, $includeTypeValues = FALSE, $ignoreFieldId = NULL) {
@@ -2959,9 +3024,10 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
    * BirthDate + SurveyOrPhoneField + SurveyOnlyField         Individual,Activity\0ActivityType:2:28
    * BirthDate + StudentField + Subject + SurveyOnlyField     Individual,Activity,Student\0ActivityType:28
    *
-   * @param  Integer $gid         profile id
-   * @param  Array   $groupTypes  With key having group type names
+   * @param $gId
+   * @param  Array $groupTypes With key having group type names
    *
+   * @internal param int $gid profile id
    * @return Boolean
    */
   static function updateGroupTypes($gId, $groupTypes = array(
@@ -2975,7 +3041,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
       return CRM_Core_DAO::setFieldValue('CRM_Core_DAO_UFGroup', $gId, 'group_type', 'null');
     }
 
-    $componentGroupTypes = array('Contribution', 'Participant', 'Membership', 'Activity');
+    $componentGroupTypes = array('Contribution', 'Participant', 'Membership', 'Activity', 'Case');
     $validGroupTypes = array_merge(array('Contact', 'Individual', 'Organization', 'Household'), $componentGroupTypes, CRM_Contact_BAO_ContactType::subTypes());
 
     $gTypes = $gTypeValues = array();
@@ -3027,6 +3093,8 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
    * @param array $coreTypes e.g. array('Individual','Contact','Student')
    * @param array $subTypes e.g. array('ActivityType' => array(7, 11))
    * @param string $delim
+   *
+   * @return string
    * @throws CRM_Core_Exception
    */
   static function encodeGroupType($coreTypes, $subTypes, $delim = CRM_Core_DAO::VALUE_SEPARATOR) {
@@ -3048,10 +3116,12 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
   /**
    * This function is used to setDefault componet specific profile fields.
    *
-   * @param array  $fields      profile fields.
-   * @param int    $componentId componetID
-   * @param string $component   component name
-   * @param array  $defaults    an array of default values.
+   * @param array $fields profile fields.
+   * @param int $componentId componetID
+   * @param string $component component name
+   * @param array $defaults an array of default values.
+   *
+   * @param bool $isStandalone
    *
    * @return void.
    */
@@ -3101,7 +3171,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
       $fldName = $isStandalone ? $name : "field[$componentId][$name]";
       if (in_array($name, $dateTimeFields)) {
         $timefldName = $isStandalone ? "{$name}_time" : "field[$componentId][{$name}_time]";
-        if (CRM_Utils_Array::value($name, $values)) {
+        if (!empty($values[$name])) {
           list($defaults[$fldName], $defaults[$timefldName]) = CRM_Utils_Date::setDateDefaults($values[$name]);
         }
       }
@@ -3160,7 +3230,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
 
                   // CRM-6681, $default contains formatted date, time values.
                   $defaults[$fldName] = $customValue;
-                  if (CRM_Utils_Array::value($customKey . '_time', $defaults)) {
+                  if (!empty($defaults[$customKey . '_time'])) {
                     $defaults['field'][$componentId][$name . '_time'] = $defaults[$customKey . '_time'];
                   }
                 }
@@ -3179,47 +3249,44 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
   }
 
   /**
-   * Function to retrieve reserved profiles
+   * @param array|string $profiles - name of profile(s) to create links for
+   * @param array $appendProfiles - name of profile(s) to append to each link
    *
-   * @param string $name name if the reserve profile
-   * @param array $extraProfiles associated array of profile id's that needs to merge
-   *
-   * @return array $reservedProfiles returns associated array
-   * @static
+   * @return array
    */
-  static function getReservedProfiles($type = 'Contact', $extraProfiles = NULL) {
-    $reservedProfiles = array();
-    $profileNames = array();
-    if ($type == 'Contact') {
-      $whereClause = 'name IN ( "new_individual", "new_organization", "new_household" )';
-      if (CRM_Contact_BAO_ContactType::isActive('Individual')) {
-        $profileNames[] = '"new_individual"';
-      }
-      if (CRM_Contact_BAO_ContactType::isActive('Household')) {
-        $profileNames[] = '"new_household"';
-      }
-      if (CRM_Contact_BAO_ContactType::isActive('Organization')) {
-        $profileNames[] = '"new_organization"';
+  static function getCreateLinks($profiles = '', $appendProfiles = array()) {
+    // Default to contact profiles
+    if (!$profiles) {
+      $profiles = array('new_individual', 'new_organization', 'new_household');
+    }
+    $profiles = (array) $profiles;
+    $toGet = array_merge($profiles, (array) $appendProfiles);
+    $retrieved = civicrm_api3('uf_group', 'get', array(
+      'name' => array('IN' => $toGet),
+      'is_active' => 1,
+    ));
+    $links = $append = array();
+    if (!empty($retrieved['values'])) {
+      foreach($retrieved['values'] as $id => $profile) {
+        if (in_array($profile['name'], $profiles)) {
+          $links[] = array(
+            'label' => $profile['title'],
+            'url' => CRM_Utils_System::url('civicrm/profile/create', "reset=1&context=dialog&gid=$id",
+              NULL, NULL, FALSE, NULL, FALSE) ,
+            'type' => ucfirst(str_replace('new_', '', $profile['name'])),
+          );
+        }
+        else {
+          $append[] = $id;
+        }
       }
-    }
-    if (!empty($profileNames)) {
-      $whereClause = 'name IN ( ' . implode(',', $profileNames) . ' ) AND is_reserved = 1';
-    }
-    else {
-      $whereClause = 'is_reserved = 1';
-    }
-
-    $query = "SELECT id, title FROM civicrm_uf_group WHERE {$whereClause}";
-
-    $dao = CRM_Core_DAO::executeQuery($query);
-    while ($dao->fetch()) {
-      $key = $dao->id;
-      if ($extraProfiles) {
-        $key .= ',' . implode(',', $extraProfiles);
+      foreach ($append as $id) {
+        foreach ($links as &$link) {
+          $link['url'] .= ",$id";
+        }
       }
-      $reservedProfiles[$key] = $dao->title;
     }
-    return $reservedProfiles;
+    return $links;
   }
 
   /**
@@ -3398,6 +3465,9 @@ SELECT  group_id
    * @params Integer $profileId       Profile Id
    * @params String  $groupType       Group Type
    *
+   * @param $profileId
+   * @param null $groupType
+   *
    * @return Array   group type values
    * @static
    * @access public
@@ -3407,7 +3477,7 @@ SELECT  group_id
     $groupTypes = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $profileId, 'group_type');
 
     $groupTypeParts = explode(CRM_Core_DAO::VALUE_SEPARATOR, $groupTypes);
-    if (!CRM_Utils_Array::value(1, $groupTypeParts)) {
+    if (empty($groupTypeParts[1])) {
       return $groupTypeValue;
     }
     $participantExtends = array('ParticipantRole', 'ParticipantEventName', 'ParticipantEventType');
@@ -3481,6 +3551,14 @@ SELECT  group_id
     return $profileIds;
   }
 
+  /**
+   * @todo what do I do?
+   * @param $source
+   * @param $destination
+   * @param bool $returnMultiSummaryFields
+   *
+   * @return array|null
+   */
   static function shiftMultiRecordFields(&$source, &$destination, $returnMultiSummaryFields = FALSE) {
     $multiSummaryFields = $returnMultiSummaryFields ? array( ) : NULL;
     foreach ($source as $field => $properties) {