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,89 @@
<?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 Synchronizing CMS Users
*/
class CRM_Admin_Form_CMSUser extends CRM_Core_Form {
/**
* Build the form object.
*/
public function buildQuickForm() {
$this->addButtons(array(
array(
'type' => 'next',
'name' => ts('OK'),
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
)
);
}
/**
* Process the form submission.
*/
public function postProcess() {
$result = CRM_Utils_System::synchronizeUsers();
$status = ts('Checked one user record.',
array(
'count' => $result['contactCount'],
'plural' => 'Checked %count user records.',
)
);
if ($result['contactMatching']) {
$status .= '<br />' . ts('Found one matching contact record.',
array(
'count' => $result['contactMatching'],
'plural' => 'Found %count matching contact records.',
)
);
}
$status .= '<br />' . ts('Created one new contact record.',
array(
'count' => $result['contactCreated'],
'plural' => 'Created %count new contact records.',
)
);
CRM_Core_Session::setStatus($status, ts('Synchronize Complete'), 'success');
CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/admin', 'reset=1'));
}
}

View file

@ -0,0 +1,149 @@
<?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 ContactSub Type.
*/
class CRM_Admin_Form_ContactType extends CRM_Admin_Form {
/**
* Build the form object.
*/
public function buildQuickForm() {
parent::buildQuickForm();
$this->setPageTitle(ts('Contact Type'));
if ($this->_action & CRM_Core_Action::DELETE) {
return;
}
$this->applyFilter('__ALL__', 'trim');
$this->add('text', 'label', ts('Name'),
CRM_Core_DAO::getAttribute('CRM_Contact_DAO_ContactType', 'label'),
TRUE
);
$contactType = $this->add('select', 'parent_id', ts('Basic Contact Type'),
CRM_Contact_BAO_ContactType::basicTypePairs(FALSE, 'id')
);
$enabled = $this->add('checkbox', 'is_active', ts('Enabled?'));
if ($this->_action & CRM_Core_Action::UPDATE) {
$contactType->freeze();
// We'll display actual "name" for built-in types (for reference) when editing their label / image_URL
$contactTypeName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_ContactType', $this->_id, 'name');
$this->assign('contactTypeName', $contactTypeName);
$this->_parentId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_ContactType', $this->_id, 'parent_id');
// Freeze Enabled field for built-in contact types (parent_id is NULL for these)
if (is_null($this->_parentId)) {
$enabled->freeze();
}
}
$this->addElement('text', 'image_URL', ts('Image URL'));
$this->add('text', 'description', ts('Description'),
CRM_Core_DAO::getAttribute('CRM_Contact_DAO_ContactType', 'description')
);
$this->assign('cid', $this->_id);
$this->addFormRule(array('CRM_Admin_Form_ContactType', 'formRule'), $this);
}
/**
* Global form rule.
*
* @param array $fields
* The input form values.
*
* @param $files
* @param $self
*
* @return bool|array
* true if no errors, else array of errors
*/
public static function formRule($fields, $files, $self) {
$errors = array();
if ($self->_id) {
$contactName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_ContactType', $self->_id, 'name');
}
else {
$contactName = ucfirst(CRM_Utils_String::munge($fields['label']));
}
if (!CRM_Core_DAO::objectExists($contactName, 'CRM_Contact_DAO_ContactType', $self->_id)) {
$errors['label'] = ts('This contact type name already exists in database. Contact type names must be unique.');
}
$reservedKeyWords = CRM_Core_SelectValues::customGroupExtends();
//restrict "name" from being a reserved keyword when a new contact subtype is created
if (!$self->_id && in_array($contactName, array_keys($reservedKeyWords))) {
$errors['label'] = ts('Contact type names should not use reserved keywords.');
}
return empty($errors) ? TRUE : $errors;
}
/**
* Process the form submission.
*/
public function postProcess() {
CRM_Utils_System::flushCache();
if ($this->_action & CRM_Core_Action::DELETE) {
$isDelete = CRM_Contact_BAO_ContactType::del($this->_id);
if ($isDelete) {
CRM_Core_Session::setStatus(ts('Selected contact type has been deleted.'), ts('Record Deleted'), 'success');
}
else {
CRM_Core_Session::setStatus(ts("Selected contact type can not be deleted. Make sure contact type doesn't have any associated custom data or group."), ts('Sorry'), 'error');
}
return;
}
// store the submitted values in an array
$params = $this->exportValues();
if ($this->_action & CRM_Core_Action::UPDATE) {
$params['id'] = $this->_id;
// Force Enabled = true for built-in contact types to fix problems caused by CRM-6471 (parent_id is NULL for these types)
if (is_null($this->_parentId)) {
$params['is_active'] = 1;
}
}
if ($this->_action & CRM_Core_Action::ADD) {
$params['name'] = ucfirst(CRM_Utils_String::munge($params['label']));
}
$contactType = CRM_Contact_BAO_ContactType::add($params);
CRM_Core_Session::setStatus(ts("The Contact Type '%1' has been saved.",
array(1 => $contactType->label)
), ts('Saved'), 'success');
}
}

View file

@ -0,0 +1,225 @@
<?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 Extensions.
*/
class CRM_Admin_Form_Extensions extends CRM_Admin_Form {
/**
* Form pre-processing.
*/
public function preProcess() {
parent::preProcess();
$mainPage = new CRM_Admin_Page_Extensions();
$localExtensionRows = $mainPage->formatLocalExtensionRows();
$this->assign('localExtensionRows', $localExtensionRows);
$remoteExtensionRows = $mainPage->formatRemoteExtensionRows($localExtensionRows);
$this->assign('remoteExtensionRows', $remoteExtensionRows);
$this->_key = CRM_Utils_Request::retrieve('key', 'String',
$this, FALSE, 0
);
if (!CRM_Utils_Type::validate($this->_key, 'ExtensionKey') && !empty($this->_key)) {
throw new CRM_Core_Exception('Extension Key does not match expected standard');
}
$session = CRM_Core_Session::singleton();
$url = CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1&action=browse');
$session->pushUserContext($url);
$this->assign('id', $this->_id);
$this->assign('key', $this->_key);
switch ($this->_action) {
case CRM_Core_Action::ADD:
case CRM_Core_Action::DELETE:
case CRM_Core_Action::ENABLE:
case CRM_Core_Action::DISABLE:
$info = CRM_Extension_System::singleton()->getMapper()->keyToInfo($this->_key);
$extInfo = CRM_Admin_Page_Extensions::createExtendedInfo($info);
$this->assign('extension', $extInfo);
break;
case CRM_Core_Action::UPDATE:
if (!CRM_Extension_System::singleton()->getBrowser()->isEnabled()) {
CRM_Core_Error::fatal(ts('The system administrator has disabled this feature.'));
}
$info = CRM_Extension_System::singleton()->getBrowser()->getExtension($this->_key);
$extInfo = CRM_Admin_Page_Extensions::createExtendedInfo($info);
$this->assign('extension', $extInfo);
break;
default:
CRM_Core_Error::fatal(ts('Unsupported action'));
}
}
/**
* Set default values for the form.
*/
public function setDefaultValues() {
$defaults = array();
return $defaults;
}
/**
* Build the form object.
*/
public function buildQuickForm() {
switch ($this->_action) {
case CRM_Core_Action::ADD:
$buttonName = ts('Install');
$title = ts('Install "%1"?', array(
1 => $this->_key,
));
break;
case CRM_Core_Action::UPDATE:
$buttonName = ts('Download and Install');
$title = ts('Download and Install "%1"?', array(
1 => $this->_key,
));
break;
case CRM_Core_Action::DELETE:
$buttonName = ts('Uninstall');
$title = ts('Uninstall "%1"?', array(
1 => $this->_key,
));
break;
case CRM_Core_Action::ENABLE:
$buttonName = ts('Enable');
$title = ts('Enable "%1"?', array(
1 => $this->_key,
));
break;
case CRM_Core_Action::DISABLE:
$buttonName = ts('Disable');
$title = ts('Disable "%1"?', array(
1 => $this->_key,
));
break;
}
$this->assign('title', $title);
$this->addButtons(array(
array(
'type' => 'next',
'name' => $buttonName,
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
)
);
}
/**
* Global form rule.
*
* @param array $fields
* The input form values.
* @param array $files
* The uploaded files if any.
* @param array $self
* This object.
*
* @return bool|array
* true if no errors, else an array of errors
*/
public static function formRule($fields, $files, $self) {
$errors = array();
return empty($errors) ? TRUE : $errors;
}
/**
* Process the form submission.
*/
public function postProcess() {
CRM_Utils_System::flushCache();
if ($this->_action & CRM_Core_Action::DELETE) {
try {
CRM_Extension_System::singleton()->getManager()->uninstall(array($this->_key));
CRM_Core_Session::setStatus("", ts('Extension Uninstalled'), "success");
}
catch (CRM_Extension_Exception_DependencyException $e) {
// currently only thrown for payment-processor dependencies
CRM_Core_Session::setStatus(ts('Cannot uninstall this extension - there is at least one payment processor using the payment processor type provided by it.'), ts('Uninstall Error'), 'error');
}
}
if ($this->_action & CRM_Core_Action::ADD) {
civicrm_api3('Extension', 'install', array('keys' => $this->_key));
CRM_Core_Session::setStatus("", ts('Extension Installed'), "success");
}
if ($this->_action & CRM_Core_Action::ENABLE) {
civicrm_api3('Extension', 'enable', array('keys' => $this->_key));
CRM_Core_Session::setStatus("", ts('Extension Enabled'), "success");
}
if ($this->_action & CRM_Core_Action::DISABLE) {
CRM_Extension_System::singleton()->getManager()->disable(array($this->_key));
CRM_Core_Session::setStatus("", ts('Extension Disabled'), "success");
}
if ($this->_action & CRM_Core_Action::UPDATE) {
$result = civicrm_api('Extension', 'download', array(
'version' => 3,
'key' => $this->_key,
));
if (!CRM_Utils_Array::value('is_error', $result, FALSE)) {
CRM_Core_Session::setStatus("", ts('Extension Upgraded'), "success");
}
else {
CRM_Core_Session::setStatus($result['error_message'], ts('Extension Upgrade Failed'), "error");
}
}
CRM_Utils_System::redirect(
CRM_Utils_System::url(
'civicrm/admin/extensions',
'reset=1&action=browse'
)
);
}
}

View file

@ -0,0 +1,242 @@
<?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 for configuring jobs.
*/
class CRM_Admin_Form_Job extends CRM_Admin_Form {
protected $_id = NULL;
public function preProcess() {
parent::preProcess();
CRM_Utils_System::setTitle(ts('Manage - Scheduled Jobs'));
if ($this->_id) {
$refreshURL = CRM_Utils_System::url('civicrm/admin/job',
"reset=1&action=update&id={$this->_id}",
FALSE, NULL, FALSE
);
}
else {
$refreshURL = CRM_Utils_System::url('civicrm/admin/job',
"reset=1&action=add",
FALSE, NULL, FALSE
);
}
$this->assign('refreshURL', $refreshURL);
}
/**
* Build the form object.
*
* @param bool $check
*/
public function buildQuickForm($check = FALSE) {
parent::buildQuickForm();
if ($this->_action & CRM_Core_Action::DELETE) {
return;
}
$attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Job');
$this->add('text', 'name', ts('Name'),
$attributes['name'], TRUE
);
$this->addRule('name', ts('Name already exists in Database.'), 'objectExists', array(
'CRM_Core_DAO_Job',
$this->_id,
));
$this->add('text', 'description', ts('Description'),
$attributes['description']
);
$this->add('text', 'api_entity', ts('API Call Entity'),
$attributes['api_entity'], TRUE
);
$this->add('text', 'api_action', ts('API Call Action'),
$attributes['api_action'], TRUE
);
$this->add('select', 'run_frequency', ts('Run frequency'), CRM_Core_SelectValues::getJobFrequency());
// CRM-17686
$this->add('datepicker', 'scheduled_run_date', ts('Scheduled Run Date'), NULL, FALSE, array('minDate' => time()));
$this->add('textarea', 'parameters', ts('Command parameters'),
"cols=50 rows=6"
);
// is this job active ?
$this->add('checkbox', 'is_active', ts('Is this Scheduled Job active?'));
$this->addFormRule(array('CRM_Admin_Form_Job', 'formRule'));
}
/**
* @param $fields
*
* @return array|bool
* @throws API_Exception
*/
public static function formRule($fields) {
$errors = array();
require_once 'api/api.php';
/** @var \Civi\API\Kernel $apiKernel */
$apiKernel = \Civi::service('civi_api_kernel');
$apiRequest = \Civi\API\Request::create($fields['api_entity'], $fields['api_action'], array('version' => 3), NULL);
try {
$apiKernel->resolve($apiRequest);
}
catch (\Civi\API\Exception\NotImplementedException $e) {
$errors['api_action'] = ts('Given API command is not defined.');
}
if (!empty($errors)) {
return $errors;
}
return empty($errors) ? TRUE : $errors;
}
/**
* @return array
*/
public function setDefaultValues() {
$defaults = array();
if (!$this->_id) {
$defaults['is_active'] = $defaults['is_default'] = 1;
return $defaults;
}
$domainID = CRM_Core_Config::domainID();
$dao = new CRM_Core_DAO_Job();
$dao->id = $this->_id;
$dao->domain_id = $domainID;
if (!$dao->find(TRUE)) {
return $defaults;
}
CRM_Core_DAO::storeValues($dao, $defaults);
// CRM-17686
if (!empty($dao->scheduled_run_date)) {
$ts = strtotime($dao->scheduled_run_date);
$defaults['scheduled_run_date'] = date("Y-m-d H:i:s", $ts);
}
// CRM-10708
// job entity thats shipped with core is all lower case.
// this makes sure camel casing is followed for proper working of default population.
if (!empty($defaults['api_entity'])) {
$defaults['api_entity'] = ucfirst($defaults['api_entity']);
}
return $defaults;
}
/**
* Process the form submission.
*/
public function postProcess() {
CRM_Utils_System::flushCache('CRM_Core_DAO_Job');
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Core_BAO_Job::del($this->_id);
CRM_Core_Session::setStatus("", ts('Scheduled Job Deleted.'), "success");
return;
}
$values = $this->controller->exportValues($this->_name);
$domainID = CRM_Core_Config::domainID();
$dao = new CRM_Core_DAO_Job();
$dao->id = $this->_id;
$dao->domain_id = $domainID;
$dao->run_frequency = $values['run_frequency'];
$dao->parameters = $values['parameters'];
$dao->name = $values['name'];
$dao->api_entity = $values['api_entity'];
$dao->api_action = $values['api_action'];
$dao->description = $values['description'];
$dao->is_active = CRM_Utils_Array::value('is_active', $values, 0);
// CRM-17686
$ts = strtotime($values['scheduled_run_date']);
// if a date/time is supplied and not in the past, then set the next scheduled run...
if ($ts > time()) {
$dao->scheduled_run_date = CRM_Utils_Date::currentDBDate($ts);
// warn about monthly/quarterly scheduling, if applicable
if (($dao->run_frequency == 'Monthly') || ($dao->run_frequency == 'Quarter')) {
$info = getdate($ts);
if ($info['mday'] > 28) {
CRM_Core_Session::setStatus(
ts('Relative month values are calculated based on the length of month(s) that they pass through.
The result will land on the same day of the month except for days 29-31 when the target month contains fewer days than the previous month.
For example, if a job is scheduled to run on August 31st, the following invocation will occur on October 1st, and then the 1st of every month thereafter.
To avoid this issue, please schedule Monthly and Quarterly jobs to run within the first 28 days of the month.'),
ts('Warning'), 'info', array('expires' => 0));
}
}
}
// ...otherwise, if this isn't a new scheduled job, clear the next scheduled run
elseif ($dao->id) {
$job = new CRM_Core_ScheduledJob(array('id' => $dao->id));
$job->clearScheduledRunDate();
}
$dao->save();
// CRM-11143 - Give warning message if update_greetings is Enabled (is_active) since it generally should not be run automatically via execute action or runjobs url.
if ($values['api_action'] == 'update_greeting' && CRM_Utils_Array::value('is_active', $values) == 1) {
// pass "wiki" as 6th param to docURL2 if you are linking to a page in wiki.civicrm.org
$docLink = CRM_Utils_System::docURL2("Managing Scheduled Jobs", NULL, NULL, NULL, NULL, "wiki");
$msg = ts('The update greeting job can be very resource intensive and is typically not necessary to run on a regular basis. If you do choose to enable the job, we recommend you do not run it with the force=1 option, which would rebuild greetings on all records. Leaving that option absent, or setting it to force=0, will only rebuild greetings for contacts that do not currently have a value stored. %1', array(1 => $docLink));
CRM_Core_Session::setStatus($msg, ts('Warning: Update Greeting job enabled'), 'alert');
}
}
}

View file

@ -0,0 +1,250 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright (C) 2011 Marty Wright |
| Licensed to CiviCRM under the Academic Free License version 3.0. |
+--------------------------------------------------------------------+
| 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 Label Format Settings.
*/
class CRM_Admin_Form_LabelFormats extends CRM_Admin_Form {
/**
* Label Format ID.
*/
protected $_id = NULL;
/**
* Group name, label format or name badge
*/
protected $_group = NULL;
public function preProcess() {
$this->_id = $this->get('id');
$this->_group = CRM_Utils_Request::retrieve('group', 'String', $this, FALSE, 'label_format');
$this->_values = array();
if (isset($this->_id)) {
$params = array('id' => $this->_id);
CRM_Core_BAO_LabelFormat::retrieve($params, $this->_values, $this->_group);
}
}
/**
* Build the form object.
*/
public function buildQuickForm() {
parent::buildQuickForm();
if ($this->_action & (CRM_Core_Action::DELETE | CRM_Core_Action::COPY)) {
$formatName = CRM_Core_BAO_LabelFormat::getFieldValue('CRM_Core_BAO_LabelFormat', $this->_id, 'label');
$this->assign('formatName', $formatName);
return;
}
$disabled = array();
$required = TRUE;
$is_reserved = $this->_id ? CRM_Core_BAO_LabelFormat::getFieldValue('CRM_Core_BAO_LabelFormat', $this->_id, 'is_reserved') : FALSE;
if ($is_reserved) {
$disabled['disabled'] = 'disabled';
$required = FALSE;
}
$attributes = CRM_Core_DAO::getAttribute('CRM_Core_BAO_LabelFormat');
$this->add('text', 'label', ts('Name'), $attributes['label'] + $disabled, $required);
$this->add('text', 'description', ts('Description'), array('size' => CRM_Utils_Type::HUGE));
$this->add('checkbox', 'is_default', ts('Is this Label Format the default?'));
// currently we support only mailing label creation, hence comment below code
/*
$options = array(
'label_format' => ts('Mailing Label'),
'name_badge' => ts('Name Badge'),
);
$labelType = $this->addRadio('label_type', ts('Used For'), $options, null, '&nbsp;&nbsp;');
if ($this->_action != CRM_Core_Action::ADD) {
$labelType->freeze();
}
*/
$this->add('select', 'paper_size', ts('Sheet Size'),
array(
0 => ts('- default -'),
) + CRM_Core_BAO_PaperSize::getList(TRUE), FALSE,
array(
'onChange' => "selectPaper( this.value );",
) + $disabled
);
$this->add('static', 'paper_dimensions', NULL, ts('Sheet Size (w x h)'));
$this->add('select', 'orientation', ts('Orientation'), CRM_Core_BAO_LabelFormat::getPageOrientations(), FALSE,
array(
'onChange' => "updatePaperDimensions();",
) + $disabled
);
$this->add('select', 'font_name', ts('Font Name'), CRM_Core_BAO_LabelFormat::getFontNames($this->_group));
$this->add('select', 'font_size', ts('Font Size'), CRM_Core_BAO_LabelFormat::getFontSizes());
$this->add('static', 'font_style', ts('Font Style'));
$this->add('checkbox', 'bold', ts('Bold'));
$this->add('checkbox', 'italic', ts('Italic'));
$this->add('select', 'metric', ts('Unit of Measure'), CRM_Core_BAO_LabelFormat::getUnits(), FALSE,
array('onChange' => "selectMetric( this.value );")
);
$this->add('text', 'width', ts('Label Width'), array('size' => 8, 'maxlength' => 8) + $disabled, $required);
$this->add('text', 'height', ts('Label Height'), array('size' => 8, 'maxlength' => 8) + $disabled, $required);
$this->add('text', 'NX', ts('Labels Per Row'), array('size' => 3, 'maxlength' => 3) + $disabled, $required);
$this->add('text', 'NY', ts('Labels Per Column'), array('size' => 3, 'maxlength' => 3) + $disabled, $required);
$this->add('text', 'tMargin', ts('Top Margin'), array('size' => 8, 'maxlength' => 8) + $disabled, $required);
$this->add('text', 'lMargin', ts('Left Margin'), array('size' => 8, 'maxlength' => 8) + $disabled, $required);
$this->add('text', 'SpaceX', ts('Horizontal Spacing'), array('size' => 8, 'maxlength' => 8) + $disabled, $required);
$this->add('text', 'SpaceY', ts('Vertical Spacing'), array('size' => 8, 'maxlength' => 8) + $disabled, $required);
$this->add('text', 'lPadding', ts('Left Padding'), array('size' => 8, 'maxlength' => 8), $required);
$this->add('text', 'tPadding', ts('Top Padding'), array('size' => 8, 'maxlength' => 8), $required);
$this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Core_BAO_LabelFormat', 'weight'), TRUE);
$this->addRule('label', ts('Name already exists in Database.'), 'objectExists', array(
'CRM_Core_BAO_LabelFormat',
$this->_id,
));
$this->addRule('NX', ts('Please enter a valid integer.'), 'integer');
$this->addRule('NY', ts('Please enter a valid integer.'), 'integer');
$this->addRule('tMargin', ts('Please enter a valid number.'), 'numeric');
$this->addRule('lMargin', ts('Please enter a valid number.'), 'numeric');
$this->addRule('SpaceX', ts('Please enter a valid number.'), 'numeric');
$this->addRule('SpaceY', ts('Please enter a valid number.'), 'numeric');
$this->addRule('lPadding', ts('Please enter a valid number.'), 'numeric');
$this->addRule('tPadding', ts('Please enter a valid number.'), 'numeric');
$this->addRule('width', ts('Please enter a valid number.'), 'numeric');
$this->addRule('height', ts('Please enter a valid number.'), 'numeric');
$this->addRule('weight', ts('Please enter a valid integer.'), 'integer');
}
/**
* @return int
*/
public function setDefaultValues() {
if ($this->_action & CRM_Core_Action::ADD) {
$defaults['weight'] = CRM_Utils_Array::value('weight', CRM_Core_BAO_LabelFormat::getDefaultValues($this->_group), 0);
}
else {
$defaults = $this->_values;
// Convert field names that are illegal PHP/SMARTY variable names
$defaults['paper_size'] = $defaults['paper-size'];
unset($defaults['paper-size']);
$defaults['font_name'] = $defaults['font-name'];
unset($defaults['font-name']);
$defaults['font_size'] = $defaults['font-size'];
unset($defaults['font-size']);
$defaults['bold'] = (stripos($defaults['font-style'], 'B') !== FALSE);
$defaults['italic'] = (stripos($defaults['font-style'], 'I') !== FALSE);
unset($defaults['font-style']);
}
$defaults['label_type'] = $this->_group;
return $defaults;
}
/**
* Process the form submission.
*/
public function postProcess() {
if ($this->_action & CRM_Core_Action::DELETE) {
// delete Label Format
CRM_Core_BAO_LabelFormat::del($this->_id, $this->_group);
CRM_Core_Session::setStatus(ts('Selected Label Format has been deleted.'), ts('Record Deleted'), 'success');
return;
}
if ($this->_action & CRM_Core_Action::COPY) {
// make a copy of the Label Format
$labelFormat = CRM_Core_BAO_LabelFormat::getById($this->_id, $this->_group);
$newlabel = ts('Copy of %1', array(1 => $labelFormat['label']));
$list = CRM_Core_BAO_LabelFormat::getList(TRUE, $this->_group);
$count = 1;
while (in_array($newlabel, $list)) {
$count++;
$newlabel = ts('Copy %1 of %2', array(1 => $count, 2 => $labelFormat['label']));
}
$labelFormat['label'] = $newlabel;
$labelFormat['grouping'] = CRM_Core_BAO_LabelFormat::customGroupName();
$labelFormat['is_default'] = 0;
$labelFormat['is_reserved'] = 0;
$bao = new CRM_Core_BAO_LabelFormat();
$bao->saveLabelFormat($labelFormat, NULL, $this->_group);
CRM_Core_Session::setStatus(ts('%1 has been created.', array(1 => $labelFormat['label'])), ts('Saved'), 'success');
return;
}
$values = $this->controller->exportValues($this->getName());
// since we currently support only mailing label format
$values['label_type'] = 'label_format';
$values['is_default'] = isset($values['is_default']);
// Restore field names that were converted because they are illegal PHP/SMARTY variable names
if (isset($values['paper_size'])) {
$values['paper-size'] = $values['paper_size'];
unset($values['paper_size']);
}
if (isset($values['font_name'])) {
$values['font-name'] = $values['font_name'];
unset($values['font_name']);
}
if (isset($values['font_size'])) {
$values['font-size'] = $values['font_size'];
unset($values['font_size']);
}
$style = '';
if (isset($values['bold'])) {
$style .= 'B';
}
if (isset($values['italic'])) {
$style .= 'I';
}
$values['font-style'] = $style;
$bao = new CRM_Core_BAO_LabelFormat();
$bao->saveLabelFormat($values, $this->_id, $values['label_type']);
$status = ts('Your new Label Format titled <strong>%1</strong> has been saved.', array(1 => $values['label']));
if ($this->_action & CRM_Core_Action::UPDATE) {
$status = ts('Your Label Format titled <strong>%1</strong> has been updated.', array(1 => $values['label']));
}
CRM_Core_Session::setStatus($status, ts('Saved'), 'success');
}
}

View file

@ -0,0 +1,127 @@
<?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 Location Type.
*/
class CRM_Admin_Form_LocationType extends CRM_Admin_Form {
/**
* Build the form object.
*/
public function buildQuickForm() {
parent::buildQuickForm();
$this->setPageTitle(ts('Location Type'));
if ($this->_action & CRM_Core_Action::DELETE) {
return;
}
$this->applyFilter('__ALL__', 'trim');
$this->add('text',
'name',
ts('Name'),
CRM_Core_DAO::getAttribute('CRM_Core_DAO_LocationType', 'name'),
TRUE
);
$this->addRule('name',
ts('Name already exists in Database.'),
'objectExists',
array('CRM_Core_DAO_LocationType', $this->_id)
);
$this->addRule('name',
ts('Name can only consist of alpha-numeric characters'),
'variable'
);
$this->add('text', 'display_name', ts('Display Name'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_LocationType', 'display_name'), TRUE);
$this->add('text', 'vcard_name', ts('vCard Name'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_LocationType', 'vcard_name'));
$this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_LocationType', 'description'));
$this->add('checkbox', 'is_active', ts('Enabled?'));
$this->add('checkbox', 'is_default', ts('Default?'));
if ($this->_action & CRM_Core_Action::UPDATE) {
if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_LocationType', $this->_id, 'is_reserved')) {
$this->freeze(array('name', 'description', 'is_active'));
}
if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_LocationType', $this->_id, 'is_default')) {
$this->freeze(array('is_default'));
}
}
}
/**
* Process the form submission.
*/
public function postProcess() {
CRM_Utils_System::flushCache('CRM_Core_DAO_LocationType');
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Core_BAO_LocationType::del($this->_id);
CRM_Core_Session::setStatus(ts('Selected Location type has been deleted.'), ts('Record Deleted'), 'success');
return;
}
// store the submitted values in an array
$params = $this->exportValues();
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
$params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE);
// action is taken depending upon the mode
$locationType = new CRM_Core_DAO_LocationType();
$locationType->name = $params['name'];
$locationType->display_name = $params['display_name'];
$locationType->vcard_name = $params['vcard_name'];
$locationType->description = $params['description'];
$locationType->is_active = $params['is_active'];
$locationType->is_default = $params['is_default'];
if ($params['is_default']) {
$query = "UPDATE civicrm_location_type SET is_default = 0";
CRM_Core_DAO::executeQuery($query);
}
if ($this->_action & CRM_Core_Action::UPDATE) {
$locationType->id = $this->_id;
}
$locationType->save();
CRM_Core_Session::setStatus(ts("The location type '%1' has been saved.",
array(1 => $locationType->name)
), ts('Saved'), 'success');
}
}

View file

@ -0,0 +1,199 @@
<?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 handles mail account settings.
*
*/
class CRM_Admin_Form_MailSettings extends CRM_Admin_Form {
/**
* Build the form object.
*/
public function buildQuickForm() {
parent::buildQuickForm();
$this->setPageTitle(ts('Mail Account'));
if ($this->_action & CRM_Core_Action::DELETE) {
return;
}
$this->applyFilter('__ALL__', 'trim');
//get the attributes.
$attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_MailSettings');
//build setting form
$this->add('text', 'name', ts('Name'), $attributes['name'], TRUE);
$this->add('text', 'domain', ts('Email Domain'), $attributes['domain'], TRUE);
$this->addRule('domain', ts('Email domain must use a valid internet domain format (e.g. \'example.org\').'), 'domain');
$this->add('text', 'localpart', ts('Localpart'), $attributes['localpart']);
$this->add('text', 'return_path', ts('Return-Path'), $attributes['return_path']);
$this->addRule('return_path', ts('Return-Path must use a valid email address format.'), 'email');
$this->add('select', 'protocol',
ts('Protocol'),
array('' => ts('- select -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_MailSettings', 'protocol'),
TRUE
);
$this->add('text', 'server', ts('Server'), $attributes['server']);
$this->add('text', 'username', ts('Username'), array('autocomplete' => 'off'));
$this->add('password', 'password', ts('Password'), array('autocomplete' => 'off'));
$this->add('text', 'source', ts('Source'), $attributes['source']);
$this->add('checkbox', 'is_ssl', ts('Use SSL?'));
$usedfor = array(
1 => ts('Bounce Processing'),
0 => ts('Email-to-Activity Processing'),
);
$this->add('select', 'is_default', ts('Used For?'), $usedfor);
$this->addField('activity_status', array('placeholder' => FALSE));
}
/**
* Add local and global form rules.
*/
public function addRules() {
$this->addFormRule(array('CRM_Admin_Form_MailSettings', 'formRule'));
}
public function getDefaultEntity() {
return 'MailSettings';
}
/**
* Add local and global form rules.
*/
public function setDefaultValues() {
$defaults = parent::setDefaultValues();
// Set activity status to "Completed" by default.
if ($this->_action != CRM_Core_Action::DELETE &&
(!$this->_id || !CRM_Core_DAO::getFieldValue('CRM_Core_BAO_MailSettings', $this->_id, 'activity_status'))
) {
$defaults['activity_status'] = 'Completed';
}
return $defaults;
}
/**
* Global validation rules for the form.
*
* @param array $fields
* Posted values of the form.
*
* @return array
* list of errors to be posted back to the form
*/
public static function formRule($fields) {
$errors = array();
// Check for default from email address and organization (domain) name. Force them to change it.
if ($fields['domain'] == 'EXAMPLE.ORG') {
$errors['domain'] = ts('Please enter a valid domain for this mailbox account (the part after @).');
}
return empty($errors) ? TRUE : $errors;
}
/**
* Process the form submission.
*/
public function postProcess() {
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Core_BAO_MailSettings::deleteMailSettings($this->_id);
CRM_Core_Session::setStatus("", ts('Mail Setting Deleted.'), "success");
return;
}
//get the submitted form values.
$formValues = $this->controller->exportValues($this->_name);
//form fields.
$fields = array(
'name',
'domain',
'localpart',
'server',
'return_path',
'protocol',
'port',
'username',
'password',
'source',
'is_ssl',
'is_default',
'activity_status',
);
$params = array();
foreach ($fields as $f) {
if (in_array($f, array(
'is_default',
'is_ssl',
))) {
$params[$f] = CRM_Utils_Array::value($f, $formValues, FALSE);
}
else {
$params[$f] = CRM_Utils_Array::value($f, $formValues);
}
}
$params['domain_id'] = CRM_Core_Config::domainID();
// assign id only in update mode
$status = ts('Your New Email Settings have been saved.');
if ($this->_action & CRM_Core_Action::UPDATE) {
$params['id'] = $this->_id;
$status = ts('Your Email Settings have been updated.');
}
$mailSettings = CRM_Core_BAO_MailSettings::create($params);
if ($mailSettings->id) {
CRM_Core_Session::setStatus($status, ts("Saved"), "success");
}
else {
CRM_Core_Session::setStatus("", ts('Changes Not Saved.'), "info");
}
}
}

View file

@ -0,0 +1,110 @@
<?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 Mapping.
*/
class CRM_Admin_Form_Mapping extends CRM_Admin_Form {
/**
* Build the form object.
*/
public function preProcess() {
parent::preProcess();
$mapping = new CRM_Core_DAO_Mapping();
$mapping->id = $this->_id;
$mapping->find(TRUE);
$this->assign('mappingName', $mapping->name);
}
public function buildQuickForm() {
parent::buildQuickForm();
$this->setPageTitle(ts('Field Mapping'));
if ($this->_action == CRM_Core_Action::DELETE) {
return;
}
else {
$this->applyFilter('__ALL__', 'trim');
$this->add('text', 'name', ts('Name'),
CRM_Core_DAO::getAttribute('CRM_Core_DAO_Mapping', 'name'), TRUE
);
$this->addRule('name', ts('Name already exists in Database.'), 'objectExists', array(
'CRM_Core_DAO_Mapping',
$this->_id,
));
$this->addElement('text', 'description', ts('Description'),
CRM_Core_DAO::getAttribute('CRM_Core_DAO_Mapping', 'description')
);
$mappingType = $this->addElement('select', 'mapping_type_id', ts('Mapping Type'), CRM_Core_PseudoConstant::get('CRM_Core_DAO_Mapping', 'mapping_type_id'));
if ($this->_action == CRM_Core_Action::UPDATE) {
$mappingType->freeze();
}
}
}
/**
* @return array
*/
public function setDefaultValues() {
$defaults = parent::setDefaultValues();
return $defaults;
}
/**
* Process the form submission.
*/
public function postProcess() {
// store the submitted values in an array
$params = $this->exportValues();
if ($this->_action == CRM_Core_Action::DELETE) {
if ($this->_id) {
CRM_Core_BAO_Mapping::del($this->_id);
CRM_Core_Session::setStatus(ts('Selected mapping has been deleted successfully.'), ts('Deleted'), 'success');
}
}
else {
if ($this->_id) {
$params['id'] = $this->_id;
}
CRM_Core_BAO_Mapping::add($params);
}
}
}

View file

@ -0,0 +1,304 @@
<?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 Message templates
* used by membership, contributions, event registrations, etc.
*/
class CRM_Admin_Form_MessageTemplates extends CRM_Admin_Form {
// which (and whether) mailing workflow this template belongs to
protected $_workflow_id = NULL;
// Is document file is already loaded as default value?
protected $_is_document = FALSE;
public function preProcess() {
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
$this->_action = CRM_Utils_Request::retrieve('action', 'String',
$this, FALSE, 'add'
);
$this->assign('action', $this->_action);
$this->_BAOName = 'CRM_Core_BAO_MessageTemplate';
$this->set('BAOName', $this->_BAOName);
parent::preProcess();
}
/**
* Set default values for the form.
*
* The default values are retrieved from the database.
*/
public function setDefaultValues() {
$defaults = $this->_values;
if (empty($defaults['pdf_format_id'])) {
$defaults['pdf_format_id'] = 'null';
}
if (empty($defaults['file_type'])) {
$defaults['file_type'] = 0;
}
if ($this->_action & CRM_Core_Action::ADD) {
$defaults['is_active'] = 1;
}
if ($this->_action & CRM_Core_Action::UPDATE) {
$documentInfo = CRM_Core_BAO_File::getEntityFile('civicrm_msg_template', $this->_id, TRUE);
if (!empty($documentInfo)) {
$defaults['file_type'] = 1;
$this->_is_document = TRUE;
$this->assign('attachment', $documentInfo);
}
}
return $defaults;
}
/**
* Build the form object.
*/
public function buildQuickForm() {
// For VIEW we only want Done button
if ($this->_action & CRM_Core_Action::VIEW) {
// currently, the above action is used solely for previewing default workflow templates
$cancelURL = CRM_Utils_System::url('civicrm/admin/messageTemplates', 'selectedChild=workflow&reset=1');
$cancelURL = str_replace('&amp;', '&', $cancelURL);
$this->addButtons(array(
array(
'type' => 'cancel',
'name' => ts('Done'),
'js' => array('onclick' => "location.href='{$cancelURL}'; return false;"),
'isDefault' => TRUE,
),
)
);
}
else {
$this->_workflow_id = CRM_Utils_Array::value('workflow_id', $this->_values);
$this->assign('workflow_id', $this->_workflow_id);
if ($this->_workflow_id) {
$selectedChild = 'workflow';
}
else {
$selectedChild = 'user';
}
$cancelURL = CRM_Utils_System::url('civicrm/admin/messageTemplates', "selectedChild={$selectedChild}&reset=1");
$cancelURL = str_replace('&amp;', '&', $cancelURL);
$buttons[] = array(
'type' => 'upload',
'name' => $this->_action & CRM_Core_Action::DELETE ? ts('Delete') : ts('Save'),
'isDefault' => TRUE,
);
if (!($this->_action & CRM_Core_Action::DELETE)) {
$buttons[] = array(
'type' => 'submit',
'name' => ts('Save and Done'),
'subName' => 'done',
);
}
$buttons[] = array(
'type' => 'cancel',
'name' => ts('Cancel'),
'js' => array('onclick' => "location.href='{$cancelURL}'; return false;"),
);
$this->addButtons($buttons);
}
if ($this->_action & CRM_Core_Action::DELETE) {
return;
}
$breadCrumb = array(
array(
'title' => ts('Message Templates'),
'url' => CRM_Utils_System::url('civicrm/admin/messageTemplates',
'action=browse&reset=1'
),
),
);
CRM_Utils_System::appendBreadCrumb($breadCrumb);
$this->applyFilter('__ALL__', 'trim');
$this->add('text', 'msg_title', ts('Message Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_MessageTemplate', 'msg_title'), TRUE);
$options = array(ts('Compose On-screen'), ts('Upload Document'));
$element = $this->addRadio('file_type', ts('Source'), $options);
if ($this->_id) {
$element->freeze();
}
$this->addElement('file', "file_id", ts('Upload Document'), 'size=30 maxlength=255');
$this->addUploadElement("file_id");
$this->add('text', 'msg_subject',
ts('Message Subject'),
CRM_Core_DAO::getAttribute('CRM_Core_DAO_MessageTemplate', 'msg_subject')
);
//get the tokens.
$tokens = CRM_Core_SelectValues::contactTokens();
$this->assign('tokens', CRM_Utils_Token::formatTokensForDisplay($tokens));
// if not a system message use a wysiwyg editor, CRM-5971
if ($this->_id &&
CRM_Core_DAO::getFieldValue('CRM_Core_DAO_MessageTemplate',
$this->_id,
'workflow_id'
)
) {
$this->add('textarea', 'msg_html', ts('HTML Message'),
"cols=50 rows=6"
);
}
else {
$this->add('wysiwyg', 'msg_html', ts('HTML Message'),
array(
'cols' => '80',
'rows' => '8',
'onkeyup' => "return verify(this)",
'preset' => 'civimail',
)
);
}
$this->add('textarea', 'msg_text', ts('Text Message'),
"cols=50 rows=6"
);
$this->add('select', 'pdf_format_id', ts('PDF Page Format'),
array(
'null' => ts('- default -'),
) + CRM_Core_BAO_PdfFormat::getList(TRUE), FALSE
);
$this->add('checkbox', 'is_active', ts('Enabled?'));
$this->addFormRule(array(__CLASS__, 'formRule'), $this);
if ($this->_action & CRM_Core_Action::VIEW) {
$this->freeze();
CRM_Utils_System::setTitle(ts('View System Default Message Template'));
}
}
/**
* Global form rule.
*
* @param array $params
* The input form values.
* @param array $files
* The uploaded files if any.
* @param array $self
*
* @return array
* array of errors
*/
public static function formRule($params, $files, $self) {
// If user uploads non-document file other than odt/docx
if (!empty($files['file_id']['tmp_name']) &&
array_search($files['file_id']['type'], CRM_Core_SelectValues::documentApplicationType()) == NULL
) {
$errors['file_id'] = ts('Invalid document file format');
}
// If default is not set and no document file is uploaded
elseif (empty($files['file_id']['tmp_name']) && !empty($params['file_type']) && !$self->_is_document) {
//On edit page of docx/odt message template if user changes file type but forgot to upload document
$errors['file_id'] = ts('Please upload document');
}
return empty($errors) ? TRUE : $errors;
}
/**
* Process the form submission.
*/
public function postProcess() {
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Core_BAO_MessageTemplate::del($this->_id);
}
elseif ($this->_action & CRM_Core_Action::VIEW) {
// currently, the above action is used solely for previewing default workflow templates
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/messageTemplates', 'selectedChild=workflow&reset=1'));
}
else {
// store the submitted values in an array
$params = $this->controller->exportValues();
if ($this->_action & CRM_Core_Action::UPDATE) {
$params['id'] = $this->_id;
}
if (!empty($params['file_type'])) {
unset($params['msg_html']);
unset($params['msg_text']);
CRM_Utils_File::formatFile($params, 'file_id');
}
// delete related file references if html/text/pdf template are chosen over document
elseif (!empty($this->_id)) {
$entityFileDAO = new CRM_Core_DAO_EntityFile();
$entityFileDAO->entity_id = $this->_id;
$entityFileDAO->entity_table = 'civicrm_msg_template';
if ($entityFileDAO->find(TRUE)) {
$fileDAO = new CRM_Core_DAO_File();
$fileDAO->id = $entityFileDAO->file_id;
$fileDAO->find(TRUE);
$entityFileDAO->delete();
$fileDAO->delete();
}
}
$this->_workflow_id = CRM_Utils_Array::value('workflow_id', $this->_values);
if ($this->_workflow_id) {
$params['workflow_id'] = $this->_workflow_id;
$params['is_active'] = TRUE;
}
$messageTemplate = CRM_Core_BAO_MessageTemplate::add($params);
CRM_Core_Session::setStatus(ts('The Message Template \'%1\' has been saved.', array(1 => $messageTemplate->msg_title)), ts('Saved'), 'success');
if (isset($this->_submitValues['_qf_MessageTemplates_upload'])) {
// Save button was pressed
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/messageTemplates/add', "action=update&id={$messageTemplate->id}&reset=1"));
}
// Save and done button was pressed
if ($this->_workflow_id) {
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/messageTemplates', 'selectedChild=workflow&reset=1'));
}
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/messageTemplates', 'selectedChild=user&reset=1'));
}
}
}

View file

@ -0,0 +1,154 @@
<?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 Navigation.
*/
class CRM_Admin_Form_Navigation extends CRM_Admin_Form {
/**
* The parent id of the navigation menu.
*/
protected $_currentParentID = NULL;
/**
* Build the form object.
*/
public function buildQuickForm() {
parent::buildQuickForm();
$this->setPageTitle(ts('Menu Item'));
if ($this->_action & CRM_Core_Action::DELETE) {
return;
}
if (isset($this->_id)) {
$params = array('id' => $this->_id);
CRM_Core_BAO_Navigation::retrieve($params, $this->_defaults);
}
$this->applyFilter('__ALL__', 'trim');
$this->add('text',
'label',
ts('Title'),
CRM_Core_DAO::getAttribute('CRM_Core_DAO_Navigation', 'label'),
TRUE
);
$this->add('text', 'url', ts('Url'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Navigation', 'url'));
$this->add('text', 'icon', ts('Icon'), array('class' => 'crm-icon-picker', 'title' => ts('Choose Icon'), 'allowClear' => TRUE));
$permissions = array();
foreach (CRM_Core_Permission::basicPermissions(TRUE, TRUE) as $id => $vals) {
$permissions[] = array('id' => $id, 'label' => $vals[0], 'description' => (array) CRM_Utils_Array::value(1, $vals));
}
$this->add('text', 'permission', ts('Permission'),
array('placeholder' => ts('Unrestricted'), 'class' => 'huge', 'data-select-params' => json_encode(array('data' => array('results' => $permissions, 'text' => 'label'))))
);
$operators = array('AND' => ts('AND'), 'OR' => ts('OR'));
$this->add('select', 'permission_operator', NULL, $operators);
//make separator location configurable
$separator = array(ts('None'), ts('After menu element'), ts('Before menu element'));
$this->add('select', 'has_separator', ts('Separator'), $separator);
$active = $this->add('advcheckbox', 'is_active', ts('Enabled'));
if (CRM_Utils_Array::value('name', $this->_defaults) == 'Home') {
$active->freeze();
}
else {
$parentMenu = CRM_Core_BAO_Navigation::getNavigationList();
if (isset($this->_id)) {
unset($parentMenu[$this->_id]);
}
// also unset home.
$homeMenuId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Home', 'id', 'name');
unset($parentMenu[$homeMenuId]);
$this->add('select', 'parent_id', ts('Parent'), array('' => ts('Top level')) + $parentMenu, FALSE, array('class' => 'crm-select2'));
}
}
/**
* @return array
*/
public function setDefaultValues() {
$defaults = parent::setDefaultValues();
if (isset($this->_id)) {
//Take parent id in object variable to calculate the menu
//weight if menu parent id changed
$this->_currentParentID = CRM_Utils_Array::value('parent_id', $this->_defaults);
}
else {
$defaults['permission'] = "access CiviCRM";
}
// its ok if there is no element called is_active
$defaults['is_active'] = ($this->_id) ? $this->_defaults['is_active'] : 1;
return $defaults;
}
/**
* Process the form submission.
*/
public function postProcess() {
// get the submitted form values.
$params = $this->controller->exportValues($this->_name);
if (isset($this->_id)) {
$params['id'] = $this->_id;
$params['current_parent_id'] = $this->_currentParentID;
}
if (!empty($params['icon'])) {
$params['icon'] = 'crm-i ' . $params['icon'];
}
$navigation = CRM_Core_BAO_Navigation::add($params);
// also reset navigation
CRM_Core_BAO_Navigation::resetNavigation();
CRM_Core_Session::setStatus(ts('Menu \'%1\' has been saved.',
array(1 => $navigation->label)
), ts('Saved'), 'success');
}
}

View file

@ -0,0 +1,133 @@
<?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 Option Group.
*/
class CRM_Admin_Form_OptionGroup extends CRM_Admin_Form {
/**
* Explicitly declare the entity api name.
*/
public function getDefaultEntity() {
return 'OptionGroup';
}
/**
* Build the form object.
*/
public function buildQuickForm() {
parent::buildQuickForm();
if ($this->_action & CRM_Core_Action::DELETE) {
return;
}
CRM_Utils_System::setTitle(ts('Dropdown Options'));
$this->applyFilter('__ALL__', 'trim');
$this->add('text',
'name',
ts('Name'),
CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionGroup', 'name'),
TRUE
);
$this->addRule('name',
ts('Name already exists in Database.'),
'objectExists',
array('CRM_Core_DAO_OptionGroup', $this->_id)
);
$this->add('text',
'title',
ts('Group Title'),
CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionGroup', 'title')
);
$this->add('text',
'description',
ts('Description'),
CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionGroup', 'description')
);
$this->addSelect('data_type', array('options' => CRM_Utils_Type::dataTypes()), TRUE);
$element = $this->add('checkbox', 'is_active', ts('Enabled?'));
if ($this->_action & CRM_Core_Action::UPDATE) {
if (in_array($this->_values['name'], array(
'encounter_medium',
'case_type',
'case_status',
))) {
static $caseCount = NULL;
if (!isset($caseCount)) {
$caseCount = CRM_Case_BAO_Case::caseCount(NULL, FALSE);
}
if ($caseCount > 0) {
$element->freeze();
}
}
if (!empty($this->_values['is_reserved'])) {
$this->freeze(array('name', 'is_active'));
}
}
$this->assign('id', $this->_id);
}
/**
* Process the form submission.
*/
public function postProcess() {
CRM_Utils_System::flushCache();
$params = $this->exportValues();
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Core_BAO_OptionGroup::del($this->_id);
CRM_Core_Session::setStatus(ts('Selected option group has been deleted.'), ts('Record Deleted'), 'success');
}
else {
$params = $ids = array();
// store the submitted values in an array
$params = $this->exportValues();
if ($this->_action & CRM_Core_Action::UPDATE) {
$ids['optionGroup'] = $this->_id;
}
$optionGroup = CRM_Core_BAO_OptionGroup::add($params, $ids);
CRM_Core_Session::setStatus(ts('The Option Group \'%1\' has been saved.', array(1 => $optionGroup->name)), ts('Saved'), 'success');
}
}
}

View file

@ -0,0 +1,511 @@
<?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 Options.
*/
class CRM_Admin_Form_Options extends CRM_Admin_Form {
/**
* The option group name.
*
* @var array
*/
protected $_gName;
/**
* The option group name in display format (capitalized, without underscores...etc)
*
* @var array
*/
protected $_gLabel;
/**
* Is this Option Group Domain Specific
* @var bool
*/
protected $_domainSpecific = FALSE;
/**
* Pre-process
*/
public function preProcess() {
parent::preProcess();
$session = CRM_Core_Session::singleton();
if (!$this->_gName && !empty($this->urlPath[3])) {
$this->_gName = $this->urlPath[3];
}
if (!$this->_gName && !empty($_GET['gid'])) {
$this->_gName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', (int) $_GET['gid'], 'name');
}
if ($this->_gName) {
$this->set('gName', $this->_gName);
}
else {
$this->_gName = $this->get('gName');
}
$this->_gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup',
$this->_gName,
'id',
'name'
);
$this->_gLabel = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_gid, 'title');
$this->_domainSpecific = in_array($this->_gName, CRM_Core_OptionGroup::$_domainIDGroups);
$url = "civicrm/admin/options/{$this->_gName}";
$params = "reset=1";
if (($this->_action & CRM_Core_Action::DELETE) &&
in_array($this->_gName, array('email_greeting', 'postal_greeting', 'addressee'))
) {
// Don't allow delete if the option value belongs to addressee, postal or email greetings and is in use.
$findValue = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'value');
$queryParam = array(1 => array($findValue, 'Integer'));
$columnName = $this->_gName . "_id";
$sql = "SELECT count(id) FROM civicrm_contact WHERE " . $columnName . " = %1";
$isInUse = CRM_Core_DAO::singleValueQuery($sql, $queryParam);
if ($isInUse) {
$scriptURL = "<a href='" . CRM_Utils_System::docURL2('Update Greetings and Address Data for Contacts', TRUE, NULL, NULL, NULL, "wiki") . "'>" . ts('Learn more about a script that can automatically update contact addressee and greeting options.') . "</a>";
CRM_Core_Session::setStatus(ts('The selected %1 option has <strong>not been deleted</strong> because it is currently in use. Please update these contacts to use a different format before deleting this option. %2', array(
1 => $this->_gLabel,
2 => $scriptURL,
)), ts('Sorry'), 'error');
$redirect = CRM_Utils_System::url($url, $params);
CRM_Utils_System::redirect($redirect);
}
}
$session->pushUserContext(CRM_Utils_System::url($url, $params));
$this->assign('id', $this->_id);
if ($this->_id && in_array($this->_gName, CRM_Core_OptionGroup::$_domainIDGroups)) {
$domainID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'domain_id', 'id');
if (CRM_Core_Config::domainID() != $domainID) {
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
}
}
}
/**
* Set default values for the form.
*/
public function setDefaultValues() {
$defaults = parent::setDefaultValues();
// Default weight & value
$fieldValues = array('option_group_id' => $this->_gid);
foreach (array('weight', 'value') as $field) {
if (empty($defaults[$field])) {
$defaults[$field] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues, $field);
}
}
//setDefault of contact types for email greeting, postal greeting, addressee, CRM-4575
if (in_array($this->_gName, array(
'email_greeting',
'postal_greeting',
'addressee',
))) {
$defaults['contactOptions'] = (CRM_Utils_Array::value('filter', $defaults)) ? $defaults['filter'] : NULL;
}
// CRM-11516
if ($this->_gName == 'payment_instrument' && $this->_id) {
$defaults['financial_account_id'] = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($this->_id, NULL, 'civicrm_option_value');
}
if (empty($this->_id) || !CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'color')) {
$defaults['color'] = '#ffffff';
}
return $defaults;
}
/**
* Build the form object.
*/
public function buildQuickForm() {
parent::buildQuickForm();
$this->setPageTitle(ts('%1 Option', array(1 => $this->_gLabel)));
if ($this->_action & CRM_Core_Action::DELETE) {
return;
}
$this->applyFilter('__ALL__', 'trim');
$isReserved = FALSE;
if ($this->_id) {
$isReserved = (bool) CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'is_reserved');
}
$this->add('text',
'label',
ts('Label'),
CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'label'),
TRUE
);
if ($this->_gName != 'activity_type') {
$this->add('text',
'value',
ts('Value'),
CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'value'),
TRUE
);
$this->addRule('value',
ts('This Value already exists in the database for this option group. Please select a different Value.'),
'optionExists',
array('CRM_Core_DAO_OptionValue', $this->_id, $this->_gid, 'value', $this->_domainSpecific)
);
}
else {
$this->add('text', 'icon', ts('Icon'), array('class' => 'crm-icon-picker', 'title' => ts('Choose Icon'), 'allowClear' => TRUE));
}
if (in_array($this->_gName, array('activity_status', 'case_status'))) {
$this->add('color', 'color', ts('Color'));
}
if (!in_array($this->_gName, array(
'email_greeting',
'postal_greeting',
'addressee',
)) && !$isReserved
) {
$this->addRule('label',
ts('This Label already exists in the database for this option group. Please select a different Label.'),
'optionExists',
array('CRM_Core_DAO_OptionValue', $this->_id, $this->_gid, 'label', $this->_domainSpecific)
);
}
if ($this->_gName == 'case_status') {
$classes = array(
'Opened' => ts('Opened'),
'Closed' => ts('Closed'),
);
$grouping = $this->add('select',
'grouping',
ts('Status Class'),
$classes
);
if ($isReserved) {
$grouping->freeze();
}
}
// CRM-11516
if ($this->_gName == 'payment_instrument') {
$accountType = CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name = 'Asset' ");
$financialAccount = CRM_Contribute_PseudoConstant::financialAccount(NULL, key($accountType));
$this->add('select', 'financial_account_id', ts('Financial Account'),
array('' => ts('- select -')) + $financialAccount,
TRUE
);
}
if ($this->_gName == 'activity_status') {
$this->add('select',
'filter',
ts('Status Type'),
array(
CRM_Activity_BAO_Activity::INCOMPLETE => ts('Incomplete'),
CRM_Activity_BAO_Activity::COMPLETED => ts('Completed'),
CRM_Activity_BAO_Activity::CANCELLED => ts('Cancelled'),
)
);
}
if ($this->_gName == 'redaction_rule') {
$this->add('checkbox',
'filter',
ts('Regular Expression?')
);
}
if ($this->_gName == 'participant_listing') {
$this->add('text',
'description',
ts('Description'),
CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'description')
);
}
else {
// Hard-coding attributes here since description is still stored as varchar and not text in the schema. dgg
$this->add('wysiwyg', 'description',
ts('Description'),
array('rows' => 4, 'cols' => 80),
$this->_gName == 'custom_search'
);
}
if ($this->_gName == 'event_badge') {
$this->add('text',
'name',
ts('Class Name'),
CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'name')
);
}
$this->add('text',
'weight',
ts('Order'),
CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'weight'),
TRUE
);
$this->addRule('weight', ts('is a numeric field'), 'numeric');
// If CiviCase enabled AND "Add" mode OR "edit" mode for non-reserved activities, only allow user to pick Core or CiviCase component.
// FIXME: Each component should define whether adding new activity types is allowed.
$config = CRM_Core_Config::singleton();
if ($this->_gName == 'activity_type' && in_array("CiviCase", $config->enableComponents) &&
(($this->_action & CRM_Core_Action::ADD) || !$isReserved)
) {
$caseID = CRM_Core_Component::getComponentID('CiviCase');
$components = array('' => ts('Contacts AND Cases'), $caseID => ts('Cases Only'));
$this->add('select',
'component_id',
ts('Component'),
$components, FALSE
);
}
$enabled = $this->add('checkbox', 'is_active', ts('Enabled?'));
if ($isReserved) {
$enabled->freeze();
}
//fix for CRM-3552, CRM-4575
$showIsDefaultGroups = array(
'email_greeting',
'postal_greeting',
'addressee',
'from_email_address',
'case_status',
'encounter_medium',
'case_type',
'payment_instrument',
'communication_style',
'soft_credit_type',
'website_type',
);
if (in_array($this->_gName, $showIsDefaultGroups)) {
$this->assign('showDefault', TRUE);
$this->add('checkbox', 'is_default', ts('Default Option?'));
}
//get contact type for which user want to create a new greeting/addressee type, CRM-4575
if (in_array($this->_gName, array(
'email_greeting',
'postal_greeting',
'addressee',
)) && !$isReserved
) {
$values = array(
1 => ts('Individual'),
2 => ts('Household'),
3 => ts('Organization'),
4 => ts('Multiple Contact Merge'),
);
$this->add('select', 'contactOptions', ts('Contact Type'), array('' => '-select-') + $values, TRUE);
$this->assign('showContactFilter', TRUE);
}
if ($this->_gName == 'participant_status') {
// For Participant Status options, expose the 'filter' field to track which statuses are "Counted", and the Visibility field
$element = $this->add('checkbox', 'filter', ts('Counted?'));
$this->add('select', 'visibility_id', ts('Visibility'), CRM_Core_PseudoConstant::visibility());
}
if ($this->_gName == 'participant_role') {
// For Participant Role options, expose the 'filter' field to track which statuses are "Counted"
$this->add('checkbox', 'filter', ts('Counted?'));
}
$this->addFormRule(array('CRM_Admin_Form_Options', 'formRule'), $this);
}
/**
* 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 array
* array of errors / empty array.
*/
public static function formRule($fields, $files, $self) {
$errors = array();
if ($self->_gName == 'case_status' && empty($fields['grouping'])) {
$errors['grouping'] = ts('Status class is a required field');
}
if (in_array($self->_gName, array(
'email_greeting',
'postal_greeting',
'addressee',
)) && empty($self->_defaultValues['is_reserved'])
) {
$label = $fields['label'];
$condition = " AND v.label = '{$label}' ";
$values = CRM_Core_OptionGroup::values($self->_gName, FALSE, FALSE, FALSE, $condition, 'filter');
$checkContactOptions = TRUE;
if ($self->_id && ($self->_defaultValues['contactOptions'] == $fields['contactOptions'])) {
$checkContactOptions = FALSE;
}
if ($checkContactOptions && in_array($fields['contactOptions'], $values)) {
$errors['label'] = ts('This Label already exists in the database for the selected contact type.');
}
}
if ($self->_gName == 'from_email_address') {
$formEmail = CRM_Utils_Mail::pluckEmailFromHeader($fields['label']);
if (!CRM_Utils_Rule::email($formEmail)) {
$errors['label'] = ts('Please enter a valid email address.');
}
$formName = explode('"', $fields['label']);
if (empty($formName[1]) || count($formName) != 3) {
$errors['label'] = ts('Please follow the proper format for From Email Address');
}
}
$dataType = self::getOptionGroupDataType($self->_gName);
if ($dataType && $self->_gName !== 'activity_type') {
$validate = CRM_Utils_Type::validate($fields['value'], $dataType, FALSE);
if (!$validate) {
CRM_Core_Session::setStatus(
ts('Data Type of the value field for this option value does not match ' . $dataType),
ts('Value field Data Type mismatch'));
}
}
return $errors;
}
/**
* Get the DataType for a specified Option Group.
*
* @param string $optionGroupName name of the option group
*
* @return string|null
*/
public static function getOptionGroupDataType($optionGroupName) {
$optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $optionGroupName, 'id', 'name');
$dataType = CRM_Core_BAO_OptionGroup::getDataType($optionGroupId);
return $dataType;
}
/**
* Process the form submission.
*/
public function postProcess() {
if ($this->_action & CRM_Core_Action::DELETE) {
$fieldValues = array('option_group_id' => $this->_gid);
$wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues);
if (CRM_Core_BAO_OptionValue::del($this->_id)) {
if ($this->_gName == 'phone_type') {
CRM_Core_BAO_Phone::setOptionToNull(CRM_Utils_Array::value('value', $this->_defaultValues));
}
CRM_Core_Session::setStatus(ts('Selected %1 type has been deleted.', array(1 => $this->_gLabel)), ts('Record Deleted'), 'success');
}
else {
CRM_Core_Session::setStatus(ts('Selected %1 type has not been deleted.', array(1 => $this->_gLabel)), ts('Sorry'), 'error');
CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $fieldValues);
}
}
else {
$ids = array();
$params = $this->exportValues();
// allow multiple defaults within group.
$allowMultiDefaults = array('email_greeting', 'postal_greeting', 'addressee', 'from_email_address');
if (in_array($this->_gName, $allowMultiDefaults)) {
if ($this->_gName == 'from_email_address') {
$params['reset_default_for'] = array('domain_id' => CRM_Core_Config::domainID());
}
elseif ($filter = CRM_Utils_Array::value('contactOptions', $params)) {
$params['filter'] = $filter;
$params['reset_default_for'] = array('filter' => "0, " . $params['filter']);
}
//make sure we should has to have space, CRM-6977
if ($this->_gName == 'from_email_address') {
$params['label'] = str_replace('"<', '" <', $params['label']);
}
}
// set value of filter if not present in params
if ($this->_id && !array_key_exists('filter', $params)) {
if ($this->_gName == 'participant_role') {
$params['filter'] = 0;
}
else {
$params['filter'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'filter', 'id');
}
}
if (isset($params['color']) && strtolower($params['color']) == '#ffffff') {
$params['color'] = 'null';
}
$groupParams = array('name' => ($this->_gName));
$optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id);
// CRM-11516
if (!empty($params['financial_account_id'])) {
$relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' "));
$params = array(
'entity_table' => 'civicrm_option_value',
'entity_id' => $optionValue->id,
'account_relationship' => $relationTypeId,
'financial_account_id' => $params['financial_account_id'],
);
CRM_Financial_BAO_FinancialTypeAccount::add($params);
}
CRM_Core_Session::setStatus(ts('The %1 \'%2\' has been saved.', array(
1 => $this->_gLabel,
2 => $optionValue->label,
)), ts('Saved'), 'success');
$this->ajaxResponse['optionValue'] = $optionValue->toArray();
}
}
}

View file

@ -0,0 +1,148 @@
<?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_Admin_Form_ParticipantStatusType extends CRM_Admin_Form {
/**
* Explicitly declare the entity api name.
*/
public function getDefaultEntity() {
return 'ParticipantStatusType';
}
/**
* Build form.
*/
public function buildQuickForm() {
parent::buildQuickForm();
if ($this->_action & CRM_Core_Action::DELETE) {
return;
}
$this->applyFilter('__ALL__', 'trim');
$attributes = CRM_Core_DAO::getAttribute('CRM_Event_DAO_ParticipantStatusType');
$this->add('text', 'name', ts('Name'), NULL, TRUE);
$this->add('text', 'label', ts('Label'), $attributes['label'], TRUE);
$this->addSelect('class', array('required' => TRUE));
$this->add('checkbox', 'is_active', ts('Active?'));
$this->add('checkbox', 'is_counted', ts('Counted?'));
$this->add('text', 'weight', ts('Order'), $attributes['weight'], TRUE);
$this->addSelect('visibility_id', array('label' => ts('Visibility'), 'required' => TRUE));
$this->assign('id', $this->_id);
}
/**
* Set default values.
*
* @return array
*/
public function setDefaultValues() {
$defaults = parent::setDefaultValues();
if (empty($defaults['weight'])) {
$defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Event_DAO_ParticipantStatusType');
}
$this->_isReserved = CRM_Utils_Array::value('is_reserved', $defaults);
if ($this->_isReserved) {
$this->freeze(array('name', 'class', 'is_active'));
}
return $defaults;
}
public function postProcess() {
if ($this->_action & CRM_Core_Action::DELETE) {
if (CRM_Event_BAO_ParticipantStatusType::deleteParticipantStatusType($this->_id)) {
CRM_Core_Session::setStatus(ts('Selected participant status has been deleted.'), ts('Record Deleted'), 'success');
}
else {
CRM_Core_Session::setStatus(ts('Selected participant status has <strong>NOT</strong> been deleted; there are still participants with this status.'), ts('Sorry'), 'error');
}
return;
}
$formValues = $this->controller->exportValues($this->_name);
$params = array(
'name' => CRM_Utils_Array::value('name', $formValues),
'label' => CRM_Utils_Array::value('label', $formValues),
'class' => CRM_Utils_Array::value('class', $formValues),
'is_active' => CRM_Utils_Array::value('is_active', $formValues, FALSE),
'is_counted' => CRM_Utils_Array::value('is_counted', $formValues, FALSE),
'weight' => CRM_Utils_Array::value('weight', $formValues),
'visibility_id' => CRM_Utils_Array::value('visibility_id', $formValues),
);
// make sure a malicious POST does not change these on reserved statuses
if ($this->_isReserved) {
unset($params['name'], $params['class'], $params['is_active']);
}
if ($this->_action & CRM_Core_Action::UPDATE) {
$params['id'] = $this->_id;
}
if ($this->_id) {
$oldWeight = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantStatusType', $this->_id, 'weight', 'id');
}
else {
$oldWeight = 0;
}
$params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Event_DAO_ParticipantStatusType', $oldWeight, $params['weight']);
$participantStatus = CRM_Event_BAO_ParticipantStatusType::create($params);
if ($participantStatus->id) {
if ($this->_action & CRM_Core_Action::UPDATE) {
CRM_Core_Session::setStatus(ts('The Participant Status has been updated.'), ts('Saved'), 'success');
}
else {
CRM_Core_Session::setStatus(ts('The new Participant Status has been saved.'), ts('Saved'), 'success');
}
}
else {
CRM_Core_Session::setStatus(ts('The changes have not been saved.'), ts('Saved'), 'success');
}
}
}

View file

@ -0,0 +1,436 @@
<?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 Payment Processor.
*/
class CRM_Admin_Form_PaymentProcessor extends CRM_Admin_Form {
protected $_id = NULL;
protected $_testID = NULL;
protected $_fields = NULL;
protected $_ppDAO;
/**
* Get the name of the base entity being edited.
*
* @return string
*/
public function getDefaultEntity() {
return 'PaymentProcessor';
}
public function preProcess() {
parent::preProcess();
if ($this->_id) {
$this->_ppType = CRM_Utils_Request::retrieve('pp', 'String', $this, FALSE, NULL);
if (!$this->_ppType) {
$this->_ppType = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessor',
$this->_id,
'payment_processor_type_id'
);
}
$this->set('pp', $this->_ppType);
}
else {
$this->_ppType = CRM_Utils_Request::retrieve('pp', 'String', $this, TRUE, NULL);
}
$this->assign('ppType', $this->_ppType);
$ppTypeName = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessorType',
$this->_ppType,
'name'
);
$this->assign('ppTypeName', $ppTypeName);
$this->_ppDAO = new CRM_Financial_DAO_PaymentProcessorType();
$this->_ppDAO->id = $this->_ppType;
$this->_ppDAO->find(TRUE);
if ($this->_id) {
$refreshURL = CRM_Utils_System::url('civicrm/admin/paymentProcessor',
"reset=1&action=update&id={$this->_id}",
FALSE, NULL, FALSE
);
}
else {
$refreshURL = CRM_Utils_System::url('civicrm/admin/paymentProcessor',
"reset=1&action=add",
FALSE, NULL, FALSE
);
}
//CRM-4129
$destination = CRM_Utils_Request::retrieve('civicrmDestination', 'String', $this);
if ($destination) {
$destination = urlencode($destination);
$refreshURL .= "&civicrmDestination=$destination";
}
$this->assign('refreshURL', $refreshURL);
$this->assign('is_recur', $this->_ppDAO->is_recur);
$this->_fields = array(
array(
'name' => 'user_name',
'label' => $this->_ppDAO->user_name_label,
),
array(
'name' => 'password',
'label' => $this->_ppDAO->password_label,
),
array(
'name' => 'signature',
'label' => $this->_ppDAO->signature_label,
),
array(
'name' => 'subject',
'label' => $this->_ppDAO->subject_label,
),
array(
'name' => 'url_site',
'label' => ts('Site URL'),
'rule' => 'url',
'msg' => ts('Enter a valid URL'),
),
);
if ($this->_ppDAO->is_recur) {
$this->_fields[] = array(
'name' => 'url_recur',
'label' => ts('Recurring Payments URL'),
'rule' => 'url',
'msg' => ts('Enter a valid URL'),
);
}
if (!empty($this->_ppDAO->url_button_default)) {
$this->_fields[] = array(
'name' => 'url_button',
'label' => ts('Button URL'),
'rule' => 'url',
'msg' => ts('Enter a valid URL'),
);
}
if (!empty($this->_ppDAO->url_api_default)) {
$this->_fields[] = array(
'name' => 'url_api',
'label' => ts('API URL'),
'rule' => 'url',
'msg' => ts('Enter a valid URL'),
);
}
}
/**
* Build the form object.
*
* @param bool $check
*/
public function buildQuickForm($check = FALSE) {
parent::buildQuickForm();
if ($this->_action & CRM_Core_Action::DELETE) {
return;
}
$attributes = CRM_Core_DAO::getAttribute('CRM_Financial_DAO_PaymentProcessor');
$this->add('text', 'name', ts('Name'),
$attributes['name'], TRUE
);
$this->addRule('name', ts('Name already exists in Database.'), 'objectExists', array(
'CRM_Financial_DAO_PaymentProcessor',
$this->_id,
'name',
CRM_Core_Config::domainID(),
));
$this->add('text', 'description', ts('Description'),
$attributes['description']
);
$types = CRM_Core_PseudoConstant::paymentProcessorType();
$this->add('select', 'payment_processor_type_id', ts('Payment Processor Type'), $types, TRUE,
array('onchange' => "reload(true)")
);
// Financial Account of account type asset CRM-11515
$accountType = CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name = 'Asset' ");
$financialAccount = CRM_Contribute_PseudoConstant::financialAccount(NULL, key($accountType));
if ($fcount = count($financialAccount)) {
$this->assign('financialAccount', $fcount);
}
$this->add('select', 'financial_account_id', ts('Financial Account'),
array('' => ts('- select -')) + $financialAccount,
TRUE
);
$this->addSelect('payment_instrument_id',
array(
'entity' => 'contribution',
'label' => ts('Payment Method'),
'placeholder' => NULL,
)
);
// is this processor active ?
$this->add('checkbox', 'is_active', ts('Is this Payment Processor active?'));
$this->add('checkbox', 'is_default', ts('Is this Payment Processor the default?'));
$creditCardTypes = CRM_Contribute_PseudoConstant::creditCard();
$this->addCheckBox('accept_credit_cards', ts('Accepted Credit Card Type(s)'),
$creditCardTypes, NULL, NULL, NULL, NULL, '&nbsp;&nbsp;&nbsp;');
foreach ($this->_fields as $field) {
if (empty($field['label'])) {
continue;
}
$this->addField($field['name'], array('label' => $field['label']));
$fieldSpec = civicrm_api3($this->getDefaultEntity(), 'getfield', array(
'name' => $field['name'],
'action' => 'create',
));
$this->add($fieldSpec['values']['html']['type'], "test_{$field['name']}",
$field['label'], $attributes[$field['name']]
);
if (!empty($field['rule'])) {
$this->addRule($field['name'], $field['msg'], $field['rule']);
$this->addRule("test_{$field['name']}", $field['msg'], $field['rule']);
}
}
$this->addFormRule(array('CRM_Admin_Form_PaymentProcessor', 'formRule'));
}
/**
* @param $fields
*
* @return array|bool
*/
public static function formRule($fields) {
// make sure that at least one of live or test is present
// and we have at least name and url_site
// would be good to make this processor specific
$errors = array();
if (!(self::checkSection($fields, $errors) ||
self::checkSection($fields, $errors, 'test')
)
) {
$errors['_qf_default'] = ts('You must have at least the test or live section filled');
}
if (!empty($errors)) {
return $errors;
}
return empty($errors) ? TRUE : $errors;
}
/**
* @param $fields
* @param $errors
* @param null $section
*
* @return bool
*/
public static function checkSection(&$fields, &$errors, $section = NULL) {
$names = array('user_name');
$present = FALSE;
$allPresent = TRUE;
foreach ($names as $name) {
if ($section) {
$name = "{$section}_$name";
}
if (!empty($fields[$name])) {
$present = TRUE;
}
else {
$allPresent = FALSE;
}
}
if ($present) {
if (!$allPresent) {
$errors['_qf_default'] = ts('You must have at least the user_name specified');
}
}
return $present;
}
/**
* @return array
*/
public function setDefaultValues() {
$defaults = array();
if (!$this->_id) {
$defaults['is_active'] = $defaults['is_default'] = 1;
$defaults['url_site'] = $this->_ppDAO->url_site_default;
$defaults['url_api'] = $this->_ppDAO->url_api_default;
$defaults['url_recur'] = $this->_ppDAO->url_recur_default;
$defaults['url_button'] = $this->_ppDAO->url_button_default;
$defaults['test_url_site'] = $this->_ppDAO->url_site_test_default;
$defaults['test_url_api'] = $this->_ppDAO->url_api_test_default;
$defaults['test_url_recur'] = $this->_ppDAO->url_recur_test_default;
$defaults['test_url_button'] = $this->_ppDAO->url_button_test_default;
$defaults['payment_instrument_id'] = $this->_ppDAO->payment_instrument_id;
// When user changes payment processor type, it is passed in via $this->_ppType so update defaults array.
if ($this->_ppType) {
$defaults['payment_processor_type_id'] = $this->_ppType;
}
return $defaults;
}
$domainID = CRM_Core_Config::domainID();
$dao = new CRM_Financial_DAO_PaymentProcessor();
$dao->id = $this->_id;
$dao->domain_id = $domainID;
if (!$dao->find(TRUE)) {
return $defaults;
}
CRM_Core_DAO::storeValues($dao, $defaults);
// When user changes payment processor type, it is passed in via $this->_ppType so update defaults array.
if ($this->_ppType) {
$defaults['payment_processor_type_id'] = $this->_ppType;
}
$cards = json_decode(CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessor',
$this->_id,
'accepted_credit_cards'
), TRUE);
$acceptedCards = array();
if (!empty($cards)) {
foreach ($cards as $card => $val) {
$acceptedCards[$card] = 1;
}
}
$defaults['accept_credit_cards'] = $acceptedCards;
unset($defaults['accepted_credit_cards']);
// now get testID
$testDAO = new CRM_Financial_DAO_PaymentProcessor();
$testDAO->name = $dao->name;
$testDAO->is_test = 1;
$testDAO->domain_id = $domainID;
if ($testDAO->find(TRUE)) {
$this->_testID = $testDAO->id;
foreach ($this->_fields as $field) {
$testName = "test_{$field['name']}";
$defaults[$testName] = $testDAO->{$field['name']};
}
}
$defaults['financial_account_id'] = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($dao->id, NULL, 'civicrm_payment_processor');
return $defaults;
}
/**
* Process the form submission.
*/
public function postProcess() {
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Financial_BAO_PaymentProcessor::del($this->_id);
CRM_Core_Session::setStatus("", ts('Payment Processor Deleted.'), "success");
return NULL;
}
$values = $this->controller->exportValues($this->_name);
$domainID = CRM_Core_Config::domainID();
if (!empty($values['is_default'])) {
$query = "UPDATE civicrm_payment_processor SET is_default = 0 WHERE domain_id = $domainID";
CRM_Core_DAO::executeQuery($query);
}
$this->updatePaymentProcessor($values, $domainID, FALSE);
$this->updatePaymentProcessor($values, $domainID, TRUE);
CRM_Core_Session::setStatus(ts('Payment processor %1 has been saved.', array(1 => "<em>{$values['name']}</em>")), ts('Saved'), 'success');
}
/**
* Save a payment processor.
*
* @param array $values
* @param int $domainID
* @param bool $test
*/
public function updatePaymentProcessor(&$values, $domainID, $test) {
if ($test) {
foreach (array('user_name', 'password', 'signature', 'url_site', 'url_recur', 'url_api', 'url_button', 'subject') as $field) {
$values[$field] = empty($values["test_{$field}"]) ? CRM_Utils_Array::value($field, $values) : $values["test_{$field}"];
}
}
if (!empty($values['accept_credit_cards'])) {
$creditCards = array();
$accptedCards = array_keys($values['accept_credit_cards']);
$creditCardTypes = CRM_Contribute_PseudoConstant::creditCard();
foreach ($creditCardTypes as $type => $val) {
if (in_array($type, $accptedCards)) {
$creditCards[$type] = $creditCardTypes[$type];
}
}
$creditCards = json_encode($creditCards);
}
else {
$creditCards = "NULL";
}
$params = array_merge(array(
'id' => $test ? $this->_testID : $this->_id,
'domain_id' => $domainID,
'is_test' => $test,
'is_active' => 0,
'is_default' => 0,
'is_recur' => $this->_ppDAO->is_recur,
'billing_mode' => $this->_ppDAO->billing_mode,
'class_name' => $this->_ppDAO->class_name,
'payment_type' => $this->_ppDAO->payment_type,
'payment_instrument_id' => $this->_ppDAO->payment_instrument_id,
'financial_account_id' => $values['financial_account_id'],
'accepted_credit_cards' => $creditCards,
), $values);
civicrm_api3('PaymentProcessor', 'create', $params);
}
}

View file

@ -0,0 +1,240 @@
<?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 Location Type.
*/
class CRM_Admin_Form_PaymentProcessorType extends CRM_Admin_Form {
protected $_id = NULL;
protected $_fields = NULL;
public function preProcess() {
parent::preProcess();
$this->_fields = array(
array(
'name' => 'name',
'label' => ts('Name'),
'required' => TRUE,
),
array(
'name' => 'title',
'label' => ts('Title'),
'required' => TRUE,
),
array(
'name' => 'billing_mode',
'label' => ts('Billing Mode'),
'required' => TRUE,
'rule' => 'positiveInteger',
'msg' => ts('Enter a positive integer'),
),
array(
'name' => 'description',
'label' => ts('Description'),
),
array(
'name' => 'user_name_label',
'label' => ts('User Name Label'),
),
array(
'name' => 'password_label',
'label' => ts('Password Label'),
),
array(
'name' => 'signature_label',
'label' => ts('Signature Label'),
),
array(
'name' => 'subject_label',
'label' => ts('Subject Label'),
),
array(
'name' => 'class_name',
'label' => ts('PHP class name'),
'required' => TRUE,
),
array(
'name' => 'url_site_default',
'label' => ts('Live Site URL'),
'required' => TRUE,
'rule' => 'url',
'msg' => ts('Enter a valid URL'),
),
array(
'name' => 'url_api_default',
'label' => ts('Live API URL'),
'required' => FALSE,
'rule' => 'url',
'msg' => ts('Enter a valid URL'),
),
array(
'name' => 'url_recur_default',
'label' => ts('Live Recurring Payments URL'),
'required' => TRUE,
'rule' => 'url',
'msg' => ts('Enter a valid URL'),
),
array(
'name' => 'url_button_default',
'label' => ts('Live Button URL'),
'rule' => 'url',
'msg' => ts('Enter a valid URL'),
),
array(
'name' => 'url_site_test_default',
'label' => ts('Test Site URL'),
'required' => TRUE,
'rule' => 'url',
'msg' => ts('Enter a valid URL'),
),
array(
'name' => 'url_api_test_default',
'label' => ts('Test API URL'),
'required' => FALSE,
'rule' => 'url',
'msg' => ts('Enter a valid URL'),
),
array(
'name' => 'url_recur_test_default',
'label' => ts('Test Recurring Payments URL'),
'required' => TRUE,
'rule' => 'url',
'msg' => ts('Enter a valid URL'),
),
array(
'name' => 'url_button_test_default',
'label' => ts('Test Button URL'),
'rule' => 'url',
'msg' => ts('Enter a valid URL'),
),
);
}
/**
* Build the form object.
*
* @param bool $check
*/
public function buildQuickForm($check = FALSE) {
parent::buildQuickForm();
if ($this->_action & CRM_Core_Action::DELETE) {
return;
}
$attributes = CRM_Core_DAO::getAttribute('CRM_Financial_DAO_PaymentProcessorType');
foreach ($this->_fields as $field) {
$required = CRM_Utils_Array::value('required', $field, FALSE);
$this->add('text', $field['name'],
$field['label'], $attributes['name'], $required
);
if (!empty($field['rule'])) {
$this->addRule($field['name'], $field['msg'], $field['rule']);
}
}
// is this processor active ?
$this->add('checkbox', 'is_active', ts('Is this Payment Processor Type active?'));
$this->add('checkbox', 'is_default', ts('Is this Payment Processor Type the default?'));
$this->add('checkbox', 'is_recur', ts('Does this Payment Processor Type support recurring donations?'));
}
/**
* @return array
*/
public function setDefaultValues() {
$defaults = array();
if (!$this->_id) {
$defaults['is_active'] = $defaults['is_default'] = 1;
$defaults['user_name_label'] = ts('User Name');
$defaults['password_label'] = ts('Password');
$defaults['signature_label'] = ts('Signature');
$defaults['subject_label'] = ts('Subject');
return $defaults;
}
$dao = new CRM_Financial_DAO_PaymentProcessorType();
$dao->id = $this->_id;
if (!$dao->find(TRUE)) {
return $defaults;
}
CRM_Core_DAO::storeValues($dao, $defaults);
return $defaults;
}
/**
* Process the form submission.
*/
public function postProcess() {
CRM_Utils_System::flushCache('CRM_Financial_DAO_PaymentProcessorType');
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Financial_BAO_PaymentProcessorType::del($this->_id);
return;
}
$values = $this->controller->exportValues($this->_name);
if (!empty($values['is_default'])) {
$query = "
UPDATE civicrm_payment_processor SET is_default = 0";
CRM_Core_DAO::executeQuery($query);
}
$dao = new CRM_Financial_DAO_PaymentProcessorType();
$dao->id = $this->_id;
$dao->is_default = CRM_Utils_Array::value('is_default', $values, 0);
$dao->is_active = CRM_Utils_Array::value('is_active', $values, 0);
$dao->is_recur = CRM_Utils_Array::value('is_recur', $values, 0);
$dao->name = $values['name'];
$dao->description = $values['description'];
foreach ($this->_fields as $field) {
$dao->{$field['name']} = trim($values[$field['name']]);
if (empty($dao->{$field['name']})) {
$dao->{$field['name']} = 'null';
}
}
$dao->save();
}
}

View file

@ -0,0 +1,129 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright (C) 2011 Marty Wright |
| Licensed to CiviCRM under the Academic Free License version 3.0. |
+--------------------------------------------------------------------+
| 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 PDF Page Format Settings.
*/
class CRM_Admin_Form_PdfFormats extends CRM_Admin_Form {
/**
* PDF Page Format ID.
*/
protected $_id = NULL;
/**
* Build the form object.
*/
public function buildQuickForm() {
parent::buildQuickForm();
if ($this->_action & CRM_Core_Action::DELETE) {
$formatName = CRM_Core_BAO_PdfFormat::getFieldValue('CRM_Core_BAO_PdfFormat', $this->_id, 'name');
$this->assign('formatName', $formatName);
return;
}
$attributes = CRM_Core_DAO::getAttribute('CRM_Core_BAO_PdfFormat');
$this->add('text', 'name', ts('Name'), $attributes['name'], TRUE);
$this->add('text', 'description', ts('Description'), array('size' => CRM_Utils_Type::HUGE));
$this->add('checkbox', 'is_default', ts('Is this PDF Page Format the default?'));
$this->add('select', 'paper_size', ts('Paper Size'),
array(
0 => ts('- default -'),
) + CRM_Core_BAO_PaperSize::getList(TRUE), FALSE,
array('onChange' => "selectPaper( this.value );")
);
$this->add('static', 'paper_dimensions', NULL, ts('Width x Height'));
$this->add('select', 'orientation', ts('Orientation'), CRM_Core_BAO_PdfFormat::getPageOrientations(), FALSE,
array('onChange' => "updatePaperDimensions();")
);
$this->add('select', 'metric', ts('Unit of Measure'), CRM_Core_BAO_PdfFormat::getUnits(), FALSE,
array('onChange' => "selectMetric( this.value );")
);
$this->add('text', 'margin_left', ts('Left Margin'), array('size' => 8, 'maxlength' => 8), TRUE);
$this->add('text', 'margin_right', ts('Right Margin'), array('size' => 8, 'maxlength' => 8), TRUE);
$this->add('text', 'margin_top', ts('Top Margin'), array('size' => 8, 'maxlength' => 8), TRUE);
$this->add('text', 'margin_bottom', ts('Bottom Margin'), array('size' => 8, 'maxlength' => 8), TRUE);
$this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Core_BAO_PdfFormat', 'weight'), TRUE);
$this->addRule('name', ts('Name already exists in Database.'), 'objectExists', array(
'CRM_Core_BAO_PdfFormat',
$this->_id,
));
$this->addRule('margin_left', ts('Margin must be numeric'), 'numeric');
$this->addRule('margin_right', ts('Margin must be numeric'), 'numeric');
$this->addRule('margin_top', ts('Margin must be numeric'), 'numeric');
$this->addRule('margin_bottom', ts('Margin must be numeric'), 'numeric');
$this->addRule('weight', ts('Weight must be integer'), 'integer');
}
/**
* @return int
*/
public function setDefaultValues() {
if ($this->_action & CRM_Core_Action::ADD) {
$defaults['weight'] = CRM_Utils_Array::value('weight', CRM_Core_BAO_PdfFormat::getDefaultValues(), 0);
}
else {
$defaults = $this->_values;
}
return $defaults;
}
/**
* Process the form submission.
*/
public function postProcess() {
if ($this->_action & CRM_Core_Action::DELETE) {
// delete PDF Page Format
CRM_Core_BAO_PdfFormat::del($this->_id);
CRM_Core_Session::setStatus(ts('Selected PDF Page Format has been deleted.'), ts('Record Deleted'), 'success');
return;
}
$values = $this->controller->exportValues($this->getName());
$values['is_default'] = isset($values['is_default']);
$bao = new CRM_Core_BAO_PdfFormat();
$bao->savePdfFormat($values, $this->_id);
$status = ts('Your new PDF Page Format titled <strong>%1</strong> has been saved.', array(1 => $values['name']), ts('Saved'), 'success');
if ($this->_action & CRM_Core_Action::UPDATE) {
$status = ts('Your PDF Page Format titled <strong>%1</strong> has been updated.', array(1 => $values['name']), ts('Saved'), 'success');
}
CRM_Core_Session::setStatus($status);
}
}

View file

@ -0,0 +1,107 @@
<?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
*/
/**
* Customize the output to meet our specific requirements.
*/
class CRM_Admin_Form_Persistent extends CRM_Core_Form {
/**
* Pre-process form.
*/
public function preProcess() {
$this->_indexID = CRM_Utils_Request::retrieve('id', 'Integer', $this, FALSE);
$this->_config = CRM_Utils_Request::retrieve('config', 'Integer', $this, 0);
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE);
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin/tplstrings', 'reset=1'));
CRM_Utils_System::setTitle(ts('DB Template Strings'));
parent::preProcess();
}
/**
* Set default values.
*
* @return array
*/
public function setDefaultValues() {
$defaults = array();
if ($this->_indexID && ($this->_action & (CRM_Core_Action::UPDATE))) {
$params = array('id' => $this->_indexID);
CRM_Core_BAO_Persistent::retrieve($params, $defaults);
if (CRM_Utils_Array::value('is_config', $defaults) == 1) {
$defaults['data'] = implode(',', $defaults['data']);
}
}
return $defaults;
}
public function buildQuickForm() {
$this->add('text', 'context', ts('Context:'), NULL, TRUE);
$this->add('text', 'name', ts('Name:'), NULL, TRUE);
$this->add('textarea', 'data', ts('Data:'), array('rows' => 4, 'cols' => 50), TRUE);
$this->addButtons(array(
array(
'type' => 'submit',
'name' => ts('Save'),
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
)
);
}
public function postProcess() {
$params = $ids = array();
$params = $this->controller->exportValues($this->_name);
$params['is_config'] = $this->_config;
if ($this->_action & CRM_Core_Action::ADD) {
CRM_Core_Session::setStatus(ts('DB Template has been added successfully.'), ts("Saved"), "success");
}
if ($this->_action & CRM_Core_Action::UPDATE) {
$ids['persistent'] = $this->_indexID;
CRM_Core_Session::setStatus(ts('DB Template has been updated successfully.'), ts("Saved"), "success");
}
CRM_Core_BAO_Persistent::add($params, $ids);
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/tplstrings', "reset=1"));
}
}

View file

@ -0,0 +1,305 @@
<?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
*/
/**
* Base class for settings forms.
*/
class CRM_Admin_Form_Preferences extends CRM_Core_Form {
protected $_system = FALSE;
protected $_contactID = NULL;
public $_action = NULL;
protected $_checkbox = NULL;
protected $_varNames = NULL;
protected $_config = NULL;
protected $_params = NULL;
public function preProcess() {
$this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive',
$this, FALSE
);
$this->_system = CRM_Utils_Request::retrieve('system', 'Boolean',
$this, FALSE, TRUE
);
$this->_action = CRM_Utils_Request::retrieve('action', 'String',
$this, FALSE, 'update'
);
if (isset($action)) {
$this->assign('action', $action);
}
$session = CRM_Core_Session::singleton();
$this->_config = new CRM_Core_DAO();
if ($this->_system) {
if (CRM_Core_Permission::check('administer CiviCRM')) {
$this->_contactID = NULL;
}
else {
CRM_Utils_System::fatal('You do not have permission to edit preferences');
}
$this->_config->contact_id = NULL;
}
else {
if (!$this->_contactID) {
$this->_contactID = $session->get('userID');
if (!$this->_contactID) {
CRM_Utils_System::fatal('Could not retrieve contact id');
}
$this->set('cid', $this->_contactID);
}
$this->_config->contact_id = $this->_contactID;
}
$settings = Civi::settings();
foreach ($this->_varNames as $groupName => $settingNames) {
foreach ($settingNames as $settingName => $options) {
$this->_config->$settingName = $settings->get($settingName);
}
}
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin', 'reset=1'));
}
/**
* @return array
*/
public function setDefaultValues() {
$defaults = array();
foreach ($this->_varNames as $groupName => $settings) {
foreach ($settings as $settingName => $settingDetails) {
$defaults[$settingName] = isset($this->_config->$settingName) ? $this->_config->$settingName : CRM_Utils_Array::value('default', $settingDetails, NULL);
}
}
return $defaults;
}
/**
* @param $defaults
*/
public function cbsDefaultValues(&$defaults) {
foreach ($this->_varNames as $groupName => $groupValues) {
foreach ($groupValues as $settingName => $fieldValue) {
if ($fieldValue['html_type'] == 'checkboxes') {
if (isset($this->_config->$settingName) &&
$this->_config->$settingName
) {
$value = explode(CRM_Core_DAO::VALUE_SEPARATOR,
substr($this->_config->$settingName, 1, -1)
);
if (!empty($value)) {
$defaults[$settingName] = array();
foreach ($value as $n => $v) {
$defaults[$settingName][$v] = 1;
}
}
}
}
}
}
}
/**
* Build the form object.
*/
public function buildQuickForm() {
parent::buildQuickForm();
if (!empty($this->_varNames)) {
foreach ($this->_varNames as $groupName => $groupValues) {
$formName = CRM_Utils_String::titleToVar($groupName);
$this->assign('formName', $formName);
$fields = array();
foreach ($groupValues as $fieldName => $fieldValue) {
$fields[$fieldName] = $fieldValue;
switch ($fieldValue['html_type']) {
case 'text':
$this->addElement('text',
$fieldName,
$fieldValue['title'],
array(
'maxlength' => 64,
'size' => 32,
)
);
break;
case 'textarea':
case 'checkbox':
$this->add($fieldValue['html_type'],
$fieldName,
$fieldValue['title']
);
break;
case 'radio':
$options = CRM_Core_OptionGroup::values($fieldName, FALSE, FALSE, TRUE);
$this->addRadio($fieldName, $fieldValue['title'], $options, NULL, '&nbsp;&nbsp;');
break;
case 'YesNo':
$this->addRadio($fieldName, $fieldValue['title'], array(0 => 'No', 1 => 'Yes'), NULL, '&nbsp;&nbsp;');
break;
case 'checkboxes':
$options = array_flip(CRM_Core_OptionGroup::values($fieldName, FALSE, FALSE, TRUE));
$newOptions = array();
foreach ($options as $key => $val) {
$newOptions[$key] = $val;
}
$this->addCheckBox($fieldName,
$fieldValue['title'],
$newOptions,
NULL, NULL, NULL, NULL,
array('&nbsp;&nbsp;', '&nbsp;&nbsp;', '<br/>')
);
break;
case 'select':
$this->addElement('select',
$fieldName,
$fieldValue['title'],
$fieldValue['option_values']
);
break;
case 'wysiwyg':
$this->add('wysiwyg', $fieldName, $fieldValue['title'], $fieldValue['attributes']);
break;
case 'entity_reference':
$this->addEntityRef($fieldName, $fieldValue['title'], CRM_Utils_Array::value('options', $fieldValue, array()));
}
}
$fields = CRM_Utils_Array::crmArraySortByField($fields, 'weight');
$this->assign('fields', $fields);
}
}
$this->addButtons(array(
array(
'type' => 'next',
'name' => ts('Save'),
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
)
);
if ($this->_action == CRM_Core_Action::VIEW) {
$this->freeze();
}
}
/**
* Process the form submission.
*/
public function postProcess() {
$config = CRM_Core_Config::singleton();
if ($this->_action == CRM_Core_Action::VIEW) {
return;
}
$this->_params = $this->controller->exportValues($this->_name);
$this->postProcessCommon();
}
/**
* Process the form submission.
*/
public function postProcessCommon() {
foreach ($this->_varNames as $groupName => $groupValues) {
foreach ($groupValues as $settingName => $fieldValue) {
switch ($fieldValue['html_type']) {
case 'checkboxes':
if (!empty($this->_params[$settingName]) &&
is_array($this->_params[$settingName])
) {
$this->_config->$settingName = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR,
array_keys($this->_params[$settingName])
) . CRM_Core_DAO::VALUE_SEPARATOR;
}
else {
$this->_config->$settingName = NULL;
}
break;
case 'checkbox':
$this->_config->$settingName = !empty($this->_params[$settingName]) ? 1 : 0;
break;
case 'text':
case 'select':
case 'radio':
case 'YesNo':
case 'entity_reference':
$this->_config->$settingName = CRM_Utils_Array::value($settingName, $this->_params);
break;
case 'textarea':
$value = CRM_Utils_Array::value($settingName, $this->_params);
if ($value) {
$value = trim($value);
$value = str_replace(array("\r\n", "\r"), "\n", $value);
}
$this->_config->$settingName = $value;
break;
}
}
}
foreach ($this->_varNames as $groupName => $groupValues) {
foreach ($groupValues as $settingName => $fieldValue) {
$settingValue = isset($this->_config->$settingName) ? $this->_config->$settingName : NULL;
Civi::settings()->set($settingName, $settingValue);
}
}
// Update any settings stored in dynamic js
CRM_Core_Resources::singleton()->resetCacheCode();
CRM_Core_Session::setStatus(ts('Your changes have been saved.'), ts('Saved'), 'success');
}
}

View file

@ -0,0 +1,192 @@
<?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 Address Section.
*/
class CRM_Admin_Form_Preferences_Address extends CRM_Admin_Form_Preferences {
public function preProcess() {
CRM_Utils_System::setTitle(ts('Settings - Addresses'));
// Address Standardization
$addrProviders = array(
'' => '- select -',
) + CRM_Core_SelectValues::addressProvider();
$this->_varNames = array(
CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME => array(
'address_options' => array(
'html_type' => 'checkboxes',
'title' => ts('Address Fields'),
'weight' => 1,
),
'address_format' => array(
'html_type' => 'textarea',
'title' => ts('Display Format'),
'description' => NULL,
'weight' => 2,
),
'mailing_format' => array(
'html_type' => 'textarea',
'title' => ts('Mailing Label Format'),
'description' => NULL,
'weight' => 3,
),
'hideCountryMailingLabels' => array(
'html_type' => 'YesNo',
'title' => ts('Hide Country in Mailing Labels when same as domain country'),
'weight' => 4,
),
),
CRM_Core_BAO_Setting::ADDRESS_STANDARDIZATION_PREFERENCES_NAME => array(
'address_standardization_provider' => array(
'html_type' => 'select',
'title' => ts('Provider'),
'option_values' => $addrProviders,
'weight' => 5,
),
'address_standardization_userid' => array(
'html_type' => 'text',
'title' => ts('User ID'),
'description' => NULL,
'weight' => 6,
),
'address_standardization_url' => array(
'html_type' => 'text',
'title' => ts('Web Service URL'),
'description' => NULL,
'weight' => 7,
),
),
);
parent::preProcess();
}
/**
* @return array
*/
public function setDefaultValues() {
$defaults = array();
$defaults['address_standardization_provider'] = $this->_config->address_standardization_provider;
$defaults['address_standardization_userid'] = $this->_config->address_standardization_userid;
$defaults['address_standardization_url'] = $this->_config->address_standardization_url;
$this->addressSequence = isset($newSequence) ? $newSequence : "";
$defaults['address_format'] = $this->_config->address_format;
$defaults['mailing_format'] = $this->_config->mailing_format;
$defaults['hideCountryMailingLabels'] = $this->_config->hideCountryMailingLabels;
parent::cbsDefaultValues($defaults);
return $defaults;
}
/**
* Build the form object.
*/
public function buildQuickForm() {
$this->applyFilter('__ALL__', 'trim');
$this->addFormRule(array('CRM_Admin_Form_Preferences_Address', 'formRule'));
//get the tokens for Mailing Label field
$tokens = CRM_Core_SelectValues::contactTokens();
$this->assign('tokens', CRM_Utils_Token::formatTokensForDisplay($tokens));
parent::buildQuickForm();
}
/**
* @param $fields
*
* @return bool
*/
public static function formRule($fields) {
$p = $fields['address_standardization_provider'];
$u = $fields['address_standardization_userid'];
$w = $fields['address_standardization_url'];
// make sure that there is a value for all of them
// if any of them are set
if ($p || $u || $w) {
if (!CRM_Utils_System::checkPHPVersion(5, FALSE)) {
$errors['_qf_default'] = ts('Address Standardization features require PHP version 5 or greater.');
return $errors;
}
if (!($p && $u && $w)) {
$errors['_qf_default'] = ts('You must provide values for all three Address Standarization fields.');
return $errors;
}
}
return TRUE;
}
/**
* Process the form submission.
*/
public function postProcess() {
if ($this->_action == CRM_Core_Action::VIEW) {
return;
}
$this->_params = $this->controller->exportValues($this->_name);
// check if county option has been set
$options = CRM_Core_OptionGroup::values('address_options', FALSE, FALSE, TRUE);
foreach ($options as $key => $title) {
if ($title == ts('County')) {
// check if the $key is present in $this->_params
if (isset($this->_params['address_options']) &&
!empty($this->_params['address_options'][$key])
) {
// print a status message to the user if county table seems small
$countyCount = CRM_Core_DAO::singleValueQuery("SELECT count(*) FROM civicrm_county");
if ($countyCount < 10) {
CRM_Core_Session::setStatus(ts('You have enabled the County option. Please ensure you populate the county table in your CiviCRM Database. You can find extensions to populate counties in the <a %1>CiviCRM Extensions Directory</a>.', array(1 => 'href="' . CRM_Utils_System::url('civicrm/admin/extensions', array('reset' => 1), TRUE, 'extensions-addnew') . '"')),
ts('Populate counties'),
"info"
);
}
}
}
}
$this->postProcessCommon();
}
}

View file

@ -0,0 +1,63 @@
<?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: Display.php 36505 2011-10-03 14:19:56Z lobo $
*
*/
/**
* This class generates form components for the display preferences
*
*/
class CRM_Admin_Form_Preferences_Campaign extends CRM_Admin_Form_Preferences {
public function preProcess() {
CRM_Utils_System::setTitle(ts('CiviCampaign Component Settings'));
$this->_varNames = array(
CRM_Core_BAO_Setting::CAMPAIGN_PREFERENCES_NAME => array(
'tag_unconfirmed' => array(
'html_type' => 'text',
'title' => ts('Tag for Unconfirmed Petition Signers'),
'weight' => 1,
'description' => ts('If set, new contacts that are created when signing a petition are assigned a tag of this name.'),
),
'petition_contacts' => array(
'html_type' => 'text',
'title' => ts('Petition Signers Group'),
'weight' => 2,
'description' => ts('All contacts that have signed a CiviCampaign petition will be added to this group. The group will be created if it does not exist (it is required for email verification).'),
),
),
);
parent::preProcess();
}
}

View file

@ -0,0 +1,233 @@
<?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 the display preferences.
*/
class CRM_Admin_Form_Preferences_Contribute extends CRM_Admin_Form_Preferences {
protected $_settings = array(
'cvv_backoffice_required' => CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME,
'update_contribution_on_membership_type_change' => CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME,
'acl_financial_type' => CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME,
'always_post_to_accounts_receivable' => CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME,
'deferred_revenue_enabled' => CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME,
'default_invoice_page' => CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME,
'invoicing' => CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME,
);
/**
* Process the form submission.
*/
public function preProcess() {
$config = CRM_Core_Config::singleton();
CRM_Utils_System::setTitle(ts('CiviContribute Component Settings'));
$this->_varNames = array(
CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME => array(
'invoice_prefix' => array(
'html_type' => 'text',
'title' => ts('Invoice Prefix'),
'weight' => 1,
'description' => ts('Enter prefix to be display on PDF for invoice'),
),
'credit_notes_prefix' => array(
'html_type' => 'text',
'title' => ts('Credit Notes Prefix'),
'weight' => 2,
'description' => ts('Enter prefix to be display on PDF for credit notes.'),
),
'due_date' => array(
'html_type' => 'text',
'title' => ts('Due Date'),
'weight' => 3,
),
'due_date_period' => array(
'html_type' => 'select',
'title' => ts('For transmission'),
'weight' => 4,
'description' => ts('Select the interval for due date.'),
'option_values' => array(
'select' => ts('- select -'),
'days' => ts('Days'),
'months' => ts('Months'),
'years' => ts('Years'),
),
),
'notes' => array(
'html_type' => 'wysiwyg',
'title' => ts('Notes or Standard Terms'),
'weight' => 5,
'description' => ts('Enter note or message to be displayed on PDF invoice or credit notes '),
'attributes' => array('rows' => 2, 'cols' => 40),
),
'is_email_pdf' => array(
'html_type' => 'checkbox',
'title' => ts('Automatically email invoice when user purchases online'),
'weight' => 6,
),
'tax_term' => array(
'html_type' => 'text',
'title' => ts('Tax Term'),
'weight' => 7,
),
'tax_display_settings' => array(
'html_type' => 'select',
'title' => ts('Tax Display Settings'),
'weight' => 8,
'option_values' => array(
'Do_not_show' => ts('Do not show breakdown, only show total -i.e ' .
$config->defaultCurrencySymbol . '120.00'),
'Inclusive' => ts('Show [tax term] inclusive price - i.e. ' .
$config->defaultCurrencySymbol .
'120.00 (includes [tax term] of ' .
$config->defaultCurrencySymbol . '20.00)'),
'Exclusive' => ts('Show [tax term] exclusive price - i.e. ' .
$config->defaultCurrencySymbol . '100.00 + ' .
$config->defaultCurrencySymbol . '20.00 [tax term]'),
),
),
),
);
parent::preProcess();
}
/**
* Build the form object.
*/
public function buildQuickForm() {
$htmlFields = array();
foreach ($this->_settings as $setting => $group) {
$settingMetaData = civicrm_api3('setting', 'getfields', array('name' => $setting));
$props = $settingMetaData['values'][$setting];
if (isset($props['quick_form_type'])) {
$add = 'add' . $props['quick_form_type'];
if ($add == 'addElement') {
if (in_array($props['html_type'], array('checkbox', 'textarea'))) {
$this->add($props['html_type'],
$setting,
$props['title']
);
}
else {
if ($props['html_type'] == 'select') {
$functionName = CRM_Utils_Array::value('name', CRM_Utils_Array::value('pseudoconstant', $props));
if ($functionName) {
$props['option_values'] = array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::$functionName();
}
}
$this->$add(
$props['html_type'],
$setting,
ts($props['title']),
CRM_Utils_Array::value($props['html_type'] == 'select' ? 'option_values' : 'html_attributes', $props, array()),
$props['html_type'] == 'select' ? CRM_Utils_Array::value('html_attributes', $props) : NULL
);
}
}
elseif ($add == 'addMonthDay') {
$this->add('date', $setting, ts($props['title']), CRM_Core_SelectValues::date(NULL, 'M d'));
}
elseif ($add == 'addDate') {
$this->addDate($setting, ts($props['title']), FALSE, array('formatType' => $props['type']));
}
else {
$this->$add($setting, ts($props['title']));
}
}
$htmlFields[$setting] = ts($props['description']);
}
$this->assign('htmlFields', $htmlFields);
parent::buildQuickForm();
}
/**
* Set default values for the form.
*
* default values are retrieved from the database
*/
public function setDefaultValues() {
$defaults = Civi::settings()->get('contribution_invoice_settings');
//CRM-16691: Changes made related to settings of 'CVV'.
foreach (array('cvv_backoffice_required') as $setting) {
$defaults[$setting] = civicrm_api3('setting', 'getvalue',
array(
'name' => $setting,
'group' => CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME,
)
);
}
return $defaults;
}
/**
* Process the form after the input has been submitted and validated.
*/
public function postProcess() {
// store the submitted values in an array
$params = $this->controller->exportValues($this->_name);
unset($params['qfKey']);
unset($params['entryURL']);
Civi::settings()->set('contribution_invoice_settings', $params);
Civi::settings()->set('update_contribution_on_membership_type_change',
CRM_Utils_Array::value('update_contribution_on_membership_type_change', $params)
);
// to set default value for 'Invoices / Credit Notes' checkbox on display preferences
$values = CRM_Core_BAO_Setting::getItem("CiviCRM Preferences");
$optionValues = CRM_Core_OptionGroup::values('user_dashboard_options', FALSE, FALSE, FALSE, NULL, 'name');
$setKey = array_search('Invoices / Credit Notes', $optionValues);
if (isset($params['invoicing'])) {
$value = array($setKey => $optionValues[$setKey]);
$setInvoice = CRM_Core_DAO::VALUE_SEPARATOR .
implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($value)) .
CRM_Core_DAO::VALUE_SEPARATOR;
Civi::settings()->set('user_dashboard_options', $values['user_dashboard_options'] . $setInvoice);
}
else {
$setting = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($values['user_dashboard_options'], 1, -1));
$invoiceKey = array_search($setKey, $setting);
if ($invoiceKey !== FALSE) {
unset($setting[$invoiceKey]);
}
$settingName = CRM_Core_DAO::VALUE_SEPARATOR .
implode(CRM_Core_DAO::VALUE_SEPARATOR, array_values($setting)) .
CRM_Core_DAO::VALUE_SEPARATOR;
Civi::settings()->set('user_dashboard_options', $settingName);
}
//CRM-16691: Changes made related to settings of 'CVV'.
$settings = array_intersect_key($params, array('cvv_backoffice_required' => 1));
$result = civicrm_api3('setting', 'create', $settings);
CRM_Core_Session::setStatus(ts('Your changes have been saved.'), ts('Changes Saved'), "success");
}
}

View file

@ -0,0 +1,197 @@
<?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 the display preferences.
*/
class CRM_Admin_Form_Preferences_Display extends CRM_Admin_Form_Preferences {
public function preProcess() {
CRM_Utils_System::setTitle(ts('Settings - Display Preferences'));
$this->_varNames = array(
CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME => array(
'contact_view_options' => array(
'html_type' => 'checkboxes',
'title' => ts('Viewing Contacts'),
'weight' => 1,
),
'contact_smart_group_display' => array(
'html_type' => 'radio',
'title' => ts('Viewing Smart Groups'),
'weight' => 2,
),
'contact_edit_options' => array(
'html_type' => 'checkboxes',
'title' => ts('Editing Contacts'),
'weight' => 3,
),
'advanced_search_options' => array(
'html_type' => 'checkboxes',
'title' => ts('Contact Search'),
'weight' => 4,
),
'activity_assignee_notification' => array(
'html_type' => 'checkbox',
'title' => ts('Notify Activity Assignees'),
'weight' => 5,
),
'activity_assignee_notification_ics' => array(
'html_type' => 'checkbox',
'title' => ts('Include ICal Invite to Activity Assignees'),
'weight' => 6,
),
'preserve_activity_tab_filter' => array(
'html_type' => 'checkbox',
'title' => ts('Preserve activity filters as a user preference'),
'weight' => 7,
),
'contact_ajax_check_similar' => array(
'html_type' => 'checkbox',
'title' => ts('Check for Similar Contacts'),
'weight' => 8,
),
'user_dashboard_options' => array(
'html_type' => 'checkboxes',
'title' => ts('Contact Dashboard'),
'weight' => 9,
),
'display_name_format' => array(
'html_type' => 'textarea',
'title' => ts('Individual Display Name Format'),
'weight' => 10,
),
'sort_name_format' => array(
'html_type' => 'textarea',
'title' => ts('Individual Sort Name Format'),
'weight' => 11,
),
'editor_id' => array(
'html_type' => NULL,
'weight' => 12,
),
'ajaxPopupsEnabled' => array(
'html_type' => 'checkbox',
'title' => ts('Enable Popup Forms'),
'weight' => 13,
),
),
);
parent::preProcess();
}
/**
* @return array
*/
public function setDefaultValues() {
$defaults = parent::setDefaultValues();
parent::cbsDefaultValues($defaults);
if ($this->_config->display_name_format) {
$defaults['display_name_format'] = $this->_config->display_name_format;
}
if ($this->_config->sort_name_format) {
$defaults['sort_name_format'] = $this->_config->sort_name_format;
}
return $defaults;
}
/**
* Build the form object.
*/
public function buildQuickForm() {
$wysiwyg_options = CRM_Core_OptionGroup::values('wysiwyg_editor', FALSE, FALSE, FALSE, NULL, 'label', TRUE, FALSE, 'name');
//changes for freezing the invoices/credit notes checkbox if invoicing is uncheck
$invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
$invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
$this->assign('invoicing', $invoicing);
$extra = array();
$this->addElement('select', 'editor_id', ts('WYSIWYG Editor'), $wysiwyg_options, $extra);
$this->addElement('submit', 'ckeditor_config', ts('Configure CKEditor'));
$editOptions = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 0');
$this->assign('editOptions', $editOptions);
$contactBlocks = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 1');
$this->assign('contactBlocks', $contactBlocks);
$nameFields = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 2');
$this->assign('nameFields', $nameFields);
$this->addElement('hidden', 'contact_edit_preferences', NULL, array('id' => 'contact_edit_preferences'));
$optionValues = CRM_Core_OptionGroup::values('user_dashboard_options', FALSE, FALSE, FALSE, NULL, 'name');
$invoicesKey = array_search('Invoices / Credit Notes', $optionValues);
$this->assign('invoicesKey', $invoicesKey);
parent::buildQuickForm();
}
/**
* Process the form submission.
*/
public function postProcess() {
if ($this->_action == CRM_Core_Action::VIEW) {
return;
}
$this->_params = $this->controller->exportValues($this->_name);
if (!empty($this->_params['contact_edit_preferences'])) {
$preferenceWeights = explode(',', $this->_params['contact_edit_preferences']);
foreach ($preferenceWeights as $key => $val) {
if (!$val) {
unset($preferenceWeights[$key]);
}
}
$opGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'contact_edit_options', 'id', 'name');
CRM_Core_BAO_OptionValue::updateOptionWeights($opGroupId, array_flip($preferenceWeights));
}
$this->_config->editor_id = $this->_params['editor_id'];
$this->postProcessCommon();
// If "Configure CKEditor" button was clicked
if (!empty($this->_params['ckeditor_config'])) {
// Suppress the "Saved" status message and redirect to the CKEditor Config page
$session = CRM_Core_Session::singleton();
$session->getStatus(TRUE);
$url = CRM_Utils_System::url('civicrm/admin/ckeditor', 'reset=1');
$session->pushUserContext($url);
}
}
}

View file

@ -0,0 +1,72 @@
<?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: Display.php 36505 2011-10-03 14:19:56Z lobo $
*
*/
/**
* This class generates form components for the display preferences
*
*/
class CRM_Admin_Form_Preferences_Event extends CRM_Admin_Form_Preferences {
public function preProcess() {
CRM_Utils_System::setTitle(ts('CiviEvent Component Settings'));
// pass "wiki" as 6th param to docURL2 if you are linking to a page in wiki.civicrm.org
$docLink = CRM_Utils_System::docURL2("CiviEvent Cart Checkout", NULL, NULL, NULL, NULL, "wiki");
// build an array containing all selectable option values for show_events
$optionValues = array();
for ($i = 10; $i <= 100; $i += 10) {
$optionValues[$i] = $i;
}
$this->_varNames = array(
CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME => array(
'enable_cart' => array(
'html_type' => 'checkbox',
'title' => ts('Use Shopping Cart Style Event Registration'),
'weight' => 1,
'description' => ts('This feature allows users to register for more than one event at a time. When enabled, users will add event(s) to a "cart" and then pay for them all at once. Enabling this setting will affect online registration for all active events. The code is an alpha state, and you will potentially need to have developer resources to debug and fix sections of the codebase while testing and deploying it. %1',
array(1 => $docLink)),
),
'show_events' => array(
'html_type' => 'select',
'title' => ts('Dashboard entries'),
'weight' => 2,
'description' => ts('Configure how many events should be shown on the dashboard. This overrides the default value of 10 entries.'),
'option_values' => array('' => ts('- select -')) + $optionValues + array(-1 => ts('show all')),
),
),
);
parent::preProcess();
}
}

View file

@ -0,0 +1,139 @@
<?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: Display.php 36505 2011-10-03 14:19:56Z lobo $
*
*/
/**
* This class generates form components for the component preferences
*
*/
class CRM_Admin_Form_Preferences_Mailing extends CRM_Admin_Form_Preferences {
public function preProcess() {
CRM_Utils_System::setTitle(ts('CiviMail Component Settings'));
$this->_varNames = array(
CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME => array(
'profile_double_optin' => array(
'html_type' => 'checkbox',
'title' => ts('Enable Double Opt-in for Profile Group(s) field'),
'weight' => 1,
'description' => ts('When CiviMail is enabled, users who "subscribe" to a group from a profile Group(s) checkbox will receive a confirmation email. They must respond (opt-in) before they are added to the group.'),
),
'profile_add_to_group_double_optin' => array(
'html_type' => 'checkbox',
'title' => ts('Enable Double Opt-in for Profiles which use the "Add to Group" setting'),
'weight' => 2,
'description' => ts('When CiviMail is enabled and a profile uses the "Add to Group" setting, users who complete the profile form will receive a confirmation email. They must respond (opt-in) before they are added to the group.'),
),
'track_civimail_replies' => array(
'html_type' => 'checkbox',
'title' => ts('Track replies using VERP in Reply-To header'),
'weight' => 3,
'description' => ts('If checked, mailings will default to tracking replies using VERP-ed Reply-To.'),
),
'civimail_workflow' => array(
'html_type' => 'checkbox',
'title' => ts('Enable workflow support for CiviMail'),
'weight' => 4,
'description' => ts('Drupal-only. Rules module must be enabled (beta feature - use with caution).'),
),
'civimail_multiple_bulk_emails' => array(
'html_type' => 'checkbox',
'title' => ts('Enable multiple bulk email address for a contact.'),
'weight' => 5,
'description' => ts('CiviMail will deliver a copy of the email to each bulk email listed for the contact.'),
),
'civimail_server_wide_lock' => array(
'html_type' => 'checkbox',
'title' => ts('Enable global server wide lock for CiviMail'),
'weight' => 6,
'description' => NULL,
),
'include_message_id' => array(
'html_type' => 'checkbox',
'title' => ts('Enable CiviMail to generate Message-ID header'),
'weight' => 7,
'description' => NULL,
),
'write_activity_record' => array(
'html_type' => 'checkbox',
'title' => ts('Enable CiviMail to create activities on delivery'),
'weight' => 8,
'description' => NULL,
),
'disable_mandatory_tokens_check' => array(
'html_type' => 'checkbox',
'title' => ts('Disable check for mandatory tokens'),
'weight' => 9,
'description' => ts('Don\'t check for presence of mandatory tokens (domain address; unsubscribe/opt-out) before sending mailings. WARNING: Mandatory tokens are a safe-guard which facilitate compliance with the US CAN-SPAM Act. They should only be disabled if your organization adopts other mechanisms for compliance or if your organization is not subject to CAN-SPAM.'),
),
'dedupe_email_default' => array(
'html_type' => 'checkbox',
'title' => ts('CiviMail dedupes e-mail addresses by default'),
'weight' => 10,
'description' => NULL,
),
'hash_mailing_url' => array(
'html_type' => 'checkbox',
'title' => ts('Hashed Mailing URL\'s'),
'weight' => 11,
'description' => 'If enabled, a randomized hash key will be used to reference the mailing URL in the mailing.viewUrl token, instead of the mailing ID',
),
),
);
parent::preProcess();
}
public function postProcess() {
// check if mailing tab is enabled, if not prompt user to enable the tab if "write_activity_record" is disabled
$params = $this->controller->exportValues($this->_name);
if (empty($params['write_activity_record'])) {
$existingViewOptions = Civi::settings()->get('contact_view_options');
$displayValue = CRM_Core_OptionGroup::getValue('contact_view_options', 'CiviMail', 'name');
$viewOptions = explode(CRM_Core_DAO::VALUE_SEPARATOR, $existingViewOptions);
if (!in_array($displayValue, $viewOptions)) {
$existingViewOptions .= $displayValue . CRM_Core_DAO::VALUE_SEPARATOR;
Civi::settings()->set('contact_view_options', $existingViewOptions);
CRM_Core_Session::setStatus(ts('We have automatically enabled the Mailings tab for the Contact Summary screens
so that you can view mailings sent to each contact.'), ts('Saved'), 'success');
}
}
parent::postProcess();
}
}

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
*/
/**
* This class generates form components for component preferences.
*/
class CRM_Admin_Form_Preferences_Member extends CRM_Admin_Form_Preferences {
public function preProcess() {
CRM_Utils_System::setTitle(ts('CiviMember Component Settings'));
$this->_varNames = array(
CRM_Core_BAO_Setting::MEMBER_PREFERENCES_NAME => array(
'default_renewal_contribution_page' => array(
'html_type' => 'select',
'title' => ts('Default online membership renewal page'),
'option_values' => array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage(),
'weight' => 1,
'description' => ts('If you select a default online contribution page for self-service membership renewals, a "renew" link pointing to that page will be displayed on the Contact Dashboard for memberships which were entered offline. You will need to ensure that the membership block for the selected online contribution page includes any currently available memberships.'),
),
),
);
parent::preProcess();
}
/**
* Build the form object.
*/
public function buildQuickForm() {
parent::buildQuickForm();
}
}

View file

@ -0,0 +1,81 @@
<?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: Display.php 36505 2011-10-03 14:19:56Z lobo $
*
*/
/**
* This class generates form components for multi site preferences
*
*/
class CRM_Admin_Form_Preferences_Multisite extends CRM_Admin_Form_Preferences {
public function preProcess() {
$msDoc = CRM_Utils_System::docURL2('Multi Site Installation', NULL, NULL, NULL, NULL, "wiki");
CRM_Utils_System::setTitle(ts('Multi Site Settings'));
$this->_varNames = array(
CRM_Core_BAO_Setting::MULTISITE_PREFERENCES_NAME => array(
'is_enabled' => array(
'html_type' => 'checkbox',
'title' => ts('Enable Multi Site Configuration'),
'weight' => 1,
'description' => ts('Make CiviCRM aware of multiple domains. You should configure a domain group if enabled') . ' ' . $msDoc,
),
/** Remove this checkbox until some one knows what this setting does
* 'uniq_email_per_site' => array(
* 'html_type' => 'checkbox',
* 'title' => ts('Ensure multi sites have a unique email per site'),
* 'weight' => 2,
* 'description' => NULL,
* ),
*/
'domain_group_id' => array(
'html_type' => 'entity_reference',
'title' => ts('Domain Group'),
'weight' => 3,
'options' => array('entity' => 'group', 'select' => array('minimumInputLength' => 0)),
'description' => ts('Contacts created on this site are added to this group'),
),
/** Remove this checkbox until some one knows what this setting does
* 'event_price_set_domain_id' => array(
* 'html_type' => 'text',
* 'title' => ts('Domain for event price sets'),
* 'weight' => 4,
* 'description' => NULL,
* ),
*/
),
);
parent::preProcess();
}
}

View file

@ -0,0 +1,136 @@
<?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 Location Type.
*/
class CRM_Admin_Form_PreferencesDate extends CRM_Admin_Form {
/**
* Build the form object.
*/
public function buildQuickForm() {
parent::buildQuickForm();
if ($this->_action & CRM_Core_Action::DELETE) {
return;
}
$attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_PreferencesDate');
$this->applyFilter('__ALL__', 'trim');
$name = &$this->add('text',
'name',
ts('Name'),
$attributes['name'],
TRUE
);
$name->freeze();
$this->add('text', 'description', ts('Description'), $attributes['description'], FALSE);
$this->add('text', 'start', ts('Start Offset'), $attributes['start'], TRUE);
$this->add('text', 'end', ts('End Offset'), $attributes['end'], TRUE);
$formatType = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_PreferencesDate', $this->_id, 'name');
if ($formatType == 'creditCard') {
$this->add('text', 'date_format', ts('Format'), $attributes['date_format'], TRUE);
}
else {
$this->add('select', 'date_format', ts('Format'),
array('' => ts('- default input format -')) + CRM_Core_SelectValues::getDatePluginInputFormats()
);
$this->add('select', 'time_format', ts('Time'),
array('' => ts('- none -')) + CRM_Core_SelectValues::getTimeFormats()
);
}
$this->addRule('start', ts('Value must be an integer.'), 'integer');
$this->addRule('end', ts('Value must be an integer.'), 'integer');
// add a form rule
$this->addFormRule(array('CRM_Admin_Form_PreferencesDate', 'formRule'));
}
/**
* Global validation rules for the form.
*
* @param array $fields
* Posted values of the form.
*
* @return array
* if errors then list of errors to be posted back to the form,
* true otherwise
*/
public static function formRule($fields) {
$errors = array();
if ($fields['name'] == 'activityDateTime' && !$fields['time_format']) {
$errors['time_format'] = ts('Time is required for this format.');
}
return empty($errors) ? TRUE : $errors;
}
/**
* Process the form submission.
*/
public function postProcess() {
if (!($this->_action & CRM_Core_Action::UPDATE)) {
CRM_Core_Session::setStatus(ts('Preferences Date Options can only be updated'), ts('Sorry'), 'error');
return;
}
// store the submitted values in an array
$params = $this->controller->exportValues($this->_name);
// action is taken depending upon the mode
$dao = new CRM_Core_DAO_PreferencesDate();
$dao->id = $this->_id;
$dao->description = $params['description'];
$dao->start = $params['start'];
$dao->end = $params['end'];
$dao->date_format = $params['date_format'];
$dao->time_format = $params['time_format'];
$dao->save();
// Update dynamic js to reflect new date settings
CRM_Core_Resources::singleton()->resetCacheCode();
CRM_Core_Session::setStatus(ts("The date type '%1' has been saved.",
array(1 => $params['name'])
), ts('Saved'), 'success');
}
}

View file

@ -0,0 +1,173 @@
<?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 Relationship Type.
*/
class CRM_Admin_Form_RelationshipType extends CRM_Admin_Form {
/**
* Build the form object.
*/
public function buildQuickForm() {
parent::buildQuickForm();
$this->setPageTitle(ts('Relationship Type'));
if ($this->_action & CRM_Core_Action::DELETE) {
return;
}
$this->applyFilter('__ALL__', 'trim');
$this->add('text', 'label_a_b', ts('Relationship Label-A to B'),
CRM_Core_DAO::getAttribute('CRM_Contact_DAO_RelationshipType', 'label_a_b'), TRUE
);
$this->addRule('label_a_b', ts('Label already exists in Database.'),
'objectExists', array('CRM_Contact_DAO_RelationshipType', $this->_id, 'label_a_b')
);
$this->add('text', 'label_b_a', ts('Relationship Label-B to A'),
CRM_Core_DAO::getAttribute('CRM_Contact_DAO_RelationshipType', 'label_b_a')
);
$this->addRule('label_b_a', ts('Label already exists in Database.'),
'objectExists', array('CRM_Contact_DAO_RelationshipType', $this->_id, 'label_b_a')
);
$this->add('text', 'description', ts('Description'),
CRM_Core_DAO::getAttribute('CRM_Contact_DAO_RelationshipType', 'description')
);
$contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(FALSE, TRUE, '__');
// add select for contact type
$contactTypeA = &$this->add('select', 'contact_types_a', ts('Contact Type A') . ' ',
array(
'' => ts('All Contacts'),
) + $contactTypes
);
$contactTypeB = &$this->add('select', 'contact_types_b', ts('Contact Type B') . ' ',
array(
'' => ts('All Contacts'),
) + $contactTypes
);
$isActive = &$this->add('checkbox', 'is_active', ts('Enabled?'));
//only selected field should be allow for edit, CRM-4888
if ($this->_id &&
CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $this->_id, 'is_reserved')
) {
foreach (array('contactTypeA', 'contactTypeB', 'isActive') as $field) {
$$field->freeze();
}
}
if ($this->_action & CRM_Core_Action::VIEW) {
$this->freeze();
}
$this->assign('relationship_type_id', $this->_id);
}
/**
* @return array
*/
public function setDefaultValues() {
if ($this->_action != CRM_Core_Action::DELETE &&
isset($this->_id)
) {
$defaults = $params = array();
$params = array('id' => $this->_id);
$baoName = $this->_BAOName;
$baoName::retrieve($params, $defaults);
$defaults['contact_types_a'] = CRM_Utils_Array::value('contact_type_a', $defaults);
if (!empty($defaults['contact_sub_type_a'])) {
$defaults['contact_types_a'] .= '__' . $defaults['contact_sub_type_a'];
}
$defaults['contact_types_b'] = CRM_Utils_Array::value('contact_type_b', $defaults);
if (!empty($defaults['contact_sub_type_b'])) {
$defaults['contact_types_b'] .= '__' . $defaults['contact_sub_type_b'];
}
return $defaults;
}
else {
return parent::setDefaultValues();
}
}
/**
* Process the form submission.
*/
public function postProcess() {
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Contact_BAO_RelationshipType::del($this->_id);
CRM_Core_Session::setStatus(ts('Selected Relationship type has been deleted.'), ts('Record Deleted'), 'success');
}
else {
$ids = array();
// store the submitted values in an array
$params = $this->exportValues();
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
if ($this->_action & CRM_Core_Action::UPDATE) {
$ids['relationshipType'] = $this->_id;
}
$cTypeA = CRM_Utils_System::explode('__',
$params['contact_types_a'],
2
);
$cTypeB = CRM_Utils_System::explode('__',
$params['contact_types_b'],
2
);
$params['contact_type_a'] = $cTypeA[0];
$params['contact_type_b'] = $cTypeB[0];
$params['contact_sub_type_a'] = $cTypeA[1] ? $cTypeA[1] : 'NULL';
$params['contact_sub_type_b'] = $cTypeB[1] ? $cTypeB[1] : 'NULL';
$result = CRM_Contact_BAO_RelationshipType::add($params, $ids);
$this->ajaxResponse['relationshipType'] = $result->toArray();
CRM_Core_Session::setStatus(ts('The Relationship Type has been saved.'), ts('Saved'), 'success');
}
}
}

View file

@ -0,0 +1,685 @@
<?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 Scheduling Reminders.
*/
class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form {
/**
* Scheduled Reminder ID.
*/
protected $_id = NULL;
public $_freqUnits;
/**
* Build the form object.
*/
public function buildQuickForm() {
parent::buildQuickForm();
$this->_mappingID = $mappingID = NULL;
$providersCount = CRM_SMS_BAO_Provider::activeProviderCount();
$this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
//CRM-16777: Don't provide access to administer schedule reminder page, with user that does not have 'administer CiviCRM' permission
if (empty($this->_context) && !CRM_Core_Permission::check('administer CiviCRM')) {
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
}
//CRM-16777: When user have ACLs 'edit' permission for specific event, do not give access to add, delete & updtae
//schedule reminder for other events.
else {
$this->_compId = CRM_Utils_Request::retrieve('compId', 'Integer', $this);
if (!CRM_Event_BAO_Event::checkPermission($this->_compId, CRM_Core_Permission::EDIT)) {
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
}
}
if ($this->_action & (CRM_Core_Action::DELETE)) {
$reminderName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionSchedule', $this->_id, 'title');
if ($this->_context == 'event') {
$this->_compId = CRM_Utils_Request::retrieve('compId', 'Integer', $this);
}
$this->assign('reminderName', $reminderName);
return;
}
elseif ($this->_action & (CRM_Core_Action::UPDATE)) {
$this->_mappingID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionSchedule', $this->_id, 'mapping_id');
if ($this->_context == 'event') {
$this->_compId = CRM_Utils_Request::retrieve('compId', 'Integer', $this);
}
}
elseif (!empty($this->_context)) {
if ($this->_context == 'event') {
$this->_compId = CRM_Utils_Request::retrieve('compId', 'Integer', $this);
$isTemplate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_compId, 'is_template');
$mapping = CRM_Utils_Array::first(CRM_Core_BAO_ActionSchedule::getMappings(array(
'id' => $isTemplate ? CRM_Event_ActionMapping::EVENT_TPL_MAPPING_ID : CRM_Event_ActionMapping::EVENT_NAME_MAPPING_ID,
)));
if ($mapping) {
$this->_mappingID = $mapping->getId();
}
else {
CRM_Core_Error::fatal('Could not find mapping for event scheduled reminders.');
}
}
}
if (!empty($_POST) && !empty($_POST['entity']) && empty($this->_context)) {
$mappingID = $_POST['entity'][0];
}
elseif ($this->_mappingID) {
$mappingID = $this->_mappingID;
if ($this->_context == 'event') {
$this->add('hidden', 'mappingID', $mappingID);
}
}
$this->add(
'text',
'title',
ts('Title'),
CRM_Core_DAO::getAttribute('CRM_Core_DAO_ActionSchedule', 'title'),
TRUE
);
$mappings = CRM_Core_BAO_ActionSchedule::getMappings();
$selectedMapping = $mappings[$mappingID ? $mappingID : 1];
$entityRecipientLabels = $selectedMapping->getRecipientTypes() + CRM_Core_BAO_ActionSchedule::getAdditionalRecipients();
$this->assign('entityMapping', json_encode(
CRM_Utils_Array::collectMethod('getEntity', $mappings)
));
$this->assign('recipientMapping', json_encode(
array_combine(array_keys($entityRecipientLabels), array_keys($entityRecipientLabels))
));
if (empty($this->_context)) {
$sel = &$this->add(
'hierselect',
'entity',
ts('Entity'),
array(
'name' => 'entity[0]',
'style' => 'vertical-align: top;',
)
);
$sel->setOptions(array(
CRM_Utils_Array::collectMethod('getLabel', $mappings),
CRM_Core_BAO_ActionSchedule::getAllEntityValueLabels(),
CRM_Core_BAO_ActionSchedule::getAllEntityStatusLabels(),
));
if (is_a($sel->_elements[1], 'HTML_QuickForm_select')) {
// make second selector a multi-select -
$sel->_elements[1]->setMultiple(TRUE);
$sel->_elements[1]->setSize(5);
}
if (is_a($sel->_elements[2], 'HTML_QuickForm_select')) {
// make third selector a multi-select -
$sel->_elements[2]->setMultiple(TRUE);
$sel->_elements[2]->setSize(5);
}
}
else {
// Dig deeper - this code is sublimely stupid.
$allEntityStatusLabels = CRM_Core_BAO_ActionSchedule::getAllEntityStatusLabels();
$options = $allEntityStatusLabels[$this->_mappingID][0];
$attributes = array('multiple' => 'multiple', 'class' => 'crm-select2 huge', 'placeholder' => $options[0]);
unset($options[0]);
$this->add('select', 'entity', ts('Recipient(s)'), $options, TRUE, $attributes);
$this->assign('context', $this->_context);
}
//get the frequency units.
$this->_freqUnits = CRM_Core_SelectValues::getRecurringFrequencyUnits();
//reminder_interval
$this->add('number', 'start_action_offset', ts('When'), array('class' => 'six', 'min' => 0));
$this->addRule('start_action_offset', ts('Value should be a positive number'), 'positiveInteger');
$isActive = ts('Send email');
$recordActivity = ts('Record activity for automated email');
if ($providersCount) {
$this->assign('sms', $providersCount);
$isActive = ts('Send email or SMS');
$recordActivity = ts('Record activity for automated email or SMS');
$options = CRM_Core_OptionGroup::values('msg_mode');
$this->add('select', 'mode', ts('Send as'), $options);
$providers = CRM_SMS_BAO_Provider::getProviders(NULL, NULL, TRUE, 'is_default desc');
$providerSelect = array();
foreach ($providers as $provider) {
$providerSelect[$provider['id']] = $provider['title'];
}
$this->add('select', 'sms_provider_id', ts('SMS Provider'), $providerSelect, TRUE);
}
foreach ($this->_freqUnits as $val => $label) {
$freqUnitsDisplay[$val] = ts('%1(s)', array(1 => $label));
}
$this->addDate('absolute_date', ts('Start Date'), FALSE, array('formatType' => 'mailing'));
//reminder_frequency
$this->add('select', 'start_action_unit', ts('Frequency'), $freqUnitsDisplay, TRUE);
$condition = array(
'before' => ts('before'),
'after' => ts('after'),
);
//reminder_action
$this->add('select', 'start_action_condition', ts('Action Condition'), $condition);
$this->add('select', 'start_action_date', ts('Date Field'), $selectedMapping->getDateFields(), TRUE);
$this->addElement('checkbox', 'record_activity', $recordActivity);
$this->addElement('checkbox', 'is_repeat', ts('Repeat'),
NULL, array('onchange' => "return showHideByValue('is_repeat',true,'repeatFields','table-row','radio',false);")
);
$this->add('select', 'repetition_frequency_unit', ts('every'), $freqUnitsDisplay);
$this->add('number', 'repetition_frequency_interval', ts('every'), array('class' => 'six', 'min' => 0));
$this->addRule('repetition_frequency_interval', ts('Value should be a positive number'), 'positiveInteger');
$this->add('select', 'end_frequency_unit', ts('until'), $freqUnitsDisplay);
$this->add('number', 'end_frequency_interval', ts('until'), array('class' => 'six', 'min' => 0));
$this->addRule('end_frequency_interval', ts('Value should be a positive number'), 'positiveInteger');
$this->add('select', 'end_action', ts('Repetition Condition'), $condition, TRUE);
$this->add('select', 'end_date', ts('Date Field'), $selectedMapping->getDateFields(), TRUE);
$this->add('text', 'from_name', ts('From Name'));
$this->add('text', 'from_email', ts('From Email'));
$recipientListingOptions = array();
if ($mappingID) {
$mapping = CRM_Utils_Array::first(CRM_Core_BAO_ActionSchedule::getMappings(array(
'id' => $mappingID,
)));
}
$limitOptions = array('' => '-neither-', 1 => ts('Limit to'), 0 => ts('Also include'));
$recipientLabels = array('activity' => ts('Recipients'), 'other' => ts('Limit or Add Recipients'));
$this->assign('recipientLabels', $recipientLabels);
$this->add('select', 'limit_to', ts('Limit Options'), $limitOptions, FALSE, array('onChange' => "showHideByValue('limit_to','','recipient', 'select','select',true);"));
$this->add('select', 'recipient', $recipientLabels['other'], $entityRecipientLabels,
FALSE, array('onchange' => "showHideByValue('recipient','manual','recipientManual','table-row','select',false); showHideByValue('recipient','group','recipientGroup','table-row','select',false);")
);
if (!empty($this->_submitValues['recipient_listing'])) {
if (!empty($this->_context)) {
$recipientListingOptions = CRM_Core_BAO_ActionSchedule::getRecipientListing($this->_mappingID, $this->_submitValues['recipient']);
}
else {
$recipientListingOptions = CRM_Core_BAO_ActionSchedule::getRecipientListing($_POST['entity'][0], $_POST['recipient']);
}
}
elseif (!empty($this->_values['recipient_listing'])) {
$recipientListingOptions = CRM_Core_BAO_ActionSchedule::getRecipientListing($this->_values['mapping_id'], $this->_values['recipient']);
}
$this->add('select', 'recipient_listing', ts('Recipient Roles'), $recipientListingOptions, FALSE,
array('multiple' => TRUE, 'class' => 'crm-select2 huge', 'placeholder' => TRUE));
$this->addEntityRef('recipient_manual_id', ts('Manual Recipients'), array('multiple' => TRUE, 'create' => TRUE));
$this->add('select', 'group_id', ts('Group'),
CRM_Core_PseudoConstant::nestedGroup('Mailing'), FALSE, array('class' => 'crm-select2 huge')
);
// multilingual only options
$multilingual = CRM_Core_I18n::isMultilingual();
if ($multilingual) {
$smarty = CRM_Core_Smarty::singleton();
$smarty->assign('multilingual', $multilingual);
$languages = CRM_Core_I18n::languages(TRUE);
$languageFilter = $languages + array(CRM_Core_I18n::NONE => ts('Contacts with no preferred language'));
$element = $this->add('select', 'filter_contact_language', ts('Recipients language'), $languageFilter, FALSE,
array('multiple' => TRUE, 'class' => 'crm-select2', 'placeholder' => TRUE));
$communicationLanguage = array(
'' => ts('System default language'),
CRM_Core_I18n::AUTO => ts('Follow recipient preferred language'),
);
$communicationLanguage = $communicationLanguage + $languages;
$this->add('select', 'communication_language', ts('Communication language'), $communicationLanguage);
}
CRM_Mailing_BAO_Mailing::commonCompose($this);
$this->add('text', 'subject', ts('Subject'),
CRM_Core_DAO::getAttribute('CRM_Core_DAO_ActionSchedule', 'subject')
);
$this->add('checkbox', 'is_active', $isActive);
$this->addFormRule(array('CRM_Admin_Form_ScheduleReminders', 'formRule'), $this);
$this->setPageTitle(ts('Scheduled Reminder'));
}
/**
* Global form rule.
*
* @param array $fields
* The input form values.
* @param array $files
* @param CRM_Admin_Form_ScheduleReminders $self
*
* @return array|bool
* True if no errors, else array of errors
*/
public static function formRule($fields, $files, $self) {
$errors = array();
if ((array_key_exists(1, $fields['entity']) && $fields['entity'][1][0] === 0) ||
(array_key_exists(2, $fields['entity']) && $fields['entity'][2][0] == 0)
) {
$errors['entity'] = ts('Please select appropriate value');
}
if (!empty($fields['is_active']) &&
CRM_Utils_System::isNull($fields['subject'])
) {
$errors['subject'] = ts('Subject is a required field.');
}
if (!empty($fields['is_active']) &&
CRM_Utils_System::isNull(trim(strip_tags($fields['html_message'])))
) {
$errors['html_message'] = ts('The HTML message is a required field.');
}
if (empty($self->_context) && CRM_Utils_System::isNull(CRM_Utils_Array::value(1, $fields['entity']))) {
$errors['entity'] = ts('Please select entity value');
}
if (!CRM_Utils_System::isNull($fields['absolute_date'])) {
if (CRM_Utils_Date::format(CRM_Utils_Date::processDate($fields['absolute_date'], NULL)) < CRM_Utils_Date::format(date('Ymd'))) {
$errors['absolute_date'] = ts('Absolute date cannot be earlier than the current time.');
}
}
$recipientKind = array(
'participant_role' => array(
'name' => 'participant role',
'target_id' => 'recipient_listing',
),
'manual' => array(
'name' => 'recipient',
'target_id' => 'recipient_manual_id',
),
);
if ($fields['limit_to'] != '' && array_key_exists($fields['recipient'], $recipientKind) && empty($fields[$recipientKind[$fields['recipient']]['target_id']])) {
$errors[$recipientKind[$fields['recipient']]['target_id']] = ts('If "Also include" or "Limit to" are selected, you must specify at least one %1', array(1 => $recipientKind[$fields['recipient']]['name']));
}
$actionSchedule = $self->parseActionSchedule($fields);
if ($actionSchedule->mapping_id) {
$mapping = CRM_Core_BAO_ActionSchedule::getMapping($actionSchedule->mapping_id);
CRM_Utils_Array::extend($errors, $mapping->validateSchedule($actionSchedule));
}
if (!empty($errors)) {
return $errors;
}
return empty($errors) ? TRUE : $errors;
}
/**
* @return int
*/
public function setDefaultValues() {
if ($this->_action & CRM_Core_Action::ADD) {
$defaults['is_active'] = 1;
$defaults['mode'] = 'Email';
$defaults['record_activity'] = 1;
}
else {
$defaults = $this->_values;
$entityValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, CRM_Utils_Array::value('entity_value', $defaults));
$entityStatus = explode(CRM_Core_DAO::VALUE_SEPARATOR, CRM_Utils_Array::value('entity_status', $defaults));
if (empty($this->_context)) {
$defaults['entity'][0] = CRM_Utils_Array::value('mapping_id', $defaults);
$defaults['entity'][1] = $entityValue;
$defaults['entity'][2] = $entityStatus;
}
else {
$defaults['entity'] = $entityStatus;
}
if ($absoluteDate = CRM_Utils_Array::value('absolute_date', $defaults)) {
list($date, $time) = CRM_Utils_Date::setDateDefaults($absoluteDate);
$defaults['absolute_date'] = $date;
}
if ($recipientListing = CRM_Utils_Array::value('recipient_listing', $defaults)) {
$defaults['recipient_listing'] = explode(CRM_Core_DAO::VALUE_SEPARATOR,
$recipientListing
);
}
$defaults['text_message'] = CRM_Utils_Array::value('body_text', $defaults);
$defaults['html_message'] = CRM_Utils_Array::value('body_html', $defaults);
$defaults['sms_text_message'] = CRM_Utils_Array::value('sms_body_text', $defaults);
$defaults['template'] = CRM_Utils_Array::value('msg_template_id', $defaults);
$defaults['SMStemplate'] = CRM_Utils_Array::value('sms_template_id', $defaults);
if (!empty($defaults['group_id'])) {
$defaults['recipient'] = 'group';
}
elseif (!empty($defaults['recipient_manual'])) {
$defaults['recipient'] = 'manual';
$defaults['recipient_manual_id'] = $defaults['recipient_manual'];
}
if ($contactLanguage = CRM_Utils_Array::value('filter_contact_language', $defaults)) {
$defaults['filter_contact_language'] = explode(CRM_Core_DAO::VALUE_SEPARATOR, $contactLanguage);
}
}
return $defaults;
}
/**
* Process the form submission.
*/
public function postProcess() {
if ($this->_action & CRM_Core_Action::DELETE) {
// delete reminder
CRM_Core_BAO_ActionSchedule::del($this->_id);
CRM_Core_Session::setStatus(ts('Selected Reminder has been deleted.'), ts('Record Deleted'), 'success');
if ($this->_context == 'event' && $this->_compId) {
$url = CRM_Utils_System::url('civicrm/event/manage/reminder',
"reset=1&action=browse&id={$this->_compId}&component={$this->_context}&setTab=1"
);
$session = CRM_Core_Session::singleton();
$session->pushUserContext($url);
}
return;
}
$values = $this->controller->exportValues($this->getName());
$bao = $this->parseActionSchedule($values)->save();
// we need to set this on the form so that hooks can identify the created entity
$this->set('id', $bao->id);
$bao->free();
$status = ts("Your new Reminder titled %1 has been saved.",
array(1 => "<strong>{$values['title']}</strong>")
);
if ($this->_action) {
if ($this->_action & CRM_Core_Action::UPDATE) {
$status = ts("Your Reminder titled %1 has been updated.",
array(1 => "<strong>{$values['title']}</strong>")
);
}
if ($this->_context == 'event' && $this->_compId) {
$url = CRM_Utils_System::url('civicrm/event/manage/reminder', "reset=1&action=browse&id={$this->_compId}&component={$this->_context}&setTab=1");
$session = CRM_Core_Session::singleton();
$session->pushUserContext($url);
}
}
CRM_Core_Session::setStatus($status, ts('Saved'), 'success');
}
/**
* @param array $values
* The submitted form values.
* @return CRM_Core_DAO_ActionSchedule
*/
public function parseActionSchedule($values) {
$params = array();
$keys = array(
'title',
'subject',
'absolute_date',
'group_id',
'record_activity',
'limit_to',
'mode',
'sms_provider_id',
'from_name',
'from_email',
);
foreach ($keys as $key) {
$params[$key] = CRM_Utils_Array::value($key, $values);
}
$params['is_repeat'] = CRM_Utils_Array::value('is_repeat', $values, 0);
$moreKeys = array(
'start_action_offset',
'start_action_unit',
'start_action_condition',
'start_action_date',
'repetition_frequency_unit',
'repetition_frequency_interval',
'end_frequency_unit',
'end_frequency_interval',
'end_action',
'end_date',
);
if ($absoluteDate = CRM_Utils_Array::value('absolute_date', $params)) {
$params['absolute_date'] = CRM_Utils_Date::processDate($absoluteDate);
}
else {
$params['absolute_date'] = 'null';
}
foreach ($moreKeys as $mkey) {
if ($params['absolute_date'] != 'null' && CRM_Utils_String::startsWith($mkey, 'start_action')) {
$params[$mkey] = 'null';
continue;
}
$params[$mkey] = CRM_Utils_Array::value($mkey, $values);
}
$params['body_text'] = CRM_Utils_Array::value('text_message', $values);
$params['sms_body_text'] = CRM_Utils_Array::value('sms_text_message', $values);
$params['body_html'] = CRM_Utils_Array::value('html_message', $values);
if (CRM_Utils_Array::value('recipient', $values) == 'manual') {
$params['recipient_manual'] = CRM_Utils_Array::value('recipient_manual_id', $values);
$params['group_id'] = $params['recipient'] = $params['recipient_listing'] = 'null';
}
elseif (CRM_Utils_Array::value('recipient', $values) == 'group') {
$params['group_id'] = $values['group_id'];
$params['recipient_manual'] = $params['recipient'] = $params['recipient_listing'] = 'null';
}
elseif (isset($values['recipient_listing']) && isset($values['limit_to']) && !CRM_Utils_System::isNull($values['recipient_listing']) && !CRM_Utils_System::isNull($values['limit_to'])) {
$params['recipient'] = CRM_Utils_Array::value('recipient', $values);
$params['recipient_listing'] = implode(CRM_Core_DAO::VALUE_SEPARATOR,
CRM_Utils_Array::value('recipient_listing', $values)
);
$params['group_id'] = $params['recipient_manual'] = 'null';
}
else {
$params['recipient'] = CRM_Utils_Array::value('recipient', $values);
$params['group_id'] = $params['recipient_manual'] = $params['recipient_listing'] = 'null';
}
if (!empty($this->_mappingID) && !empty($this->_compId)) {
$params['mapping_id'] = $this->_mappingID;
$params['entity_value'] = $this->_compId;
$params['entity_status'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $values['entity']);
}
else {
$params['mapping_id'] = $values['entity'][0];
if ($params['mapping_id'] == 1) {
$params['limit_to'] = 1;
}
$entity_value = CRM_Utils_Array::value(1, $values['entity'], array());
$entity_status = CRM_Utils_Array::value(2, $values['entity'], array());
$params['entity_value'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $entity_value);
$params['entity_status'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $entity_status);
}
$params['is_active'] = CRM_Utils_Array::value('is_active', $values, 0);
if (CRM_Utils_Array::value('is_repeat', $values) == 0) {
$params['repetition_frequency_unit'] = 'null';
$params['repetition_frequency_interval'] = 'null';
$params['end_frequency_unit'] = 'null';
$params['end_frequency_interval'] = 'null';
$params['end_action'] = 'null';
$params['end_date'] = 'null';
}
// multilingual options
$params['filter_contact_language'] = CRM_Utils_Array::value('filter_contact_language', $values, array());
$params['filter_contact_language'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $params['filter_contact_language']);
$params['communication_language'] = CRM_Utils_Array::value('communication_language', $values, NULL);
if ($this->_action & CRM_Core_Action::UPDATE) {
$params['id'] = $this->_id;
}
elseif ($this->_action & CRM_Core_Action::ADD) {
// we do this only once, so name never changes
$params['name'] = CRM_Utils_String::munge($params['title'], '_', 64);
}
$modePrefixes = array('Mail' => NULL, 'SMS' => 'SMS');
if ($params['mode'] == 'Email' || empty($params['sms_provider_id'])) {
unset($modePrefixes['SMS']);
}
elseif ($params['mode'] == 'SMS') {
unset($modePrefixes['Mail']);
}
//TODO: handle postprocessing of SMS and/or Email info based on $modePrefixes
$composeFields = array(
'template',
'saveTemplate',
'updateTemplate',
'saveTemplateName',
);
$msgTemplate = NULL;
//mail template is composed
foreach ($modePrefixes as $prefix) {
$composeParams = array();
foreach ($composeFields as $key) {
$key = $prefix . $key;
if (!empty($values[$key])) {
$composeParams[$key] = $values[$key];
}
}
if (!empty($composeParams[$prefix . 'updateTemplate'])) {
$templateParams = array('is_active' => TRUE);
if ($prefix == 'SMS') {
$templateParams += array(
'msg_text' => $params['sms_body_text'],
'is_sms' => TRUE,
);
}
else {
$templateParams += array(
'msg_text' => $params['body_text'],
'msg_html' => $params['body_html'],
'msg_subject' => $params['subject'],
);
}
$templateParams['id'] = $values[$prefix . 'template'];
$msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams);
}
if (!empty($composeParams[$prefix . 'saveTemplate'])) {
$templateParams = array('is_active' => TRUE);
if ($prefix == 'SMS') {
$templateParams += array(
'msg_text' => $params['sms_body_text'],
'is_sms' => TRUE,
);
}
else {
$templateParams += array(
'msg_text' => $params['body_text'],
'msg_html' => $params['body_html'],
'msg_subject' => $params['subject'],
);
}
$templateParams['msg_title'] = $composeParams[$prefix . 'saveTemplateName'];
$msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams);
}
if ($prefix == 'SMS') {
if (isset($msgTemplate->id)) {
$params['sms_template_id'] = $msgTemplate->id;
}
else {
$params['sms_template_id'] = CRM_Utils_Array::value('SMStemplate', $values);
}
}
else {
if (isset($msgTemplate->id)) {
$params['msg_template_id'] = $msgTemplate->id;
}
else {
$params['msg_template_id'] = CRM_Utils_Array::value('template', $values);
}
}
}
$actionSchedule = new CRM_Core_DAO_ActionSchedule();
$actionSchedule->copyValues($params);
return $actionSchedule;
}
/**
* List available tokens for this form.
*
* @return array
*/
public function listTokens() {
$tokens = CRM_Core_SelectValues::contactTokens();
$tokens = array_merge(CRM_Core_SelectValues::activityTokens(), $tokens);
$tokens = array_merge(CRM_Core_SelectValues::eventTokens(), $tokens);
$tokens = array_merge(CRM_Core_SelectValues::membershipTokens(), $tokens);
$tokens = array_merge(CRM_Core_SelectValues::contributionTokens(), $tokens);
return $tokens;
}
}

View file

@ -0,0 +1,306 @@
<?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 generic to CiviCRM settings.
*/
class CRM_Admin_Form_Setting extends CRM_Core_Form {
protected $_settings = array();
/**
* Set default values for the form.
*
* Default values are retrieved from the database.
*/
public function setDefaultValues() {
if (!$this->_defaults) {
$this->_defaults = array();
$formArray = array('Component', 'Localization');
$formMode = FALSE;
if (in_array($this->_name, $formArray)) {
$formMode = TRUE;
}
CRM_Core_BAO_ConfigSetting::retrieve($this->_defaults);
// we can handle all the ones defined in the metadata here. Others to be converted
foreach ($this->_settings as $setting => $group) {
$this->_defaults[$setting] = civicrm_api('setting', 'getvalue', array(
'version' => 3,
'name' => $setting,
'group' => $group,
)
);
}
$this->_defaults['contact_autocomplete_options'] = self::getAutocompleteContactSearch();
$this->_defaults['contact_reference_options'] = self::getAutocompleteContactReference();
$this->_defaults['enableSSL'] = Civi::settings()->get('enableSSL');
$this->_defaults['verifySSL'] = Civi::settings()->get('verifySSL');
$this->_defaults['environment'] = CRM_Core_Config::environment();
$this->_defaults['enableComponents'] = Civi::settings()->get('enable_components');
}
return $this->_defaults;
}
/**
* Build the form object.
*/
public function buildQuickForm() {
CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/admin', 'reset=1'));
$this->addButtons(array(
array(
'type' => 'next',
'name' => ts('Save'),
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
)
);
$descriptions = array();
$settingMetaData = $this->getSettingsMetaData();
foreach ($settingMetaData as $setting => $props) {
if (isset($props['quick_form_type'])) {
if (isset($props['pseudoconstant'])) {
$options = civicrm_api3('Setting', 'getoptions', array(
'field' => $setting,
));
}
else {
$options = NULL;
}
$add = 'add' . $props['quick_form_type'];
if ($add == 'addElement') {
$this->$add(
$props['html_type'],
$setting,
ts($props['title']),
($options !== NULL) ? $options['values'] : CRM_Utils_Array::value('html_attributes', $props, array()),
($options !== NULL) ? CRM_Utils_Array::value('html_attributes', $props, array()) : NULL
);
}
elseif ($add == 'addSelect') {
$this->addElement('select', $setting, ts($props['title']), $options['values'], CRM_Utils_Array::value('html_attributes', $props));
}
elseif ($add == 'addCheckBox') {
$this->addCheckBox($setting, ts($props['title']), $options['values'], NULL, CRM_Utils_Array::value('html_attributes', $props), NULL, NULL, array('&nbsp;&nbsp;'));
}
elseif ($add == 'addChainSelect') {
$this->addChainSelect($setting, array(
'label' => ts($props['title']),
));
}
elseif ($add == 'addMonthDay') {
$this->add('date', $setting, ts($props['title']), CRM_Core_SelectValues::date(NULL, 'M d'));
}
else {
$this->$add($setting, ts($props['title']));
}
// Migrate to using an array as easier in smart...
$descriptions[$setting] = ts($props['description']);
$this->assign("{$setting}_description", ts($props['description']));
if ($setting == 'max_attachments') {
//temp hack @todo fix to get from metadata
$this->addRule('max_attachments', ts('Value should be a positive number'), 'positiveInteger');
}
if ($setting == 'maxFileSize') {
//temp hack
$this->addRule('maxFileSize', ts('Value should be a positive number'), 'positiveInteger');
}
}
}
// setting_description should be deprecated - see Mail.tpl for metadata based tpl.
$this->assign('setting_descriptions', $descriptions);
$this->assign('settings_fields', $settingMetaData);
}
/**
* Get default entity.
*
* @return string
*/
public function getDefaultEntity() {
return 'Setting';
}
/**
* Process the form submission.
*/
public function postProcess() {
// store the submitted values in an array
$params = $this->controller->exportValues($this->_name);
self::commonProcess($params);
}
/**
* Common Process.
*
* @todo Document what I do.
*
* @param array $params
*/
public function commonProcess(&$params) {
// save autocomplete search options
if (!empty($params['contact_autocomplete_options'])) {
Civi::settings()->set('contact_autocomplete_options',
CRM_Utils_Array::implodePadded(array_keys($params['contact_autocomplete_options'])));
unset($params['contact_autocomplete_options']);
}
// save autocomplete contact reference options
if (!empty($params['contact_reference_options'])) {
Civi::settings()->set('contact_reference_options',
CRM_Utils_Array::implodePadded(array_keys($params['contact_reference_options'])));
unset($params['contact_reference_options']);
}
// save components to be enabled
if (array_key_exists('enableComponents', $params)) {
civicrm_api3('setting', 'create', array(
'enable_components' => $params['enableComponents'],
));
unset($params['enableComponents']);
}
foreach (array('verifySSL', 'enableSSL') as $name) {
if (isset($params[$name])) {
Civi::settings()->set($name, $params[$name]);
unset($params[$name]);
}
}
$settings = array_intersect_key($params, $this->_settings);
$result = civicrm_api('setting', 'create', $settings + array('version' => 3));
foreach ($settings as $setting => $settingGroup) {
//@todo array_diff this
unset($params[$setting]);
}
if (!empty($result['error_message'])) {
CRM_Core_Session::setStatus($result['error_message'], ts('Save Failed'), 'error');
}
//CRM_Core_BAO_ConfigSetting::create($params);
$params = CRM_Core_BAO_ConfigSetting::filterSkipVars($params);
if (!empty($params)) {
CRM_Core_Error::fatal('Unrecognized setting. This may be a config field which has not been properly migrated to a setting. (' . implode(', ', array_keys($params)) . ')');
}
CRM_Core_Config::clearDBCache();
CRM_Utils_System::flushCache();
CRM_Core_Resources::singleton()->resetCacheCode();
CRM_Core_Session::setStatus(" ", ts('Changes Saved'), "success");
}
public function rebuildMenu() {
// ensure config is set with new values
$config = CRM_Core_Config::singleton(TRUE, TRUE);
// rebuild menu items
CRM_Core_Menu::store();
// also delete the IDS file so we can write a new correct one on next load
$configFile = $config->uploadDir . 'Config.IDS.ini';
@unlink($configFile);
}
/**
* Ugh, this shouldn't exist.
*
* Get the selected values of "contact_reference_options" formatted for checkboxes.
*
* @return array
*/
public static function getAutocompleteContactReference() {
$cRlist = array_flip(CRM_Core_OptionGroup::values('contact_reference_options',
FALSE, FALSE, TRUE, NULL, 'name'
));
$cRlistEnabled = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'contact_reference_options'
);
$cRSearchFields = array();
if (!empty($cRlist) && !empty($cRlistEnabled)) {
$cRSearchFields = array_combine($cRlist, $cRlistEnabled);
}
return array(
'1' => 1,
) + $cRSearchFields;
}
/**
* Ugh, this shouldn't exist.
*
* Get the selected values of "contact_autocomplete_options" formatted for checkboxes.
*
* @return array
*/
public static function getAutocompleteContactSearch() {
$list = array_flip(CRM_Core_OptionGroup::values('contact_autocomplete_options',
FALSE, FALSE, TRUE, NULL, 'name'
));
$listEnabled = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'contact_autocomplete_options'
);
$autoSearchFields = array();
if (!empty($list) && !empty($listEnabled)) {
$autoSearchFields = array_combine($list, $listEnabled);
}
//Set defaults for autocomplete and contact reference options
return array(
'1' => 1,
) + $autoSearchFields;
}
/**
* Get the metadata relating to the settings on the form, ordered by the keys in $this->_settings.
*
* @return array
*/
protected function getSettingsMetaData() {
$allSettingMetaData = civicrm_api3('setting', 'getfields', array());
$settingMetaData = array_intersect_key($allSettingMetaData['values'], $this->_settings);
// This array_merge re-orders to the key order of $this->_settings.
$settingMetaData = array_merge($this->_settings, $settingMetaData);
return $settingMetaData;
}
}

View file

@ -0,0 +1,54 @@
<?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 CiviCase.
*/
class CRM_Admin_Form_Setting_Case extends CRM_Admin_Form_Setting {
protected $_settings = array(
'civicaseRedactActivityEmail' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'civicaseAllowMultipleClients' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'civicaseNaturalActivityTypeSort' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'civicaseActivityRevisions' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
);
/**
* Build the form object.
*/
public function buildQuickForm() {
CRM_Utils_System::setTitle(ts('Settings - CiviCase'));
parent::buildQuickForm();
}
}

View file

@ -0,0 +1,173 @@
<?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 Component.
*/
class CRM_Admin_Form_Setting_Component extends CRM_Admin_Form_Setting {
protected $_components;
/**
* Build the form object.
*/
public function buildQuickForm() {
CRM_Utils_System::setTitle(ts('Settings - Enable Components'));
$components = $this->_getComponentSelectValues();
$include = &$this->addElement('advmultiselect', 'enableComponents',
ts('Components') . ' ', $components,
array(
'size' => 5,
'style' => 'width:150px',
'class' => 'advmultiselect',
)
);
$include->setButtonAttributes('add', array('value' => ts('Enable >>')));
$include->setButtonAttributes('remove', array('value' => ts('<< Disable')));
$this->addFormRule(array('CRM_Admin_Form_Setting_Component', 'formRule'), $this);
parent::buildQuickForm();
}
/**
* Global form rule.
*
* @param array $fields
* The input form values.
* @param array $files
* The uploaded files if any.
* @param array $options
* Additional user data.
*
* @return bool|array
* true if no errors, else array of errors
*/
public static function formRule($fields, $files, $options) {
$errors = array();
if (array_key_exists('enableComponents', $fields) && is_array($fields['enableComponents'])) {
if (in_array('CiviPledge', $fields['enableComponents']) &&
!in_array('CiviContribute', $fields['enableComponents'])
) {
$errors['enableComponents'] = ts('You need to enable CiviContribute before enabling CiviPledge.');
}
if (in_array('CiviCase', $fields['enableComponents']) &&
!CRM_Core_DAO::checkTriggerViewPermission(TRUE, FALSE)
) {
$errors['enableComponents'] = ts('CiviCase requires CREATE VIEW and DROP VIEW permissions for the database.');
}
}
return $errors;
}
/**
* @return array
*/
private function _getComponentSelectValues() {
$ret = array();
$this->_components = CRM_Core_Component::getComponents();
foreach ($this->_components as $name => $object) {
$ret[$name] = $object->info['translatedName'];
}
return $ret;
}
public function postProcess() {
$params = $this->controller->exportValues($this->_name);
parent::commonProcess($params);
// reset navigation when components are enabled / disabled
CRM_Core_BAO_Navigation::resetNavigation();
}
/**
* Load case sample data.
*
* @param string $fileName
* @param bool $lineMode
*/
public static function loadCaseSampleData($fileName, $lineMode = FALSE) {
$dao = new CRM_Core_DAO();
$db = $dao->getDatabaseConnection();
$domain = new CRM_Core_DAO_Domain();
$domain->find(TRUE);
$multiLingual = (bool) $domain->locales;
$smarty = CRM_Core_Smarty::singleton();
$smarty->assign('multilingual', $multiLingual);
$smarty->assign('locales', explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales));
if (!$lineMode) {
$string = $smarty->fetch($fileName);
// change \r\n to fix windows issues
$string = str_replace("\r\n", "\n", $string);
//get rid of comments starting with # and --
$string = preg_replace("/^#[^\n]*$/m", "\n", $string);
$string = preg_replace("/^(--[^-]).*/m", "\n", $string);
$queries = preg_split('/;$/m', $string);
foreach ($queries as $query) {
$query = trim($query);
if (!empty($query)) {
$res = &$db->query($query);
if (PEAR::isError($res)) {
die("Cannot execute $query: " . $res->getMessage());
}
}
}
}
else {
$fd = fopen($fileName, "r");
while ($string = fgets($fd)) {
$string = preg_replace("/^#[^\n]*$/m", "\n", $string);
$string = preg_replace("/^(--[^-]).*/m", "\n", $string);
$string = trim($string);
if (!empty($string)) {
$res = &$db->query($string);
if (PEAR::isError($res)) {
die("Cannot execute $string: " . $res->getMessage());
}
}
}
}
}
}

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
*/
/**
* This class generates form components for Date Formatting.
*/
class CRM_Admin_Form_Setting_Date extends CRM_Admin_Form_Setting {
public $_settings = array(
'dateformatDatetime' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
'dateformatFull' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
'dateformatPartial' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
'dateformatYear' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
'dateformatTime' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
'dateformatFinancialBatch' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
'dateformatshortdate' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
'weekBegins' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
'dateInputFormat' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
'timeInputFormat' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
'fiscalYearStart' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
);
/**
* Build the form object.
*/
public function buildQuickForm() {
CRM_Utils_System::setTitle(ts('Settings - Date'));
parent::buildQuickForm();
}
}

View file

@ -0,0 +1,64 @@
<?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 Error Handling and Debugging.
*/
class CRM_Admin_Form_Setting_Debugging extends CRM_Admin_Form_Setting {
protected $_settings = array(
'debug_enabled' => CRM_Core_BAO_Setting::DEVELOPER_PREFERENCES_NAME,
'backtrace' => CRM_Core_BAO_Setting::DEVELOPER_PREFERENCES_NAME,
'fatalErrorHandler' => CRM_Core_BAO_Setting::DEVELOPER_PREFERENCES_NAME,
'assetCache' => CRM_Core_BAO_Setting::DEVELOPER_PREFERENCES_NAME,
'environment' => CRM_Core_BAO_Setting::DEVELOPER_PREFERENCES_NAME,
);
/**
* Build the form object.
*/
public function buildQuickForm() {
CRM_Utils_System::setTitle(ts(' Settings - Debugging and Error Handling '));
if (CRM_Core_Config::singleton()->userSystem->supports_UF_Logging == '1') {
$this->_settings['userFrameworkLogging'] = CRM_Core_BAO_Setting::DEVELOPER_PREFERENCES_NAME;
}
parent::buildQuickForm();
if (Civi::settings()->getMandatory('environment') !== NULL) {
$element = $this->getElement('environment');
$element->freeze();
CRM_Core_Session::setStatus(ts('The environment settings have been disabled because it has been overridden in the settings file.'), ts('Environment settings'), 'info');
}
}
}

View file

@ -0,0 +1,393 @@
<?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 Localization.
*/
class CRM_Admin_Form_Setting_Localization extends CRM_Admin_Form_Setting {
protected $_settings = array(
'contact_default_language' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
'countryLimit' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
'customTranslateFunction' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
'defaultContactCountry' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
'defaultContactStateProvince' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
'defaultCurrency' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
'fieldSeparator' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
'inheritLocale' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
'lcMessages' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
'legacyEncoding' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
'monetaryThousandSeparator' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
'monetaryDecimalPoint' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
'moneyformat' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
'moneyvalueformat' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
'provinceLimit' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
);
/**
* Build the form object.
*/
public function buildQuickForm() {
$config = CRM_Core_Config::singleton();
CRM_Utils_System::setTitle(ts('Settings - Localization'));
$warningTitle = json_encode(ts("Warning"));
$defaultLocaleOptions = CRM_Admin_Form_Setting_Localization::getDefaultLocaleOptions();
$domain = new CRM_Core_DAO_Domain();
$domain->find(TRUE);
if ($domain->locales) {
// add language limiter and language adder
$this->addCheckBox('languageLimit', ts('Available Languages'), array_flip($defaultLocaleOptions), NULL, NULL, NULL, NULL, ' &nbsp; ');
$this->addElement('select', 'addLanguage', ts('Add Language'), array_merge(array('' => ts('- select -')), array_diff(CRM_Core_I18n::languages(), $defaultLocaleOptions)));
// add the ability to return to single language
$warning = ts('This will make your CiviCRM installation a single-language one again. THIS WILL DELETE ALL DATA RELATED TO LANGUAGES OTHER THAN THE DEFAULT ONE SELECTED ABOVE (and only that language will be preserved).');
$this->assign('warning', $warning);
$warning = json_encode($warning);
$this->addElement('checkbox', 'makeSinglelingual', ts('Return to Single Language'),
NULL, array('onChange' => "if (this.checked) CRM.alert($warning, $warningTitle)")
);
}
else {
$warning = ts('Enabling multiple languages changes the schema of your database, so make sure you know what you are doing when enabling this function; making a database backup is strongly recommended.');
$this->assign('warning', $warning);
$warning = json_encode($warning);
$validTriggerPermission = CRM_Core_DAO::checkTriggerViewPermission(TRUE);
if ($validTriggerPermission &&
!\Civi::settings()->get('logging')
) {
$this->addElement('checkbox', 'makeMultilingual', ts('Enable Multiple Languages'),
NULL, array('onChange' => "if (this.checked) CRM.alert($warning, $warningTitle)")
);
}
}
$this->addElement('select', 'contact_default_language', ts('Default Language for users'),
CRM_Admin_Form_Setting_Localization::getDefaultLanguageOptions());
$includeCurrency = &$this->addElement('advmultiselect', 'currencyLimit',
ts('Available Currencies') . ' ', self::getCurrencySymbols(),
array(
'size' => 5,
'style' => 'width:150px',
'class' => 'advmultiselect',
)
);
$includeCurrency->setButtonAttributes('add', array('value' => ts('Add >>')));
$includeCurrency->setButtonAttributes('remove', array('value' => ts('<< Remove')));
$this->addFormRule(array('CRM_Admin_Form_Setting_Localization', 'formRule'));
parent::buildQuickForm();
}
/**
* @param $fields
*
* @return array|bool
*/
public static function formRule($fields) {
$errors = array();
if (CRM_Utils_Array::value('monetaryThousandSeparator', $fields) ==
CRM_Utils_Array::value('monetaryDecimalPoint', $fields)
) {
$errors['monetaryThousandSeparator'] = ts('Thousands Separator and Decimal Delimiter can not be the same.');
}
if (strlen($fields['monetaryThousandSeparator']) == 0) {
$errors['monetaryThousandSeparator'] = ts('Thousands Separator can not be empty. You can use a space character instead.');
}
if (strlen($fields['monetaryThousandSeparator']) > 1) {
$errors['monetaryThousandSeparator'] = ts('Thousands Separator can not have more than 1 character.');
}
if (strlen($fields['monetaryDecimalPoint']) > 1) {
$errors['monetaryDecimalPoint'] = ts('Decimal Delimiter can not have more than 1 character.');
}
if (trim($fields['customTranslateFunction']) &&
!function_exists(trim($fields['customTranslateFunction']))
) {
$errors['customTranslateFunction'] = ts('Please define the custom translation function first.');
}
// CRM-7962, CRM-7713, CRM-9004
if (!empty($fields['defaultContactCountry']) &&
(!empty($fields['countryLimit']) &&
(!in_array($fields['defaultContactCountry'], $fields['countryLimit']))
)
) {
$errors['defaultContactCountry'] = ts('Please select a default country that is in the list of available countries.');
}
return empty($errors) ? TRUE : $errors;
}
/**
* Set the default values for the form.
*
* @return array
*/
public function setDefaultValues() {
parent::setDefaultValues();
// CRM-1496
// retrieve default values for currencyLimit
$this->_defaults['currencyLimit'] = array_keys(CRM_Core_OptionGroup::values('currencies_enabled'));
$this->_defaults['languageLimit'] = Civi::settings()->get('languageLimit');
// CRM-5111: unset these two unconditionally, we dont want them to stick ever
unset($this->_defaults['makeMultilingual']);
unset($this->_defaults['makeSinglelingual']);
return $this->_defaults;
}
public function postProcess() {
$values = $this->exportValues();
//cache contact fields retaining localized titles
//though we changed localization, so reseting cache.
CRM_Core_BAO_Cache::deleteGroup('contact fields');
//CRM-8559, cache navigation do not respect locale if it is changed, so reseting cache.
CRM_Core_BAO_Cache::deleteGroup('navigation');
// we do this only to initialize monetary decimal point and thousand separator
$config = CRM_Core_Config::singleton();
// save enabled currencies and default currency in option group 'currencies_enabled'
// CRM-1496
if (empty($values['currencyLimit'])) {
$values['currencyLimit'] = array($values['defaultCurrency']);
}
elseif (!in_array($values['defaultCurrency'], $values['currencyLimit'])) {
$values['currencyLimit'][] = $values['defaultCurrency'];
}
self::updateEnabledCurrencies($values['currencyLimit'], $values['defaultCurrency']);
// unset currencyLimit so we dont store there
unset($values['currencyLimit']);
// make the site multi-lang if requested
if (!empty($values['makeMultilingual'])) {
CRM_Core_I18n_Schema::makeMultilingual($values['lcMessages']);
$values['languageLimit'][$values['lcMessages']] = 1;
// make the site single-lang if requested
}
elseif (!empty($values['makeSinglelingual'])) {
CRM_Core_I18n_Schema::makeSinglelingual($values['lcMessages']);
$values['languageLimit'] = '';
}
// add a new db locale if the requested language is not yet supported by the db
if (!CRM_Utils_Array::value('makeSinglelingual', $values) and CRM_Utils_Array::value('addLanguage', $values)) {
$domain = new CRM_Core_DAO_Domain();
$domain->find(TRUE);
if (!substr_count($domain->locales, $values['addLanguage'])) {
CRM_Core_I18n_Schema::addLocale($values['addLanguage'], $values['lcMessages']);
}
$values['languageLimit'][$values['addLanguage']] = 1;
}
// if we manipulated the language list, return to the localization admin screen
$return = (bool) (CRM_Utils_Array::value('makeMultilingual', $values) or CRM_Utils_Array::value('addLanguage', $values));
$filteredValues = $values;
unset($filteredValues['makeMultilingual']);
unset($filteredValues['makeSinglelingual']);
unset($filteredValues['addLanguage']);
unset($filteredValues['languageLimit']);
Civi::settings()->set('languageLimit', CRM_Utils_Array::value('languageLimit', $values));
// save all the settings
parent::commonProcess($filteredValues);
if ($return) {
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/setting/localization', 'reset=1'));
}
}
/**
* Replace available currencies by the ones provided
*
* @param $currencies array of currencies ['USD', 'CAD']
* @param $default default currency
*/
public static function updateEnabledCurrencies($currencies, $default) {
// sort so that when we display drop down, weights have right value
sort($currencies);
// get labels for all the currencies
$options = array();
$currencySymbols = CRM_Admin_Form_Setting_Localization::getCurrencySymbols();
for ($i = 0; $i < count($currencies); $i++) {
$options[] = array(
'label' => $currencySymbols[$currencies[$i]],
'value' => $currencies[$i],
'weight' => $i + 1,
'is_active' => 1,
'is_default' => $currencies[$i] == $default,
);
}
$dontCare = NULL;
CRM_Core_OptionGroup::createAssoc('currencies_enabled', $options, $dontCare);
}
/**
* @return array
*/
public static function getAvailableCountries() {
$i18n = CRM_Core_I18n::singleton();
$country = array();
CRM_Core_PseudoConstant::populate($country, 'CRM_Core_DAO_Country', TRUE, 'name', 'is_active');
$i18n->localizeArray($country, array('context' => 'country'));
asort($country);
return $country;
}
/**
* Get the default locale options.
*
* @return array
*/
public static function getDefaultLocaleOptions() {
$domain = new CRM_Core_DAO_Domain();
$domain->find(TRUE);
$locales = CRM_Core_I18n::languages();
if ($domain->locales) {
// for multi-lingual sites, populate default language drop-down with available languages
$defaultLocaleOptions = array();
foreach ($locales as $loc => $lang) {
if (substr_count($domain->locales, $loc)) {
$defaultLocaleOptions[$loc] = $lang;
}
}
}
else {
$defaultLocaleOptions = $locales;
}
return $defaultLocaleOptions;
}
/**
* Get a list of currencies (with their symbols).
*
* @return array
* Array('USD' => 'USD ($)').
*/
public static function getCurrencySymbols() {
$symbols = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'currency', array(
'labelColumn' => 'symbol',
'orderColumn' => TRUE,
));
$_currencySymbols = array();
foreach ($symbols as $key => $value) {
$_currencySymbols[$key] = "$key";
if ($value) {
$_currencySymbols[$key] .= " ($value)";
}
}
return $_currencySymbols;
}
/**
* Update session and uf_match table when the locale is updated.
*
* @param string $oldLocale
* @param string $newLocale
* @param array $metadata
* @param int $domainID
*/
public static function onChangeLcMessages($oldLocale, $newLocale, $metadata, $domainID) {
if ($oldLocale == $newLocale) {
return;
}
$session = CRM_Core_Session::singleton();
if ($newLocale && $session->get('userID')) {
$ufm = new CRM_Core_DAO_UFMatch();
$ufm->contact_id = $session->get('userID');
if ($newLocale && $ufm->find(TRUE)) {
$ufm->language = $newLocale;
$ufm->save();
$session->set('lcMessages', $newLocale);
}
}
}
public static function onChangeDefaultCurrency($oldCurrency, $newCurrency, $metadata) {
if ($oldCurrency == $newCurrency) {
return;
}
// ensure that default currency is always in the list of enabled currencies
$currencies = array_keys(CRM_Core_OptionGroup::values('currencies_enabled'));
if (!in_array($newCurrency, $currencies)) {
if (empty($currencies)) {
$currencies = array($values['defaultCurrency']);
}
else {
$currencies[] = $newCurrency;
}
CRM_Admin_Form_Setting_Localization::updateEnabledCurrencies($currencies, $newCurrency);
}
}
/**
* @return array
*/
public static function getDefaultLanguageOptions() {
return array(
'*default*' => ts('Use default site language'),
'undefined' => ts('Leave undefined'),
'current_site_language' => ts('Use language in use at the time'),
);
}
}

View file

@ -0,0 +1,80 @@
<?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 CiviMail.
*/
class CRM_Admin_Form_Setting_Mail extends CRM_Admin_Form_Setting {
protected $_settings = array(
'mailerBatchLimit' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
'mailThrottleTime' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
'mailerJobSize' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
'mailerJobsMax' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
'verpSeparator' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
'replyTo' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
);
/**
* Build the form object.
*/
public function buildQuickForm() {
CRM_Utils_System::setTitle(ts('Settings - CiviMail'));
$this->addFormRule(array('CRM_Admin_Form_Setting_Mail', 'formRule'));
parent::buildQuickForm();
}
/**
* @param $fields
*
* @return array|bool
*/
public static function formRule($fields) {
$errors = array();
if (CRM_Utils_Array::value('mailerJobSize', $fields) > 0) {
if (CRM_Utils_Array::value('mailerJobSize', $fields) < 1000) {
$errors['mailerJobSize'] = ts('The job size must be at least 1000 or set to 0 (unlimited).');
}
elseif (CRM_Utils_Array::value('mailerJobSize', $fields) <
CRM_Utils_Array::value('mailerBatchLimit', $fields)
) {
$errors['mailerJobSize'] = ts('A job size smaller than the batch limit will negate the effect of the batch limit.');
}
}
return empty($errors) ? TRUE : $errors;
}
}

View file

@ -0,0 +1,90 @@
<?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 Mapping and Geocoding.
*/
class CRM_Admin_Form_Setting_Mapping extends CRM_Admin_Form_Setting {
protected $_settings = array(
'mapAPIKey' => CRM_Core_BAO_Setting::MAP_PREFERENCES_NAME,
'mapProvider' => CRM_Core_BAO_Setting::MAP_PREFERENCES_NAME,
'geoAPIKey' => CRM_Core_BAO_Setting::MAP_PREFERENCES_NAME,
'geoProvider' => CRM_Core_BAO_Setting::MAP_PREFERENCES_NAME,
);
/**
* Build the form object.
*/
public function buildQuickForm() {
CRM_Utils_System::setTitle(ts('Settings - Mapping and Geocoding Providers'));
parent::buildQuickForm();
}
/**
* Global form rule.
*
* @param array $fields
* The input form values.
*
* @return bool|array
* true if no errors, else array of errors
*/
public static function formRule($fields) {
$errors = array();
if (!CRM_Utils_System::checkPHPVersion(5, FALSE)) {
$errors['_qf_default'] = ts('Mapping features require PHP version 5 or greater');
}
if (!$fields['mapAPIKey'] && ($fields['mapProvider'] != '' && $fields['mapProvider'] == 'Yahoo')) {
$errors['mapAPIKey'] = "Map Provider key is a required field.";
}
if ($fields['mapProvider'] == 'OpenStreetMaps' && $fields['geoProvider'] == '') {
$errors['geoProvider'] = "Please select a Geocoding Provider - Open Street Maps does not provide geocoding.";
}
return $errors;
}
/**
* Add the rules (mainly global rules) for form.
*
* All local rules are added near the element
*/
public function addRules() {
$this->addFormRule(array('CRM_Admin_Form_Setting_Mapping', 'formRule'));
}
}

View file

@ -0,0 +1,138 @@
<?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 Miscellaneous.
*/
class CRM_Admin_Form_Setting_Miscellaneous extends CRM_Admin_Form_Setting {
protected $_settings = array(
'max_attachments' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'contact_undelete' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'empoweredBy' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'logging' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'maxFileSize' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'doNotAttachPDFReceipt' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'recordGeneratedLetters' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'secondDegRelPermissions' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'checksum_timeout' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'recaptchaOptions' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'recaptchaPublicKey' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'recaptchaPrivateKey' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'wkhtmltopdfPath' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'recentItemsMaxCount' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'recentItemsProviders' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'dedupe_default_limit' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'remote_profile_submissions' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
);
public $_uploadMaxSize;
/**
* Basic setup.
*/
public function preProcess() {
$this->_uploadMaxSize = (int) ini_get('upload_max_filesize');
// check for post max size
CRM_Utils_Number::formatUnitSize(ini_get('post_max_size'), TRUE);
// This is a temp hack for the fact we really don't need to hard-code each setting in the tpl but
// we haven't worked through NOT doing that. These settings have been un-hardcoded.
$this->assign('pure_config_settings', array(
'empoweredBy',
'max_attachments',
'maxFileSize',
'secondDegRelPermissions',
'recentItemsMaxCount',
'recentItemsProviders',
'dedupe_default_limit',
));
}
/**
* Build the form object.
*/
public function buildQuickForm() {
CRM_Utils_System::setTitle(ts('Misc (Undelete, PDFs, Limits, Logging, Captcha, etc.)'));
$this->assign('validTriggerPermission', CRM_Core_DAO::checkTriggerViewPermission(FALSE));
$this->addFormRule(array('CRM_Admin_Form_Setting_Miscellaneous', 'formRule'), $this);
parent::buildQuickForm();
$this->addRule('checksum_timeout', ts('Value should be a positive number'), 'positiveInteger');
}
/**
* Global form rule.
*
* @param array $fields
* The input form values.
* @param array $files
* The uploaded files if any.
* @param array $options
* Additional user data.
*
* @return bool|array
* true if no errors, else array of errors
*/
public static function formRule($fields, $files, $options) {
$errors = array();
// validate max file size
if ($fields['maxFileSize'] > $options->_uploadMaxSize) {
$errors['maxFileSize'] = ts("Maximum file size cannot exceed Upload max size ('upload_max_filesize') as defined in PHP.ini.");
}
// validate recent items stack size
if ($fields['recentItemsMaxCount'] && ($fields['recentItemsMaxCount'] < 1 || $fields['recentItemsMaxCount'] > CRM_Utils_Recent::MAX_ITEMS)) {
$errors['recentItemsMaxCount'] = ts("Illegal stack size. Use values between 1 and %1.", array(1 => CRM_Utils_Recent::MAX_ITEMS));
}
if (!empty($fields['wkhtmltopdfPath'])) {
// check and ensure that thi leads to the wkhtmltopdf binary
// and it is a valid executable binary
// Only check the first space separated piece to allow for a value
// such as /usr/bin/xvfb-run -- wkhtmltopdf (CRM-13292)
$pieces = explode(' ', $fields['wkhtmltopdfPath']);
$path = $pieces[0];
if (
!file_exists($path) ||
!is_executable($path)
) {
$errors['wkhtmltopdfPath'] = ts('The wkhtmltodfPath does not exist or is not valid');
}
}
return $errors;
}
}

View file

@ -0,0 +1,81 @@
<?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 File System Path.
*/
class CRM_Admin_Form_Setting_Path extends CRM_Admin_Form_Setting {
protected $_settings = array(
'uploadDir' => CRM_Core_BAO_Setting::DIRECTORY_PREFERENCES_NAME,
'imageUploadDir' => CRM_Core_BAO_Setting::DIRECTORY_PREFERENCES_NAME,
'customFileUploadDir' => CRM_Core_BAO_Setting::DIRECTORY_PREFERENCES_NAME,
'customTemplateDir' => CRM_Core_BAO_Setting::DIRECTORY_PREFERENCES_NAME,
'customPHPPathDir' => CRM_Core_BAO_Setting::DIRECTORY_PREFERENCES_NAME,
'extensionsDir' => CRM_Core_BAO_Setting::DIRECTORY_PREFERENCES_NAME,
);
/**
* Build the form object.
*/
public function buildQuickForm() {
CRM_Utils_System::setTitle(ts('Settings - Upload Directories'));
parent::buildQuickForm();
$directories = array(
'uploadDir' => ts('Temporary Files'),
'imageUploadDir' => ts('Images'),
'customFileUploadDir' => ts('Custom Files'),
'customTemplateDir' => ts('Custom Templates'),
'customPHPPathDir' => ts('Custom PHP Path Directory'),
'extensionsDir' => ts('CiviCRM Extensions Directory'),
);
foreach ($directories as $name => $title) {
//$this->add('text', $name, $title);
$this->addRule($name,
ts("'%1' directory does not exist",
array(1 => $title)
),
'settingPath'
);
}
}
public function postProcess() {
parent::postProcess();
parent::rebuildMenu();
}
}

View file

@ -0,0 +1,108 @@
<?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 Search Parameters
*
*/
class CRM_Admin_Form_Setting_Search extends CRM_Admin_Form_Setting {
protected $_settings = array(
'contact_reference_options' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME,
'contact_autocomplete_options' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME,
'search_autocomplete_count' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME,
'enable_innodb_fts' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME,
'includeWildCardInName' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME,
'includeEmailInName' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME,
'includeNickNameInName' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME,
'includeAlphabeticalPager' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME,
'includeOrderByClause' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME,
'smartGroupCacheTimeout' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME,
'defaultSearchProfileID' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME,
'searchPrimaryDetailsOnly' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME,
);
/**
* Build the form object.
*/
public function buildQuickForm() {
CRM_Utils_System::setTitle(ts('Settings - Search Preferences'));
parent::buildQuickForm();
// @todo remove the following adds in favour of setting via the settings array (above).
// Autocomplete for Contact Search (quick search etc.)
$element = $this->getElement('contact_autocomplete_options');
$element->_elements[0]->_flagFrozen = TRUE;
// Autocomplete for Contact Reference (custom fields)
$element = $this->getElement('contact_reference_options');
$element->_elements[0]->_flagFrozen = TRUE;
}
/**
* @return array
*/
public static function getContactAutocompleteOptions() {
return array(
ts('Contact Name') => 1,
) + array_flip(CRM_Core_OptionGroup::values('contact_autocomplete_options',
FALSE, FALSE, TRUE
));
}
/**
* @return array
*/
public static function getAvailableProfiles() {
return array('' => ts('- none -')) + CRM_Core_BAO_UFGroup::getProfiles(array(
'Contact',
'Individual',
'Organization',
'Household',
));
}
/**
* @return array
*/
public static function getContactReferenceOptions() {
return array(
ts('Contact Name') => 1,
) + array_flip(CRM_Core_OptionGroup::values('contact_reference_options',
FALSE, FALSE, TRUE
));
}
}

View file

@ -0,0 +1,265 @@
<?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 Smtp Server.
*/
class CRM_Admin_Form_Setting_Smtp extends CRM_Admin_Form_Setting {
protected $_testButtonName;
/**
* Build the form object.
*/
public function buildQuickForm() {
$outBoundOption = array(
CRM_Mailing_Config::OUTBOUND_OPTION_MAIL => ts('mail()'),
CRM_Mailing_Config::OUTBOUND_OPTION_SMTP => ts('SMTP'),
CRM_Mailing_Config::OUTBOUND_OPTION_SENDMAIL => ts('Sendmail'),
CRM_Mailing_Config::OUTBOUND_OPTION_DISABLED => ts('Disable Outbound Email'),
CRM_Mailing_Config::OUTBOUND_OPTION_REDIRECT_TO_DB => ts('Redirect to Database'),
);
$this->addRadio('outBound_option', ts('Select Mailer'), $outBoundOption);
CRM_Utils_System::setTitle(ts('Settings - Outbound Mail'));
$this->add('text', 'sendmail_path', ts('Sendmail Path'));
$this->add('text', 'sendmail_args', ts('Sendmail Argument'));
$this->add('text', 'smtpServer', ts('SMTP Server'));
$this->add('text', 'smtpPort', ts('SMTP Port'));
$this->addYesNo('smtpAuth', ts('Authentication?'));
$this->addElement('text', 'smtpUsername', ts('SMTP Username'));
$this->addElement('password', 'smtpPassword', ts('SMTP Password'));
$this->_testButtonName = $this->getButtonName('refresh', 'test');
$this->addFormRule(array('CRM_Admin_Form_Setting_Smtp', 'formRule'));
parent::buildQuickForm();
$buttons = $this->getElement('buttons')->getElements();
$buttons[] = $this->createElement('submit', $this->_testButtonName, ts('Save & Send Test Email'), array('crm-icon' => 'fa-envelope-o'));
$this->getElement('buttons')->setElements($buttons);
}
/**
* Process the form submission.
*/
public function postProcess() {
// flush caches so we reload details for future requests
// CRM-11967
CRM_Utils_System::flushCache();
$formValues = $this->controller->exportValues($this->_name);
$buttonName = $this->controller->getButtonName();
// check if test button
if ($buttonName == $this->_testButtonName) {
if ($formValues['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_DISABLED) {
CRM_Core_Session::setStatus(ts('You have selected "Disable Outbound Email". A test email can not be sent.'), ts("Email Disabled"), "error");
}
elseif ($formValues['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_REDIRECT_TO_DB) {
CRM_Core_Session::setStatus(ts('You have selected "Redirect to Database". A test email can not be sent.'), ts("Email Disabled"), "error");
}
else {
$session = CRM_Core_Session::singleton();
$userID = $session->get('userID');
list($toDisplayName, $toEmail, $toDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($userID);
//get the default domain email address.CRM-4250
list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
if (!$domainEmailAddress || $domainEmailAddress == 'info@EXAMPLE.ORG') {
$fixUrl = CRM_Utils_System::url("civicrm/admin/domain", 'action=update&reset=1');
CRM_Core_Error::fatal(ts('The site administrator needs to enter a valid \'FROM Email Address\' in <a href="%1">Administer CiviCRM &raquo; Communications &raquo; FROM Email Addresses</a>. The email address used may need to be a valid mail account with your email service provider.', array(1 => $fixUrl)));
}
if (!$toEmail) {
CRM_Core_Error::statusBounce(ts('Cannot send a test email because your user record does not have a valid email address.'));
}
if (!trim($toDisplayName)) {
$toDisplayName = $toEmail;
}
$to = '"' . $toDisplayName . '"' . "<$toEmail>";
$from = '"' . $domainEmailName . '" <' . $domainEmailAddress . '>';
$testMailStatusMsg = ts('Sending test email. FROM: %1 TO: %2.<br />', array(
1 => $domainEmailAddress,
2 => $toEmail,
));
$params = array();
if ($formValues['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_SMTP) {
$subject = "Test for SMTP settings";
$message = "SMTP settings are correct.";
$params['host'] = $formValues['smtpServer'];
$params['port'] = $formValues['smtpPort'];
if ($formValues['smtpAuth']) {
$params['username'] = $formValues['smtpUsername'];
$params['password'] = $formValues['smtpPassword'];
$params['auth'] = TRUE;
}
else {
$params['auth'] = FALSE;
}
// set the localhost value, CRM-3153, CRM-9332
$params['localhost'] = $_SERVER['SERVER_NAME'];
// also set the timeout value, lets set it to 30 seconds
// CRM-7510, CRM-9332
$params['timeout'] = 30;
$mailerName = 'smtp';
}
elseif ($formValues['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_SENDMAIL) {
$subject = "Test for Sendmail settings";
$message = "Sendmail settings are correct.";
$params['sendmail_path'] = $formValues['sendmail_path'];
$params['sendmail_args'] = $formValues['sendmail_args'];
$mailerName = 'sendmail';
}
elseif ($formValues['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_MAIL) {
$subject = "Test for PHP mail settings";
$message = "mail settings are correct.";
$mailerName = 'mail';
}
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject,
);
$mailer = Mail::factory($mailerName, $params);
$errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
$result = $mailer->send($toEmail, $headers, $message);
unset($errorScope);
if (defined('CIVICRM_MAIL_LOG')) {
CRM_Core_Session::setStatus($testMailStatusMsg . ts('You have defined CIVICRM_MAIL_LOG - no mail will be sent. Your %1 settings have not been tested.', array(1 => strtoupper($mailerName))), ts("Mail not sent"), "warning");
}
elseif (!is_a($result, 'PEAR_Error')) {
CRM_Core_Session::setStatus($testMailStatusMsg . ts('Your %1 settings are correct. A test email has been sent to your email address.', array(1 => strtoupper($mailerName))), ts("Mail Sent"), "success");
}
else {
$message = CRM_Utils_Mail::errorMessage($mailer, $result);
CRM_Core_Session::setStatus($testMailStatusMsg . ts('Oops. Your %1 settings are incorrect. No test mail has been sent.', array(1 => strtoupper($mailerName))) . $message, ts("Mail Not Sent"), "error");
}
}
}
$mailingBackend = Civi::settings()->get('mailing_backend');
if (!empty($mailingBackend)) {
$formValues = array_merge($mailingBackend, $formValues);
}
// if password is present, encrypt it
if (!empty($formValues['smtpPassword'])) {
$formValues['smtpPassword'] = CRM_Utils_Crypt::encrypt($formValues['smtpPassword']);
}
Civi::settings()->set('mailing_backend', $formValues);
}
/**
* Global validation rules for the form.
*
* @param array $fields
* Posted values of the form.
*
* @return array
* list of errors to be posted back to the form
*/
public static function formRule($fields) {
if ($fields['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_SMTP) {
if (empty($fields['smtpServer'])) {
$errors['smtpServer'] = 'SMTP Server name is a required field.';
}
if (empty($fields['smtpPort'])) {
$errors['smtpPort'] = 'SMTP Port is a required field.';
}
if (!empty($fields['smtpAuth'])) {
if (empty($fields['smtpUsername'])) {
$errors['smtpUsername'] = 'If your SMTP server requires authentication please provide a valid user name.';
}
if (empty($fields['smtpPassword'])) {
$errors['smtpPassword'] = 'If your SMTP server requires authentication, please provide a password.';
}
}
}
if ($fields['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_SENDMAIL) {
if (!$fields['sendmail_path']) {
$errors['sendmail_path'] = 'Sendmail Path is a required field.';
}
if (!$fields['sendmail_args']) {
$errors['sendmail_args'] = 'Sendmail Argument is a required field.';
}
}
return empty($errors) ? TRUE : $errors;
}
/**
* Set default values for the form.
*/
public function setDefaultValues() {
if (!$this->_defaults) {
$this->_defaults = array();
$mailingBackend = Civi::settings()->get('mailing_backend');
if (!empty($mailingBackend)) {
$this->_defaults = $mailingBackend;
if (!empty($this->_defaults['smtpPassword'])) {
$this->_defaults['smtpPassword'] = CRM_Utils_Crypt::decrypt($this->_defaults['smtpPassword']);
}
}
else {
if (!isset($this->_defaults['smtpServer'])) {
$this->_defaults['smtpServer'] = 'localhost';
$this->_defaults['smtpPort'] = 25;
$this->_defaults['smtpAuth'] = 0;
}
if (!isset($this->_defaults['sendmail_path'])) {
$this->_defaults['sendmail_path'] = '/usr/sbin/sendmail';
$this->_defaults['sendmail_args'] = '-i';
}
}
}
return $this->_defaults;
}
}

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
*/
/**
* This class generates form components for Site Url.
*/
class CRM_Admin_Form_Setting_UF extends CRM_Admin_Form_Setting {
protected $_settings = array();
protected $_uf = NULL;
/**
* Build the form object.
*/
public function buildQuickForm() {
$config = CRM_Core_Config::singleton();
$this->_uf = $config->userFramework;
$this->_settings['syncCMSEmail'] = CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME;
if ($this->_uf == 'WordPress') {
$this->_settings['wpBasePage'] = CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME;
}
CRM_Utils_System::setTitle(
ts('Settings - %1 Integration', array(1 => $this->_uf))
);
if ($config->userSystem->is_drupal) {
$this->_settings['userFrameworkUsersTableName'] = CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME;
}
// find out if drupal has its database prefixed
global $databases;
$drupal_prefix = '';
if (isset($databases['default']['default']['prefix'])) {
if (is_array($databases['default']['default']['prefix'])) {
$drupal_prefix = $databases['default']['default']['prefix']['default'];
}
else {
$drupal_prefix = $databases['default']['default']['prefix'];
}
}
if (
function_exists('module_exists') &&
module_exists('views') &&
(
$config->dsn != $config->userFrameworkDSN || !empty($drupal_prefix)
)
) {
$dsnArray = DB::parseDSN($config->dsn);
$tableNames = CRM_Core_DAO::getTableNames();
$tablePrefixes = '$databases[\'default\'][\'default\'][\'prefix\']= array(';
$tablePrefixes .= "\n 'default' => '$drupal_prefix',"; // add default prefix: the drupal database prefix
$prefix = "";
if ($config->dsn != $config->userFrameworkDSN) {
$prefix = "`{$dsnArray['database']}`.";
}
foreach ($tableNames as $tableName) {
$tablePrefixes .= "\n '" . str_pad($tableName . "'", 41) . " => '{$prefix}',";
}
$tablePrefixes .= "\n);";
$this->assign('tablePrefixes', $tablePrefixes);
}
parent::buildQuickForm();
}
}

View file

@ -0,0 +1,86 @@
<?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 Error Handling and Debugging
*/
class CRM_Admin_Form_Setting_UpdateConfigBackend extends CRM_Admin_Form_Setting {
/**
* Build the form object.
*/
public function buildQuickForm() {
CRM_Utils_System::setTitle(ts('Settings - Cleanup Caches and Update Paths'));
$this->addElement(
'submit', $this->getButtonName('next', 'cleanup'), 'Cleanup Caches',
array('class' => 'crm-form-submit', 'id' => 'cleanup-cache')
);
$this->addElement(
'submit', $this->getButtonName('next', 'resetpaths'), 'Reset Paths',
array('class' => 'crm-form-submit', 'id' => 'resetpaths')
);
//parent::buildQuickForm();
}
public function postProcess() {
if (!empty($_POST['_qf_UpdateConfigBackend_next_cleanup'])) {
$config = CRM_Core_Config::singleton();
// cleanup templates_c directory
$config->cleanup(1, FALSE);
// clear all caches
CRM_Core_Config::clearDBCache();
CRM_Utils_System::flushCache();
parent::rebuildMenu();
CRM_Core_BAO_WordReplacement::rebuild();
CRM_Core_Session::setStatus(ts('Cache has been cleared and menu has been rebuilt successfully.'), ts("Success"), "success");
}
if (!empty($_POST['_qf_UpdateConfigBackend_next_resetpaths'])) {
$msg = CRM_Core_BAO_ConfigSetting::doSiteMove();
CRM_Core_Session::setStatus($msg, ts("Success"), "success");
}
return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/setting/updateConfigBackend', 'reset=1'));
}
}

View file

@ -0,0 +1,103 @@
<?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 Site Url.
*/
class CRM_Admin_Form_Setting_Url extends CRM_Admin_Form_Setting {
protected $_settings = array(
'disable_core_css' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'userFrameworkResourceURL' => CRM_Core_BAO_Setting::URL_PREFERENCES_NAME,
'imageUploadURL' => CRM_Core_BAO_Setting::URL_PREFERENCES_NAME,
'customCSSURL' => CRM_Core_BAO_Setting::URL_PREFERENCES_NAME,
'extensionsURL' => CRM_Core_BAO_Setting::URL_PREFERENCES_NAME,
);
/**
* Build the form object.
*/
public function buildQuickForm() {
CRM_Utils_System::setTitle(ts('Settings - Resource URLs'));
$settingFields = civicrm_api('setting', 'getfields', array(
'version' => 3,
));
$this->addYesNo('enableSSL', ts('Force Secure URLs (SSL)'));
$this->addYesNo('verifySSL', ts('Verify SSL Certs'));
// FIXME: verifySSL should use $_settings instead of manually adding fields
$this->assign('verifySSL_description', $settingFields['values']['verifySSL']['description']);
$this->addFormRule(array('CRM_Admin_Form_Setting_Url', 'formRule'));
parent::buildQuickForm();
}
/**
* @param $fields
*
* @return array|bool
*/
public static function formRule($fields) {
if (isset($fields['enableSSL']) &&
$fields['enableSSL']
) {
$config = CRM_Core_Config::singleton();
$url = str_replace('http://', 'https://',
CRM_Utils_System::url('civicrm/dashboard', 'reset=1', TRUE,
NULL, FALSE, FALSE
)
);
if (!CRM_Utils_System::checkURL($url, TRUE)) {
$errors = array(
'enableSSL' => ts('You need to set up a secure server before you can use the Force Secure URLs option'),
);
return $errors;
}
}
return TRUE;
}
public function postProcess() {
// if extensions url is set, lets clear session status messages to avoid
// a potentially spurious message which might already have been set. This
// is a bit hackish
// CRM-10629
$session = CRM_Core_Session::singleton();
$session->getStatus(TRUE);
parent::postProcess();
parent::rebuildMenu();
}
}

View file

@ -0,0 +1,240 @@
<?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_Admin_Form_WordReplacements extends CRM_Core_Form {
protected $_numStrings = 10;
protected $_stringName = NULL;
public $unsavedChangesWarn = TRUE;
/**
* Pre process function.
*/
public function preProcess() {
// This controller was originally written to CRUD $config->locale_custom_strings,
// but that's no longer the canonical store. Re-sync from canonical store to ensure
// that we display that latest data. This is inefficient - at some point, we
// should rewrite this UI.
CRM_Core_BAO_WordReplacement::rebuild(FALSE);
$this->_soInstance = CRM_Utils_Array::value('instance', $_GET);
$this->assign('soInstance', $this->_soInstance);
}
/**
* Set default values.
*
* @return array
*/
public function setDefaultValues() {
if (!empty($this->_defaults)) {
return $this->_defaults;
}
$this->_defaults = array();
$config = CRM_Core_Config::singleton();
$values = CRM_Core_BAO_WordReplacement::getLocaleCustomStrings($config->lcMessages);
$i = 1;
$enableDisable = array(
1 => 'enabled',
0 => 'disabled',
);
$cardMatch = array('wildcardMatch', 'exactMatch');
foreach ($enableDisable as $key => $val) {
foreach ($cardMatch as $kc => $vc) {
if (!empty($values[$val][$vc])) {
foreach ($values[$val][$vc] as $k => $v) {
$this->_defaults["enabled"][$i] = $key;
$this->_defaults["cb"][$i] = $kc;
$this->_defaults["old"][$i] = $k;
$this->_defaults["new"][$i] = $v;
$i++;
}
}
}
}
return $this->_defaults;
}
/**
* Build the form object.
*/
public function buildQuickForm() {
$config = CRM_Core_Config::singleton();
$values = CRM_Core_BAO_WordReplacement::getLocaleCustomStrings($config->lcMessages);
//CRM-14179
$instances = 0;
foreach ($values as $valMatchType) {
foreach ($valMatchType as $valPairs) {
$instances += count($valPairs);
}
}
if ($instances > 10) {
$this->_numStrings = $instances;
}
$soInstances = range(1, $this->_numStrings, 1);
$stringOverrideInstances = array();
if ($this->_soInstance) {
$soInstances = array($this->_soInstance);
}
elseif (!empty($_POST['old'])) {
$soInstances = $stringOverrideInstances = array_keys($_POST['old']);
}
elseif (!empty($this->_defaults) && is_array($this->_defaults)) {
$stringOverrideInstances = array_keys($this->_defaults['new']);
if (count($this->_defaults['old']) > count($this->_defaults['new'])) {
$stringOverrideInstances = array_keys($this->_defaults['old']);
}
}
foreach ($soInstances as $instance) {
$this->addElement('checkbox', "enabled[$instance]");
$this->add('textarea', "old[$instance]", NULL, array('rows' => 1, 'cols' => 40));
$this->add('textarea', "new[$instance]", NULL, array('rows' => 1, 'cols' => 40));
$this->addElement('checkbox', "cb[$instance]");
}
$this->assign('numStrings', $this->_numStrings);
if ($this->_soInstance) {
return;
}
$this->assign('stringOverrideInstances', empty($stringOverrideInstances) ? FALSE : $stringOverrideInstances);
$this->addButtons(array(
array(
'type' => 'next',
'name' => ts('Save'),
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
)
);
$this->addFormRule(array('CRM_Admin_Form_WordReplacements', 'formRule'), $this);
}
/**
* Global validation rules for the form.
*
* @param array $values
* Posted values of the form.
*
* @return array
* list of errors to be posted back to the form
*/
public static function formRule($values) {
$errors = array();
$oldValues = CRM_Utils_Array::value('old', $values);
$newValues = CRM_Utils_Array::value('new', $values);
$enabled = CRM_Utils_Array::value('enabled', $values);
$exactMatch = CRM_Utils_Array::value('cb', $values);
foreach ($oldValues as $k => $v) {
if ($v && !$newValues[$k]) {
$errors['new[' . $k . ']'] = ts('Please Enter the value for Replacement Word');
}
elseif (!$v && $newValues[$k]) {
$errors['old[' . $k . ']'] = ts('Please Enter the value for Original Word');
}
elseif ((empty($newValues[$k]) && empty($oldValues[$k]))
&& (!empty($enabled[$k]) || !empty($exactMatch[$k]))
) {
$errors['old[' . $k . ']'] = ts('Please Enter the value for Original Word');
$errors['new[' . $k . ']'] = ts('Please Enter the value for Replacement Word');
}
}
return $errors;
}
/**
* Process the form submission.
*/
public function postProcess() {
$params = $this->controller->exportValues($this->_name);
$this->_numStrings = count($params['old']);
$enabled['exactMatch'] = $enabled['wildcardMatch'] = $disabled['exactMatch'] = $disabled['wildcardMatch'] = array();
for ($i = 1; $i <= $this->_numStrings; $i++) {
if (!empty($params['new'][$i]) && !empty($params['old'][$i])) {
if (isset($params['enabled']) && !empty($params['enabled'][$i])) {
if (!empty($params['cb']) && !empty($params['cb'][$i])) {
$enabled['exactMatch'] += array($params['old'][$i] => $params['new'][$i]);
}
else {
$enabled['wildcardMatch'] += array($params['old'][$i] => $params['new'][$i]);
}
}
else {
if (isset($params['cb']) && is_array($params['cb']) && array_key_exists($i, $params['cb'])) {
$disabled['exactMatch'] += array($params['old'][$i] => $params['new'][$i]);
}
else {
$disabled['wildcardMatch'] += array($params['old'][$i] => $params['new'][$i]);
}
}
}
}
$overrides = array(
'enabled' => $enabled,
'disabled' => $disabled,
);
$config = CRM_Core_Config::singleton();
CRM_Core_BAO_WordReplacement::setLocaleCustomStrings($config->lcMessages, $overrides);
// This controller was originally written to CRUD $config->locale_custom_strings,
// but that's no longer the canonical store. Sync changes to canonical store
// (civicrm_word_replacement table in the database).
// This is inefficient - at some point, we should rewrite this UI.
CRM_Core_BAO_WordReplacement::rebuildWordReplacementTable();
CRM_Core_Session::setStatus("", ts("Settings Saved"), "success");
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/options/wordreplacements',
"reset=1"
));
}
}