Ejemplo n.º 1
0
 public function buildQuickForm()
 {
     $this->add('text', 'title', ts('Find'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'title'));
     $groupTypes = CRM_Core_OptionGroup::values('group_type', TRUE);
     $config = CRM_Core_Config::singleton();
     if ($config->userFramework == 'Joomla') {
         unset($groupTypes['Access Control']);
     }
     $this->addCheckBox('group_type', ts('Type'), $groupTypes, NULL, NULL, NULL, NULL, '   ');
     $this->add('select', 'visibility', ts('Visibility'), array('' => ts('- any visibility -')) + CRM_Core_SelectValues::ufVisibility(TRUE));
     $groupStatuses = array(ts('Enabled') => 1, ts('Disabled') => 2);
     $this->addCheckBox('group_status', ts('Status'), $groupStatuses, NULL, NULL, NULL, NULL, '   ');
     $this->addButtons(array(array('type' => 'refresh', 'name' => ts('Search'), 'isDefault' => TRUE)));
     parent::buildQuickForm();
     $this->assign('suppressForm', TRUE);
 }
Ejemplo n.º 2
0
 public function buildQuickForm()
 {
     $this->add('text', 'title', ts('Find'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'title'));
     require_once 'CRM/Core/OptionGroup.php';
     $groupTypes = CRM_Core_OptionGroup::values('group_type', true);
     $config =& CRM_Core_Config::singleton();
     if ($config->userFramework == 'Joomla') {
         unset($groupTypes['Access Control']);
     }
     $this->addCheckBox('group_type', ts('Type'), $groupTypes, null, null, null, null, '   ');
     $this->add('select', 'visibility', ts('Visibility'), array('' => ts('- any visibility -')) + CRM_Core_SelectValues::ufVisibility(true));
     $this->addElement('checkbox', 'active_status', ts('Enabled'));
     $this->addElement('checkbox', 'inactive_status', ts('Disabled'));
     $this->addButtons(array(array('type' => 'refresh', 'name' => ts('Search'), 'isDefault' => true)));
     parent::buildQuickForm();
 }
Ejemplo n.º 3
0
 /**
  * This function to get list of groups.
  *
  * @param array $params
  *   Associated array for params.
  *
  * @return array
  */
 public static function getGroupList(&$params)
 {
     $config = CRM_Core_Config::singleton();
     $whereClause = self::whereClause($params, FALSE);
     //$this->pagerAToZ( $whereClause, $params );
     if (!empty($params['rowCount']) && $params['rowCount'] > 0) {
         $limit = " LIMIT {$params['offset']}, {$params['rowCount']} ";
     }
     $orderBy = ' ORDER BY groups.title asc';
     if (!empty($params['sort'])) {
         $orderBy = ' ORDER BY ' . CRM_Utils_Type::escape($params['sort'], 'String');
         // CRM-16905 - Sort by count cannot be done with sql
         if (strpos($params['sort'], 'count') === 0) {
             $orderBy = $limit = '';
         }
     }
     $select = $from = $where = "";
     $groupOrg = FALSE;
     if (CRM_Core_Permission::check('administer Multiple Organizations') && CRM_Core_Permission::isMultisiteEnabled()) {
         $select = ", contact.display_name as org_name, contact.id as org_id";
         $from = " LEFT JOIN civicrm_group_organization gOrg\n                               ON gOrg.group_id = groups.id\n                        LEFT JOIN civicrm_contact contact\n                               ON contact.id = gOrg.organization_id ";
         //get the Organization ID
         $orgID = CRM_Utils_Request::retrieve('oid', 'Positive', CRM_Core_DAO::$_nullObject);
         if ($orgID) {
             $where = " AND gOrg.organization_id = {$orgID}";
         }
         $groupOrg = TRUE;
     }
     $query = "\n        SELECT groups.*, createdBy.sort_name as created_by {$select}\n        FROM  civicrm_group groups\n        LEFT JOIN civicrm_contact createdBy\n          ON createdBy.id = groups.created_id\n        {$from}\n        WHERE {$whereClause} {$where}\n        GROUP BY groups.id\n        {$orderBy}\n        {$limit}";
     $object = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Contact_DAO_Group');
     //FIXME CRM-4418, now we are handling delete separately
     //if we introduce 'delete for group' make sure to handle here.
     $groupPermissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('edit groups')) {
         $groupPermissions[] = CRM_Core_Permission::EDIT;
         $groupPermissions[] = CRM_Core_Permission::DELETE;
     }
     // CRM-9936
     $reservedPermission = CRM_Core_Permission::check('administer reserved groups');
     $links = self::actionLinks();
     $allTypes = CRM_Core_OptionGroup::values('group_type');
     $values = $groupsToCount = array();
     $visibility = CRM_Core_SelectValues::ufVisibility();
     while ($object->fetch()) {
         $permission = CRM_Contact_BAO_Group::checkPermission($object->id, $object->title);
         //@todo CRM-12209 introduced an ACL check in the whereClause function
         // it may be that this checking is now obsolete - or that what remains
         // should be removed to the whereClause (which is also accessed by getCount)
         if ($permission) {
             $newLinks = $links;
             $values[$object->id] = array('class' => array(), 'count' => '0');
             CRM_Core_DAO::storeValues($object, $values[$object->id]);
             // Wrap with crm-editable. Not an ideal solution.
             if (in_array(CRM_Core_Permission::EDIT, $groupPermissions)) {
                 $values[$object->id]['title'] = '<span class="crm-editable crmf-title">' . $values[$object->id]['title'] . '</span>';
             }
             if ($object->saved_search_id) {
                 $values[$object->id]['title'] .= ' (' . ts('Smart Group') . ')';
                 // check if custom search, if so fix view link
                 $customSearchID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $object->saved_search_id, 'search_custom_id');
                 if ($customSearchID) {
                     $newLinks[CRM_Core_Action::VIEW]['url'] = 'civicrm/contact/search/custom';
                     $newLinks[CRM_Core_Action::VIEW]['qs'] = "reset=1&force=1&ssID={$object->saved_search_id}";
                 }
             }
             $action = array_sum(array_keys($newLinks));
             // CRM-9936
             if (array_key_exists('is_reserved', $object)) {
                 //if group is reserved and I don't have reserved permission, suppress delete/edit
                 if ($object->is_reserved && !$reservedPermission) {
                     $action -= CRM_Core_Action::DELETE;
                     $action -= CRM_Core_Action::UPDATE;
                     $action -= CRM_Core_Action::DISABLE;
                 }
             }
             if (array_key_exists('is_active', $object)) {
                 if ($object->is_active) {
                     $action -= CRM_Core_Action::ENABLE;
                 } else {
                     $values[$object->id]['class'][] = 'disabled';
                     $action -= CRM_Core_Action::VIEW;
                     $action -= CRM_Core_Action::DISABLE;
                 }
             }
             $action = $action & CRM_Core_Action::mask($groupPermissions);
             $values[$object->id]['visibility'] = $visibility[$values[$object->id]['visibility']];
             $groupsToCount[$object->saved_search_id ? 'civicrm_group_contact_cache' : 'civicrm_group_contact'][] = $object->id;
             if (isset($values[$object->id]['group_type'])) {
                 $groupTypes = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($values[$object->id]['group_type'], 1, -1));
                 $types = array();
                 foreach ($groupTypes as $type) {
                     $types[] = CRM_Utils_Array::value($type, $allTypes);
                 }
                 $values[$object->id]['group_type'] = implode(', ', $types);
             }
             $values[$object->id]['action'] = CRM_Core_Action::formLink($newLinks, $action, array('id' => $object->id, 'ssid' => $object->saved_search_id), ts('more'), FALSE, 'group.selector.row', 'Group', $object->id);
             // If group has children, add class for link to view children
             $values[$object->id]['is_parent'] = FALSE;
             if (array_key_exists('children', $values[$object->id])) {
                 $values[$object->id]['class'][] = "crm-group-parent";
                 $values[$object->id]['is_parent'] = TRUE;
             }
             // If group is a child, add child class
             if (array_key_exists('parents', $values[$object->id])) {
                 $values[$object->id]['class'][] = "crm-group-child";
             }
             if ($groupOrg) {
                 if ($object->org_id) {
                     $contactUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$object->org_id}");
                     $values[$object->id]['org_info'] = "<a href='{$contactUrl}'>{$object->org_name}</a>";
                 } else {
                     $values[$object->id]['org_info'] = '';
                     // Empty cell
                 }
             } else {
                 $values[$object->id]['org_info'] = NULL;
                 // Collapsed column if all cells are NULL
             }
             if ($object->created_id) {
                 $contactUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$object->created_id}");
                 $values[$object->id]['created_by'] = "<a href='{$contactUrl}'>{$object->created_by}</a>";
             }
         }
     }
     // Get group counts - executes one query for regular groups and another for smart groups
     foreach ($groupsToCount as $table => $groups) {
         $where = "g.group_id IN (" . implode(',', $groups) . ")";
         if ($table == 'civicrm_group_contact') {
             $where .= " AND g.status = 'Added'";
         }
         // Exclude deleted contacts
         $where .= " and c.id = g.contact_id AND c.is_deleted = 0";
         $dao = CRM_Core_DAO::executeQuery("SELECT g.group_id, COUNT(g.id) as `count` FROM {$table} g, civicrm_contact c WHERE {$where} GROUP BY g.group_id");
         while ($dao->fetch()) {
             $values[$dao->group_id]['count'] = $dao->count;
         }
     }
     // CRM-16905 - Sort by count cannot be done with sql
     if (!empty($params['sort']) && strpos($params['sort'], 'count') === 0) {
         usort($values, function ($a, $b) {
             return $a['count'] - $b['count'];
         });
         if (strpos($params['sort'], 'desc')) {
             $values = array_reverse($values, TRUE);
         }
         return array_slice($values, $params['offset'], $params['rowCount']);
     }
     return $values;
 }
Ejemplo n.º 4
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete Profile Field'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     if (isset($this->_id)) {
         $params = array('id' => $this->_id);
         CRM_Core_BAO_UFField::retrieve($params, $defaults);
         // set it to null if so (avoids crappy E_NOTICE errors below
         $defaults['location_type_id'] = CRM_Utils_Array::value('location_type_id', $defaults);
         $specialFields = array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'postal_code_suffix', 'geo_code_1', 'geo_code_2', 'state_province', 'country', 'county', 'phone', 'email', 'im', 'address_name');
         if (!$defaults['location_type_id'] && in_array($defaults['field_name'], $specialFields)) {
             $defaults['location_type_id'] = 0;
         }
         $defaults['field_name'] = array($defaults['field_type'], $defaults['field_name'], $defaults['location_type_id'], CRM_Utils_Array::value('phone_type_id', $defaults));
         $this->_gid = $defaults['uf_group_id'];
     } else {
         $defaults['is_active'] = 1;
     }
     if ($this->_action & CRM_Core_Action::ADD) {
         $fieldValues = array('uf_group_id' => $this->_gid);
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_UFField', $fieldValues);
     }
     // lets trim all the whitespace
     $this->applyFilter('__ALL__', 'trim');
     //hidden field to catch the group id in profile
     $this->add('hidden', 'group_id', $this->_gid);
     //hidden field to catch the field id in profile
     $this->add('hidden', 'field_id', $this->_id);
     $fields = array();
     $fields['Individual'] =& CRM_Contact_BAO_Contact::importableFields('Individual', false, false, true);
     $fields['Household'] =& CRM_Contact_BAO_Contact::importableFields('Household', false, false, true);
     $fields['Organization'] =& CRM_Contact_BAO_Contact::importableFields('Organization', false, false, true);
     // add current employer for individuals
     $fields['Individual']['current_employer'] = array('name' => 'organization_name', 'title' => ts('Current Employer'));
     // unset unwanted fields
     $unsetFieldArray = array('note', 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom', 'id');
     foreach ($unsetFieldArray as $value) {
         unset($fields['Individual'][$value]);
         unset($fields['Household'][$value]);
         unset($fields['Organization'][$value]);
     }
     require_once 'CRM/Core/BAO/Preferences.php';
     $addressOptions = CRM_Core_BAO_Preferences::valueOptions('address_options', true, null, true);
     if (!$addressOptions['county']) {
         unset($fields['Individual']['county']);
         unset($fields['Household']['county']);
         unset($fields['Organization']['county']);
     }
     //build the common contact fields array CRM-3037.
     foreach ($fields['Individual'] as $key => $value) {
         if (CRM_Utils_Array::value($key, $fields['Household']) && CRM_Utils_Array::value($key, $fields['Organization'])) {
             $fields['Contact'][$key] = $value;
             //as we move common fields to contacts. There fore these fields
             //are unset from resoective array's.
             unset($fields['Individual'][$key]);
             unset($fields['Household'][$key]);
             unset($fields['Organization'][$key]);
         }
     }
     // add current employer for individuals
     $fields['Contact']['id'] = array('name' => 'id', 'title' => ts('Internal Contact ID'));
     unset($fields['Contact']['contact_type']);
     // since we need a hierarchical list to display contact types & subtypes,
     // this is what we going to display in first selector
     $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(false, false);
     unset($contactTypes['']);
     // include Subtypes For Profile
     $subTypes = CRM_Contact_BAO_ContactType::subTypeInfo();
     foreach ($subTypes as $name => $val) {
         //custom fields for sub type
         $subTypeFields = CRM_Core_BAO_CustomField::getFieldsForImport($name);
         if (array_key_exists($val['parent'], $fields)) {
             $fields[$name] = $fields[$val['parent']] + $subTypeFields;
         } else {
             $fields[$name] = $subTypeFields;
         }
     }
     unset($subTypes);
     if (CRM_Core_Permission::access('Quest')) {
         require_once 'CRM/Quest/BAO/Student.php';
         $fields['Student'] =& CRM_Quest_BAO_Student::exportableFields();
     }
     if (CRM_Core_Permission::access('CiviContribute')) {
         $contribFields =& CRM_Contribute_BAO_Contribution::getContributionFields();
         if (!empty($contribFields)) {
             unset($contribFields['is_test']);
             unset($contribFields['is_pay_later']);
             unset($contribFields['contribution_id']);
             $fields['Contribution'] =& $contribFields;
         }
     }
     if (CRM_Core_Permission::access('CiviEvent')) {
         require_once 'CRM/Event/BAO/Query.php';
         $participantFields =& CRM_Event_BAO_Query::getParticipantFields(true);
         if (!empty($participantFields)) {
             unset($participantFields['external_identifier']);
             unset($participantFields['event_id']);
             unset($participantFields['participant_contact_id']);
             unset($participantFields['participant_is_test']);
             unset($participantFields['participant_fee_level']);
             unset($participantFields['participant_id']);
             unset($participantFields['participant_is_pay_later']);
             $fields['Participant'] =& $participantFields;
         }
     }
     if (CRM_Core_Permission::access('CiviMember')) {
         require_once 'CRM/Member/BAO/Membership.php';
         $membershipFields =& CRM_Member_BAO_Membership::getMembershipFields();
         unset($membershipFields['membership_id']);
         unset($membershipFields['join_date']);
         unset($membershipFields['membership_start_date']);
         unset($membershipFields['membership_type_id']);
         unset($membershipFields['membership_end_date']);
         unset($membershipFields['member_is_test']);
         unset($membershipFields['is_override']);
         unset($membershipFields['status_id']);
         unset($membershipFields['member_is_pay_later']);
         $fields['Membership'] =& $membershipFields;
     }
     $noSearchable = array();
     foreach ($fields as $key => $value) {
         foreach ($value as $key1 => $value1) {
             //CRM-2676, replacing the conflict for same custom field name from different custom group.
             require_once 'CRM/Core/BAO/CustomField.php';
             if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key1)) {
                 $customGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $customFieldId, 'custom_group_id');
                 $customGroupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $customGroupId, 'title');
                 $this->_mapperFields[$key][$key1] = $value1['title'] . ' :: ' . $customGroupName;
             } else {
                 $this->_mapperFields[$key][$key1] = $value1['title'];
             }
             $hasLocationTypes[$key][$key1] = CRM_Utils_Array::value('hasLocationType', $value1);
             // hide the 'is searchable' field for 'File' custom data
             if (isset($value1['data_type']) && isset($value1['html_type']) && ($value1['data_type'] == 'File' && $value1['html_type'] == 'File' || $value1['data_type'] == 'Link' && $value1['html_type'] == 'Link')) {
                 if (!in_array($value1['title'], $noSearchable)) {
                     $noSearchable[] = $value1['title'];
                 }
             }
         }
     }
     $this->assign('noSearchable', $noSearchable);
     require_once 'CRM/Core/BAO/LocationType.php';
     $this->_location_types =& CRM_Core_PseudoConstant::locationType();
     $defaultLocationType =& CRM_Core_BAO_LocationType::getDefault();
     /* FIXME: dirty hack to make the default option show up first.  This
      * avoids a mozilla browser bug with defaults on dynamically constructed
      * selector widgets. */
     if ($defaultLocationType) {
         $defaultLocation = $this->_location_types[$defaultLocationType->id];
         unset($this->_location_types[$defaultLocationType->id]);
         $this->_location_types = array($defaultLocationType->id => $defaultLocation) + $this->_location_types;
     }
     $this->_location_types = array('Primary') + $this->_location_types;
     $contactTypes = !empty($contactTypes) ? array('Contact' => 'Contacts') + $contactTypes : array();
     $sel1 = array('' => '- select -') + $contactTypes;
     if (CRM_Core_Permission::access('Quest')) {
         $sel1['Student'] = 'Students';
     }
     if (CRM_Core_Permission::access('CiviEvent')) {
         $sel1['Participant'] = 'Participants';
     }
     if (!empty($contribFields)) {
         $sel1['Contribution'] = 'Contributions';
     }
     if (!empty($membershipFields)) {
         $sel1['Membership'] = 'Membership';
     }
     foreach ($sel1 as $key => $sel) {
         if ($key) {
             $sel2[$key] = $this->_mapperFields[$key];
         }
     }
     $sel3[''] = null;
     $phoneTypes = CRM_Core_PseudoConstant::phoneType();
     ksort($phoneTypes);
     foreach ($sel1 as $k => $sel) {
         if ($k) {
             foreach ($this->_location_types as $key => $value) {
                 $sel4[$k]['phone'][$key] =& $phoneTypes;
             }
         }
     }
     foreach ($sel1 as $k => $sel) {
         if ($k) {
             if (is_array($this->_mapperFields[$k])) {
                 foreach ($this->_mapperFields[$k] as $key => $value) {
                     if ($hasLocationTypes[$k][$key]) {
                         $sel3[$k][$key] = $this->_location_types;
                     } else {
                         $sel3[$key] = null;
                     }
                 }
             }
         }
     }
     $this->_defaults = array();
     $js = "<script type='text/javascript'>\n";
     $formName = "document.{$this->_name}";
     $alreadyMixProfile = false;
     if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) {
         $alreadyMixProfile = true;
     }
     $this->assign('alreadyMixProfile', $alreadyMixProfile);
     $attributes = array('onclick' => "showLabel();mixProfile();", 'onblur' => 'showLabel();mixProfile();');
     $sel =& $this->addElement('hierselect', "field_name", ts('Field Name'), $attributes);
     $formValues = array();
     $formValues = $this->exportValues();
     if (empty($formValues)) {
         for ($k = 1; $k < 4; $k++) {
             if (!$defaults['field_name'][$k]) {
                 $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n";
             }
         }
     } else {
         if (!empty($formValues['field_name'])) {
             foreach ($formValues['field_name'] as $value) {
                 for ($k = 1; $k < 4; $k++) {
                     if (!isset($formValues['field_name'][$k]) || !$formValues['field_name'][$k]) {
                         $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n";
                     } else {
                         $js .= "{$formName}['field_name[{$k}]'].style.display = '';\n";
                     }
                 }
             }
         } else {
             for ($k = 1; $k < 4; $k++) {
                 if (!isset($defaults['field_name'][$k])) {
                     $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n";
                 }
             }
         }
     }
     foreach ($sel2 as $k => $v) {
         if (is_array($sel2[$k])) {
             asort($sel2[$k]);
         }
     }
     $sel->setOptions(array($sel1, $sel2, $sel3, $sel4));
     $js .= "</script>\n";
     $this->assign('initHideBoxes', $js);
     $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::ufVisibility(), true, array("onChange" => "showHideSeletorSearch(this.value);"));
     //CRM-4363
     $js = array('onclick' => "mixProfile();");
     // should the field appear in selectors (as a column)?
     $this->add('checkbox', 'in_selector', ts('Results Column?'), null, null, $js);
     $this->add('checkbox', 'is_searchable', ts('Searchable?'), null, null, $js);
     // weight
     $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'weight'), true);
     $this->addRule('weight', ts('is a numeric field'), 'numeric');
     $this->add('textarea', 'help_post', ts('Field Help'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'help_post'));
     // listings title
     $this->add('text', 'listings_title', ts('Listings Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'listings_title'));
     $this->addRule('listings_title', ts('Please enter a valid title for this field when displayed in user listings.'), 'title');
     $this->add('checkbox', 'is_required', ts('Required?'));
     $this->add('checkbox', 'is_active', ts('Active?'));
     $this->add('checkbox', 'is_view', ts('View Only?'));
     // $this->add( 'checkbox', 'is_registration', ts( 'Display in Registration Form?' ) );
     //$this->add( 'checkbox', 'is_match'       , ts( 'Key to Match Contacts?'        ) );
     $this->add('text', 'label', ts('Field Label'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'label'));
     $js = null;
     if ($this->_hasSearchableORInSelector) {
         $js = array('onclick' => "return verify( );");
     }
     // add buttons
     $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => true, 'js' => $js), array('type' => 'next', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $js), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $this->addFormRule(array('CRM_UF_Form_Field', 'formRule'), $this);
     // if view mode pls freeze it with the done button.
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
         $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/uf/group/field?reset=1&action=browse&gid=" . $this->_gid . "'"));
     }
     $this->setDefaults($defaults);
 }
Ejemplo n.º 5
0
 /**
  * Function to actually build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     if ($this->_action == CRM_Core_Action::DELETE) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete Group'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     $this->add('text', 'title', ts('Name') . ' ', CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'title'), TRUE);
     $this->add('textarea', 'description', ts('Description') . ' ', CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'description'));
     $groupTypes = CRM_Core_OptionGroup::values('group_type', TRUE);
     $config = CRM_Core_Config::singleton();
     if (isset($this->_id) && CRM_Utils_Array::value('saved_search_id', $this->_groupValues)) {
         unset($groupTypes['Access Control']);
     }
     if (!empty($groupTypes)) {
         $this->addCheckBox('group_type', ts('Group Type'), $groupTypes, NULL, NULL, NULL, NULL, '&nbsp;&nbsp;&nbsp;');
     }
     $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::ufVisibility(TRUE), TRUE);
     $groupNames = CRM_Core_PseudoConstant::group();
     $parentGroups = $parentGroupElements = array();
     if (isset($this->_id) && CRM_Utils_Array::value('parents', $this->_groupValues)) {
         $parentGroupIds = explode(',', $this->_groupValues['parents']);
         foreach ($parentGroupIds as $parentGroupId) {
             $parentGroups[$parentGroupId] = $groupNames[$parentGroupId];
             if (array_key_exists($parentGroupId, $groupNames)) {
                 $parentGroupElements[$parentGroupId] = $groupNames[$parentGroupId];
                 $this->addElement('checkbox', "remove_parent_group_{$parentGroupId}", $groupNames[$parentGroupId]);
             }
         }
     }
     $this->assign_by_ref('parent_groups', $parentGroupElements);
     if (isset($this->_id)) {
         $potentialParentGroupIds = CRM_Contact_BAO_GroupNestingCache::getPotentialCandidates($this->_id, $groupNames);
     } else {
         $potentialParentGroupIds = array_keys($groupNames);
     }
     $parentGroupSelectValues = array('' => '- ' . ts('select') . ' -');
     foreach ($potentialParentGroupIds as $potentialParentGroupId) {
         if (array_key_exists($potentialParentGroupId, $groupNames)) {
             $parentGroupSelectValues[$potentialParentGroupId] = $groupNames[$potentialParentGroupId];
         }
     }
     if (count($parentGroupSelectValues) > 1) {
         if (CRM_Core_Permission::isMultisiteEnabled()) {
             $required = empty($parentGroups) ? TRUE : FALSE;
             $required = $this->_id && CRM_Core_BAO_Domain::isDomainGroup($this->_id) || !isset($this->_id) ? FALSE : $required;
         } else {
             $required = FALSE;
         }
         $this->add('select', 'parents', ts('Add Parent'), $parentGroupSelectValues, $required);
     }
     if (CRM_Core_Permission::check('administer Multiple Organizations') && CRM_Core_Permission::isMultisiteEnabled()) {
         //group organization Element
         $groupOrgDataURL = CRM_Utils_System::url('civicrm/ajax/search', 'org=1', FALSE, NULL, FALSE);
         $this->assign('groupOrgDataURL', $groupOrgDataURL);
         $this->addElement('text', 'organization', ts('Organization'), '');
         $this->addElement('hidden', 'organization_id', '', array('id' => 'organization_id'));
     }
     // is_reserved property CRM-9936
     $this->addElement('checkbox', 'is_reserved', ts('Reserved Group?'));
     if (!CRM_Core_Permission::check('administer reserved groups')) {
         $this->freeze('is_reserved');
     }
     //build custom data
     CRM_Custom_Form_CustomData::buildQuickForm($this);
     $this->addButtons(array(array('type' => 'upload', 'name' => $this->_action == CRM_Core_Action::ADD ? ts('Continue') : ts('Save'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $doParentCheck = FALSE;
     if (CRM_Core_Permission::isMultisiteEnabled()) {
         $doParentCheck = $this->_id && CRM_Core_BAO_Domain::isDomainGroup($this->_id) ? FALSE : TRUE;
     }
     $options = array('selfObj' => $this, 'parentGroups' => $parentGroups, 'doParentCheck' => $doParentCheck);
     $this->addFormRule(array('CRM_Group_Form_Edit', 'formRule'), $options);
 }
Ejemplo n.º 6
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 function buildQuickForm()
 {
     if ($this->_action & CRM_CORE_ACTION_DELETE) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete Profile Field'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     if (isset($this->_id)) {
         $params = array('id' => $this->_id);
         CRM_Core_BAO_UFField::retrieve($params, $defaults);
         $defaults['field_name'] = array($defaults['field_type'], $defaults['field_name'], $defaults['location_type_id'], $defaults['phone_type']);
         $this->_gid = $defaults['uf_group_id'];
     } else {
         $defaults['is_active'] = 1;
     }
     if ($this->_action & CRM_CORE_ACTION_ADD) {
         $uf =& new CRM_Core_DAO();
         $sql = "SELECT weight FROM civicrm_uf_field  WHERE uf_group_id = " . $this->_gid . " ORDER BY weight  DESC LIMIT 0, 1";
         $uf->query($sql);
         while ($uf->fetch()) {
             $defaults['weight'] = $uf->weight + 1;
         }
         if (empty($defaults['weight'])) {
             $defaults['weight'] = 1;
         }
     }
     // lets trim all the whitespace
     $this->applyFilter('__ALL__', 'trim');
     //hidden field to catch the group id in profile
     $this->add('hidden', 'group_id', $this->_gid);
     //hidden field to catch the field id in profile
     $this->add('hidden', 'field_id', $this->_id);
     $fields = array();
     $fields['Individual'] =& CRM_Contact_BAO_Contact::exportableFields('Individual');
     $fields['Household'] =& CRM_Contact_BAO_Contact::exportableFields('Household');
     $fields['Organization'] =& CRM_Contact_BAO_Contact::exportableFields('Organization');
     $contribFields =& CRM_Contribute_BAO_Contribution::getContributionFields();
     if (!empty($contribFields)) {
         $fields['Contribution'] =& $contribFields;
     }
     foreach ($fields as $key => $value) {
         foreach ($value as $key1 => $value1) {
             $this->_mapperFields[$key][$key1] = $value1['title'];
             $hasLocationTypes[$key][$key1] = $value1['hasLocationType'];
         }
     }
     require_once 'CRM/Core/BAO/LocationType.php';
     $this->_location_types =& CRM_Core_PseudoConstant::locationType();
     $defaultLocationType =& CRM_Core_BAO_LocationType::getDefault();
     /* FIXME: dirty hack to make the default option show up first.  This
      * avoids a mozilla browser bug with defaults on dynamically constructed
      * selector widgets. */
     if ($defaultLocationType) {
         $defaultLocation = $this->_location_types[$defaultLocationType->id];
         unset($this->_location_types[$defaultLocationType->id]);
         $this->_location_types = array($defaultLocationType->id => $defaultLocation) + $this->_location_types;
     }
     $sel1 = array('' => '-select-') + CRM_Core_SelectValues::contactType();
     if (!empty($contribFields)) {
         $sel1['Contribution'] = 'Contributions';
     }
     foreach ($sel1 as $key => $sel) {
         if ($key) {
             $sel2[$key] = $this->_mapperFields[$key];
         }
     }
     $sel3[''] = null;
     $phoneTypes = CRM_Core_SelectValues::phoneType();
     foreach ($sel1 as $k => $sel) {
         if ($k) {
             foreach ($this->_location_types as $key => $value) {
                 $sel4[$k]['phone'][$key] =& $phoneTypes;
             }
         }
     }
     foreach ($sel1 as $k => $sel) {
         if ($k) {
             foreach ($this->_mapperFields[$k] as $key => $value) {
                 if ($hasLocationTypes[$k][$key]) {
                     $sel3[$k][$key] = $this->_location_types;
                 } else {
                     $sel3[$key] = null;
                 }
             }
         }
     }
     $this->_defaults = array();
     $js = "<script type='text/javascript'>\n";
     $formName = "document.{$this->_name}";
     $sel =& $this->addElement('hierselect', "field_name", ts('Field Name'), 'onclick="showLabel();"');
     $formValues = array();
     //$formValues = $this->controller->exportValues( $this->_name );
     $formValues = $_POST;
     // using $_POST since export values don't give values on first submit
     if (empty($formValues)) {
         for ($k = 1; $k < 4; $k++) {
             if (!$defaults['field_name'][$k]) {
                 $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n";
             }
         }
     } else {
         foreach ($formValues['field_name'] as $value) {
             for ($k = 1; $k < 4; $k++) {
                 if (!$formValues['field_name'][$k]) {
                     $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n";
                 }
             }
         }
     }
     $sel->setOptions(array($sel1, $sel2, $sel3, $sel4));
     $js .= "</script>\n";
     $this->assign('initHideBoxes', $js);
     $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::ufVisibility(), true);
     // should the field appear in selector?
     $this->add('checkbox', 'in_selector', ts('In Selector?'));
     // weight
     $this->add('text', 'weight', ts('Weight'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'weight'), true);
     $this->addRule('weight', ts(' is a numeric field'), 'numeric');
     $this->add('textarea', 'help_post', ts('Field Help'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'help_post'));
     // listings title
     $this->add('text', 'listings_title', ts('Listings Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'listings_title'));
     $this->addRule('listings_title', ts('Please enter a valid title for this field when displayed in user listings.'), 'title');
     $this->add('checkbox', 'is_required', ts('Required?'));
     $this->add('checkbox', 'is_active', ts('Active?'));
     $this->add('checkbox', 'is_searchable', ts('Searchable?'));
     $this->add('checkbox', 'is_view', ts('View Only?'));
     // $this->add( 'checkbox', 'is_registration', ts( 'Display in Registration Form?' ) );
     //$this->add( 'checkbox', 'is_match'       , ts( 'Key to Match Contacts?'        ) );
     $this->add('text', 'label', ts('Field Label'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'label'));
     // add buttons
     $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $this->addFormRule(array('CRM_UF_Form_Field', 'formRule'));
     // if view mode pls freeze it with the done button.
     if ($this->_action & CRM_CORE_ACTION_VIEW) {
         $this->freeze();
         $this->addElement('button', 'done', ts('Done'), array('onClick' => "location.href='civicrm/admin/uf/group/field?reset=1&action=browse&gid=" . $this->_gid . "'"));
     }
     $this->setDefaults($defaults);
 }
Ejemplo n.º 7
0
 /**
  * Build the form object.
  *
  * @return void
  */
 public function buildQuickForm()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete Profile Field'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     if (isset($this->_id)) {
         $params = array('id' => $this->_id);
         CRM_Core_BAO_UFField::retrieve($params, $defaults);
         // set it to null if so (avoids crappy E_NOTICE errors below
         $defaults['location_type_id'] = CRM_Utils_Array::value('location_type_id', $defaults);
         $specialFields = CRM_Core_BAO_UFGroup::getLocationFields();
         if (!$defaults['location_type_id'] && $defaults["field_type"] != "Formatting" && in_array($defaults['field_name'], $specialFields)) {
             $defaults['location_type_id'] = 0;
         }
         $defaults['field_name'] = array($defaults['field_type'], $defaults['field_type'] == "Formatting" ? "" : $defaults['field_name'], $defaults['field_name'] == "url" ? $defaults['website_type_id'] : $defaults['location_type_id'], CRM_Utils_Array::value('phone_type_id', $defaults));
         $this->_gid = $defaults['uf_group_id'];
     } else {
         $defaults['is_active'] = 1;
     }
     $otherModules = array_values(CRM_Core_BAO_UFGroup::getUFJoinRecord($this->_gid));
     $this->assign('otherModules', $otherModules);
     if ($this->_action & CRM_Core_Action::ADD) {
         $fieldValues = array('uf_group_id' => $this->_gid);
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_UFField', $fieldValues);
     }
     // lets trim all the whitespace
     $this->applyFilter('__ALL__', 'trim');
     //hidden field to catch the group id in profile
     $this->add('hidden', 'group_id', $this->_gid);
     //hidden field to catch the field id in profile
     $this->add('hidden', 'field_id', $this->_id);
     $fields = CRM_Core_BAO_UFField::getAvailableFields($this->_gid, $defaults);
     $noSearchable = $hasWebsiteTypes = array();
     $addressCustomFields = array_keys(CRM_Core_BAO_CustomField::getFieldsForImport('Address'));
     foreach ($fields as $key => $value) {
         foreach ($value as $key1 => $value1) {
             //CRM-2676, replacing the conflict for same custom field name from different custom group.
             if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key1)) {
                 $customGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $customFieldId, 'custom_group_id');
                 $customGroupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $customGroupId, 'title');
                 $this->_mapperFields[$key][$key1] = $value1['title'] . ' :: ' . $customGroupName;
                 if (in_array($key1, $addressCustomFields)) {
                     $noSearchable[] = $value1['title'] . ' :: ' . $customGroupName;
                 }
             } else {
                 $this->_mapperFields[$key][$key1] = $value1['title'];
             }
             $hasLocationTypes[$key][$key1] = CRM_Utils_Array::value('hasLocationType', $value1);
             $hasWebsiteTypes[$key][$key1] = CRM_Utils_Array::value('hasWebsiteType', $value1);
             // hide the 'is searchable' field for 'File' custom data
             if (isset($value1['data_type']) && isset($value1['html_type']) && ($value1['data_type'] == 'File' && $value1['html_type'] == 'File' || $value1['data_type'] == 'Link' && $value1['html_type'] == 'Link')) {
                 if (!in_array($value1['title'], $noSearchable)) {
                     $noSearchable[] = $value1['title'];
                 }
             }
         }
     }
     $this->assign('noSearchable', $noSearchable);
     $this->_location_types = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
     $defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
     $this->_website_types = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id');
     /**
      * FIXME: dirty hack to make the default option show up first.  This
      * avoids a mozilla browser bug with defaults on dynamically constructed
      * selector widgets.
      */
     if ($defaultLocationType) {
         $defaultLocation = $this->_location_types[$defaultLocationType->id];
         unset($this->_location_types[$defaultLocationType->id]);
         $this->_location_types = array($defaultLocationType->id => $defaultLocation) + $this->_location_types;
     }
     $this->_location_types = array('Primary') + $this->_location_types;
     // since we need a hierarchical list to display contact types & subtypes,
     // this is what we going to display in first selector
     $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(FALSE, FALSE);
     unset($contactTypes['']);
     $contactTypes = !empty($contactTypes) ? array('Contact' => 'Contacts') + $contactTypes : array();
     $sel1 = array('' => '- select -') + $contactTypes;
     if (!empty($fields['Activity'])) {
         $sel1['Activity'] = 'Activity';
     }
     if (CRM_Core_Permission::access('CiviEvent')) {
         $sel1['Participant'] = 'Participants';
     }
     if (!empty($fields['Contribution'])) {
         $sel1['Contribution'] = 'Contributions';
     }
     if (!empty($fields['Membership'])) {
         $sel1['Membership'] = 'Membership';
     }
     if (!empty($fields['Case'])) {
         $sel1['Case'] = 'Case';
     }
     if (!empty($fields['Formatting'])) {
         $sel1['Formatting'] = 'Formatting';
     }
     foreach ($sel1 as $key => $sel) {
         if ($key) {
             $sel2[$key] = $this->_mapperFields[$key];
         }
     }
     $sel3[''] = NULL;
     $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
     ksort($phoneTypes);
     foreach ($sel1 as $k => $sel) {
         if ($k) {
             foreach ($this->_location_types as $key => $value) {
                 $sel4[$k]['phone'][$key] =& $phoneTypes;
                 $sel4[$k]['phone_and_ext'][$key] =& $phoneTypes;
             }
         }
     }
     foreach ($sel1 as $k => $sel) {
         if ($k) {
             if (is_array($this->_mapperFields[$k])) {
                 foreach ($this->_mapperFields[$k] as $key => $value) {
                     if ($hasLocationTypes[$k][$key]) {
                         $sel3[$k][$key] = $this->_location_types;
                     } elseif ($hasWebsiteTypes[$k][$key]) {
                         $sel3[$k][$key] = $this->_website_types;
                     } else {
                         $sel3[$key] = NULL;
                     }
                 }
             }
         }
     }
     $this->_defaults = array();
     $js = "<script type='text/javascript'>\n";
     $formName = "document.{$this->_name}";
     $alreadyMixProfile = FALSE;
     if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) {
         $alreadyMixProfile = TRUE;
     }
     $this->assign('alreadyMixProfile', $alreadyMixProfile);
     $sel =& $this->addElement('hierselect', 'field_name', ts('Field Name'));
     $formValues = $this->exportValues();
     if (empty($formValues)) {
         for ($k = 1; $k < 4; $k++) {
             if (!isset($defaults['field_name'][$k])) {
                 $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n";
             }
         }
     } else {
         if (!empty($formValues['field_name'])) {
             for ($key = 1; $key < 4; $key++) {
                 if (!isset($formValues['field_name'][$key])) {
                     $js .= "{$formName}['field_name[{$key}]'].style.display = 'none';\n";
                 } else {
                     $js .= "{$formName}['field_name[{$key}]'].style.display = '';\n";
                 }
             }
         } else {
             for ($k = 1; $k < 4; $k++) {
                 if (!isset($defaults['field_name'][$k])) {
                     $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n";
                 }
             }
         }
     }
     foreach ($sel2 as $k => $v) {
         if (is_array($sel2[$k])) {
             asort($sel2[$k]);
         }
     }
     $sel->setOptions(array($sel1, $sel2, $sel3, $sel4));
     // proper interpretation of spec in CRM-8732
     if (!isset($this->_id) && in_array('Search Profile', $otherModules)) {
         $defaults['visibility'] = 'Public Pages and Listings';
     }
     $js .= "</script>\n";
     $this->assign('initHideBoxes', $js);
     $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::ufVisibility(), TRUE, array('onChange' => "showHideSeletorSearch(this.value);"));
     //CRM-4363
     $js = array('onChange' => "mixProfile();");
     // should the field appear in selectors (as a column)?
     $this->add('checkbox', 'in_selector', ts('Results Column?'), NULL, NULL, $js);
     $this->add('checkbox', 'is_searchable', ts('Searchable?'), NULL, NULL, $js);
     $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField');
     // weight
     $this->add('text', 'weight', ts('Order'), $attributes['weight'], TRUE);
     $this->addRule('weight', ts('is a numeric field'), 'numeric');
     $this->add('textarea', 'help_pre', ts('Field Pre Help'), $attributes['help_pre']);
     $this->add('textarea', 'help_post', ts('Field Post Help'), $attributes['help_post']);
     $this->add('checkbox', 'is_required', ts('Required?'));
     $this->add('checkbox', 'is_multi_summary', ts('Include in multi-record listing?'));
     $this->add('checkbox', 'is_active', ts('Active?'));
     $this->add('checkbox', 'is_view', ts('View Only?'));
     // $this->add( 'checkbox', 'is_registration', ts( 'Display in Registration Form?' ) );
     //$this->add( 'checkbox', 'is_match'       , ts( 'Key to Match Contacts?'        ) );
     $this->add('text', 'label', ts('Field Label'), $attributes['label']);
     $js = NULL;
     if ($this->_hasSearchableORInSelector) {
         $js = array('onclick' => "return verify( );");
     }
     // add buttons
     $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE, 'js' => $js), array('type' => 'next', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $js), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $this->addFormRule(array('CRM_UF_Form_Field', 'formRule'), $this);
     // if view mode pls freeze it with the done button.
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
         $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/uf/group/field?reset=1&action=browse&gid=" . $this->_gid . "'"));
     }
     $this->setDefaults($defaults);
 }
Ejemplo n.º 8
0
 /**
  * Function to actually build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     if ($this->_action == CRM_Core_Action::DELETE) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete Group'), 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     $this->add('text', 'title', ts('Name') . ' ', CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'title'), true);
     $this->addRule('title', ts('Name already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Group', $this->_id, 'title'));
     $this->add('textarea', 'description', ts('Description') . ' ', CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'description'));
     require_once 'CRM/Core/OptionGroup.php';
     $groupTypes = CRM_Core_OptionGroup::values('group_type', true);
     $config =& CRM_Core_Config::singleton();
     if (isset($this->_id) && CRM_Utils_Array::value('saved_search_id', $this->_groupValues) || $config->userFramework == 'Joomla') {
         unset($groupTypes['Access Control']);
     }
     if (!CRM_Core_Permission::access('CiviMail')) {
         unset($groupTypes['Mailing List']);
     }
     if (!empty($groupTypes)) {
         $this->addCheckBox('group_type', ts('Group Type'), $groupTypes, null, null, null, null, '&nbsp;&nbsp;&nbsp;');
     }
     $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::ufVisibility(true), true);
     $groupNames =& CRM_Core_PseudoConstant::group();
     $parentGroups = array();
     if (isset($this->_id) && CRM_Utils_Array::value('parents', $this->_groupValues)) {
         $parentGroupIds = explode(',', $this->_groupValues['parents']);
         foreach ($parentGroupIds as $parentGroupId) {
             $parentGroups[$parentGroupId] = $groupNames[$parentGroupId];
             $this->addElement('checkbox', "remove_parent_group_{$parentGroupId}", $groupNames[$parentGroupId]);
         }
     }
     $this->assign_by_ref('parent_groups', $parentGroups);
     if (isset($this->_id)) {
         require_once 'CRM/Contact/BAO/GroupNestingCache.php';
         $potentialParentGroupIds = CRM_Contact_BAO_GroupNestingCache::getPotentialCandidates($this->_id, $groupNames);
     } else {
         $potentialParentGroupIds = array_keys($groupNames);
     }
     $parentGroupSelectValues = array('' => '- ' . ts('select') . ' -');
     foreach ($potentialParentGroupIds as $potentialParentGroupId) {
         if (array_key_exists($potentialParentGroupId, $groupNames)) {
             $parentGroupSelectValues[$potentialParentGroupId] = $groupNames[$potentialParentGroupId];
         }
     }
     if (count($parentGroupSelectValues) > 1) {
         if (defined('CIVICRM_MULTISITE') && CIVICRM_MULTISITE) {
             $required = empty($parentGroups) ? true : false;
             $required = $this->_id && CRM_Core_BAO_Domain::isDomainGroup($this->_id) ? false : $required;
         } else {
             $required = false;
         }
         $this->add('select', 'parents', ts('Add Parent'), $parentGroupSelectValues, $required);
     }
     if (defined('CIVICRM_MULTISITE') && CIVICRM_MULTISITE && CRM_Core_Permission::check('administer Multiple Organizations')) {
         //group organization Element
         $groupOrgDataURL = CRM_Utils_System::url('civicrm/ajax/search', 'org=1', false, null, false);
         $this->assign('groupOrgDataURL', $groupOrgDataURL);
         $this->addElement('text', 'organization', ts('Organization'), '');
         $this->addElement('hidden', 'organization_id', '', array('id' => 'organization_id'));
     }
     //build custom data
     CRM_Custom_Form_Customdata::buildQuickForm($this);
     $this->addButtons(array(array('type' => 'upload', 'name' => $this->_action == CRM_Core_Action::ADD ? ts('Continue') : ts('Save'), 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
     if (defined('CIVICRM_MULTISITE') && CIVICRM_MULTISITE) {
         $doParentCheck = $this->_id && CRM_Core_BAO_Domain::isDomainGroup($this->_id) ? false : true;
     } else {
         $doParentCheck = false;
     }
     if ($doParentCheck) {
         $this->addFormRule(array('CRM_Group_Form_Edit', 'formRule'), $parentGroups);
     }
 }
Ejemplo n.º 9
0
 /**
  * Browse all CiviCRM Profile group fields.
  *
  * @return void
  */
 public function browse()
 {
     $resourceManager = CRM_Core_Resources::singleton();
     if (!empty($_GET['new']) && $resourceManager->ajaxPopupsEnabled) {
         $resourceManager->addScriptFile('civicrm', 'js/crm.addNew.js', 999, 'html-header');
     }
     $ufField = array();
     $ufFieldBAO = new CRM_Core_BAO_UFField();
     // fkey is gid
     $ufFieldBAO->uf_group_id = $this->_gid;
     $ufFieldBAO->orderBy('weight', 'field_name');
     $ufFieldBAO->find();
     $otherModules = CRM_Core_BAO_UFGroup::getUFJoinRecord($this->_gid);
     $this->assign('otherModules', $otherModules);
     $isGroupReserved = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'is_reserved');
     $this->assign('isGroupReserved', $isGroupReserved);
     $profileType = CRM_Core_BAO_UFField::getProfileType($this->_gid);
     if ($profileType == 'Contribution' || $profileType == 'Membership' || $profileType == 'Activity' || $profileType == 'Participant') {
         $this->assign('skipCreate', TRUE);
     }
     $locationType = array();
     $locationType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
     $fields = CRM_Contact_BAO_Contact::exportableFields('All', FALSE, TRUE);
     $fields = array_merge(CRM_Contribute_BAO_Contribution::getContributionFields(), $fields);
     $select = array();
     foreach ($fields as $name => $field) {
         if ($name) {
             $select[$name] = $field['title'];
         }
     }
     $select['group'] = ts('Group(s)');
     $select['tag'] = ts('Tag(s)');
     $visibility = CRM_Core_SelectValues::ufVisibility();
     while ($ufFieldBAO->fetch()) {
         $ufField[$ufFieldBAO->id] = array();
         $phoneType = $locType = '';
         CRM_Core_DAO::storeValues($ufFieldBAO, $ufField[$ufFieldBAO->id]);
         $ufField[$ufFieldBAO->id]['visibility_display'] = $visibility[$ufFieldBAO->visibility];
         $ufField[$ufFieldBAO->id]['label'] = $ufFieldBAO->label;
         $action = array_sum(array_keys($this->actionLinks()));
         if ($ufFieldBAO->is_active) {
             $action -= CRM_Core_Action::ENABLE;
         } else {
             $action -= CRM_Core_Action::DISABLE;
         }
         if ($ufFieldBAO->is_reserved) {
             $action -= CRM_Core_Action::UPDATE;
             $action -= CRM_Core_Action::DISABLE;
             $action -= CRM_Core_Action::DELETE;
         }
         $ufField[$ufFieldBAO->id]['order'] = $ufField[$ufFieldBAO->id]['weight'];
         $ufField[$ufFieldBAO->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('id' => $ufFieldBAO->id, 'gid' => $this->_gid), ts('more'), FALSE, 'ufField.row.actions', 'UFField', $ufFieldBAO->id);
     }
     $returnURL = CRM_Utils_System::url('civicrm/admin/uf/group/field', "reset=1&action=browse&gid={$this->_gid}");
     $filter = "uf_group_id = {$this->_gid}";
     CRM_Utils_Weight::addOrder($ufField, 'CRM_Core_DAO_UFField', 'id', $returnURL, $filter);
     $this->assign('ufField', $ufField);
     // retrieve showBestResult from session
     $session = CRM_Core_Session::singleton();
     $showBestResult = $session->get('showBestResult');
     $this->assign('showBestResult', $showBestResult);
     $session->set('showBestResult', 0);
 }
Ejemplo n.º 10
0
 /**
  * Function to actually build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     $this->addElement('checkbox', 'override_verp', ts('Track Replies?'));
     $defaults['override_verp'] = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'track_civimail_replies', NULL, FALSE);
     $this->add('checkbox', 'forward_replies', ts('Forward Replies?'));
     $defaults['forward_replies'] = FALSE;
     $this->add('checkbox', 'url_tracking', ts('Track Click-throughs?'));
     $defaults['url_tracking'] = TRUE;
     $this->add('checkbox', 'open_tracking', ts('Track Opens?'));
     $defaults['open_tracking'] = TRUE;
     $this->add('checkbox', 'auto_responder', ts('Auto-respond to Replies?'));
     $defaults['auto_responder'] = FALSE;
     $this->add('select', 'visibility', ts('Mailing Visibility'), CRM_Core_SelectValues::ufVisibility(TRUE), TRUE);
     $this->add('select', 'reply_id', ts('Auto-responder'), CRM_Mailing_PseudoConstant::component('Reply'), TRUE);
     $this->add('select', 'unsubscribe_id', ts('Unsubscribe Message'), CRM_Mailing_PseudoConstant::component('Unsubscribe'), TRUE);
     $this->add('select', 'resubscribe_id', ts('Resubscribe Message'), CRM_Mailing_PseudoConstant::component('Resubscribe'), TRUE);
     $this->add('select', 'optout_id', ts('Opt-out Message'), CRM_Mailing_PseudoConstant::component('OptOut'), TRUE);
     $buttons = array(array('type' => 'back', 'name' => ts('<< Previous')), array('type' => 'next', 'name' => ts('Next >>'), 'spacing' => '&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;', 'isDefault' => TRUE), array('type' => 'submit', 'name' => ts('Save & Continue Later')), array('type' => 'cancel', 'name' => ts('Cancel')));
     $this->addButtons($buttons);
     $this->setDefaults($defaults);
 }
Ejemplo n.º 11
0
 /**
  * Function to actually build the form
  *
  * @return None
  * @access public
  */
 function buildQuickForm()
 {
     if ($this->_action == CRM_CORE_ACTION_DELETE) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete Group'), 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
     } else {
         $this->applyFilter('__ALL__', 'trim');
         $this->add('text', 'title', ts('Name:') . ' ', CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'title'));
         $this->addRule('title', ts('Group name is required.'), 'required');
         $this->addRule('title', ts('Name already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Group', $this->_id, 'title'));
         $this->add('text', 'description', ts('Description:') . ' ', CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'description'));
         $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::ufVisibility(), true);
         $this->addButtons(array(array('type' => 'next', 'name' => $this->_action == CRM_CORE_ACTION_ADD ? ts('Continue') : ts('Save'), 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
         $this->_groupTree =& CRM_Core_BAO_CustomGroup::getTree('Group', $this->_id, 0);
         CRM_Core_BAO_CustomGroup::buildQuickForm($this, $this->_groupTree, 'showBlocks1', 'hideBlocks1');
     }
 }