First commit

This commit is contained in:
Theodotos Andreou 2018-01-14 13:10:16 +00:00
commit c6e2478c40
13918 changed files with 2303184 additions and 0 deletions

View file

@ -0,0 +1,121 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
/**
* This class generates form components
* for previewing Civicrm Profile Group
*
*/
class CRM_UF_Form_AbstractPreview extends CRM_Core_Form {
/**
* The fields needed to build this form.
*
* @var array
*/
public $_fields;
/**
* Set the profile/field structure for this form
*
* @param array $fields
* List of fields per CRM_Core_BAO_UFGroup::formatUFFields or CRM_Core_BAO_UFGroup::getFields.
* @param bool $isSingleField
* @param bool $flag
*/
public function setProfile($fields, $isSingleField = FALSE, $flag = FALSE) {
if ($isSingleField) {
$this->assign('previewField', $isSingleField);
}
if ($flag) {
$this->assign('viewOnly', FALSE);
}
else {
$this->assign('viewOnly', TRUE);
}
$this->set('fieldId', NULL);
$this->assign("fields", $fields);
$this->_fields = $fields;
}
/**
* Set the default form values.
*
*
* @return array
* the default array reference
*/
public function setDefaultValues() {
$defaults = array();
foreach ($this->_fields as $name => $field) {
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($field['name'])) {
CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $defaults, NULL, CRM_Profile_Form::MODE_REGISTER);
}
}
//set default for country.
CRM_Core_BAO_UFGroup::setRegisterDefaults($this->_fields, $defaults);
return $defaults;
}
/**
* Build the form object.
*
* @return void
*/
public function buildQuickForm() {
foreach ($this->_fields as $name => $field) {
if (empty($field['is_view'])) {
CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE);
}
}
}
/**
* Use the form name to create the tpl file name.
*
* @return string
*/
/**
* @return string
*/
public function getTemplateFileName() {
return 'CRM/UF/Form/Preview.tpl';
}
}

View file

@ -0,0 +1,100 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
class CRM_UF_Form_AdvanceSetting extends CRM_UF_Form_Group {
/**
* Build the form object for Advanced Settings.
*
* @param CRM_Core_Form $form
*/
public static function buildAdvanceSetting(&$form) {
// should mapping be enabled for this group
$form->addElement('checkbox', 'is_map', ts('Enable mapping for this profile?'));
// should we allow updates on a exisitng contact
$options = array();
$options[] = $form->createElement('radio', NULL, NULL, ts('Issue warning and do not save'), 0);
$options[] = $form->createElement('radio', NULL, NULL, ts('Update the matching contact'), 1);
$options[] = $form->createElement('radio', NULL, NULL, ts('Allow duplicate contact to be created'), 2);
$form->addGroup($options, 'is_update_dupe', ts('What to do upon duplicate match'));
// we do not have any url checks to allow relative urls
$form->addElement('text', 'post_URL', ts('Redirect URL'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFGroup', 'post_URL'));
$form->addElement('text', 'cancel_URL', ts('Cancel Redirect URL'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFGroup', 'cancel_URL'));
$form->addElement('text', 'cancel_button_text', ts('Cancel Button Text'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFGroup', 'cancel_button_text'));
$form->addElement('text', 'submit_button_text', ts('Submit Button Text'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFGroup', 'submit_button_text'));
// add select for groups
$group = array('' => ts('- select -')) + $form->_group;
$form->_groupElement = &$form->addElement('select', 'group', ts('Limit listings to a specific Group?'), $group);
//add notify field
$form->addElement('text', 'notify', ts('Notify when profile form is submitted?'));
//group where new contacts are directed.
$form->addElement('select', 'add_contact_to_group', ts('Add new contacts to a Group?'), $group);
// add CAPTCHA To this group ?
$form->addElement('checkbox', 'add_captcha', ts('Include reCAPTCHA?'));
// should we display an edit link
$form->addElement('checkbox', 'is_edit_link', ts('Include profile edit links in search results?'));
// should we display a link to the website profile
$config = CRM_Core_Config::singleton();
$form->addElement('checkbox', 'is_uf_link', ts('Include %1 user account information links in search results?', array(1 => $config->userFramework)));
// want to create cms user
$session = CRM_Core_Session::singleton();
$cmsId = FALSE;
if ($form->_cId = $session->get('userID')) {
$form->_cmsId = TRUE;
}
$options = array();
$options[] = $form->createElement('radio', NULL, NULL, ts('No account create option'), 0);
$options[] = $form->createElement('radio', NULL, NULL, ts('Give option, but not required'), 1);
$options[] = $form->createElement('radio', NULL, NULL, ts('Account creation required'), 2);
$form->addGroup($options, 'is_cms_user', ts('%1 user account registration option?', array(1 => $config->userFramework)));
// options for including Proximity Search in the profile search form
$proxOptions = array();
$proxOptions[] = $form->createElement('radio', NULL, NULL, ts('None'), 0);
$proxOptions[] = $form->createElement('radio', NULL, NULL, ts('Optional'), 1);
$proxOptions[] = $form->createElement('radio', NULL, NULL, ts('Required'), 2);
$form->addGroup($proxOptions, 'is_proximity_search', ts('Proximity Search'));
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,387 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
/**
* This class is for UF Group
*/
class CRM_UF_Form_Group extends CRM_Core_Form {
/**
* The form id saved to the session for an update.
*
* @var int
*/
protected $_id;
/**
* The title for group.
*
* @var int
*/
protected $_title;
protected $_groupElement;
protected $_group;
protected $_allPanes;
/**
* Set variables up before form is built.
*
* @return void
*/
public function preProcess() {
// current form id
$this->_id = $this->get('id');
if (!$this->_id) {
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0);
}
$this->assign('gid', $this->_id);
$this->_group = CRM_Core_PseudoConstant::group();
if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::DELETE)) {
$title = CRM_Core_BAO_UFGroup::getTitle($this->_id);
$this->assign('profileTitle', $title);
}
// setting title for html page
if ($this->_action & CRM_Core_Action::UPDATE) {
CRM_Utils_System::setTitle(ts('Profile Settings') . " - $title");
}
elseif ($this->_action & (CRM_Core_Action::DISABLE | CRM_Core_Action::DELETE)) {
$ufGroup['module'] = implode(' , ', CRM_Core_BAO_UFGroup::getUFJoinRecord($this->_id, TRUE));
$status = 0;
$status = CRM_Core_BAO_UFGroup::usedByModule($this->_id);
if ($this->_action & (CRM_Core_Action::DISABLE)) {
if ($status) {
$message = 'This profile is currently used for ' . $ufGroup['module'] . '. If you disable the profile - it will be removed from these forms and/or modules. Do you want to continue?';
}
else {
$message = 'Are you sure you want to disable this Profile?';
}
}
else {
if ($status) {
$message = 'This profile is currently used for ' . $ufGroup['module'] . '. If you delete the profile - it will be removed from these forms and/or modules. This action cannot be undone. Do you want to continue?';
}
else {
$message = 'Are you sure you want to delete this Profile? This action cannot be undone.';
}
}
$this->assign('message', $message);
}
else {
CRM_Utils_System::setTitle(ts('New CiviCRM Profile'));
}
}
/**
* Build the form object.
*
* @return void
*/
public function buildQuickForm() {
if ($this->_action & (CRM_Core_Action::DISABLE | CRM_Core_Action::DELETE)) {
if ($this->_action & (CRM_Core_Action::DISABLE)) {
$display = 'Disable Profile';
}
else {
$display = 'Delete Profile';
}
$this->addButtons(array(
array(
'type' => 'next',
'name' => $display,
'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
));
return;
}
$this->applyFilter('__ALL__', 'trim');
// title
$this->add('text', 'title', ts('Profile Name'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFGroup', 'title'), TRUE);
$this->add('textarea', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFGroup', 'description'));
//add checkboxes
$uf_group_type = array();
$UFGroupType = CRM_Core_SelectValues::ufGroupTypes();
foreach ($UFGroupType as $key => $value) {
$uf_group_type[] = $this->createElement('checkbox', $key, NULL, $value);
}
$this->addGroup($uf_group_type, 'uf_group_type', ts('Used For'), '&nbsp;');
// help text
$this->add('wysiwyg', 'help_pre', ts('Pre-form Help'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFGroup', 'help_post'));
$this->add('wysiwyg', 'help_post', ts('Post-form Help'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFGroup', 'help_post'));
// weight
$this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFJoin', 'weight'), TRUE);
$this->addRule('weight', ts('is a numeric field'), 'numeric');
// is this group active ?
$this->addElement('checkbox', 'is_active', ts('Is this CiviCRM Profile active?'));
$paneNames = array('Advanced Settings' => 'buildAdvanceSetting');
foreach ($paneNames as $name => $type) {
if ($this->_id) {
$dataURL = "&reset=1&action=update&id={$this->_id}&snippet=4&formType={$type}";
}
else {
$dataURL = "&reset=1&action=add&snippet=4&formType={$type}";
}
$allPanes[$name] = array(
'url' => CRM_Utils_System::url('civicrm/admin/uf/group/setting',
$dataURL
),
'open' => 'false',
'id' => $type,
);
CRM_UF_Form_AdvanceSetting::$type($this);
}
$this->addButtons(array(
array(
'type' => 'next',
'name' => ts('Save'),
'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
));
// views are implemented as frozen form
if ($this->_action & CRM_Core_Action::VIEW) {
$this->freeze();
$this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/uf/group?reset=1&action=browse'"));
}
$this->addFormRule(array('CRM_UF_Form_Group', 'formRule'), $this);
}
/**
* Set default values for the form. Note that in edit/view mode
* the default values are retrieved from the database
*
*
* @return void
*/
public function setDefaultValues() {
$defaults = array();
$showHide = new CRM_Core_ShowHideBlocks();
if ($this->_action == CRM_Core_Action::ADD) {
$defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_UFJoin');
}
//id fetched for Dojo Pane
$pId = CRM_Utils_Request::retrieve('id', 'Positive', $this);
if (isset($pId)) {
$this->_id = $pId;
}
if ((isset($this->_id))) {
$defaults['weight'] = CRM_Core_BAO_UFGroup::getWeight($this->_id);
$params = array('id' => $this->_id);
CRM_Core_BAO_UFGroup::retrieve($params, $defaults);
$defaults['group'] = CRM_Utils_Array::value('limit_listings_group_id', $defaults);
$defaults['add_contact_to_group'] = CRM_Utils_Array::value('add_to_group_id', $defaults);
//get the uf join records for current uf group
$ufJoinRecords = CRM_Core_BAO_UFGroup::getUFJoinRecord($this->_id);
foreach ($ufJoinRecords as $key => $value) {
$checked[$value] = 1;
}
$defaults['uf_group_type'] = isset($checked) ? $checked : "";
//get the uf join records for current uf group other than default modules
$otherModules = array();
$otherModules = CRM_Core_BAO_UFGroup::getUFJoinRecord($this->_id, TRUE, TRUE);
if (!empty($otherModules)) {
$otherModuleString = NULL;
foreach ($otherModules as $key) {
$otherModuleString .= " [ x ] <label>" . $key . "</label>";
}
$this->assign('otherModuleString', $otherModuleString);
}
$showAdvanced = 0;
$advFields = array(
'group',
'post_URL',
'cancel_URL',
'add_captcha',
'is_map',
'is_uf_link',
'is_edit_link',
'is_update_dupe',
'is_cms_user',
'is_proximity_search',
);
foreach ($advFields as $key) {
if (!empty($defaults[$key])) {
$showAdvanced = 1;
$this->_allPanes['Advanced Settings']['open'] = 'true';
break;
}
}
}
else {
$defaults['is_active'] = 1;
$defaults['is_map'] = 0;
$defaults['is_update_dupe'] = 0;
$defaults['is_proximity_search'] = 0;
}
// Don't assign showHide elements to template in DELETE mode (fields to be shown and hidden don't exist)
if (!($this->_action & CRM_Core_Action::DELETE) && !($this->_action & CRM_Core_Action::DISABLE)) {
$showHide->addToTemplate();
}
$this->assign('allPanes', $this->_allPanes);
return $defaults;
}
/**
* Global form rule.
*
* @param array $fields
* The input form values.
* @param array $files
* The uploaded files if any.
* @param array $self
* Current form object.
*
* @return bool|array
* true if no errors, else array of errors
*/
public static function formRule($fields, $files, $self) {
$errors = array();
//validate profile title as well as name.
$title = $fields['title'];
$name = CRM_Utils_String::munge($title, '_', 56);
$name .= $self->_id ? '_' . $self->_id : '';
$query = 'select count(*) from civicrm_uf_group where ( name like %1 ) and id != %2';
$pCnt = CRM_Core_DAO::singleValueQuery($query, array(
1 => array($name, 'String'),
2 => array((int) $self->_id, 'Integer'),
));
if ($pCnt) {
$errors['title'] = ts('Profile \'%1\' already exists in Database.', array(1 => $title));
}
return empty($errors) ? TRUE : $errors;
}
/**
* Process the form.
*
* @return void
*/
public function postProcess() {
if ($this->_action & CRM_Core_Action::DELETE) {
$title = CRM_Core_BAO_UFGroup::getTitle($this->_id);
CRM_Core_BAO_UFGroup::del($this->_id);
CRM_Core_Session::setStatus(ts("Your CiviCRM Profile '%1' has been deleted.", array(1 => $title)), ts('Profile Deleted'), 'success');
}
elseif ($this->_action & CRM_Core_Action::DISABLE) {
$ufJoinParams = array('uf_group_id' => $this->_id);
CRM_Core_BAO_UFGroup::delUFJoin($ufJoinParams);
CRM_Core_BAO_UFGroup::setIsActive($this->_id, 0);
}
else {
// get the submitted form values.
$params = $ids = array();
$params = $this->controller->exportValues($this->_name);
if (!array_key_exists('is_active', $params)) {
$params['is_active'] = 0;
}
if ($this->_action & (CRM_Core_Action::UPDATE)) {
$ids['ufgroup'] = $this->_id;
// CRM-5284
// lets skip trying to mess around with profile weights and allow the user to do as needed.
}
elseif ($this->_action & CRM_Core_Action::ADD) {
$session = CRM_Core_Session::singleton();
$params['created_id'] = $session->get('userID');
$params['created_date'] = date('YmdHis');
}
// create uf group
$ufGroup = CRM_Core_BAO_UFGroup::add($params, $ids);
if (!empty($params['is_active'])) {
//make entry in uf join table
CRM_Core_BAO_UFGroup::createUFJoin($params, $ufGroup->id);
}
elseif ($this->_id) {
// this profile has been set to inactive, delete all corresponding UF Join's
$ufJoinParams = array('uf_group_id' => $this->_id);
CRM_Core_BAO_UFGroup::delUFJoin($ufJoinParams);
}
if ($this->_action & CRM_Core_Action::UPDATE) {
$url = CRM_Utils_System::url('civicrm/admin/uf/group', 'reset=1&action=browse');
CRM_Core_Session::setStatus(ts("Your CiviCRM Profile '%1' has been saved.", array(1 => $ufGroup->title)), ts('Profile Saved'), 'success');
}
else {
// Jump directly to adding a field if popups are disabled
$action = CRM_Core_Resources::singleton()->ajaxPopupsEnabled ? '' : '/add';
$url = CRM_Utils_System::url("civicrm/admin/uf/group/field$action", 'reset=1&new=1&gid=' . $ufGroup->id . '&action=' . ($action ? 'add' : 'browse'));
CRM_Core_Session::setStatus(ts('Your CiviCRM Profile \'%1\' has been added. You can add fields to this profile now.',
array(1 => $ufGroup->title)
), ts('Profile Added'), 'success');
}
$session = CRM_Core_Session::singleton();
$session->replaceUserContext($url);
}
// update cms integration with registration / my account
CRM_Utils_System::updateCategories();
}
}

View file

@ -0,0 +1,75 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This class generates form components
* for previewing Civicrm Profile Group
*/
class CRM_UF_Form_Inline_Preview extends CRM_UF_Form_AbstractPreview {
/**
* Pre processing work done here.
*
* gets session variables for group or field id
*/
public function preProcess() {
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
// CRM_Core_Controller validates qfKey for POST requests, but not necessarily
// for GET requests. Allowing GET would therefore be CSRF vulnerability.
CRM_Core_Error::fatal(ts('Preview only supports HTTP POST'));
}
// Inline forms don't get menu-level permission checks
$checkPermission = array(
array(
'administer CiviCRM',
'manage event profiles',
),
);
if (!CRM_Core_Permission::check($checkPermission)) {
CRM_Core_Error::fatal(ts('Permission Denied'));
}
$content = json_decode($_REQUEST['ufData'], TRUE);
foreach (array('ufGroup', 'ufFieldCollection') as $key) {
if (!is_array($content[$key])) {
CRM_Core_Error::fatal("Missing JSON parameter, $key");
}
}
//echo '<pre>'.htmlentities(var_export($content, TRUE)) .'</pre>';
//CRM_Utils_System::civiExit();
$fields = CRM_Core_BAO_UFGroup::formatUFFields($content['ufGroup'], $content['ufFieldCollection']);
//$fields = CRM_Core_BAO_UFGroup::getFields(1);
$this->setProfile($fields);
//echo '<pre>'.htmlentities(var_export($fields, TRUE)) .'</pre>';CRM_Utils_System::civiExit();
}
}

View file

@ -0,0 +1,62 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
/**
* This class generates form components
* for previewing Civicrm Profile Group
*
*/
class CRM_UF_Form_Inline_PreviewById extends CRM_UF_Form_AbstractPreview {
/**
* Pre processing work done here.
*
* gets session variables for group or field id
*
* @param
*
* @return void
*/
public function preProcess() {
// Inline forms don't get menu-level permission checks
if (!CRM_Core_Permission::check('access CiviCRM')) {
CRM_Core_Error::fatal(ts('Permission Denied'));
}
$gid = CRM_Utils_Request::retrieve('id', 'Positive');
$fields = CRM_Core_BAO_UFGroup::getFields($gid, FALSE, NULL, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, 'field_name', NULL, TRUE);
$this->setProfile($fields);
}
}

View file

@ -0,0 +1,143 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
/**
* This class generates form components
* for previewing Civicrm Profile Group
*
*/
class CRM_UF_Form_Preview extends CRM_UF_Form_AbstractPreview {
/**
* Pre processing work done here.
*
* gets session variables for group or field id
*
* @param
*
* @return void
*/
public function preProcess() {
$flag = FALSE;
$gid = $this->get('id');
$this->set('gid', $gid);
$field = CRM_Utils_Request::retrieve('field', 'Boolean', $this, TRUE, 0);
if ($field) {
$fields = CRM_Core_BAO_UFGroup::getFields($gid, FALSE, NULL, NULL, NULL, TRUE);
$fieldDAO = new CRM_Core_DAO_UFField();
$fieldDAO->id = $this->get('fieldId');
$fieldDAO->find(TRUE);
if ($fieldDAO->is_active == 0) {
CRM_Core_Error::statusBounce(ts('This field is inactive so it will not be displayed on profile form.'));
}
elseif ($fieldDAO->is_view == 1) {
CRM_Core_Error::statusBounce(ts('This field is view only so it will not be displayed on profile form.'));
}
$name = $fieldDAO->field_name;
if ($fieldDAO->field_name == 'phone_and_ext') {
$name = 'phone';
}
// preview for field
$specialFields = array(
'address_name',
'street_address',
'supplemental_address_1',
'supplemental_address_2',
'supplemental_address_3',
'city',
'postal_code',
'postal_code_suffix',
'geo_code_1',
'geo_code_2',
'state_province',
'country',
'county',
'phone',
'email',
'im',
);
if ($fieldDAO->location_type_id) {
$name .= '-' . $fieldDAO->location_type_id;
}
elseif (in_array($name, $specialFields)) {
$name .= '-Primary';
}
if (isset($fieldDAO->phone_type_id)) {
$name .= '-' . $fieldDAO->phone_type_id;
}
$fieldArray[$name] = $fields[$name];
if ($fieldDAO->field_name == 'phone_and_ext') {
$phoneExtField = str_replace('phone', 'phone_ext', $name);;
$fieldArray[$phoneExtField] = $fields[$phoneExtField];
}
$fields = $fieldArray;
if (!is_array($fields[$name])) {
$flag = TRUE;
}
$this->setProfile($fields, TRUE, $flag);
}
else {
$fields = CRM_Core_BAO_UFGroup::getFields($gid);
$this->setProfile($fields);
}
}
/**
* Build the form object.
*
* @return void
*/
public function buildQuickForm() {
parent::buildQuickForm();
$this->addButtons(array(
array(
'type' => 'cancel',
'name' => ts('Done with Preview'),
'isDefault' => TRUE,
),
));
}
}

View file

@ -0,0 +1,53 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
/**
* This class contains all the function that are called using AJAX
*/
class CRM_UF_Page_AJAX {
/**
* Function the check whether the field belongs.
* to multi-record custom set
*/
public function checkIsMultiRecord() {
$customId = $_GET['customId'];
$isMultiple = CRM_Core_BAO_CustomField::isMultiRecordField($customId);
$isMultiple = array('is_multi' => $isMultiple);
CRM_Utils_JSON::output($isMultiple);
}
}

View file

@ -0,0 +1,297 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* Create a page for displaying CiviCRM Profile Fields.
*
* Heart of this class is the run method which checks
* for action type and then displays the appropriate
* page.
*
*/
class CRM_UF_Page_Field extends CRM_Core_Page {
public $useLivePageJS = TRUE;
/**
* The group id of the field.
*
* @var int
*/
protected $_gid;
/**
* The action links that we need to display for the browse screen.
*
* @var array
*/
private static $_actionLinks;
/**
* Get the action links for this page.
*
* @return array
*/
public static function &actionLinks() {
if (!isset(self::$_actionLinks)) {
self::$_actionLinks = array(
CRM_Core_Action::UPDATE => array(
'name' => ts('Edit'),
'url' => 'civicrm/admin/uf/group/field/update',
'qs' => 'reset=1&action=update&id=%%id%%&gid=%%gid%%',
'title' => ts('Edit CiviCRM Profile Field'),
),
CRM_Core_Action::PREVIEW => array(
'name' => ts('Preview'),
'url' => 'civicrm/admin/uf/group/field',
'qs' => 'action=preview&id=%%id%%&field=1',
'title' => ts('Preview CiviCRM Profile Field'),
),
CRM_Core_Action::DISABLE => array(
'name' => ts('Disable'),
'ref' => 'crm-enable-disable',
'title' => ts('Disable CiviCRM Profile Field'),
),
CRM_Core_Action::ENABLE => array(
'name' => ts('Enable'),
'ref' => 'crm-enable-disable',
'title' => ts('Enable CiviCRM Profile Field'),
),
CRM_Core_Action::DELETE => array(
'name' => ts('Delete'),
'url' => 'civicrm/admin/uf/group/field',
'qs' => 'action=delete&id=%%id%%',
'title' => ts('Enable CiviCRM Profile Field'),
),
);
}
return self::$_actionLinks;
}
/**
* 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);
$isMixedProfile = CRM_Core_BAO_UFField::checkProfileType($this->_gid);
if ($isMixedProfile) {
$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(self::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);
}
/**
* Edit CiviCRM Profile data.
*
* editing would involved modifying existing fields + adding data to new fields.
*
* @param string $action
* The action to be invoked.
*
* @return void
*/
public function edit($action) {
// create a simple controller for editing CiviCRM Profile data
$controller = new CRM_Core_Controller_Simple('CRM_UF_Form_Field', ts('CiviCRM Profile Field'), $action);
// set the userContext stack
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin/uf/group/field',
'reset=1&action=browse&gid=' . $this->_gid
));
$controller->set('gid', $this->_gid);
$controller->setEmbedded(TRUE);
$controller->process();
$controller->run();
}
/**
* Run the page.
*
* This method is called after the page is created. It checks for the
* type of action and executes that action.
*
* @return void
*/
public function run() {
// get the group id
$this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive',
$this, FALSE, 0
);
if ($this->_gid) {
$groupTitle = CRM_Core_BAO_UFGroup::getTitle($this->_gid);
$this->assign('gid', $this->_gid);
$this->assign('groupTitle', $groupTitle);
CRM_Utils_System::setTitle(ts('%1 - CiviCRM Profile Fields', array(1 => $groupTitle)));
}
// get the requested action
$action = CRM_Utils_Request::retrieve('action', 'String',
// default to 'browse'
$this, FALSE, 'browse'
);
// assign vars to templates
$this->assign('action', $action);
$id = CRM_Utils_Request::retrieve('id', 'Positive',
$this, FALSE, 0
);
// what action to take ?
if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::VIEW | CRM_Core_Action::DELETE)) {
// no browse for edit/update/view/delete
$this->edit($action);
}
elseif ($action & CRM_Core_Action::PREVIEW) {
$this->preview($id, $this->_gid);
}
else {
$this->browse();
}
// Call the parents run method
return parent::run();
}
/**
* Preview custom field.
*
* @param int $fieldId
* Custom field id.
* @param int $groupId
*
* @return void
*/
public function preview($fieldId, $groupId) {
$controller = new CRM_Core_Controller_Simple('CRM_UF_Form_Preview', ts('Preview Custom Data'), CRM_Core_Action::PREVIEW);
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin/uf/group/field',
'reset=1&action=browse&gid=' . $this->_gid
));
$controller->set('fieldId', $fieldId);
$controller->set('id', $groupId);
$controller->setEmbedded(TRUE);
$controller->process();
$controller->run();
}
}

View file

@ -0,0 +1,530 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
/**
* Create a page for displaying UF Groups.
*
* Heart of this class is the run method which checks
* for action type and then displays the appropriate
* page.
*
*/
class CRM_UF_Page_Group extends CRM_Core_Page {
/**
* The action links that we need to display for the browse screen.
*
* @var array
*/
private static $_actionLinks = NULL;
/**
* Get the action links for this page.
*
* @param
*
* @return array
*/
public static function &actionLinks() {
// check if variable _actionsLinks is populated
if (!self::$_actionLinks) {
// helper variable for nicer formatting
$copyExtra = ts('Are you sure you want to make a copy of this Profile?');
self::$_actionLinks = array(
CRM_Core_Action::BROWSE => array(
'name' => ts('Fields'),
'url' => 'civicrm/admin/uf/group/field',
'qs' => 'reset=1&action=browse&gid=%%id%%',
'title' => ts('View and Edit Fields'),
),
CRM_Core_Action::UPDATE => array(
'name' => ts('Settings'),
'url' => 'civicrm/admin/uf/group/update',
'qs' => 'action=update&id=%%id%%&context=group',
'title' => ts('Edit CiviCRM Profile Group'),
),
CRM_Core_Action::PREVIEW => array(
'name' => ts('Preview'),
'url' => 'civicrm/admin/uf/group',
'qs' => 'action=preview&id=%%id%%&field=0&context=group',
'title' => ts('Edit CiviCRM Profile Group'),
),
CRM_Core_Action::ADD => array(
'name' => ts('Use - Create Mode'),
'url' => 'civicrm/profile/create',
'qs' => 'gid=%%id%%&reset=1',
'title' => ts('Use - Create Mode'),
'fe' => TRUE,
),
CRM_Core_Action::ADVANCED => array(
'name' => ts('Use - Edit Mode'),
'url' => 'civicrm/profile/edit',
'qs' => 'gid=%%id%%&reset=1',
'title' => ts('Use - Edit Mode'),
'fe' => TRUE,
),
CRM_Core_Action::BASIC => array(
'name' => ts('Use - Listings Mode'),
'url' => 'civicrm/profile',
'qs' => 'gid=%%id%%&reset=1',
'title' => ts('Use - Listings Mode'),
'fe' => TRUE,
),
CRM_Core_Action::DISABLE => array(
'name' => ts('Disable'),
'ref' => 'crm-enable-disable',
'title' => ts('Disable CiviCRM Profile Group'),
),
CRM_Core_Action::ENABLE => array(
'name' => ts('Enable'),
'ref' => 'crm-enable-disable',
'title' => ts('Enable CiviCRM Profile Group'),
),
CRM_Core_Action::DELETE => array(
'name' => ts('Delete'),
'url' => 'civicrm/admin/uf/group',
'qs' => 'action=delete&id=%%id%%',
'title' => ts('Delete CiviCRM Profile Group'),
),
CRM_Core_Action::COPY => array(
'name' => ts('Copy'),
'url' => 'civicrm/admin/uf/group',
'qs' => 'action=copy&gid=%%id%%',
'title' => ts('Make a Copy of CiviCRM Profile Group'),
'extra' => 'onclick = "return confirm(\'' . $copyExtra . '\');"',
),
);
$allowRemoteSubmit = Civi::settings()->get('remote_profile_submissions');
if ($allowRemoteSubmit) {
self::$_actionLinks[CRM_Core_Action::PROFILE] = array(
'name' => ts('HTML Form Snippet'),
'url' => 'civicrm/admin/uf/group',
'qs' => 'action=profile&gid=%%id%%',
'title' => ts('HTML Form Snippet for this Profile'),
);
}
}
return self::$_actionLinks;
}
/**
* Run the page.
*
* This method is called after the page is created. It checks for the
* type of action and executes that action.
* Finally it calls the parent's run method.
*
* @param
*
* @return void
*/
public function run() {
// get the requested action
$action = CRM_Utils_Request::retrieve('action', 'String',
$this, FALSE,
// default to 'browse'
'browse'
);
// assign vars to templates
$this->assign('action', $action);
$this->assign('selectedChild', CRM_Utils_Request::retrieve('selectedChild', 'String', $this));
$id = CRM_Utils_Request::retrieve('id', 'Positive',
$this, FALSE, 0
);
//set the context and then start w/ action.
$this->setContext($id, $action);
// what action to take ?
if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE | CRM_Core_Action::DISABLE)) {
$this->edit($id, $action);
}
else {
// if action is enable or disable do the needful.
if ($action & CRM_Core_Action::ENABLE) {
CRM_Core_BAO_UFGroup::setIsActive($id, 1);
// update cms integration with registration / my account
CRM_Utils_System::updateCategories();
}
elseif ($action & CRM_Core_Action::PROFILE) {
$this->profile();
CRM_Utils_System::setTitle(ts('%1 - HTML Form Snippet', array(1 => $this->_title)));
}
elseif ($action & CRM_Core_Action::PREVIEW) {
$this->preview($id, $action);
}
elseif ($action & CRM_Core_Action::COPY) {
$this->copy();
}
// finally browse the uf groups
$this->browse();
}
// parent run
return parent::run();
}
/**
* make a copy of a profile, including
* all the fields in the profile
*
* @return void
*/
public function copy() {
$gid = CRM_Utils_Request::retrieve('gid', 'Positive',
$this, TRUE, 0, 'GET'
);
CRM_Core_BAO_UFGroup::copy($gid);
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/uf/group', 'reset=1'));
}
/**
* for profile mode (standalone html form ) for uf group
*
* @return void
*/
public function profile() {
$config = CRM_Core_Config::singleton();
// reassign resource base to be the full url, CRM-4660
$config->resourceBase = $config->userFrameworkResourceURL;
$config->useFrameworkRelativeBase = $config->userFrameworkBaseURL;
$gid = CRM_Utils_Request::retrieve('gid', 'Positive',
$this, FALSE, 0, 'GET'
);
$controller = new CRM_Core_Controller_Simple('CRM_Profile_Form_Edit', ts('Create'), CRM_Core_Action::ADD,
FALSE, FALSE, TRUE
);
$controller->reset();
$controller->process();
$controller->set('gid', $gid);
$controller->setEmbedded(TRUE);
$controller->run();
$template = CRM_Core_Smarty::singleton();
$template->assign('gid', $gid);
$template->assign('tplFile', 'CRM/Profile/Form/Edit.tpl');
$profile = trim($template->fetch('CRM/Form/default.tpl'));
// not sure how to circumvent our own navigation system to generate the right form url
$urlReplaceWith = 'civicrm/profile/create&amp;gid=' . $gid . '&amp;reset=1';
if ($config->userSystem->is_drupal && $config->cleanURL) {
$urlReplaceWith = 'civicrm/profile/create?gid=' . $gid . '&amp;reset=1';
}
$profile = str_replace('civicrm/admin/uf/group', $urlReplaceWith, $profile);
// FIXME: (CRM-3587) hack to make standalone profile work
// in wordpress and joomla without administrator login
if ($config->userFramework == 'Joomla') {
$profile = str_replace('/administrator/', '/index.php', $profile);
}
elseif ($config->userFramework == 'WordPress') {
//@todo remove this part when it is OK to deprecate CIVICRM_UF_WP_BASEPAGE-CRM-15933
if (defined('CIVICRM_UF_WP_BASEPAGE')) {
$wpbase = CIVICRM_UF_WP_BASEPAGE;
}
elseif (!empty($config->wpBasePage)) {
$wpbase = $config->wpBasePage;
}
else {
$wpbase = 'index.php';
}
$profile = str_replace('/wp-admin/admin.php', '/' . $wpbase . '/', $profile);
}
// add header files
CRM_Core_Resources::singleton()->addCoreResources('html-header');
$profile = CRM_Core_Region::instance('html-header')->render('', FALSE) . $profile;
$this->assign('profile', htmlentities($profile, ENT_NOQUOTES, 'UTF-8'));
//get the title of uf group
if ($gid) {
$title = CRM_Core_BAO_UFGroup::getTitle($gid);
$this->_title = $title;
}
else {
$title = 'Profile Form';
}
$this->assign('title', $title);
$this->assign('action', CRM_Core_Action::PROFILE);
$this->assign('isForm', 0);
}
/**
* Edit uf group.
*
* @param int $id
* Uf group id.
* @param string $action
* The action to be invoked.
*
* @return void
*/
public function edit($id, $action) {
// create a simple controller for editing uf data
$controller = new CRM_Core_Controller_Simple('CRM_UF_Form_Group', ts('CiviCRM Profile Group'), $action);
$this->setContext($id, $action);
$controller->set('id', $id);
$controller->setEmbedded(TRUE);
$controller->process();
$controller->run();
}
/**
* Browse all uf data groups.
*
* @param
*
* @return void
*/
public function browse($action = NULL) {
$ufGroup = array();
$allUFGroups = CRM_Core_BAO_UFGroup::getModuleUFGroup();
if (empty($allUFGroups)) {
return;
}
$ufGroups = CRM_Core_PseudoConstant::get('CRM_Core_DAO_UFField', 'uf_group_id');
CRM_Utils_Hook::aclGroup(CRM_Core_Permission::ADMIN, NULL, 'civicrm_uf_group', $ufGroups, $allUFGroups);
foreach ($allUFGroups as $id => $value) {
$ufGroup[$id] = array();
$ufGroup[$id]['id'] = $id;
$ufGroup[$id]['title'] = $value['title'];
$ufGroup[$id]['created_id'] = $value['created_id'];
$ufGroup[$id]['created_by'] = CRM_Contact_BAO_Contact::displayName($value['created_id']);
$ufGroup[$id]['description'] = $value['description'];
$ufGroup[$id]['is_active'] = $value['is_active'];
$ufGroup[$id]['group_type'] = $value['group_type'];
$ufGroup[$id]['is_reserved'] = $value['is_reserved'];
// form all action links
$action = array_sum(array_keys(self::actionLinks()));
// update enable/disable links depending on uf_group properties.
if ($value['is_active']) {
$action -= CRM_Core_Action::ENABLE;
}
else {
$action -= CRM_Core_Action::DISABLE;
}
// drop certain actions if the profile is reserved
if ($value['is_reserved']) {
$action -= CRM_Core_Action::UPDATE;
$action -= CRM_Core_Action::DISABLE;
$action -= CRM_Core_Action::DELETE;
}
$groupTypes = self::extractGroupTypes($value['group_type']);
// drop Create, Edit and View mode links if profile group_type is one of the following:
// Contribution, Membership, Activity, Participant, Case, Grant
$isMixedProfile = CRM_Core_BAO_UFField::checkProfileType($id);
if ($isMixedProfile) {
$action -= CRM_Core_Action::ADD;
$action -= CRM_Core_Action::ADVANCED;
$action -= CRM_Core_Action::BASIC;
//CRM-21004
if (array_key_exists(CRM_Core_Action::PROFILE, self::$_actionLinks)) {
$action -= CRM_Core_Action::PROFILE;
}
}
$ufGroup[$id]['group_type'] = self::formatGroupTypes($groupTypes);
$ufGroup[$id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action,
array('id' => $id),
ts('more'),
FALSE,
'ufGroup.row.actions',
'UFGroup',
$id
);
//get the "Used For" from uf_join
$ufGroup[$id]['module'] = implode(', ', CRM_Core_BAO_UFGroup::getUFJoinRecord($id, TRUE));
}
$this->assign('rows', $ufGroup);
}
/**
* for preview mode for ufoup.
*
* @param int $id
* Uf group id.
*
* @param int $action
*/
public function preview($id, $action) {
$controller = new CRM_Core_Controller_Simple('CRM_UF_Form_Preview', ts('CiviCRM Profile Group Preview'), NULL);
$controller->set('id', $id);
$controller->setEmbedded(TRUE);
$controller->process();
$controller->run();
}
/**
* @param int $id
* @param $action
*/
public function setContext($id, $action) {
$context = CRM_Utils_Request::retrieve('context', 'String', $this);
//we need to differentiate context for update and preview profile.
if (!$context && !($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::PREVIEW))) {
$context = 'group';
}
if ($context == 'field') {
$url = CRM_Utils_System::url('civicrm/admin/uf/group/field', "reset=1&action=browse&gid={$id}");
}
else {
$url = CRM_Utils_System::url('civicrm/admin/uf/group', 'reset=1&action=browse');
}
$session = CRM_Core_Session::singleton();
$session->pushUserContext($url);
}
/**
* @param $groupType
*
* @return array
*/
public static function extractGroupTypes($groupType) {
$returnGroupTypes = array();
if (!$groupType) {
return $returnGroupTypes;
}
$groupTypeParts = explode(CRM_Core_DAO::VALUE_SEPARATOR, $groupType);
foreach (explode(',', $groupTypeParts[0]) as $type) {
$returnGroupTypes[$type] = $type;
}
if (!empty($groupTypeParts[1])) {
foreach (explode(',', $groupTypeParts[1]) as $typeValue) {
$groupTypeValues = $valueLabels = array();
$valueParts = explode(':', $typeValue);
$typeName = NULL;
switch ($valueParts[0]) {
case 'ContributionType':
$typeName = 'Contribution';
$valueLabels = CRM_Contribute_PseudoConstant::financialType();
break;
case 'ParticipantRole':
$typeName = 'Participant';
$valueLabels = CRM_Event_PseudoConstant::participantRole();
break;
case 'ParticipantEventName':
$typeName = 'Participant';
$valueLabels = CRM_Event_PseudoConstant::event();
break;
case 'ParticipantEventType':
$typeName = 'Participant';
$valueLabels = CRM_Event_PseudoConstant::eventType();
break;
case 'MembershipType':
$typeName = 'Membership';
$valueLabels = CRM_Member_PseudoConstant::membershipType();
break;
case 'ActivityType':
$typeName = 'Activity';
$valueLabels = CRM_Core_PseudoConstant::ActivityType(TRUE, TRUE, FALSE, 'label', TRUE);
break;
case 'CaseType':
$typeName = 'Case';
$valueLabels = CRM_Case_PseudoConstant::caseType();
break;
}
foreach ($valueParts as $val) {
if (CRM_Utils_Rule::integer($val)) {
$groupTypeValues[$val] = CRM_Utils_Array::value($val, $valueLabels);
}
}
if (!is_array($returnGroupTypes[$typeName])) {
$returnGroupTypes[$typeName] = array();
}
$returnGroupTypes[$typeName][$valueParts[0]] = $groupTypeValues;
}
}
return $returnGroupTypes;
}
/**
* Format 'group_type' field for display
*
* @param array $groupTypes
* output from self::extractGroupTypes
* @return string
*/
public static function formatGroupTypes($groupTypes) {
$groupTypesString = '';
if (!empty($groupTypes)) {
$groupTypesStrings = array();
foreach ($groupTypes as $groupType => $typeValues) {
if (is_array($typeValues)) {
if ($groupType == 'Participant') {
foreach ($typeValues as $subType => $subTypeValues) {
$groupTypesStrings[] = $subType . '::' . implode(': ', $subTypeValues);
}
}
else {
$groupTypesStrings[] = $groupType . '::' . implode(': ', current($typeValues));
}
}
else {
$groupTypesStrings[] = $groupType;
}
}
$groupTypesString = implode(', ', $groupTypesStrings);
}
return $groupTypesString;
}
}

View file

@ -0,0 +1,318 @@
<?php
require_once 'CRM/Core/Page.php';
/**
* This class is not a real page -- it contains helpers for rendering the profile-selector and profile-editor
* widgets
*/
class CRM_UF_Page_ProfileEditor extends CRM_Core_Page {
/**
* Run page.
*
* @throws \Exception
*/
public function run() {
CRM_Core_Error::fatal('This is not a real page!');
}
/**
* Register profile scripts.
*/
public static function registerProfileScripts() {
static $loaded = FALSE;
if ($loaded || CRM_Core_Resources::isAjaxMode()) {
return;
}
$loaded = TRUE;
CRM_Core_Resources::singleton()
->addSettingsFactory(function () {
$ufGroups = civicrm_api3('UFGroup', 'get', array(
'sequential' => 1,
'is_active' => 1,
'options' => array('limit' => 0),
));
//CRM-16915 - insert 'module' param for the profile used by CiviEvent.
if (CRM_Core_Permission::check('manage event profiles') && !CRM_Core_Permission::check('administer CiviCRM')) {
foreach ($ufGroups['values'] as $key => $value) {
$ufJoin = CRM_Core_BAO_UFGroup::getUFJoinRecord($value['id']);
if (in_array('CiviEvent', $ufJoin) || in_array('CiviEvent_Additional', $ufJoin)) {
$ufGroups['values'][$key]['module'] = 'CiviEvent';
}
}
}
return array(
'PseudoConstant' => array(
'locationType' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'),
'websiteType' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id'),
'phoneType' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'),
),
'initialProfileList' => $ufGroups,
'contactSubTypes' => CRM_Contact_BAO_ContactType::subTypes(),
'profilePreviewKey' => CRM_Core_Key::get('CRM_UF_Form_Inline_Preview', TRUE),
);
})
->addScriptFile('civicrm', 'packages/backbone/json2.js', 100, 'html-header', FALSE)
->addScriptFile('civicrm', 'packages/backbone/backbone.js', 120, 'html-header')
->addScriptFile('civicrm', 'packages/backbone/backbone.marionette.js', 125, 'html-header', FALSE)
->addScriptFile('civicrm', 'packages/backbone/backbone.collectionsubset.js', 125, 'html-header', FALSE)
->addScriptFile('civicrm', 'packages/backbone-forms/distribution/backbone-forms.js', 130, 'html-header', FALSE)
->addScriptFile('civicrm', 'packages/backbone-forms/distribution/adapters/backbone.bootstrap-modal.min.js', 140, 'html-header', FALSE)
->addScriptFile('civicrm', 'packages/backbone-forms/distribution/editors/list.min.js', 140, 'html-header', FALSE)
->addStyleFile('civicrm', 'packages/backbone-forms/distribution/templates/default.css', 140, 'html-header')
->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)
->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header')
->addStyleFile('civicrm', 'css/crm.designer.css', 140, 'html-header')
->addScriptFile('civicrm', 'js/crm.backbone.js', 150)
->addScriptFile('civicrm', 'js/model/crm.schema-mapped.js', 200)
->addScriptFile('civicrm', 'js/model/crm.uf.js', 200)
->addScriptFile('civicrm', 'js/model/crm.designer.js', 200)
->addScriptFile('civicrm', 'js/model/crm.profile-selector.js', 200)
->addScriptFile('civicrm', 'js/view/crm.designer.js', 200)
->addScriptFile('civicrm', 'js/view/crm.profile-selector.js', 200)
->addScriptFile('civicrm', 'js/jquery/jquery.crmProfileSelector.js', 250)
->addScriptFile('civicrm', 'js/crm.designerapp.js', 250);
CRM_Core_Region::instance('page-header')->add(array(
'template' => 'CRM/UF/Page/ProfileTemplates.tpl',
));
}
/**
* Register entity schemas for use in the editor's palette.
*
* @param array $entityTypes
* Strings, e.g. "IndividualModel", "ActivityModel".
*/
public static function registerSchemas($entityTypes) {
// TODO in cases where registerSchemas is called multiple times for same entity, be more efficient
CRM_Core_Resources::singleton()->addSettingsFactory(function () use ($entityTypes) {
return array(
'civiSchema' => CRM_UF_Page_ProfileEditor::getSchema($entityTypes),
);
});
}
/**
* AJAX callback.
*/
public static function getSchemaJSON() {
$entityTypes = explode(',', $_REQUEST['entityTypes']);
CRM_Utils_JSON::output(self::getSchema($entityTypes));
}
/**
* Get a list of Backbone-Form models
*
* @param array $entityTypes
* Model names ("IndividualModel").
*
* @throws CRM_Core_Exception
* @return array; keys are model names ("IndividualModel") and values describe 'sections' and 'schema'
* @see js/model/crm.core.js
* @see js/model/crm.mappedcore.js
*/
public static function getSchema($entityTypes) {
// FIXME: Depending on context (eg civicrm/profile/create vs search-columns), it may be appropriate to
// pick importable or exportable fields
$entityTypes = array_unique($entityTypes);
$availableFields = NULL;
$civiSchema = array();
foreach ($entityTypes as $entityType) {
if (!$availableFields) {
$availableFields = CRM_Core_BAO_UFField::getAvailableFieldsFlat();
}
switch ($entityType) {
case 'IndividualModel':
$civiSchema[$entityType] = self::convertCiviModelToBackboneModel(
'Individual',
ts('Individual'),
$availableFields
);
break;
case 'OrganizationModel':
$civiSchema[$entityType] = self::convertCiviModelToBackboneModel(
'Organization',
ts('Organization'),
$availableFields
);
break;
case 'HouseholdModel':
$civiSchema[$entityType] = self::convertCiviModelToBackboneModel(
'Household',
ts('Household'),
$availableFields
);
break;
case 'ActivityModel':
$civiSchema[$entityType] = self::convertCiviModelToBackboneModel(
'Activity',
ts('Activity'),
$availableFields
);
break;
case 'ContributionModel':
$civiSchema[$entityType] = self::convertCiviModelToBackboneModel(
'Contribution',
ts('Contribution'),
$availableFields
);
break;
case 'MembershipModel':
$civiSchema[$entityType] = self::convertCiviModelToBackboneModel(
'Membership',
ts('Membership'),
$availableFields
);
break;
case 'ParticipantModel':
$civiSchema[$entityType] = self::convertCiviModelToBackboneModel(
'Participant',
ts('Participant'),
$availableFields
);
break;
case 'CaseModel':
$civiSchema[$entityType] = self::convertCiviModelToBackboneModel(
'Case',
ts('Case'),
$availableFields
);
break;
default:
throw new CRM_Core_Exception("Unrecognized entity type: $entityType");
}
}
// Adding the oddball "formatting" field here because there's no other place to put it
foreach (array('Individual', 'Organization', 'Household') as $type) {
if (isset($civiSchema[$type . 'Model'])) {
$civiSchema[$type . 'Model']['schema'] += array(
'formatting' => array(
'type' => 'Markup',
'title' => ts('Free HTML'),
'civiFieldType' => 'Formatting',
'section' => 'formatting',
),
);
$civiSchema[$type . 'Model']['sections'] += array(
'formatting' => array(
'title' => ts('Formatting'),
'is_addable' => FALSE,
),
);
}
}
return $civiSchema;
}
/**
* FIXME: Move to somewhere more useful
* FIXME: Do real mapping of "types"
*
* @param string $extends
* Entity type; note: "Individual" means "Individual|Contact"; "Household" means "Household|Contact".
* @param string $title
* A string to use in section headers.
* @param array $availableFields
* List of fields that are allowed in profiles, e.g. $availableFields['my_field']['field_type'].
* @return array
* with keys 'sections' and 'schema'
* @see js/model/crm.core.js
* @see js/model/crm.mappedcore.js
*/
public static function convertCiviModelToBackboneModel($extends, $title, $availableFields) {
$locationFields = CRM_Core_BAO_UFGroup::getLocationFields();
// schema in format array($fieldName => $fieldSchema)
// sections in format array($sectionName => $section)
$result = array(
'schema' => array(),
'sections' => array(),
);
// build field list
foreach ($availableFields as $fieldName => $field) {
switch ($extends) {
case 'Individual':
case 'Organization':
case 'Household':
if ($field['field_type'] != $extends && $field['field_type'] != 'Contact'
//CRM-15595 check if subtype
&& !in_array($field['field_type'], CRM_Contact_BAO_ContactType::subTypes($extends))
) {
continue 2;
}
break;
default:
if ($field['field_type'] != $extends) {
continue 2;
}
}
// FIXME: type set to "Text"
$result['schema'][$fieldName] = array(
'type' => 'Text',
'title' => $field['title'],
'civiFieldType' => $field['field_type'],
);
if (in_array($fieldName, $locationFields)) {
$result['schema'][$fieldName]['civiIsLocation'] = TRUE;
}
if ($fieldName == 'url') {
$result['schema'][$fieldName]['civiIsWebsite'] = TRUE;
}
if (in_array($fieldName, array('phone', 'phone_and_ext'))) {
// FIXME what about phone_ext?
$result['schema'][$fieldName]['civiIsPhone'] = TRUE;
}
}
// build section list
$result['sections']['default'] = array(
'title' => $title,
'is_addable' => FALSE,
);
$customGroup = CRM_Core_BAO_CustomGroup::getAllCustomGroupsByBaseEntity($extends);
$customGroup->orderBy('weight');
$customGroup->is_active = 1;
$customGroup->find();
while ($customGroup->fetch()) {
$sectionName = 'cg_' . $customGroup->id;
$section = array(
'title' => ts('%1: %2', array(1 => $title, 2 => $customGroup->title)),
'is_addable' => $customGroup->is_reserved ? FALSE : TRUE,
'custom_group_id' => $customGroup->id,
'extends_entity_column_id' => $customGroup->extends_entity_column_id,
'extends_entity_column_value' => CRM_Utils_Array::explodePadded($customGroup->extends_entity_column_value),
'is_reserved' => $customGroup->is_reserved ? TRUE : FALSE,
);
$result['sections'][$sectionName] = $section;
}
// put fields in their sections
$fields = CRM_Core_BAO_CustomField::getFields($extends);
foreach ($fields as $fieldId => $field) {
$sectionName = 'cg_' . $field['custom_group_id'];
$fieldName = 'custom_' . $fieldId;
if (isset($result['schema'][$fieldName])) {
$result['schema'][$fieldName]['section'] = $sectionName;
$result['schema'][$fieldName]['civiIsMultiple'] = (bool) CRM_Core_BAO_CustomField::isMultiRecordField($fieldId);
}
}
return $result;
}
}