<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.4 |
+ | CiviCRM version 4.5 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013 |
+ | Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
* $Id$
*
*/
// and also the profile is of type 'Profile'
$query = "
-SELECT module
- FROM civicrm_uf_join
- WHERE module = 'Profile'
- AND uf_group_id = %1
+SELECT module,is_reserved
+ FROM civicrm_uf_group
+ LEFT JOIN civicrm_uf_join ON uf_group_id = civicrm_uf_group.id
+ WHERE civicrm_uf_group.id = %1
";
+
$params = array(1 => array($this->_gid, 'Integer'));
$dao = CRM_Core_DAO::executeQuery($query, $params);
- if (!$dao->fetch()) {
+
+ $isProfile = FALSE;
+ while ($dao->fetch()) {
+ $isProfile = ($isProfile || ($dao->module == "Profile"));
+ }
+
+ //Check that the user has the "add contacts" Permission
+ $canAdd = CRM_Core_Permission::check("add contacts");
+
+ //Remove need for Profile module type when using reserved profiles [CRM-14488]
+ if (!$dao->N || (!$isProfile && !($dao->is_reserved && $canAdd))) {
CRM_Core_Error::fatal(ts('The requested Profile (gid=%1) is not configured to be used for \'Profile\' edit and view forms in its Settings. Contact the site administrator if you need assistance.',
- array(1 => $this->_gid)
- ));
+ array(1 => $this->_gid)
+ ));
}
}
);
}
- if ($this->_multiRecordProfile) {
- $urlParams = "reset=1&id={$this->_id}&gid={$gidString}";
-
- // get checksum if present
- if ($this->get('cs')) {
- $urlParams .= "&cs=" . $this->get('cs');
- }
- $this->_postURL = CRM_Utils_System::url('civicrm/profile/edit', $urlParams);
- $this->_cancelURL = CRM_Utils_System::url('civicrm/profile/edit', $urlParams);
-
- //passing the post url to template so the popup form does
- //proper redirection and proccess form errors if any
- if (!isset($this->_onPopupClose) || $this->_onPopupClose == 'redirectToProfile') {
- $popupRedirect = CRM_Utils_System::url('civicrm/profile/edit', $urlParams, FALSE, NULL, FALSE);
- }
- elseif ($this->_onPopupClose == 'redirectToTab') {
- $popupRedirect = CRM_Utils_System::url('civicrm/contact/view',
- "reset=1&cid={$this->_id}&selectedChild=custom_{$this->_customGroupId}", FALSE, NULL, FALSE);
- }
-
- $this->assign('urlParams', $urlParams);
- $this->assign('postUrl', $popupRedirect);
- }
-
// we do this gross hack since qf also does entity replacement
$this->_postURL = str_replace('&', '&', $this->_postURL);
$this->_cancelURL = str_replace('&', '&', $this->_cancelURL);
- if ($this->_cancelURL) {
- $this->addElement('hidden', 'cancelURL', $this->_cancelURL);
- }
-
// also retain error URL if set
$this->_errorURL = CRM_Utils_Array::value('errorURL', $_POST);
if ($this->_errorURL) {
if (($this->_multiRecord & CRM_Core_Action::DELETE) && $this->_recordExists) {
$this->_deleteButtonName = $this->getButtonName('upload', 'delete');
- $this->addElement('submit',
- $this->_deleteButtonName,
- ts('Delete')
- );
+ $this->addElement('submit', $this->_deleteButtonName, ts('Delete'));
$buttons[] = array(
'type' => 'cancel',
'name' => ts('Cancel'),
'isDefault' => TRUE,
+ 'js' => array('onclick' => "location.href='{$this->_cancelURL}'; return false;"),
);
$this->addButtons($buttons);
return;
'isDefault' => TRUE,
);
- if ($this->_context != 'dialog') {
- $buttons[] = array(
- 'type' => 'cancel',
- 'name' => ts('Cancel'),
- 'isDefault' => TRUE,
- );
- }
+ $buttons[] = array(
+ 'type' => 'cancel',
+ 'name' => ts('Cancel'),
+ 'isDefault' => TRUE,
+ 'js' => array('onclick' => "location.href='{$this->_cancelURL}'; return false;"),
+ );
$this->addButtons($buttons);
public function postProcess() {
parent::postProcess();
- // this is special case when we create contact using Dialog box
- if ($this->_context == 'dialog') {
- $displayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_id, 'display_name');
- $sortName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_id, 'sort_name');
- $returnArray = array(
- 'contactID' => $this->_id,
- 'displayName' => $displayName,
- 'sortName' => $sortName,
- 'newContactSuccess' => TRUE,
- );
-
- echo json_encode($returnArray);
- CRM_Utils_System::civiExit();
- }
+ $displayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_id, 'display_name');
+ $sortName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_id, 'sort_name');
+ $this->ajaxResponse['label'] = $sortName;
- //for delete record handling
- if (!CRM_Utils_Array::value($this->_deleteButtonName, $_POST)) {
+ // When saving (not deleting) and not in an ajax popup
+ if (empty($_POST[$this->_deleteButtonName]) && $this->_context != 'dialog') {
CRM_Core_Session::setStatus(ts('Your information has been saved.'), ts('Thank you.'), 'success');
}
function validate() {
$errors = parent::validate();
- if (!$errors &&
- CRM_Utils_Array::value('errorURL', $_POST)
- ) {
+ if (!$errors && !empty($_POST['errorURL'])) {
$message = NULL;
foreach ($this->_errors as $name => $mess) {
$message .= $mess;