/** * Build the common elements between the search/advanced form. */ public function buildQuickForm() { parent::buildQuickForm(); CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header'); $permission = CRM_Core_Permission::getPermission(); // some tasks.. what do we want to do with the selected contacts ? $tasks = array(); if ($this->_componentMode == 1 || $this->_componentMode == 7) { $tasks += CRM_Contact_Task::permissionedTaskTitles($permission, CRM_Utils_Array::value('deleted_contacts', $this->_formValues)); } else { $className = $this->_modeValue['taskClassName']; $tasks += $className::permissionedTaskTitles($permission, FALSE); } if (isset($this->_ssID)) { if ($permission == CRM_Core_Permission::EDIT) { $tasks = $tasks + CRM_Contact_Task::optionalTaskTitle(); } $search_custom_id = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID, 'search_custom_id'); $savedSearchValues = array('id' => $this->_ssID, 'name' => CRM_Contact_BAO_SavedSearch::getName($this->_ssID, 'title'), 'search_custom_id' => $search_custom_id); $this->assign_by_ref('savedSearch', $savedSearchValues); $this->assign('ssID', $this->_ssID); } if ($this->_context === 'smog') { // CRM-11788, we might want to do this for all of search where force=1 $formQFKey = CRM_Utils_Array::value('qfKey', $this->_formValues); $getQFKey = CRM_Utils_Array::value('qfKey', $_GET); $postQFKey = CRM_Utils_Array::value('qfKey', $_POST); if ($formQFKey && empty($getQFKey) && empty($postQFKey)) { $url = CRM_Utils_System::makeURL('qfKey') . $formQFKey; CRM_Utils_System::redirect($url); } $permissionForGroup = FALSE; if (!empty($this->_groupID)) { // check if user has permission to edit members of this group $permission = CRM_Contact_BAO_Group::checkPermission($this->_groupID); if ($permission && in_array(CRM_Core_Permission::EDIT, $permission)) { $permissionForGroup = TRUE; } // check if _groupID exists, it might not if // we are displaying a hidden group if (!isset($this->_group[$this->_groupID])) { $this->_group[$this->_groupID] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID, 'title'); } // set the group title $groupValues = array('id' => $this->_groupID, 'title' => $this->_group[$this->_groupID]); $this->assign_by_ref('group', $groupValues); // also set ssID if this is a saved search $ssID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID, 'saved_search_id'); $this->assign('ssID', $ssID); //get the saved search mapping id if ($ssID) { $this->_ssID = $ssID; $ssMappingId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $ssID, 'mapping_id'); $this->assign('ssMappingID', $ssMappingId); } // Set dynamic page title for 'Show Members of Group' CRM_Utils_System::setTitle(ts('Contacts in Group: %1', array(1 => $this->_group[$this->_groupID]))); } $group_contact_status = array(); foreach (CRM_Core_SelectValues::groupContactStatus() as $k => $v) { if (!empty($k)) { $group_contact_status[] = $this->createElement('checkbox', $k, NULL, $v); } } $this->addGroup($group_contact_status, 'group_contact_status', ts('Group Status')); $this->assign('permissionedForGroup', $permissionForGroup); } // add the go button for the action form, note it is of type 'next' rather than of type 'submit' if ($this->_context === 'amtg') { // check if _groupID exists, it might not if // we are displaying a hidden group if (!isset($this->_group[$this->_amtgID])) { $this->assign('permissionedForGroup', FALSE); $this->_group[$this->_amtgID] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_amtgID, 'title'); } // Set dynamic page title for 'Add Members Group' CRM_Utils_System::setTitle(ts('Add to Group: %1', array(1 => $this->_group[$this->_amtgID]))); // also set the group title and freeze the action task with Add Members to Group $groupValues = array('id' => $this->_amtgID, 'title' => $this->_group[$this->_amtgID]); $this->assign_by_ref('group', $groupValues); $this->add('submit', $this->_actionButtonName, ts('Add Contacts to %1', array(1 => $this->_group[$this->_amtgID])), array('class' => 'crm-form-submit')); $this->add('hidden', 'task', CRM_Contact_Task::GROUP_CONTACTS); $selectedRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked')); $allRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all'); $this->assign('ts_sel_id', $selectedRowsRadio->_attributes['id']); $this->assign('ts_all_id', $allRowsRadio->_attributes['id']); } $selectedContactIds = array(); $qfKeyParam = CRM_Utils_Array::value('qfKey', $this->_formValues); // We use ajax to handle selections only if the search results component_mode is set to "contacts" if ($qfKeyParam && ($this->get('component_mode') <= 1 || $this->get('component_mode') == 7)) { $this->addClass('crm-ajax-selection-form'); $qfKeyParam = "civicrm search {$qfKeyParam}"; $selectedContactIdsArr = CRM_Core_BAO_PrevNextCache::getSelection($qfKeyParam); $selectedContactIds = array_keys($selectedContactIdsArr[$qfKeyParam]); } $this->assign_by_ref('selectedContactIds', $selectedContactIds); $rows = $this->get('rows'); if (is_array($rows)) { $this->addRowSelectors($rows); } }
/** * process the form after the input has been submitted and validated * * @access public * * @return void */ public function postProcess() { // saved search form values $formValues = $this->controller->exportValues(); $session = CRM_Core_Session::singleton(); //save the search $savedSearch = new CRM_Contact_BAO_SavedSearch(); $savedSearch->id = $this->_id; $savedSearch->form_values = serialize($this->get('formValues')); $savedSearch->mapping_id = $mappingId; $savedSearch->save(); $this->set('ssID', $savedSearch->id); CRM_Core_Session::setStatus(ts("Your smart group has been saved as '%1'.", array(1 => $formValues['title'])), ts('Saved'), 'success'); // also create a group that is associated with this saved search only if new saved search $params = array(); $params['title'] = $formValues['title']; $params['description'] = $formValues['description']; $params['visibility'] = 'User and User Admin Only'; $params['saved_search_id'] = $savedSearch->id; $params['is_active'] = 1; if ($this->_id) { $params['id'] = CRM_Contact_BAO_SavedSearch::getName($this->_id, 'id'); } $group = CRM_Contact_BAO_Group::create($params); }
/** * Build the common elements between the search/advanced form * * @access public * * @return void */ function buildQuickForm() { $permission = CRM_Core_Permission::getPermission(); // some tasks.. what do we want to do with the selected contacts ? $tasks = array('' => ts('- actions -')); if ($this->_componentMode == 1 || $this->_componentMode == 7) { $tasks += CRM_Contact_Task::permissionedTaskTitles($permission, CRM_Utils_Array::value('deleted_contacts', $this->_formValues)); } else { require_once str_replace('_', DIRECTORY_SEPARATOR, $this->_modeValue['taskClassName']) . '.php'; eval('$tasks += ' . $this->_modeValue['taskClassName'] . '::permissionedTaskTitles( $permission );'); } if (isset($this->_ssID)) { if ($permission == CRM_Core_Permission::EDIT) { $tasks = $tasks + CRM_Contact_Task::optionalTaskTitle(); } $search_custom_id = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID, 'search_custom_id'); $savedSearchValues = array('id' => $this->_ssID, 'name' => CRM_Contact_BAO_SavedSearch::getName($this->_ssID, 'title'), 'search_custom_id' => $search_custom_id); $this->assign_by_ref('savedSearch', $savedSearchValues); $this->assign('ssID', $this->_ssID); } if ($this->_context === 'smog') { if (!empty($this->_groupID)) { // set the group title $groupValues = array('id' => $this->_groupID, 'title' => $this->_group[$this->_groupID]); $this->assign_by_ref('group', $groupValues); // also set ssID if this is a saved search $ssID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID, 'saved_search_id'); $this->assign('ssID', $ssID); //get the saved search mapping id if ($ssID) { $this->_ssID = $ssID; $ssMappingId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $ssID, 'mapping_id'); $this->assign('ssMappingID', $ssMappingId); } } $group_contact_status = array(); foreach (CRM_Core_SelectValues::groupContactStatus() as $k => $v) { if (!empty($k)) { $group_contact_status[] = $this->createElement('checkbox', $k, NULL, $v); } } $this->addGroup($group_contact_status, 'group_contact_status', ts('Group Status')); $this->assign('permissionedForGroup', FALSE); if (!empty($this->_groupID)) { // Set dynamic page title for 'Show Members of Group' CRM_Utils_System::setTitle(ts('Contacts in Group: %1', array(1 => $this->_group[$this->_groupID]))); // check if user has permission to edit members of this group $permission = CRM_Contact_BAO_Group::checkPermission($this->_groupID, $this->_group[$this->_groupID]); if ($permission && in_array(CRM_Core_Permission::EDIT, $permission)) { $this->assign('permissionedForGroup', TRUE); } } } // add the go button for the action form, note it is of type 'next' rather than of type 'submit' if ($this->_context === 'amtg') { // Set dynamic page title for 'Add Members Group' CRM_Utils_System::setTitle(ts('Add to Group: %1', array(1 => $this->_group[$this->_amtgID]))); // also set the group title and freeze the action task with Add Members to Group $groupValues = array('id' => $this->_amtgID, 'title' => $this->_group[$this->_amtgID]); $this->assign_by_ref('group', $groupValues); $this->add('submit', $this->_actionButtonName, ts('Add Contacts to %1', array(1 => $this->_group[$this->_amtgID])), array('class' => 'form-submit', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 1);")); $this->add('hidden', 'task', CRM_Contact_Task::GROUP_CONTACTS); } else { $this->add('select', 'task', ts('Actions:') . ' ', $tasks); $this->add('submit', $this->_actionButtonName, ts('Go'), array('class' => 'form-submit', 'id' => 'Go', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0, " . (int) empty($this->_customSearchClass) . ");")); } // need to perform tasks on all or selected items ? using radio_ts(task selection) for it $selectedRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked', 'onclick' => 'toggleTaskAction( true );')); $this->assign('ts_sel_id', $selectedRowsRadio->_attributes['id']); if ($qfKeyParam = CRM_Utils_Array::value('qfKey', $this->_formValues)) { $qfKeyParam = "civicrm search {$qfKeyParam}"; $selectedContactIdsArr = CRM_Core_BAO_PrevNextCache::getSelection($qfKeyParam); $selectedContactIds = array_keys($selectedContactIdsArr[$qfKeyParam]); } $this->assign_by_ref('selectedContactIds', $selectedContactIds); $allRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all', array('onclick' => $this->getName() . ".toggleSelect.checked = false; toggleCheckboxVals('mark_x_', this);toggleTaskAction( true );toggleContactSelection( 'resetSel', '{$qfKeyParam}', 'reset' );")); $this->assign('ts_all_id', $allRowsRadio->_attributes['id']); /* * add form checkboxes for each row. This is needed out here to conform to QF protocol * of all elements being declared in builQuickForm */ $rows = $this->get('rows'); if (is_array($rows)) { $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('onclick' => "toggleTaskAction( true ); toggleCheckboxVals('mark_x_',this);return toggleContactSelection( 'toggleSelect', '" . $qfKeyParam . "' , 'multiple' );")); $unselectedContactIds = array(); foreach ($rows as $row) { $this->addElement('checkbox', $row['checkbox'], NULL, NULL, array('onclick' => "toggleContactSelection( '" . $row['checkbox'] . "', '" . $qfKeyParam . "' , 'single' );toggleTaskAction( true ); return checkSelectedBox('" . $row['checkbox'] . "');")); if (!in_array($row['contact_id'], $selectedContactIds)) { $unselectedContactIds[] = $row['contact_id']; } } $this->assign_by_ref('unselectedContactIds', $unselectedContactIds); } // add buttons $this->addButtons(array(array('type' => 'refresh', 'name' => ts('Search'), 'isDefault' => TRUE))); $this->add('submit', $this->_printButtonName, ts('Print'), array('class' => 'form-submit', 'id' => 'Print', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 1, 1);")); $this->setDefaultAction('refresh'); }
/** * Build the common elements between the search/advanced form * * @access public * @return void */ function buildQuickForm() { $permission = CRM_Core_Permission::getPermission(); // some tasks.. what do we want to do with the selected contacts ? $tasks = array('' => ts('- more actions -')) + CRM_Contact_Task::permissionedTaskTitles($permission); if (isset($this->_ssID)) { if ($permission == CRM_Core_Permission::EDIT) { $tasks = $tasks + CRM_Contact_Task::optionalTaskTitle(); } $savedSearchValues = array('id' => $this->_ssID, 'name' => CRM_Contact_BAO_SavedSearch::getName($this->_ssID, 'title')); $this->assign_by_ref('savedSearch', $savedSearchValues); $this->assign('ssID', $this->_ssID); } if ($this->_context === 'smog') { // need to figure out how to freeze a bunch of checkboxes, hack for now if ($this->_action != CRM_Core_Action::ADVANCED) { //Fix ME //$this->_groupElement->freeze( ); } // also set the group title $groupValues = array('id' => $this->_groupID, 'title' => $this->_group[$this->_groupID]); $this->assign_by_ref('group', $groupValues); // also set ssID if this is a saved search $ssID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID, 'saved_search_id'); $this->assign('ssID', $ssID); //get the saved search mapping id if ($ssID) { $ssMappingId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $ssID, 'mapping_id'); } if (isset($ssMappingId)) { $this->assign('ssMappingID', $ssMappingId); } $group_contact_status = array(); foreach (CRM_Core_SelectValues::groupContactStatus() as $k => $v) { if (!empty($k)) { $group_contact_status[] = HTML_QuickForm::createElement('checkbox', $k, null, $v); } } $this->addGroup($group_contact_status, 'group_contact_status', ts('Group Status')); /* * commented out to fix CRM-4268 * * $this->addGroupRule( 'group_contact_status', * ts( 'Please select at least Group Status value.' ), 'required', null, 1 ); */ // Set dynamic page title for 'Show Members of Group' CRM_Utils_System::setTitle(ts('Group Members: %1', array(1 => $this->_group[$this->_groupID]))); // check if user has permission to edit members of this group require_once 'CRM/Contact/BAO/Group.php'; $permission = CRM_Contact_BAO_Group::checkPermission($this->_groupID, $this->_group[$this->_groupID]); if ($permission && in_array(CRM_Core_Permission::EDIT, $permission)) { $this->assign('permissionedForGroup', true); } else { $this->assign('permissionedForGroup', false); } } /* * add the go button for the action form, note it is of type 'next' rather than of type 'submit' * */ if ($this->_context === 'amtg') { // Set dynamic page title for 'Add Members Group' CRM_Utils_System::setTitle(ts('Add Members: %1', array(1 => $this->_group[$this->_amtgID]))); // also set the group title and freeze the action task with Add Members to Group $groupValues = array('id' => $this->_amtgID, 'title' => $this->_group[$this->_amtgID]); $this->assign_by_ref('group', $groupValues); $this->add('submit', $this->_actionButtonName, ts('Add Contacts to %1', array(1 => $this->_group[$this->_amtgID])), array('class' => 'form-submit', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 1);")); $this->add('hidden', 'task', CRM_Contact_Task::GROUP_CONTACTS); } else { $this->add('select', 'task', ts('Actions:') . ' ', $tasks); $this->add('submit', $this->_actionButtonName, ts('Go'), array('class' => 'form-submit', 'id' => 'Go', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0);")); } // need to perform tasks on all or selected items ? using radio_ts(task selection) for it $this->addElement('radio', 'radio_ts', null, '', 'ts_sel', array('checked' => 'checked', 'onclick' => 'toggleTaskAction( true );')); $this->addElement('radio', 'radio_ts', null, '', 'ts_all', array('onclick' => $this->getName() . ".toggleSelect.checked = false; toggleCheckboxVals('mark_x_', this);toggleTaskAction( true );")); /* * add form checkboxes for each row. This is needed out here to conform to QF protocol * of all elements being declared in builQuickForm */ $rows = $this->get('rows'); if (is_array($rows)) { $this->addElement('checkbox', 'toggleSelect', null, null, array('onclick' => "toggleTaskAction( true ); return toggleCheckboxVals('mark_x_',this);")); foreach ($rows as $row) { $this->addElement('checkbox', $row['checkbox'], null, null, array('onclick' => "toggleTaskAction( true ); return checkSelectedBox('" . $row['checkbox'] . "', '" . $this->getName() . "');")); } } // add buttons $this->addButtons(array(array('type' => 'refresh', 'name' => ts('Search'), 'isDefault' => true))); $this->add('submit', $this->_printButtonName, ts('Print'), array('class' => 'form-submit', 'id' => 'Print', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 1);")); $this->setDefaultAction('refresh'); }
/** * Build the form object. * * * @return void */ public function buildQuickForm() { parent::buildQuickForm(); $this->addElement('text', 'sort_name', ts('Participant Name or Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); CRM_Event_BAO_Query::buildSearchForm($this); $rows = $this->get('rows'); if (is_array($rows)) { $lineItems = $eventIds = array(); if (!$this->_single) { $this->addRowSelectors($rows); } foreach ($rows as $row) { $eventIds[$row['event_id']] = $row['event_id']; if (CRM_Event_BAO_Event::usesPriceSet($row['event_id'])) { // add line item details if applicable $lineItems[$row['participant_id']] = CRM_Price_BAO_LineItem::getLineItems($row['participant_id']); } } //get actual count only when we are dealing w/ single event. $participantCount = 0; if (count($eventIds) == 1) { //convert form values to clause. $seatClause = array(); if (CRM_Utils_Array::value('participant_test', $this->_formValues) == '1' || CRM_Utils_Array::value('participant_test', $this->_formValues) == '0') { $seatClause[] = "( participant.is_test = {$this->_formValues['participant_test']} )"; } if (!empty($this->_formValues['participant_status_id'])) { $seatClause[] = CRM_Contact_BAO_Query::buildClause("participant.status_id", '=', $this->_formValues['participant_status_id'], 'Int'); if ($status = CRM_Utils_Array::value('IN', $this->_formValues['participant_status_id'])) { $this->_formValues['participant_status_id'] = $status; } } if (!empty($this->_formValues['participant_role_id'])) { $seatClause[] = '( participant.role_id IN ( ' . implode(' , ', (array) $this->_formValues['participant_role_id']) . ' ) )'; } // CRM-15379 if (!empty($this->_formValues['participant_fee_id'])) { $participant_fee_id = $this->_formValues['participant_fee_id']; $feeLabel = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $participant_fee_id, 'label'); $feeLabel = CRM_Core_DAO::escapeString(trim($feeLabel)); $seatClause[] = "( participant.fee_level LIKE '%{$feeLabel}%' )"; } $seatClause = implode(' AND ', $seatClause); $participantCount = CRM_Event_BAO_Event::eventTotalSeats(array_pop($eventIds), $seatClause); } $this->assign('participantCount', $participantCount); $this->assign('lineItems', $lineItems); $permission = CRM_Core_Permission::getPermission(); $tasks = CRM_Event_Task::permissionedTaskTitles($permission); if (isset($this->_ssID)) { if ($permission == CRM_Core_Permission::EDIT) { $tasks = $tasks + CRM_Event_Task::optionalTaskTitle(); } $savedSearchValues = array('id' => $this->_ssID, 'name' => CRM_Contact_BAO_SavedSearch::getName($this->_ssID, 'title')); $this->assign_by_ref('savedSearch', $savedSearchValues); $this->assign('ssID', $this->_ssID); } $this->addTaskMenu($tasks); } }
/** * Build the form object. * * * @return void */ public function buildQuickForm() { parent::buildQuickForm(); $this->addSortNameField(); if (CRM_Core_Permission::check('access deleted contacts') and Civi::settings()->get('contact_undelete')) { $this->addElement('checkbox', 'deleted_contacts', ts('Search in Trash') . '<br />' . ts('(deleted contacts)')); } CRM_Event_BAO_Query::buildSearchForm($this); $rows = $this->get('rows'); if (is_array($rows)) { $lineItems = $eventIds = array(); if (!$this->_single) { $this->addRowSelectors($rows); } foreach ($rows as $row) { $eventIds[$row['event_id']] = $row['event_id']; if (CRM_Event_BAO_Event::usesPriceSet($row['event_id'])) { // add line item details if applicable $lineItems[$row['participant_id']] = CRM_Price_BAO_LineItem::getLineItems($row['participant_id']); } } //get actual count only when we are dealing w/ single event. $participantCount = 0; if (count($eventIds) == 1) { //convert form values to clause. $seatClause = array(); if (CRM_Utils_Array::value('participant_test', $this->_formValues) == '1' || CRM_Utils_Array::value('participant_test', $this->_formValues) == '0') { $seatClause[] = "( participant.is_test = {$this->_formValues['participant_test']} )"; } if (!empty($this->_formValues['participant_status_id'])) { $seatClause[] = CRM_Contact_BAO_Query::buildClause("participant.status_id", '=', $this->_formValues['participant_status_id'], 'Int'); if ($status = CRM_Utils_Array::value('IN', $this->_formValues['participant_status_id'])) { $this->_formValues['participant_status_id'] = $status; } } if (!empty($this->_formValues['participant_role_id'])) { $escapedRoles = array(); foreach ((array) $this->_formValues['participant_role_id'] as $participantRole) { $escapedRoles[] = CRM_Utils_Type::escape($participantRole, 'String'); } $seatClause[] = "( participant.role_id IN ( '" . implode("' , '", $escapedRoles) . "' ) )"; } // CRM-15379 if (!empty($this->_formValues['participant_fee_id'])) { $participant_fee_id = $this->_formValues['participant_fee_id']; foreach ($participant_fee_id as $k => &$val) { $val = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $val, 'label'); $val = CRM_Core_DAO::escapeString(trim($val)); } $feeLabel = implode('|', $participant_fee_id); $seatClause[] = "( participant.fee_level REGEXP '{$feeLabel}' )"; } $seatClause = implode(' AND ', $seatClause); $participantCount = CRM_Event_BAO_Event::eventTotalSeats(array_pop($eventIds), $seatClause); } $this->assign('participantCount', $participantCount); $this->assign('lineItems', $lineItems); $permission = CRM_Core_Permission::getPermission(); $tasks = CRM_Event_Task::permissionedTaskTitles($permission); if (isset($this->_ssID)) { if ($permission == CRM_Core_Permission::EDIT) { $tasks = $tasks + CRM_Event_Task::optionalTaskTitle(); } $savedSearchValues = array('id' => $this->_ssID, 'name' => CRM_Contact_BAO_SavedSearch::getName($this->_ssID, 'title')); $this->assign_by_ref('savedSearch', $savedSearchValues); $this->assign('ssID', $this->_ssID); } $this->addTaskMenu($tasks); } }
/** * Build the form * * @access public * @return void */ function buildQuickForm() { $this->addElement('text', 'sort_name', ts('Participant Name or Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); require_once 'CRM/Event/BAO/Query.php'; CRM_Event_BAO_Query::buildSearchForm($this); /* * add form checkboxes for each row. This is needed out here to conform to QF protocol * of all elements being declared in builQuickForm */ $rows = $this->get('rows'); if (is_array($rows)) { $lineItems = array(); require_once 'CRM/Event/BAO/Event.php'; if (!$this->_single) { $this->addElement('checkbox', 'toggleSelect', null, null, array('onclick' => "toggleTaskAction( true ); return toggleCheckboxVals('mark_x_',this);")); } foreach ($rows as $row) { if (!$this->_single) { $this->addElement('checkbox', $row['checkbox'], null, null, array('onclick' => "toggleTaskAction( true ); return checkSelectedBox('" . $row['checkbox'] . "', '" . $this->getName() . "');")); } if (CRM_Event_BAO_Event::usesPriceSet($row['event_id'])) { // add line item details if applicable require_once 'CRM/Price/BAO/LineItem.php'; $lineItems[$row['participant_id']] = CRM_Price_BAO_LineItem::getLineItems($row['participant_id']); } } $this->assign('lineItems', $lineItems); $total = $cancel = 0; require_once "CRM/Core/Permission.php"; $permission = CRM_Core_Permission::getPermission(); require_once 'CRM/Event/Task.php'; $tasks = array('' => ts('- more actions -')) + CRM_Event_Task::permissionedTaskTitles($permission); if (isset($this->_ssID)) { if ($permission == CRM_Core_Permission::EDIT) { require_once "CRM/Contact/Task.php"; $tasks = $tasks + CRM_Event_Task::optionalTaskTitle(); } $savedSearchValues = array('id' => $this->_ssID, 'name' => CRM_Contact_BAO_SavedSearch::getName($this->_ssID, 'title')); $this->assign_by_ref('savedSearch', $savedSearchValues); $this->assign('ssID', $this->_ssID); } $this->add('select', 'task', ts('Actions:') . ' ', $tasks); $this->add('submit', $this->_actionButtonName, ts('Go'), array('class' => 'form-submit', 'id' => 'Go', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0);")); $this->add('submit', $this->_printButtonName, ts('Print'), array('class' => 'form-submit', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 1);")); // need to perform tasks on all or selected items ? using radio_ts(task selection) for it $this->addElement('radio', 'radio_ts', null, '', 'ts_sel', array('checked' => 'checked')); $this->addElement('radio', 'radio_ts', null, '', 'ts_all', array('onclick' => $this->getName() . ".toggleSelect.checked = false; toggleCheckboxVals('mark_x_',this); toggleTaskAction( true );")); } // add buttons $this->addButtons(array(array('type' => 'refresh', 'name' => ts('Search'), 'isDefault' => true))); }
/** * Build the form * * @access public * * @return void */ function buildQuickForm() { $this->addElement('text', 'sort_name', ts('Participant Name or Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); CRM_Event_BAO_Query::buildSearchForm($this); /* * add form checkboxes for each row. This is needed out here to conform to QF protocol * of all elements being declared in builQuickForm */ $rows = $this->get('rows'); if (is_array($rows)) { $lineItems = $eventIds = array(); if (!$this->_single) { $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('onclick' => "toggleTaskAction( true ); return toggleCheckboxVals('mark_x_',this);")); } foreach ($rows as $row) { $eventIds[$row['event_id']] = $row['event_id']; if (!$this->_single) { $this->addElement('checkbox', $row['checkbox'], NULL, NULL, array('onclick' => "toggleTaskAction( true ); return checkSelectedBox('" . $row['checkbox'] . "');")); } if (CRM_Event_BAO_Event::usesPriceSet($row['event_id'])) { // add line item details if applicable $lineItems[$row['participant_id']] = CRM_Price_BAO_LineItem::getLineItems($row['participant_id']); } } //get actual count only when we are dealing w/ single event. $participantCount = 0; if (count($eventIds) == 1) { //convert form values to clause. $seatClause = array(); // Filter on is_test if specified in search form if (CRM_Utils_Array::value('participant_test', $this->_formValues) == '1' || CRM_Utils_Array::value('participant_test', $this->_formValues) == '0') { $seatClause[] = "( participant.is_test = {$this->_formValues['participant_test']} )"; } if (CRM_Utils_Array::value('participant_status_id', $this->_formValues)) { $statuses = array_keys($this->_formValues['participant_status_id']); $seatClause[] = '( participant.status_id IN ( ' . implode(' , ', $statuses) . ' ) )'; } if (CRM_Utils_Array::value('participant_role_id', $this->_formValues)) { $roles = array_keys($this->_formValues['participant_role_id']); $seatClause[] = '( participant.role_id IN ( ' . implode(' , ', $roles) . ' ) )'; } $clause = NULL; if (!empty($seatClause)) { $clause = implode(' AND ', $seatClause); } $participantCount = CRM_Event_BAO_Event::eventTotalSeats(array_pop($eventIds), $clause); } $this->assign('participantCount', $participantCount); $this->assign('lineItems', $lineItems); $total = $cancel = 0; $permission = CRM_Core_Permission::getPermission(); $tasks = array('' => ts('- actions -')) + CRM_Event_Task::permissionedTaskTitles($permission); if (isset($this->_ssID)) { if ($permission == CRM_Core_Permission::EDIT) { $tasks = $tasks + CRM_Event_Task::optionalTaskTitle(); } $savedSearchValues = array('id' => $this->_ssID, 'name' => CRM_Contact_BAO_SavedSearch::getName($this->_ssID, 'title')); $this->assign_by_ref('savedSearch', $savedSearchValues); $this->assign('ssID', $this->_ssID); } $this->add('select', 'task', ts('Actions:') . ' ', $tasks); $this->add('submit', $this->_actionButtonName, ts('Go'), array('class' => 'form-submit', 'id' => 'Go', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0);")); $this->add('submit', $this->_printButtonName, ts('Print'), array('class' => 'form-submit', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 1);")); // need to perform tasks on all or selected items ? using radio_ts(task selection) for it $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked')); $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all', array('onclick' => $this->getName() . ".toggleSelect.checked = false; toggleCheckboxVals('mark_x_',this); toggleTaskAction( true );")); } // add buttons $this->addButtons(array(array('type' => 'refresh', 'name' => ts('Search'), 'isDefault' => TRUE))); }
/** * Process the form after the input has been submitted and validated. */ public function postProcess() { // saved search form values // get form values of all the forms in this controller $formValues = $this->controller->exportValues(); $isAdvanced = $this->get('isAdvanced'); $isSearchBuilder = $this->get('isSearchBuilder'); // add mapping record only for search builder saved search $mappingId = NULL; if ($isAdvanced == '2' && $isSearchBuilder == '1') { //save the mapping for search builder if (!$this->_id) { //save record in mapping table $mappingParams = array('mapping_type' => 'Search Builder'); $temp = array(); $mapping = CRM_Core_BAO_Mapping::add($mappingParams, $temp); $mappingId = $mapping->id; } else { //get the mapping id from saved search $savedSearch = new CRM_Contact_BAO_SavedSearch(); $savedSearch->id = $this->_id; $savedSearch->find(TRUE); $mappingId = $savedSearch->mapping_id; } //save mapping fields CRM_Core_BAO_Mapping::saveMappingFields($formValues, $mappingId); } //save the search $savedSearch = new CRM_Contact_BAO_SavedSearch(); $savedSearch->id = $this->_id; $savedSearch->form_values = serialize($this->get('formValues')); $savedSearch->mapping_id = $mappingId; $savedSearch->search_custom_id = $this->get('customSearchID'); $savedSearch->save(); $this->set('ssID', $savedSearch->id); CRM_Core_Session::setStatus(ts("Your smart group has been saved as '%1'.", array(1 => $formValues['title'])), ts('Group Saved'), 'success'); // also create a group that is associated with this saved search only if new saved search $params = array(); $params['title'] = $formValues['title']; $params['description'] = $formValues['description']; if (isset($formValues['group_type']) && is_array($formValues['group_type'])) { $params['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($formValues['group_type'])) . CRM_Core_DAO::VALUE_SEPARATOR; } else { $params['group_type'] = ''; } $params['visibility'] = 'User and User Admin Only'; $params['saved_search_id'] = $savedSearch->id; $params['is_active'] = 1; //CRM-14190 $params['parents'] = $formValues['parents']; if ($this->_id) { $params['id'] = CRM_Contact_BAO_SavedSearch::getName($this->_id, 'id'); } $group = CRM_Contact_BAO_Group::create($params); // CRM-9464 $this->_id = $savedSearch->id; //CRM-14190 if (!empty($formValues['parents'])) { CRM_Contact_BAO_GroupNestingCache::update(); } }
/** * Process the form after the input has been submitted and validated. */ public function postProcess() { // saved search form values // get form values of all the forms in this controller $formValues = $this->controller->exportValues(); $isAdvanced = $this->get('isAdvanced'); $isSearchBuilder = $this->get('isSearchBuilder'); // add mapping record only for search builder saved search $mappingId = NULL; if ($isAdvanced == '2' && $isSearchBuilder == '1') { //save the mapping for search builder if (!$this->_id) { //save record in mapping table $mappingParams = array('mapping_type' => 'Search Builder'); $temp = array(); $mapping = CRM_Core_BAO_Mapping::add($mappingParams, $temp); $mappingId = $mapping->id; } else { //get the mapping id from saved search $savedSearch = new CRM_Contact_BAO_SavedSearch(); $savedSearch->id = $this->_id; $savedSearch->find(TRUE); $mappingId = $savedSearch->mapping_id; } //save mapping fields CRM_Core_BAO_Mapping::saveMappingFields($formValues, $mappingId); } //save the search $savedSearch = new CRM_Contact_BAO_SavedSearch(); $savedSearch->id = $this->_id; // Use the query parameters rather than the form values - these have already been assessed / converted // with the extra knowledge that the form has. // Note that we want to move towards a standardised way of saving the query that is not // an exact match for the form requirements & task the form layer with converting backwards and forwards. // Ideally per CRM-17075 we will use entity reference fields heavily in the form layer & convert to the // sql operator syntax at the query layer. $savedSearch->form_values = serialize($this->get('queryParams')); $savedSearch->mapping_id = $mappingId; $savedSearch->search_custom_id = $this->get('customSearchID'); $savedSearch->save(); $this->set('ssID', $savedSearch->id); CRM_Core_Session::setStatus(ts("Your smart group has been saved as '%1'.", array(1 => $formValues['title'])), ts('Group Saved'), 'success'); // also create a group that is associated with this saved search only if new saved search $params = array(); $params['title'] = $formValues['title']; $params['description'] = $formValues['description']; if (isset($formValues['group_type']) && is_array($formValues['group_type'])) { $params['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($formValues['group_type'])) . CRM_Core_DAO::VALUE_SEPARATOR; } else { $params['group_type'] = ''; } $params['visibility'] = 'User and User Admin Only'; $params['saved_search_id'] = $savedSearch->id; $params['is_active'] = 1; //CRM-14190 $params['parents'] = $formValues['parents']; if ($this->_id) { $params['id'] = CRM_Contact_BAO_SavedSearch::getName($this->_id, 'id'); } $group = CRM_Contact_BAO_Group::create($params); // CRM-9464 $this->_id = $savedSearch->id; //CRM-14190 if (!empty($formValues['parents'])) { CRM_Contact_BAO_GroupNestingCache::update(); } }
/** * process the form after the input has been submitted and validated * * @access public * @return void */ public function postProcess() { // saved search form values // get form values of all the forms in this controller $formValues = $this->controller->exportValues(); $isAdvanced = $this->get('isAdvanced'); $isSearchBuilder = $this->get('isSearchBuilder'); // add mapping record only for search builder saved search $mappingId = null; if ($isAdvanced == '2' && $isSearchBuilder == '1') { //save the mapping for search builder require_once "CRM/Core/BAO/Mapping.php"; if (!$this->_id) { //save record in mapping table $mappingParams = array('mapping_type' => 'Search Builder'); $temp = array(); $mapping = CRM_Core_BAO_Mapping::add($mappingParams, $temp); $mappingId = $mapping->id; } else { //get the mapping id from saved search require_once "CRM/Contact/BAO/SavedSearch.php"; $savedSearch = new CRM_Contact_BAO_SavedSearch(); $savedSearch->id = $this->_id; $savedSearch->find(true); $mappingId = $savedSearch->mapping_id; } //save mapping fields CRM_Core_BAO_Mapping::saveMappingFields($formValues, $mappingId); } //save the search $savedSearch = new CRM_Contact_BAO_SavedSearch(); $savedSearch->id = $this->_id; $savedSearch->form_values = serialize($this->get('formValues')); $savedSearch->mapping_id = $mappingId; $savedSearch->search_custom_id = $this->get('customSearchID'); $savedSearch->save(); $this->set('ssID', $savedSearch->id); CRM_Core_Session::setStatus(ts('Your smart group has been saved as \'%1\'.', array(1 => $formValues['title']))); // also create a group that is associated with this saved search only if new saved search $params = array(); $params['title'] = $formValues['title']; $params['description'] = $formValues['description']; if (is_array($formValues['group_type'])) { $params['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($formValues['group_type'])) . CRM_Core_DAO::VALUE_SEPARATOR; } else { $params['group_type'] = ''; } $params['visibility'] = 'User and User Admin Only'; $params['saved_search_id'] = $savedSearch->id; $params['is_active'] = 1; if ($this->_id) { $params['id'] = CRM_Contact_BAO_SavedSearch::getName($this->_id, 'id'); } require_once 'CRM/Contact/BAO/Group.php'; $group =& CRM_Contact_BAO_Group::create($params); }
/** * Build the common elements between the search/advanced form * * @access public * * @return void */ function buildQuickForm() { CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.searchForm.js')->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header'); $permission = CRM_Core_Permission::getPermission(); // some tasks.. what do we want to do with the selected contacts ? $tasks = array('' => ts('- actions -')); if ($this->_componentMode == 1 || $this->_componentMode == 7) { $tasks += CRM_Contact_Task::permissionedTaskTitles($permission, CRM_Utils_Array::value('deleted_contacts', $this->_formValues)); } else { $className = $this->_modeValue['taskClassName']; $tasks += $className::permissionedTaskTitles($permission, false); } if (isset($this->_ssID)) { if ($permission == CRM_Core_Permission::EDIT) { $tasks = $tasks + CRM_Contact_Task::optionalTaskTitle(); } $search_custom_id = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID, 'search_custom_id'); $savedSearchValues = array('id' => $this->_ssID, 'name' => CRM_Contact_BAO_SavedSearch::getName($this->_ssID, 'title'), 'search_custom_id' => $search_custom_id); $this->assign_by_ref('savedSearch', $savedSearchValues); $this->assign('ssID', $this->_ssID); } if ($this->_context === 'smog') { // CRM-11788, we might want to do this for all of search where force=1 $formQFKey = CRM_Utils_Array::value('qfKey', $this->_formValues); $getQFKey = CRM_Utils_Array::value('qfKey', $_GET); $postQFKey = CRM_Utils_Array::value('qfKey', $_POST); if ($formQFKey && empty($getQFKey) && empty($postQFKey)) { $url = CRM_Utils_System::makeURL('qfKey') . $formQFKey; CRM_Utils_System::redirect($url); } if (!empty($this->_groupID)) { $permissionForGroup = FALSE; // check if user has permission to edit members of this group $permission = CRM_Contact_BAO_Group::checkPermission($this->_groupID); if ($permission && in_array(CRM_Core_Permission::EDIT, $permission)) { $permissionForGroup = TRUE; } // check if _groupID exists, it might not if // we are displaying a hidden group if (!isset($this->_group[$this->_groupID])) { $permissionForGroup = FALSE; $this->_group[$this->_groupID] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID, 'title'); } $this->assign('permissionedForGroup', $permissionForGroup); // set the group title $groupValues = array('id' => $this->_groupID, 'title' => $this->_group[$this->_groupID]); $this->assign_by_ref('group', $groupValues); // also set ssID if this is a saved search $ssID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID, 'saved_search_id'); $this->assign('ssID', $ssID); //get the saved search mapping id if ($ssID) { $this->_ssID = $ssID; $ssMappingId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $ssID, 'mapping_id'); $this->assign('ssMappingID', $ssMappingId); } // Set dynamic page title for 'Show Members of Group' CRM_Utils_System::setTitle(ts('Contacts in Group: %1', array(1 => $this->_group[$this->_groupID]))); } $group_contact_status = array(); foreach (CRM_Core_SelectValues::groupContactStatus() as $k => $v) { if (!empty($k)) { $group_contact_status[] = $this->createElement('checkbox', $k, NULL, $v); } } $this->addGroup($group_contact_status, 'group_contact_status', ts('Group Status')); $this->assign('permissionedForGroup', FALSE); } // add the go button for the action form, note it is of type 'next' rather than of type 'submit' if ($this->_context === 'amtg') { // check if _groupID exists, it might not if // we are displaying a hidden group if (!isset($this->_group[$this->_amtgID])) { $this->assign('permissionedForGroup', FALSE); $this->_group[$this->_amtgID] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_amtgID, 'title'); } // Set dynamic page title for 'Add Members Group' CRM_Utils_System::setTitle(ts('Add to Group: %1', array(1 => $this->_group[$this->_amtgID]))); // also set the group title and freeze the action task with Add Members to Group $groupValues = array('id' => $this->_amtgID, 'title' => $this->_group[$this->_amtgID]); $this->assign_by_ref('group', $groupValues); $this->add('submit', $this->_actionButtonName, ts('Add Contacts to %1', array(1 => $this->_group[$this->_amtgID])), array('class' => 'form-submit', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 1);")); $this->add('hidden', 'task', CRM_Contact_Task::GROUP_CONTACTS); } else { $this->add('select', 'task', ts('Actions:') . ' ', $tasks); $this->add('submit', $this->_actionButtonName, ts('Go'), array('class' => 'form-submit', 'id' => 'Go', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0, 1);")); } // need to perform tasks on all or selected items ? using radio_ts(task selection) for it $selectedRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked', 'onclick' => 'toggleTaskAction( true );')); $this->assign('ts_sel_id', $selectedRowsRadio->_attributes['id']); if ($qfKeyParam = CRM_Utils_Array::value('qfKey', $this->_formValues)) { $qfKeyParam = "civicrm search {$qfKeyParam}"; $selectedContactIdsArr = CRM_Core_BAO_PrevNextCache::getSelection($qfKeyParam); $selectedContactIds = array_keys($selectedContactIdsArr[$qfKeyParam]); } $this->assign_by_ref('selectedContactIds', $selectedContactIds); $allRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all', array('class' => 'select-rows', 'onclick' => $this->getName() . ".toggleSelect.checked = false; toggleTaskAction( true );toggleContactSelection( 'resetSel', '{$qfKeyParam}', 'reset' );")); $this->assign('ts_all_id', $allRowsRadio->_attributes['id']); /* * add form checkboxes for each row. This is needed out here to conform to QF protocol * of all elements being declared in builQuickForm */ $rows = $this->get('rows'); if (is_array($rows)) { $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('class' => 'select-rows', 'onclick' => "toggleTaskAction( true ); toggleContactSelection( 'toggleSelect', '" . $qfKeyParam . "' , 'multiple' );")); $unselectedContactIds = array(); foreach ($rows as $row) { $this->addElement('checkbox', $row['checkbox'], NULL, NULL, array('onclick' => "toggleContactSelection( '" . $row['checkbox'] . "', '" . $qfKeyParam . "' , 'single' );toggleTaskAction( true );", 'class' => 'select-row')); if (!in_array($row['contact_id'], $selectedContactIds)) { $unselectedContactIds[] = $row['contact_id']; } } $this->assign_by_ref('unselectedContactIds', $unselectedContactIds); } // add buttons $this->addButtons(array(array('type' => 'refresh', 'name' => ts('Search'), 'isDefault' => TRUE))); $this->setDefaultAction('refresh'); }
/** * process the form after the input has been submitted and validated * * @access public * @return void */ function postProcess() { // saved search form values $formValues = $this->controller->exportValues($this->_name); // save the search $savedSearch =& new CRM_Contact_BAO_SavedSearch(); $savedSearch->id = $this->_id; $savedSearch->domain_id = CRM_Core_Config::domainID(); $savedSearch->form_values = serialize($this->get('formValues')); $savedSearch->is_active = 1; $savedSearch->save(); $this->set('ssID', $savedSearch->id); CRM_Core_Session::setStatus(ts('Your smart group has been saved as "%1".', array(1 => $formValues['title']))); // also create a group that is associated with this saved search only if new saved search $params = array(); $params['domain_id'] = CRM_Core_Config::domainID(); $params['title'] = $formValues['title']; $params['description'] = $formValues['description']; $params['visibility'] = 'User and User Admin Only'; $params['saved_search_id'] = $savedSearch->id; $params['is_active'] = 1; if ($this->_id) { $params['id'] = CRM_Contact_BAO_SavedSearch::getName($this->_id, 'id'); } $group =& CRM_Contact_BAO_Group::create($params); }