refactoring phase1
authormonishdeb <monish.deb@webaccessglobal.com>
Fri, 4 Sep 2015 05:08:47 +0000 (10:38 +0530)
committermonishdeb <monish.deb@webaccessglobal.com>
Thu, 10 Sep 2015 08:24:30 +0000 (13:54 +0530)
CRM/Contact/Form/ProfileContact.php
CRM/Contribute/Form/Contribution/Main.php
CRM/Contribute/Form/ContributionBase.php
CRM/Core/xml/Menu/Contact.xml
templates/CRM/Contact/Form/ProfileContact.tpl [new file with mode: 0644]
templates/CRM/Contribute/Form/Contribution/Main.tpl
templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl [deleted file]

index 59b9d279fdcc1c76dbaf3817999c6636a868b376..5fc1a7eb7875ba69e39b21ea107c948bdf696ab6 100644 (file)
  * @package CRM
  * @copyright CiviCRM LLC (c) 2004-2015
  */
-class CRM_Contact_Form_ProfileContact {
+class CRM_Contact_Form_ProfileContact extends CRM_Core_Form {
 
-  protected $_mode;
+  protected $_profileId;
+
+  protected $_prefix;
 
   /**
    * Set variables up before form is built.
    *
    * @param CRM_Core_Form $form
    */
-  public static function preProcess(&$form) {
-    $contactID = $form->_contactID;
-
-    foreach (array('soft_credit', 'on_behalf') as $module) {
-      $ufJoinParams = array(
-        'module' => $module,
-        'entity_table' => 'civicrm_contribution_page',
-        'entity_id' => $form->_id,
-      );
-
-      $ufJoin = new CRM_Core_DAO_UFJoin();
-      $ufJoin->copyValues($ufJoinParams);
-      $ufJoin->find(TRUE);
-      if (!$ufJoin->is_active) {
-        continue;
-      }
-
-      if ($module == 'soft_credit') {
-        $form->_honoreeProfileId = $ufJoin->uf_group_id;
-        $form->_honor_block_is_active = $ufJoin->is_active;
-
-        if (!$form->_honoreeProfileId ||
-          !CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_honoreeProfileId, 'is_active')
-        ) {
-          CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of honoree and the selected honoree profile is either disabled or not found.'));
-        }
-
-        $profileContactType = CRM_Core_BAO_UFGroup::getContactType($form->_honoreeProfileId);
-        $requiredProfileFields = array(
-          'Individual' => array('first_name', 'last_name'),
-          'Organization' => array('organization_name', 'email'),
-          'Household' => array('household_name', 'email'),
-        );
-        $validProfile = CRM_Core_BAO_UFGroup::checkValidProfile($form->_honoreeProfileId, $requiredProfileFields[$profileContactType]);
-        if (!$validProfile) {
-          CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of honoree and the required fields of the selected honoree profile are disabled or doesn\'t exist.'));
-        }
-      }
-      else {
-        $form->_onbehalf = FALSE;
-        $params = CRM_Contribute_BAO_ContributionPage::formatModuleData($ufJoin->module_data, TRUE, 'on_behalf');
-        $form->_values = array_merge($params, $form->_values);
-        if (CRM_Utils_Array::value('is_for_organization', $params)) {
-          if ($params['is_for_organization'] == 2) {
-            $form->_onBehalfRequired = TRUE;
-          }
-          // Add organization profile if 1 of the following are true:
-          // If the org profile is required
-          if ($form->_onBehalfRequired ||
-            // Or we are building the form for the first time
-            empty($_POST) ||
-            // Or the user has submitted the form and checked the "On Behalf" checkbox
-            !empty($_POST['is_for_organization'])
-          ) {
-            $form->_onbehalf = TRUE;
-            $form->_onBehalfProfileId = $ufJoin->uf_group_id;
-
-            if (!$form->_onBehalfProfileId ||
-              !CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_onBehalfProfileId, 'is_active')
-            ) {
-              CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of an organization and the selected onbehalf profile is either disabled or not found.'));
-            }
-
-            $requiredProfileFields = array('organization_name', 'email');
-            $validProfile = CRM_Core_BAO_UFGroup::checkValidProfile($form->_onBehalfProfileId, $requiredProfileFields);
-            if (!$validProfile) {
-              CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of an organization and the required fields of the selected onbehalf profile are disabled.'));
-            }
-
-            //CRM-5001,CRM-15787
-            $member = CRM_Member_BAO_Membership::getMembershipBlock($form->_id);
-            if (empty($member['is_active'])) {
-              $msg = ts('Mixed profile not allowed for on behalf of registration/sign up.');
-              $onBehalfProfile = CRM_Core_BAO_UFGroup::profileGroups($form->_onBehalfProfileId);
-              foreach (array(
-                  'Individual',
-                  'Organization',
-                  'Household',
-                ) as $contactType) {
-                if (in_array($contactType, $onBehalfProfile) &&
-                  (in_array('Membership', $onBehalfProfile) ||
-                    in_array('Contribution', $onBehalfProfile)
-                  )
-                ) {
-                  CRM_Core_Error::fatal($msg);
-                }
-              }
-
-              if ($postID = CRM_Utils_Array::value('custom_post_id', $form->_values)) {
-                $postProfile = CRM_Core_BAO_UFGroup::profileGroups($postID);
-                foreach (array(
-                    'Individual',
-                    'Organization',
-                    'Household',
-                  ) as $contactType) {
-                  if (in_array($contactType, $postProfile) &&
-                    (in_array('Membership', $postProfile) ||
-                      in_array('Contribution', $postProfile)
-                    )
-                  ) {
-                    CRM_Core_Error::fatal($msg);
-                  }
-                }
-              }
-            }
-
-            $form->assign('profileId', $form->_onBehalfProfileId);
-            $form->assign('mode', $form->_mode);
-
-            if ($contactID) {
-              $form->_employers = CRM_Contact_BAO_Relationship::getPermissionedEmployer($contactID);
-
-              if (!empty($form->_membershipContactID) && $contactID != $form->_membershipContactID) {
-                // renewal case - membership being renewed may or may not be for organization
-                if (!empty($form->_employers) && array_key_exists($form->_membershipContactID, $form->_employers)) {
-                  // if _membershipContactID belongs to employers list, we can say:
-                  $form->_relatedOrganizationFound = TRUE;
-                }
-              }
-              elseif (!empty($form->_employers)) {
-                // not a renewal case and _employers list is not empty
-                $form->_relatedOrganizationFound = TRUE;
-              }
+  public function preProcess() {
+    parent::preProcess();
 
-              if ($form->_relatedOrganizationFound) {
-                // Related org url - pass checksum if needed
-                $args = array('cid' => '');
-                if (!empty($_GET['cs'])) {
-                  $args = array(
-                    'uid' => $form->_contactID,
-                    'cs' => $_GET['cs'],
-                    'cid' => '',
-                  );
-                }
-                $locDataURL = CRM_Utils_System::url('civicrm/ajax/permlocation', $args, FALSE, NULL, FALSE);
-                $form->assign('locDataURL', $locDataURL);
+    $this->_profileId = CRM_Utils_Request::retrieve('id', 'Positive', $this, NULL, FALSE, NULL, 'GET');
+    $this->_prefix = CRM_Utils_Request::retrieve('prefix', 'String', $this, NULL, FALSE, NULL, 'GET');
 
-                if (!empty($form->_submitValues['onbehalf'])) {
-                  if (!empty($form->_submitValues['onbehalfof_id'])) {
-                    $form->assign('submittedOnBehalf', $form->_submitValues['onbehalfof_id']);
-                  }
-                  $form->assign('submittedOnBehalfInfo', json_encode($form->_submitValues['onbehalf']));
-                }
-              }
-
-              if ($params['is_for_organization'] != 2) {
-                $form->assign('relatedOrganizationFound', $form->_relatedOrganizationFound);
-              }
-              else {
-                $form->assign('onBehalfRequired', $form->_onBehalfRequired);
-              }
-
-              if (count($form->_employers) == 1) {
-                foreach ($form->_employers as $id => $value) {
-                  $form->_organizationName = $value['name'];
-                  $orgId = $id;
-                }
-                $form->assign('orgId', $orgId);
-                $form->assign('organizationName', $form->_organizationName);
-              }
-            }
-          }
-        }
-        $form->assign('onBehalfRequired', $form->_onBehalfRequired);
-      }
-    }
+    $this->assign('suppressForm', TRUE);
+    $this->assign('snippet', TRUE);
+    $this->controller->_generateQFKey = FALSE;
   }
 
   /**
@@ -213,118 +58,81 @@ class CRM_Contact_Form_ProfileContact {
    * @param CRM_Core_Form $form
    *
    */
-  public static function buildQuickForm(&$form) {
-    if (!empty($form->_honor_block_is_active)) {
-      self::buildHonorBlock($form);
-    }
-
-    if (!empty($form->_onbehalf)) {
-      self::buildOnBehalfBlock($form);
-    }
-  }
-
-  /**
-   * @param $form
-   */
-  public static function postProcess($form) {
-  }
-
-  public static function buildHonorBlock(&$form) {
-    $form->assign('honor_block_is_active', TRUE);
+  public function buildQuickForm() {
+    $contactID = $this->getContactID();
+
+    if ($this->_prefix == 'onbehalf') {
+      $this->assign('fieldSetTitle', ts('Organization Details'));
+      $this->assign('profileId', $this->_profileId);
+
+      if ($contactID) {
+        $employer = CRM_Contact_BAO_Relationship::getPermissionedEmployer($contactID);
+
+        if (count($employer)) {
+          // Related org url - pass checksum if needed
+          $args = array('cid' => '');
+          if (!empty($_GET['cs'])) {
+            $args = array(
+              'uid' => $this->_contactID,
+              'cs' => $_GET['cs'],
+              'cid' => '',
+            );
+          }
+          $locDataURL = CRM_Utils_System::url('civicrm/ajax/permlocation', $args, FALSE, NULL, FALSE);
+          $this->assign('locDataURL', $locDataURL);
+        }
+        if (count($employer) > 1) {
+          $this->add('text', 'organization_id', ts('Select an existing related Organization OR enter a new one'));
+          $this->add('select', 'onbehalfof_id', '', CRM_Utils_Array::collect('name', $employer));
+
+          $orgOptions = array(
+            0 => ts('Select an existing organization'),
+            1 => ts('Enter a new organization'),
+          );
+          $this->addRadio('org_option', ts('options'), $orgOptions);
+          $this->setDefaults(array('org_option' => 0));
+        }
+        elseif (count($employer) == 1) {
+          foreach ($form->_employers as $id => $value) {
+            $form->assign('orgId', $id);
+            $form->assign('organizationName', $value['name']);
+          }
+        }
+      }
 
-    //build soft-credit section
-    CRM_Contribute_Form_SoftCredit::buildQuickForm($form);
+      $profileFields = CRM_Core_BAO_UFGroup::getFields($this->_profileId, FALSE, CRM_Core_Action::VIEW, NULL,
+                       NULL, FALSE, NULL, FALSE, NULL,
+                       CRM_Core_Permission::CREATE, NULL
+      );
+      $this->assign('onBehalfOfFields', $profileFields);
+      $this->addElement('hidden', 'onbehalf_profile_id', $this->_profileId);
+
+      $fieldTypes = array('Contact', 'Organization');
+      $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
+      $fieldTypes = array_merge($fieldTypes, $contactSubType);
+
+      foreach ($profileFields as $name => $field) {
+        if (in_array($field['field_type'], $fieldTypes)) {
+          list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2);
+          if (in_array($prefixName, array('organization_name', 'email')) && empty($field['is_required'])) {
+            $field['is_required'] = 1;
+          }
 
-    $ufGroup = new CRM_Core_DAO_UFGroup();
-    $ufGroup->id = $form->_honoreeProfileId;
-    if (!$ufGroup->find(TRUE)) {
-      CRM_Core_Error::fatal(ts('Chosen honoree profile for this contribution is disabled'));
+          CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, NULL, FALSE, $this->_prefix, NULL, $this->_prefix);
+        }
+      }
     }
 
-    $prefix = 'honor';
-    $honoreeProfileFields = CRM_Core_BAO_UFGroup::getFields($form->_honoreeProfileId, FALSE, NULL,
+/*$prefix = 'honor';
+
+    $honoreeProfileFields = CRM_Core_BAO_UFGroup::getFields(9, FALSE, NULL,
       NULL, NULL,
       FALSE, NULL,
       TRUE, NULL,
       CRM_Core_Permission::CREATE
     );
-    $form->addElement('hidden', 'honoree_profile_id', $form->_honoreeProfileId);
-    $form->assign('honoreeProfileFields', $honoreeProfileFields);
-
-    // add the form elements
-    foreach ($honoreeProfileFields as $name => $field) {
-      // If soft credit type is not chosen then make omit requiredness from honoree profile fields
-      if (count($form->_submitValues) && empty($form->_submitValues['soft_credit_type_id']) && !empty($field['is_required'])) {
-        $field['is_required'] = FALSE;
-      }
-      CRM_Core_BAO_UFGroup::buildProfile($form, $field, CRM_Profile_Form::MODE_CREATE, NULL, FALSE, FALSE, NULL, $prefix);
-    }
-  }
-
-  public static function buildOnBehalfBlock(&$form) {
-    $form->assign('buildOnBehalfForm', TRUE);
-    $form->assign('fieldSetTitle', ts('Organization Details'));
-
-    $contactID = $form->_contactID;
-
-    if ($form->_membershipContactID) {
-      $entityBlock = array('contact_id' => $form->_membershipContactID);
-      //CRM_Core_BAO_Location::getValues($entityBlock, $form->_defaults);
-    }
-
-    if (!$form->_onBehalfRequired) {
-      $form->addElement('checkbox', 'is_for_organization',
-        $form->_values['for_organization'],
-        NULL, array('onclick' => "showOnBehalf( );")
-      );
-    }
-
-    $form->assign('is_for_organization', TRUE);
-    $form->assign('urlPath', 'civicrm/contribute/transact');
-
-    if ($contactID && count($form->_employers) >= 1) {
-      $form->add('text', 'organization_id', ts('Select an existing related Organization OR enter a new one'));
-
-      $form->add('select', 'onbehalfof_id', '', CRM_Utils_Array::collect('name', $form->_employers));
-
-      $orgOptions = array(
-        0 => ts('Select an existing organization'),
-        1 => ts('Enter a new organization'),
-      );
-
-      $form->addRadio('org_option', ts('options'), $orgOptions);
-      $form->setDefaults(array('org_option' => 0));
-      $form->add('checkbox', 'mode', '');
-    }
-
-    $prefix = 'onbehalf';
-    $profileFields = CRM_Core_BAO_UFGroup::getFields($form->_onBehalfProfileId, FALSE, CRM_Core_Action::VIEW, NULL,
-      NULL, FALSE, NULL, FALSE, NULL,
-      CRM_Core_Permission::CREATE, NULL
-    );
-    $fieldTypes = array('Contact', 'Organization');
-    $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
-    $fieldTypes = array_merge($fieldTypes, $contactSubType);
-
-    if (is_array($form->_membershipBlock) && !empty($form->_membershipBlock)) {
-      $fieldTypes = array_merge($fieldTypes, array('Membership'));
-    }
-    else {
-      $fieldTypes = array_merge($fieldTypes, array('Contribution'));
-    }
-
-    foreach ($profileFields as $name => $field) {
-      if (in_array($field['field_type'], $fieldTypes)) {
-        list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2);
-        if (in_array($prefixName, array('organization_name', 'email')) && empty($field['is_required'])) {
-          $field['is_required'] = 1;
-        }
-
-        CRM_Core_BAO_UFGroup::buildProfile($form, $field, NULL, NULL, FALSE, $prefix, NULL, $prefix);
-      }
-    }
-
-    $form->assign('onBehalfOfFields', $profileFields);
-    $form->addElement('hidden', 'onbehalf_profile_id', $form->_onBehalfProfileId);
+    $this->addElement('hidden', 'honoree_profile_id', 9);
+    $this->assign('honoreeProfileFields', $honoreeProfileFields);
+*/
   }
 }
index 1f32a03635cfa37ab6854898b432ca4d148ca3bf..ce7a0d5ef950b6262b08fe2421d6046036606f1f 100644 (file)
@@ -78,13 +78,6 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
     $this->assign('mainDisplay', CRM_Utils_Request::retrieve('_qf_Main_display', 'Boolean',
       CRM_Core_DAO::$_nullObject));
 
-    CRM_Contact_Form_ProfileContact::preprocess($this);
-
-    if ($this->_snippet) {
-      $this->assign('isOnBehalfCallback', CRM_Utils_Array::value('onbehalf', $_GET, FALSE));
-      return;
-    }
-
     if (!empty($this->_pcpInfo['id']) && !empty($this->_pcpInfo['intro_text'])) {
       $this->assign('intro_text', $this->_pcpInfo['intro_text']);
     }
@@ -293,6 +286,8 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
     $this->buildCustom($this->_values['custom_pre_id'], 'customPre');
     $this->buildCustom($this->_values['custom_post_id'], 'customPost');
 
+    $this->buildComponentForm($this->_id, $this);
+
     if (!empty($this->_fields) && !empty($this->_values['custom_pre_id'])) {
       $profileAddressFields = array();
       foreach ($this->_fields as $key => $value) {
@@ -314,8 +309,6 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
       $this->assign('display_name', CRM_Contact_BAO_Contact::displayName($contactID));
     }
 
-    CRM_Contact_Form_ProfileContact::buildQuickForm($this);
-
     // Return if we are in an ajax callback
     if ($this->_onbehalf && $this->_snippet) {
       return;
index e4db6f63fc5a587a734239275f67f8b1d8e7e503..6f6e2bd0bd4e3a134fe07c8d5eaaf68bfff208fa 100644 (file)
@@ -710,6 +710,129 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
     }
   }
 
+
+  public function buildComponentForm($id, $form) {
+    if (empty($id)) {
+      return;
+    }
+
+    $contactID = $this->getContactID();
+
+    foreach (array('soft_credit', 'on_behalf') as $module) {
+      $ufJoinParams = array(
+        'module' => $module,
+        'entity_table' => 'civicrm_contribution_page',
+        'entity_id' => $id,
+      );
+
+      $ufJoin = new CRM_Core_DAO_UFJoin();
+      $ufJoin->copyValues($ufJoinParams);
+      $ufJoin->find(TRUE);
+      if (!$ufJoin->is_active) {
+        continue;
+      }
+
+      if ($module == 'soft_credit') {
+        $form->_honoreeProfileId = $ufJoin->uf_group_id;
+        $form->_honor_block_is_active = $ufJoin->is_active;
+
+        if (!$form->_honoreeProfileId ||
+          !CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_honoreeProfileId, 'is_active')
+        ) {
+          CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of honoree and the selected honoree profile is either disabled or not found.'));
+        }
+
+        $profileContactType = CRM_Core_BAO_UFGroup::getContactType($form->_honoreeProfileId);
+        $requiredProfileFields = array(
+          'Individual' => array('first_name', 'last_name'),
+          'Organization' => array('organization_name', 'email'),
+          'Household' => array('household_name', 'email'),
+        );
+        $validProfile = CRM_Core_BAO_UFGroup::checkValidProfile($form->_honoreeProfileId, $requiredProfileFields[$profileContactType]);
+        if (!$validProfile) {
+          CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of honoree and the required fields of the selected honoree profile are disabled or doesn\'t exist.'));
+        }
+
+        //build soft-credit section
+        CRM_Contribute_Form_SoftCredit::buildQuickForm($form);
+      }
+      else {
+        $params = CRM_Contribute_BAO_ContributionPage::formatModuleData($ufJoin->module_data, TRUE, 'on_behalf');
+        $form->_values = array_merge($params, $form->_values);
+
+        $onBehalfProfileId = $ufJoin->uf_group_id;
+
+        if (!$onBehalfProfileId ||
+          !CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $onBehalfProfileId, 'is_active')
+        ) {
+          CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of an organization and the selected onbehalf profile is either disabled or not found.'));
+        }
+
+        $member = CRM_Member_BAO_Membership::getMembershipBlock($form->_id);
+        if (empty($member['is_active'])) {
+          $msg = ts('Mixed profile not allowed for on behalf of registration/sign up.');
+          $onBehalfProfile = CRM_Core_BAO_UFGroup::profileGroups($onBehalfProfileId);
+          foreach (array(
+              'Individual',
+              'Organization',
+              'Household',
+            ) as $contactType) {
+            if (in_array($contactType, $onBehalfProfile) &&
+              (in_array('Membership', $onBehalfProfile) ||
+                in_array('Contribution', $onBehalfProfile)
+              )
+            ) {
+              CRM_Core_Error::fatal($msg);
+            }
+          }
+        }
+
+        if ($contactID) {
+          $form->_employers = CRM_Contact_BAO_Relationship::getPermissionedEmployer($contactID);
+
+          if (!empty($form->_membershipContactID) && $contactID != $form->_membershipContactID) {
+            // renewal case - membership being renewed may or may not be for organization
+            if (!empty($form->_employers) && array_key_exists($form->_membershipContactID, $form->_employers)) {
+              // if _membershipContactID belongs to employers list, we can say:
+              $form->_relatedOrganizationFound = TRUE;
+            }
+          }
+          elseif (!empty($form->_employers)) {
+            // not a renewal case and _employers list is not empty
+            $form->_relatedOrganizationFound = TRUE;
+          }
+
+          if ($params['is_for_organization'] != 2) {
+            $form->assign('relatedOrganizationFound', $form->_relatedOrganizationFound);
+          }
+          else {
+            $form->assign('onBehalfRequired', $form->_onBehalfRequired);
+          }
+
+          if (count($form->_employers) == 1) {
+            foreach ($form->_employers as $id => $value) {
+              $form->_organizationName = $value['name'];
+            }
+          }
+        }
+
+        if (CRM_Utils_Array::value('is_for_organization', $params)) {
+          if ($params['is_for_organization'] == 2) {
+            $this->assign('onBehalfRequired', TRUE);
+          }
+          else {
+            $form->addElement('checkbox', 'is_for_organization',
+              $form->_values['for_organization'],
+              NULL
+            );
+          }
+        }
+        $form->assign('onBehalfprofileId', $onBehalfProfileId);
+      }
+    }
+
+  }
+
   /**
    * Check template file exists.
    *
index 7f1ac88b2a4110640171edbd880689b1a2b25bfc..58987ab3720f34575ed4e65249f97ae060d332e1 100644 (file)
      <page_callback>CRM_Contact_Page_AJAX::flipDupePairs</page_callback>
      <access_arguments>merge duplicate contacts</access_arguments>
 </item>
+<item>
+    <path>civicrm/profileContact/form</path>
+    <access_callback>1</access_callback>
+    <page_callback>CRM_Contact_Form_ProfileContact</page_callback>
+    <is_public>true</is_public>
+    <weight>0</weight>
+</item>
 <item>
   <path>civicrm/activity/sms/add</path>
   <path_arguments>action=add</path_arguments>
diff --git a/templates/CRM/Contact/Form/ProfileContact.tpl b/templates/CRM/Contact/Form/ProfileContact.tpl
new file mode 100644 (file)
index 0000000..9c983a2
--- /dev/null
@@ -0,0 +1,195 @@
+{*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.6                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
+ +--------------------------------------------------------------------+
+ | 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        |
+ +--------------------------------------------------------------------+
+*}
+{**
+ * This file provides the HTML for the on-behalf-of form.
+ * Also used for related contact edit form.
+ * FIXME: This is way more complex than it needs to be
+ * FIXME: Why are we not just using the dynamic form tpl to display this profile?
+ *}
+{if $form.is_for_organization}
+  <div class="crm-section {$form.is_for_organization.name}-section">
+    <div class="label">&nbsp;</div>
+    <div class="content">
+      {$form.is_for_organization.html}&nbsp;{$form.is_for_organization.label}
+    </div>
+    <div class="clear"></div>
+  </div>
+{/if}
+
+<div id="on-behalf-block">
+  {crmRegion name="onbehalf-block"}
+    {if $onBehalfOfFields|@count}
+      <fieldset>
+      <legend>{$fieldSetTitle}</legend>
+      {if $form.org_option}
+        <div id='orgOptions' class="section crm-section">
+          <div class="content">
+            {$form.org_option.html}
+          </div>
+        </div>
+      {/if}
+      {include file="CRM/UF/Form/Block.tpl" fields=$onBehalfOfFields mode=8 prefix='onbehalf'}
+      </fieldset>
+    {/if}
+  {/crmRegion}
+</div>
+
+{literal}
+<script type="text/javascript">
+
+  CRM.$(function($) {
+    var snippet = {/literal}"{$snippet}"{literal};
+
+    $("#orgOptions").show( );
+    var orgOption = $("input:radio[name=org_option]:checked").val( ); 
+    selectCreateOrg(orgOption, false);
+
+    function resetValues() {
+     // Don't trip chain-select when clearing values
+     $('.crm-chain-select-control', "#select_org div").select2('val', '');
+     $('input[type=text], select, textarea', "#select_org div").not('.crm-chain-select-control, #onbehalfof_id').val('').change();
+     $('input[type=radio], input[type=checkbox]', "#select_org div").prop('checked', false).change();
+    }
+
+    function buildOnBehalfProfile(type) {
+      if (type == 0) {
+        $("#on-behalf-block").html('');
+        return;
+      }
+      {/literal}{if $onBehalfprofileId}
+        {capture assign='onBehalfprofileId'}id={$onBehalfprofileId}&{/capture};
+        var dataUrl = "{crmURL p='civicrm/profileContact/form' h=0 q="`$onBehalfprofileId`prefix=onbehalf"}";
+      {/if}{literal}
+      if (typeof dataUrl != 'undefined') {CRM.loadPage(dataUrl, {target: '#on-behalf-block'})};
+    }
+
+    if ($('#is_for_organization').length) {
+      $('#is_for_organization').on('change', function() {
+         var type = $(this).is(':checked') ? 1 : 0;
+         buildOnBehalfProfile(type);
+      });
+    }
+    else if (!snippet) {
+      var type = {/literal}"{$onBehalfRequired}"{literal}; 
+      buildOnBehalfProfile(type);
+    }
+
+   $("input:radio[name='org_option']").click( function( ) {
+     var orgOption = $(this).val();
+     selectCreateOrg(orgOption, true);
+   });
+
+   $('#onbehalfof_id').change(function() {
+    setLocationDetails($(this).val());
+   }).change();
+
+   function selectCreateOrg( orgOption, reset ) {
+    if (orgOption == 0) {
+      $("#onbehalfof_id").show().change();
+      $("input#onbehalf_organization_name").hide();
+    }
+    else if ( orgOption == 1 ) {
+      $("input#onbehalf_organization_name").show();
+      $("#onbehalfof_id").hide();
+    }
+
+    if ( reset ) {
+      resetValues();
+    }
+  }
+
+function setLocationDetails(contactID , reset) {
+  var submittedCID = {/literal}"{$submittedOnBehalf}"{literal};
+  var submittedOnBehalfInfo = {/literal}'{$submittedOnBehalfInfo}'{literal};
+  if (submittedOnBehalfInfo) {
+    submittedOnBehalfInfo = $.parseJSON(submittedOnBehalfInfo);
+
+    if (submittedCID == contactID) {
+      $.each(submittedOnBehalfInfo, function(key, value) {
+        $('#onbehalf_' + key ).val(value);
+      });
+      return;
+    }
+  }
+
+  resetValues();
+  var locationUrl = {/literal}"{$locDataURL}"{literal} + contactID + "&ufId=" + {/literal}"{$profileId}"{literal};
+   $.ajax({
+    url         : locationUrl,
+    dataType    : "json",
+    timeout     : 5000, //Time in milliseconds
+    success     : function(data, status) {
+      for (var ele in data) {
+        if ($("#"+ ele).hasClass('crm-chain-select-target')) {
+          $("#"+ ele).data('newVal', data[ele].value).off('.autofill').on('crmOptionsUpdated.autofill', function() {
+            $(this).off('.autofill').val($(this).data('newVal')).change();
+          });
+        }
+        else if ($('#' + ele).data('select2')) {
+          $('#' + ele).select2('val', data[ele].value);
+        }
+        if (data[ele].type == 'Radio') {
+          if (data[ele].value) {
+            var fldName = ele.replace('onbehalf_', '');
+            $("input[name='onbehalf["+ fldName +"]']").filter("[value='" + data[ele].value + "']").prop('checked', true);
+          }
+        }
+        else if (data[ele].type == 'CheckBox') {
+          for (var selectedOption in data[ele].value) {
+            var fldName = ele.replace('onbehalf_', '');
+            $("input[name='onbehalf["+ fldName+"]["+ selectedOption +"]']").prop('checked','checked');
+          }
+        }
+        else if (data[ele].type == 'AdvMulti-Select') {
+          var customFld = ele.replace('onbehalf_', '');
+          // remove empty value if any
+          $('#onbehalf\\['+ customFld +'\\]-f option[value=""]').remove();
+          $('#onbehalf\\['+ customFld +'\\]-t option[value=""]').remove();
+
+          for (var selectedOption in data[ele].value) {
+            // remove selected values from left and selected values to right
+            $('#onbehalf\\['+ customFld +'\\]-f option[value="' + selectedOption + '"]').remove()
+              .appendTo('#onbehalf\\['+ customFld +'\\]-t');
+            $('#onbehalf_'+ customFld).val(selectedOption);
+          }
+        }
+        else {
+          // do not set defaults to file type fields
+          if ($('#' + ele).attr('type') != 'file') {
+            $('#' + ele ).val(data[ele].value).change();
+          }
+        }
+      }
+    },
+    error       : function(XMLHttpRequest, textStatus, errorThrown) {
+      CRM.console('error', "HTTP error status: ", textStatus);
+    }
+  });
+}
+});
+
+</script>
+{/literal}
index cb6642f865be2866f54c3753c10272d127478943..90e280be2ed00dd09f23d26cdb69cbf3a8e90dff 100644 (file)
     <div class="clear"></div>
   </div>
 
-  {if $form.is_for_organization}
-  <div class="crm-section {$form.is_for_organization.name}-section">
-    <div class="label">&nbsp;</div>
-    <div class="content">
-      {$form.is_for_organization.html}&nbsp;{$form.is_for_organization.label}
-    </div>
-    <div class="clear"></div>
-  </div>
-  {/if}
-
-  {if $is_for_organization}
-    {include file="CRM/Contribute/Form/Contribution/OnBehalfOf.tpl"}
-  {/if}
+  {include file="CRM/Contact/Form/ProfileContact.tpl"}
 
   {* User account registration option. Displays if enabled for one of the profiles on this page. *}
   {include file="CRM/common/CMSUser.tpl"}
     }
   }
 
-  {/literal}
-  {if $relatedOrganizationFound and $reset}
-    cj( "#is_for_organization" ).prop('checked', true );
-    showOnBehalf(false);
-  {elseif $onBehalfRequired}
-    showOnBehalf(true);
-  {/if}
-  {literal}
-
   cj('input[name="soft_credit_type_id"]').on('change', function() {
     enableHonorType();
   });
diff --git a/templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl b/templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl
deleted file mode 100644 (file)
index e58bb75..0000000
+++ /dev/null
@@ -1,231 +0,0 @@
-{*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.7                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2015                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*}
-{**
- * This file provides the HTML for the on-behalf-of form.
- * Also used for related contact edit form.
- * FIXME: This is way more complex than it needs to be
- * FIXME: Why are we not just using the dynamic form tpl to display this profile?
- *}
-
-{if $buildOnBehalfForm or $onBehalfRequired}
-  {if !empty($context)}
-    <fieldset id="for_organization" class="for_organization-group">
-    <legend>{$fieldSetTitle}</legend>
-    {if ( $relatedOrganizationFound or $onBehalfRequired ) and !$organizationName and $form.org_option.html}
-      <div id='orgOptions' class="section crm-section">
-        <div class="content">
-          {$form.org_option.html}
-        </div>
-      </div>
-    {/if}
-  {/if}
-  <div id='onBehalfOfOrg' class="crm-section">
-    {include file="CRM/UF/Form/Block.tpl" fields=$onBehalfOfFields mode=8 prefix='onbehalf'}
-  </div>
-
-  <div>{$form.mode.html}</div>
-  {if !empty($context)}
-    </fieldset>
-  {/if}
-{/if}
-{literal}
-<script type="text/javascript">
-
-  showOnBehalf({/literal}"{$onBehalfRequired}"{literal});
-
-  cj( "#mode" ).hide( );
-  cj( "#mode" ).prop('checked', true );
-  if ( cj( "#mode" ).prop('checked' ) && !{/literal}"{$reset}"{literal} ) {
-    $text = ' {/literal}{ts escape="js"}Use existing organization{/ts}{literal} ';
-    cj( "#createNewOrg" ).text( $text );
-    cj( "#mode" ).prop('checked', false );
-  }
-
-function showOnBehalf(onBehalfRequired) {
-  if ( cj( "#is_for_organization" ).prop( 'checked' ) || onBehalfRequired ) {
-    var urlPath = {/literal}"{crmURL p=$urlPath h=0 q="snippet=4&onbehalf=1&id=$contributionPageID&qfKey=$qfKey"}";
-    {if $mode eq 'test'}
-      urlPath += '&action=preview';
-    {/if}
-    {if $reset}
-      urlPath += '&reset={$reset}';
-    {/if}{literal}
-    cj("#onBehalfOfOrg").show();
-    if (cj("fieldset", '#onBehalfOfOrg').length < 1) {
-      cj('#onBehalfOfOrg').load(urlPath);
-    }
-  }
-  else {
-    cj("#onBehalfOfOrg").hide();
-  }
-}
-
-function resetValues() {
-  // Don't trip chain-select when clearing values
-  cj('.crm-chain-select-control', "#select_org div").select2('val', '');
-  cj('input[type=text], select, textarea', "#select_org div").not('.crm-chain-select-control, #onbehalfof_id').val('').change();
-  cj('input[type=radio], input[type=checkbox]', "#select_org div").prop('checked', false).change();
-}
-
-function createNew( ) {
-  if (cj("#mode").prop('checked')) {
-    var textMessage = ' {/literal}{ts escape="js"}Use existing organization{/ts}{literal} ';
-    cj("#onbehalf_organization_name").prop('readonly', false);
-    cj("#mode").prop('checked', false);
-    resetValues();
-  }
-  else {
-    var textMessage = ' {/literal}{ts escape="js"}Enter a new organization{/ts}{literal} ';
-    cj("#mode").prop('checked', true);
-    setOrgName( );
-  }
-  cj("#createNewOrg").text(textMessage);
-}
-
-function setOrgName( ) {
-  var orgName = "{/literal}{$organizationName}{literal}";
-  var orgId   = "{/literal}{$orgId}{literal}";
-  cj("#onbehalf_organization_name").val(orgName);
-  cj("#onbehalf_organization_name").attr('readonly', true);
-  setLocationDetails(orgId);
-}
-
-
-function setLocationDetails(contactID , reset) {
-  var submittedCID = {/literal}"{$submittedOnBehalf}"{literal};
-  var submittedOnBehalfInfo = {/literal}'{$submittedOnBehalfInfo}'{literal};
-  if (submittedOnBehalfInfo) {
-    submittedOnBehalfInfo = cj.parseJSON(submittedOnBehalfInfo);
-
-    if (submittedCID == contactID) {
-      cj.each(submittedOnBehalfInfo, function(key, value) {
-        cj('#onbehalf_' + key ).val(value);
-      });
-      return;
-    }
-  }
-
-  resetValues();
-  var locationUrl = {/literal}"{$locDataURL}"{literal} + contactID + "&ufId=" + {/literal}"{$profileId}"{literal};
-  cj.ajax({
-    url         : locationUrl,
-    dataType    : "json",
-    timeout     : 5000, //Time in milliseconds
-    success     : function(data, status) {
-      for (var ele in data) {
-        if (cj("#"+ ele).hasClass('crm-chain-select-target')) {
-          cj("#"+ ele).data('newVal', data[ele].value).off('.autofill').on('crmOptionsUpdated.autofill', function() {
-            cj(this).off('.autofill').val(cj(this).data('newVal')).change();
-          });
-        }
-        else if (cj('#' + ele).data('select2')) {
-          cj('#' + ele).select2('val', data[ele].value);
-        }
-        if (data[ele].type == 'Radio') {
-          if (data[ele].value) {
-            var fldName = ele.replace('onbehalf_', '');
-            cj("input[name='onbehalf["+ fldName +"]']").filter("[value='" + data[ele].value + "']").prop('checked', true);
-          }
-        }
-        else if (data[ele].type == 'CheckBox') {
-          for (var selectedOption in data[ele].value) {
-            var fldName = ele.replace('onbehalf_', '');
-            cj("input[name='onbehalf["+ fldName+"]["+ selectedOption +"]']").prop('checked','checked');
-          }
-        }
-        else if (data[ele].type == 'AdvMulti-Select') {
-          var customFld = ele.replace('onbehalf_', '');
-          // remove empty value if any
-          cj('#onbehalf\\['+ customFld +'\\]-f option[value=""]').remove();
-          cj('#onbehalf\\['+ customFld +'\\]-t option[value=""]').remove();
-
-          for (var selectedOption in data[ele].value) {
-            // remove selected values from left and selected values to right
-            cj('#onbehalf\\['+ customFld +'\\]-f option[value="' + selectedOption + '"]').remove()
-              .appendTo('#onbehalf\\['+ customFld +'\\]-t');
-            cj('#onbehalf_'+ customFld).val(selectedOption);
-          }
-        }
-        else {
-          // do not set defaults to file type fields
-          if (cj('#' + ele).attr('type') != 'file') {
-            cj('#' + ele ).val(data[ele].value).change();
-          }
-        }
-      }
-    },
-    error       : function(XMLHttpRequest, textStatus, errorThrown) {
-      CRM.console('error', "HTTP error status: ", textStatus);
-    }
-  });
-}
-
-cj("input:radio[name='org_option']").click( function( ) {
-  var orgOption = cj(this).val();
-  selectCreateOrg(orgOption, true);
-});
-
-cj('#onbehalfof_id').change(function() {
-  setLocationDetails(cj(this).val());
-}).change();
-
-function selectCreateOrg( orgOption, reset ) {
-  if (orgOption == 0) {
-    cj("#onbehalfof_id").show().change();
-    cj("input#onbehalf_organization_name").hide();
-  }
-  else if ( orgOption == 1 ) {
-    cj("input#onbehalf_organization_name").show();
-    cj("#onbehalfof_id").hide();
-  }
-
-  if ( reset ) {
-    resetValues();
-  }
-}
-
-{/literal}
-{if ($relatedOrganizationFound or $onBehalfRequired) and $reset and $organizationName}
-  setOrgName( );
-{else}
-  cj("#orgOptions").show( );
-  var orgOption = cj("input:radio[name=org_option]:checked").val( );
-  selectCreateOrg(orgOption, false);
-{/if}
-
-{* If mid present in the url, take the required action (poping up related existing contact ..etc) *}
-{if $membershipContactID}
-{literal}
-  CRM.$(function($) {
-    $('#organization_id').val("{/literal}{$membershipContactName}{literal}");
-    $('#organization_name').val("{/literal}{$membershipContactName}{literal}");
-    $('#onbehalfof_id').val("{/literal}{$membershipContactID}{literal}");
-    setLocationDetails( "{/literal}{$membershipContactID}{literal}" );
-  });
-{/literal}
-{/if}
-
-</script>