/** * Process the form after the input has been submitted and validated. */ public function postProcess() { $formparams = $this->exportValues(); $caseId = $formparams['unclosed_case_id']; $filedActivities = 0; foreach ($this->_activityHolderIds as $key => $id) { $targetContactValues = $defaults = array(); $params = array('id' => $id); CRM_Activity_BAO_Activity::retrieve($params, $defaults); if (CRM_Case_BAO_Case::checkPermission($id, 'File On Case', $defaults['activity_type_id'])) { if (!CRM_Utils_Array::crmIsEmptyArray($defaults['target_contact'])) { $targetContactValues = array_combine(array_unique($defaults['target_contact']), explode(';', trim($defaults['target_contact_value']))); $targetContactValues = implode(',', array_keys($targetContactValues)); } $params = array('caseID' => $caseId, 'activityID' => $id, 'newSubject' => empty($defaults['subject']) ? '' : $defaults['subject'], 'targetContactIds' => $targetContactValues, 'mode' => 'file'); $error_msg = CRM_Activity_Page_AJAX::_convertToCaseActivity($params); if (empty($error_msg['error_msg'])) { $filedActivities++; } else { CRM_Core_Session::setStatus($error_msg['error_msg'], ts("Error"), "error"); } } else { CRM_Core_Session::setStatus(ts('Not permitted to file activity %1 %2.', array(1 => empty($defaults['subject']) ? '' : $defaults['subject'], 2 => $defaults['activity_date_time'])), ts("Error"), "error"); } } CRM_Core_Session::setStatus($filedActivities, ts("Filed Activities"), "success"); CRM_Core_Session::setStatus("", ts('Total Selected Activities: %1', array(1 => count($this->_activityHolderIds))), "info"); }
static function _toRearrangeTokenArray($tokens) { $tokenArray = array(); if (CRM_Utils_Array::crmIsEmptyArray($tokens)) { return $tokenArray; } foreach ($tokens as $key => $value) { $explodedValues = explode('_', $value); $tokenArray[$explodedValues[0]][$explodedValues[2]] = $value; } return $tokenArray; }
/** * This function sets the default values for the form. For edit/view mode * the default values are retrieved from the database * * @access public * * @return None */ function setDefaultValues() { $targetContactValues = $defaults = array(); $params = array('id' => $this->_activityId); CRM_Activity_BAO_Activity::retrieve($params, $defaults); $defaults['case_activity_subject'] = $defaults['subject']; if (!CRM_Utils_Array::crmIsEmptyArray($defaults['target_contact'])) { $targetContactValues = array_combine(array_unique($defaults['target_contact']), explode(';', trim($defaults['target_contact_value']))); } $this->assign('targetContactValues', empty($targetContactValues) ? FALSE : $targetContactValues); return $defaults; }
function run() { $qrToken = QRCODE_SETTING_DB_COLUMN_QRCODE_TOKEN; $qrTarget = QRCODE_SETTING_DB_COLUMN_QRCODE_TARGET; $argExt = QRCODE_SETTING_DB_COLUMN_QRCODE_ARG_EXT; $argCs = QRCODE_SETTING_DB_COLUMN_QRCODE_ARG_CS; $QrCodeDAO = CRM_Civiqrcode_Form_QRCodeSettings::getQrDetails(); $existingQrcodeTokens = array(); while ($QrCodeDAO->fetch()) { $url = CRM_Utils_System::url('civicrm/admin/form/qrcodesetting', 'reset=1&action=update&id=' . $QrCodeDAO->id, TRUE); $existingQrcodeTokens[$QrCodeDAO->id] = array('qr_token_name' => $QrCodeDAO->{$qrToken}, 'qr_target_url' => $QrCodeDAO->{$qrTarget}, 'arg_externalid' => $QrCodeDAO->{$argExt}, 'arg_checksum' => $QrCodeDAO->{$argCs}, 'token_replace' => "[CiviCRM.civiqrcode.{$QrCodeDAO->{$qrToken}};block=w:image;ope=changepic]", 'action' => sprintf("<span><a href='%s'>Edit</a></span> \n <span><a href='javascript:void(0)' onclick='delQrCode(%d);'>Delete</a></span>", $url, $QrCodeDAO->id)); } if (!CRM_Utils_Array::crmIsEmptyArray($existingQrcodeTokens)) { $this->assign('existingQrcodeTokens', $existingQrcodeTokens); } $this->assign('addone', CRM_Utils_System::url('civicrm/admin/form/qrcodesetting', 'reset=1')); parent::run(); }
/** * Function used to build form element for soft credit block * * @param object $form form object * @access public * * @return void */ static function buildQuickForm(&$form) { $prefix = 'soft_credit_'; // by default generate 5 blocks $item_count = 6; $showSoftCreditRow = 2; $showCreateNew = TRUE; if ($form->_action & CRM_Core_Action::UPDATE) { $form->_softCreditInfo = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($form->_id, TRUE); if (!empty($form->_softCreditInfo['soft_credit'])) { $showSoftCreditRow = count($form->_softCreditInfo['soft_credit']); $showSoftCreditRow++; $showCreateNew = FALSE; } } for ($rowNumber = 1; $rowNumber <= $item_count; $rowNumber++) { CRM_Contact_Form_NewContact::buildQuickForm($form, $rowNumber, NULL, FALSE, $prefix); $form->addMoney("{$prefix}amount[{$rowNumber}]", ts('Amount'), FALSE, NULL, FALSE); if (!empty($form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id'])) { $form->add('hidden', "{$prefix}id[{$rowNumber}]", $form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id']); } } // CRM-7368 allow user to set or edit PCP link for contributions $siteHasPCPs = CRM_Contribute_PseudoConstant::pcPage(); if (!CRM_Utils_Array::crmIsEmptyArray($siteHasPCPs)) { $form->assign('siteHasPCPs', 1); $pcpDataUrl = CRM_Utils_System::url('civicrm/ajax/rest', 'className=CRM_Contact_Page_AJAX&fnName=getPCPList&json=1&context=contact&reset=1', FALSE, NULL, FALSE); $form->assign('pcpDataUrl', $pcpDataUrl); $form->addElement('text', 'pcp_made_through', ts('Credit to a Personal Campaign Page')); $form->addElement('hidden', 'pcp_made_through_id', '', array('id' => 'pcp_made_through_id')); $form->addElement('checkbox', 'pcp_display_in_roll', ts('Display in Honor Roll?'), NULL); $form->addElement('text', 'pcp_roll_nickname', ts('Name (for Honor Roll)')); $form->addElement('textarea', 'pcp_personal_note', ts('Personal Note (for Honor Roll)')); } $form->assign('showSoftCreditRow', $showSoftCreditRow); $form->assign('rowCount', $item_count); $form->assign('showCreateNew', $showCreateNew); // Tell tpl to hide soft credit field if contribution is linked directly to a PCP Page if (CRM_Utils_Array::value('pcp_made_through_id', $form->_values)) { $form->assign('pcpLinked', 1); } }
/** * Add PCP fields for the new contribution form and others. * * @param CRM_Core_Form &$form * The form being built. * @param string $suffix * A suffix to add to field names. */ public static function addPCPFields(&$form, $suffix = '') { // CRM-7368 allow user to set or edit PCP link for contributions $siteHasPCPs = CRM_Contribute_PseudoConstant::pcPage(); if (!CRM_Utils_Array::crmIsEmptyArray($siteHasPCPs)) { $form->assign('siteHasPCPs', 1); // Fixme: Not a true entityRef field. Relies on PCP.js.tpl $form->add('text', "pcp_made_through_id{$suffix}", ts('Credit to a Personal Campaign Page'), array('class' => 'twenty', 'placeholder' => ts('- select -'))); // stores the label $form->add('hidden', "pcp_made_through{$suffix}"); $form->addElement('checkbox', "pcp_display_in_roll{$suffix}", ts('Display in Honor Roll?'), NULL); $form->addElement('text', "pcp_roll_nickname{$suffix}", ts('Name (for Honor Roll)')); $form->addElement('textarea', "pcp_personal_note{$suffix}", ts('Personal Note (for Honor Roll)')); } }
/** * Global validation rules for the form. * * @param array $values * Posted values of the form. * @param $files * @param $self * * @return array * list of errors to be posted back to the form */ public static function formRule($values, $files, $self) { // If $values['_qf_Participant_next'] is Delete or // $values['event_id'] is empty, then return // instead of proceeding further. if (CRM_Utils_Array::value('_qf_Participant_next', $values) == 'Delete' || !$values['event_id']) { return TRUE; } $errorMsg = array(); if (!empty($values['payment_processor_id'])) { // make sure that payment instrument values (e.g. credit card number and cvv) are valid CRM_Core_Payment_Form::validatePaymentInstrument($values['payment_processor_id'], $values, $errorMsg, NULL); } if (!empty($values['record_contribution'])) { if (empty($values['financial_type_id'])) { $errorMsg['financial_type_id'] = ts('Please enter the associated Financial Type'); } if (empty($values['payment_instrument_id'])) { $errorMsg['payment_instrument_id'] = ts('Payment Method is a required field.'); } } // validate contribution status for 'Failed'. if ($self->_onlinePendingContributionId && !empty($values['record_contribution']) && CRM_Utils_Array::value('contribution_status_id', $values) == array_search('Failed', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'))) { $errorMsg['contribution_status_id'] = ts('Please select a valid payment status before updating.'); } // do the amount validations. //skip for update mode since amount is freeze, CRM-6052 if (!$self->_id && empty($values['total_amount']) && empty($self->_values['line_items']) || $self->_id && !$self->_paymentId && isset($self->_values['line_items']) && is_array($self->_values['line_items'])) { if ($priceSetId = CRM_Utils_Array::value('priceSetId', $values)) { CRM_Price_BAO_PriceField::priceSetValidation($priceSetId, $values, $errorMsg, TRUE); } } // For single additions - show validation error if the contact has already been registered // for this event with the same role. if ($self->_single && $self->_action & CRM_Core_Action::ADD) { $contactId = $self->_contactId; $eventId = CRM_Utils_Array::value('event_id', $values); if (!empty($contactId) && !empty($eventId)) { $dupeCheck = new CRM_Event_BAO_Participant(); $dupeCheck->contact_id = $contactId; $dupeCheck->event_id = $eventId; $dupeCheck->find(TRUE); if (!empty($dupeCheck->id)) { $errorMsg['event_id'] = ts("This contact has already been assigned to this event."); } } } return CRM_Utils_Array::crmIsEmptyArray($errorMsg) ? TRUE : $errorMsg; }
/** * Process activity creation. * * @param array $params * Associated array of submitted values. * * @return self|null|object */ protected function processActivity(&$params) { $activityAssigned = array(); $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); // format assignee params if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) { //skip those assignee contacts which are already assigned //while sending a copy.CRM-4509. $activityAssigned = array_flip($params['assignee_contact_id']); if ($this->_activityId) { $assigneeContacts = CRM_Activity_BAO_ActivityContact::getNames($this->_activityId, $assigneeID); $activityAssigned = array_diff_key($activityAssigned, $assigneeContacts); } } // call begin post process. Idea is to let injecting file do // any processing before the activity is added/updated. $this->beginPostProcess($params); $activity = CRM_Activity_BAO_Activity::create($params); // add tags if exists $tagParams = array(); if (!empty($params['tag'])) { foreach ($params['tag'] as $tag) { $tagParams[$tag] = 1; } } // Save static tags. CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_activity', $activity->id); // Save free tags. if (isset($params['activity_taglist']) && !empty($params['activity_taglist'])) { CRM_Core_Form_Tag::postProcess($params['activity_taglist'], $activity->id, 'civicrm_activity', $this); } // call end post process. Idea is to let injecting file do any // processing needed, after the activity has been added/updated. $this->endPostProcess($params, $activity); // CRM-9590 if (!empty($params['is_multi_activity'])) { $this->_activityIds[] = $activity->id; } else { $this->_activityId = $activity->id; } // create follow up activity if needed $followupStatus = ''; $followupActivity = NULL; if (!empty($params['followup_activity_type_id'])) { $followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($activity->id, $params); $followupStatus = ts('A followup activity has been scheduled.'); } // send copy to assignee contacts.CRM-4509 $mailStatus = ''; if (Civi::settings()->get('activity_assignee_notification')) { $activityIDs = array($activity->id); if ($followupActivity) { $activityIDs = array_merge($activityIDs, array($followupActivity->id)); } $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activityIDs, TRUE, FALSE); if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) { $mailToContacts = array(); // Build an associative array with unique email addresses. foreach ($activityAssigned as $id => $dnc) { if (isset($id) && array_key_exists($id, $assigneeContacts)) { $mailToContacts[$assigneeContacts[$id]['email']] = $assigneeContacts[$id]; } } $sent = CRM_Activity_BAO_Activity::sendToAssignee($activity, $mailToContacts); if ($sent) { $mailStatus .= ts("A copy of the activity has also been sent to assignee contacts(s)."); } } // Also send email to follow-up activity assignees if set if ($followupActivity) { $mailToFollowupContacts = array(); foreach ($assigneeContacts as $values) { if ($values['activity_id'] == $followupActivity->id) { $mailToFollowupContacts[$values['email']] = $values; } } $sentFollowup = CRM_Activity_BAO_Activity::sendToAssignee($followupActivity, $mailToFollowupContacts); if ($sentFollowup) { $mailStatus .= '<br />' . ts("A copy of the follow-up activity has also been sent to follow-up assignee contacts(s)."); } } } // set status message $subject = ''; if (!empty($params['subject'])) { $subject = "'" . $params['subject'] . "'"; } CRM_Core_Session::setStatus(ts('Activity %1 has been saved. %2 %3', array(1 => $subject, 2 => $followupStatus, 3 => $mailStatus)), ts('Saved'), 'success'); return $activity; }
/** * global validation rules for the form * * @param array $fields posted values of the form * * @return array list of errors to be posted back to the form * @static * @access public */ static function formRule($values, $files, $self) { $errorMsg = array(); if (!empty($values['tax_rate'])) { if ($values['tax_rate'] <= 0 || $values['tax_rate'] > 100) { $errorMsg['tax_rate'] = ts('Tax Rate Should be between 0 - 100'); } } return CRM_Utils_Array::crmIsEmptyArray($errorMsg) ? true : $errorMsg; }
/** * Set default values for the form. For edit/view mode * the default values are retrieved from the database * * * @return void */ public function setDefaultValues() { $this->_defaults = parent::setDefaultValues(); $targetContactValues = array(); foreach ($this->_caseId as $key => $val) { //get all clients. $clients = CRM_Case_BAO_Case::getContactNames($val); if (isset($this->_activityId) && empty($_POST)) { if (!CRM_Utils_Array::crmIsEmptyArray($this->_defaults['target_contact'])) { $targetContactValues = array_combine(array_unique($this->_defaults['target_contact']), explode(';', trim($this->_defaults['target_contact_value']))); //exclude all clients. foreach ($clients as $clientId => $vals) { if (array_key_exists($clientId, $targetContactValues)) { unset($targetContactValues[$clientId]); } } } } $this->assign('targetContactValues', empty($targetContactValues) ? FALSE : $targetContactValues); if (isset($this->_encounterMedium)) { $this->_defaults['medium_id'] = $this->_encounterMedium; } elseif (empty($this->_defaults['medium_id'])) { // set default encounter medium CRM-4816 $medium = CRM_Core_OptionGroup::values('encounter_medium', FALSE, FALSE, FALSE, 'AND is_default = 1'); if (count($medium) == 1) { $this->_defaults['medium_id'] = key($medium); } } return $this->_defaults; } }
/** * global validation rules for the form * * @param array $fields posted values of the form * * @return array list of errors to be posted back to the form * @static * @access public */ static function formRule($values, $files, $self) { // If $values['_qf_Participant_next'] is Delete or // $values['event_id'] is empty, then return // instead of proceeding further. if (CRM_Utils_Array::value('_qf_Participant_next', $values) == 'Delete' || !$values['event_id']) { return TRUE; } $errorMsg = array(); //check if contact is selected in standalone mode if (isset($values['contact_select_id'][1]) && !$values['contact_select_id'][1]) { $errorMsg['contact[1]'] = ts('Please select a contact or create new contact'); } if (CRM_Utils_Array::value('payment_processor_id', $values)) { // make sure that credit card number and cvv are valid CRM_Core_Payment_Form::validateCreditCard($values, $errorMsg); } if (CRM_Utils_Array::value('record_contribution', $values)) { if (!CRM_Utils_Array::value('financial_type_id', $values)) { $errorMsg['financial_type_id'] = ts('Please enter the associated Financial Type'); } if (!CRM_Utils_Array::value('payment_instrument_id', $values)) { $errorMsg['payment_instrument_id'] = ts('Paid By is a required field.'); } } // validate contribution status for 'Failed'. if ($self->_onlinePendingContributionId && CRM_Utils_Array::value('record_contribution', $values) && CRM_Utils_Array::value('contribution_status_id', $values) == array_search('Failed', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'))) { $errorMsg['contribution_status_id'] = ts('Please select a valid payment status before updating.'); } // do the amount validations. //skip for update mode since amount is freeze, CRM-6052 if (!$self->_id && !CRM_Utils_Array::value('total_amount', $values) && empty($self->_values['line_items']) || $self->_id && !$self->_paymentId && isset($self->_values['line_items']) && is_array($self->_values['line_items'])) { if ($priceSetId = CRM_Utils_Array::value('priceSetId', $values)) { CRM_Price_BAO_PriceField::priceSetValidation($priceSetId, $values, $errorMsg, TRUE); } } return CRM_Utils_Array::crmIsEmptyArray($errorMsg) ? TRUE : $errorMsg; }
/** * Function used to build form element for soft credit block. * * @param CRM_Core_Form $form * * @return void */ public static function buildQuickForm(&$form) { if (!empty($form->_honor_block_is_active)) { $ufJoinDAO = new CRM_Core_DAO_UFJoin(); $ufJoinDAO->module = 'soft_credit'; $ufJoinDAO->entity_id = $form->_id; if ($ufJoinDAO->find(TRUE)) { $jsonData = CRM_Contribute_BAO_ContributionPage::formatMultilingualHonorParams($ufJoinDAO->module_data, TRUE); if ($jsonData) { foreach (array('honor_block_title', 'honor_block_text') as $name) { $form->assign($name, $jsonData[$name]); } $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE); // radio button for Honor Type foreach ($jsonData['soft_credit_types'] as $value) { $honorTypes[$value] = $form->createElement('radio', NULL, NULL, $softCreditTypes[$value], $value); } $form->addGroup($honorTypes, 'soft_credit_type_id', NULL)->setAttribute('allowClear', TRUE); } } return $form; } // by default generate 10 blocks $item_count = 11; $showSoftCreditRow = 2; if ($form->getAction() & CRM_Core_Action::UPDATE) { $form->_softCreditInfo = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($form->_id, TRUE); } elseif (!empty($form->_pledgeID)) { //Check and select most recent completed contrubtion and use it to retrieve //soft-credit information to use as default for current pledge payment, CRM-13981 $pledgePayments = CRM_Pledge_BAO_PledgePayment::getPledgePayments($form->_pledgeID); foreach ($pledgePayments as $id => $record) { if ($record['contribution_id']) { $softCredits = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($record['contribution_id'], TRUE); if ($record['status'] == 'Completed' && count($softCredits) > 0) { $form->_softCreditInfo = $softCredits; } } } } if (property_exists($form, "_softCreditInfo")) { if (!empty($form->_softCreditInfo['soft_credit'])) { $showSoftCreditRow = count($form->_softCreditInfo['soft_credit']); $showSoftCreditRow++; } } for ($rowNumber = 1; $rowNumber <= $item_count; $rowNumber++) { $form->addEntityRef("soft_credit_contact_id[{$rowNumber}]", ts('Contact'), array('create' => TRUE)); $form->addMoney("soft_credit_amount[{$rowNumber}]", ts('Amount'), FALSE, NULL, FALSE); $form->addSelect("soft_credit_type[{$rowNumber}]", array('entity' => 'contribution_soft', 'field' => 'soft_credit_type_id', 'label' => ts('Type'))); if (!empty($form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id'])) { $form->add('hidden', "soft_credit_id[{$rowNumber}]", $form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id']); } } // CRM-7368 allow user to set or edit PCP link for contributions $siteHasPCPs = CRM_Contribute_PseudoConstant::pcPage(); if (!CRM_Utils_Array::crmIsEmptyArray($siteHasPCPs)) { $form->assign('siteHasPCPs', 1); // Fixme: Not a true entityRef field. Relies on PCP.js.tpl $form->add('text', 'pcp_made_through_id', ts('Credit to a Personal Campaign Page'), array('class' => 'twenty', 'placeholder' => ts('- select -'))); // stores the label $form->add('hidden', 'pcp_made_through'); $form->addElement('checkbox', 'pcp_display_in_roll', ts('Display in Honor Roll?'), NULL); $form->addElement('text', 'pcp_roll_nickname', ts('Name (for Honor Roll)')); $form->addElement('textarea', 'pcp_personal_note', ts('Personal Note (for Honor Roll)')); } $form->assign('showSoftCreditRow', $showSoftCreditRow); $form->assign('rowCount', $item_count); $form->addElement('hidden', 'sct_default_id', CRM_Core_OptionGroup::getDefaultValue("soft_credit_type"), array('id' => 'sct_default_id')); }
/** * Process activity creation * * @param array $params associated array of submitted values * @access protected */ protected function processActivity(&$params) { $activityAssigned = array(); $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); // format assignee params if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) { //skip those assignee contacts which are already assigned //while sending a copy.CRM-4509. $activityAssigned = array_flip($params['assignee_contact_id']); if ($this->_activityId) { $assigneeContacts = CRM_Activity_BAO_ActivityContact::getNames($this->_activityId, $assigneeID); $activityAssigned = array_diff_key($activityAssigned, $assigneeContacts); } } // call begin post process. Idea is to let injecting file do // any processing before the activity is added/updated. $this->beginPostProcess($params); $activity = CRM_Activity_BAO_Activity::create($params); // add tags if exists $tagParams = array(); if (!empty($params['tag'])) { foreach ($params['tag'] as $tag) { $tagParams[$tag] = 1; } } //save static tags CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_activity', $activity->id); //save free tags if (isset($params['activity_taglist']) && !empty($params['activity_taglist'])) { CRM_Core_Form_Tag::postProcess($params['activity_taglist'], $activity->id, 'civicrm_activity', $this); } // call end post process. Idea is to let injecting file do any // processing needed, after the activity has been added/updated. $this->endPostProcess($params, $activity); // CRM-9590 if (CRM_Utils_Array::value('is_multi_activity', $params)) { $this->_activityIds[] = $activity->id; } else { $this->_activityId = $activity->id; } // create follow up activity if needed $followupStatus = ''; if (CRM_Utils_Array::value('followup_activity_type_id', $params)) { CRM_Activity_BAO_Activity::createFollowupActivity($activity->id, $params); $followupStatus = ts('A followup activity has been scheduled.'); } // send copy to assignee contacts.CRM-4509 $mailStatus = ''; if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id']) && CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'activity_assignee_notification')) { $mailToContacts = array(); $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id, TRUE, FALSE); //build an associative array with unique email addresses. foreach ($activityAssigned as $id => $dnc) { if (isset($id) && array_key_exists($id, $assigneeContacts)) { $mailToContacts[$assigneeContacts[$id]['email']] = $assigneeContacts[$id]; } } if (!CRM_Utils_array::crmIsEmptyArray($mailToContacts)) { //include attachments while sending a copy of activity. $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id); $ics = new CRM_Activity_BAO_ICalendar($activity); $ics->addAttachment($attachments, $mailToContacts); // CRM-8400 add param with _currentlyViewedContactId for URL link in mail CRM_Case_BAO_Case::sendActivityCopy(NULL, $activity->id, $mailToContacts, $attachments, NULL); $ics->cleanup(); $mailStatus .= ts("A copy of the activity has also been sent to assignee contacts(s)."); } } // set status message $subject = ''; if (CRM_Utils_Array::value('subject', $params)) { $subject = "'" . $params['subject'] . "'"; } CRM_Core_Session::setStatus(ts('Activity %1 has been saved. %2 %3', array(1 => $subject, 2 => $followupStatus, 3 => $mailStatus)), ts('Saved'), 'success'); return $activity; }
/** * Function to process the form * * @access public * * @return None */ public function postProcess($params = NULL) { if ($this->_action & CRM_Core_Action::DELETE) { $deleteParams = array('id' => $this->_activityId); $moveToTrash = CRM_Case_BAO_Case::isCaseActivity($this->_activityId); CRM_Activity_BAO_Activity::deleteActivity($deleteParams, $moveToTrash); // delete tags for the entity $tagParams = array('entity_table' => 'civicrm_activity', 'entity_id' => $this->_activityId); CRM_Core_BAO_EntityTag::del($tagParams); CRM_Core_Session::setStatus(ts("Selected Activity has been deleted successfully.")); return; } // store the submitted values in an array if (!$params) { $params = $this->controller->exportValues($this->_name); } //set activity type id if (!CRM_Utils_Array::value('activity_type_id', $params)) { $params['activity_type_id'] = $this->_activityTypeId; } if (CRM_Utils_Array::value('hidden_custom', $params) && !isset($params['custom'])) { $customFields = CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, $this->_activityTypeId); $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, NULL, NULL, TRUE)); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_activityId, 'Activity'); } // store the date with proper format $params['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']); // assigning formated value to related variable if (CRM_Utils_Array::value('target_contact_id', $params)) { $params['target_contact_id'] = explode(',', $params['target_contact_id']); } else { $params['target_contact_id'] = array(); } if (CRM_Utils_Array::value('assignee_contact_id', $params)) { $params['assignee_contact_id'] = explode(',', $params['assignee_contact_id']); } else { $params['assignee_contact_id'] = array(); } // get ids for associated contacts if (!$params['source_contact_id']) { $params['source_contact_id'] = $this->_currentUserId; } else { $params['source_contact_id'] = $this->_submitValues['source_contact_qid']; } if (isset($this->_activityId)) { $params['id'] = $this->_activityId; } // add attachments as needed CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_activity', $this->_activityId); // format target params if (!$this->_single) { $params['target_contact_id'] = $this->_contactIds; } $activityAssigned = array(); // format assignee params if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) { //skip those assignee contacts which are already assigned //while sending a copy.CRM-4509. $activityAssigned = array_flip($params['assignee_contact_id']); if ($this->_activityId) { $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($this->_activityId); $activityAssigned = array_diff_key($activityAssigned, $assigneeContacts); } } // call begin post process. Idea is to let injecting file do // any processing before the activity is added/updated. $this->beginPostProcess($params); $activity = CRM_Activity_BAO_Activity::create($params); // add tags if exists $tagParams = array(); if (!empty($params['tag'])) { foreach ($params['tag'] as $tag) { $tagParams[$tag] = 1; } } //save static tags CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_activity', $activity->id); //save free tags if (isset($params['activity_taglist']) && !empty($params['activity_taglist'])) { CRM_Core_Form_Tag::postProcess($params['activity_taglist'], $activity->id, 'civicrm_activity', $this); } // call end post process. Idea is to let injecting file do any // processing needed, after the activity has been added/updated. $this->endPostProcess($params, $activity); // CRM-9590 $this->_activityId = $activity->id; // create follow up activity if needed $followupStatus = ''; if (CRM_Utils_Array::value('followup_activity_type_id', $params)) { $followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($activity->id, $params); $followupStatus = ts('A followup activity has been scheduled.'); } // send copy to assignee contacts.CRM-4509 $mailStatus = ''; if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id']) && CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'activity_assignee_notification')) { $mailToContacts = array(); $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id, TRUE, FALSE); //build an associative array with unique email addresses. foreach ($activityAssigned as $id => $dnc) { if (isset($id) && array_key_exists($id, $assigneeContacts)) { $mailToContacts[$assigneeContacts[$id]['email']] = $assigneeContacts[$id]; } } if (!CRM_Utils_array::crmIsEmptyArray($mailToContacts)) { //include attachments while sendig a copy of activity. $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id); // CRM-8400 add param with _currentlyViewedContactId for URL link in mail $result = CRM_Case_BAO_Case::sendActivityCopy(NULL, $activity->id, $mailToContacts, $attachments, NULL); $mailStatus .= ts("A copy of the activity has also been sent to assignee contacts(s)."); } } // set status message if (CRM_Utils_Array::value('subject', $params)) { $params['subject'] = "'" . $params['subject'] . "'"; } CRM_Core_Session::setStatus(ts('Activity %1 has been saved. %2. %3', array(1 => $params['subject'], 2 => $followupStatus, 3 => $mailStatus))); return array('activity' => $activity); }
/** * Function to build the form * * @return None * @access public */ public function buildQuickForm() { if ($this->_cdType) { return CRM_Custom_Form_CustomData::buildQuickForm($this); } // build price set form. $buildPriceSet = FALSE; if (empty($this->_lineItems) && ($this->_priceSetId || CRM_Utils_Array::value('price_set_id', $_POST))) { $buildPriceSet = TRUE; $getOnlyPriceSetElements = TRUE; if (!$this->_priceSetId) { $this->_priceSetId = $_POST['price_set_id']; $getOnlyPriceSetElements = FALSE; } $this->set('priceSetId', $this->_priceSetId); CRM_Price_BAO_Set::buildPriceSet($this); // get only price set form elements. if ($getOnlyPriceSetElements) { return; } } // use to build form during form rule. $this->assign('buildPriceSet', $buildPriceSet); $showAdditionalInfo = FALSE; $defaults = $this->_values; $additionalDetailFields = array('note', 'thankyou_date', 'invoice_id', 'non_deductible_amount', 'fee_amount', 'net_amount'); foreach ($additionalDetailFields as $key) { if (!empty($defaults[$key])) { $defaults['hidden_AdditionalDetail'] = 1; break; } } $honorFields = array('honor_type_id', 'honor_prefix_id', 'honor_first_name', 'honor_lastname', 'honor_email'); foreach ($honorFields as $key) { if (!empty($defaults[$key])) { $defaults['hidden_Honoree'] = 1; break; } } //check for honoree pane. if ($this->_ppID && CRM_Utils_Array::value('honor_contact_id', $this->_pledgeValues)) { $defaults['hidden_Honoree'] = 1; } if ($this->_productDAO) { if ($this->_productDAO->product_id) { $defaults['hidden_Premium'] = 1; } } if ($this->_noteID && isset($this->_values['note'])) { $defaults['hidden_AdditionalDetail'] = 1; } $paneNames = array(ts('Additional Details') => 'AdditionalDetail', ts('Honoree Information') => 'Honoree'); //Add Premium pane only if Premium is exists. $dao = new CRM_Contribute_DAO_Product(); $dao->is_active = 1; if ($dao->find(TRUE)) { $paneNames[ts('Premium Information')] = 'Premium'; } $ccPane = NULL; if ($this->_mode) { if (CRM_Utils_Array::value('payment_type', $this->_processors) & CRM_Core_Payment::PAYMENT_TYPE_DIRECT_DEBIT) { $ccPane = array(ts('Direct Debit Information') => 'DirectDebit'); } else { $ccPane = array(ts('Credit Card Information') => 'CreditCard'); } } if (is_array($ccPane)) { $paneNames = array_merge($ccPane, $paneNames); } $buildRecurBlock = FALSE; foreach ($paneNames as $name => $type) { $urlParams = "snippet=4&formType={$type}"; if ($this->_mode) { $urlParams .= "&mode={$this->_mode}"; } $open = 'false'; if ($type == 'CreditCard' || $type == 'DirectDebit') { $open = 'true'; } $allPanes[$name] = array('url' => CRM_Utils_System::url('civicrm/contact/view/contribution', $urlParams), 'open' => $open, 'id' => $type); // see if we need to include this paneName in the current form if ($this->_formType == $type || CRM_Utils_Array::value("hidden_{$type}", $_POST) || CRM_Utils_Array::value("hidden_{$type}", $defaults)) { $showAdditionalInfo = TRUE; $allPanes[$name]['open'] = 'true'; } if ($type == 'CreditCard') { $buildRecurBlock = TRUE; $this->add('hidden', 'hidden_CreditCard', 1); CRM_Core_Payment_Form::buildCreditCard($this, TRUE); } elseif ($type == 'DirectDebit') { $buildRecurBlock = TRUE; $this->add('hidden', 'hidden_DirectDebit', 1); CRM_Core_Payment_Form::buildDirectDebit($this, TRUE); } else { eval('CRM_Contribute_Form_AdditionalInfo::build' . $type . '( $this );'); } } if (empty($this->_recurPaymentProcessors)) { $buildRecurBlock = FALSE; } if ($buildRecurBlock) { CRM_Contribute_Form_Contribution_Main::buildRecur($this); $this->setDefaults(array('is_recur' => 0)); } $this->assign('buildRecurBlock', $buildRecurBlock); $qfKey = $this->controller->_key; $this->assign('qfKey', $qfKey); $this->assign('allPanes', $allPanes); $this->assign('showAdditionalInfo', $showAdditionalInfo); if ($this->_formType) { $this->assign('formType', $this->_formType); return; } $this->applyFilter('__ALL__', 'trim'); if ($this->_action & CRM_Core_Action::DELETE) { $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); return; } //need to assign custom data type and subtype to the template $this->assign('customDataType', 'Contribution'); $this->assign('customDataSubType', $this->_contributionType); $this->assign('entityID', $this->_id); if ($this->_context == 'standalone') { CRM_Contact_Form_NewContact::buildQuickForm($this); } $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution'); $element = $this->add('select', 'contribution_type_id', ts('Contribution Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType(), TRUE, array('onChange' => "buildCustomData( 'Contribution', this.value );")); if ($this->_online) { $element->freeze(); } if (!$this->_mode) { $element = $this->add('select', 'payment_instrument_id', ts('Paid By'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), FALSE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);")); if ($this->_online) { $element->freeze(); } } $element = $this->add('text', 'trxn_id', ts('Transaction ID'), $attributes['trxn_id']); if ($this->_online) { $element->freeze(); } else { $this->addRule('trxn_id', ts('This Transaction ID already exists in the database. Include the account number for checks.'), 'objectExists', array('CRM_Contribute_DAO_Contribution', $this->_id, 'trxn_id')); } //add receipt for offline contribution $this->addElement('checkbox', 'is_email_receipt', ts('Send Receipt?')); $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails); $status = CRM_Contribute_PseudoConstant::contributionStatus(); // supressing contribution statuses that are NOT relevant to pledges (CRM-5169) if ($this->_ppID) { $statusName = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); foreach (array('Cancelled', 'Failed', 'In Progress') as $supress) { unset($status[CRM_Utils_Array::key($supress, $statusName)]); } } $this->add('select', 'contribution_status_id', ts('Contribution Status'), $status, FALSE, array('onClick' => "if (this.value != 3) { status();} else return false", 'onChange' => "return showHideByValue('contribution_status_id','3','cancelInfo','table-row','select',false);")); // add various dates $this->addDateTime('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDateTime')); if ($this->_online) { $this->assign('hideCalender', TRUE); } $element = $this->add('text', 'check_number', ts('Check Number'), $attributes['check_number']); if ($this->_online) { $element->freeze(); } $this->addDateTime('receipt_date', ts('Receipt Date'), FALSE, array('formatType' => 'activityDateTime')); $this->addDateTime('cancel_date', ts('Cancelled Date'), FALSE, array('formatType' => 'activityDateTime')); $this->add('textarea', 'cancel_reason', ts('Cancellation Reason'), $attributes['cancel_reason']); $recurJs = NULL; if ($buildRecurBlock) { $recurJs = array('onChange' => "buildRecurBlock( this.value ); return false;"); } $element = $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, NULL, $recurJs); if ($this->_online) { $element->freeze(); } if (empty($this->_lineItems)) { $buildPriceSet = FALSE; $priceSets = CRM_Price_BAO_Set::getAssoc(FALSE, 'CiviContribute'); if (!empty($priceSets) && !$this->_ppID) { $buildPriceSet = TRUE; } // don't allow price set for contribution if it is related to participant, or if it is a pledge payment // and if we already have line items for that participant. CRM-5095 if ($buildPriceSet && $this->_id) { $componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id); $pledgePaymentId = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $this->_id, 'id', 'contribution_id'); if ($pledgePaymentId) { $buildPriceSet = FALSE; } if ($participantID = CRM_Utils_Array::value('participant', $componentDetails)) { $participantLI = CRM_Price_BAO_LineItem::getLineItems($participantID); if (!CRM_Utils_System::isNull($participantLI)) { $buildPriceSet = FALSE; } } } $hasPriceSets = FALSE; if ($buildPriceSet) { $hasPriceSets = TRUE; $element = $this->add('select', 'price_set_id', ts('Choose price set'), array('' => ts('Choose price set')) + $priceSets, NULL, array('onchange' => "buildAmount( this.value );")); if ($this->_online) { $element->freeze(); } } $this->assign('hasPriceSets', $hasPriceSets); $currencyFreeze = FALSE; if ($this->_online || $this->_ppID) { $attributes['total_amount'] = array_merge($attributes['total_amount'], array('READONLY' => TRUE, 'style' => "background-color:#EBECE4")); $optionTypes = array('1' => ts('Adjust Pledge Payment Schedule?'), '2' => ts('Adjust Total Pledge Amount?')); $element = $this->addRadio('option_type', NULL, $optionTypes, array(), '<br/>'); $currencyFreeze = TRUE; } $element = $this->addMoney('total_amount', ts('Total Amount'), $hasPriceSets ? FALSE : TRUE, $attributes['total_amount'], TRUE, 'currency', NULL, $currencyFreeze); } $element = $this->add('text', 'source', ts('Source'), CRM_Utils_Array::value('source', $attributes)); //CRM-7362 --add campaigns. CRM_Campaign_BAO_Campaign::addCampaign($this, CRM_Utils_Array::value('campaign_id', $this->_values)); // CRM-7368 allow user to set or edit PCP link for contributions $siteHasPCPs = CRM_Contribute_PseudoConstant::pcPage(); if (!CRM_Utils_Array::crmIsEmptyArray($siteHasPCPs)) { $this->assign('siteHasPCPs', 1); $pcpDataUrl = CRM_Utils_System::url('civicrm/ajax/rest', "className=CRM_Contact_Page_AJAX&fnName=getPCPList&json=1&context=contact&reset=1", FALSE, NULL, FALSE); $this->assign('pcpDataUrl', $pcpDataUrl); $this->addElement('text', 'pcp_made_through', ts('Credit to a Personal Campaign Page')); $this->addElement('hidden', 'pcp_made_through_id', '', array('id' => 'pcp_made_through_id')); $this->addElement('checkbox', 'pcp_display_in_roll', ts('Display in Honor Roll?'), NULL); $this->addElement('text', 'pcp_roll_nickname', ts('Name (for Honor Roll)')); $this->addElement('textarea', 'pcp_personal_note', ts('Personal Note (for Honor Roll)')); } $dataUrl = CRM_Utils_System::url('civicrm/ajax/rest', "className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=contact&reset=1&context=softcredit&id={$this->_id}", FALSE, NULL, FALSE); $this->assign('dataUrl', $dataUrl); $this->addElement('text', 'soft_credit_to', ts('Soft Credit To')); // Tell tpl to hide Soft Credit field if contribution is linked directly to a PCP Page if (CRM_Utils_Array::value('pcp_made_through_id', $this->_values)) { $this->assign('pcpLinked', 1); } $this->addElement('hidden', 'soft_contact_id', '', array('id' => 'soft_contact_id')); $js = NULL; if (!$this->_mode) { $js = array('onclick' => "return verify( );"); } $mailingInfo = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailing_backend'); $this->assign('outBound_option', $mailingInfo['outBound_option']); $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'js' => $js, 'isDefault' => TRUE), array('type' => 'upload', 'name' => ts('Save and New'), 'js' => $js, 'subName' => 'new'), array('type' => 'cancel', 'name' => ts('Cancel')))); $this->addFormRule(array('CRM_Contribute_Form_Contribution', 'formRule'), $this); if ($this->_action & CRM_Core_Action::VIEW) { $this->freeze(); } }
/** * Function to process the form * * @access public * @return None */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { $statusMsg = null; //block deleting activities which affects //case attributes.CRM-4543 $activityCondition = " AND v.name IN ('Open Case', 'Change Case Type', 'Change Case Status', 'Change Case Start Date')"; $caseAttributeActivities = CRM_Core_OptionGroup::values('activity_type', false, false, false, $activityCondition); if (!array_key_exists($this->_activityTypeId, $caseAttributeActivities)) { $params = array('id' => $this->_activityId); $activityDelete = CRM_Activity_BAO_Activity::deleteActivity($params, true); if ($activityDelete) { $statusMsg = ts('The selected activity has been moved to the Trash. You can view and / or restore deleted activities by checking "Deleted Activities" from the Case Activities search filter (under Manage Case).<br />'); } } else { $statusMsg = ts("Selected Activity cannot be deleted."); } require_once 'CRM/Core/BAO/EntityTag.php'; $tagParams = array('entity_table' => 'civicrm_activity', 'entity_id' => $this->_activityId); CRM_Core_BAO_EntityTag::del($tagParams); CRM_Core_Session::setStatus($statusMsg); return; } if ($this->_action & CRM_Core_Action::RENEW) { $statusMsg = null; $params = array('id' => $this->_activityId); $activityRestore = CRM_Activity_BAO_Activity::restoreActivity($params); if ($activityRestore) { $statusMsg = ts('The selected activity has been restored.<br />'); } CRM_Core_Session::setStatus($statusMsg); return; } // store the submitted values in an array $params = $this->controller->exportValues($this->_name); if ($params['source_contact_id']) { $params['source_contact_id'] = $params['source_contact_qid']; } //set parent id if its edit mode if ($parentId = CRM_Utils_Array::value('parent_id', $this->_defaults)) { $params['parent_id'] = $parentId; } // required for status msg $recordStatus = 'created'; // store the dates with proper format $params['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']); $params['activity_type_id'] = $this->_activityTypeId; require_once 'CRM/Case/XMLProcessor/Process.php'; $xmlProcessorProcess = new CRM_Case_XMLProcessor_Process(); $isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients(); $this->assign('multiClient', $isMultiClient); $targetContacts = array($this->_currentlyViewedContactId); if (CRM_Utils_Array::value('hidden_target_contact', $params) && CRM_Utils_Array::value('target_contact_id', $params)) { $targetContacts = array_unique(explode(',', $params['target_contact_id'])); } $params['target_contact_id'] = $targetContacts; // format activity custom data if (CRM_Utils_Array::value('hidden_custom', $params)) { if ($this->_activityId) { // unset custom fields-id from params since we want custom // fields to be saved for new activity. foreach ($params as $key => $value) { $match = array(); if (preg_match('/^(custom_\\d+_)(\\d+)$/', $key, $match)) { $params[$match[1] . '-1'] = $params[$key]; // for autocomplete transfer hidden value instead of label if ($params[$key] && isset($params[$key . '_id'])) { $params[$match[1] . '-1_id'] = $params[$key . '_id']; unset($params[$key . '_id']); } unset($params[$key]); } } } // build custom data getFields array $customFields = CRM_Core_BAO_CustomField::getFields('Activity', false, false, $this->_activityTypeId); $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Activity', false, false, null, null, true)); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_activityId, 'Activity'); } if (CRM_Utils_Array::value('assignee_contact_id', $params)) { $assineeContacts = explode(',', $params['assignee_contact_id']); $assineeContacts = array_unique($assineeContacts); unset($params['assignee_contact_id']); } else { $params['assignee_contact_id'] = $assineeContacts = array(); } if (isset($this->_activityId)) { // activity which hasn't been modified by a user yet if ($this->_defaults['is_auto'] == 1) { $params['is_auto'] = 0; } // always create a revision of an case activity. CRM-4533 $newActParams = $params; // add target contact values in update mode if (empty($params['target_contact_id']) && !empty($this->_defaults['target_contact'])) { $newActParams['target_contact_id'] = $this->_defaults['target_contact']; } // record status for status msg $recordStatus = 'updated'; } if (!isset($newActParams)) { // add more attachments if needed for old activity CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_activity'); // call begin post process, before the activity is created/updated. $this->beginPostProcess($params); $params['case_id'] = $this->_caseId; // activity create/update $activity = CRM_Activity_BAO_Activity::create($params); // call end post process, after the activity has been created/updated. $this->endPostProcess($params, $activity); } else { // since the params we need to set are very few, and we don't want rest of the // work done by bao create method , lets use dao object to make the changes $params = array('id' => $this->_activityId); $params['is_current_revision'] = 0; $activity = new CRM_Activity_DAO_Activity(); $activity->copyValues($params); $activity->save(); } // create a new version of activity if activity was found to // have been modified/created by user if (isset($newActParams)) { // set proper original_id if (CRM_Utils_Array::value('original_id', $this->_defaults)) { $newActParams['original_id'] = $this->_defaults['original_id']; } else { $newActParams['original_id'] = $activity->id; } //is_current_revision will be set to 1 by default. // add attachments if any CRM_Core_BAO_File::formatAttachment($newActParams, $newActParams, 'civicrm_activity'); // call begin post process, before the activity is created/updated. $this->beginPostProcess($newActParams); $newActParams['case_id'] = $this->_caseId; $activity = CRM_Activity_BAO_Activity::create($newActParams); // call end post process, after the activity has been created/updated. $this->endPostProcess($newActParams, $activity); // copy files attached to old activity if any, to new one, // as long as users have not selected the 'delete attachment' option. if (!CRM_Utils_Array::value('is_delete_attachment', $newActParams)) { CRM_Core_BAO_File::copyEntityFile('civicrm_activity', $this->_activityId, 'civicrm_activity', $activity->id); } // copy back params to original var $params = $newActParams; } if ($activity->id) { // add tags if exists $tagParams = array(); if (!empty($params['tag'])) { foreach ($params['tag'] as $tag) { $tagParams[$tag] = 1; } } //save static tags require_once 'CRM/Core/BAO/EntityTag.php'; CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_activity', $activity->id); //save free tags if (isset($params['taglist']) && !empty($params['taglist'])) { require_once 'CRM/Core/Form/Tag.php'; CRM_Core_Form_Tag::postProcess($params['taglist'], $activity->id, 'civicrm_activity', $this); } } $params['assignee_contact_id'] = $assineeContacts; // update existing case record if needed $caseParams = $params; $caseParams['id'] = $this->_caseId; if (CRM_Utils_Array::value('case_type_id', $caseParams)) { $caseParams['case_type_id'] = CRM_Case_BAO_Case::VALUE_SEPERATOR . $caseParams['case_type_id'] . CRM_Case_BAO_Case::VALUE_SEPERATOR; } if (CRM_Utils_Array::value('case_status_id', $caseParams)) { $caseParams['status_id'] = $caseParams['case_status_id']; } // unset params intended for activities only unset($caseParams['subject'], $caseParams['details'], $caseParams['status_id'], $caseParams['custom']); $case = CRM_Case_BAO_Case::create($caseParams); // create case activity record $caseParams = array('activity_id' => $activity->id, 'case_id' => $this->_caseId); CRM_Case_BAO_Case::processCaseActivity($caseParams); // create activity assignee records $assigneeParams = array('activity_id' => $activity->id); if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) { //skip those assignee contacts which are already assigned //while sending a copy.CRM-4509. $activityAssigned = array_flip($params['assignee_contact_id']); $activityId = isset($this->_activityId) ? $this->_activityId : $activity->id; $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activityId); $activityAssigned = array_diff_key($activityAssigned, $assigneeContacts); foreach ($params['assignee_contact_id'] as $key => $id) { $assigneeParams['assignee_contact_id'] = $id; CRM_Activity_BAO_Activity::createActivityAssignment($assigneeParams); } //modify assigne_contact as per newly assigned contact before sending copy. CRM-4509. $params['assignee_contact_id'] = $activityAssigned; } // Insert civicrm_log record for the activity (e.g. store the // created / edited by contact id and date for the activity) // Note - civicrm_log is already created by CRM_Activity_BAO_Activity::create() // send copy to selected contacts. $mailStatus = ''; $mailToContacts = array(); //CRM-5695 //check for notification settings for assignee contacts $selectedContacts = array('contact_check'); $config =& CRM_Core_Config::singleton(); if ($config->activityAssigneeNotification) { $selectedContacts[] = 'assignee_contact_id'; } foreach ($selectedContacts as $dnt => $val) { if (array_key_exists($val, $params) && !CRM_Utils_array::crmIsEmptyArray($params[$val])) { if ($val == 'contact_check') { $mailStatus = ts("A copy of the activity has also been sent to selected contacts(s)."); } else { $this->_relatedContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id, true, false); $mailStatus .= ' ' . ts("A copy of the activity has also been sent to assignee contacts(s)."); } //build an associative array with unique email addresses. foreach ($params[$val] as $id => $dnc) { if (isset($id) && array_key_exists($id, $this->_relatedContacts)) { //if email already exists in array then append with ', ' another role only otherwise add it to array. if ($contactDetails = CRM_Utils_Array::value($this->_relatedContacts[$id]['email'], $mailToContacts)) { $caseRole = CRM_Utils_Array::value('role', $this->_relatedContacts[$id]); $mailToContacts[$this->_relatedContacts[$id]['email']]['role'] = $contactDetails['role'] . ', ' . $caseRole; } else { $mailToContacts[$this->_relatedContacts[$id]['email']] = $this->_relatedContacts[$id]; } } } } } if (!CRM_Utils_array::crmIsEmptyArray($mailToContacts)) { //include attachments while sendig a copy of activity. $attachments =& CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id); $result = CRM_Case_BAO_Case::sendActivityCopy($this->_currentlyViewedContactId, $activity->id, $mailToContacts, $attachments, $this->_caseId); if (empty($result)) { $mailStatus = ''; } } else { $mailStatus = ''; } // create follow up activity if needed $followupStatus = ''; if (CRM_Utils_Array::value('followup_activity_type_id', $params)) { $followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($activity->id, $params); if ($followupActivity) { $caseParams = array('activity_id' => $followupActivity->id, 'case_id' => $this->_caseId); CRM_Case_BAO_Case::processCaseActivity($caseParams); $followupStatus = ts("A followup activity has been scheduled."); } } CRM_Core_Session::setStatus(ts("'%1' activity has been %2. %3 %4", array(1 => $this->_activityTypeName, 2 => $recordStatus, 3 => $followupStatus, 4 => $mailStatus))); }
/** * Process the form submission. * * @param array $params */ public function postProcess($params = NULL) { $transaction = new CRM_Core_Transaction(); if ($this->_action & CRM_Core_Action::DELETE) { $statusMsg = NULL; //block deleting activities which affects //case attributes.CRM-4543 $activityCondition = " AND v.name IN ('Open Case', 'Change Case Type', 'Change Case Status', 'Change Case Start Date')"; $caseAttributeActivities = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, $activityCondition); if (!array_key_exists($this->_activityTypeId, $caseAttributeActivities)) { $params = array('id' => $this->_activityId); $activityDelete = CRM_Activity_BAO_Activity::deleteActivity($params, TRUE); if ($activityDelete) { $statusMsg = ts('The selected activity has been moved to the Trash. You can view and / or restore deleted activities by checking "Deleted Activities" from the Case Activities search filter (under Manage Case).<br />'); } } else { $statusMsg = ts("Selected Activity cannot be deleted."); } $tagParams = array('entity_table' => 'civicrm_activity', 'entity_id' => $this->_activityId); CRM_Core_BAO_EntityTag::del($tagParams); CRM_Core_Session::setStatus('', $statusMsg, 'info'); return; } if ($this->_action & CRM_Core_Action::RENEW) { $statusMsg = NULL; $params = array('id' => $this->_activityId); $activityRestore = CRM_Activity_BAO_Activity::restoreActivity($params); if ($activityRestore) { $statusMsg = ts('The selected activity has been restored.<br />'); } CRM_Core_Session::setStatus('', $statusMsg, 'info'); return; } // store the submitted values in an array $params = $this->controller->exportValues($this->_name); //set parent id if its edit mode if ($parentId = CRM_Utils_Array::value('parent_id', $this->_defaults)) { $params['parent_id'] = $parentId; } // store the dates with proper format $params['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']); $params['activity_type_id'] = $this->_activityTypeId; // format with contact (target contact) values if (isset($params['target_contact_id'])) { $params['target_contact_id'] = explode(',', $params['target_contact_id']); } else { $params['target_contact_id'] = array(); } // format activity custom data if (!empty($params['hidden_custom'])) { if ($this->_activityId) { // retrieve and include the custom data of old Activity $oldActivity = civicrm_api3('Activity', 'getsingle', array('id' => $this->_activityId)); $params = array_merge($oldActivity, $params); // unset custom fields-id from params since we want custom // fields to be saved for new activity. foreach ($params as $key => $value) { $match = array(); if (preg_match('/^(custom_\\d+_)(\\d+)$/', $key, $match)) { $params[$match[1] . '-1'] = $params[$key]; // for autocomplete transfer hidden value instead of label if ($params[$key] && isset($params[$key . '_id'])) { $params[$match[1] . '-1_id'] = $params[$key . '_id']; unset($params[$key . '_id']); } unset($params[$key]); } } } // build custom data getFields array $customFields = CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, $this->_activityTypeId); $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, NULL, NULL, TRUE)); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $this->_activityId, 'Activity'); } // assigning formatted value if (!empty($params['assignee_contact_id'])) { $params['assignee_contact_id'] = explode(',', $params['assignee_contact_id']); } else { $params['assignee_contact_id'] = array(); } if (isset($this->_activityId)) { // activity which hasn't been modified by a user yet if ($this->_defaults['is_auto'] == 1) { $params['is_auto'] = 0; } // always create a revision of an case activity. CRM-4533 $newActParams = $params; // add target contact values in update mode if (empty($params['target_contact_id']) && !empty($this->_defaults['target_contact'])) { $newActParams['target_contact_id'] = $this->_defaults['target_contact']; } } if (!isset($newActParams)) { // add more attachments if needed for old activity CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_activity'); // call begin post process, before the activity is created/updated. $this->beginPostProcess($params); foreach ($this->_caseId as $key => $val) { $params['case_id'] = $val; // activity create/update $activity = CRM_Activity_BAO_Activity::create($params); $vvalue[] = array('case_id' => $val, 'actId' => $activity->id); // call end post process, after the activity has been created/updated. $this->endPostProcess($params, $activity); } } else { // since the params we need to set are very few, and we don't want rest of the // work done by bao create method , lets use dao object to make the changes $params = array('id' => $this->_activityId); $params['is_current_revision'] = 0; $activity = new CRM_Activity_DAO_Activity(); $activity->copyValues($params); $activity->save(); } // create a new version of activity if activity was found to // have been modified/created by user if (isset($newActParams)) { // set proper original_id if (!empty($this->_defaults['original_id'])) { $newActParams['original_id'] = $this->_defaults['original_id']; } else { $newActParams['original_id'] = $activity->id; } //is_current_revision will be set to 1 by default. // add attachments if any CRM_Core_BAO_File::formatAttachment($newActParams, $newActParams, 'civicrm_activity'); // call begin post process, before the activity is created/updated. $this->beginPostProcess($newActParams); foreach ($this->_caseId as $key => $val) { $newActParams['case_id'] = $val; $activity = CRM_Activity_BAO_Activity::create($newActParams); $vvalue[] = array('case_id' => $val, 'actId' => $activity->id); // call end post process, after the activity has been created/updated. $this->endPostProcess($newActParams, $activity); } // copy files attached to old activity if any, to new one, // as long as users have not selected the 'delete attachment' option. if (empty($newActParams['is_delete_attachment'])) { CRM_Core_BAO_File::copyEntityFile('civicrm_activity', $this->_activityId, 'civicrm_activity', $activity->id); } // copy back params to original var $params = $newActParams; } foreach ($vvalue as $vkey => $vval) { if ($vval['actId']) { // add tags if exists $tagParams = array(); if (!empty($params['tag'])) { foreach ($params['tag'] as $tag) { $tagParams[$tag] = 1; } } //save static tags CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_activity', $vval['actId']); //save free tags if (isset($params['taglist']) && !empty($params['taglist'])) { CRM_Core_Form_Tag::postProcess($params['taglist'], $vval['actId'], 'civicrm_activity', $this); } } // update existing case record if needed $caseParams = $params; $caseParams['id'] = $vval['case_id']; if (!empty($caseParams['case_status_id'])) { $caseParams['status_id'] = $caseParams['case_status_id']; } // unset params intended for activities only unset($caseParams['subject'], $caseParams['details'], $caseParams['status_id'], $caseParams['custom']); $case = CRM_Case_BAO_Case::create($caseParams); // create case activity record $caseParams = array('activity_id' => $vval['actId'], 'case_id' => $vval['case_id']); CRM_Case_BAO_Case::processCaseActivity($caseParams); } // Insert civicrm_log record for the activity (e.g. store the // created / edited by contact id and date for the activity) // Note - civicrm_log is already created by CRM_Activity_BAO_Activity::create() // send copy to selected contacts. $mailStatus = ''; $mailToContacts = array(); //CRM-5695 //check for notification settings for assignee contacts $selectedContacts = array('contact_check'); $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); if (Civi::settings()->get('activity_assignee_notification')) { $selectedContacts[] = 'assignee_contact_id'; } foreach ($vvalue as $vkey => $vval) { foreach ($selectedContacts as $dnt => $val) { if (array_key_exists($val, $params) && !CRM_Utils_Array::crmIsEmptyArray($params[$val])) { if ($val == 'contact_check') { $mailStatus = ts("A copy of the activity has also been sent to selected contacts(s)."); } else { $this->_relatedContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames(array($vval['actId']), TRUE, FALSE); $mailStatus .= ' ' . ts("A copy of the activity has also been sent to assignee contacts(s)."); } //build an associative array with unique email addresses. foreach ($params[$val] as $key => $value) { if ($val == 'contact_check') { $id = $key; } else { $id = $value; } if (isset($id) && array_key_exists($id, $this->_relatedContacts) && isset($this->_relatedContacts[$id]['email'])) { //if email already exists in array then append with ', ' another role only otherwise add it to array. if ($contactDetails = CRM_Utils_Array::value($this->_relatedContacts[$id]['email'], $mailToContacts)) { $caseRole = CRM_Utils_Array::value('role', $this->_relatedContacts[$id]); $mailToContacts[$this->_relatedContacts[$id]['email']]['role'] = $contactDetails['role'] . ', ' . $caseRole; } else { $mailToContacts[$this->_relatedContacts[$id]['email']] = $this->_relatedContacts[$id]; } } } } } $extraParams = array('case_id' => $vval['case_id'], 'client_id' => $this->_currentlyViewedContactId); $result = CRM_Activity_BAO_Activity::sendToAssignee($activity, $mailToContacts, $extraParams); if (empty($result)) { $mailStatus = ''; } // create follow up activity if needed $followupStatus = ''; if (!empty($params['followup_activity_type_id'])) { $followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($vval['actId'], $params); if ($followupActivity) { $caseParams = array('activity_id' => $followupActivity->id, 'case_id' => $vval['case_id']); CRM_Case_BAO_Case::processCaseActivity($caseParams); $followupStatus = ts("A followup activity has been scheduled.") . '<br /><br />'; } } $title = ts("%1 Saved", array(1 => $this->_activityTypeName)); CRM_Core_Session::setStatus($followupStatus . $mailStatus, $title, 'success'); } }
/** * takes an associative array and creates a custom group object * * This function is invoked from within the web form layer and also from the api layer * * @param array $params (reference) an assoc array of name/value pairs * * @return object CRM_Core_DAO_CustomGroup object * @access public * @static */ static function create(&$params) { $fieldLength = CRM_Core_DAO::getAttribute('CRM_Core_DAO_CustomGroup', 'name'); // create custom group dao, populate fields and then save. $group =& new CRM_Core_DAO_CustomGroup(); $group->title = $params['title']; $group->name = CRM_Utils_String::titleToVar($params['title'], $fieldLength['maxlength']); if (in_array($params['extends'][0], array('ParticipantRole', 'ParticipantEventName', 'ParticipantEventType'))) { $group->extends = 'Participant'; } else { $group->extends = $params['extends'][0]; } $group->extends_entity_column_id = null; if ($params['extends'][0] == 'ParticipantRole' || $params['extends'][0] == 'ParticipantEventName' || $params['extends'][0] == 'ParticipantEventType') { $group->extends_entity_column_id = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $params['extends'][0], 'value', 'name'); } if (is_array($params['extends'][1]) && !CRM_Utils_Array::crmIsEmptyArray($params['extends'][1])) { $params['extends'][1] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $params['extends'][1]); if ($params['extends'][0] == 'Relationship') { $group->extends_entity_column_value = str_replace(array('_a_b', '_b_a'), array('', ''), $params['extends'][1]); } else { $group->extends_entity_column_value = $params['extends'][1]; } } if (!empty($group->extends_entity_column_value)) { $group->extends_entity_column_value = CRM_Core_DAO::VALUE_SEPARATOR . $group->extends_entity_column_value . CRM_Core_DAO::VALUE_SEPARATOR; } else { $group->extends_entity_column_value = "null"; } if (isset($params['id'])) { $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['id'], 'weight', 'id'); } else { $oldWeight = 0; } require_once 'CRM/Utils/Weight.php'; $group->weight = CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_CustomGroup', $oldWeight, CRM_Utils_Array::value('weight', $params, false)); $fields = array('style', 'collapse_display', 'collapse_adv_display', 'help_pre', 'help_post', 'is_active', 'is_multiple'); foreach ($fields as $field) { $group->{$field} = CRM_Utils_Array::value($field, $params, false); } $group->max_multiple = isset($params['is_multiple']) ? isset($params['max_multiple']) && $params['max_multiple'] >= '0' ? $params['max_multiple'] : 'null' : 'null'; $tableName = null; if (isset($params['id'])) { $group->id = $params['id']; //check whether custom group was changed from single-valued to multiple-valued $isMultiple = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['id'], 'is_multiple'); if ($params['is_multiple'] != $isMultiple && (CRM_Utils_Array::value('is_multiple', $params) || $isMultiple)) { $oldTableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['id'], 'table_name'); } } else { $group->created_id = CRM_Utils_Array::value('created_id', $params); $group->created_date = CRM_Utils_Array::value('created_date', $params); // lets create the table associated with the group and save it $tableName = $group->table_name = "civicrm_value_" . strtolower(CRM_Utils_String::munge($group->title, '_', 32)); } // enclose the below in a transaction require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); $group->save(); if ($tableName) { // now append group id to table name, this prevent any name conflicts // like CRM-2742 $tableName .= "_{$group->id}"; $group->table_name = $tableName; CRM_Core_DAO::setFieldValue('CRM_Core_DAO_CustomGroup', $group->id, 'table_name', $tableName); // now create the table associated with this group self::createTable($group); } elseif ($oldTableName) { require_once 'CRM/Core/BAO/SchemaHandler.php'; CRM_Core_BAO_SchemaHandler::changeUniqueToIndex($oldTableName, CRM_Utils_Array::value('is_multiple', $params)); } if ($params['overrideFKConstraint'] == 1) { $table = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['id'], 'table_name'); require_once 'CRM/Core/BAO/SchemaHandler.php'; CRM_Core_BAO_SchemaHandler::changeFKConstraint($table, self::mapTableName($params['extends'][0])); } $transaction->commit(); // reset the cache require_once 'CRM/Core/BAO/Cache.php'; CRM_Core_BAO_Cache::deleteGroup('contact fields'); require_once 'CRM/Utils/Hook.php'; if ($tableName) { CRM_Utils_Hook::post('create', 'CustomGroup', $group->id, $group); } else { CRM_Utils_Hook::post('edit', 'CustomGroup', $group->id, $group); } return $group; }
/** * Global validation rules for the form. * * @param array $values * @param $files * @param $self * * @return array * list of errors to be posted back to the form */ public static function formRule($values, $files, $self) { $errors = array(); if (!empty($values['contact_name']) && !is_numeric($values['created_id'])) { $errors['contact_name'] = ts('Please select a valid contact.'); } if ($values['item_count'] && (!is_numeric($values['item_count']) || $values['item_count'] < 1)) { $errors['item_count'] = ts('Number of Transactions should a positive number'); } if ($values['total'] && (!is_numeric($values['total']) || $values['total'] <= 0)) { $errors['total'] = ts('Total Amount should be a positive number'); } if (!empty($values['created_date']) && date('Y-m-d') < date('Y-m-d', strtotime($values['created_date']))) { $errors['created_date'] = ts('Created date cannot be greater than current date'); } $batchName = $values['title']; if (!CRM_Core_DAO::objectExists($batchName, 'CRM_Batch_DAO_Batch', $self->_id)) { $errors['title'] = ts('This name already exists in database. Batch names must be unique.'); } return CRM_Utils_Array::crmIsEmptyArray($errors) ? TRUE : $errors; }
/** * Function used to build form element for soft credit block * * @param object $form form object * @access public * * @return void */ static function buildQuickForm(&$form) { if ($form->_mode == 'live' && !empty($form->_values['honor_block_is_active'])) { $ufJoinDAO = new CRM_Core_DAO_UFJoin(); $ufJoinDAO->module = 'soft_credit'; $ufJoinDAO->entity_id = $form->_id; if ($ufJoinDAO->find(TRUE)) { $jsonData = json_decode($ufJoinDAO->module_data); if ($jsonData) { $form->assign('honor_block_title', $jsonData->soft_credit->honor_block_title); $form->assign('honor_block_text', $jsonData->soft_credit->honor_block_text); $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE); $extraOption = array('onclick' => "enableHonorType();"); // radio button for Honor Type foreach ($jsonData->soft_credit->soft_credit_types as $value) { $honorTypes[$value] = $form->createElement('radio', NULL, NULL, $softCreditTypes[$value], $value, $extraOption); } $form->addGroup($honorTypes, 'soft_credit_type_id', NULL); } } return $form; } $prefix = 'soft_credit_'; // by default generate 5 blocks $item_count = 6; $showSoftCreditRow = 2; $showCreateNew = TRUE; if ($form->_action & CRM_Core_Action::UPDATE) { $form->_softCreditInfo = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($form->_id, TRUE); } elseif ($form->_pledgeID) { //Check and select most recent completed contrubtion and use it to retrieve //soft-credit information to use as default for current pledge payment, CRM-13981 $pledgePayments = CRM_Pledge_BAO_PledgePayment::getPledgePayments($form->_pledgeID); foreach ($pledgePayments as $id => $record) { if ($record['contribution_id']) { $softCredits = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($record['contribution_id'], TRUE); if ($record['status'] == 'Completed' && count($softCredits) > 0) { $form->_softCreditInfo = $softCredits; } } } } if (property_exists($form, "_softCreditInfo")) { if (!empty($form->_softCreditInfo['soft_credit'])) { $showSoftCreditRow = count($form->_softCreditInfo['soft_credit']); $showSoftCreditRow++; $showCreateNew = FALSE; } } for ($rowNumber = 1; $rowNumber <= $item_count; $rowNumber++) { CRM_Contact_Form_NewContact::buildQuickForm($form, $rowNumber, NULL, FALSE, $prefix); $form->addMoney("{$prefix}amount[{$rowNumber}]", ts('Amount'), FALSE, NULL, FALSE); $form->add('select', "{$prefix}type[{$rowNumber}]", ts('Soft Credit Type'), array('' => ts('- select -')) + CRM_Core_OptionGroup::values("{$prefix}type", FALSE)); if (!empty($form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id'])) { $form->add('hidden', "{$prefix}id[{$rowNumber}]", $form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id']); } } // CRM-7368 allow user to set or edit PCP link for contributions $siteHasPCPs = CRM_Contribute_PseudoConstant::pcPage(); if (!CRM_Utils_Array::crmIsEmptyArray($siteHasPCPs)) { $form->assign('siteHasPCPs', 1); $pcpDataUrl = CRM_Utils_System::url('civicrm/ajax/rest', 'className=CRM_Contact_Page_AJAX&fnName=getPCPList&json=1&context=contact&reset=1', FALSE, NULL, FALSE); $form->assign('pcpDataUrl', $pcpDataUrl); $form->addElement('text', 'pcp_made_through', ts('Credit to a Personal Campaign Page')); $form->addElement('hidden', 'pcp_made_through_id', '', array('id' => 'pcp_made_through_id')); $form->addElement('checkbox', 'pcp_display_in_roll', ts('Display in Honor Roll?'), NULL); $form->addElement('text', 'pcp_roll_nickname', ts('Name (for Honor Roll)')); $form->addElement('textarea', 'pcp_personal_note', ts('Personal Note (for Honor Roll)')); } $form->assign('showSoftCreditRow', $showSoftCreditRow); $form->assign('rowCount', $item_count); $form->assign('showCreateNew', $showCreateNew); $form->addElement('hidden', 'sct_default_id', CRM_Core_OptionGroup::getDefaultValue("{$prefix}type"), array('id' => 'sct_default_id')); // Tell tpl to hide soft credit field if contribution is linked directly to a PCP Page if (!empty($form->_values['pcp_made_through_id'])) { $form->assign('pcpLinked', 1); } }
/** * global validation rules for the form * * @param array $fields posted values of the form * * @return array list of errors to be posted back to the form * @static * @access public */ static function formRule($values, $files, $self) { $errorMsg = array(); $errorFlag = FALSE; if ($self->_action == CRM_Core_Action::DELETE) { $relationValues = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship'); if (CRM_Utils_Array::value('financial_account_id', $values) != 'select') { if ($relationValues[$values['account_relationship']] == 'Premiums Inventory Account is' || $relationValues[$values['account_relationship']] == 'Cost of Sales Account is') { $premiumsProduct = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_PremiumsProduct', $values['financial_type_id'], 'product_id', 'financial_type_id'); $product = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Product', $values['financial_type_id'], 'name', 'financial_type_id'); if (!empty($premiumsProduct) || !empty($product)) { $errorMsg['account_relationship'] = 'You cannot remove ' . $relationValues[$values['account_relationship']] . ' relationship while the Financial Type is used for a Premium.'; } } } } if (CRM_Utils_Array::value('account_relationship', $values) == 'select') { $errorMsg['account_relationship'] = 'Financial Account relationship is a required field.'; } if (CRM_Utils_Array::value('financial_account_id', $values) == 'select') { $errorMsg['financial_account_id'] = 'Financial Account is a required field.'; } if (!empty($values['account_relationship']) && !empty($values['financial_account_id'])) { $params = array('account_relationship' => $values['account_relationship'], 'entity_id' => $self->_aid); $defaults = array(); if ($self->_action == CRM_Core_Action::ADD) { $result = CRM_Financial_BAO_FinancialTypeAccount::retrieve($params, $defaults); if ($result) { $errorFlag = TRUE; } } if ($self->_action == CRM_Core_Action::UPDATE) { if ($values['account_relationship'] == $self->_defaultValues['account_relationship'] && $values['financial_account_id'] == $self->_defaultValues['financial_account_id']) { $errorFlag = FALSE; } else { $params['financial_account_id'] = $values['financial_account_id']; $result = CRM_Financial_BAO_FinancialTypeAccount::retrieve($params, $defaults); if ($result) { $errorFlag = TRUE; } } } if ($errorFlag) { $errorMsg['account_relationship'] = ts('This account relationship already exits'); } } return CRM_Utils_Array::crmIsEmptyArray($errorMsg) ? TRUE : $errorMsg; }
/** * Creates or updates an Activity. See the example for usage * * @param array $params Associative array of property name/value * pairs for the activity. * {@getfields activity_create} * * @return array Array containing 'is_error' to denote success or failure and details of the created activity * * @example ActivityCreate.php Standard create example * @example Activity/ContactRefCustomField.php Create example including setting a contact reference custom field * {@example ActivityCreate.php 0} * */ function civicrm_api3_activity_create($params) { if (!CRM_Utils_Array::value('id', $params)) { // an update does not require any mandatory parameters civicrm_api3_verify_one_mandatory($params, NULL, array('activity_name', 'activity_type_id', 'activity_label')); } $errors = array(); // check for various error and required conditions $errors = _civicrm_api3_activity_check_params($params); if (!empty($errors)) { return $errors; } // processing for custom data $values = array(); _civicrm_api3_custom_format_params($params, $values, 'Activity'); if (!empty($values['custom'])) { $params['custom'] = $values['custom']; } $params['skipRecentView'] = TRUE; // If this is a case activity, see if there is an existing activity // and set it as an old revision. Also retrieve details we'll need. $case_id = ''; $createRevision = FALSE; $oldActivityValues = array(); if (CRM_Utils_Array::value('case_id', $params)) { $case_id = $params['case_id']; if (CRM_Utils_Array::value('id', $params)) { $oldActivityParams = array('id' => $params['id']); if (!$oldActivityValues) { CRM_Activity_BAO_Activity::retrieve($oldActivityParams, $oldActivityValues); } if (empty($oldActivityValues)) { return civicrm_api3_create_error(ts("Unable to locate existing activity."), NULL, CRM_Core_DAO::$_nullObject); } else { require_once 'CRM/Activity/DAO/Activity.php'; $activityDAO = new CRM_Activity_DAO_Activity(); $activityDAO->id = $params['id']; $activityDAO->is_current_revision = 0; if (!$activityDAO->save()) { return civicrm_api3_create_error(ts("Unable to revision existing case activity."), NULL, $activityDAO); } $createRevision = TRUE; } } } $deleteActivityAssignment = FALSE; if (isset($params['assignee_contact_id'])) { $deleteActivityAssignment = TRUE; } $deleteActivityTarget = FALSE; if (isset($params['target_contact_id'])) { $deleteActivityTarget = TRUE; } $params['deleteActivityAssignment'] = CRM_Utils_Array::value('deleteActivityAssignment', $params, $deleteActivityAssignment); $params['deleteActivityTarget'] = CRM_Utils_Array::value('deleteActivityTarget', $params, $deleteActivityTarget); if ($case_id && $createRevision) { // This is very similar to the copy-to-case action. if (!CRM_Utils_Array::crmIsEmptyArray($oldActivityValues['target_contact'])) { $oldActivityValues['targetContactIds'] = implode(',', array_unique($oldActivityValues['target_contact'])); } if (!CRM_Utils_Array::crmIsEmptyArray($oldActivityValues['assignee_contact'])) { $oldActivityValues['assigneeContactIds'] = implode(',', array_unique($oldActivityValues['assignee_contact'])); } $oldActivityValues['mode'] = 'copy'; $oldActivityValues['caseID'] = $case_id; $oldActivityValues['activityID'] = $oldActivityValues['id']; $oldActivityValues['contactID'] = $oldActivityValues['source_contact_id']; require_once 'CRM/Activity/Page/AJAX.php'; $copyToCase = CRM_Activity_Page_AJAX::_convertToCaseActivity($oldActivityValues); if (empty($copyToCase['error_msg'])) { // now fix some things that are different from copy-to-case // then fall through to the create below to update with the passed in params $params['id'] = $copyToCase['newId']; $params['is_auto'] = 0; $params['original_id'] = empty($oldActivityValues['original_id']) ? $oldActivityValues['id'] : $oldActivityValues['original_id']; } else { return civicrm_api3_create_error(ts("Unable to create new revision of case activity."), NULL, CRM_Core_DAO::$_nullObject); } } // create activity $activityBAO = CRM_Activity_BAO_Activity::create($params); if (isset($activityBAO->id)) { if ($case_id && !$createRevision) { // If this is a brand new case activity we need to add this $caseActivityParams = array('activity_id' => $activityBAO->id, 'case_id' => $case_id); require_once 'CRM/Case/BAO/Case.php'; CRM_Case_BAO_Case::processCaseActivity($caseActivityParams); } _civicrm_api3_object_to_array($activityBAO, $activityArray[$activityBAO->id]); return civicrm_api3_create_success($activityArray, $params, 'activity', 'get', $activityBAO); } }
/** * Given an id creates a subject/content array * * @param int $id * Id of the block. * * @return array */ public static function getContent($id) { // return if upgrade mode $config = CRM_Core_Config::singleton(); if ($config->isUpgradeMode()) { return NULL; } if (!self::getProperty($id, 'active')) { return NULL; } if ($id == self::EVENT && CRM_Core_Permission::check('view event info')) { // is CiviEvent enabled? if (!CRM_Core_Permission::access('CiviEvent', FALSE)) { return NULL; } // do nothing } elseif (!CRM_Core_Permission::check('access CiviCRM') && $id != self::LANGSWITCH) { return NULL; } elseif ($id == self::ADD) { $hasAccess = TRUE; if (!CRM_Core_Permission::check('add contacts') && !CRM_Core_Permission::check('edit groups')) { $hasAccess = FALSE; } //validate across edit/view - CRM-5666 if ($hasAccess) { $hasAccess = CRM_Core_Permission::giveMeAllACLs(); } if (!$hasAccess) { return NULL; } } self::setTemplateValues($id); // Suppress Recent Items block if it's empty - CRM-5188 if ($id == self::RECENTLY_VIEWED) { $recent = self::getProperty($id, 'templateValues'); if (CRM_Utils_Array::crmIsEmptyArray($recent)) { return NULL; } } // Suppress Language switcher if language is inherited from CMS - CRM-9971 $config = CRM_Core_Config::singleton(); if ($id == self::LANGSWITCH && property_exists($config, "inheritLocale") && $config->inheritLocale) { return NULL; } $block = array(); $block['name'] = 'block-civicrm'; $block['id'] = $block['name'] . '_' . $id; $block['subject'] = self::fetch($id, 'Subject.tpl', array('subject' => self::getProperty($id, 'subject'))); $block['content'] = self::fetch($id, self::getProperty($id, 'template'), self::getProperty($id, 'templateValues')); return $block; }
/** * Given an id creates a subject/content array * * @param int $id id of the block * * @return array * @access public */ static function getContent($id) { // return if upgrade mode $config =& CRM_Core_Config::singleton(); if (CRM_Utils_Array::value($config->userFrameworkURLVar, $_GET) == 'civicrm/upgrade') { return; } if (!self::getProperty($id, 'active')) { return null; } if ($id == self::CIVICRM_CONTENT) { $output = civicrm_invoke(); return $output; } require_once 'CRM/Core/Permission.php'; if ($id == self::EVENT && CRM_Core_Permission::check('view event info')) { // is CiviEvent enabled? if (!CRM_Core_Permission::access('CiviEvent', false)) { return null; } // do nothing } else { if (!CRM_Core_Permission::check('access CiviCRM')) { return null; } else { if ($id == self::ADD && !CRM_Core_Permission::check('add contacts') && !CRM_Core_Permission::check('edit groups')) { return null; } } } self::setTemplateValues($id); // Suppress Recent Items block if it's empty - CRM-5188 if ($id == self::RECENTLY_VIEWED) { $recent = self::getProperty($id, 'templateValues'); if (CRM_Utils_Array::crmIsEmptyArray($recent)) { return null; } } $block = array(); $block['name'] = 'block-civicrm'; $block['id'] = $block['name'] . '_' . $id; $block['subject'] = self::fetch($id, 'Subject.tpl', array('subject' => self::getProperty($id, 'subject'))); $block['content'] = self::fetch($id, self::getProperty($id, 'template'), self::getProperty($id, 'templateValues')); return $block; }
/** * Global validation rules for the form. * * @param array $values * posted values of the form * @param $files * @param $self * * @return array * list of errors to be posted back to the form */ public static function formRule($values, $files, $self) { $errorMsg = array(); $financialAccountTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name LIKE 'Liability' ")); if (isset($values['is_tax'])) { if ($values['financial_account_type_id'] != $financialAccountTypeId) { $errorMsg['financial_account_type_id'] = ts('Taxable accounts should have Financial Account Type set to Liability.'); } if (CRM_Utils_Array::value('tax_rate', $values) == NULL) { $errorMsg['tax_rate'] = ts('Please enter value for tax rate'); } } if (CRM_Utils_Array::value('tax_rate', $values) != NULL) { if ($values['tax_rate'] < 0 || $values['tax_rate'] >= 100) { $errorMsg['tax_rate'] = ts('Tax Rate Should be between 0 - 100'); } } if ($self->_action & CRM_Core_Action::UPDATE) { if (!isset($values['is_tax'])) { $relationshipId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Sales Tax Account is' ")); $params = array('financial_account_id' => $self->_id, 'account_relationship' => $relationshipId); $result = CRM_Financial_BAO_FinancialTypeAccount::retrieve($params, $defaults); if ($result) { $errorMsg['is_tax'] = ts('Is Tax? must be set for this financial account'); } } } return CRM_Utils_Array::crmIsEmptyArray($errorMsg) ? TRUE : $errorMsg; }
/** * Function to process the form * * @access public * @return None */ public function postProcess($params = null) { if ($this->_action & CRM_Core_Action::DELETE) { $deleteParams = array('id' => $this->_activityId); CRM_Activity_BAO_Activity::deleteActivity($deleteParams); CRM_Core_Session::setStatus(ts("Selected Activity has been deleted sucessfully.")); return; } // store the submitted values in an array if (!$params) { $params = $this->controller->exportValues($this->_name); } //set activity type id if (!CRM_Utils_Array::value('activity_type_id', $params)) { $params['activity_type_id'] = $this->_activityTypeId; } if (CRM_Utils_Array::value('hidden_custom', $params) && !isset($params['custom'])) { $customFields = CRM_Core_BAO_CustomField::getFields('Activity', false, false, $this->_activityTypeId); $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Activity', false, false, null, null, true)); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_activityId, 'Activity'); } // store the date with proper format $params['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']); // assigning formated value to related variable if (CRM_Utils_Array::value('target_contact_id', $params)) { $params['target_contact_id'] = explode(',', $params['target_contact_id']); } else { $params['target_contact_id'] = array(); } if (CRM_Utils_Array::value('assignee_contact_id', $params)) { $params['assignee_contact_id'] = explode(',', $params['assignee_contact_id']); } else { $params['assignee_contact_id'] = array(); } // get ids for associated contacts if (!$params['source_contact_id']) { $params['source_contact_id'] = $this->_currentUserId; } else { $params['source_contact_id'] = $this->_submitValues['source_contact_qid']; } if (isset($this->_activityId)) { $params['id'] = $this->_activityId; } // add attachments as needed CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_activity', $this->_activityId); // format target params if (!$this->_single) { $params['target_contact_id'] = $this->_contactIds; } $activityAssigned = array(); // format assignee params if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) { //skip those assignee contacts which are already assigned //while sending a copy.CRM-4509. $activityAssigned = array_flip($params['assignee_contact_id']); if ($this->_activityId) { $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($this->_activityId); $activityAssigned = array_diff_key($activityAssigned, $assigneeContacts); } } // call begin post process. Idea is to let injecting file do // any processing before the activity is added/updated. $this->beginPostProcess($params); $activity = CRM_Activity_BAO_Activity::create($params); // call end post process. Idea is to let injecting file do any // processing needed, after the activity has been added/updated. $this->endPostProcess($params, $activity); // create follow up activity if needed $followupStatus = ''; if (CRM_Utils_Array::value('followup_activity_type_id', $params)) { $followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($activity->id, $params); $followupStatus = "A followup activity has been scheduled."; } // send copy to assignee contacts.CRM-4509 $mailStatus = ''; $config =& CRM_Core_Config::singleton(); if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id']) && $config->activityAssigneeNotification) { $mailToContacts = array(); $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id, true, false); //build an associative array with unique email addresses. foreach ($activityAssigned as $id => $dnc) { if (isset($id) && array_key_exists($id, $assigneeContacts)) { $mailToContacts[$assigneeContacts[$id]['email']] = $assigneeContacts[$id]; } } if (!CRM_Utils_array::crmIsEmptyArray($mailToContacts)) { //include attachments while sendig a copy of activity. $attachments =& CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id); require_once "CRM/Case/BAO/Case.php"; $result = CRM_Case_BAO_Case::sendActivityCopy(null, $activity->id, $mailToContacts, $attachments, null); $mailStatus .= ts("A copy of the activity has also been sent to assignee contacts(s)."); } } // set status message if (CRM_Utils_Array::value('subject', $params)) { $params['subject'] = "'" . $params['subject'] . "'"; } CRM_Core_Session::setStatus(ts('Activity %1 has been saved. %2. %3', array(1 => $params['subject'], 2 => $followupStatus, 3 => $mailStatus))); return array('activity' => $activity); }
/** * Send activity as attachment. * * @param object $activity * @param array $mailToContacts * @param array $params * * @return bool */ public static function sendToAssignee($activity, $mailToContacts, $params = array()) { if (!CRM_Utils_Array::crmIsEmptyArray($mailToContacts)) { $clientID = CRM_Utils_Array::value('client_id', $params); $caseID = CRM_Utils_Array::value('case_id', $params); $ics = new CRM_Activity_BAO_ICalendar($activity); $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id); $ics->addAttachment($attachments, $mailToContacts); $result = CRM_Case_BAO_Case::sendActivityCopy($clientID, $activity->id, $mailToContacts, $attachments, $caseID); $ics->cleanup(); return $result; } return FALSE; }
/** * Creates or updates an Activity. * * @param array $params * Array per getfields documentation. * * @throws API_Exception * @return array * API result array */ function civicrm_api3_activity_create($params) { if (empty($params['id'])) { // an update does not require any mandatory parameters civicrm_api3_verify_one_mandatory($params, NULL, array('activity_name', 'activity_type_id', 'activity_label')); } // check for various error and required conditions // note that almost all the processing in there should be managed by the wrapper layer // & should be removed - needs testing $errors = _civicrm_api3_activity_check_params($params); // this should not be required as should throw exception rather than return errors - //needs testing if (!empty($errors)) { return $errors; } // processing for custom data $values = $activityArray = array(); _civicrm_api3_custom_format_params($params, $values, 'Activity'); if (!empty($values['custom'])) { $params['custom'] = $values['custom']; } // this should be set as a default rather than hard coded // needs testing $params['skipRecentView'] = TRUE; // If this is a case activity, see if there is an existing activity // and set it as an old revision. Also retrieve details we'll need. // this handling should all be moved to the BAO layer $case_id = ''; $createRevision = FALSE; $oldActivityValues = array(); // Lookup case id if not supplied if (!isset($params['case_id']) && !empty($params['id'])) { $params['case_id'] = CRM_Core_DAO::singleValueQuery("SELECT case_id FROM civicrm_case_activity WHERE activity_id = " . (int) $params['id']); } if (!empty($params['case_id'])) { $case_id = $params['case_id']; if (!empty($params['id'])) { $oldActivityParams = array('id' => $params['id']); if (!$oldActivityValues) { CRM_Activity_BAO_Activity::retrieve($oldActivityParams, $oldActivityValues); } if (empty($oldActivityValues)) { throw new API_Exception(ts("Unable to locate existing activity.")); } else { $activityDAO = new CRM_Activity_DAO_Activity(); $activityDAO->id = $params['id']; $activityDAO->is_current_revision = 0; if (!$activityDAO->save()) { if (is_object($activityDAO)) { $activityDAO->free(); } throw new API_Exception(ts("Unable to revision existing case activity.")); } $createRevision = TRUE; } } } $deleteActivityAssignment = FALSE; if (isset($params['assignee_contact_id'])) { $deleteActivityAssignment = TRUE; } $deleteActivityTarget = FALSE; if (isset($params['target_contact_id'])) { $deleteActivityTarget = TRUE; } // this should all be handled at the BAO layer $params['deleteActivityAssignment'] = CRM_Utils_Array::value('deleteActivityAssignment', $params, $deleteActivityAssignment); $params['deleteActivityTarget'] = CRM_Utils_Array::value('deleteActivityTarget', $params, $deleteActivityTarget); if ($case_id && $createRevision) { // This is very similar to the copy-to-case action. if (!CRM_Utils_Array::crmIsEmptyArray($oldActivityValues['target_contact'])) { $oldActivityValues['targetContactIds'] = implode(',', array_unique($oldActivityValues['target_contact'])); } if (!CRM_Utils_Array::crmIsEmptyArray($oldActivityValues['assignee_contact'])) { $oldActivityValues['assigneeContactIds'] = implode(',', array_unique($oldActivityValues['assignee_contact'])); } $oldActivityValues['mode'] = 'copy'; $oldActivityValues['caseID'] = $case_id; $oldActivityValues['activityID'] = $oldActivityValues['id']; $oldActivityValues['contactID'] = $oldActivityValues['source_contact_id']; $copyToCase = CRM_Activity_Page_AJAX::_convertToCaseActivity($oldActivityValues); if (empty($copyToCase['error_msg'])) { // now fix some things that are different from copy-to-case // then fall through to the create below to update with the passed in params $params['id'] = $copyToCase['newId']; $params['is_auto'] = 0; $params['original_id'] = empty($oldActivityValues['original_id']) ? $oldActivityValues['id'] : $oldActivityValues['original_id']; } else { throw new API_Exception(ts("Unable to create new revision of case activity.")); } } // create activity $activityBAO = CRM_Activity_BAO_Activity::create($params); if (isset($activityBAO->id)) { if ($case_id && !$createRevision) { // If this is a brand new case activity we need to add this $caseActivityParams = array('activity_id' => $activityBAO->id, 'case_id' => $case_id); CRM_Case_BAO_Case::processCaseActivity($caseActivityParams); } _civicrm_api3_object_to_array($activityBAO, $activityArray[$activityBAO->id]); return civicrm_api3_create_success($activityArray, $params, 'Activity', 'get', $activityBAO); } }
/** * Mark dupe pairs as selected from un-selected state or vice-versa, in dupe cache table. */ public static function toggleDedupeSelect() { $rgid = CRM_Utils_Type::escape($_REQUEST['rgid'], 'Integer'); $gid = CRM_Utils_Type::escape($_REQUEST['gid'], 'Integer'); $pnid = $_REQUEST['pnid']; $isSelected = CRM_Utils_Type::escape($_REQUEST['is_selected'], 'Boolean'); $cacheKeyString = CRM_Dedupe_Merger::getMergeCacheKeyString($rgid, $gid); $params = array(1 => array($isSelected, 'Boolean'), 3 => array("{$cacheKeyString}%", 'String')); //check pnid is_array or integer $whereClause = NULL; if (is_array($pnid) && !CRM_Utils_Array::crmIsEmptyArray($pnid)) { CRM_Utils_Type::escapeAll($pnid, 'Positive'); $pnid = implode(', ', $pnid); $whereClause = " id IN ( {$pnid} ) "; } else { $pnid = CRM_Utils_Type::escape($pnid, 'Integer'); $whereClause = " id = %2"; $params[2] = array($pnid, 'Integer'); } $sql = "UPDATE civicrm_prevnext_cache SET is_selected = %1 WHERE {$whereClause} AND cacheKey LIKE %3"; CRM_Core_DAO::executeQuery($sql, $params); CRM_Utils_System::civiExit(); }
/** * global validation rules for the form * * @param array $fields posted values of the form * * @return array list of errors to be posted back to the form * @static * @access public */ static function formRule($values, $files, $self) { // If $values['_qf_Participant_next'] is Delete or // $values['event_id'] is empty, then return // instead of proceeding further. if (CRM_Utils_Array::value('_qf_Participant_next', $values) == 'Delete' || !$values['event_id']) { return true; } //check if contact is selected in standalone mode if (isset($values['contact_select_id'][1]) && !$values['contact_select_id'][1]) { $errorMsg['contact[1]'] = ts('Please select a contact or create new contact'); } if (CRM_Utils_Array::value('payment_processor_id', $values)) { // make sure that credit card number and cvv are valid require_once 'CRM/Utils/Rule.php'; if (CRM_Utils_Array::value('credit_card_type', $values)) { if (CRM_Utils_Array::value('credit_card_number', $values) && !CRM_Utils_Rule::creditCardNumber($values['credit_card_number'], $values['credit_card_type'])) { $errorMsg['credit_card_number'] = ts("Please enter a valid Credit Card Number"); } if (CRM_Utils_Array::value('cvv2', $values) && !CRM_Utils_Rule::cvv($values['cvv2'], $values['credit_card_type'])) { $errorMsg['cvv2'] = ts("Please enter a valid Credit Card Verification Number"); } } } if (CRM_Utils_Array::value('record_contribution', $values) && !CRM_Utils_Array::value('contribution_type_id', $values)) { $errorMsg['contribution_type_id'] = ts("Please enter the associated Contribution Type"); } // validate contribution status for 'Failed'. if ($self->_onlinePendingContributionId && CRM_Utils_Array::value('record_contribution', $values) && CRM_Utils_Array::value('contribution_status_id', $values) == array_search('Failed', CRM_Contribute_PseudoConstant::contributionStatus(null, 'name'))) { $errorMsg['contribution_status_id'] = ts("Please select a valid payment status before updating."); } // do the amount validations. //skip for update mode since amount is freeze, CRM-6052 if (!$self->_id && !CRM_Utils_Array::value('total_amount', $values) && empty($self->_values['line_items']) || $self->_id && !$self->_paymentId && is_array($self->_values['line_items'])) { if ($priceSetId = CRM_Utils_Array::value('priceSetId', $values)) { require_once 'CRM/Price/BAO/Field.php'; CRM_Price_BAO_Field::priceSetValidation($priceSetId, $values, $errorMsg); } } return CRM_Utils_Array::crmIsEmptyArray($errorMsg) ? true : $errorMsg; }