/**
  * Build the form object.
  *
  * @return void
  */
 public function buildQuickForm()
 {
     $participantStatuses = CRM_Event_PseudoConstant::participantStatus();
     $partiallyPaidStatusId = array_search('Partially paid', $participantStatuses);
     $this->assign('partiallyPaidStatusId', $partiallyPaidStatusId);
     if ($this->_showFeeBlock) {
         return CRM_Event_Form_EventFees::buildQuickForm($this);
     }
     //need to assign custom data type to the template
     $this->assign('customDataType', 'Participant');
     $this->applyFilter('__ALL__', 'trim');
     if ($this->_action & CRM_Core_Action::DELETE) {
         if ($this->_single) {
             $additionalParticipant = count(CRM_Event_BAO_Event::buildCustomProfile($this->_id, NULL, $this->_contactId, FALSE, TRUE)) - 1;
             if ($additionalParticipant) {
                 $deleteParticipants = array(1 => ts('Delete this participant record along with associated participant record(s).'), 2 => ts('Delete only this participant record.'));
                 $this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />');
                 $this->setDefaults(array('delete_participant' => 1));
                 $this->assign('additionalParticipant', $additionalParticipant);
             }
         }
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     if ($this->_single && $this->_context == 'standalone') {
         $this->addEntityRef('contact_id', ts('Contact'), array('create' => TRUE, 'api' => array('extra' => array('email'))), TRUE);
     }
     $eventFieldParams = array('entity' => 'event', 'select' => array('minimumInputLength' => 0), 'api' => array('extra' => array('campaign_id', 'default_role_id', 'event_type_id')));
     if ($this->_mode) {
         // exclude events which are not monetary when credit card registration is used
         $eventFieldParams['api']['params']['is_monetary'] = 1;
         $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, TRUE);
     }
     $element = $this->addEntityRef('event_id', ts('Event'), $eventFieldParams, TRUE);
     //frozen the field fix for CRM-4171
     if ($this->_action & CRM_Core_Action::UPDATE && $this->_id) {
         if (CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'contribution_id', 'participant_id')) {
             $element->freeze();
         }
     }
     //CRM-7362 --add campaigns.
     $campaignId = NULL;
     if ($this->_id) {
         $campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'campaign_id');
     }
     if (!$campaignId) {
         $eventId = CRM_Utils_Request::retrieve('eid', 'Positive', $this);
         if ($eventId) {
             $campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventId, 'campaign_id');
         }
     }
     CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId);
     $this->addDateTime('register_date', ts('Registration Date'), TRUE, array('formatType' => 'activityDateTime'));
     if ($this->_id) {
         $this->assign('entityID', $this->_id);
     }
     $this->addSelect('role_id', array('multiple' => TRUE, 'class' => 'huge'), TRUE);
     // CRM-4395
     $checkCancelledJs = array('onchange' => "return sendNotification( );");
     $confirmJS = NULL;
     if ($this->_onlinePendingContributionId) {
         $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus());
         $cancelledContributionStatusId = array_search('Cancelled', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'));
         $checkCancelledJs = array('onchange' => "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});");
         $participantStatusId = array_search('Pending from pay later', CRM_Event_PseudoConstant::participantStatus());
         $contributionStatusId = array_search('Completed', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'));
         $confirmJS = array('onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );");
     }
     // get the participant status names to build special status array which is used to show notification
     // checkbox below participant status select
     $participantStatusName = CRM_Event_PseudoConstant::participantStatus();
     $notificationStatuses = array('Cancelled', 'Pending from waitlist', 'Pending from approval', 'Expired');
     // get the required status and then implode only ids
     $notificationStatusIds = implode(',', array_keys(array_intersect($participantStatusName, $notificationStatuses)));
     $this->assign('notificationStatusIds', $notificationStatusIds);
     $this->_participantStatuses = $statusOptions = CRM_Event_BAO_Participant::buildOptions('status_id', 'create');
     // Only show refund status when editing
     if ($this->_action & CRM_Core_Action::ADD) {
         $pendingRefundStatusId = array_search('Pending refund', $participantStatusName);
         if ($pendingRefundStatusId) {
             unset($statusOptions[$pendingRefundStatusId]);
         }
     }
     $this->addSelect('status_id', $checkCancelledJs + array('options' => $statusOptions, 'option_url' => 'civicrm/admin/participant_status'), TRUE);
     $this->addElement('checkbox', 'is_notify', ts('Send Notification'), NULL);
     $this->add('text', 'source', ts('Event Source'));
     $noteAttributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Note');
     $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']);
     $buttons[] = array('type' => 'upload', 'name' => ts('Save'), 'isDefault' => TRUE, 'js' => $confirmJS);
     $path = CRM_Utils_System::currentPath();
     $excludeForPaths = array('civicrm/contact/search', 'civicrm/group/search');
     if (!in_array($path, $excludeForPaths)) {
         $buttons[] = array('type' => 'upload', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $confirmJS);
     }
     $buttons[] = array('type' => 'cancel', 'name' => ts('Cancel'));
     $this->addButtons($buttons);
     if ($this->_action == CRM_Core_Action::VIEW) {
         $this->freeze();
     }
 }
Exemple #2
0
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     if ($this->_showFeeBlock) {
         return CRM_Event_Form_EventFees::buildQuickForm($this);
     }
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::buildQuickForm($this);
     }
     //need to assign custom data type to the template
     $this->assign('customDataType', 'Participant');
     $this->applyFilter('__ALL__', 'trim');
     if ($this->_action & CRM_Core_Action::DELETE) {
         if ($this->_single) {
             $additionalParticipant = count(CRM_Event_BAO_Event::buildCustomProfile($this->_id, NULL, $this->_contactId, FALSE, TRUE)) - 1;
             if ($additionalParticipant) {
                 $deleteParticipants = array(1 => ts('Delete this participant record along with associated participant record(s).'), 2 => ts('Delete only this participant record.'));
                 $this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />');
                 $this->setDefaults(array('delete_participant' => 1));
                 $this->assign('additionalParticipant', $additionalParticipant);
             }
         }
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     if ($this->_single) {
         $urlPath = 'civicrm/contact/view/participant';
         $urlParams = "reset=1&cid={$this->_contactId}&context=participant";
         if ($this->_context == 'standalone') {
             CRM_Contact_Form_NewContact::buildQuickForm($this);
             $urlParams = 'reset=1&context=standalone';
             $urlPath = 'civicrm/participant/add';
         }
         if ($this->_id) {
             $urlParams .= "&action=update&id={$this->_id}";
         } else {
             $urlParams .= "&action=add";
         }
         if ($this->_mode) {
             $urlParams .= "&mode={$this->_mode}";
         }
         $url = CRM_Utils_System::url($urlPath, $urlParams, FALSE, NULL, FALSE);
     } else {
         $currentPath = CRM_Utils_System::currentPath();
         $url = CRM_Utils_System::url($currentPath, '_qf_Participant_display=true', FALSE, NULL, FALSE);
     }
     $this->assign('refreshURL', $url);
     $this->add('hidden', 'past_event');
     $events = array();
     if ($this->_eID) {
         $eventEndDate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_eID, 'end_date');
     }
     $this->assign('past', 0);
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $events = CRM_Event_BAO_Event::getEvents(1, FALSE, FALSE);
     } elseif ($this->getElementValue('past_event') || isset($eventEndDate) && CRM_Utils_Date::currentDBDate() > CRM_Utils_Date::processDate($eventEndDate)) {
         $pastval = $this->getElementValue('past_event');
         $events = CRM_Event_BAO_Event::getEvents($pastval);
         $this->assign('past', $pastval);
     } else {
         $events = CRM_Event_BAO_Event::getEvents();
     }
     if ($this->_mode) {
         //unset the event which are not monetary when credit card
         //event registration is used
         foreach ($events as $key => $val) {
             $isPaid = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $key, 'is_monetary');
             if (!$isPaid) {
                 unset($events[$key]);
             }
         }
         $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, TRUE);
     }
     // build array(event -> eventType) mapper
     $query = "\nSELECT     civicrm_event.id as id, civicrm_event.event_type_id as event_type_id\nFROM       civicrm_event\nWHERE      civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0";
     $dao = CRM_Core_DAO::executeQuery($query);
     $eventAndTypeMapping = array();
     while ($dao->fetch()) {
         $eventAndTypeMapping[$dao->id] = $dao->event_type_id;
     }
     $eventAndTypeMapping = json_encode($eventAndTypeMapping);
     // building of mapping ends --
     //inherit the campaign from event.
     $eventCampaigns = array();
     $allEventIds = array_keys($events);
     if (!empty($allEventIds)) {
         CRM_Core_PseudoConstant::populate($eventCampaigns, 'CRM_Event_DAO_Event', TRUE, 'campaign_id');
     }
     $eventCampaigns = json_encode($eventCampaigns);
     $element = $this->add('select', 'event_id', ts('Event'), array('' => ts('- select -')) + $events, TRUE, array('onchange' => "buildFeeBlock( this.value ); CRM.buildCustomData( 'Participant', this.value, {$this->_eventNameCustomDataTypeID} ); buildParticipantRole( this.value ); buildEventTypeCustomData( this.value, {$this->_eventTypeCustomDataTypeID}, '{$eventAndTypeMapping}' ); loadCampaign( this.value, {$eventCampaigns} );", 'class' => 'huge'));
     // CRM-6111
     // note that embedding JS within PHP files is quite awful, IMO
     // but we do the same for the onChange element and this form is complex
     // and i did not want to break it late in the 3.2 cycle
     $preloadJSSnippet = NULL;
     if (CRM_Utils_Array::value('reset', $_GET) && $this->_eID) {
         $preloadJSSnippet = "\ncj(function() {\ncj('#event_id').val( '{$this->_eID}' );\nbuildFeeBlock( {$this->_eID} );\nCRM.buildCustomData( 'Participant', {$this->_eID}, {$this->_eventNameCustomDataTypeID} );\nbuildEventTypeCustomData( {$this->_eID}, {$this->_eventTypeCustomDataTypeID}, '{$eventAndTypeMapping}' );\nloadCampaign( {$this->_eID}, {$eventCampaigns} );\n});\n";
     }
     $this->assign('preloadJSSnippet', $preloadJSSnippet);
     //frozen the field fix for CRM-4171
     if ($this->_action & CRM_Core_Action::UPDATE && $this->_id) {
         if (CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'contribution_id', 'participant_id')) {
             $element->freeze();
         }
     }
     //CRM-7362 --add campaigns.
     $campaignId = NULL;
     if ($this->_id) {
         $campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'campaign_id');
     }
     if (!$campaignId) {
         $eventId = CRM_Utils_Request::retrieve('eid', 'Positive', $this);
         if ($eventId) {
             $campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventId, 'campaign_id');
         }
     }
     CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId);
     $this->addDateTime('register_date', ts('Registration Date'), TRUE, array('formatType' => 'activityDateTime'));
     if ($this->_id) {
         $this->assign('entityID', $this->_id);
     }
     $roleids = CRM_Event_PseudoConstant::participantRole();
     foreach ($roleids as $rolekey => $rolevalue) {
         $roleTypes[] = $this->createElement('checkbox', $rolekey, NULL, $rolevalue, array('onclick' => "showCustomData( 'Participant', {$rolekey}, {$this->_roleCustomDataTypeID} );"));
     }
     $this->addGroup($roleTypes, 'role_id', ts('Participant Role'));
     $this->addRule('role_id', ts('Role is required'), 'required');
     // CRM-4395
     $checkCancelledJs = array('onchange' => "return sendNotification( );");
     $confirmJS = NULL;
     if ($this->_onlinePendingContributionId) {
         $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus());
         $cancelledContributionStatusId = array_search('Cancelled', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'));
         $checkCancelledJs = array('onchange' => "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});");
         $participantStatusId = array_search('Pending from pay later', CRM_Event_PseudoConstant::participantStatus());
         $contributionStatusId = array_search('Completed', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'));
         $confirmJS = array('onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );");
     }
     // get the participant status names to build special status array which is used to show notification
     // checkbox below participant status select
     $participantStatusName = CRM_Event_PseudoConstant::participantStatus();
     $notificationStatuses = array('Cancelled', 'Pending from waitlist', 'Pending from approval', 'Expired');
     // get the required status and then implode only ids
     $notificationStatusIds = implode(',', array_keys(array_intersect($participantStatusName, $notificationStatuses)));
     $this->assign('notificationStatusIds', $notificationStatusIds);
     $this->_participantStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label');
     $this->add('select', 'status_id', ts('Participant Status'), array('' => ts('- select -')) + $this->_participantStatuses, TRUE, $checkCancelledJs);
     $this->addElement('checkbox', 'is_notify', ts('Send Notification'), NULL);
     $this->add('text', 'source', ts('Event Source'));
     $noteAttributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Note');
     $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']);
     $buttons[] = array('type' => 'upload', 'name' => ts('Save'), 'isDefault' => TRUE, 'js' => $confirmJS);
     $path = CRM_Utils_System::currentPath();
     $excludeForPaths = array('civicrm/contact/search', 'civicrm/group/search');
     if (!in_array($path, $excludeForPaths)) {
         $buttons[] = array('type' => 'upload', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $confirmJS);
     }
     $buttons[] = array('type' => 'cancel', 'name' => ts('Cancel'));
     $this->addButtons($buttons);
     if ($this->_action == CRM_Core_Action::VIEW) {
         $this->freeze();
     }
 }
Exemple #3
0
 /** 
  * Function to build the form 
  * 
  * @return None 
  * @access public 
  */
 public function buildQuickForm()
 {
     if ($this->_showFeeBlock) {
         return CRM_Event_Form_EventFees::buildQuickForm($this);
     }
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::buildQuickForm($this);
     }
     //need to assign custom data type to the template
     $this->assign('customDataType', 'Participant');
     $this->applyFilter('__ALL__', 'trim');
     if ($this->_action & CRM_Core_Action::DELETE) {
         if ($this->_single) {
             require_once 'CRM/Event/BAO/Event.php';
             $additionalParticipant = count(CRM_Event_BAO_Event::buildCustomProfile($this->_participantId, null, $this->_contactID, false, true)) - 1;
             if ($additionalParticipant) {
                 $this->assign("additionalParticipant", $additionalParticipant);
             }
         }
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     if ($this->_single) {
         $urlPath = 'civicrm/contact/view/participant';
         $urlParams = "reset=1&cid={$this->_contactID}&context=participant";
         if ($this->_context == 'standalone') {
             require_once 'CRM/Contact/Form/NewContact.php';
             CRM_Contact_Form_NewContact::buildQuickForm($this);
             $urlParams = "reset=1&context=standalone";
             $urlPath = 'civicrm/participant/add';
         }
         if ($this->_participantId) {
             $urlParams .= "&action=update&id={$this->_participantId}";
         } else {
             $urlParams .= "&action=add";
         }
         if (CRM_Utils_Request::retrieve('past', 'Boolean', $this)) {
             $urlParams .= "&past=true";
         }
         if ($this->_mode) {
             $urlParams .= "&mode={$this->_mode}";
         }
         $url = CRM_Utils_System::url($urlPath, $urlParams, false, null, false);
     } else {
         $currentPath = CRM_Utils_System::currentPath();
         $url = CRM_Utils_System::url($currentPath, '_qf_Participant_display=true', false, null, false);
     }
     $this->assign("refreshURL", $url);
     $url .= "&past=true";
     $this->assign("pastURL", $url);
     $events = array();
     $this->assign("past", false);
     require_once "CRM/Event/BAO/Event.php";
     if (CRM_Utils_Request::retrieve('past', 'Boolean', $this) || $this->_action & CRM_Core_Action::UPDATE) {
         $events = CRM_Event_BAO_Event::getEvents(true);
         $this->assign("past", true);
     } else {
         $events = CRM_Event_BAO_Event::getEvents();
     }
     if ($this->_mode) {
         //unset the event which are not monetary when credit card
         //event registration is used
         foreach ($events as $key => $val) {
             $isPaid = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $key, 'is_monetary');
             if (!$isPaid) {
                 unset($events[$key]);
             }
         }
         $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, true);
     }
     $element = $this->add('select', 'event_id', ts('Event'), array('' => ts('- select -')) + $events, true, array('onchange' => "buildFeeBlock( this.value ); buildCustomData( 'Participant', this.value, {$this->_eventNameCustomDataTypeID} );", 'class' => 'huge'));
     //frozen the field fix for CRM-4171
     if ($this->_action & CRM_Core_Action::UPDATE && $this->_participantId) {
         if (CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_participantId, 'contribution_id', 'participant_id')) {
             $element->freeze();
         }
     }
     $this->addDateTime('register_date', ts('Registration Date'), true);
     if ($this->_participantId) {
         $this->assign('entityID', $this->_participantId);
     }
     $this->add('select', 'role_id', ts('Participant Role'), array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantRole(), true, array('onchange' => "buildCustomData( 'Participant', this.value, {$this->_roleCustomDataTypeID} );"));
     // CRM-4395
     $checkCancelledJs = array('onchange' => "return sendNotification( );");
     if ($this->_onlinePendingContributionId) {
         $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus());
         $cancelledContributionStatusId = array_search('Cancelled', CRM_Contribute_PseudoConstant::contributionStatus(null, 'name'));
         $checkCancelledJs = array('onchange' => "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});");
     }
     $this->add('select', 'status_id', ts('Participant Status'), array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantStatus(null, null, 'label'), true, $checkCancelledJs);
     $this->addElement('checkbox', 'is_notify', ts('Send Notification'), null);
     $this->add('text', 'source', ts('Event Source'));
     $noteAttributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Note');
     $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']);
     $confirmJS = null;
     if ($this->_onlinePendingContributionId) {
         $participantStatusId = array_search('Pending from pay later', CRM_Event_PseudoConstant::participantStatus());
         $contributionStatusId = array_search('Completed', CRM_Contribute_PseudoConstant::contributionStatus(null, 'name'));
         $confirmJS = array('onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );");
     }
     $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'isDefault' => true, 'js' => $confirmJS), array('type' => 'upload', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $confirmJS), array('type' => 'cancel', 'name' => ts('Cancel'))));
     if ($this->_action == CRM_Core_Action::VIEW) {
         $this->freeze();
     }
 }
 /** 
  * Function to build the form 
  * 
  * @return None 
  * @access public 
  */
 public function buildQuickForm()
 {
     if ($this->_showFeeBlock) {
         return CRM_Event_Form_EventFees::buildQuickForm($this);
     }
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::buildQuickForm($this);
     }
     //need to assign custom data type to the template
     $this->assign('customDataType', 'Participant');
     $this->applyFilter('__ALL__', 'trim');
     if ($this->_action & CRM_Core_Action::DELETE) {
         if ($this->_single) {
             require_once 'CRM/Event/BAO/Event.php';
             $additionalParticipant = count(CRM_Event_BAO_Event::buildCustomProfile($this->_id, null, $this->_contactId, false, true)) - 1;
             if ($additionalParticipant) {
                 $deleteParticipants = array(1 => ts('Delete this participant record along with associated participant record(s).'), 2 => ts('Delete only this participant record.'));
                 $this->addRadio('delete_participant', null, $deleteParticipants, null, '<br />');
                 $this->setDefaults(array('delete_participant' => 1));
                 $this->assign("additionalParticipant", $additionalParticipant);
             }
         }
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     if ($this->_single) {
         $urlPath = 'civicrm/contact/view/participant';
         $urlParams = "reset=1&cid={$this->_contactId}&context=participant";
         if ($this->_context == 'standalone') {
             require_once 'CRM/Contact/Form/NewContact.php';
             CRM_Contact_Form_NewContact::buildQuickForm($this);
             $urlParams = "reset=1&context=standalone";
             $urlPath = 'civicrm/participant/add';
         }
         if ($this->_id) {
             $urlParams .= "&action=update&id={$this->_id}";
         } else {
             $urlParams .= "&action=add";
         }
         if ($this->_mode) {
             $urlParams .= "&mode={$this->_mode}";
         }
         $url = CRM_Utils_System::url($urlPath, $urlParams, false, null, false);
     } else {
         $currentPath = CRM_Utils_System::currentPath();
         $url = CRM_Utils_System::url($currentPath, '_qf_Participant_display=true', false, null, false);
     }
     $this->assign("refreshURL", $url);
     $this->add('hidden', 'past_event');
     $events = array();
     $this->assign("past", false);
     require_once "CRM/Event/BAO/Event.php";
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $events = CRM_Event_BAO_Event::getEvents(true, false, false);
     } elseif ($this->getElementValue('past_event')) {
         $events = CRM_Event_BAO_Event::getEvents(true);
         $this->assign("past", true);
     } else {
         $events = CRM_Event_BAO_Event::getEvents();
     }
     if ($this->_mode) {
         //unset the event which are not monetary when credit card
         //event registration is used
         foreach ($events as $key => $val) {
             $isPaid = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $key, 'is_monetary');
             if (!$isPaid) {
                 unset($events[$key]);
             }
         }
         $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, true);
     }
     // build array(event -> eventType) mapper
     $query = "\nSELECT     civicrm_event.id as id, civicrm_event.event_type_id as event_type_id\nFROM       civicrm_event\nWHERE      civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0";
     $dao =& CRM_Core_DAO::executeQuery($query);
     $eventAndTypeMapping = array();
     while ($dao->fetch()) {
         $eventAndTypeMapping[$dao->id] = $dao->event_type_id;
     }
     $eventAndTypeMapping = json_encode($eventAndTypeMapping);
     // building of mapping ends --
     $element = $this->add('select', 'event_id', ts('Event'), array('' => ts('- select -')) + $events, true, array('onchange' => "buildFeeBlock( this.value ); buildCustomData( 'Participant', this.value, {$this->_eventNameCustomDataTypeID} ); buildParticipantRole( this.value ); buildEventTypeCustomData( this.value, {$this->_eventTypeCustomDataTypeID}, '{$eventAndTypeMapping}' );", 'class' => 'huge'));
     // CRM-6111
     // note that embedding JS within PHP files is quite awful, IMO
     // but we do the same for the onChange element and this form is complex
     // and i did not want to break it late in the 3.2 cycle
     $preloadJSSnippet = null;
     if (CRM_Utils_Array::value('reset', $_GET)) {
         $this->_eID = CRM_Utils_Request::retrieve('eid', 'Positive', $this);
         if ($this->_eID) {
             $preloadJSSnippet = "\ncj(function() {\ncj('#event_id').val( '{$this->_eID}' );\nbuildFeeBlock( {$this->_eID} ); \nbuildCustomData( 'Participant', {$this->_eID}, {$this->_eventNameCustomDataTypeID} );\nbuildEventTypeCustomData( {$this->_eID}, {$this->_eventTypeCustomDataTypeID}, '{$eventAndTypeMapping}' );\n});\n";
         }
     }
     $this->assign('preloadJSSnippet', $preloadJSSnippet);
     //frozen the field fix for CRM-4171
     if ($this->_action & CRM_Core_Action::UPDATE && $this->_id) {
         if (CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'contribution_id', 'participant_id')) {
             $element->freeze();
         }
     }
     $this->addDateTime('register_date', ts('Registration Date'), true, array('formatType' => 'activityDateTime'));
     if ($this->_id) {
         $this->assign('entityID', $this->_id);
     }
     $roleids = CRM_Event_PseudoConstant::participantRole();
     foreach ($roleids as $rolekey => $rolevalue) {
         $roleTypes[] = HTML_QuickForm::createElement('checkbox', $rolekey, null, $rolevalue, array('onclick' => "showCustomData( 'Participant', {$rolekey}, {$this->_roleCustomDataTypeID} );"));
     }
     $this->addGroup($roleTypes, 'role_id', ts('Participant Role'));
     $this->addRule('role_id', ts('Role is required'), 'required');
     // CRM-4395
     $checkCancelledJs = array('onchange' => "return sendNotification( );");
     $confirmJS = null;
     if ($this->_onlinePendingContributionId) {
         $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus());
         $cancelledContributionStatusId = array_search('Cancelled', CRM_Contribute_PseudoConstant::contributionStatus(null, 'name'));
         $checkCancelledJs = array('onchange' => "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});");
         $participantStatusId = array_search('Pending from pay later', CRM_Event_PseudoConstant::participantStatus());
         $contributionStatusId = array_search('Completed', CRM_Contribute_PseudoConstant::contributionStatus(null, 'name'));
         $confirmJS = array('onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );");
     }
     $this->_participantStatuses = CRM_Event_PseudoConstant::participantStatus(null, null, 'label');
     $this->add('select', 'status_id', ts('Participant Status'), array('' => ts('- select -')) + $this->_participantStatuses, true, $checkCancelledJs);
     $this->addElement('checkbox', 'is_notify', ts('Send Notification'), null);
     $this->add('text', 'source', ts('Event Source'));
     $noteAttributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Note');
     $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']);
     $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'isDefault' => true, 'js' => $confirmJS), array('type' => 'upload', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $confirmJS), array('type' => 'cancel', 'name' => ts('Cancel'))));
     if ($this->_action == CRM_Core_Action::VIEW) {
         $this->freeze();
     }
 }