Fix spelling and capitalization of Contact ID and External ID
[civicrm-core.git] / CRM / Profile / Form / Edit.php
index 4c5289b4f8cd7d513997391f107bcfa6d1367f34..4885617df1a861909d39bf941c44ad800d468abf 100644 (file)
@@ -113,26 +113,30 @@ class CRM_Profile_Form_Edit extends CRM_Profile_Form {
 
     parent::preProcess();
 
-    // make sure the gid is set and valid
-    if (!$this->_gid) {
-      CRM_Core_Error::fatal(ts('The requested Profile (gid=%1) is disabled, OR there is no Profile with that ID, OR a valid \'gid=\' integer value is missing from the URL. Contact the site administrator if you need assistance.',
-          array(1 => $this->_gid)
-        ));
-    }
-
     // 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)
+      ));
     }
   }
 
@@ -143,11 +147,7 @@ SELECT module
    * @access public
    */
   public function buildQuickForm() {
-    // add the hidden field to redirect the postProcess from
-    $ufGroup = new CRM_Core_DAO_UFGroup();
-
-    $ufGroup->id = $this->_gid;
-    if (!$ufGroup->find(TRUE)) {
+    if (empty($this->_ufGroup['id'])) {
       CRM_Core_Error::fatal();
     }
 
@@ -157,24 +157,20 @@ SELECT module
         'Edit ' . $this->_customGroupTitle . ' Record' : $this->_customGroupTitle;
 
     } else {
-      $groupTitle = $ufGroup->title;
+      $groupTitle = $this->_ufGroup['title'];
     }
     CRM_Utils_System::setTitle($groupTitle);
     $this->assign('recentlyViewed', FALSE);
 
     if ($this->_context != 'dialog') {
-      $this->_postURL = CRM_Utils_Array::value('postURL', $_POST);
-      $this->_cancelURL = CRM_Utils_Array::value('cancelURL', $_POST);
+      $this->_postURL = $this->_ufGroup['post_URL'];
+      $this->_cancelURL = $this->_ufGroup['cancel_URL'];
 
       $gidString = $this->_gid;
       if (!empty($this->_profileIds)) {
         $gidString = implode(',', $this->_profileIds);
       }
 
-      if (!$this->_postURL) {
-        $this->_postURL = $ufGroup->post_URL;
-      }
-
       if (!$this->_postURL) {
         if ($this->_context == 'Search') {
           $this->_postURL = CRM_Utils_System::url('civicrm/contact/search');
@@ -193,25 +189,15 @@ SELECT module
       }
 
       if (!$this->_cancelURL) {
-        if ($ufGroup->cancel_URL) {
-          $this->_cancelURL = $ufGroup->cancel_URL;
-        }
-        else {
-          $this->_cancelURL = CRM_Utils_System::url('civicrm/profile',
-            "reset=1&gid={$gidString}"
-          );
-        }
+        $this->_cancelURL = CRM_Utils_System::url('civicrm/profile',
+          "reset=1&gid={$gidString}"
+        );
       }
 
       // we do this gross hack since qf also does entity replacement
       $this->_postURL = str_replace('&', '&', $this->_postURL);
       $this->_cancelURL = str_replace('&', '&', $this->_cancelURL);
 
-      $this->addElement('hidden', 'postURL', $this->_postURL);
-      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) {
@@ -236,6 +222,7 @@ SELECT module
         'type' => 'cancel',
         'name' => ts('Cancel'),
         'isDefault' => TRUE,
+        'js' => array('onclick' => "location.href='{$this->_cancelURL}'; return false;"),
       );
       $this->addButtons($buttons);
       return;
@@ -262,6 +249,7 @@ SELECT module
       'type' => 'cancel',
       'name' => ts('Cancel'),
       'isDefault' => TRUE,
+      'js' => array('onclick' => "location.href='{$this->_cancelURL}'; return false;"),
     );
 
     $this->addButtons($buttons);